inspection tool window: navigate prev/next can navigate to entities with applied fixes

This commit is contained in:
Dmitry Batkovich
2016-04-27 11:09:09 +03:00
parent 6d7d268c32
commit 7eb90703ff
6 changed files with 44 additions and 37 deletions
@@ -77,17 +77,17 @@ public abstract class InspectionRVContentProvider {
final TreePath[] treePaths = tree.getSelectionPaths();
if (treePaths == null) return false;
for (TreePath selectionPath : treePaths) {
if (!TreeUtil.traverseDepth((TreeNode)selectionPath.getLastPathComponent(), new TreeUtil.Traverse() {
@Override
public boolean accept(final Object node) {
if (!((InspectionTreeNode)node).isValid()) return true;
if (node instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode)node).getDescriptor();
if (!TreeUtil.traverseDepth((TreeNode)selectionPath.getLastPathComponent(), node -> {
if (!((InspectionTreeNode) node).isValid()) return true;
if (node instanceof ProblemDescriptionNode) {
ProblemDescriptionNode problemDescriptionNode = (ProblemDescriptionNode)node;
if (!problemDescriptionNode.isQuickFixAppliedFromView()) {
final CommonProblemDescriptor descriptor = problemDescriptionNode.getDescriptor();
final QuickFix[] fixes = descriptor != null ? descriptor.getFixes() : null;
return fixes == null || fixes.length == 0;
}
return true;
}
return true;
})) {
return true;
}
@@ -69,27 +69,25 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
final List<RefEntity> selectedElements = new ArrayList<RefEntity>();
final Map<RefEntity, CommonProblemDescriptor[]> actions = new HashMap<>();
for (TreePath selectionPath : treePaths) {
TreeUtil.traverseDepth((TreeNode)selectionPath.getLastPathComponent(), new TreeUtil.Traverse() {
@Override
public boolean accept(final Object node) {
if (!((InspectionTreeNode)node).isValid()) return true;
if (node instanceof OfflineProblemDescriptorNode) {
final OfflineProblemDescriptorNode descriptorNode = (OfflineProblemDescriptorNode)node;
final RefEntity element = descriptorNode.getElement();
selectedElements.add(element);
CommonProblemDescriptor[] descriptors = actions.get(element);
final CommonProblemDescriptor descriptor = descriptorNode.getDescriptor();
final CommonProblemDescriptor[] descriptorAsArray = descriptor == null ? CommonProblemDescriptor.EMPTY_ARRAY
: new CommonProblemDescriptor[]{descriptor};
actions.put(element, descriptors == null ?
descriptorAsArray :
DefaultInspectionToolPresentation.mergeDescriptors(descriptors, descriptorAsArray));
}
else if (node instanceof RefElementNode) {
selectedElements.add(((RefElementNode)node).getElement());
}
return true;
TreeUtil.traverseDepth((TreeNode)selectionPath.getLastPathComponent(), node -> {
if (!((InspectionTreeNode)node).isValid()) return true;
if (node instanceof OfflineProblemDescriptorNode) {
if (!((OfflineProblemDescriptorNode)node).isQuickFixAppliedFromView()) return true;
final OfflineProblemDescriptorNode descriptorNode = (OfflineProblemDescriptorNode)node;
final RefEntity element = descriptorNode.getElement();
selectedElements.add(element);
CommonProblemDescriptor[] descriptors = actions.get(element);
final CommonProblemDescriptor descriptor = descriptorNode.getDescriptor();
final CommonProblemDescriptor[] descriptorAsArray = descriptor == null ? CommonProblemDescriptor.EMPTY_ARRAY
: new CommonProblemDescriptor[]{descriptor};
actions.put(element, descriptors == null ?
descriptorAsArray :
DefaultInspectionToolPresentation.mergeDescriptors(descriptors, descriptorAsArray));
}
else if (node instanceof RefElementNode) {
selectedElements.add(((RefElementNode)node).getElement());
}
return true;
});
}
@@ -241,8 +241,19 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
}
}
else if (node instanceof ProblemDescriptionNode) {
if (!((ProblemDescriptionNode)node).isValid()) return null;
return navigate(((ProblemDescriptionNode)node).getDescriptor());
boolean isValid;
if (((ProblemDescriptionNode)node).isValid()) {
if (((ProblemDescriptionNode)node).isQuickFixAppliedFromView()) {
isValid = ((ProblemDescriptionNode)node).calculateIsValid();
} else {
isValid = true;
}
} else {
isValid = false;
}
return isValid
? navigate(((ProblemDescriptionNode)node).getDescriptor())
: InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode)node);
}
return null;
}
@@ -43,6 +43,9 @@ public class InspectionResultsViewUtil {
@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
RefEntity element = node.getElement();
while (element != null && !element.isValid()) {
element = element.getOwner();
}
if (!(element instanceof RefElement)) return null;
PsiElement containingElement = ((RefElement)element).getElement();
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid()) return null;
@@ -70,12 +70,7 @@ class InspectionViewPsiTreeChangeAdapter extends PsiTreeChangeAdapter {
Set<VirtualFile> files = new HashSet<>();
for (Update update : updates) {
VirtualFile file = (VirtualFile)update.getEqualityObjects()[0];
VfsUtilCore.iterateChildrenRecursively(file, VirtualFileFilter.ALL, new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
return files.add(fileOrDir);
}
});
VfsUtilCore.iterateChildrenRecursively(file, VirtualFileFilter.ALL, files::add);
}
final Project project = view.getProject();
@@ -93,7 +93,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
}
@Override
public boolean calculateIsValid() {
protected boolean calculateIsValid() {
if (myElement instanceof RefElement && !myElement.isValid()) return false;
final CommonProblemDescriptor descriptor = getDescriptor();
if (descriptor instanceof ProblemDescriptor) {
@@ -138,7 +138,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
}
@Override
public String calculatePresentableName() {
protected String calculatePresentableName() {
CommonProblemDescriptor descriptor = getDescriptor();
if (descriptor == null) return "";
PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null;