Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-4941: Static methods cannot be called during AST transformation v... #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
expression << new ImportNode(ClassHelper.make(target), alias)
}

/**
* Creates an ImportNode.
*/
void importNode(ClassNode target, String alias = null) {
expression << new ImportNode(target, alias)
}

/**
* Creates a CatchStatement.
*/
Expand Down Expand Up @@ -646,6 +653,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
expression << new ClassExpression(ClassHelper.make(type))
}

/**
* Creates a ClassExpression.
*/
void classExpression(ClassNode type) {
expression << new ClassExpression(type)
}

/**
* Creates a UnaryMinusExpression
*/
Expand Down Expand Up @@ -739,6 +753,32 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a Parameter.
*/
void parameter(String name, Class type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
captureAndCreateNode("Parameter", argBlock) {
new Parameter(ClassHelper.make(type), name, expression[0])
}
} else {
expression << (new Parameter(ClassHelper.make(type), name))
}
}

/**
* Creates a Parameter.
*/
void parameter(String name, ClassNode type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
captureAndCreateNode("Parameter", argBlock) {
new Parameter(type, name, expression[0])
}
} else {
expression << (new Parameter(type, name))
}
}

/**
* Creates an ArrayExpression.
*/
Expand All @@ -748,6 +788,15 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates an ArrayExpression.
*/
void array(ClassNode type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode("ArrayExpression", argBlock) {
new ArrayExpression(type, new ArrayList(expression))
}
}

/**
* Creates a GenericsType.
*/
Expand All @@ -761,6 +810,19 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a GenericsType.
*/
void genericsType(ClassNode type, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
captureAndCreateNode("GenericsType", argBlock) {
new GenericsType(type, expression[0] as ClassNode[], expression[1])
}
} else {
expression << new GenericsType(ClassHelper.make(type))
}
}

/**
* Creates a list of upperBound ClassNodes.
*/
Expand All @@ -775,6 +837,13 @@ class AstSpecificationCompiler implements GroovyInterceptable {
expression << ClassHelper.make(target)
}

/**
* Create lowerBound ClassNode.
*/
void lowerBound(ClassNode target) {
expression << target
}

/**
* Creates a 2 element list of name and Annotation. Used with Annotation Members.
*/
Expand Down Expand Up @@ -813,6 +882,24 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates an AnnotationNode.
*/
void annotation(ClassNode target, @DelegatesTo(AstSpecificationCompiler) Closure argBlock = null) {
if (argBlock) {
//todo: add better error handling
captureAndCreateNode("ArgumentListExpression", argBlock) {
def node = new AnnotationNode(target)
expression?.each {
node.addMember(it[0], it[1])
}
node
}
} else {
expression << new AnnotationNode(target)
}
}

/**
* Creates a MixinNode.
*/
Expand Down Expand Up @@ -923,6 +1010,20 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a MethodNode.
*/
void method(String name, int modifiers, ClassNode returnType, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode("MethodNode", argBlock) {
//todo: enforce contract
def result = new MethodNode(name, modifiers, returnType, expression[0], expression[1], expression[2])
if (expression[3]) {
result.addAnnotations(new ArrayList(expression[3]))
}
result
}
}

/**
* Creates a token.
*/
Expand Down Expand Up @@ -995,6 +1096,28 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a FieldNode.
*/
void fieldNode(String name, int modifiers, ClassNode type, ClassNode owner, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode("FieldNode", argBlock) {
def annotations = null
if (expression.size() > 1) {
annotations = expression[1]
expression.remove(1)
}
expression.add(0, owner)
expression.add(0, type)
expression.add(0, modifiers)
expression.add(0, name)
def result = new FieldNode(*enforceConstraints('fieldNode', [String, Integer, ClassNode, ClassNode, Expression]))
if (annotations) {
result.addAnnotations(new ArrayList(annotations))
}
result
}
}

/**
* Creates an inner class.
*/
Expand Down Expand Up @@ -1034,6 +1157,29 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a PropertyNode.
*/
void propertyNode(String name, int modifiers, ClassNode type, ClassNode owner, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
//todo: improve error handling?
captureAndCreateNode("PropertyNode", argBlock) {
def annotations = null
// check if the last expression looks like annotations
if (List.isAssignableFrom(expression[-1].getClass())) {
annotations = expression[-1]
expression.remove(expression.size() - 1)
}
def result = new PropertyNode(name, modifiers, type, owner,
expression[0], // initial value (possibly null)
expression[1], // getter block (possibly null)
expression[2]) // setter block (possibly null)
if (annotations) {
result.addAnnotations(new ArrayList(annotations))
}
result
}
}

/**
* Creates a StaticMethodCallExpression.
*/
Expand All @@ -1045,6 +1191,17 @@ class AstSpecificationCompiler implements GroovyInterceptable {
}
}

/**
* Creates a StaticMethodCallExpression.
*/
void staticMethodCall(ClassNode target, String name, @DelegatesTo(AstSpecificationCompiler) Closure argBlock) {
captureAndCreateNode("StaticMethodCallExpression", argBlock) {
expression.add(0, name)
expression.add(0, target)
new StaticMethodCallExpression(*enforceConstraints('staticMethodCall', [ClassNode, String, Expression]))
}
}

/**
* Creates a StaticMethodCallExpression.
*/
Expand Down