Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 289848139 -> 69b545844
use assertions instead of println in a test, fix javadoc Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/69b54584 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/69b54584 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/69b54584 Branch: refs/heads/GROOVY_2_5_X Commit: 69b5458447a3fee972845d23233a7e2fb7332e15 Parents: 2898481 Author: Paul King <[email protected]> Authored: Sun Sep 2 22:00:15 2018 +1000 Committer: Paul King <[email protected]> Committed: Sun Sep 2 23:05:20 2018 +1000 ---------------------------------------------------------------------- .../groovy/control/CompilerConfiguration.java | 12 ++++---- .../groovy/transform/GlobalTransformTest.groovy | 28 ++++++------------ .../groovy/transform/TestTransform.groovy | 30 +++++++++----------- 3 files changed, 30 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/69b54584/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 99c56d5..b3850cd 100644 --- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java @@ -188,9 +188,9 @@ public class CompilerConfiguration { private final List<CompilationCustomizer> compilationCustomizers = new LinkedList<CompilationCustomizer>(); /** - * 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, - * none is disabled. + * Global AST transformations which should not be loaded even if they are + * defined in META-INF/services/org.codehaus.groovy.transform.ASTTransformation files. + * By default, none are disabled. */ private Set<String> disabledGlobalASTTransformations; @@ -844,13 +844,15 @@ public class CompilerConfiguration { } /** - * Disables global AST transformations. In order to avoid class loading side effects, it is not recommended + * Disables the specified global AST transformations. In order to avoid class loading side effects, it is not recommended * to use MyASTTransformation.class.getName() by directly use the class name as a string. Disabled AST transformations * only apply to automatically loaded global AST transformations, that is to say transformations defined in a - * META-INF/org.codehaus.groovy.transform.ASTTransformation file. If you explicitly add a global AST transformation + * META-INF/services/org.codehaus.groovy.transform.ASTTransformation file. + * If you explicitly add a global AST transformation * in your compilation process, for example using the {@link org.codehaus.groovy.control.customizers.ASTTransformationCustomizer} or * using a {@link org.codehaus.groovy.control.CompilationUnit.PrimaryClassNodeOperation}, then nothing will prevent * the transformation from being loaded. + * * @param disabledGlobalASTTransformations a set of fully qualified class names of global AST transformations * which should not be loaded. */ http://git-wip-us.apache.org/repos/asf/groovy/blob/69b54584/src/test/org/codehaus/groovy/transform/GlobalTransformTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/GlobalTransformTest.groovy b/src/test/org/codehaus/groovy/transform/GlobalTransformTest.groovy index aa2e35e..fd13db3 100644 --- a/src/test/org/codehaus/groovy/transform/GlobalTransformTest.groovy +++ b/src/test/org/codehaus/groovy/transform/GlobalTransformTest.groovy @@ -18,28 +18,18 @@ */ package org.codehaus.groovy.transform -/** - * @author Danno.Ferrin - * @author Alex Tkachman - */ -class GlobalTransformTest extends GroovyShellTestCase { - - URL transformRoot = new File(getClass().classLoader. - getResource("org/codehaus/groovy/transform/META-INF/services/org.codehaus.groovy.transform.ASTTransformation"). - toURI()).parentFile.parentFile.parentFile.toURL() +class GlobalLegacyTransformTest extends GroovyTestCase { + def path = "org/codehaus/groovy/transform/META-INF/services/org.codehaus.groovy.transform.ASTTransformation" + URL transformRoot = new File(getClass().classLoader.getResource(path).toURI()).parentFile.parentFile.parentFile.toURI().toURL() void testGlobalTransform() { + def shell = new GroovyShell() shell.classLoader.addURL(transformRoot) shell.evaluate(""" - import org.codehaus.groovy.control.CompilePhase - - if (org.codehaus.groovy.transform.TestTransform.phases == [CompilePhase.CONVERSION, CompilePhase.CLASS_GENERATION]) { - println "Phase sync bug fixed" - } else if (org.codehaus.groovy.transform.TestTransform.phases == [CompilePhase.CONVERSION, CompilePhase.INSTRUCTION_SELECTION]) { - println "Phase sync bug still present" - } else { - assert false, "FAIL" - } + import static org.codehaus.groovy.control.CompilePhase.* + def ph = org.codehaus.groovy.transform.TestTransform.phases + assert ph.TestTransformConversion == [CONVERSION] + assert ph.TestTransformClassGeneration == [CLASS_GENERATION] """) } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/groovy/blob/69b54584/src/test/org/codehaus/groovy/transform/TestTransform.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/transform/TestTransform.groovy b/src/test/org/codehaus/groovy/transform/TestTransform.groovy index c0b3752..587c487 100644 --- a/src/test/org/codehaus/groovy/transform/TestTransform.groovy +++ b/src/test/org/codehaus/groovy/transform/TestTransform.groovy @@ -18,33 +18,31 @@ */ package org.codehaus.groovy.transform +import groovy.transform.CompilationUnitAware import org.codehaus.groovy.ast.ASTNode +import org.codehaus.groovy.control.CompilationUnit import org.codehaus.groovy.control.CompilePhase import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.transform.ASTTransformation -import org.codehaus.groovy.transform.GroovyASTTransformation - -/** - * @author Danno.Ferrin - */ -class TestTransform implements ASTTransformation { +class TestTransform implements ASTTransformation, CompilationUnitAware { static List<ASTNode[]> visitedNodes = [] - static List<CompilePhase> phases = [] + static Map<String, List<CompilePhase>> phases = [:].withDefault{ [] } + CompilationUnit unit = null - public void visit(ASTNode[] nodes, SourceUnit source) { + void visit(ASTNode[] nodes, SourceUnit source) { visitedNodes += nodes - phases += CompilePhase.phases[source.getPhase()] + // TODO work out why source.phase is not equal to unit.phase in all cases + phases[getClass().simpleName] += CompilePhase.phases[unit.phase] } + @Override + void setCompilationUnit(CompilationUnit unit) { + this.unit = unit + } } @GroovyASTTransformation(phase=CompilePhase.CONVERSION) -class TestTransformConversion extends TestTransform { - -} +class TestTransformConversion extends TestTransform { } @GroovyASTTransformation(phase=CompilePhase.CLASS_GENERATION) -class TestTransformClassGeneration extends TestTransform { - -} \ No newline at end of file +class TestTransformClassGeneration extends TestTransform { }
