Search in sources :

Example 1 with ProblemDescriptionNode

use of com.intellij.codeInspection.ui.ProblemDescriptionNode 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)

Aggregations

GlobalInspectionContextImpl (com.intellij.codeInspection.ex.GlobalInspectionContextImpl)1 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 RefEntity (com.intellij.codeInspection.reference.RefEntity)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