Package org.codehaus.groovy.ast.query
Interface AstContext
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.
- Since:
- 6.0.0
-
Method Summary
Modifier and TypeMethodDescriptionReturns the ancestors of the candidate node, nearest first (the immediate parent is the first element).Returns the nearest enclosing class, ornullif the candidate is not inside one.Returns the nearest enclosing method or constructor, ornullif the candidate is not inside one.parent()Returns the immediate parent of the candidate node, ornullif the candidate is the query root.
-
Method Details
-
parent
ASTNode parent()Returns the immediate parent of the candidate node, ornullif the candidate is the query root.- Returns:
- the parent node or
null
-
ancestors
Returns the ancestors of the candidate node, nearest first (the immediate parent is the first element). The candidate node itself is not included.- Returns:
- an immutable snapshot of the ancestor chain
-
enclosingMethod
MethodNode enclosingMethod()Returns the nearest enclosing method or constructor, ornullif the candidate is not inside one.- Returns:
- the enclosing
MethodNodeornull
-
enclosingClass
ClassNode enclosingClass()Returns the nearest enclosing class, ornullif the candidate is not inside one.- Returns:
- the enclosing
ClassNodeornull
-