public class StatementReplacer
extends CodeVisitorSupport
Tool for replacing Statement objects in an AST by other Statement instances.
Within
| Constructor and description |
|---|
StatementReplacer(Closure<Boolean> when, Closure<Statement> replaceWith)Creates a replacer with the supplied predicate and replacement strategy. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public int |
getClosureLevel()Returns the current closure nesting depth. |
|
public Closure<Statement> |
getReplaceWith()Returns the closure that builds replacement statements. |
|
public Closure<Boolean> |
getWhen()Returns the predicate that decides whether a statement should be replaced. |
|
public void |
replaceIn(ASTNode root)Replaces matching statements within the supplied AST subtree. |
|
public void |
setClosureLevel(int closureLevel)Sets the current closure nesting depth. |
|
public void |
setReplaceWith(Closure<Statement> replaceWith)Sets the closure that builds replacement statements. |
|
public void |
setWhen(Closure<Boolean> when)Sets the predicate that decides whether a statement should be replaced. |
|
public void |
visitBlockStatement(BlockStatement block)* Visits a BlockStatement, traversing each contained statement in order. * *
|
|
public void |
visitClosureExpression(ClosureExpression expression)* Visits a ClosureExpression, traversing parameter initializers and the closure code block. * *
|
|
public void |
visitDoWhileLoop(DoWhileStatement loop)* Visits a DoWhileStatement, traversing the loop body before the boolean condition. * *
|
|
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 |
visitWhileLoop(WhileStatement loop)* Visits a WhileStatement, traversing the boolean condition and loop body. * *
|
Returns the current closure nesting depth.
Returns the closure that builds replacement statements.
Returns the predicate that decides whether a statement should be replaced.
Replaces matching statements within the supplied AST subtree.
root - the AST subtree to mutateSets the current closure nesting depth.
closureLevel - the closure nesting depthSets the closure that builds replacement statements.
replaceWith - the replacement closureSets the predicate that decides whether a statement should be replaced.
when - the replacement predicate* Visits a BlockStatement, traversing each contained statement in order. * *
block - the block statement to visit, may contain multiple statements
** Visits a ClosureExpression, traversing parameter initializers and the closure code block. * *
expression - the closure expression* Visits a DoWhileStatement, traversing the loop body before the boolean condition. * *
statement - the do-while loop 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 WhileStatement, traversing the boolean condition and loop body. * *
statement - the while loop statementCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.