This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 53657938bb19b2685e859df9d691a7cc1d8f659e Author: Eric Milles <[email protected]> AuthorDate: Sun Apr 24 10:30:25 2022 -0500 add `GroovyShell#withConfig(Closure)` and refactor some unit tests --- .../builder/CompilerCustomizationBuilder.groovy | 36 ++++----- src/main/java/groovy/grape/Grape.java | 6 +- src/main/java/groovy/lang/GroovyShell.java | 23 +++++- .../customizers/builder/CustomizersFactory.java | 15 ++-- .../typing/TypeCheckingExtensionSpecTest.groovy | 14 ++-- .../bugs/DirectMethodCallWithVargsTest.groovy | 93 ++++++++-------------- .../transform/ConditionalInterruptTest.groovy | 12 ++- src/test/groovy/transform/LazyTest.groovy | 10 +-- src/test/groovy/transform/ReadWriteLockTest.groovy | 14 ++-- .../groovy/transform/ThreadInterruptTest.groovy | 12 ++- .../groovy/transform/TimedInterruptTest.groovy | 14 ++-- .../groovy/transform/stc/MethodCallsSTCTest.groovy | 15 ++-- .../groovy/transform/AutoCloneTransformTest.groovy | 8 +- .../groovy/transform/AutoFinalTransformTest.groovy | 7 +- 14 files changed, 123 insertions(+), 156 deletions(-) diff --git a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy index 2ed466d315..c300c50d55 100644 --- a/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy +++ b/src/main/groovy/org/codehaus/groovy/control/customizers/builder/CompilerCustomizationBuilder.groovy @@ -19,6 +19,7 @@ package org.codehaus.groovy.control.customizers.builder +import groovy.transform.AutoFinal import groovy.transform.CompileStatic import org.codehaus.groovy.control.CompilerConfiguration @@ -27,22 +28,28 @@ import org.codehaus.groovy.control.CompilerConfiguration * various compilation customizers by hand, you may use this builder instead, which provides a * shorter syntax and removes most of the verbosity. */ -@CompileStatic +@AutoFinal @CompileStatic class CompilerCustomizationBuilder extends FactoryBuilderSupport { - CompilerCustomizationBuilder() { - registerFactories() - } - static CompilerConfiguration withConfig(CompilerConfiguration config, - @DelegatesTo(type = 'org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder') Closure code) { - CompilerCustomizationBuilder builder = new CompilerCustomizationBuilder() - config.invokeMethod('addCompilationCustomizers', builder.invokeMethod('customizers', code)) + static CompilerConfiguration withConfig(CompilerConfiguration config, @DelegatesTo(type='org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder') Closure spec) { + config.invokeMethod('addCompilationCustomizers', new CompilerCustomizationBuilder().invokeMethod('customizers', spec)) config } + //-------------------------------------------------------------------------- + + CompilerCustomizationBuilder() { + registerFactory('customizers', new CustomizersFactory()) // root + + registerFactory('ast', new ASTTransformationCustomizerFactory()) + registerFactory('imports', new ImportCustomizerFactory()) + registerFactory('inline', new InlinedASTCustomizerFactory()) + registerFactory('secureAst', new SecureASTCustomizerFactory()) + registerFactory('source', new SourceAwareCustomizerFactory()) + } + @Override - @SuppressWarnings('Instanceof') - protected Object postNodeCompletion(final Object parent, final Object node) { + protected Object postNodeCompletion(Object parent, Object node) { Object value = super.postNodeCompletion(parent, node) Object factory = getContextAttribute(CURRENT_FACTORY) if (factory instanceof PostCompletionFactory) { @@ -51,13 +58,4 @@ class CompilerCustomizationBuilder extends FactoryBuilderSupport { } value } - - private void registerFactories() { - registerFactory('ast', new ASTTransformationCustomizerFactory()) - registerFactory('customizers', new CustomizersFactory()) - registerFactory('imports', new ImportCustomizerFactory()) - registerFactory('inline', new InlinedASTCustomizerFactory()) - registerFactory('secureAst', new SecureASTCustomizerFactory()) - registerFactory('source', new SourceAwareCustomizerFactory()) - } } diff --git a/src/main/java/groovy/grape/Grape.java b/src/main/java/groovy/grape/Grape.java index 78e346ba43..5e71bf3b76 100644 --- a/src/main/java/groovy/grape/Grape.java +++ b/src/main/java/groovy/grape/Grape.java @@ -18,7 +18,6 @@ */ package groovy.grape; -import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.security.PrivilegedAction; import java.util.Collections; @@ -121,10 +120,9 @@ public class Grape { if (instance == null) { try { // by default use GrapeIvy - //TODO META-INF/services resolver? + // TODO: META-INF/services resolver? instance = (GrapeEngine) Class.forName("groovy.grape.GrapeIvy").getDeclaredConstructor().newInstance(); - } catch (InstantiationException | ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - //LOGME + } catch (ReflectiveOperationException ignore) { } } return instance; diff --git a/src/main/java/groovy/lang/GroovyShell.java b/src/main/java/groovy/lang/GroovyShell.java index 6630356cc6..e167823d04 100644 --- a/src/main/java/groovy/lang/GroovyShell.java +++ b/src/main/java/groovy/lang/GroovyShell.java @@ -39,6 +39,7 @@ import java.security.PrivilegedExceptionAction; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import static org.codehaus.groovy.control.ResolveVisitor.EMPTY_STRING_ARRAY; import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME; /** @@ -47,17 +48,35 @@ import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME; public class GroovyShell extends GroovyObjectSupport { public static final String DEFAULT_CODE_BASE = "/groovy/shell"; - private static final String[] EMPTY_STRING_ARRAY = new String[0]; + private static final String CONFIGURATION_CUSTOMIZER = "org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder"; private final Binding context; private final AtomicInteger counter = new AtomicInteger(0); private final CompilerConfiguration config; private final GroovyClassLoader loader; - public static void main(String[] args) { + public static void main(final String[] args) { GroovyMain.main(args); } + /** + * @since 4.0.3 + */ + public static GroovyShell withConfig(@DelegatesTo(type = CONFIGURATION_CUSTOMIZER) final Closure<Void> spec) { + //TODO return new GroovyShell(CompilerCustomizationBuilder.withConfig(new CompilerConfiguration(), spec)); + CompilerConfiguration config = new CompilerConfiguration(); + try { + Class.forName(CONFIGURATION_CUSTOMIZER) + .getDeclaredMethod("withConfig", CompilerConfiguration.class, Closure.class) + .invoke(null, config, spec); + } catch (ReflectiveOperationException e) { + throw new GroovyRuntimeException(e); + } + return new GroovyShell(config); + } + + //-------------------------------------------------------------------------- + public GroovyShell() { this(null, new Binding()); } diff --git a/src/main/java/org/codehaus/groovy/control/customizers/builder/CustomizersFactory.java b/src/main/java/org/codehaus/groovy/control/customizers/builder/CustomizersFactory.java index 4f86a90156..c9b512acd4 100644 --- a/src/main/java/org/codehaus/groovy/control/customizers/builder/CustomizersFactory.java +++ b/src/main/java/org/codehaus/groovy/control/customizers/builder/CustomizersFactory.java @@ -22,9 +22,8 @@ import groovy.util.AbstractFactory; import groovy.util.FactoryBuilderSupport; import org.codehaus.groovy.control.customizers.CompilationCustomizer; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; -import java.util.List; import java.util.Map; /** @@ -32,29 +31,25 @@ import java.util.Map; * * @since 2.1.0 */ +@SuppressWarnings({"unchecked","rawtypes"}) public class CustomizersFactory extends AbstractFactory implements PostCompletionFactory { - private static final CompilationCustomizer[] EMPTY_COMPILATIONCUSTOMIZER_ARRAY = new CompilationCustomizer[0]; @Override public Object newInstance(final FactoryBuilderSupport builder, final Object name, final Object value, final Map attributes) throws InstantiationException, IllegalAccessException { - return new LinkedList(); + return new ArrayList(); } @Override - @SuppressWarnings("unchecked") public void setChild(final FactoryBuilderSupport builder, final Object parent, final Object child) { if (parent instanceof Collection && child instanceof CompilationCustomizer) { ((Collection) parent).add(child); } } - @Override - @SuppressWarnings("unchecked") public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) { - if (node instanceof List) { - List col = (List) node; - return col.toArray(EMPTY_COMPILATIONCUSTOMIZER_ARRAY); + if (node instanceof Collection) { + return ((Collection) node).toArray(new CompilationCustomizer[0]); } return node; } diff --git a/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy b/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy index 56e19d3262..7da5b6ff7f 100644 --- a/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy +++ b/src/spec/test/typing/TypeCheckingExtensionSpecTest.groovy @@ -22,13 +22,11 @@ import groovy.test.GroovyAssert import groovy.test.GroovyTestCase import groovy.transform.TypeChecked import groovy.xml.MarkupBuilder -import org.codehaus.groovy.control.CompilerConfiguration import org.codehaus.groovy.control.MultipleCompilationErrorsException -import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer import static asciidoctor.Utils.stripAsciidocMarkup -class TypeCheckingExtensionSpecTest extends GroovyTestCase { +final class TypeCheckingExtensionSpecTest extends GroovyTestCase { void testIntro() { def out = new PrintWriter(new ByteArrayOutputStream()) @@ -613,13 +611,11 @@ new DelegateTest().delegate() } private def assertScriptWithExtension(String extensionName, String code, Closure<Void> configurator=null) { - def config = new CompilerConfiguration() - config.addCompilationCustomizers( - new ASTTransformationCustomizer(TypeChecked, extensions:[extensionName])) - def binding = new Binding() - def shell = new GroovyShell(binding,config) + def shell = GroovyShell.withConfig { + ast(TypeChecked, extensions: [extensionName]) + } if (configurator) { - configurator.call(binding) + configurator.call(shell.context) } shell.evaluate(code) } diff --git a/src/test/groovy/bugs/DirectMethodCallWithVargsTest.groovy b/src/test/groovy/bugs/DirectMethodCallWithVargsTest.groovy index bbdd658c97..1abd390f12 100644 --- a/src/test/groovy/bugs/DirectMethodCallWithVargsTest.groovy +++ b/src/test/groovy/bugs/DirectMethodCallWithVargsTest.groovy @@ -18,29 +18,23 @@ */ package groovy.bugs -import groovy.test.GroovyTestCase import org.codehaus.groovy.ast.ClassCodeVisitorSupport -import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.ast.expr.MethodCallExpression import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.CompilationCustomizer -import org.codehaus.groovy.control.CompilePhase -import org.codehaus.groovy.classgen.GeneratorContext -import org.codehaus.groovy.ast.ClassNode +import org.codehaus.groovy.ast.expr.MethodCallExpression +import org.codehaus.groovy.control.SourceUnit +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript -class DirectMethodCallWithVargsTest extends GroovyTestCase { +final class DirectMethodCallWithVargsTest { + @Test void testDirectMethodCallWithVargs() { - def config = new CompilerConfiguration() - config.addCompilationCustomizers( - new MyCustomizer() - ) - GroovyShell shell = new GroovyShell(config) - shell.evaluate ''' + assertScript shell, ''' def foo(String... args) { (args as List).join(',') } + assert foo() == '' assert foo('1') == '1' assert foo('1','2','3') == '1,2,3' @@ -50,20 +44,16 @@ class DirectMethodCallWithVargsTest extends GroovyTestCase { def b = '2' def c = '3' assert foo(a,b,c) == '1,2,3' - ''' } + @Test void testDirectMethodCallWithPrimitiveVargs() { - def config = new CompilerConfiguration() - config.addCompilationCustomizers( - new MyCustomizer() - ) - GroovyShell shell = new GroovyShell(config) - shell.evaluate ''' + assertScript shell, ''' def foo(int... args) { (args as List).join(',') } + assert foo() == '' assert foo(1) == '1' assert foo(1,2,3) == '1,2,3' @@ -71,16 +61,13 @@ class DirectMethodCallWithVargsTest extends GroovyTestCase { ''' } - void testDirectMethodCallWithArgPlusVargs() { - def config = new CompilerConfiguration() - config.addCompilationCustomizers( - new MyCustomizer() - ) - GroovyShell shell = new GroovyShell(config) - shell.evaluate ''' + @Test + void testDirectMethodCallWithArgumentAndVargs() { + assertScript shell, ''' def foo(String prefix, String... args) { prefix+(args as List).join(',') } + assert foo('A') == 'A' assert foo('A','1') == 'A1' assert foo('A','1','2','3') == 'A1,2,3' @@ -90,20 +77,16 @@ class DirectMethodCallWithVargsTest extends GroovyTestCase { def b = '2' def c = '3' assert foo('A',a,b,c) == 'A1,2,3' - ''' } - void testDirectMethodCallWithPrefixAndPrimitiveVargs() { - def config = new CompilerConfiguration() - config.addCompilationCustomizers( - new MyCustomizer() - ) - GroovyShell shell = new GroovyShell(config) - shell.evaluate ''' + @Test + void testDirectMethodCallWithArgumentAndPrimitiveVargs() { + assertScript shell, ''' def foo(int prefix, int... args) { "$prefix"+(args as List).join(',') } + assert foo(1) == '1' assert foo(1,1) == '11' assert foo(1,1,2,3) == '11,2,3' @@ -111,50 +94,36 @@ class DirectMethodCallWithVargsTest extends GroovyTestCase { ''' } - private static class MyCustomizer extends CompilationCustomizer { + //-------------------------------------------------------------------------- - MyCustomizer() { - super(CompilePhase.CANONICALIZATION) - } - - @Override - void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) { - def visitor = new MethodCallVisitor(source) - classNode.methods.each { visitor.visitMethod(it) } + private final GroovyShell shell = GroovyShell.withConfig { + inline(phase: 'CANONICALIZATION') { sourceUnit, x, classNode -> + def visitor = new MethodCallVisitor(sourceUnit) + classNode.methods.each(visitor.&acceptMethod) visitor.visitClass(classNode) } } private static class MethodCallVisitor extends ClassCodeVisitorSupport { - private final SourceUnit unit private MethodNode fooMethod + final SourceUnit sourceUnit - MethodCallVisitor(SourceUnit source) { - unit = source - } - - @Override - protected SourceUnit getSourceUnit() { - return unit + MethodCallVisitor(final SourceUnit unit) { + sourceUnit = unit } - @Override - void visitMethod(final MethodNode node) { - super.visitMethod(node) - if (node.name=='foo') { + void acceptMethod(final MethodNode node) { + if (node.name == 'foo') { fooMethod = node } } - @Override void visitMethodCallExpression(final MethodCallExpression call) { super.visitMethodCallExpression(call) - if (call.methodAsString=='foo') { + if (call.methodAsString == 'foo') { call.methodTarget = fooMethod } } - - } } diff --git a/src/test/groovy/transform/ConditionalInterruptTest.groovy b/src/test/groovy/transform/ConditionalInterruptTest.groovy index cb86990292..330c9914a0 100644 --- a/src/test/groovy/transform/ConditionalInterruptTest.groovy +++ b/src/test/groovy/transform/ConditionalInterruptTest.groovy @@ -18,8 +18,6 @@ */ package groovy.transform -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.junit.Test import static groovy.test.GroovyAssert.assertScript @@ -29,12 +27,12 @@ import static groovy.test.GroovyAssert.assertScript */ final class ConditionalInterruptTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().addCompilationCustomizers( - new ImportCustomizer().tap { - addStarImports('groovy.transform') - addStaticImport('groovy.test.GroovyAssert', 'shouldFail') + private final GroovyShell shell = GroovyShell.withConfig { + imports { + star 'groovy.transform' + staticMember 'groovy.test.GroovyAssert', 'shouldFail' } - )) + } @Test void testMethodIsVisited_AndExceptionMessage() { diff --git a/src/test/groovy/transform/LazyTest.groovy b/src/test/groovy/transform/LazyTest.groovy index bdfc19e059..c16d54f595 100644 --- a/src/test/groovy/transform/LazyTest.groovy +++ b/src/test/groovy/transform/LazyTest.groovy @@ -18,8 +18,6 @@ */ package groovy.transform -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.junit.Test import static groovy.test.GroovyAssert.assertScript @@ -29,9 +27,11 @@ import static groovy.test.GroovyAssert.assertScript */ final class LazyTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().addCompilationCustomizers( - new ImportCustomizer().tap { addStaticStars('java.lang.reflect.Modifier') } - )) + private final GroovyShell shell = GroovyShell.withConfig { + imports { + staticStar 'java.lang.reflect.Modifier' + } + } @Test void testLazyPrimitiveWrapping() { diff --git a/src/test/groovy/transform/ReadWriteLockTest.groovy b/src/test/groovy/transform/ReadWriteLockTest.groovy index 7a77bb05a9..91e7de5f4e 100644 --- a/src/test/groovy/transform/ReadWriteLockTest.groovy +++ b/src/test/groovy/transform/ReadWriteLockTest.groovy @@ -18,8 +18,6 @@ */ package groovy.transform -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.junit.Test import static groovy.test.GroovyAssert.assertScript @@ -30,13 +28,13 @@ import static groovy.test.GroovyAssert.shouldFail */ final class ReadWriteLockTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().addCompilationCustomizers( - new ImportCustomizer().tap { - addStarImports('groovy.transform') - addStaticStars('java.lang.reflect.Modifier') - addImport('java.util.concurrent.locks.ReentrantReadWriteLock') + private final GroovyShell shell = GroovyShell.withConfig { + imports { + star 'groovy.transform' + staticStar 'java.lang.reflect.Modifier' + normal 'java.util.concurrent.locks.ReentrantReadWriteLock' } - )) + } @Test void testLockFieldDefaultsForReadLock() { diff --git a/src/test/groovy/transform/ThreadInterruptTest.groovy b/src/test/groovy/transform/ThreadInterruptTest.groovy index bc7f3a2b22..95cd0242ec 100644 --- a/src/test/groovy/transform/ThreadInterruptTest.groovy +++ b/src/test/groovy/transform/ThreadInterruptTest.groovy @@ -20,8 +20,6 @@ package groovy.transform import groovy.mock.interceptor.StubFor import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.codehaus.groovy.transform.ThreadInterruptibleASTTransformation import org.junit.After import org.junit.Before @@ -39,12 +37,12 @@ import static org.junit.Assume.assumeTrue */ final class ThreadInterruptTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().addCompilationCustomizers( - new ImportCustomizer().tap { - addStarImports('groovy.transform') - addImport('groovy.mock.interceptor.StubFor') + private final GroovyShell shell = GroovyShell.withConfig { + imports { + star 'groovy.transform' + normal 'groovy.mock.interceptor.StubFor' } - )) + } private static final boolean jdk12plus = isAtLeastJdk('12.0') private Map<String, MethodNode> oldValues = [:] diff --git a/src/test/groovy/transform/TimedInterruptTest.groovy b/src/test/groovy/transform/TimedInterruptTest.groovy index b4aadbde3e..2108c83a26 100644 --- a/src/test/groovy/transform/TimedInterruptTest.groovy +++ b/src/test/groovy/transform/TimedInterruptTest.groovy @@ -19,9 +19,7 @@ package groovy.transform import groovy.mock.interceptor.StubFor -import org.codehaus.groovy.control.CompilerConfiguration import org.codehaus.groovy.control.MultipleCompilationErrorsException -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.junit.Test import java.util.concurrent.TimeoutException @@ -34,13 +32,13 @@ import static groovy.test.GroovyAssert.shouldFail */ final class TimedInterruptTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().addCompilationCustomizers( - new ImportCustomizer().tap { - addStarImports('groovy.transform') - addStaticStars(TimedInterruptTest.name) - addImport('groovy.mock.interceptor.StubFor') + private final GroovyShell shell = GroovyShell.withConfig { + imports { + star 'groovy.transform' + staticStar TimedInterruptTest.name + normal 'groovy.mock.interceptor.StubFor' } - )) + } @Test void testClassMethodIsVisited() { diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy index 779c84f4f8..3b11fc9e83 100644 --- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy +++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy @@ -20,7 +20,8 @@ package groovy.transform.stc import org.codehaus.groovy.control.MultipleCompilationErrorsException import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer -import org.codehaus.groovy.control.customizers.ImportCustomizer + +import static org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder.withConfig /** * Unit tests for static type checking : method calls. @@ -29,11 +30,13 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase { @Override protected void configure() { - config.addCompilationCustomizers(new ImportCustomizer().tap { - addImport('A', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass' ) - addImport('B', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass2') - addImport('C', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass3') - }) + withConfig(config) { + imports { + alias 'A', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass' + alias 'B', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass2' + alias 'C', 'groovy.transform.stc.MethodCallsSTCTest.MyMethodCallTestClass3' + } + } } void testMethodCallOnInstance() { diff --git a/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy index c0d2674863..81b3d60613 100644 --- a/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy +++ b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy @@ -18,8 +18,6 @@ */ package org.codehaus.groovy.transform -import org.codehaus.groovy.control.CompilerConfiguration -import org.codehaus.groovy.control.customizers.ImportCustomizer import org.junit.Test import static groovy.test.GroovyAssert.assertScript @@ -30,9 +28,9 @@ import static groovy.test.GroovyAssert.shouldFail */ final class AutoCloneTransformTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration(). - addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoClone') }) - ) + private final GroovyShell shell = GroovyShell.withConfig { + imports { normal 'groovy.transform.AutoClone' } + } @Test void testBasics() { diff --git a/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy index 854b788e6e..99422ffa13 100644 --- a/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy +++ b/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy @@ -18,7 +18,6 @@ */ package org.codehaus.groovy.transform -import org.codehaus.groovy.control.CompilerConfiguration import org.codehaus.groovy.control.customizers.* import org.junit.Test @@ -30,9 +29,9 @@ import static groovy.test.GroovyAssert.shouldFail */ final class AutoFinalTransformTest { - private final GroovyShell shell = new GroovyShell(new CompilerConfiguration(). - addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoFinal', 'groovy.transform.ASTTest') }) - ) + private final GroovyShell shell = GroovyShell.withConfig { + imports { normal 'groovy.transform.AutoFinal', 'groovy.transform.ASTTest' } + } @Test void testAutoFinalOnClass() {
