Class VariableExpressionReplacer
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.transform.tailrec.VariableExpressionReplacer
- All Implemented Interfaces:
GroovyCodeVisitor
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 @TailRecursive it is used - to swap the access of method args with the access to iteration variables - to swap the access of iteration variables with the access of temp vars
-
Constructor Summary
ConstructorsConstructorDescriptionVariableExpressionReplacer(Closure<Boolean> when, Closure<VariableExpression> replaceWith) -
Method Summary
Modifier and TypeMethodDescriptiongetWhen()voidvoidsetReplaceWith(Closure<VariableExpression> replaceWith) voidvoidvisitAssertStatement(AssertStatement statement) Visits anAssertStatement, traversing the assertion condition and optional message expression.voidvisitBinaryExpression(BinaryExpression expression) It's the only Expression type in which replacing is considered.voidvisitCaseStatement(CaseStatement statement) Visits aCaseStatement, traversing the case expression and code block.voidVisits aDoWhileStatement, traversing the loop body before the boolean condition.voidvisitExpressionStatement(ExpressionStatement statement) Visits anExpressionStatement, traversing its contained expression.voidvisitForLoop(ForStatement forLoop) Visits aForStatement, traversing the collection expression and loop body.voidvisitIfElse(IfStatement ifElse) Visits anIfStatement, traversing the condition, if-block, and optional else-block.voidvisitReturnStatement(ReturnStatement statement) Visits aReturnStatement, traversing its return expression.voidvisitSwitch(SwitchStatement statement) Visits aSwitchStatement, traversing the switch expression, case statements, and default statement.voidvisitSynchronizedStatement(SynchronizedStatement statement) Visits aSynchronizedStatement, traversing the synchronization expression and code block.voidvisitThrowStatement(ThrowStatement statement) Visits aThrowStatement, traversing the exception expression.voidvisitWhileLoop(WhileStatement loop) Visits aWhileStatement, traversing the boolean condition and loop body.Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Constructor Details
-
VariableExpressionReplacer
-
-
Method Details
-
visitReturnStatement
Description copied from class:CodeVisitorSupportVisits aReturnStatement, traversing its return expression.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classCodeVisitorSupport- Parameters:
statement- the return statement
-
visitIfElse
Description copied from class:CodeVisitorSupportVisits anIfStatement, traversing the condition, if-block, and optional else-block.- Specified by:
visitIfElsein interfaceGroovyCodeVisitor- Overrides:
visitIfElsein classCodeVisitorSupport- Parameters:
ifElse- the if-else statement
-
visitForLoop
Description copied from class:CodeVisitorSupportVisits aForStatement, traversing the collection expression and loop body.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Overrides:
visitForLoopin classCodeVisitorSupport- Parameters:
forLoop- the for loop statement
-
visitBinaryExpression
It'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.- Specified by:
visitBinaryExpressionin interfaceGroovyCodeVisitor- Overrides:
visitBinaryExpressionin classCodeVisitorSupport- Parameters:
expression- the binary expression
-
visitWhileLoop
Description copied from class:CodeVisitorSupportVisits aWhileStatement, traversing the boolean condition and loop body.- Specified by:
visitWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitWhileLoopin classCodeVisitorSupport- Parameters:
loop- the while loop statement
-
visitDoWhileLoop
Description copied from class:CodeVisitorSupportVisits aDoWhileStatement, traversing the loop body before the boolean condition.- Specified by:
visitDoWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitDoWhileLoopin classCodeVisitorSupport- Parameters:
loop- the do-while loop statement
-
visitSwitch
Description copied from class:CodeVisitorSupportVisits aSwitchStatement, traversing the switch expression, case statements, and default statement.- Specified by:
visitSwitchin interfaceGroovyCodeVisitor- Overrides:
visitSwitchin classCodeVisitorSupport- Parameters:
statement- the switch statement
-
visitCaseStatement
Description copied from class:CodeVisitorSupportVisits aCaseStatement, traversing the case expression and code block.- Specified by:
visitCaseStatementin interfaceGroovyCodeVisitor- Overrides:
visitCaseStatementin classCodeVisitorSupport- Parameters:
statement- the case statement
-
visitExpressionStatement
Description copied from class:CodeVisitorSupportVisits anExpressionStatement, traversing its contained expression.- Specified by:
visitExpressionStatementin interfaceGroovyCodeVisitor- Overrides:
visitExpressionStatementin classCodeVisitorSupport- Parameters:
statement- the expression statement
-
visitThrowStatement
Description copied from class:CodeVisitorSupportVisits aThrowStatement, traversing the exception expression.- Specified by:
visitThrowStatementin interfaceGroovyCodeVisitor- Overrides:
visitThrowStatementin classCodeVisitorSupport- Parameters:
statement- the throw statement
-
visitAssertStatement
Description copied from class:CodeVisitorSupportVisits anAssertStatement, traversing the assertion condition and optional message expression.- Specified by:
visitAssertStatementin interfaceGroovyCodeVisitor- Overrides:
visitAssertStatementin classCodeVisitorSupport- Parameters:
statement- the assert statement
-
visitSynchronizedStatement
Description copied from class:CodeVisitorSupportVisits aSynchronizedStatement, traversing the synchronization expression and code block.- Specified by:
visitSynchronizedStatementin interfaceGroovyCodeVisitor- Overrides:
visitSynchronizedStatementin classCodeVisitorSupport- Parameters:
statement- the synchronized statement
-
replaceIn
-
getWhen
-
setWhen
-
getReplaceWith
-
setReplaceWith
-