Search in sources :

Example 1 with GlobalInspectionContextImpl

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

the class SuppressActionSequentialTask method suppress.

private void suppress(@NotNull final PsiElement element, @Nullable final CommonProblemDescriptor descriptor, @NotNull final SuppressIntentionAction action, @NotNull final RefEntity refEntity, InspectionToolWrapper wrapper, @NotNull final SuppressableInspectionTreeNode node) {
    if (action instanceof SuppressIntentionActionFromFix && !(descriptor instanceof ProblemDescriptor)) {
        LOG.info("local suppression fix for specific problem descriptor:  " + wrapper.getTool().getClass().getName());
    }
    final Project project = element.getProject();
    ApplicationManager.getApplication().runWriteAction(() -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        try {
            PsiElement container = null;
            if (action instanceof SuppressIntentionActionFromFix) {
                container = ((SuppressIntentionActionFromFix) action).getContainer(element);
            }
            if (container == null) {
                container = element;
            }
            if (action.isAvailable(project, null, element)) {
                action.invoke(project, null, element);
            }
            final Set<GlobalInspectionContextImpl> globalInspectionContexts = ((InspectionManagerEx) InspectionManager.getInstance(element.getProject())).getRunningContexts();
            for (GlobalInspectionContextImpl context : globalInspectionContexts) {
                context.ignoreElement(wrapper.getTool(), container);
                if (descriptor != null) {
                    context.getPresentation(wrapper).ignoreCurrentElementProblem(refEntity, descriptor);
                }
            }
            final RefElement containerRef = refEntity.getRefManager().getReference(container);
            final Set<Object> suppressedNodes = myContext.getView().getSuppressedNodes(wrapper.getShortName());
            if (containerRef != null) {
                Queue<RefEntity> toIgnoreInView = new Queue<>(1);
                toIgnoreInView.addLast(containerRef);
                while (!toIgnoreInView.isEmpty()) {
                    final RefEntity entity = toIgnoreInView.pullFirst();
                    if (node instanceof ProblemDescriptionNode) {
                        final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
                        if (descriptors != null) {
                            Collections.addAll(suppressedNodes, descriptors);
                        }
                    } else {
                        suppressedNodes.add(entity);
                    }
                    final List<RefEntity> children = entity.getChildren();
                    for (RefEntity child : children) {
                        toIgnoreInView.addLast(child);
                    }
                }
            }
            if (node instanceof ProblemDescriptionNode) {
                suppressedNodes.add(descriptor);
            }
        } catch (IncorrectOperationException e1) {
            LOG.error(e1);
        }
    });
    node.removeSuppressActionFromAvailable(mySuppressAction);
}
Also used : InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx) GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl) RefElement(com.intellij.codeInspection.reference.RefElement) Project(com.intellij.openapi.project.Project) ProblemDescriptionNode(com.intellij.codeInspection.ui.ProblemDescriptionNode) RefEntity(com.intellij.codeInspection.reference.RefEntity) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Queue(com.intellij.util.containers.Queue) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GlobalInspectionContextImpl

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

the class CodeInspectionOnEditorAction method analyze.

protected static void analyze(Project project, PsiFile psiFile) {
    FileDocumentManager.getInstance().saveAllDocuments();
    final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
    final AnalysisScope scope = new AnalysisScope(psiFile);
    final GlobalInspectionContextImpl inspectionContext = inspectionManagerEx.createNewGlobalContext(false);
    inspectionContext.setCurrentScope(scope);
    inspectionContext.setExternalProfile(InspectionProjectProfileManager.getInstance(project).getCurrentProfile());
    inspectionContext.doInspections(scope);
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl) InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx)

Example 3 with GlobalInspectionContextImpl

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

the class ExportHTMLAction method getWorkedTools.

@NotNull
private Set<InspectionToolWrapper> getWorkedTools(@NotNull InspectionNode node) {
    final Set<InspectionToolWrapper> result = new HashSet<>();
    final InspectionToolWrapper wrapper = node.getToolWrapper();
    if (myView.getCurrentProfileName() == null) {
        result.add(wrapper);
        return result;
    }
    final String shortName = wrapper.getShortName();
    final GlobalInspectionContextImpl context = myView.getGlobalInspectionContext();
    final Tools tools = context.getTools().get(shortName);
    if (tools != null) {
        //dummy entry points tool
        for (ScopeToolState state : tools.getTools()) {
            InspectionToolWrapper toolWrapper = state.getTool();
            result.add(toolWrapper);
        }
    }
    return result;
}
Also used : GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl) ScopeToolState(com.intellij.codeInspection.ex.ScopeToolState) Tools(com.intellij.codeInspection.ex.Tools) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GlobalInspectionContextImpl

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

the class ViewOfflineResultsAction method showOfflineView.

@NotNull
public static InspectionResultsView showOfflineView(@NotNull Project project, @NotNull Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap, @NotNull InspectionProfileImpl inspectionProfile, @NotNull String title) {
    final AnalysisScope scope = new AnalysisScope(project);
    final InspectionManagerEx managerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
    final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
    context.setExternalProfile(inspectionProfile);
    context.setCurrentScope(scope);
    context.initializeTools(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
    final InspectionResultsView view = new InspectionResultsView(context, new OfflineInspectionRVContentProvider(resMap, project));
    ((RefManagerImpl) context.getRefManager()).startOfflineView();
    context.addView(view, title, true);
    view.update();
    return view;
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl) OfflineInspectionRVContentProvider(com.intellij.codeInspection.offlineViewer.OfflineInspectionRVContentProvider) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) InspectionManagerEx(com.intellij.codeInspection.ex.InspectionManagerEx) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GlobalInspectionContextImpl

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

the class CodeInspectionAction method runInspections.

protected void runInspections(Project project, AnalysisScope scope) {
    scope.setSearchInLibraries(false);
    FileDocumentManager.getInstance().saveAllDocuments();
    final GlobalInspectionContextImpl inspectionContext = getGlobalInspectionContext(project);
    inspectionContext.setExternalProfile(myExternalProfile);
    inspectionContext.setCurrentScope(scope);
    inspectionContext.doInspections(scope);
}
Also used : GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl)

Aggregations

GlobalInspectionContextImpl (com.intellij.codeInspection.ex.GlobalInspectionContextImpl)5 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 NotNull (org.jetbrains.annotations.NotNull)2 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 ScopeToolState (com.intellij.codeInspection.ex.ScopeToolState)1 Tools (com.intellij.codeInspection.ex.Tools)1 OfflineInspectionRVContentProvider (com.intellij.codeInspection.offlineViewer.OfflineInspectionRVContentProvider)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 RefEntity (com.intellij.codeInspection.reference.RefEntity)1 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)1 InspectionResultsView (com.intellij.codeInspection.ui.InspectionResultsView)1 ProblemDescriptionNode (com.intellij.codeInspection.ui.ProblemDescriptionNode)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Queue (com.intellij.util.containers.Queue)1 THashSet (gnu.trove.THashSet)1 HashSet (java.util.HashSet)1