Repository: groovy
Updated Branches:
  refs/heads/master ae74e1d62 -> 31c5dabf8


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

Avoid adding `CompilationCustomizer` multiple times and rename the option name 
to "groovy.compile.static"


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

Branch: refs/heads/master
Commit: 31c5dabf8a47b7854808ec96d565ca00611051d9
Parents: ae74e1d
Author: sunlan <sun...@apache.org>
Authored: Fri Apr 13 19:13:52 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri Apr 13 19:13:52 2018 +0800

----------------------------------------------------------------------
 .../groovy/control/CompilerConfiguration.java   | 62 ++++++++++----------
 1 file changed, 32 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/31c5dabf/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java 
b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 06a4b1f..95d4c03 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -194,8 +194,6 @@ public class CompilerConfiguration {
 
     private final List<CompilationCustomizer> compilationCustomizers = new 
LinkedList<CompilationCustomizer>();
 
-    private static final boolean COMPILE_STATIC_BY_DEFAULT = 
Boolean.getBoolean("groovy.compile.static.by.default");
-
     /**
      * Sets a list of global AST transformations which should not be loaded 
even if they are
      * defined in META-INF/org.codehaus.groovy.transform.ASTTransformation 
files. By default,
@@ -942,47 +940,51 @@ public class CompilerConfiguration {
         return indyEnabled;
     }
 
+    private boolean compileStatic;
     private void enableCompileStaticByDefault() {
-        if (!COMPILE_STATIC_BY_DEFAULT) {
+        if (compileStatic) {
+            return;
+        }
+        if (!Boolean.getBoolean("groovy.compile.static")) {
             return;
         }
 
         compilationCustomizers.add(
-                new CompilationCustomizer(CompilePhase.CONVERSION) {
-                    @Override
-                    public void call(final SourceUnit source, GeneratorContext 
context, ClassNode classNode) throws CompilationFailedException {
-                        for (ClassNode cn : source.getAST().getClasses()) {
-                            new ClassCodeVisitorSupport() {
-                                @Override
-                                public void visitClass(ClassNode node) {
-                                    enableCompileStatic(node);
+            new CompilationCustomizer(CompilePhase.CONVERSION) {
+                @Override
+                public void call(final SourceUnit source, GeneratorContext 
context, ClassNode classNode) throws CompilationFailedException {
+                    for (ClassNode cn : source.getAST().getClasses()) {
+                        new ClassCodeVisitorSupport() {
+                            @Override
+                            public void visitClass(ClassNode node) {
+                                enableCompileStatic(node);
+                            }
+
+                            private void enableCompileStatic(ClassNode 
classNode) {
+                                if 
(!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)).isEmpty())
 {
+                                    return;
                                 }
-
-                                private void enableCompileStatic(ClassNode 
classNode) {
-                                    if 
(!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)).isEmpty())
 {
-                                        return;
-                                    }
-
-                                    if 
(!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_DYNAMIC)).isEmpty())
 {
-                                        return;
-                                    }
-
-                                    classNode.addAnnotation(new 
AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)));
+                                if 
(!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_DYNAMIC)).isEmpty())
 {
+                                    return;
                                 }
 
-                                @Override
-                                protected SourceUnit getSourceUnit() {
-                                    return source;
-                                }
+                                classNode.addAnnotation(new 
AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)));
+                            }
 
-                                private static final String 
GROOVY_TRANSFORM_COMPILE_STATIC = "groovy.transform.CompileStatic";
-                                private static final String 
GROOVY_TRANSFORM_COMPILE_DYNAMIC = "groovy.transform.CompileDynamic";
-                            }.visitClass(cn);
-                        }
+                            @Override
+                            protected SourceUnit getSourceUnit() {
+                                return source;
+                            }
+
+                            private static final String 
GROOVY_TRANSFORM_COMPILE_STATIC = "groovy.transform.CompileStatic";
+                            private static final String 
GROOVY_TRANSFORM_COMPILE_DYNAMIC = "groovy.transform.CompileDynamic";
+                        }.visitClass(cn);
                     }
                 }
+            }
         );
 
+        compileStatic = true;
     }
     { enableCompileStaticByDefault(); }
 }


Reply via email to