VariableExpressionReplacer (Groovy 4.0.15)
Description: declaration: package: org.codehaus.groovy.transform.tailrec, class: VariableExpressionReplacer

Package org.codehaus.groovy.transform.tailrec

# Class VariableExpressionReplacer

java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.transform.tailrec.VariableExpressionReplacer

All Implemented Interfaces:
  `GroovyCodeVisitor`

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
  Description
  `VariableExpressionReplacer(Closure<Boolean> when, Closure<VariableExpression> replaceWith)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Closure<VariableExpression>`
  `getReplaceWith()`
  `Closure<Boolean>`
  `getWhen()`
  `void`
  `replaceIn(ASTNode root)`
  `void`
  `setReplaceWith(Closure<VariableExpression> replaceWith)`
  `void`
  `setWhen(Closure<Boolean> when)`
  `void`
  `visitAssertStatement(AssertStatement statement)`
  `void`
  `visitBinaryExpression(BinaryExpression expression)`
  It's the only Expression type in which replacing is considered.
  `void`
  `visitCaseStatement(CaseStatement statement)`
  `void`
  `visitDoWhileLoop(DoWhileStatement loop)`
  `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

  `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

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

- ## Method Details

  - ### visitReturnStatement

    public void visitReturnStatement(ReturnStatement statement)
    Specified by:
      `visitReturnStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitReturnStatement` in class `CodeVisitorSupport`

  - ### visitIfElse

    public void visitIfElse(IfStatement ifElse)
    Specified by:
      `visitIfElse` in interface `GroovyCodeVisitor`
    Overrides:
      `visitIfElse` in class `CodeVisitorSupport`

  - ### visitForLoop

    public void visitForLoop(ForStatement forLoop)
    Specified by:
      `visitForLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitForLoop` in class `CodeVisitorSupport`

  - ### visitBinaryExpression

    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.
    Specified by:
      `visitBinaryExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitBinaryExpression` in class `CodeVisitorSupport`

  - ### visitWhileLoop

    public void visitWhileLoop(WhileStatement loop)
    Specified by:
      `visitWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitWhileLoop` in class `CodeVisitorSupport`

  - ### visitDoWhileLoop

    public void visitDoWhileLoop(DoWhileStatement loop)
    Specified by:
      `visitDoWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitDoWhileLoop` in class `CodeVisitorSupport`

  - ### visitSwitch

    public void visitSwitch(SwitchStatement statement)
    Specified by:
      `visitSwitch` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSwitch` in class `CodeVisitorSupport`

  - ### visitCaseStatement

    public void visitCaseStatement(CaseStatement statement)
    Specified by:
      `visitCaseStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitCaseStatement` in class `CodeVisitorSupport`

  - ### visitExpressionStatement

    public void visitExpressionStatement(ExpressionStatement statement)
    Specified by:
      `visitExpressionStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitExpressionStatement` in class `CodeVisitorSupport`

  - ### visitThrowStatement

    public void visitThrowStatement(ThrowStatement statement)
    Specified by:
      `visitThrowStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitThrowStatement` in class `CodeVisitorSupport`

  - ### visitAssertStatement

    public void visitAssertStatement(AssertStatement statement)
    Specified by:
      `visitAssertStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitAssertStatement` in class `CodeVisitorSupport`

  - ### visitSynchronizedStatement

    public void visitSynchronizedStatement(SynchronizedStatement statement)
    Specified by:
      `visitSynchronizedStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSynchronizedStatement` in class `CodeVisitorSupport`

  - ### replaceIn

    public void replaceIn(ASTNode root)

  - ### getWhen

    public Closure<Boolean> getWhen()

  - ### setWhen

    public void setWhen(Closure<Boolean> when)

  - ### getReplaceWith

    public Closure<VariableExpression> getReplaceWith()

  - ### setReplaceWith

    public void setReplaceWith(Closure<VariableExpression> replaceWith)