com.intellij.analysis.AnalysisScope Java Examples

The following examples show how to use com.intellij.analysis.AnalysisScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static GlobalInspectionContextImpl createGlobalContextForTool(@Nonnull AnalysisScope scope,
                                                                     @Nonnull final Project project,
                                                                     @Nonnull InspectionManagerEx inspectionManager,
                                                                     @Nonnull final InspectionToolWrapper... toolWrappers) {
  final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", project, toolWrappers);
  GlobalInspectionContextImpl context = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
    @Override
    protected List<Tools> getUsedTools() {
      try {
        InspectionProfileImpl.INIT_INSPECTIONS = true;
        for (InspectionToolWrapper tool : toolWrappers) {
          profile.enableTool(tool.getShortName(), project);
        }
        return profile.getAllEnabledInspectionTools(project);
      }
      finally {
        InspectionProfileImpl.INIT_INSPECTIONS = false;
      }
    }
  };
  context.setCurrentScope(scope);

  return context;
}
 
Example #2
Source File: AbstractRefactoringPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
public AbstractRefactoringPanel(@NotNull AnalysisScope scope,
                                String detectIndicatorStatusTextKey,
                                RefactoringType refactoringType,
                                AbstractTreeTableModel model,
                                int refactorDepth) {
    this.scope = scope;
    this.scopeChooserCombo = new ScopeChooserCombo(scope.getProject());
    this.detectIndicatorStatusTextKey = detectIndicatorStatusTextKey;
    this.refactoringType = refactoringType;
    this.model = model;
    this.treeTable = new TreeTable(model);
    this.refactorDepth = refactorDepth;
    refreshLabel.setForeground(JBColor.GRAY);
    setLayout(new BorderLayout());
    setupGUI();
}
 
Example #3
Source File: TypeStateCheckingTest.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
private void performMultipleRefactoringsTest(List<Integer> eliminationGroupSizes) {
    initTest();
    eliminationGroupSizes = new ArrayList<>(eliminationGroupSizes);
    Project project = myFixture.getProject();
    while (eliminationGroupSizes.size() != 0) {
        Set<TypeCheckEliminationGroup> eliminationGroups =
                JDeodorantFacade.getTypeCheckEliminationRefactoringOpportunities(
                        new ProjectInfo(new AnalysisScope(project), false),
                        fakeProgressIndicator
                );
        assertEquals(eliminationGroupSizes.size(), eliminationGroups.size());
        TypeCheckEliminationGroup eliminationGroup = eliminationGroups.iterator().next();
        assertEquals(eliminationGroupSizes.get(0).intValue(), eliminationGroup.getCandidates().size());
        WriteCommandAction.runWriteCommandAction(
                project,
                () -> createRefactoring(eliminationGroup.getCandidates().get(0), project).apply()
        );

        if (eliminationGroupSizes.get(0) == 1) {
            eliminationGroupSizes.remove(0);
        } else {
            eliminationGroupSizes.set(0, eliminationGroupSizes.get(0) - 1);
        }
    }
    checkTest();
}
 
Example #4
Source File: DependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private AnalysisScope getScope() {
  final Set<PsiFile> selectedScope = getSelectedScope(myRightTree);
  Set<PsiFile> result = new HashSet<PsiFile>();
  ((PackageDependenciesNode)myLeftTree.getModel().getRoot()).fillFiles(result, !mySettings.UI_FLATTEN_PACKAGES);
  selectedScope.removeAll(result);
  if (selectedScope.isEmpty()) return null;
  List<VirtualFile> files = new ArrayList<VirtualFile>();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  for (PsiFile psiFile : selectedScope) {
    final VirtualFile file = psiFile.getVirtualFile();
    LOG.assertTrue(file != null);
    if (fileIndex.isInContent(file)) {
      files.add(file);
    }
  }
  if (!files.isEmpty()) {
    return new AnalysisScope(myProject, files);
  }
  return null;
}
 
