public class VariableExpressionReplacer
extends CodeVisitorSupport
Tool for replacing VariableExpression instances in an AST by other VariableExpression instances. Regardless of a real change taking place in nested expressions, all considered expression (trees) will be replaced. This could be optimized to accelerate compilation.
Within
| Constructor and description |
|---|
VariableExpressionReplacer(Closure<Boolean> when, Closure<VariableExpression> replaceWith)Creates a replacer with the supplied predicate and replacement strategy. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public Closure<VariableExpression> |
getReplaceWith()Returns the closure that creates replacement variable expressions. |
|
public Closure<Boolean> |
getWhen()Returns the predicate that decides whether a variable expression should be replaced. |
|
public void |
replaceIn(ASTNode root)Replaces matching variable expressions within the supplied AST subtree. |
|
public void |
setReplaceWith(Closure<VariableExpression> replaceWith)Sets the closure that creates replacement variable expressions. |
|
public void |
setWhen(Closure<Boolean> when)Sets the predicate that decides whether a variable expression should be replaced. |
|
public void |
visitAssertStatement(AssertStatement statement)* Visits an AssertStatement, traversing the assertion condition and optional message expression. * *
|
|
public void |
visitBinaryExpression(BinaryExpression expression)It's the only Expression type in which replacing is considered. |
|
public void |
visitCaseStatement(CaseStatement statement)* Visits a CaseStatement, traversing the case expression and code block. * *
|
|
public void |
visitDoWhileLoop(DoWhileStatement loop)* Visits a DoWhileStatement, traversing the loop body before the boolean condition. * *
|
|
public void |
visitExpressionStatement(ExpressionStatement statement)* Visits an ExpressionStatement, traversing its contained expression. * *
|
|
public void |
visitForLoop(ForStatement forLoop)* Visits a ForStatement, traversing the collection expression and loop body. * *
|
|
public void |
visitIfElse(IfStatement ifElse)* Visits an IfStatement, traversing the condition, if-block, and optional else-block. * *
|
|
public void |
visitReturnStatement(ReturnStatement statement)* Visits a ReturnStatement, traversing its return expression. * *
|
|
public void |
visitSwitch(SwitchStatement statement)* Visits a SwitchStatement, traversing the switch expression, case statements, and default statement. * *
|
|
public void |
visitSynchronizedStatement(SynchronizedStatement statement)* Visits a SynchronizedStatement, traversing the synchronization expression and code block. * *
|
|
public void |
visitThrowStatement(ThrowStatement statement)* Visits a ThrowStatement, traversing the exception expression. * *
|
|
public void |
visitWhileLoop(WhileStatement loop)* Visits a WhileStatement, traversing the boolean condition and loop body. * *
|
Creates a replacer with the supplied predicate and replacement strategy.
when - decides whether a variable expression should be replacedreplaceWith - creates the replacement variable expressionReturns the closure that creates replacement variable expressions.
Returns the predicate that decides whether a variable expression should be replaced.
Replaces matching variable expressions within the supplied AST subtree.
root - the AST subtree to mutateSets the closure that creates replacement variable expressions.
replaceWith - the replacement closureSets the predicate that decides whether a variable expression should be replaced.
when - the replacement predicate* Visits an AssertStatement, traversing the assertion condition and optional message expression. * *
statement - the assert statementIt's the only Expression type in which replacing is considered. That's an abuse of the class, but I couldn't think of a better way.
* Visits a CaseStatement, traversing the case expression and code block. * *
statement - the case statement* Visits a DoWhileStatement, traversing the loop body before the boolean condition. * *
statement - the do-while loop statement* Visits an ExpressionStatement, traversing its contained expression. * *
statement - the expression statement* Visits a ForStatement, traversing the collection expression and loop body. * *
statement - the for loop statement* Visits an IfStatement, traversing the condition, if-block, and optional else-block. * *
statement - the if-else statement* Visits a ReturnStatement, traversing its return expression. * *
statement - the return statement* Visits a SwitchStatement, traversing the switch expression, case statements, and default statement. * *
statement - the switch statement* Visits a SynchronizedStatement, traversing the synchronization expression and code block. * *
statement - the synchronized statement* Visits a ThrowStatement, traversing the exception expression. * *
statement - the throw statement* Visits a WhileStatement, traversing the boolean condition and loop body. * *
statement - the while loop statementCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.