Search in sources :

Example 11 with InspectionToolPresentation

use of com.intellij.codeInspection.ui.InspectionToolPresentation in project intellij-community by JetBrains.

the class GlobalInspectionContextImpl method runGlobalTools.

private void runGlobalTools(@NotNull final AnalysisScope scope, @NotNull final InspectionManager inspectionManager, @NotNull List<Tools> globalTools, boolean isOfflineInspections) {
    LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed() || isOfflineInspections, "Must not run under read action, too unresponsive");
    final List<InspectionToolWrapper> needRepeatSearchRequest = new ArrayList<>();
    final boolean canBeExternalUsages = !(scope.getScopeType() == AnalysisScope.PROJECT && scope.isIncludeTestSource());
    for (Tools tools : globalTools) {
        for (ScopeToolState state : tools.getTools()) {
            final InspectionToolWrapper toolWrapper = state.getTool();
            final GlobalInspectionTool tool = (GlobalInspectionTool) toolWrapper.getTool();
            final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
            try {
                if (tool.isGraphNeeded()) {
                    try {
                        ((RefManagerImpl) getRefManager()).findAllDeclarations();
                    } catch (Throwable e) {
                        getStdJobDescriptors().BUILD_GRAPH.setDoneAmount(0);
                        throw e;
                    }
                }
                ApplicationManager.getApplication().runReadAction(() -> {
                    tool.runInspection(scope, inspectionManager, this, toolPresentation);
                    //skip phase when we are sure that scope already contains everything, unused declaration though needs to proceed with its suspicious code
                    if ((canBeExternalUsages || tool.getAdditionalJobs(this) != null) && tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) {
                        needRepeatSearchRequest.add(toolWrapper);
                    }
                });
            } catch (ProcessCanceledException | IndexNotReadyException e) {
                throw e;
            } catch (Throwable e) {
                LOG.error(e);
            }
        }
    }
    for (GlobalInspectionContextExtension extension : myExtensions.values()) {
        try {
            extension.performPostRunActivities(needRepeatSearchRequest, this);
        } catch (ProcessCanceledException | IndexNotReadyException e) {
            throw e;
        } catch (Throwable e) {
            LOG.error(e);
        }
    }
    addProblemsToView(globalTools);
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) GlobalInspectionContextExtension(com.intellij.codeInspection.lang.GlobalInspectionContextExtension) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 12 with InspectionToolPresentation

use of com.intellij.codeInspection.ui.InspectionToolPresentation in project intellij-community by JetBrains.

the class LocalQuickFixWrapper method ignore.

private void ignore(@NotNull Collection<PsiElement> ignoredElements, @NotNull CommonProblemDescriptor descriptor, @Nullable QuickFix fix, @NotNull GlobalInspectionContextImpl context) {
    if (fix != null) {
        InspectionToolPresentation presentation = context.getPresentation(myToolWrapper);
        presentation.ignoreProblem(descriptor, fix);
    }
    if (descriptor instanceof ProblemDescriptor) {
        PsiElement element = ((ProblemDescriptor) descriptor).getPsiElement();
        if (element != null) {
            ignoredElements.add(element);
        }
    }
}
Also used : InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement)

Example 13 with InspectionToolPresentation

use of com.intellij.codeInspection.ui.InspectionToolPresentation in project intellij-community by JetBrains.

the class GlobalJavaInspectionContextImpl method performPostRunActivities.

@Override
public void performPostRunActivities(@NotNull List<InspectionToolWrapper> needRepeatSearchRequest, @NotNull final GlobalInspectionContext context) {
    JobDescriptor progress = context.getStdJobDescriptors().FIND_EXTERNAL_USAGES;
    progress.setTotalAmount(getRequestCount());
    do {
        processSearchRequests(context);
        InspectionToolWrapper[] requestors = needRepeatSearchRequest.toArray(new InspectionToolWrapper[needRepeatSearchRequest.size()]);
        InspectionManager inspectionManager = InspectionManager.getInstance(context.getProject());
        for (InspectionToolWrapper toolWrapper : requestors) {
            boolean result = false;
            if (toolWrapper instanceof GlobalInspectionToolWrapper) {
                InspectionToolPresentation presentation = ((GlobalInspectionContextImpl) context).getPresentation(toolWrapper);
                result = ((GlobalInspectionToolWrapper) toolWrapper).getTool().queryExternalUsagesRequests(inspectionManager, context, presentation);
            }
            if (!result) {
                needRepeatSearchRequest.remove(toolWrapper);
            }
        }
        int oldSearchRequestCount = progress.getTotalAmount();
        int oldDoneAmount = progress.getDoneAmount();
        int totalAmount = oldSearchRequestCount + getRequestCount();
        progress.setTotalAmount(totalAmount);
        progress.setDoneAmount(oldDoneAmount);
    } while (!needRepeatSearchRequest.isEmpty());
}
Also used : InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) InspectionManager(com.intellij.codeInspection.InspectionManager)

Aggregations

InspectionToolPresentation (com.intellij.codeInspection.ui.InspectionToolPresentation)13 DefaultInspectionToolPresentation (com.intellij.codeInspection.ui.DefaultInspectionToolPresentation)8 RefEntity (com.intellij.codeInspection.reference.RefEntity)5 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)5 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)5 AnalysisScope (com.intellij.analysis.AnalysisScope)4 LocalInspectionsPass (com.intellij.codeInsight.daemon.impl.LocalInspectionsPass)4 GlobalInspectionContextExtension (com.intellij.codeInspection.lang.GlobalInspectionContextExtension)4 ProblemGroup (com.intellij.lang.annotation.ProblemGroup)4 NotNull (org.jetbrains.annotations.NotNull)4 AnalysisUIOptions (com.intellij.analysis.AnalysisUIOptions)3 PerformAnalysisInBackgroundOption (com.intellij.analysis.PerformAnalysisInBackgroundOption)3 FileModificationService (com.intellij.codeInsight.FileModificationService)3 ProblemHighlightFilter (com.intellij.codeInsight.daemon.ProblemHighlightFilter)3 HighlightInfoProcessor (com.intellij.codeInsight.daemon.impl.HighlightInfoProcessor)3 com.intellij.codeInspection (com.intellij.codeInspection)3 CleanupInspectionIntention (com.intellij.codeInspection.actions.CleanupInspectionIntention)3 RefElement (com.intellij.codeInspection.reference.RefElement)3 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)3 InspectionResultsView (com.intellij.codeInspection.ui.InspectionResultsView)3