public abstract class ContextualClassCodeVisitor
extends ClassCodeVisitorSupport
A class code visitor which is capable of remembering the context of the current visit. This makes it easier for subclasses to perform context-dependent transformations, where for example it is necessary to check the parent nodes of an AST node before performing some operations.
| Constructor and description |
|---|
ContextualClassCodeVisitor()Creates a visitor with an initial root context. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public TreeContext |
getLastContext()Returns the most recently popped traversal context. |
|
public TreeContext |
getTreeContext()Returns the current traversal context. |
|
public List<TreeContext> |
getTreePath()Returns the current traversal path, starting with the last completed context. |
|
public static List<ASTNodePredicate> |
matchByClass(Class<ASTNode> classes)Creates class-based predicates for the supplied AST node classes. |
|
public List<TreeContext> |
pathMatches(List<ASTNodePredicate> predicates)Returns the current path when all supplied predicates match successive parents. |
|
public List<TreeContext> |
pathUpTo(ASTNodePredicate predicate)Returns the path up to the first node matching the supplied predicate. |
|
public List<TreeContext> |
pathUpTo(Class<ASTNode> node)Returns the path up to the first node whose class matches node. |
|
public List<TreeContext> |
pathUpTo(Class<ASTNode> node, ASTNodePredicate predicate)Returns the path up to the first node that matches the supplied class and predicate. |
|
protected TreeContext |
popContext()Pops the current traversal context. |
|
protected void |
pushContext(TreeContext ctx)Pushes an explicit traversal context. |
|
protected void |
pushContext(ASTNode node)Pushes a child context for the supplied AST node. |
|
public void |
visitArrayExpression(ArrayExpression expression)Visits an array expression while tracking traversal context. |
|
public void |
visitAssertStatement(AssertStatement statement)Visits an assert statement while tracking traversal context. |
|
public void |
visitAttributeExpression(AttributeExpression expression)Visits an attribute expression while tracking traversal context. |
|
public void |
visitBinaryExpression(BinaryExpression expression)Visits a binary expression while tracking traversal context. |
|
public void |
visitBitwiseNegationExpression(BitwiseNegationExpression expression)Visits a bitwise-negation expression while tracking traversal context. |
|
public void |
visitBlockStatement(BlockStatement block)Visits a block statement while tracking traversal context. |
|
public void |
visitBooleanExpression(BooleanExpression expression)Visits a boolean expression while tracking traversal context. |
|
public void |
visitBreakStatement(BreakStatement statement)Visits a break statement while tracking traversal context. |
|
public void |
visitBytecodeExpression(BytecodeExpression cle)Visits a bytecode expression while tracking traversal context. |
|
public void |
visitCaseStatement(CaseStatement statement)Visits a case statement while tracking traversal context. |
|
public void |
visitCastExpression(CastExpression expression)Visits a cast expression while tracking traversal context. |
|
public void |
visitCatchStatement(CatchStatement statement)Visits a catch statement while tracking traversal context. |
|
public void |
visitClass(ClassNode node)Visits a class node while tracking traversal context. |
|
public void |
visitClassExpression(ClassExpression expression)Visits a class expression while tracking traversal context. |
|
public void |
visitClosureExpression(ClosureExpression expression)Visits a closure expression while tracking traversal context. |
|
public void |
visitClosureListExpression(ClosureListExpression cle)Visits a closure-list expression while tracking traversal context. |
|
public void |
visitConstantExpression(ConstantExpression expression)Visits a constant expression while tracking traversal context. |
|
public void |
visitConstructorCallExpression(ConstructorCallExpression call)Visits a constructor call expression while tracking traversal context. |
|
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor)Visits a constructor or method while tracking traversal context. |
|
public void |
visitContinueStatement(ContinueStatement statement)Visits a continue statement while tracking traversal context. |
|
public void |
visitDoWhileLoop(DoWhileStatement loop)Visits a do-while loop while tracking traversal context. |
|
public void |
visitEmptyStatement(EmptyStatement statement)Visits an empty statement while tracking traversal context. |
|
public void |
visitExpressionStatement(ExpressionStatement statement)Visits an expression statement while tracking traversal context. |
|
public void |
visitField(FieldNode node)Visits a field node while tracking traversal context. |
|
public void |
visitFieldExpression(FieldExpression expression)Visits a field expression while tracking traversal context. |
|
public void |
visitForLoop(ForStatement forLoop)Visits a for loop while tracking traversal context. |
|
public void |
visitGStringExpression(GStringExpression expression)Visits a GString expression while tracking traversal context. |
|
public void |
visitIfElse(IfStatement ifElse)Visits an if/else statement while tracking traversal context. |
|
public void |
visitImports(ModuleNode node)Visits module imports while tracking traversal context. |
|
public void |
visitListExpression(ListExpression expression)Visits a list expression while tracking traversal context. |
|
public void |
visitMapEntryExpression(MapEntryExpression expression)Visits a map-entry expression while tracking traversal context. |
|
public void |
visitMapExpression(MapExpression expression)Visits a map expression while tracking traversal context. |
|
public void |
visitMethodCallExpression(MethodCallExpression call)Visits a method call expression while tracking traversal context. |
|
public void |
visitMethodPointerExpression(MethodPointerExpression expression)Visits a method-pointer expression while tracking traversal context. |
|
public void |
visitNotExpression(NotExpression expression)Visits a not expression while tracking traversal context. |
|
public void |
visitPackage(PackageNode node)Visits a package node while tracking traversal context. |
|
public void |
visitPostfixExpression(PostfixExpression expression)Visits a postfix expression while tracking traversal context. |
|
public void |
visitPrefixExpression(PrefixExpression expression)Visits a prefix expression while tracking traversal context. |
|
public void |
visitProperty(PropertyNode node)Visits a property node while tracking traversal context. |
|
public void |
visitPropertyExpression(PropertyExpression expression)Visits a property expression while tracking traversal context. |
|
public void |
visitRangeExpression(RangeExpression expression)Visits a range expression while tracking traversal context. |
|
public void |
visitReturnStatement(ReturnStatement statement)Visits a return statement while tracking traversal context. |
|
public void |
visitShortTernaryExpression(ElvisOperatorExpression expression)Visits an Elvis expression while tracking traversal context. |
|
public void |
visitSpreadExpression(SpreadExpression expression)Visits a spread expression while tracking traversal context. |
|
public void |
visitSpreadMapExpression(SpreadMapExpression expression)Visits a spread-map expression while tracking traversal context. |
|
public void |
visitStaticMethodCallExpression(StaticMethodCallExpression call)Visits a static method call expression while tracking traversal context. |
|
public void |
visitSwitch(SwitchStatement statement)Visits a switch statement while tracking traversal context. |
|
public void |
visitSynchronizedStatement(SynchronizedStatement statement)Visits a synchronized statement while tracking traversal context. |
|
public void |
visitTernaryExpression(TernaryExpression expression)Visits a ternary expression while tracking traversal context. |
|
public void |
visitThrowStatement(ThrowStatement statement)Visits a throw statement while tracking traversal context. |
|
public void |
visitTryCatchFinally(TryCatchStatement statement)Visits a try/catch/finally statement while tracking traversal context. |
|
public void |
visitTupleExpression(TupleExpression expression)Visits a tuple expression while tracking traversal context. |
|
public void |
visitUnaryMinusExpression(UnaryMinusExpression expression)Visits a unary-minus expression while tracking traversal context. |
|
public void |
visitUnaryPlusExpression(UnaryPlusExpression expression)Visits a unary-plus expression while tracking traversal context. |
|
public void |
visitVariableExpression(VariableExpression expression)Visits a variable expression while tracking traversal context. |
|
public void |
visitWhileLoop(WhileStatement loop)Visits a while loop while tracking traversal context. |
Creates a visitor with an initial root context.
Returns the most recently popped traversal context.
Returns the current traversal context.
nullReturns the current traversal path, starting with the last completed context.
Creates class-based predicates for the supplied AST node classes.
classes - the classes to matchReturns the current path when all supplied predicates match successive parents.
predicates - the predicates to match against the pathReturns the path up to the first node matching the supplied predicate.
predicate - the predicate that terminates the path Returns the path up to the first node whose class matches node.
node - the node class that terminates the pathReturns the path up to the first node that matches the supplied class and predicate.
node - the node class that terminates the path, or nullpredicate - the predicate that terminates the path, or nullPops the current traversal context.
Pushes an explicit traversal context.
ctx - the context to pushPushes a child context for the supplied AST node.
node - the node to enterVisits an array expression while tracking traversal context.
Visits an assert statement while tracking traversal context.
Visits an attribute expression while tracking traversal context.
Visits a binary expression while tracking traversal context.
Visits a bitwise-negation expression while tracking traversal context.
Visits a block statement while tracking traversal context.
Visits a boolean expression while tracking traversal context.
Visits a break statement while tracking traversal context.
Visits a bytecode expression while tracking traversal context.
Visits a case statement while tracking traversal context.
Visits a cast expression while tracking traversal context.
Visits a catch statement while tracking traversal context.
Visits a class node while tracking traversal context.
Visits a class expression while tracking traversal context.
Visits a closure expression while tracking traversal context.
Visits a closure-list expression while tracking traversal context.
Visits a constant expression while tracking traversal context.
Visits a constructor call expression while tracking traversal context.
Visits a constructor or method while tracking traversal context.
Visits a continue statement while tracking traversal context.
Visits a do-while loop while tracking traversal context.
Visits an empty statement while tracking traversal context.
Visits an expression statement while tracking traversal context.
Visits a field node while tracking traversal context.
Visits a field expression while tracking traversal context.
Visits a for loop while tracking traversal context.
Visits a GString expression while tracking traversal context.
Visits an if/else statement while tracking traversal context.
Visits module imports while tracking traversal context.
Visits a list expression while tracking traversal context.
Visits a map-entry expression while tracking traversal context.
Visits a map expression while tracking traversal context.
Visits a method call expression while tracking traversal context.
Visits a method-pointer expression while tracking traversal context.
Visits a not expression while tracking traversal context.
Visits a package node while tracking traversal context.
Visits a postfix expression while tracking traversal context.
Visits a prefix expression while tracking traversal context.
Visits a property node while tracking traversal context.
Visits a property expression while tracking traversal context.
Visits a range expression while tracking traversal context.
Visits a return statement while tracking traversal context.
Visits an Elvis expression while tracking traversal context.
Visits a spread expression while tracking traversal context.
Visits a spread-map expression while tracking traversal context.
Visits a static method call expression while tracking traversal context.
Visits a switch statement while tracking traversal context.
Visits a synchronized statement while tracking traversal context.
Visits a ternary expression while tracking traversal context.
Visits a throw statement while tracking traversal context.
Visits a try/catch/finally statement while tracking traversal context.
Visits a tuple expression while tracking traversal context.
Visits a unary-minus expression while tracking traversal context.
Visits a unary-plus expression while tracking traversal context.
Visits a variable expression while tracking traversal context.
Visits a while loop while tracking traversal context.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.