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);
}
Aggregations