Example #5
Source File: RefManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public RefManagerImpl(@Nonnull Project project, @Nullable AnalysisScope scope, @Nonnull GlobalInspectionContext context) {
  myProject = project;
  myScope = scope;
  myContext = context;
  myPsiManager = PsiManager.getInstance(project);
  myRefProject = new RefProjectImpl(this);
  for (InspectionExtensionsFactory factory : InspectionExtensionsFactory.EP_NAME.getExtensionList()) {
    final RefManagerExtension<?> extension = factory.createRefManagerExtension(this);
    if (extension != null) {
      myExtensions.put(extension.getID(), extension);
      for (Language language : extension.getLanguages()) {
        myLanguageExtensions.put(language, extension);
      }
    }
  }
  if (scope != null) {
    for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
      getRefModule(module);
    }
  }
}
 
Example #6
Source File: FieldAccessTest.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
private void testMethod(String methodCode, int fieldNumber) {
    String testContent = getPrefix() + methodCode + getSuffix();

    myFixture.configureByText("TestFieldAccess.java", testContent);

    Project project = myFixture.getProject();
    ProjectInfo projectInfo = new ProjectInfo(new AnalysisScope(project), false);

    new ASTReader(projectInfo, new ProgressIndicatorBase());
    SystemObject systemObject = ASTReader.getSystemObject();
    MySystem mySystem = new MySystem(systemObject, true);
    MyClass myClass = mySystem.getClassIterator().next();

    MyAttribute testField = myClass.getAttributeList().get(fieldNumber);
    List<String> entitySet = new ArrayList<>(testField.getFullEntitySet());

    String fieldName = "FIELD";
    if (fieldNumber == 1) {
        fieldName = "extraField";
    } else if (fieldNumber == 2) {
        fieldName = "SWITCH_CASE_TEST";
    }

    assertEquals(fieldName + "'s entity set does not contain given method.", 2, entitySet.size());
}
 
Example #7
Source File: GlobalInspectionContextBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void launchInspections(@Nonnull final AnalysisScope scope) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  LOG.info("Code inspection started");
  ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), InspectionsBundle.message("inspection.progress.title"), true,
                                                            createOption()) {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {
      performInspectionsWithProgress(scope, false, false);
    }

    @RequiredUIAccess
    @Override
    public void onSuccess() {
      notifyInspectionsFinished();
    }
  });
}
 
Example #8
Source File: GodClassDistanceMatrixTest.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
@Nullable
private ExtractClassCandidateGroup getExractClassCandidateGroup(@NotNull String classFileName) {
    myFixture.setTestDataPath(PATH_TO_TESTDATA);
    myFixture.configureByFile(PATH_TO_TESTS + classFileName);
    Project project = myFixture.getProject();
    PsiFile psiFile = FilenameIndex.getFilesByName(project, classFileName, GlobalSearchScope.allScope(project))[0];
    ProjectInfo projectInfo = new ProjectInfo(new AnalysisScope(project), false);

    Set<ExtractClassCandidateGroup> set = getExtractClassRefactoringOpportunities(projectInfo, new ProgressIndicatorBase());

    if (set.isEmpty()) {
        return null;
    }

    return set.iterator().next();
}
 
Example #9
Source File: MoveMethodPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
private static void openDefinition(@Nullable PsiMember unit, AnalysisScope scope) {
    new Task.Backgroundable(scope.getProject(), "Search Definition") {
        private PsiElement result;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            result = unit;
        }

        @Override
        public void onSuccess() {
            if (result != null) {
                EditorHelper.openInEditor(result);
            }
        }
    }.queue();
}
 
