groovy / 4.0 / org / codehaus / groovy / transform / tailrec / variableexpressionreplacer.html

[Java] Class VariableExpressionReplacer

  • org.codehaus.groovy.transform.tailrec.VariableExpressionReplacer
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

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

Constructors
Constructor and description
VariableExpressionReplacer(Closure<Boolean> when, Closure<VariableExpression> replaceWith)

Methods Summary

Methods
Type Params Return Type Name and description
public Closure<VariableExpression> getReplaceWith()
public Closure<Boolean> getWhen()
public void replaceIn(ASTNode root)
public void setReplaceWith(Closure<VariableExpression> replaceWith)
public void setWhen(Closure<Boolean> when)
public void visitAssertStatement(AssertStatement statement)
public void visitBinaryExpression(BinaryExpression expression)
It's the only Expression type in which replacing is considered.
public void visitCaseStatement(CaseStatement statement)
public void visitDoWhileLoop(DoWhileStatement loop)
public void visitExpressionStatement(ExpressionStatement statement)
public void visitForLoop(ForStatement forLoop)
public void visitIfElse(IfStatement ifElse)
public void visitReturnStatement(ReturnStatement statement)
public void visitSwitch(SwitchStatement statement)
public void visitSynchronizedStatement(SynchronizedStatement statement)
public void visitThrowStatement(ThrowStatement statement)
public void visitWhileLoop(WhileStatement loop)

Inherited Methods Summary

Constructor Detail

public VariableExpressionReplacer(Closure<Boolean> when, Closure<VariableExpression> replaceWith)

Method Detail

public Closure<VariableExpression> getReplaceWith()

public Closure<Boolean> getWhen()

public void replaceIn(ASTNode root)

public void setReplaceWith(Closure<VariableExpression> replaceWith)

public void setWhen(Closure<Boolean> when)

@Override public void visitAssertStatement(AssertStatement statement)

@Override public void visitBinaryExpression(BinaryExpression expression)

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.

@Override public void visitCaseStatement(CaseStatement statement)

@Override public void visitDoWhileLoop(DoWhileStatement loop)

@Override public void visitExpressionStatement(ExpressionStatement statement)

@Override public void visitForLoop(ForStatement forLoop)

@Override public void visitIfElse(IfStatement ifElse)

@Override public void visitReturnStatement(ReturnStatement statement)

@Override public void visitSwitch(SwitchStatement statement)

@Override public void visitSynchronizedStatement(SynchronizedStatement statement)

@Override public void visitThrowStatement(ThrowStatement statement)

@Override public void visitWhileLoop(WhileStatement loop)

© 2003-2022 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/4.0.0/html/gapi/org/codehaus/groovy/transform/tailrec/VariableExpressionReplacer.html