1
1
package com.nagternal.groovy.clojure.transform
2
2
3
3
import clojure.lang.RT
4
- import clojure.lang.Var
5
4
import com.nagternal.groovy.clojure.Clj
6
5
import org.codehaus.groovy.GroovyBugError
7
6
import org.codehaus.groovy.ast.*
8
7
import org.codehaus.groovy.ast.expr.ArgumentListExpression
9
- import org.codehaus.groovy.ast.expr.ClassExpression
10
8
import org.codehaus.groovy.ast.expr.ConstantExpression
11
- import org.codehaus.groovy.ast.expr.Expression
12
- import org.codehaus.groovy.ast.expr.ExpressionTransformer
13
- import org.codehaus.groovy.ast.expr.MethodCallExpression
14
9
import org.codehaus.groovy.ast.expr.StaticMethodCallExpression
15
- import org.codehaus.groovy.ast.expr.VariableExpression
16
10
import org.codehaus.groovy.control.CompilePhase
17
11
import org.codehaus.groovy.control.SourceUnit
18
12
import org.codehaus.groovy.transform.ASTTransformation
@@ -32,26 +26,31 @@ class RequireASTTransformation implements ASTTransformation {
32
26
if (nodes. length != 2 || ! (nodes[0 ] instanceof AnnotationNode ) || ! (nodes[1 ] instanceof AnnotatedNode )) {
33
27
throw new GroovyBugError (" Internal error: expecting [AnnotationNode, AnnotatedNode] but got: ${ nodes} " )
34
28
}
35
- AnnotatedNode targetField = nodes[1 ]
29
+ AnnotatedNode targetField = nodes[1 ]
36
30
AnnotationNode annotation = nodes[0 ]
37
31
if (! (targetField instanceof FieldNode )) {
38
32
throw new GroovyBugError (" Field annotation ${ annotation.classNode.name} not annotating Field." )
39
33
}
40
- final FieldNode fieldNode = targetField
34
+ FieldNode fieldNode = targetField
41
35
42
36
String varName = getVarName(annotation)
43
37
String ns, name
44
38
(ns, name) = Clj . nsname(varName)
45
39
46
- if (! fieldNode. static ) { fieldNode. modifiers + = Opcodes . ACC_STATIC }
47
- if (! fieldNode. final ) { fieldNode. modifiers + = Opcodes . ACC_FINAL }
48
- fieldNode. initialValueExpression = new StaticMethodCallExpression (
49
- new ClassNode (RT ), ' var' , new ArgumentListExpression (new ConstantExpression (ns), new ConstantExpression (name))
50
- )
40
+ if (! fieldNode. static ) {
41
+ fieldNode. modifiers + = Opcodes . ACC_STATIC
42
+ }
43
+ if (! fieldNode. final ) {
44
+ fieldNode. modifiers + = Opcodes . ACC_FINAL
45
+ }
46
+ fieldNode. initialValueExpression = new StaticMethodCallExpression (
47
+ new ClassNode (RT ), ' var' ,
48
+ new ArgumentListExpression (new ConstantExpression (ns), new ConstantExpression (name))
49
+ )
51
50
}
52
51
53
52
String getVarName (AnnotationNode annotation ) {
54
53
ConstantExpression expr = annotation. getMember(' value' )
55
- expr. getValue()
54
+ expr. value
56
55
}
57
56
}
0 commit comments