Example #10
Source File: DependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final AnalysisScope scope = getScope();
  LOG.assertTrue(scope != null);
  final DependenciesBuilder builder;
  if (!myForward) {
    builder = new BackwardDependenciesBuilder(myProject, scope, myScopeOfInterest);
  } else {
    builder = new ForwardDependenciesBuilder(myProject, scope, myTransitiveBorder);
  }
  ProgressManager.getInstance().runProcessWithProgressAsynchronously(myProject, AnalysisScopeBundle.message("package.dependencies.progress.title"), new Runnable() {
    @Override
    public void run() {
      builder.analyze();
    }
  }, new Runnable() {
    @Override
    public void run() {
      myBuilders.add(builder);
      myDependencies.putAll(builder.getDependencies());
      myIllegalDependencies.putAll(builder.getIllegalDependencies());
      exclude(myExcluded);
      rebuild();
    }
  }, null, new PerformAnalysisInBackgroundOption(myProject));
}
 
Example #11
Source File: ViewOfflineResultsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static InspectionResultsView showOfflineView(@Nonnull Project project,
                                                    @Nonnull Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap,
                                                    @Nonnull InspectionProfile inspectionProfile,
                                                    @Nonnull String title) {
  final AnalysisScope scope = new AnalysisScope(project);
  final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
  final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
  context.setExternalProfile(inspectionProfile);
  context.setCurrentScope(scope);
  context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
  final InspectionResultsView view = new InspectionResultsView(project, inspectionProfile, scope, context,
                                                               new OfflineInspectionRVContentProvider(resMap, project));
  ((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
  view.update();
  TreeUtil.selectFirstNode(view.getTree());
  context.addView(view, title);
  return view;
}
 
Example #12
Source File: AbstractRefactoringPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
public static void highlightField(@Nullable PsiField sourceField, AnalysisScope scope, boolean openInEditor) {
    new Task.Backgroundable(scope.getProject(), "Search Definition") {
        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
        }

        @Override
        public void onSuccess() {
            if (sourceField == null || !sourceField.isValid()) {
                return;
            }

            highlightPsiElement(sourceField, openInEditor);
        }
    }.queue();
}
 
Example #13
Source File: AnalyzeDependenciesOnSpecifiedTargetHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected DependenciesBuilder createDependenciesBuilder(AnalysisScope scope) {
  return new ForwardDependenciesBuilder(myProject, scope) {
    @Override
    public void analyze() {
      super.analyze();
      final Map<PsiFile,Set<PsiFile>> dependencies = getDependencies();
      for (PsiFile file : dependencies.keySet()) {
        final Set<PsiFile> files = dependencies.get(file);
        final Iterator<PsiFile> iterator = files.iterator();
        while (iterator.hasNext()) {
          PsiFile next = iterator.next();
          final VirtualFile virtualFile = next.getVirtualFile();
          if (virtualFile == null || !myTargetScope.contains(virtualFile)) {
            iterator.remove();
          }
        }
      }
    }
  };
}
 
Example #14
Source File: AbstractRefactoringPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
/**
 * Opens definition of method and highlights specified element in the method.
 */
public static void highlightStatement(@Nullable PsiMethod sourceMethod,
                                      AnalysisScope scope,
                                      PsiElement statement,
                                      boolean openInEditor) {
    new Task.Backgroundable(scope.getProject(), "Search Definition") {
        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
        }

        @Override
        public void onSuccess() {
            if (sourceMethod == null || !statement.isValid()) {
                return;
            }
            highlightPsiElement(statement, openInEditor);
        }
    }.queue();
}
 
Example #15
Source File: GlobalSimpleInspectionTool.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final void runInspection(@Nonnull AnalysisScope scope,
                                @Nonnull InspectionManager manager,
                                @Nonnull GlobalInspectionContext globalContext,
                                @Nonnull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
  throw new IncorrectOperationException("You must override checkFile() instead");
}
 
Example #16
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void testInspection(@Nonnull String testDir, @Nonnull InspectionToolWrapper toolWrapper) {
  VirtualFile sourceDir = copyDirectoryToProject(new File(testDir, "src").getPath(), "src");
  AnalysisScope scope = new AnalysisScope(getPsiManager().findDirectory(sourceDir));

  scope.invalidate();

  InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
  GlobalInspectionContextImpl globalContext = createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper);

  InspectionTestUtil.runTool(toolWrapper, scope, globalContext, inspectionManager);
  InspectionTestUtil.compareToolResults(globalContext, toolWrapper, false, new File(getTestDataPath(), testDir).getPath());
}
 
