Java Code Examples for com.intellij.codeInspection.InspectionManager#getInstance()

The following examples show how to use com.intellij.codeInspection.InspectionManager#getInstance() . 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: 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 2
Source File: LoadStatementAnnotator.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void validateImportTarget(@Nullable StringLiteral target) {
  if (target == null) {
    return;
  }
  String targetString = target.getStringContents();
  if (targetString == null
      || targetString.startsWith(":")
      || targetString.startsWith("//")
      || targetString.startsWith("@")
      || targetString.length() < 2) {
    return;
  }
  if (targetString.startsWith("/")) {
    Annotation annotation =
        markWarning(
            target, "Deprecated load syntax; loaded Starlark module should by in label format.");
    InspectionManager inspectionManager = InspectionManager.getInstance(target.getProject());
    ProblemDescriptor descriptor =
        inspectionManager.createProblemDescriptor(
            target,
            annotation.getMessage(),
            DeprecatedLoadQuickFix.INSTANCE,
            ProblemHighlightType.LIKE_DEPRECATED,
            true);
    annotation.registerFix(DeprecatedLoadQuickFix.INSTANCE, null, null, descriptor);
    return;
  }
  markError(target, "Invalid load syntax: missing Starlark module.");
}
 
Example 3
Source File: AddPythonFacetQuickFixTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public void testMissingPythonInterpreter() {
  String helloProjectPath = "examples/src/scala/org/pantsbuild/example/hello/";
  doImport(helloProjectPath);

  VirtualFile vfile = myProjectRoot.findFileByRelativePath(helloProjectPath + "BUILD");
  assertNotNull(vfile);
  PsiFile build = PsiManager.getInstance(myProject).findFile(vfile);
  assertNotNull(build);
  PythonFacetInspection inspection = new PythonFacetInspection();
  InspectionManager manager = InspectionManager.getInstance(myProject);

  boolean noSdkInModules = Arrays.stream(ModuleManager.getInstance(myProject).getModules())
    .allMatch(PantsPythonSdkUtil::hasNoPythonSdk);
  assertTrue(noSdkInModules);

  // We should not have any interpreter selected for the BUILD file
  ProblemDescriptor[] problems = inspection.checkFile(build, manager, false);
  assertNotNull(problems);
  assertSize(1, problems);

  QuickFix<?>[] fixes = problems[0].getFixes();
  assertNotNull(fixes);
  assertSize(1, fixes);

  AddPythonFacetQuickFix expected = new AddPythonFacetQuickFix();
  assertEquals(fixes[0].getName(), expected.getName());
  injectFakePythonSdk();

  // invoke the quickfix in order to automatically add the python facet to the module containing the BUILD file
  AddPythonFacetQuickFix actual = (AddPythonFacetQuickFix) fixes[0];
  actual.invoke(myProject, null, build);

  ProblemDescriptor[] problemsAfterFix = inspection.checkFile(build, manager, false);
  assertNull(problemsAfterFix);

  assertAllModulesHavePythonSdk();
}
 
Example 4
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 5
Source File: QuickFixAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void refreshViews(@Nonnull Project project, @Nonnull Set<PsiElement> selectedElements, @Nonnull InspectionToolWrapper toolWrapper) {
  InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
  final Set<GlobalInspectionContextImpl> runningContexts = managerEx.getRunningContexts();
  for (GlobalInspectionContextImpl context : runningContexts) {
    for (PsiElement element : selectedElements) {
      context.ignoreElement(toolWrapper.getTool(), element);
    }
    context.refreshViews();
  }
}
 
Example 6
Source File: CodeCleanupAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void runInspections(Project project, AnalysisScope scope) {
  final InspectionProfile profile = myExternalProfile != null ? myExternalProfile : InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
  final InspectionManager managerEx = InspectionManager.getInstance(project);
  final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false);
  globalContext.codeCleanup(project, scope, profile, getTemplatePresentation().getText(), null, false);
}
 
Example 7
Source File: CodeInspectionOnEditorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void analyze(Project project, PsiFile psiFile) {
  FileDocumentManager.getInstance().saveAllDocuments();
  final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
  final AnalysisScope scope = new AnalysisScope(psiFile);
  final GlobalInspectionContextImpl inspectionContext = inspectionManagerEx.createNewGlobalContext(false);
  inspectionContext.setCurrentScope(scope);
  final InspectionProfile inspectionProfile =
    InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
  inspectionContext.setExternalProfile(inspectionProfile);
  inspectionContext.doInspections(scope);
}