inspection view: allow to invoke other suppression actions in when element is already suppressed in case of unused declaration inspection (IDEA-156821)

This commit is contained in:
Dmitry Batkovich
2016-07-12 16:18:12 +03:00
parent 191bc68923
commit 8787fba3de
3 changed files with 22 additions and 7 deletions
@@ -167,7 +167,15 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
@Override
public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements, CommonProblemDescriptor[] allowedDescriptors) {
return myQuickFixActions;
boolean showFixes = false;
for (RefEntity element : refElements) {
if (!getIgnoredRefElements().contains(element) && element.isValid()) {
showFixes = true;
break;
}
}
return showFixes ? myQuickFixActions : QuickFixAction.EMPTY;
}
final QuickFixAction[] myQuickFixActions;
@@ -122,7 +122,7 @@ public class RefElementNode extends SuppressableInspectionTreeNode {
@Override
public int getProblemCount(boolean allowSuppressed) {
return isLeaf() ? myPresentation.getIgnoredRefElements().contains(getElement()) ? 0 : 1 : super.getProblemCount(allowSuppressed);
return isLeaf() ? myPresentation.getIgnoredRefElements().contains(getElement()) && !(allowSuppressed && isAlreadySuppressedFromView() && isValid()) ? 0 : 1 : super.getProblemCount(allowSuppressed);
}
@Override
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.codeInspection.ui.ProblemDescriptionNode;
import com.intellij.codeInspection.ui.SuppressableInspectionTreeNode;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -38,6 +39,7 @@ import com.intellij.util.containers.Queue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -137,16 +139,19 @@ public class SuppressActionSequentialTask implements SequentialTask {
}
final RefElement containerRef = refEntity.getRefManager().getReference(container);
final Set<Object> suppressedNodes = myContext.getView().getSuppressedNodes(wrapper.getShortName());
if (containerRef != null) {
Queue<RefEntity> toIgnoreInView = new Queue<RefEntity>(1);
toIgnoreInView.addLast(containerRef);
while (!toIgnoreInView.isEmpty()) {
final RefEntity entity = toIgnoreInView.pullFirst();
final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
if (descriptors != null) {
for (CommonProblemDescriptor problemDescriptor : descriptors) {
myContext.getView().getSuppressedNodes(wrapper.getShortName()).add(problemDescriptor);
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();
if (children != null) {
@@ -156,7 +161,9 @@ public class SuppressActionSequentialTask implements SequentialTask {
}
}
}
myContext.getView().getSuppressedNodes(wrapper.getShortName()).add(descriptor);
if (node instanceof ProblemDescriptionNode) {
suppressedNodes.add(descriptor);
}
}
catch (IncorrectOperationException e1) {
LOG.error(e1);