Example #17
Source File: ProjectInfo.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
public ProjectInfo(@NotNull AnalysisScope scope, boolean analyseAllFiles) {
    this.project = scope.getProject();
    List<PsiJavaFile> psiFiles = analyseAllFiles ? PsiUtils.extractFiles(project) : PsiUtils.extractFiles(project).stream().filter(scope::contains).collect(Collectors.toList());
    this.psiClasses = psiFiles.stream()
            .flatMap(psiFile -> PsiUtils.extractClasses(psiFile).stream())
            .collect(Collectors.toList());

    this.psiMethods = psiClasses.stream()
            .flatMap(psiClass -> PsiUtils.extractMethods(psiClass).stream())
            .collect(Collectors.toList());
}
 
Example #18
Source File: InspectionTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void runTool(@Nonnull InspectionToolWrapper toolWrapper,
                           @Nonnull final AnalysisScope scope,
                           @Nonnull final GlobalInspectionContextImpl globalContext,
                           @Nonnull final InspectionManagerEx inspectionManager) {
  final String shortName = toolWrapper.getShortName();
  final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
  if (key == null){
    HighlightDisplayKey.register(shortName);
  }

  globalContext.doInspections(scope);
}
 
Example #19
Source File: GlobalInspectionContextBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void doInspections(@Nonnull final AnalysisScope scope) {
  if (!GlobalInspectionContextUtil.canRunInspections(myProject, true)) return;

  cleanup();

  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      myCurrentScope = scope;
      launchInspections(scope);
    }
  }, ApplicationManager.getApplication().getDisposed());
}
 
Example #20
Source File: ClasspathPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final OrderEntry selectedEntry = getSelectedEntry();
  GlobalSearchScope targetScope;
  if (selectedEntry instanceof ModuleOrderEntry) {
    final Module module = ((ModuleOrderEntry)selectedEntry).getModule();
    LOG.assertTrue(module != null);
    targetScope = GlobalSearchScope.moduleScope(module);
  }
  else {
    Library library = ((LibraryOrderEntry)selectedEntry).getLibrary();
    LOG.assertTrue(library != null);
    targetScope = new LibraryScope(getProject(), library);
  }
  new AnalyzeDependenciesOnSpecifiedTargetHandler(getProject(), new AnalysisScope(myState.getRootModel().getModule()), targetScope) {
    @Override
    protected boolean canStartInBackground() {
      return false;
    }

    @Override
    protected boolean shouldShowDependenciesPanel(List<DependenciesBuilder> builders) {
      for (DependenciesBuilder builder : builders) {
        for (Set<PsiFile> files : builder.getDependencies().values()) {
          if (!files.isEmpty()) {
            Messages.showInfoMessage(myEntryTable, "Dependencies were successfully collected in \"" +
                                                   ToolWindowId.DEPENDENCIES + "\" toolwindow",
                                     FindBundle.message("find.pointcut.applications.not.found.title"));
            return true;
          }
        }
      }
      if (Messages.showOkCancelDialog(myEntryTable, "No code dependencies were found. Would you like to remove the dependency?",
                                      CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
        removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
      }
      return false;
    }
  }.analyze();
}
 
Example #21
Source File: CleanupIntention.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().preparePsiElementForWrite(file)) return;
  final InspectionManager managerEx = InspectionManager.getInstance(project);
  final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false);
  final AnalysisScope scope = getScope(project, file);
  if (scope != null) {
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
    globalContext.codeCleanup(project, scope, profile, getText(), null, false);
  }
}
 
Example #22
Source File: RefManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void findAllDeclarations() {
  if (!myDeclarationsFound.getAndSet(true)) {
    long before = System.currentTimeMillis();
    final AnalysisScope scope = getScope();
    if (scope != null) {
      scope.accept(myProjectIterator);
    }

    LOG.info("Total duration of processing project usages:" + (System.currentTimeMillis() - before));
  }
}
 
