Search in sources :

Example 1 with GlobalInspectionToolWrapper

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

the class RedundantSuppressTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myInspectionToolWrappers = new InspectionToolWrapper[] { new LocalInspectionToolWrapper(new JavaDocReferenceInspection()), new LocalInspectionToolWrapper(new I18nInspection()), new LocalInspectionToolWrapper(new RawUseOfParameterizedTypeInspection()), new GlobalInspectionToolWrapper(new EmptyMethodInspection()), new GlobalInspectionToolWrapper(new UnusedDeclarationInspection()) };
    myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() {

        @NotNull
        @Override
        protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) {
            return myInspectionToolWrappers;
        }
    });
}
Also used : JavaDocReferenceInspection(com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection) GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) I18nInspection(com.intellij.codeInspection.i18n.I18nInspection) RawUseOfParameterizedTypeInspection(com.siyeh.ig.migration.RawUseOfParameterizedTypeInspection) EmptyMethodInspection(com.intellij.codeInspection.emptyMethod.EmptyMethodInspection) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection) NotNull(org.jetbrains.annotations.NotNull) GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GlobalInspectionToolWrapper

use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper 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 3 with GlobalInspectionToolWrapper

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

the class InspectionEngine method runInspectionOnFile.

@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
    final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
    toolWrapper.initialize(inspectionContext);
    RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
    refManager.inspectionReadActionStarted();
    try {
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
            return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
        }
        if (toolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
            final List<ProblemDescriptor> descriptors = new ArrayList<>();
            if (globalTool instanceof GlobalSimpleInspectionTool) {
                GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
                ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
                ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {

                    @Nullable
                    @Override
                    public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
                        return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
                    }

                    @Override
                    public void ignoreElement(@NotNull RefEntity refEntity) {
                        throw new RuntimeException();
                    }

                    @Override
                    public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
                        if (!(refEntity instanceof RefElement))
                            return;
                        PsiElement element = ((RefElement) refEntity).getElement();
                        convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
                    }

                    @Override
                    public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
                        throw new RuntimeException();
                    }
                };
                simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
                return descriptors;
            }
            RefElement fileRef = refManager.getReference(file);
            final AnalysisScope scope = new AnalysisScope(file);
            assert fileRef != null;
            fileRef.accept(new RefVisitor() {

                @Override
                public void visitElement(@NotNull RefEntity elem) {
                    CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
                    if (elemDescriptors != null) {
                        convertToProblemDescriptors(file, elemDescriptors, descriptors);
                    }
                    for (RefEntity child : elem.getChildren()) {
                        child.accept(this);
                    }
                }
            });
            return descriptors;
        }
    } finally {
        refManager.inspectionReadActionFinished();
        toolWrapper.cleanup(file.getProject());
        inspectionContext.cleanup();
    }
    return Collections.emptyList();
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) NotNull(org.jetbrains.annotations.NotNull) RefElement(com.intellij.codeInspection.reference.RefElement) AnalysisScope(com.intellij.analysis.AnalysisScope) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GlobalInspectionToolWrapper

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

the class EntryPointsNode method createDummyWrapper.

private static InspectionToolWrapper createDummyWrapper(@NotNull GlobalInspectionContextImpl context) {
    InspectionToolWrapper toolWrapper = new GlobalInspectionToolWrapper(new DummyEntryPointsEP());
    toolWrapper.initialize(context);
    return toolWrapper;
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) DummyEntryPointsEP(com.intellij.codeInspection.deadCode.DummyEntryPointsEP)

Example 5 with GlobalInspectionToolWrapper

use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper in project android by JetBrains.

the class AndroidInspectionsTest method getUnusedDeclarationWrapper.

private static GlobalInspectionToolWrapper getUnusedDeclarationWrapper() {
    final InspectionEP ep = new InspectionEP();
    ep.presentation = UnusedDeclarationPresentation.class.getName();
    ep.implementationClass = UnusedDeclarationInspection.class.getName();
    ep.shortName = UnusedDeclarationInspectionBase.SHORT_NAME;
    UnusedDeclarationInspection tool = new UnusedDeclarationInspection(true);
    return new GlobalInspectionToolWrapper(tool, ep);
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) InspectionEP(com.intellij.codeInspection.InspectionEP) UnusedDeclarationPresentation(com.intellij.codeInspection.deadCode.UnusedDeclarationPresentation) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)

Aggregations

GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)6 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 UnusedDeclarationInspection (com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)2 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)2 RefElement (com.intellij.codeInspection.reference.RefElement)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 InspectionEP (com.intellij.codeInspection.InspectionEP)1 DummyEntryPointsEP (com.intellij.codeInspection.deadCode.DummyEntryPointsEP)1 UnusedDeclarationPresentation (com.intellij.codeInspection.deadCode.UnusedDeclarationPresentation)1 EmptyMethodInspection (com.intellij.codeInspection.emptyMethod.EmptyMethodInspection)1 I18nInspection (com.intellij.codeInspection.i18n.I18nInspection)1 JavaDocReferenceInspection (com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection)1 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 RefEntity (com.intellij.codeInspection.reference.RefEntity)1 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)1 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)1 VisibilityInspection (com.intellij.codeInspection.visibility.VisibilityInspection)1