diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java index 0ac05c043156..ff6393c01359 100644 --- a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class PsiTreeUtil { @@ -465,6 +466,25 @@ public class PsiTreeUtil { return processor.toArray(); } + @NotNull + public static Collection collectElementsOfType(@Nullable PsiElement element, final @NotNull Class ... classes) { + PsiElementProcessor.CollectFilteredElements processor = new PsiElementProcessor.CollectFilteredElements(new PsiElementFilter() { + + @Override + public boolean isAccepted(PsiElement element) { + for (Class clazz: classes) { + if (clazz.isInstance(element)) { + return true; + } + } + + return false; + } + }); + processElements(element, processor); + return processor.getCollection(); + } + public static boolean processElements(@Nullable PsiElement element, @NotNull PsiElementProcessor processor) { if (element == null) return true; if (!processor.execute(element)) return false; @@ -740,5 +760,5 @@ public class PsiTreeUtil { } throw new AssertionError(descendant + " is not a descendant of " + ancestor); } - + } diff --git a/platform/util/src/com/intellij/util/containers/CollectionFactory.java b/platform/util/src/com/intellij/util/containers/CollectionFactory.java index f182b4ab5cb9..66c858f4b8e9 100644 --- a/platform/util/src/com/intellij/util/containers/CollectionFactory.java +++ b/platform/util/src/com/intellij/util/containers/CollectionFactory.java @@ -15,6 +15,9 @@ */ package com.intellij.util.containers; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import gnu.trove.THashMap; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -50,7 +53,7 @@ public class CollectionFactory { } public static ArrayList arrayList() { - return new ArrayList(); + return Lists.newArrayList(); } public static ArrayList arrayList(T... elements) { @@ -80,19 +83,19 @@ public class CollectionFactory { return new Stack(); } - public static HashSet hashSet() { - return new HashSet(); + public static Set hashSet() { + return Sets.newHashSet(); } - public static HashMap hashMap() { - return new HashMap(); + public static Map hashMap() { + return Maps.newHashMap(); } public static LinkedHashMap linkedMap() { - return new LinkedHashMap(); + return Maps.newLinkedHashMap(); } public static LinkedHashSet linkedHashSet() { - return new LinkedHashSet(); + return Sets.newLinkedHashSet(); } } diff --git a/platform/util/util.iml b/platform/util/util.iml index 8006db04d27a..d74a166efbe6 100644 --- a/platform/util/util.iml +++ b/platform/util/util.iml @@ -17,6 +17,7 @@ + diff --git a/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlTagTreeElement.java b/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlTagTreeElement.java index b14f957f07db..d9430f6a9d8c 100644 --- a/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlTagTreeElement.java +++ b/xml/impl/src/com/intellij/ide/structureView/impl/xml/XmlTagTreeElement.java @@ -20,6 +20,7 @@ import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -86,7 +87,8 @@ public class XmlTagTreeElement extends AbstractXmlTagTreeElement{ return buffer.toString(); } - private static String toCanonicalForm(String id) { + @Nullable + private static String toCanonicalForm(@Nullable String id) { if (id != null) { id = id.trim(); if (id.length() == 0) id = null;