Package org.codehaus.groovy.ast
Class ClassCodeExpressionTransformer
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer
- All Implemented Interfaces:
ExpressionTransformer,GroovyClassVisitor,GroovyCodeVisitor,ErrorCollecting
- Direct Known Subclasses:
FieldASTTransformation,NewifyASTTransformation,OperatorRenameASTTransformation,OptimizerVisitor,ResolveVisitor,StaticCompilationTransformer,StaticImportVisitor
public abstract class ClassCodeExpressionTransformer
extends ClassCodeVisitorSupport
implements ExpressionTransformer
Transforms expressions in a whole class. Transformed expressions are usually not visited.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidsetSourcePosition(Expression target, Expression source) Transfers the source position to target including its property expression if it has one.transform(Expression expr) NOTE: This method does not visit Expressions within Closures, for performance and historical reasons.protected voidVisits an individualAnnotationNode, traversing all member expression values.voidVisits anAssertStatement, invoking the statement hook before parent traversal.voidVisits aCaseStatement, invoking the statement hook before parent traversal.voidVisits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.protected voidvisitConstructorOrMethod(MethodNode node, boolean isConstructor) Visits a constructor or method node (implementation detail for both visit methods).voidVisits aDoWhileStatement, invoking statement hooks before parent traversal.voidVisits anExpressionStatement, invoking the statement hook before parent traversal.voidvisitField(FieldNode node) Visits aFieldNode, processing its annotations and initial value expression if present.voidvisitForLoop(ForStatement stmt) Visits aForStatement, invoking statement hooks and processing loop variable annotations.voidvisitIfElse(IfStatement stmt) Visits anIfStatement, invoking the statement hook before parent traversal.voidvisitProperty(PropertyNode node) Visits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.voidVisits aReturnStatement, invoking the statement hook before parent traversal.voidvisitSwitch(SwitchStatement stmt) Visits aSwitchStatement, invoking the statement hook before parent traversal.voidVisits aSynchronizedStatement, invoking the statement hook before parent traversal.voidVisits aThrowStatement, invoking the statement hook before parent traversal.voidvisitWhileLoop(WhileStatement stmt) Visits aWhileStatement, invoking statement hooks before parent traversal.Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, getSourceUnit, visitAnnotations, visitAnnotations, visitBlockStatement, visitBreakStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitStatement, visitStatementAnnotations, visitTryCatchFinallyMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Constructor Details
-
ClassCodeExpressionTransformer
public ClassCodeExpressionTransformer()
-
-
Method Details
-
transform
NOTE: This method does not visit Expressions within Closures, for performance and historical reasons. If you want those Expressions to be visited, you can do this:public class YourTransformer extends ClassCodeExpressionTransformer { ... @Override public Expression transform(final Expression expr) { if (expr instanceof ClosureExpression) { expr.visit(this); return expr; } // ... } }- Specified by:
transformin interfaceExpressionTransformer- Parameters:
expr- the expression to transform, may be null- Returns:
- the transformed expression, may be the same instance, a new instance, or null
-
visitAnnotation
Description copied from class:ClassCodeVisitorSupportVisits an individualAnnotationNode, traversing all member expression values. Subclasses may override to perform custom annotation processing.- Overrides:
visitAnnotationin classClassCodeVisitorSupport- Parameters:
node- the annotation node to visit
-
visitConstructorOrMethod
Description copied from class:ClassCodeVisitorSupportVisits a constructor or method node (implementation detail for both visit methods). Processes the node's annotations, all parameter annotations, and code block.- Overrides:
visitConstructorOrMethodin classClassCodeVisitorSupport- Parameters:
node- the method or constructor nodeisConstructor- true if node is a constructor, false if it is a method
-
visitClosureExpression
Description copied from class:ClassCodeVisitorSupportVisits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.- Specified by:
visitClosureExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClosureExpressionin classClassCodeVisitorSupport- Parameters:
expr- the closure expression to visit
-
visitField
Description copied from class:ClassCodeVisitorSupportVisits aFieldNode, processing its annotations and initial value expression if present.- Specified by:
visitFieldin interfaceGroovyClassVisitor- Overrides:
visitFieldin classClassCodeVisitorSupport- Parameters:
node- the field node to visit
-
visitProperty
Description copied from class:ClassCodeVisitorSupportVisits aPropertyNode, processing its annotations, initial value expression, and getter/setter blocks if present.- Specified by:
visitPropertyin interfaceGroovyClassVisitor- Overrides:
visitPropertyin classClassCodeVisitorSupport- Parameters:
node- the property node to visit
-
visitAssertStatement
Description copied from class:ClassCodeVisitorSupportVisits anAssertStatement, invoking the statement hook before parent traversal.- Specified by:
visitAssertStatementin interfaceGroovyCodeVisitor- Overrides:
visitAssertStatementin classClassCodeVisitorSupport- Parameters:
stmt- the assert statement to visit
-
visitCaseStatement
Description copied from class:ClassCodeVisitorSupportVisits aCaseStatement, invoking the statement hook before parent traversal.- Specified by:
visitCaseStatementin interfaceGroovyCodeVisitor- Overrides:
visitCaseStatementin classClassCodeVisitorSupport- Parameters:
stmt- the case statement to visit
-
visitDoWhileLoop
Description copied from class:ClassCodeVisitorSupportVisits aDoWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitDoWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitDoWhileLoopin classClassCodeVisitorSupport- Parameters:
stmt- the do-while statement to visit
-
visitExpressionStatement
Description copied from class:ClassCodeVisitorSupportVisits anExpressionStatement, invoking the statement hook before parent traversal.- Specified by:
visitExpressionStatementin interfaceGroovyCodeVisitor- Overrides:
visitExpressionStatementin classClassCodeVisitorSupport- Parameters:
stmt- the expression statement to visit
-
visitForLoop
Description copied from class:ClassCodeVisitorSupportVisits aForStatement, invoking statement hooks and processing loop variable annotations.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Overrides:
visitForLoopin classClassCodeVisitorSupport- Parameters:
stmt- the for statement to visit
-
visitIfElse
Description copied from class:ClassCodeVisitorSupportVisits anIfStatement, invoking the statement hook before parent traversal.- Specified by:
visitIfElsein interfaceGroovyCodeVisitor- Overrides:
visitIfElsein classClassCodeVisitorSupport- Parameters:
stmt- the if statement to visit
-
visitReturnStatement
Description copied from class:ClassCodeVisitorSupportVisits aReturnStatement, invoking the statement hook before parent traversal.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classClassCodeVisitorSupport- Parameters:
stmt- the return statement to visit
-
visitSwitch
Description copied from class:ClassCodeVisitorSupportVisits aSwitchStatement, invoking the statement hook before parent traversal.- Specified by:
visitSwitchin interfaceGroovyCodeVisitor- Overrides:
visitSwitchin classClassCodeVisitorSupport- Parameters:
stmt- the switch statement to visit
-
visitSynchronizedStatement
Description copied from class:ClassCodeVisitorSupportVisits aSynchronizedStatement, invoking the statement hook before parent traversal.- Specified by:
visitSynchronizedStatementin interfaceGroovyCodeVisitor- Overrides:
visitSynchronizedStatementin classClassCodeVisitorSupport- Parameters:
stmt- the synchronized statement to visit
-
visitThrowStatement
Description copied from class:ClassCodeVisitorSupportVisits aThrowStatement, invoking the statement hook before parent traversal.- Specified by:
visitThrowStatementin interfaceGroovyCodeVisitor- Overrides:
visitThrowStatementin classClassCodeVisitorSupport- Parameters:
stmt- the throw statement to visit
-
visitWhileLoop
Description copied from class:ClassCodeVisitorSupportVisits aWhileStatement, invoking statement hooks before parent traversal.- Specified by:
visitWhileLoopin interfaceGroovyCodeVisitor- Overrides:
visitWhileLoopin classClassCodeVisitorSupport- Parameters:
stmt- the while statement to visit
-
setSourcePosition
Transfers the source position to target including its property expression if it has one.- Parameters:
target- resulting nodesource- original node
-