From b943c30a6ca7bf4e07b68fc94d0038fbc45f0592 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Wed, 25 Jan 2017 12:29:13 +0300 Subject: [PATCH] resource bundle editor: npe on highlighting started IDEA-166517 --- .../ResourceBundleEditorHighlighter.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorHighlighter.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorHighlighter.java index fe6fa3ecc5f0..01f0f069cbb0 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorHighlighter.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditorHighlighter.java @@ -24,12 +24,13 @@ import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.ProblemDescriptorUtil; import com.intellij.codeInspection.ex.InspectionToolWrapper; -import com.intellij.ide.util.treeView.TreeVisitor; +import com.intellij.ide.structureView.StructureViewModel; import com.intellij.ide.util.treeView.smartTree.TreeElement; -import com.intellij.ide.util.treeView.smartTree.TreeElementWrapper; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.lang.properties.IProperty; -import com.intellij.lang.properties.editor.inspections.*; +import com.intellij.lang.properties.editor.inspections.InspectedPropertyProblems; +import com.intellij.lang.properties.editor.inspections.ResourceBundleEditorInspection; +import com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -39,6 +40,7 @@ import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.psi.PsiFile; import com.intellij.util.ArrayUtil; import com.intellij.util.SmartList; +import com.intellij.util.containers.Queue; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -93,21 +95,21 @@ public class ResourceBundleEditorHighlighter implements BackgroundEditorHighligh final List files = myEditor.getResourceBundle().getPropertiesFiles(); final Project project = myEditor.getResourceBundle().getProject(); - final TreeVisitor nodeVisitor = - new TreeVisitor() { - @Override - public boolean visit(@NotNull TreeElementWrapper wrapper) { - final TreeElement treeElement = wrapper.getValue(); - if (!(treeElement instanceof ResourceBundlePropertyStructureViewElement)) return false; - ResourceBundlePropertyStructureViewElement node = (ResourceBundlePropertyStructureViewElement) treeElement; - final String key = node.getProperty().getKey(); - LOG.assertTrue(key != null); - SortedSet highlightTypes = new TreeSet<>(Comparator.comparing(t -> t.getSeverity(null))); - List> allDescriptors = - new SmartList<>(); - final IProperty[] properties = - files.stream().map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).toArray(IProperty[]::new); - if (properties.length == 0) return false; + final StructureViewModel model = myEditor.getStructureViewComponent().getTreeModel(); + final Queue queue = new Queue<>(1); + queue.addLast(model.getRoot()); + while (!queue.isEmpty()) { + final TreeElement treeElement = queue.pullFirst(); + if (treeElement instanceof ResourceBundlePropertyStructureViewElement) { + ResourceBundlePropertyStructureViewElement node = (ResourceBundlePropertyStructureViewElement)treeElement; + final String key = node.getProperty().getKey(); + LOG.assertTrue(key != null); + SortedSet highlightTypes = new TreeSet<>(Comparator.comparing(t -> t.getSeverity(null))); + List> allDescriptors = + new SmartList<>(); + final IProperty[] properties = + files.stream().map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).toArray(IProperty[]::new); + if (properties.length != 0) { for (InspectionVisitorWrapper v : visitors) { final ResourceBundleEditorProblemDescriptor[] problemDescriptors = v.getProblemVisitor().apply(properties); if (!ArrayUtil.isEmpty(problemDescriptors)) { @@ -122,12 +124,16 @@ public class ResourceBundleEditorHighlighter implements BackgroundEditorHighligh } } } - node.setInspectedPropertyProblems(allDescriptors.isEmpty() ? null : new InspectedPropertyProblems(allDescriptors.toArray(new Pair[allDescriptors.size()]), highlightTypes)); - return false; + node.setInspectedPropertyProblems(allDescriptors.isEmpty() + ? null + : new InspectedPropertyProblems(allDescriptors.toArray(new Pair[allDescriptors.size()]), + highlightTypes)); } - }; - myEditor.getStructureViewComponent().getTreeBuilder().accept(TreeElementWrapper.class, - nodeVisitor); + } + for (TreeElement element : treeElement.getChildren()) { + queue.addLast(element); + } + } } @Override