Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 1b7ba8650 -> 1b26e1e76


GROOVY-8543: Support setting compileStatic by default via system properties

(cherry picked from commit 81ffc80)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1b26e1e7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1b26e1e7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1b26e1e7

Branch: refs/heads/GROOVY_2_6_X
Commit: 1b26e1e769774ca0dc05a2e84da8d92617c653ad
Parents: 1b7ba86
Author: sunlan <sun...@apache.org>
Authored: Fri Apr 13 07:56:00 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri Apr 13 07:57:26 2018 +0800

----------------------------------------------------------------------
 .../org/apache/groovy/parser/antlr4/AstBuilder.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/1b26e1e7/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 9b810f0..43fe5fd 100644
--- 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1202,6 +1202,9 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         classNode.putNodeMetaData(CLASS_NAME, className);
         classNode.setSyntheticPublic(syntheticPublic);
 
+        if (COMPILE_STATIC_BY_DEFAULT) {
+            attachCompileStaticAnnotation(classNode);
+        }
         if (asBoolean(ctx.TRAIT())) {
             attachTraitAnnotation(classNode);
         }
@@ -1272,8 +1275,16 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         return classNode;
     }
 
+    private void attachCompileStaticAnnotation(ClassNode classNode) {
+        attachAnnotation(classNode, GROOVY_TRANSFORM_COMPILE_STATIC);
+    }
+
     private void attachTraitAnnotation(ClassNode classNode) {
-        classNode.addAnnotation(new 
AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_TRAIT)));
+        attachAnnotation(classNode, GROOVY_TRANSFORM_TRAIT);
+    }
+
+    private void attachAnnotation(ClassNode classNode, String 
annotationClassName) {
+        classNode.addAnnotation(new 
AnnotationNode(ClassHelper.make(annotationClassName)));
     }
 
     @SuppressWarnings({"unchecked"})
@@ -4838,6 +4849,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
 
     private static final String PACKAGE_INFO = "package-info";
     private static final String PACKAGE_INFO_FILE_NAME = PACKAGE_INFO + 
".groovy";
+    private static final String GROOVY_TRANSFORM_COMPILE_STATIC = 
"groovy.transform.CompileStatic";
     private static final String GROOVY_TRANSFORM_TRAIT = 
"groovy.transform.Trait";
     private static final Set<String> PRIMITIVE_TYPE_SET = 
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("boolean", "char", 
"byte", "short", "int", "long", "float", "double")));
     private static final Logger LOGGER = 
Logger.getLogger(AstBuilder.class.getName());
@@ -4865,4 +4877,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
     private static final String ENCLOSING_INSTANCE_EXPRESSION = 
"_ENCLOSING_INSTANCE_EXPRESSION";
 
     private static final String CLASS_NAME = "_CLASS_NAME";
+
+    private static final boolean COMPILE_STATIC_BY_DEFAULT = 
Boolean.getBoolean("groovy.compile.static.by.default");
 }

Reply via email to