Example #23
Source File: CodeCleanupCheckinHandlerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void runCheckinHandlers(Runnable runnable) {
  if (VcsConfiguration.getInstance(myProject).CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT  && !DumbService.isDumb(myProject)) {

    List<VirtualFile> filesToProcess = CheckinHandlerUtil.filterOutGeneratedAndExcludedFiles(myPanel.getVirtualFiles(), myProject);
    GlobalInspectionContextBase.codeCleanup(myProject, new AnalysisScope(myProject, filesToProcess), runnable);

  } else {
    runnable.run();
  }
}
 
Example #24
Source File: UpdateCopyrightAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void analyze(@Nonnull final Project project, @Nonnull AnalysisScope scope) {
  if (scope.checkScopeWritable(project)) return;
  scope.accept(new PsiElementVisitor() {
    @Override
    public void visitFile(PsiFile file) {
      new UpdateCopyrightProcessor(project, ModuleUtilCore.findModuleForPsiElement(file), file).run();
    }
  });
}
 
Example #25
Source File: GlobalInspectionContextImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void doInspections(@Nonnull final AnalysisScope scope) {
  if (myContent != null) {
    getContentManager().removeContent(myContent, true);
  }
  super.doInspections(scope);
}
 
Example #26
Source File: GlobalInspectionContextImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void performInspectionsWithProgressAndExportResults(@Nonnull final AnalysisScope scope,
                                                           final boolean runGlobalToolsOnly,
                                                           final boolean isOfflineInspections,
                                                           @Nullable final String outputPath,
                                                           @Nonnull final List<File> inspectionsResults) {
  cleanupTools();
  setCurrentScope(scope);

  final Runnable action = new Runnable() {
    @Override
    public void run() {
      DefaultInspectionToolPresentation.setOutputPath(outputPath);
      try {
        performInspectionsWithProgress(scope, runGlobalToolsOnly, isOfflineInspections);
        exportResults(inspectionsResults, outputPath);
      }
      finally {
        DefaultInspectionToolPresentation.setOutputPath(null);
      }
    }
  };
  if (isOfflineInspections) {
    ApplicationManager.getApplication().runReadAction(action);
  }
  else {
    action.run();
  }
}
 
Example #27
Source File: BackwardDependenciesBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public BackwardDependenciesBuilder(final Project project, final AnalysisScope scope, final @Nullable AnalysisScope scopeOfInterest) {
  super(project, scope, scopeOfInterest);
  myForwardScope = ApplicationManager.getApplication().runReadAction(new Computable<AnalysisScope>() {
    @Override
    public AnalysisScope compute() {
      return getScope().getNarrowedComplementaryScope(getProject());
    }
  });
  myFileCount = myForwardScope.getFileCount();
  myTotalFileCount = myFileCount + scope.getFileCount();
}
 
Example #28
Source File: CodeInspectionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void analyze(@Nonnull Project project, @Nonnull AnalysisScope scope) {
  try {
    runInspections(project, scope);
  }
  finally {
    myGlobalInspectionContext = null;
    myExternalProfile = null;
  }
}
 
Example #29
Source File: CodeInspectionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void runInspections(Project project, AnalysisScope scope) {
  scope.setSearchInLibraries(false);
  FileDocumentManager.getInstance().saveAllDocuments();
  final GlobalInspectionContextImpl inspectionContext = getGlobalInspectionContext(project);
  inspectionContext.setExternalProfile(myExternalProfile);
  inspectionContext.setCurrentScope(scope);
  inspectionContext.doInspections(scope);
}
 
Example #30
Source File: RunInspectionIntention.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void rerunInspection(@Nonnull InspectionToolWrapper toolWrapper,
                                   @Nonnull InspectionManagerEx managerEx,
                                   @Nonnull AnalysisScope scope,
                                   PsiElement psiElement) {
  GlobalInspectionContextImpl inspectionContext = createContext(toolWrapper, managerEx, psiElement);
  inspectionContext.doInspections(scope);
}