Repository: groovy Updated Branches: refs/heads/master 31c5dabf8 -> 5443e8788
Trivial refactoring for `CompilerConfiguration` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5443e878 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5443e878 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5443e878 Branch: refs/heads/master Commit: 5443e87882f9b88169876f6d043ed54b5ae9023b Parents: 31c5dab Author: danielsun1106 <realblue...@hotmail.com> Authored: Fri Apr 13 22:23:25 2018 +0800 Committer: danielsun1106 <realblue...@hotmail.com> Committed: Fri Apr 13 22:23:25 2018 +0800 ---------------------------------------------------------------------- .../groovy/control/CompilerConfiguration.java | 63 ++++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/5443e878/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 95d4c03..a2164bb 100644 --- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java @@ -940,51 +940,50 @@ public class CompilerConfiguration { return indyEnabled; } - private boolean compileStatic; - private void enableCompileStaticByDefault() { - if (compileStatic) { - return; - } - if (!Boolean.getBoolean("groovy.compile.static")) { - return; + { + // this object initializer assures that `enableCompileStaticByDefault` must be invoked no matter which constructor called. + if (Boolean.getBoolean("groovy.compile.static")) { + enableCompileStaticByDefault(); } - + } + private void enableCompileStaticByDefault() { 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); - } + newClassCodeVisitor(source).visitClass(cn); + } + } - 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; - } + private ClassCodeVisitorSupport newClassCodeVisitor(SourceUnit source) { + return new ClassCodeVisitorSupport() { + @Override + public void visitClass(ClassNode node) { + enableCompileStatic(node); + } - classNode.addAnnotation(new AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC))); + private void enableCompileStatic(ClassNode classNode) { + if (!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)).isEmpty()) { + return; } - - @Override - protected SourceUnit getSourceUnit() { - return source; + if (!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_DYNAMIC)).isEmpty()) { + return; } - private static final String GROOVY_TRANSFORM_COMPILE_STATIC = "groovy.transform.CompileStatic"; - private static final String GROOVY_TRANSFORM_COMPILE_DYNAMIC = "groovy.transform.CompileDynamic"; - }.visitClass(cn); - } + classNode.addAnnotation(new AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC))); + } + + @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"; + }; } } ); - - compileStatic = true; } - { enableCompileStaticByDefault(); } }