Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X f1e1c2de7 -> f408749ad
Trivial refactoring for `CompilerConfiguration` (cherry picked from commit 5443e87) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f408749a Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f408749a Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f408749a Branch: refs/heads/GROOVY_2_6_X Commit: f408749ad30de8639b487439b97e1f83c61b8e65 Parents: f1e1c2d Author: danielsun1106 <realblue...@hotmail.com> Authored: Fri Apr 13 22:23:25 2018 +0800 Committer: danielsun1106 <realblue...@hotmail.com> Committed: Fri Apr 13 22:39:18 2018 +0800 ---------------------------------------------------------------------- .../groovy/control/CompilerConfiguration.java | 63 ++++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/f408749a/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 15ae8c9..bc0cf6c 100644 --- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java @@ -941,51 +941,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(); } }