public interface AstContext
The enclosing context of a candidate node during an AstQuery traversal.
A AstContext is supplied to the contextual where/forEach
overloads so a predicate or consumer can take the surrounding structure of a node into
account (for example, "a VariableExpression that occurs inside a static method").
The information is valid only for the duration of the callback; do not retain it.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public List<ASTNode> |
ancestors()Returns the ancestors of the candidate node, nearest first (the immediate parent is the first element). |
|
public ClassNode |
enclosingClass()Returns the nearest enclosing class, or null if the candidate is not inside one. |
|
public MethodNode |
enclosingMethod()Returns the nearest enclosing method or constructor, or null if the candidate is not
inside one. |
|
public ASTNode |
parent()Returns the immediate parent of the candidate node, or null if the candidate is the
query root. |
Returns the ancestors of the candidate node, nearest first (the immediate parent is the first element). The candidate node itself is not included.
Returns the nearest enclosing class, or null if the candidate is not inside one.
null Returns the nearest enclosing method or constructor, or null if the candidate is not
inside one.
null Returns the immediate parent of the candidate node, or null if the candidate is the
query root.
null