inspection toolwindow: offline inspection result: append node for descriptor but do not allow nothing

This commit is contained in:
Dmitry Batkovich
2016-06-16 17:29:46 +03:00
parent 0655318f39
commit 655bd98920
3 changed files with 20 additions and 11 deletions
@@ -178,11 +178,8 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
final boolean canPackageRepeat) {
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
final RefElementNode elemNode = addNodeToParent(container, presentation, packageNode);
if (toolWrapper instanceof LocalInspectionToolWrapper) {
for (OfflineProblemDescriptor descriptor : ((RefEntityContainer<OfflineProblemDescriptor>)container).getDescriptors()) {
final OfflineProblemDescriptorNode child = OfflineProblemDescriptorNode.create(descriptor, (LocalInspectionToolWrapper)toolWrapper, presentation);
elemNode.insertByOrder(child, true);
}
for (OfflineProblemDescriptor descriptor : ((RefEntityContainer<OfflineProblemDescriptor>)container).getDescriptors()) {
elemNode.insertByOrder(OfflineProblemDescriptorNode.create(descriptor, toolWrapper, presentation), true);
}
}
}
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
@@ -49,7 +50,7 @@ import java.util.Set;
public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
OfflineProblemDescriptorNode(RefEntity refEntity,
CommonProblemDescriptor descriptor,
@NotNull LocalInspectionToolWrapper toolWrapper,
@NotNull InspectionToolWrapper toolWrapper,
@NotNull InspectionToolPresentation presentation,
@NotNull OfflineProblemDescriptor offlineDescriptor) {
super(refEntity, descriptor, toolWrapper, presentation, false, offlineDescriptor::getLine);
@@ -60,7 +61,7 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
}
static OfflineProblemDescriptorNode create(@NotNull OfflineProblemDescriptor offlineDescriptor,
@NotNull LocalInspectionToolWrapper toolWrapper,
@NotNull InspectionToolWrapper toolWrapper,
@NotNull InspectionToolPresentation presentation) {
final RefEntity refElement = createRefElement(offlineDescriptor, presentation);
final CommonProblemDescriptor descriptor = createDescriptor(refElement, offlineDescriptor, toolWrapper, presentation);
@@ -81,6 +82,17 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
: presentableName;
}
@Override
protected boolean calculateIsValid() {
boolean isValid = super.calculateIsValid();
if (!isValid) {
if (getDescriptor() == null && !(myToolWrapper instanceof LocalInspectionToolWrapper)) {
isValid = myElement != null && myElement.isValid();
}
}
return isValid;
}
private static PsiElement[] getElementsIntersectingRange(PsiFile file, final int startOffset, final int endOffset) {
final FileViewProvider viewProvider = file.getViewProvider();
final Set<PsiElement> result = new LinkedHashSet<PsiElement>();
@@ -101,16 +113,16 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
@Nullable
private static CommonProblemDescriptor createDescriptor(@Nullable RefEntity element,
@NotNull OfflineProblemDescriptor offlineDescriptor,
@NotNull LocalInspectionToolWrapper toolWrapper,
@NotNull InspectionToolWrapper toolWrapper,
@NotNull InspectionToolPresentation presentation) {
if (!(toolWrapper instanceof LocalInspectionToolWrapper)) return null;
final InspectionManager inspectionManager = InspectionManager.getInstance(presentation.getContext().getProject());
final OfflineProblemDescriptor offlineProblemDescriptor = offlineDescriptor;
if (element instanceof RefElement) {
final PsiElement psiElement = ((RefElement)element).getElement();
if (psiElement != null) {
ProblemDescriptor descriptor = ProgressManager.getInstance().runProcess(
() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, toolWrapper), new DaemonProgressIndicator());
() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, (LocalInspectionToolWrapper)toolWrapper), new DaemonProgressIndicator());
if (descriptor != null) return descriptor;
}
return null;
@@ -115,7 +115,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
@Override
protected boolean calculateIsValid() {
if (myDescriptor == null) return false;
if (myElement == null || myElement instanceof RefElement && !myElement.isValid()) return false;
if (myElement instanceof RefElement && !myElement.isValid()) return false;
if (myDescriptor instanceof ProblemDescriptor) {
final PsiElement psiElement = ((ProblemDescriptor)myDescriptor).getPsiElement();
return psiElement != null && psiElement.isValid();