com.intellij.codeInspection.ex.LocalInspectionToolWrapper Java Examples

The following examples show how to use com.intellij.codeInspection.ex.LocalInspectionToolWrapper. 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: InspectionEngine.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Map<String, List<ProblemDescriptor>> inspectEx(@Nonnull final List<LocalInspectionToolWrapper> toolWrappers,
                                                             @Nonnull final PsiFile file,
                                                             @Nonnull final InspectionManager iManager,
                                                             final boolean isOnTheFly,
                                                             boolean failFastOnAcquireReadAction,
                                                             @Nonnull final ProgressIndicator indicator) {
  if (toolWrappers.isEmpty()) return Collections.emptyMap();


  TextRange range = file.getTextRange();
  List<Divider.DividedElements> allDivided = new ArrayList<>();
  Divider.divideInsideAndOutsideAllRoots(file, range, range, Conditions.alwaysTrue(), new CommonProcessors.CollectProcessor<>(allDivided));

  List<PsiElement> elements = ContainerUtil.concat(
          (List<List<PsiElement>>)ContainerUtil.map(allDivided, d -> ContainerUtil.concat(d.inside, d.outside, d.parents)));

  return inspectElements(toolWrappers, file, iManager, isOnTheFly, failFastOnAcquireReadAction, indicator, elements,
                         calcElementDialectIds(elements));
}
 
Example #2
Source File: InspectionEngine.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param wrapper
 * @return null means not specified
 */
@Nullable
public static Set<String> getDialectIdsSpecifiedForTool(@Nonnull LocalInspectionToolWrapper wrapper) {
  String langId = wrapper.getLanguage();
  if (langId == null) {
    return null;
  }
  Language language = Language.findLanguageByID(langId);
  Set<String> result;
  if (language != null) {
    result = new SmartHashSet<String>();
    result.add(langId);
  }
  else {
    // unknown language in plugin.xml, ignore
    result = Collections.singleton(langId);
  }
  return result;
}
 
Example #3
Source File: SwaggerYamlFileValidatorTest.java    From intellij-swagger with MIT License 5 votes vote down vote up
public void testZallyViolationsAreReported() {
  final ZallyYamlFileValidator swaggerYamlFileValidator = new ZallyYamlFileValidator();

  myFixture.enableInspections(swaggerYamlFileValidator);

  final LocalInspectionToolWrapper toolWrapper =
      new LocalInspectionToolWrapper(swaggerYamlFileValidator);
  myFixture.testInspection("zally/yaml/", toolWrapper);
}
 
Example #4
Source File: CamelInspectJavaSimpleTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testSimpleInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);

    // must be called fooroute as inspectionsimplejava fails for some odd reason
    doTest("testData/fooroute/", new LocalInspectionToolWrapper(inspection));
}
 
Example #5
Source File: InspectionsConfigTreeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getHint(final Descriptor descriptor) {
  final InspectionToolWrapper toolWrapper = descriptor.getToolWrapper();
  if (toolWrapper instanceof LocalInspectionToolWrapper ||
      toolWrapper instanceof GlobalInspectionToolWrapper && !((GlobalInspectionToolWrapper)toolWrapper).worksInBatchModeOnly()) {
    return null;
  }
  return InspectionsBundle.message("inspection.tool.availability.in.tree.node1");
}
 
Example #6
Source File: CamelInspectJavaJSonPathTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testJSonPathInspection() {

        // force Camel enabled so the inspection test can run
        CamelInspection inspection = new CamelInspection(true);

        // must be called fooroute as inspectionsimplejava fails for some odd reason
        doTest("testData/barroute/", new LocalInspectionToolWrapper(inspection));
    }
 
Example #7
Source File: LocalInspectionsPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
List<LocalInspectionToolWrapper> getInspectionTools(@Nonnull InspectionProfileWrapper profile) {
  List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
  List<LocalInspectionToolWrapper> result = new ArrayList<LocalInspectionToolWrapper>(tools.size());
  for (LocalInspectionToolWrapper tool : tools) {
    if (!tool.runForWholeFile()) result.add(tool);
  }
  return result;
}
 
