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
ConstructorDescriptionVariableExpressionReplacer
(Closure<Boolean> when, Closure<VariableExpression> replaceWith) -
Method Summary
Modifier and TypeMethodDescriptiongetWhen()
void
void
setReplaceWith
(Closure<VariableExpression> replaceWith) void
void
visitAssertStatement
(AssertStatement statement) void
visitBinaryExpression
(BinaryExpression expression) It's the only Expression type in which replacing is considered.void
visitCaseStatement
(CaseStatement statement) void
void
visitExpressionStatement
(ExpressionStatement statement) void
visitForLoop
(ForStatement forLoop) void
visitIfElse
(IfStatement ifElse) void
visitReturnStatement
(ReturnStatement statement) void
visitSwitch
(SwitchStatement statement) void
visitSynchronizedStatement
(SynchronizedStatement statement) void
visitThrowStatement
(ThrowStatement statement) void
visitWhileLoop
(WhileStatement loop) 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, visitVariableExpression
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Constructor Details
-
VariableExpressionReplacer
-
-
Method Details
-
visitReturnStatement
- Specified by:
visitReturnStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitReturnStatement
in classCodeVisitorSupport
-
visitIfElse
- Specified by:
visitIfElse
in interfaceGroovyCodeVisitor
- Overrides:
visitIfElse
in classCodeVisitorSupport
-
visitForLoop
- Specified by:
visitForLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitForLoop
in classCodeVisitorSupport
-
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:
visitBinaryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBinaryExpression
in classCodeVisitorSupport
-
visitWhileLoop
- Specified by:
visitWhileLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitWhileLoop
in classCodeVisitorSupport
-
visitDoWhileLoop
- Specified by:
visitDoWhileLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitDoWhileLoop
in classCodeVisitorSupport
-
visitSwitch
- Specified by:
visitSwitch
in interfaceGroovyCodeVisitor
- Overrides:
visitSwitch
in classCodeVisitorSupport
-
visitCaseStatement
- Specified by:
visitCaseStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitCaseStatement
in classCodeVisitorSupport
-
visitExpressionStatement
- Specified by:
visitExpressionStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitExpressionStatement
in classCodeVisitorSupport
-
visitThrowStatement
- Specified by:
visitThrowStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitThrowStatement
in classCodeVisitorSupport
-
visitAssertStatement
- Specified by:
visitAssertStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitAssertStatement
in classCodeVisitorSupport
-
visitSynchronizedStatement
- Specified by:
visitSynchronizedStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitSynchronizedStatement
in classCodeVisitorSupport
-
replaceIn
-
getWhen
-
setWhen
-
getReplaceWith
-
setReplaceWith
-