Search in sources :

Example 1 with LocalInspectionToolWrapper

use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.

the class SpellCheckingEditorCustomization method init.

@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;
}
Also used : LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 2 with LocalInspectionToolWrapper

use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.

the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections2.

public void testHighlightStatus_OtherInspections2() throws Throwable {
    myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
    final MyDomElementsInspection inspection = new MyDomElementsInspection() {

        @Override
        public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
            myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
            return ProblemDescriptor.EMPTY_ARRAY;
        }

        @Override
        public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
        }
    };
    registerInspectionKey(inspection);
    LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection);
    myInspectionProfile.setInspectionTools(toolWrapper);
    myInspectionProfile.setEnabled(toolWrapper, false);
    myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
    assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
Also used : InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 3 with LocalInspectionToolWrapper

use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.

the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections.

public void testHighlightStatus_OtherInspections() throws Throwable {
    myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
    final MyDomElementsInspection inspection = new MyDomElementsInspection() {

        @Override
        public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
            myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
            return ProblemDescriptor.EMPTY_ARRAY;
        }

        @Override
        public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
        }
    };
    registerInspectionKey(inspection);
    myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection));
    myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
    assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
    myAnnotationsManager.appendProblems(myElement, createHolder(), inspection.getClass());
    assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
Also used : InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 4 with LocalInspectionToolWrapper

use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.

the class OfflineDescriptorResolveResult method createDescriptor.

@Nullable
private static CommonProblemDescriptor createDescriptor(@Nullable RefEntity element, @NotNull OfflineProblemDescriptor offlineDescriptor, @NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionToolPresentation presentation) {
    if (toolWrapper instanceof GlobalInspectionToolWrapper) {
        final LocalInspectionToolWrapper localTool = ((GlobalInspectionToolWrapper) toolWrapper).getSharedLocalInspectionToolWrapper();
        if (localTool != null) {
            final CommonProblemDescriptor descriptor = createDescriptor(element, offlineDescriptor, localTool, presentation);
            if (descriptor != null) {
                return descriptor;
            }
        }
        return createRerunGlobalToolDescriptor((GlobalInspectionToolWrapper) toolWrapper, element);
    }
    if (!(toolWrapper instanceof LocalInspectionToolWrapper))
        return null;
    final InspectionManager inspectionManager = InspectionManager.getInstance(presentation.getContext().getProject());
    final OfflineProblemDescriptor offlineProblemDescriptor = offlineDescriptor;
    if (element instanceof RefElement) {
        final PsiElement psiElement = ((RefElement) element).getElement();
        if (psiElement != null) {
            ProblemDescriptor descriptor = ProgressManager.getInstance().runProcess(() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, (LocalInspectionToolWrapper) toolWrapper), new DaemonProgressIndicator());
            if (descriptor != null)
                return descriptor;
        }
        return null;
    }
    final List<String> hints = offlineProblemDescriptor.getHints();
    CommonProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), (QuickFix) null);
    final QuickFix[] quickFixes = getFixes(descriptor, hints, presentation);
    if (quickFixes != null) {
        descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), quickFixes);
    }
    return descriptor;
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) RefElement(com.intellij.codeInspection.reference.RefElement) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with LocalInspectionToolWrapper

use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.

the class InspectionEngine method inspectElements.

// returns map tool.shortName -> list of descriptors found
@NotNull
static Map<String, List<ProblemDescriptor>> inspectElements(@NotNull List<LocalInspectionToolWrapper> toolWrappers, @NotNull final PsiFile file, @NotNull final InspectionManager iManager, final boolean isOnTheFly, boolean failFastOnAcquireReadAction, @NotNull ProgressIndicator indicator, @NotNull final List<PsiElement> elements, @NotNull 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;
}
Also used : Language(com.intellij.lang.Language) java.util(java.util) JobLauncher(com.intellij.concurrency.JobLauncher) GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) Divider(com.intellij.codeInsight.daemon.impl.Divider) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) Conditions(com.intellij.openapi.util.Conditions) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) Logger(com.intellij.openapi.diagnostic.Logger) CommonProcessors(com.intellij.util.CommonProcessors) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) ProgressManager(com.intellij.openapi.progress.ProgressManager) RefElement(com.intellij.codeInspection.reference.RefElement) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AnalysisScope(com.intellij.analysis.AnalysisScope) TextRange(com.intellij.openapi.util.TextRange) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Processor(com.intellij.util.Processor) SmartHashSet(com.intellij.util.containers.SmartHashSet) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) Entry(java.util.Map.Entry) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) RefEntity(com.intellij.codeInspection.reference.RefEntity) THashSet(gnu.trove.THashSet) SmartHashSet(com.intellij.util.containers.SmartHashSet) TextRange(com.intellij.openapi.util.TextRange) Entry(java.util.Map.Entry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)26 NotNull (org.jetbrains.annotations.NotNull)11 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)6 Nullable (org.jetbrains.annotations.Nullable)6 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 RefElement (com.intellij.codeInspection.reference.RefElement)3 TextRange (com.intellij.openapi.util.TextRange)3 List (java.util.List)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 InspectionManager (com.intellij.codeInspection.InspectionManager)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 RedundantCastInspection (com.intellij.codeInspection.redundantCast.RedundantCastInspection)2 RefEntity (com.intellij.codeInspection.reference.RefEntity)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)2