Package org.codehaus.groovy.transform.tailrec

# Class VariableAccessReplacer

java.lang.Object
org.codehaus.groovy.transform.tailrec.VariableAccessReplacer

public class VariableAccessReplacer extends Object
Replace all access to variables and args by new variables. The variable names to replace as well as their replacement name and type have to be configured in nameAndTypeMapping before calling replaceIn().

The VariableReplacedListener can be set if clients want to react to variable replacement.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `VariableAccessReplacer(Map<String,Map> nameAndTypeMapping)`
  Creates a replacer with the supplied name/type mapping.
  `VariableAccessReplacer(Map<String,Map> nameAndTypeMapping, VariableReplacedListener listener)`
  Creates a replacer with the supplied name/type mapping and listener.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `VariableReplacedListener`
  `getListener()`
  Returns the listener notified when replacements occur.
  `void`
  `replaceIn(ASTNode root)`
  Replaces matching variable accesses within the supplied AST subtree.
  `void`
  `setListener(VariableReplacedListener listener)`
  Sets the listener notified when replacements occur.
  `void`
  `setNameAndTypeMapping(Map<String,Map> nameAndTypeMapping)`
  Sets the variable replacement mapping.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### VariableAccessReplacer

    public VariableAccessReplacer(Map<String,Map> nameAndTypeMapping)
    Creates a replacer with the supplied name/type mapping.
    Parameters:
      `nameAndTypeMapping` - the variables to replace and their replacements

  - ### VariableAccessReplacer

    public VariableAccessReplacer(Map<String,Map> nameAndTypeMapping, VariableReplacedListener listener)
    Creates a replacer with the supplied name/type mapping and listener.
    Parameters:
      `nameAndTypeMapping` - the variables to replace and their replacements
      `listener` - the listener notified about replacements

- ## Method Details

  - ### replaceIn

    public void replaceIn(ASTNode root)
    Replaces matching variable accesses within the supplied AST subtree.
    Parameters:
      `root` - the AST subtree to mutate

  - ### setNameAndTypeMapping

    public void setNameAndTypeMapping(Map<String,Map> nameAndTypeMapping)
    Sets the variable replacement mapping.
    Parameters:
      `nameAndTypeMapping` - the variables to replace and their replacements

  - ### getListener

    public VariableReplacedListener getListener()
    Returns the listener notified when replacements occur.
    Returns:
      the replacement listener

  - ### setListener

    public void setListener(VariableReplacedListener listener)
    Sets the listener notified when replacements occur.
    Parameters:
      `listener` - the replacement listener