mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add method to PsiTreeUtil
This commit is contained in:
+2
-7
@@ -63,13 +63,8 @@ public class JavaMoveLeftRightHandler extends MoveElementLeftRightHandler {
|
||||
return ((PsiTypeParameterList)element).getTypeParameters();
|
||||
}
|
||||
else if (element instanceof PsiModifierList) {
|
||||
final List<PsiElement> result = ContainerUtil.newSmartList();
|
||||
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiKeyword || child instanceof PsiAnnotation) {
|
||||
result.add(child);
|
||||
}
|
||||
}
|
||||
return result.toArray(PsiElement.EMPTY_ARRAY);
|
||||
final List<PsiElement> elements = PsiTreeUtil.getChildrenOfAnyType(element, PsiKeyword.class, PsiAnnotation.class);
|
||||
return elements.toArray(PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -346,6 +346,21 @@ public class PsiTreeUtil {
|
||||
return result == null ? null : ArrayUtil.toObjectArray(result, aClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends PsiElement> List<T> getChildrenOfAnyType(@Nullable PsiElement element, @NotNull Class<? extends T>... classes) {
|
||||
if (element == null) return ContainerUtil.emptyList();
|
||||
|
||||
List<T> result = null;
|
||||
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (instanceOf(child, classes)) {
|
||||
if (result == null) result = ContainerUtil.newSmartList();
|
||||
//noinspection unchecked
|
||||
result.add((T)child);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends PsiElement> List<T> getChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) {
|
||||
if (element == null) return Collections.emptyList();
|
||||
|
||||
Reference in New Issue
Block a user