@SuppressWarnings({"unchecked"})
  private static boolean init() {
    // It's assumed that default spell checking inspection settings are just fine for processing all
    // types of data.
    // Please perform corresponding settings tuning if that assumption is broken at future.

    Class<LocalInspectionTool>[] inspectionClasses =
        (Class<LocalInspectionTool>[]) new Class<?>[] {SpellCheckingInspection.class};
    for (Class<LocalInspectionTool> inspectionClass : inspectionClasses) {
      try {
        LocalInspectionTool tool = inspectionClass.newInstance();
        SPELL_CHECK_TOOLS.put(tool.getShortName(), new LocalInspectionToolWrapper(tool));
      } catch (Throwable e) {
        return false;
      }
    }
    return true;
  }
 private static HighlightDisplayLevel getHighlightDisplayLevel(
     final LocalInspectionTool inspectionTool,
     final InspectionProfile inspectionProfile,
     PsiElement file) {
   final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionTool.getShortName());
   return inspectionProfile.isToolEnabled(key, file)
       ? inspectionProfile.getErrorLevel(key, file)
       : HighlightDisplayLevel.DO_NOT_SHOW;
 }
Exemple #3
0
  private static ProblemDescriptor runLocalTool(
      @NotNull PsiElement psiElement,
      @NotNull InspectionManager inspectionManager,
      @NotNull OfflineProblemDescriptor offlineProblemDescriptor,
      @NotNull LocalInspectionToolWrapper toolWrapper) {
    PsiFile containingFile = psiElement.getContainingFile();
    final ProblemsHolder holder = new ProblemsHolder(inspectionManager, containingFile, false);
    final LocalInspectionTool localTool = toolWrapper.getTool();
    final int startOffset = psiElement.getTextRange().getStartOffset();
    final int endOffset = psiElement.getTextRange().getEndOffset();
    LocalInspectionToolSession session =
        new LocalInspectionToolSession(containingFile, startOffset, endOffset);
    final PsiElementVisitor visitor = localTool.buildVisitor(holder, false, session);
    localTool.inspectionStarted(session, false);
    final PsiElement[] elementsInRange =
        getElementsIntersectingRange(containingFile, startOffset, endOffset);
    for (PsiElement element : elementsInRange) {
      element.accept(visitor);
    }
    localTool.inspectionFinished(session, holder);
    if (holder.hasResults()) {
      final List<ProblemDescriptor> list = holder.getResults();
      final int idx = offlineProblemDescriptor.getProblemIndex();
      int curIdx = 0;
      for (ProblemDescriptor descriptor : list) {
        final PsiNamedElement member = localTool.getProblemElement(descriptor.getPsiElement());
        if (psiElement instanceof PsiFile || member != null && member.equals(psiElement)) {
          if (curIdx == idx) {
            return descriptor;
          }
          curIdx++;
        }
      }
    }

    return null;
  }
 /** This should be used in tests primarily */
 @TestOnly
 public LocalInspectionToolWrapper(@NotNull LocalInspectionTool tool) {
   super(tool, ourEPMap.getValue().get(tool.getShortName()));
 }