Java源码示例:com.intellij.codeInspection.ex.LocalInspectionToolWrapper

示例1
@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));
}
 
示例2
/**
 *
 * @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;
}
 
示例3
public void testZallyViolationsAreReported() {
  final ZallyYamlFileValidator swaggerYamlFileValidator = new ZallyYamlFileValidator();

  myFixture.enableInspections(swaggerYamlFileValidator);

  final LocalInspectionToolWrapper toolWrapper =
      new LocalInspectionToolWrapper(swaggerYamlFileValidator);
  myFixture.testInspection("zally/yaml/", toolWrapper);
}
 
示例4
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));
}
 
示例5
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));
    }
 
示例6
@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;
}
 
示例7
@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;
}
 
示例8
@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;
}
 
示例9
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);
}
 
示例10
@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;
}
 
示例11
@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");
}
 
示例12
public void testEndpointInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);

    doTest("testData/inspectionxml/", new LocalInspectionToolWrapper(inspection));
}
 
示例13
public void testSimpleInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);
    doTest("testData/inspectionsimplexml/", new LocalInspectionToolWrapper(inspection));
}
 
示例14
public void testEndpointInspection() {
    // force Camel enabled so the inspection test can run
    CamelInspection inspection = new CamelInspection(true);

    doTest("testData/inspectionjava/", new LocalInspectionToolWrapper(inspection));
}
 
示例15
public void doTest(@NonNls String folderName, LocalInspectionTool tool) throws Exception {
  doTest(folderName, new LocalInspectionToolWrapper(tool));
}
 
示例16
public OfflineProblemDescriptorNode(@Nonnull OfflineProblemDescriptor descriptor,
                                    @Nonnull LocalInspectionToolWrapper toolWrapper,
                                    @Nonnull InspectionToolPresentation presentation) {
  super(descriptor, toolWrapper, presentation);
}
 
示例17
@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());
}
 
示例18
@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();
    }
  };
}
 
示例19
private static Class getInspectionClass(final InspectionToolWrapper toolWrapper) {
  return toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getClass() : toolWrapper.getClass();
}