Package: org.codehaus.groovy.ast.query

## [Java] 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

- - ### Methods Summary

    Methods
    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.

- - ### Method Detail

    - #### public List<ASTNode> 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

    - #### public ClassNode enclosingClass()

      Returns the nearest enclosing class, or `null` if the candidate is not inside one.

      Returns:
        the enclosing ClassNode or `null`

    - #### public MethodNode enclosingMethod()

      Returns the nearest enclosing method or constructor, or `null` if the candidate is not inside one.

      Returns:
        the enclosing MethodNode or `null`

    - #### public ASTNode parent()

      Returns the immediate parent of the candidate node, or `null` if the candidate is the query root.

      Returns:
        the parent node or `null`