public class PsiTreeUtil
extends java.lang.Object
Constructor and Description |
---|
PsiTreeUtil() |
Modifier and Type | Method and Description |
---|---|
static <T extends PsiElement> |
childIterator(PsiElement element,
java.lang.Class<T> aClass)
Deprecated.
|
static PsiElement [] |
collectElements(PsiElement element,
PsiElementFilter filter) |
static <T extends PsiElement> |
collectElementsOfType(PsiElement element,
java.lang.Class<T>... classes) |
static <T extends PsiElement> |
collectParents(PsiElement element,
java.lang.Class<? extends T> parent,
boolean includeMyself,
java.util.function.Predicate<? super PsiElement> stopCondition) |
static int |
countChildrenOfType(PsiElement element,
java.lang.Class<? extends PsiElement> clazz) |
static PsiElement [] |
filterAncestors(PsiElement [] elements) |
static <T extends PsiElement> |
findChildOfAnyType(PsiElement element,
boolean strict,
java.lang.Class<? extends T>... classes)
Recursive (depth first) search for first element of any of given
classes . |
static <T extends PsiElement> |
findChildOfAnyType(PsiElement element,
java.lang.Class<? extends T>... classes)
|
static <T extends PsiElement> |
findChildOfType(PsiElement element,
java.lang.Class<T> aClass)
|
static <T extends PsiElement> |
findChildOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict)
|
static <T extends PsiElement> |
findChildOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict,
java.lang.Class<? extends PsiElement> stopAt)
Recursive (depth first) search for first element of a given class.
|
static <T extends PsiElement> |
findChildrenOfAnyType(PsiElement element,
boolean strict,
java.lang.Class<? extends T>... classes)
Recursive (depth first) search for all elements of any of given
classes . |
static <T extends PsiElement> |
findChildrenOfAnyType(PsiElement element,
java.lang.Class<? extends T>... classes)
|
static <T extends PsiElement> |
findChildrenOfType(PsiElement element,
java.lang.Class<? extends T> aClass)
|
static PsiElement |
findCommonContext(java.util.Collection<? extends PsiElement> elements) |
static PsiElement |
findCommonContext(PsiElement element1,
PsiElement element2) |
static PsiElement |
findCommonParent(java.util.List<? extends PsiElement> elements) |
static PsiElement |
findCommonParent(PsiElement... elements) |
static PsiElement |
findCommonParent(PsiElement element1,
PsiElement element2) |
static <T extends PsiElement> |
findElementOfClassAtOffset(PsiFile file,
int offset,
java.lang.Class<T> clazz,
boolean strictStart) |
static <T extends PsiElement> |
findElementOfClassAtOffsetWithStopSet(PsiFile file,
int offset,
java.lang.Class<T> clazz,
boolean strictStart,
java.lang.Class<? extends PsiElement>... stopAt) |
static <T extends PsiElement> |
findElementOfClassAtRange(PsiFile file,
int startOffset,
int endOffset,
java.lang.Class<T> clazz) |
static PsiElement |
findFirstContext(PsiElement element,
boolean strict,
Condition<? super PsiElement> condition) |
static PsiElement |
findFirstParent(PsiElement element,
boolean strict,
Condition<? super PsiElement> condition) |
static PsiElement |
findFirstParent(PsiElement element,
Condition<? super PsiElement> condition) |
static PsiElement |
findPrevParent(PsiElement ancestor,
PsiElement descendant) |
static PsiElement |
findSiblingBackward(PsiElement element,
IElementType elementType,
boolean strict,
Consumer<? super PsiElement> consumer) |
static PsiElement |
findSiblingBackward(PsiElement element,
IElementType elementType,
Consumer<? super PsiElement> consumer) |
static PsiElement |
findSiblingForward(PsiElement element,
IElementType elementType,
boolean strict,
Consumer<? super PsiElement> consumer) |
static PsiElement |
findSiblingForward(PsiElement element,
IElementType elementType,
Consumer<? super PsiElement> consumer) |
static PsiElement |
firstChild(PsiElement element) |
static <T extends PsiElement> |
getChildOfAnyType(PsiElement element,
java.lang.Class<? extends T>... classes)
Returns a direct child of the specified element having any of the specified classes.
|
static <T extends PsiElement> |
getChildOfType(PsiElement element,
java.lang.Class<T> aClass)
Non-recursive search for an element of type T amongst given
element children. |
static <T extends PsiElement> |
getChildrenOfAnyType(PsiElement element,
java.lang.Class<? extends T>... classes) |
static <T extends PsiElement> |
getChildrenOfType(PsiElement element,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getChildrenOfTypeAsList(PsiElement element,
java.lang.Class<? extends T> aClass) |
static <T extends PsiElement> |
getContextOfType(PsiElement element,
boolean strict,
java.lang.Class<? extends T>... classes) |
static <T extends PsiElement> |
getContextOfType(PsiElement element,
java.lang.Class<? extends T>... classes) |
static <T extends PsiElement> |
getContextOfType(PsiElement element,
java.lang.Class<? extends T> aClass,
boolean strict) |
static <T extends PsiElement> |
getContextOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict,
java.lang.Class<? extends PsiElement>... stopAt) |
static PsiElement |
getDeepestFirst(PsiElement elt) |
static PsiElement |
getDeepestLast(PsiElement elt) |
static PsiElement |
getDeepestVisibleFirst(PsiElement psiElement) |
static PsiElement |
getDeepestVisibleLast(PsiElement psiElement) |
static int |
getDepth(PsiElement element,
PsiElement topLevel) |
static java.util.List<PsiElement> |
getElementsOfRange(PsiElement start,
PsiElement end) |
static java.util.List<PsiElement> |
getInjectedElements(OuterLanguageElement outerLanguageElement) |
static <T extends PsiElement> |
getNextSiblingOfType(PsiElement sibling,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getNonStrictParentOfType(PsiElement element,
java.lang.Class<? extends T>... classes) |
static <T extends PsiElement> |
getParentOfType(PsiElement element,
java.lang.Class<? extends T>... classes) |
static <T extends PsiElement> |
getParentOfType(PsiElement element,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getParentOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict) |
static <T extends PsiElement> |
getParentOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict,
java.lang.Class<? extends PsiElement>... stopAt) |
static <T extends PsiElement> |
getParentOfType(PsiElement element,
java.lang.Class<T> aClass,
boolean strict,
int minStartOffset) |
static <T extends PsiElement> |
getPrevSiblingOfType(PsiElement sibling,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getRequiredChildOfType(PsiElement element,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getStubChildOfType(PsiElement element,
java.lang.Class<T> aClass) |
static <T extends PsiElement> |
getStubChildrenOfTypeAsList(PsiElement element,
java.lang.Class<? extends T> aClass) |
static PsiElement |
getStubOrPsiParent(PsiElement element) |
static <E extends PsiElement> |
getStubOrPsiParentOfType(PsiElement element,
java.lang.Class<E> parentClass) |
static <T extends PsiElement> |
getTopmostParentOfType(PsiElement element,
java.lang.Class<T> aClass) |
static boolean |
hasErrorElements(PsiElement element) |
static boolean |
instanceOf(java.lang.Object object,
java.lang.Class<?>... classes) |
static boolean |
isAncestor(PsiElement ancestor,
PsiElement element,
boolean strict)
Checks whether one element in the psi tree is under another.
|
static boolean |
isContextAncestor(PsiElement ancestor,
PsiElement element,
boolean strict)
Checks whether one element in the psi tree is under another in a
PsiElement.getContext() hierarchy. |
static PsiElement |
lastChild(PsiElement element) |
static void |
mark(PsiElement element,
java.lang.Object marker) |
static PsiElement |
nextLeaf(PsiElement current) |
static PsiElement |
nextLeaf(PsiElement element,
boolean skipEmptyElements) |
static PsiElement |
nextVisibleLeaf(PsiElement element) |
static PsiElement |
prevLeaf(PsiElement current) |
static PsiElement |
prevLeaf(PsiElement element,
boolean skipEmptyElements) |
static PsiElement |
prevVisibleLeaf(PsiElement element) |
static boolean |
processElements(PsiElementProcessor processor,
PsiElement... elements) |
static boolean |
processElements(PsiElement element,
PsiElementProcessor processor) |
static PsiElement |
releaseMark(PsiElement root,
java.lang.Object marker) |
static PsiElement |
skipParentsOfType(PsiElement element,
java.lang.Class<? extends PsiElement>... parentClasses) |
static PsiElement |
skipSiblingsBackward(PsiElement element,
java.lang.Class<? extends PsiElement>... elementClasses) |
static PsiElement |
skipSiblingsForward(PsiElement element,
java.lang.Class<? extends PsiElement>... elementClasses) |
static PsiElement |
skipWhitespacesAndCommentsBackward(PsiElement element) |
static PsiElement |
skipWhitespacesAndCommentsForward(PsiElement element) |
static PsiElement |
skipWhitespacesBackward(PsiElement element) |
static PsiElement |
skipWhitespacesForward(PsiElement element) |
static boolean |
treeWalkUp(PsiElement entrance,
PsiElement maxScope,
PairProcessor<? super PsiElement,? super PsiElement> eachScopeAndLastParent) |
static boolean |
treeWalkUp(PsiScopeProcessor processor,
PsiElement entrance,
PsiElement maxScope,
ResolveState state) |
public static boolean isAncestor(PsiElement ancestor, PsiElement element, boolean strict)
ancestor
- parent candidate. false
will be returned if ancestor is null.element
- child candidatestrict
- whether return true if ancestor and parent are the same.public static boolean isContextAncestor(PsiElement ancestor, PsiElement element, boolean strict)
PsiElement.getContext()
hierarchy.ancestor
- parent candidate. false
will be returned if ancestor is null.element
- child candidatestrict
- whether return true if ancestor and parent are the same.public static PsiElement findCommonParent(java.util.List<? extends PsiElement> elements)
public static PsiElement findCommonParent(PsiElement... elements)
public static PsiElement findCommonParent(PsiElement element1, PsiElement element2)
public static int getDepth(PsiElement element, PsiElement topLevel)
public static PsiElement findCommonContext(java.util.Collection<? extends PsiElement> elements)
public static PsiElement findCommonContext(PsiElement element1, PsiElement element2)
public static <T extends PsiElement> T findChildOfType(PsiElement element, java.lang.Class<T> aClass)
public static <T extends PsiElement> T findChildOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict)
public static <T extends PsiElement> T findChildOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict, java.lang.Class<? extends PsiElement> stopAt)
T
- type to cast found element toelement
- a PSI element to start search fromstrict
- if false the element
is also included in the searchaClass
- element type to search forstopAt
- element type to abort the search atnull
if nothing found@SafeVarargs public static <T extends PsiElement> T findChildOfAnyType(PsiElement element, java.lang.Class<? extends T>... classes)
@SafeVarargs public static <T extends PsiElement> T findChildOfAnyType(PsiElement element, boolean strict, java.lang.Class<? extends T>... classes)
classes
.T
- type to cast found element to.element
- a PSI element to start search from.strict
- if false the element
is also included in the search.classes
- element types to search for.null
if nothing found.public static <T extends PsiElement> java.util.Collection<T> findChildrenOfType(PsiElement element, java.lang.Class<? extends T> aClass)
@SafeVarargs public static <T extends PsiElement> java.util.Collection<T> findChildrenOfAnyType(PsiElement element, java.lang.Class<? extends T>... classes)
@SafeVarargs public static <T extends PsiElement> java.util.Collection<T> findChildrenOfAnyType(PsiElement element, boolean strict, java.lang.Class<? extends T>... classes)
classes
.T
- type to cast found elements to.element
- a PSI element to start search from.strict
- if false the element
is also included in the search.classes
- element types to search for.Collection<T>
of all found elements, or empty List<T>
if nothing found.public static <T extends PsiElement> T getChildOfType(PsiElement element, java.lang.Class<T> aClass)
element
children.T
- element type to search for.element
- a PSI element to start search from.aClass
- element type to search for.public static PsiElement findFirstParent(PsiElement element, Condition<? super PsiElement> condition)
public static PsiElement findFirstParent(PsiElement element, boolean strict, Condition<? super PsiElement> condition)
public static PsiElement findFirstContext(PsiElement element, boolean strict, Condition<? super PsiElement> condition)
public static <T extends PsiElement> T getRequiredChildOfType(PsiElement element, java.lang.Class<T> aClass)
public static int countChildrenOfType(PsiElement element, java.lang.Class<? extends PsiElement> clazz)
public static <T extends PsiElement> T [] getChildrenOfType(PsiElement element, java.lang.Class<T> aClass)
@SafeVarargs public static <T extends PsiElement> java.util.List<T> getChildrenOfAnyType(PsiElement element, java.lang.Class<? extends T>... classes)
public static <T extends PsiElement> java.util.List<T> getChildrenOfTypeAsList(PsiElement element, java.lang.Class<? extends T> aClass)
public static java.util.List<PsiElement> getElementsOfRange(PsiElement start, PsiElement end)
public static <T extends PsiElement> T getStubChildOfType(PsiElement element, java.lang.Class<T> aClass)
public static <T extends PsiElement> java.util.List<T> getStubChildrenOfTypeAsList(PsiElement element, java.lang.Class<? extends T> aClass)
public static boolean instanceOf(java.lang.Object object, java.lang.Class<?>... classes)
@SafeVarargs public static <T extends PsiElement> T getChildOfAnyType(PsiElement element, java.lang.Class<? extends T>... classes)
element
- the element to get the child for.classes
- the array of classes.public static <T extends PsiElement> T getNextSiblingOfType(PsiElement sibling, java.lang.Class<T> aClass)
public static <T extends PsiElement> T getPrevSiblingOfType(PsiElement sibling, java.lang.Class<T> aClass)
public static <T extends PsiElement> T getTopmostParentOfType(PsiElement element, java.lang.Class<T> aClass)
public static <T extends PsiElement> T getParentOfType(PsiElement element, java.lang.Class<T> aClass)
public static PsiElement getStubOrPsiParent(PsiElement element)
public static <E extends PsiElement> E getStubOrPsiParentOfType(PsiElement element, java.lang.Class<E> parentClass)
@SafeVarargs public static <T extends PsiElement> T getContextOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict, java.lang.Class<? extends PsiElement>... stopAt)
public static <T extends PsiElement> T getContextOfType(PsiElement element, java.lang.Class<? extends T> aClass, boolean strict)
@SafeVarargs public static <T extends PsiElement> T getContextOfType(PsiElement element, java.lang.Class<? extends T>... classes)
@SafeVarargs public static <T extends PsiElement> T getContextOfType(PsiElement element, boolean strict, java.lang.Class<? extends T>... classes)
public static <T extends PsiElement> T getParentOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict)
public static <T extends PsiElement> T getParentOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict, int minStartOffset)
@SafeVarargs public static <T extends PsiElement> T getParentOfType(PsiElement element, java.lang.Class<T> aClass, boolean strict, java.lang.Class<? extends PsiElement>... stopAt)
public static <T extends PsiElement> java.util.List<T> collectParents(PsiElement element, java.lang.Class<? extends T> parent, boolean includeMyself, java.util.function.Predicate<? super PsiElement> stopCondition)
public static PsiElement findSiblingForward(PsiElement element, IElementType elementType, Consumer<? super PsiElement> consumer)
public static PsiElement findSiblingForward(PsiElement element, IElementType elementType, boolean strict, Consumer<? super PsiElement> consumer)
public static PsiElement findSiblingBackward(PsiElement element, IElementType elementType, Consumer<? super PsiElement> consumer)
public static PsiElement findSiblingBackward(PsiElement element, IElementType elementType, boolean strict, Consumer<? super PsiElement> consumer)
@SafeVarargs public static PsiElement skipSiblingsForward(PsiElement element, java.lang.Class<? extends PsiElement>... elementClasses)
public static PsiElement skipWhitespacesForward(PsiElement element)
public static PsiElement skipWhitespacesAndCommentsForward(PsiElement element)
@SafeVarargs public static PsiElement skipSiblingsBackward(PsiElement element, java.lang.Class<? extends PsiElement>... elementClasses)
public static PsiElement skipWhitespacesBackward(PsiElement element)
public static PsiElement skipWhitespacesAndCommentsBackward(PsiElement element)
@SafeVarargs public static PsiElement skipParentsOfType(PsiElement element, java.lang.Class<? extends PsiElement>... parentClasses)
@SafeVarargs public static <T extends PsiElement> T getParentOfType(PsiElement element, java.lang.Class<? extends T>... classes)
@SafeVarargs public static <T extends PsiElement> T getNonStrictParentOfType(PsiElement element, java.lang.Class<? extends T>... classes)
public static PsiElement [] collectElements(PsiElement element, PsiElementFilter filter)
@SafeVarargs public static <T extends PsiElement> java.util.Collection<T> collectElementsOfType(PsiElement element, java.lang.Class<T>... classes)
public static boolean processElements(PsiElement element, PsiElementProcessor processor)
public static boolean processElements(PsiElementProcessor processor, PsiElement... elements)
public static void mark(PsiElement element, java.lang.Object marker)
public static PsiElement releaseMark(PsiElement root, java.lang.Object marker)
public static <T extends PsiElement> T findElementOfClassAtOffset(PsiFile file, int offset, java.lang.Class<T> clazz, boolean strictStart)
@SafeVarargs public static <T extends PsiElement> T findElementOfClassAtOffsetWithStopSet(PsiFile file, int offset, java.lang.Class<T> clazz, boolean strictStart, java.lang.Class<? extends PsiElement>... stopAt)
public static <T extends PsiElement> T findElementOfClassAtRange(PsiFile file, int startOffset, int endOffset, java.lang.Class<T> clazz)
public static PsiElement getDeepestFirst(PsiElement elt)
public static PsiElement getDeepestLast(PsiElement elt)
public static PsiElement prevLeaf(PsiElement current)
public static PsiElement nextLeaf(PsiElement current)
public static PsiElement lastChild(PsiElement element)
public static PsiElement firstChild(PsiElement element)
public static PsiElement prevLeaf(PsiElement element, boolean skipEmptyElements)
public static PsiElement prevVisibleLeaf(PsiElement element)
public static PsiElement nextVisibleLeaf(PsiElement element)
public static PsiElement nextLeaf(PsiElement element, boolean skipEmptyElements)
public static boolean hasErrorElements(PsiElement element)
public static PsiElement [] filterAncestors(PsiElement [] elements)
public static boolean treeWalkUp(PsiScopeProcessor processor, PsiElement entrance, PsiElement maxScope, ResolveState state)
public static boolean treeWalkUp(PsiElement entrance, PsiElement maxScope, PairProcessor<? super PsiElement,? super PsiElement> eachScopeAndLastParent)
public static PsiElement findPrevParent(PsiElement ancestor, PsiElement descendant)
public static java.util.List<PsiElement> getInjectedElements(OuterLanguageElement outerLanguageElement)
public static PsiElement getDeepestVisibleFirst(PsiElement psiElement)
public static PsiElement getDeepestVisibleLast(PsiElement psiElement)
@Deprecated public static <T extends PsiElement> java.util.Iterator<T> childIterator(PsiElement element, java.lang.Class<T> aClass)
SyntaxTraverser.psiTraverser()