Example #8
Source File: InspectionEngine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<ProblemDescriptor> inspect(@Nonnull final List<LocalInspectionToolWrapper> toolWrappers,
                                              @Nonnull final PsiFile file,
                                              @Nonnull final InspectionManager iManager,
                                              final boolean isOnTheFly,
                                              boolean failFastOnAcquireReadAction,
                                              @Nonnull final ProgressIndicator indicator) {
  final Map<String, List<ProblemDescriptor>> problemDescriptors = inspectEx(toolWrappers, file, iManager, isOnTheFly, failFastOnAcquireReadAction, indicator);

  final List<ProblemDescriptor> result = new ArrayList<>();
  for (List<ProblemDescriptor> group : problemDescriptors.values()) {
    result.addAll(group);
  }
  return result;
}
 
Example #9
Source File: InspectionEngine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static Map<String, List<ProblemDescriptor>> inspectElements(@Nonnull List<LocalInspectionToolWrapper> toolWrappers,
                                                            @Nonnull final PsiFile file,
                                                            @Nonnull final InspectionManager iManager,
                                                            final boolean isOnTheFly,
                                                            boolean failFastOnAcquireReadAction,
                                                            @Nonnull ProgressIndicator indicator,
                                                            @Nonnull final List<PsiElement> elements,
                                                            @Nonnull final Set<String> elementDialectIds) {
  TextRange range = file.getTextRange();
  final LocalInspectionToolSession session = new LocalInspectionToolSession(file, range.getStartOffset(), range.getEndOffset());

  Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedDialectIds = getToolsToSpecifiedLanguages(toolWrappers);
  List<Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedDialectIds.entrySet());
  final Map<String, List<ProblemDescriptor>> resultDescriptors = new ConcurrentHashMap<>();
  Processor<Entry<LocalInspectionToolWrapper, Set<String>>> processor = entry -> {
    ProblemsHolder holder = new ProblemsHolder(iManager, file, isOnTheFly);
    final LocalInspectionTool tool = entry.getKey().getTool();
    Set<String> dialectIdsSpecifiedForTool = entry.getValue();
    createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, elementDialectIds, dialectIdsSpecifiedForTool);

    tool.inspectionFinished(session, holder);

    if (holder.hasResults()) {
      resultDescriptors.put(tool.getShortName(), ContainerUtil.filter(holder.getResults(), descriptor -> {
        PsiElement element = descriptor.getPsiElement();
        return element == null || !SuppressionUtil.inspectionResultSuppressed(element, tool);
      }));
    }

    return true;
  };
  JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, failFastOnAcquireReadAction, processor);

  return resultDescriptors;
}
 
Example #10
Source File: InspectionEngine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Map<LocalInspectionToolWrapper, Set<String>> getToolsToSpecifiedLanguages(@Nonnull List<LocalInspectionToolWrapper> toolWrappers) {
  Map<LocalInspectionToolWrapper, Set<String>> toolToLanguages = new THashMap<>();
  for (LocalInspectionToolWrapper wrapper : toolWrappers) {
    ProgressManager.checkCanceled();
    Set<String> specifiedLangIds = getDialectIdsSpecifiedForTool(wrapper);
    toolToLanguages.put(wrapper, specifiedLangIds);
  }
  return toolToLanguages;
}
 
