Class VariableAccessReplacer
java.lang.Object
org.codehaus.groovy.transform.tailrec.VariableAccessReplacer
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
ConstructorsConstructorDescriptionVariableAccessReplacer(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 TypeMethodDescriptionReturns the listener notified when replacements occur.voidReplaces matching variable accesses within the supplied AST subtree.voidsetListener(VariableReplacedListener listener) Sets the listener notified when replacements occur.voidsetNameAndTypeMapping(Map<String, Map> nameAndTypeMapping) Sets the variable replacement mapping.
-
Constructor Details
-
VariableAccessReplacer
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 replacementslistener- the listener notified about replacements
-
-
Method Details
-
replaceIn
Replaces matching variable accesses within the supplied AST subtree.- Parameters:
root- the AST subtree to mutate
-
setNameAndTypeMapping
Sets the variable replacement mapping.- Parameters:
nameAndTypeMapping- the variables to replace and their replacements
-
getListener
Returns the listener notified when replacements occur.- Returns:
- the replacement listener
-
setListener
Sets the listener notified when replacements occur.- Parameters:
listener- the replacement listener
-