Package org.spockframework.compiler
Class AstUtil
java.lang.Object
org.spockframework.compiler.AstUtil
Utility methods for AST processing.
- Author:
- Peter Niederwieser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopySourcePosition(org.codehaus.groovy.ast.ASTNode from, org.codehaus.groovy.ast.ASTNode to) static org.codehaus.groovy.ast.expr.MethodCallExpressioncreateDirectMethodCall(org.codehaus.groovy.ast.expr.Expression target, org.codehaus.groovy.ast.MethodNode method, org.codehaus.groovy.ast.expr.Expression arguments) static voiddeleteMethod(org.codehaus.groovy.ast.ClassNode clazz, org.codehaus.groovy.ast.MethodNode method) static voidfixUpLocalVariables(List<? extends org.codehaus.groovy.ast.Variable> localVariables, org.codehaus.groovy.ast.VariableScope scope, boolean isClosureScope) Fixes up scope references to variables that used to be free or class variables, and have been changed to local variables.static voidfixUpLocalVariables(org.codehaus.groovy.ast.Variable[] localVariables, org.codehaus.groovy.ast.VariableScope scope, boolean isClosureScope) static org.codehaus.groovy.ast.AnnotationNodegetAnnotation(org.codehaus.groovy.ast.ASTNode node, Class<?> annotationType) static List<org.codehaus.groovy.ast.expr.Expression> getArgumentList(org.codehaus.groovy.ast.expr.Expression invocation) static org.codehaus.groovy.ast.expr.ExpressiongetArguments(org.codehaus.groovy.ast.expr.Expression invocation) static org.codehaus.groovy.ast.expr.ExpressiongetAssertionMessage(org.codehaus.groovy.ast.stmt.AssertStatement stat) static <T extends org.codehaus.groovy.ast.expr.Expression>
TgetExpression(org.codehaus.groovy.ast.stmt.Statement stat, Class<T> type) static org.codehaus.groovy.ast.expr.ExpressiongetImplicitParameterRef(org.codehaus.groovy.ast.expr.ClosureExpression expr) static org.codehaus.groovy.ast.expr.ExpressiongetInvocationTarget(org.codehaus.groovy.ast.expr.Expression expr) static StringgetMethodName(org.codehaus.groovy.ast.expr.Expression invocation) static List<org.codehaus.groovy.ast.stmt.Statement> getStatements(org.codehaus.groovy.ast.expr.ClosureExpression closure) static List<org.codehaus.groovy.ast.stmt.Statement> getStatements(org.codehaus.groovy.ast.MethodNode method) Returns a list of statements of the given method.static org.codehaus.groovy.ast.expr.ExpressiongetVariableName(org.codehaus.groovy.ast.expr.BinaryExpression assignment) static org.codehaus.groovy.ast.expr.ExpressiongetVariableType(org.codehaus.groovy.ast.expr.BinaryExpression assignment) static intgetVisibility(org.codehaus.groovy.ast.FieldNode field) static booleanhasAnnotation(org.codehaus.groovy.ast.ASTNode node, Class<?> annotationType) Tells whether the given node has an annotation of the given type.static booleanhasImplicitParameter(org.codehaus.groovy.ast.expr.ClosureExpression expr) static booleanhasPlausibleSourcePosition(org.codehaus.groovy.ast.ASTNode node) Tells if the source position for the given AST node is plausible.static booleanisInvocationWithImplicitThis(org.codehaus.groovy.ast.expr.Expression invocation) static booleanstatic booleanisJointCompiled(org.codehaus.groovy.ast.ClassNode clazz) static booleanisSuperExpression(org.codehaus.groovy.ast.expr.Expression expr) static booleanisSynthetic(org.codehaus.groovy.ast.MethodNode method) static booleanisThisExpression(org.codehaus.groovy.ast.expr.Expression expr) static booleanisThisOrSuperExpression(org.codehaus.groovy.ast.expr.Expression expr) static booleanisWildcardRef(org.codehaus.groovy.ast.expr.Expression expr) static voidsetVisibility(org.codehaus.groovy.ast.FieldNode field, int visibility) static voidsetVisibility(org.codehaus.groovy.ast.MethodNode method, int visibility) static org.codehaus.groovy.ast.expr.ExpressiontoArgumentArray(List<org.codehaus.groovy.ast.expr.Expression> argList, IRewriteResources resources) Turns an argument list obtained from AstUtil.getArguments() into an Object[] array suitable to be passed to InvokerHelper or SpockRuntime.
-
Constructor Details
-
AstUtil
public AstUtil()
-
-
Method Details
-
hasAnnotation
Tells whether the given node has an annotation of the given type.- Parameters:
node- an AST nodeannotationType- an annotation type- Returns:
- true iff the given node has an annotation of the given type
-
getAnnotation
public static org.codehaus.groovy.ast.AnnotationNode getAnnotation(org.codehaus.groovy.ast.ASTNode node, Class<?> annotationType) -
getStatements
public static List<org.codehaus.groovy.ast.stmt.Statement> getStatements(org.codehaus.groovy.ast.MethodNode method) Returns a list of statements of the given method. Modifications to the returned list will affect the method's statements.- Parameters:
method- a method (node)- Returns:
- a list of statements of the given method
-
getStatements
public static List<org.codehaus.groovy.ast.stmt.Statement> getStatements(org.codehaus.groovy.ast.expr.ClosureExpression closure) -
isInvocationWithImplicitThis
public static boolean isInvocationWithImplicitThis(org.codehaus.groovy.ast.expr.Expression invocation) -
hasImplicitParameter
public static boolean hasImplicitParameter(org.codehaus.groovy.ast.expr.ClosureExpression expr) -
getImplicitParameterRef
public static org.codehaus.groovy.ast.expr.Expression getImplicitParameterRef(org.codehaus.groovy.ast.expr.ClosureExpression expr) -
getInvocationTarget
public static org.codehaus.groovy.ast.expr.Expression getInvocationTarget(org.codehaus.groovy.ast.expr.Expression expr) -
isWildcardRef
public static boolean isWildcardRef(org.codehaus.groovy.ast.expr.Expression expr) -
isJavaIdentifier
-
getExpression
public static <T extends org.codehaus.groovy.ast.expr.Expression> T getExpression(org.codehaus.groovy.ast.stmt.Statement stat, Class<T> type) -
isSynthetic
public static boolean isSynthetic(org.codehaus.groovy.ast.MethodNode method) -
hasPlausibleSourcePosition
public static boolean hasPlausibleSourcePosition(org.codehaus.groovy.ast.ASTNode node) Tells if the source position for the given AST node is plausible. Does not imply that the source position is correct.- Parameters:
node- an AST node- Returns:
- true iff the AST node has a plausible source position
-
getMethodName
-
getArguments
public static org.codehaus.groovy.ast.expr.Expression getArguments(org.codehaus.groovy.ast.expr.Expression invocation) -
getArgumentList
public static List<org.codehaus.groovy.ast.expr.Expression> getArgumentList(org.codehaus.groovy.ast.expr.Expression invocation) -
toArgumentArray
public static org.codehaus.groovy.ast.expr.Expression toArgumentArray(List<org.codehaus.groovy.ast.expr.Expression> argList, IRewriteResources resources) Turns an argument list obtained from AstUtil.getArguments() into an Object[] array suitable to be passed to InvokerHelper or SpockRuntime. The main challenge is to handle SpreadExpression's correctly. -
copySourcePosition
public static void copySourcePosition(org.codehaus.groovy.ast.ASTNode from, org.codehaus.groovy.ast.ASTNode to) -
getAssertionMessage
public static org.codehaus.groovy.ast.expr.Expression getAssertionMessage(org.codehaus.groovy.ast.stmt.AssertStatement stat) -
isThisExpression
public static boolean isThisExpression(org.codehaus.groovy.ast.expr.Expression expr) -
isSuperExpression
public static boolean isSuperExpression(org.codehaus.groovy.ast.expr.Expression expr) -
isThisOrSuperExpression
public static boolean isThisOrSuperExpression(org.codehaus.groovy.ast.expr.Expression expr) -
setVisibility
public static void setVisibility(org.codehaus.groovy.ast.MethodNode method, int visibility) -
getVisibility
public static int getVisibility(org.codehaus.groovy.ast.FieldNode field) -
setVisibility
public static void setVisibility(org.codehaus.groovy.ast.FieldNode field, int visibility) -
isJointCompiled
public static boolean isJointCompiled(org.codehaus.groovy.ast.ClassNode clazz) -
createDirectMethodCall
public static org.codehaus.groovy.ast.expr.MethodCallExpression createDirectMethodCall(org.codehaus.groovy.ast.expr.Expression target, org.codehaus.groovy.ast.MethodNode method, org.codehaus.groovy.ast.expr.Expression arguments) -
deleteMethod
public static void deleteMethod(org.codehaus.groovy.ast.ClassNode clazz, org.codehaus.groovy.ast.MethodNode method) -
getVariableName
public static org.codehaus.groovy.ast.expr.Expression getVariableName(org.codehaus.groovy.ast.expr.BinaryExpression assignment) -
getVariableType
public static org.codehaus.groovy.ast.expr.Expression getVariableType(org.codehaus.groovy.ast.expr.BinaryExpression assignment) -
fixUpLocalVariables
public static void fixUpLocalVariables(org.codehaus.groovy.ast.Variable[] localVariables, org.codehaus.groovy.ast.VariableScope scope, boolean isClosureScope) -
fixUpLocalVariables
public static void fixUpLocalVariables(List<? extends org.codehaus.groovy.ast.Variable> localVariables, org.codehaus.groovy.ast.VariableScope scope, boolean isClosureScope) Fixes up scope references to variables that used to be free or class variables, and have been changed to local variables.
-