Example #11
Source File: GotoInspectionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public GotoInspectionModel(Project project) {
  super(project, IdeBundle.message("prompt.goto.inspection.enter.name"), "goto.inspection.help.id");
  final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
  for (ScopeToolState state : rootProfile.getAllTools(project)) {
    InspectionToolWrapper tool = state.getTool();
    InspectionToolWrapper workingTool = tool;
    if (tool instanceof LocalInspectionToolWrapper) {
      workingTool = LocalInspectionToolWrapper.findTool2RunInBatch(project, null, tool.getShortName());
      if (workingTool == null) {
        continue;
      }
    }
    myToolNames.put(tool.getDisplayName(), workingTool);
    final String groupName = tool.getGroupDisplayName();
    Set<InspectionToolWrapper> toolsInGroup = myGroupNames.get(groupName);
    if (toolsInGroup == null) {
      toolsInGroup = new HashSet<InspectionToolWrapper>();
      myGroupNames.put(groupName, toolsInGroup);
    }
    toolsInGroup.add(workingTool);
    myToolShortNames.put(tool.getShortName(), workingTool);
  }

  final Set<String> nameIds = new HashSet<String>();
  nameIds.addAll(myToolNames.keySet());
  nameIds.addAll(myGroupNames.keySet());
  myNames = ArrayUtil.toStringArray(nameIds);
}
 
Example #12
Source File: DumpInspectionDescriptionsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Class getInspectionClass(final InspectionToolWrapper toolWrapper) {
  return toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getClass() : toolWrapper.getClass();
}
 
Example #13
Source File: WholeFileLocalInspectionsPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  final long psiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount();
  if (psiModificationCount == myPsiModificationCount) {
    return null; //optimization
  }

  if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
    return null;
  }
  ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), visibleRange, true, new DefaultHighlightInfoProcessor()) {
    @Nonnull
    @Override
    List<LocalInspectionToolWrapper> getInspectionTools(@Nonnull InspectionProfileWrapper profile) {
      List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
      List<LocalInspectionToolWrapper> result = tools.stream().filter(LocalInspectionToolWrapper::runForWholeFile).collect(Collectors.toList());
      myFileToolsCache.put(file, !result.isEmpty());
      return result;
    }

    @Override
    protected String getPresentableName() {
      return DaemonBundle.message("pass.whole.inspections");
    }

    @Override
    void inspectInjectedPsi(@Nonnull List<PsiElement> elements,
                            boolean onTheFly,
                            @Nonnull ProgressIndicator indicator,
                            @Nonnull InspectionManager iManager,
                            boolean inVisibleRange,
                            @Nonnull List<LocalInspectionToolWrapper> wrappers) {
      // already inspected in LIP
    }

    @Override
    protected void applyInformationWithProgress() {
      super.applyInformationWithProgress();
      myPsiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount();
    }
  };
}
 
Example #14
Source File: CleanupInspectionIntention.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAvailable(@Nonnull final Project project, final Editor editor, final PsiFile file) {
  return myQuickfixClass != EmptyIntentionAction.class &&
         editor != null &&
         !(myToolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)myToolWrapper).isUnfair());
}
 
Example #15
Source File: OfflineProblemDescriptorNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
public OfflineProblemDescriptorNode(@Nonnull OfflineProblemDescriptor descriptor,
                                    @Nonnull LocalInspectionToolWrapper toolWrapper,
                                    @Nonnull InspectionToolPresentation presentation) {
  super(descriptor, toolWrapper, presentation);
}
 
Example #16
Source File: InspectionFixtureTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void doTest(@NonNls String folderName, LocalInspectionTool tool) throws Exception {
  doTest(folderName, new LocalInspectionToolWrapper(tool));
}
 
Example #17
Source File: CamelInspectJavaEndpointTestIT.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
public void testEndpointInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);

    doTest("testData/inspectionjava/", new LocalInspectionToolWrapper(inspection));
}
 
Example #18
Source File: CamelInspectXmlSimpleTestIT.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
public void testSimpleInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);
    doTest("testData/inspectionsimplexml/", new LocalInspectionToolWrapper(inspection));
}
 
Example #19
Source File: CamelInspectXmlEndpointTestIT.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
public void testEndpointInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);

    doTest("testData/inspectionxml/", new LocalInspectionToolWrapper(inspection));
}