inspection toolwindow: mark as suppressed in view all the ignored problem while suppression IDEA-156604

This commit is contained in:
Dmitry Batkovich
2016-05-26 20:43:20 +03:00
parent 733276f649
commit 2fbc405e2c
5 changed files with 48 additions and 16 deletions
@@ -73,7 +73,11 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
private final Map<CommonProblemDescriptor, RefEntity> myProblemToElements = Collections.synchronizedMap(new THashMap<CommonProblemDescriptor, RefEntity>(TObjectHashingStrategy.IDENTITY));
private DescriptorComposer myComposer;
private final Map<RefEntity, Set<QuickFix>> myQuickFixActions = Collections.synchronizedMap(new THashMap<RefEntity, Set<QuickFix>>(TObjectHashingStrategy.IDENTITY));
private final Map<RefEntity, CommonProblemDescriptor[]> myIgnoredElements = Collections.synchronizedMap(new THashMap<RefEntity, CommonProblemDescriptor[]>(TObjectHashingStrategy.IDENTITY));
private final Map<RefEntity, CommonProblemDescriptor[]> myIgnoredElements = Collections.synchronizedMap(new THashMap<RefEntity, CommonProblemDescriptor[]>(TObjectHashingStrategy.IDENTITY) {
});
protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.DescriptorProviderInspection");
private volatile boolean isDisposed;
@@ -733,7 +737,8 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
}
@NotNull
private Map<RefEntity, CommonProblemDescriptor[]> getIgnoredElements() {
@Override
public Map<RefEntity, CommonProblemDescriptor[]> getIgnoredElements() {
return myIgnoredElements;
}
@@ -617,7 +617,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
});
}
Set<Object> getSuppressedNodes() {
public Set<Object> getSuppressedNodes() {
return mySuppressedNodes;
}
@@ -38,6 +38,9 @@ public interface InspectionToolPresentation extends ProblemDescriptionsProcessor
@NotNull
InspectionToolWrapper getToolWrapper();
@NotNull
Map<RefEntity, CommonProblemDescriptor[]> getIgnoredElements();
@NotNull
InspectionNode createToolNode(@NotNull GlobalInspectionContextImpl globalInspectionContext,
@NotNull InspectionNode node,
@@ -19,11 +19,13 @@ import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
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.SuppressableInspectionTreeNode;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbModePermission;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
@@ -31,11 +33,12 @@ import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.SequentialModalProgressTask;
import com.intellij.util.SequentialTask;
import com.intellij.util.containers.Queue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
/**
@@ -47,24 +50,24 @@ public class SuppressActionSequentialTask implements SequentialTask {
private SuppressableInspectionTreeNode[] myNodesToSuppress;
@NotNull private final SuppressIntentionAction mySuppressAction;
@NotNull private final InspectionToolWrapper myWrapper;
@NotNull private final SequentialModalProgressTask myTask;
@NotNull private final GlobalInspectionContextImpl myContext;
private int myCount = 0;
public SuppressActionSequentialTask(@NotNull SuppressableInspectionTreeNode[] nodesToSuppress,
@NotNull SuppressIntentionAction suppressAction,
@NotNull InspectionToolWrapper wrapper,
@NotNull SequentialModalProgressTask task) {
@NotNull GlobalInspectionContextImpl context) {
myNodesToSuppress = nodesToSuppress;
mySuppressAction = suppressAction;
myWrapper = wrapper;
myTask = task;
myContext = context;
}
@Override
public boolean iteration() {
final SuppressableInspectionTreeNode node = myNodesToSuppress[myCount++];
final ProgressIndicator indicator = myTask.getIndicator();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.setFraction((double)myCount / myNodesToSuppress.length);
}
@@ -75,9 +78,7 @@ public class SuppressActionSequentialTask implements SequentialTask {
final PsiElement element = content.first;
RefEntity refEntity = node.getElement();
LOG.assertTrue(refEntity != null);
if (suppress(element, content.second, mySuppressAction, refEntity, myWrapper)) {
node.markAsSuppressedFromView();
}
suppress(element, content.second, mySuppressAction, refEntity, myWrapper, node);
}
});
@@ -95,19 +96,21 @@ public class SuppressActionSequentialTask implements SequentialTask {
@Override
public void prepare() {
final ProgressIndicator indicator = myTask.getIndicator();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.setText(InspectionsBundle.message("inspection.action.suppress", myWrapper.getDisplayName()));
}
}
private static boolean suppress(@NotNull final PsiElement element,
private void suppress(@NotNull final PsiElement element,
@Nullable final CommonProblemDescriptor descriptor,
@NotNull final SuppressIntentionAction action,
@NotNull final RefEntity refEntity, InspectionToolWrapper wrapper) {
@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();
@@ -132,11 +135,32 @@ public class SuppressActionSequentialTask implements SequentialTask {
context.getPresentation(wrapper).ignoreCurrentElementProblem(refEntity, descriptor);
}
}
final RefElement containerRef = refEntity.getRefManager().getReference(container);
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().add(problemDescriptor);
}
}
final List<RefEntity> children = entity.getChildren();
if (children != null) {
for (RefEntity child : children) {
toIgnoreInView.addLast(child);
}
}
}
}
myContext.getView().getSuppressedNodes().add(descriptor);
}
catch (IncorrectOperationException e1) {
LOG.error(e1);
}
});
return true;
}
}
@@ -114,7 +114,7 @@ public class SuppressActionWrapper extends ActionGroup implements CompactActionG
final SequentialModalProgressTask progressTask =
new SequentialModalProgressTask(project, templatePresentationText, true);
progressTask.setMinIterationTime(200);
progressTask.setTask(new SuppressActionSequentialTask(nodes, mySuppressAction, wrapper, progressTask));
progressTask.setTask(new SuppressActionSequentialTask(nodes, mySuppressAction, wrapper, view.getGlobalInspectionContext()));
ProgressManager.getInstance().run(progressTask);
}, templatePresentationText, null);