mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inspection toolwindow: proper is-valid resolution for offline inspection nodes IDEA-157014
This commit is contained in:
+12
-6
@@ -35,6 +35,7 @@ import com.intellij.codeInspection.ui.ProblemDescriptionNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
@@ -52,10 +53,11 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
@NotNull LocalInspectionToolWrapper toolWrapper,
|
||||
@NotNull InspectionToolPresentation presentation,
|
||||
@NotNull OfflineProblemDescriptor offlineDescriptor) {
|
||||
super(refEntity, descriptor, toolWrapper, presentation);
|
||||
super(refEntity, descriptor, toolWrapper, presentation, false);
|
||||
if (descriptor == null) {
|
||||
setUserObject(offlineDescriptor);
|
||||
}
|
||||
init(presentation.getContext().getProject());
|
||||
}
|
||||
|
||||
static OfflineProblemDescriptorNode create(@NotNull OfflineProblemDescriptor offlineDescriptor,
|
||||
@@ -66,16 +68,20 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
return new OfflineProblemDescriptorNode(refElement, descriptor, toolWrapper, presentation, offlineDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean calculateIsValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStatus getNodeStatus() {
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String calculatePresentableName() {
|
||||
String presentableName = super.calculatePresentableName();
|
||||
return presentableName.isEmpty() && getUserObject() instanceof OfflineProblemDescriptor
|
||||
? StringUtil.notNullize(((OfflineProblemDescriptor)getUserObject()).getDescription())
|
||||
: presentableName;
|
||||
}
|
||||
|
||||
private static PsiElement[] getElementsIntersectingRange(PsiFile file, final int startOffset, final int endOffset) {
|
||||
final FileViewProvider viewProvider = file.getViewProvider();
|
||||
final Set<PsiElement> result = new LinkedHashSet<PsiElement>();
|
||||
|
||||
@@ -66,8 +66,10 @@ import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.EditSourceOnDoubleClickHandler;
|
||||
import com.intellij.util.OpenSourceUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -123,7 +125,13 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
private EditorEx myPreviewEditor;
|
||||
private InspectionTreeLoadingProgressAware myLoadingProgressPreview;
|
||||
private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager;
|
||||
private final Set<Object> mySuppressedNodes = new HashSet<>();
|
||||
private final FactoryMap<String, Set<Object>> mySuppressedNodes = new FactoryMap<String, Set<Object>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected Set<Object> create(String key) {
|
||||
return new THashSet<>();
|
||||
}
|
||||
};
|
||||
private final ConcurrentMap<String, Set<SuppressIntentionAction>> mySuppressActions = new ConcurrentHashMap<>();
|
||||
|
||||
private final Object myTreeStructureUpdateLock = new Object();
|
||||
@@ -608,8 +616,8 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
});
|
||||
}
|
||||
|
||||
public Set<Object> getSuppressedNodes() {
|
||||
return mySuppressedNodes;
|
||||
public Set<Object> getSuppressedNodes(String toolId) {
|
||||
return mySuppressedNodes.get(toolId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -49,6 +49,14 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
|
||||
CommonProblemDescriptor descriptor,
|
||||
@NotNull InspectionToolWrapper toolWrapper,
|
||||
@NotNull InspectionToolPresentation presentation) {
|
||||
this(element, descriptor, toolWrapper, presentation, true);
|
||||
}
|
||||
|
||||
protected ProblemDescriptionNode(RefEntity element,
|
||||
CommonProblemDescriptor descriptor,
|
||||
@NotNull InspectionToolWrapper toolWrapper,
|
||||
@NotNull InspectionToolPresentation presentation,
|
||||
boolean doInit) {
|
||||
super(descriptor, presentation);
|
||||
myElement = element;
|
||||
myDescriptor = descriptor;
|
||||
@@ -57,7 +65,9 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
|
||||
myLevel = descriptor instanceof ProblemDescriptor
|
||||
? profile.getErrorLevel(HighlightDisplayKey.find(toolWrapper.getShortName()), ((ProblemDescriptor)descriptor).getStartElement())
|
||||
: profile.getTools(toolWrapper.getID(), element.getRefManager().getProject()).getLevel();
|
||||
init(presentation.getContext().getProject());
|
||||
if (doInit) {
|
||||
init(presentation.getContext().getProject());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,10 +104,10 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
|
||||
|
||||
@Override
|
||||
protected boolean calculateIsValid() {
|
||||
if (myDescriptor == null) return false;
|
||||
if (myElement instanceof RefElement && !myElement.isValid()) return false;
|
||||
final CommonProblemDescriptor descriptor = getDescriptor();
|
||||
if (descriptor instanceof ProblemDescriptor) {
|
||||
final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement();
|
||||
if (myDescriptor instanceof ProblemDescriptor) {
|
||||
final PsiElement psiElement = ((ProblemDescriptor)myDescriptor).getPsiElement();
|
||||
return psiElement != null && psiElement.isValid();
|
||||
}
|
||||
return true;
|
||||
@@ -137,6 +147,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String calculatePresentableName() {
|
||||
CommonProblemDescriptor descriptor = getDescriptor();
|
||||
@@ -148,7 +159,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
|
||||
}
|
||||
|
||||
public boolean isQuickFixAppliedFromView() {
|
||||
return myPresentation.isProblemResolved(getElement(), myDescriptor) && !isAlreadySuppressedFromView();
|
||||
return (myDescriptor != null && myPresentation.isProblemResolved(getElement(), myDescriptor)) && !isAlreadySuppressedFromView();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-7
@@ -54,13 +54,7 @@ public abstract class SuppressableInspectionTreeNode extends CachedInspectionTre
|
||||
public final boolean isAlreadySuppressedFromView() {
|
||||
final Object usrObj = getUserObject();
|
||||
LOG.assertTrue(usrObj != null);
|
||||
return myView.getSuppressedNodes().contains(usrObj);
|
||||
}
|
||||
|
||||
public final void markAsSuppressedFromView() {
|
||||
final Object usrObj = getUserObject();
|
||||
LOG.assertTrue(usrObj != null);
|
||||
myView.getSuppressedNodes().add(usrObj);
|
||||
return myView.getSuppressedNodes(myPresentation.getToolWrapper().getShortName()).contains(usrObj);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ public class SuppressActionSequentialTask implements SequentialTask {
|
||||
final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
|
||||
if (descriptors != null) {
|
||||
for (CommonProblemDescriptor problemDescriptor : descriptors) {
|
||||
myContext.getView().getSuppressedNodes().add(problemDescriptor);
|
||||
myContext.getView().getSuppressedNodes(wrapper.getShortName()).add(problemDescriptor);
|
||||
}
|
||||
}
|
||||
final List<RefEntity> children = entity.getChildren();
|
||||
@@ -156,7 +156,7 @@ public class SuppressActionSequentialTask implements SequentialTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
myContext.getView().getSuppressedNodes().add(descriptor);
|
||||
myContext.getView().getSuppressedNodes(wrapper.getShortName()).add(descriptor);
|
||||
}
|
||||
catch (IncorrectOperationException e1) {
|
||||
LOG.error(e1);
|
||||
|
||||
Reference in New Issue
Block a user