diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java index 16752d950b..3f6f3ecccc 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java @@ -24,9 +24,11 @@ import static org.junit.Assume.assumeTrue; import java.io.File; +import java.util.Collections; import java.util.Iterator; import java.util.Map; +import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.jdt.groovy.internal.compiler.ast.EventListener; import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope; import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration; @@ -3243,6 +3245,62 @@ public void testImplementingInterface_MethodWithParameters3_JextendsG() { runConformTest(sources, "success"); } + @Test + public void testCallingJavaFromGroovy1() { + //@formatter:off + String[] sources = { + "p/Main.groovy", + "package p\n" + + "class Main {\n" + + " static main(args) {\n" + + " new J().run()\n" + + " print new J().name\n" + + " }\n" + + "}\n", + + "p/J.java", + "package p;\n" + + "public class J {\n" + + " public String name = \"name\";\n" + + " public void run() { System.out.print(\"success\"); }\n" + + "}\n", + }; + //@formatter:on + + runConformTest(sources, "successname"); + } + + @Test + public void testCallingJavaFromGroovy2() { + //@formatter:off + String[] sources = { + "p/Main.groovy", + "package p\n" + + "@Tag(value=4)\n" + + "class Main {\n" + + " static main(args) {\n" + + " new J().run()\n" + + " }\n" + + "}\n", + + "p/J.java", + "package p;\n" + + "public class J {\n" + + " public String name = \"name\";\n" + + " public void run() { System.out.print(\"success\"); }\n" + + "}\n", + + "p/Tag.java", + "package p;\n" + + "public @interface Tag {\n" + + " int value() default 3;\n" + + "}\n", + }; + //@formatter:on + + runConformTest(sources, "success"); + } + @Test public void testCallingMethods_JcallingG() { //@formatter:off @@ -4270,62 +4328,6 @@ public void testClashingMethodsWithDefaultParams() { "----------\n"); } - @Test - public void testCallingJavaFromGroovy1() throws Exception { - //@formatter:off - String[] sources = { - "p/Code.groovy", - "package p;\n" + - "class Code {\n" + - " public static void main(String[] argv) {\n" + - " new J().run();\n" + - " print new J().name;\n" + - " }\n" + - "}\n", - - "p/J.java", - "package p;\n" + - "public class J {\n" + - " public String name = \"name\";\n" + - " public void run() { System.out.print(\"success\"); }\n" + - "}\n", - }; - //@formatter:on - - runConformTest(sources, "successname"); - } - - @Test - public void testCallingJavaFromGroovy2() throws Exception { - //@formatter:off - String[] sources = { - "p/Code.groovy", - "package p;\n" + - "@Wibble(value=4)\n" + - "class Code {\n" + - " public static void main(String[] argv) {\n" + - " new J().run();\n" + - " }\n" + - "}\n", - - "p/J.java", - "package p;\n" + - "public class J {\n" + - " public String name = \"name\";\n" + - " public void run() { System.out.print(\"success\"); }\n" + - "}\n", - - "p/Wibble.java", - "package p;\n" + - "public @interface Wibble {\n" + - " int value() default 3;\n" + - "}\n", - }; - //@formatter:on - - runConformTest(sources, "success"); - } - @Test public void testTypeVariableBoundIsRawType() { //@formatter:off @@ -4609,6 +4611,16 @@ public void testScriptCallJava() { runConformTest(sources, "abc"); } + @Test + public void testConfigDefaults() { + CompilerConfiguration cc = CompilerConfiguration.DEFAULT; + assertEquals(Collections.emptyList(), cc.getClasspath()); + assertEquals(Collections.emptyList(), cc.getCompilationCustomizers()); + assertEquals(Collections.emptyMap(), cc.getJointCompilationOptions()); + assertEquals(Collections.singleton("groovy"), cc.getScriptExtensions()); + assertEquals(Collections.emptySet(), cc.getDisabledGlobalASTTransformations()); + } + @Test public void testConfigScriptWithError() { Map options = getCompilerOptions(); diff --git a/base/org.codehaus.groovy24/src/org/codehaus/groovy/control/CompilerConfiguration.java b/base/org.codehaus.groovy24/src/org/codehaus/groovy/control/CompilerConfiguration.java index 4e54513466..ba6b5386a7 100644 --- a/base/org.codehaus.groovy24/src/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/base/org.codehaus.groovy24/src/org/codehaus/groovy/control/CompilerConfiguration.java @@ -82,7 +82,7 @@ public class CompilerConfiguration { public static final CompilerConfiguration DEFAULT = new CompilerConfiguration() { @Override public List getClasspath() { - return Optional.ofNullable(super.getClasspath()).map(Collections::unmodifiableList).orElse(null); + return Collections.unmodifiableList(super.getClasspath()); } @Override public List getCompilationCustomizers() { @@ -90,19 +90,19 @@ public List getCompilationCustomizers() { } @Override public Set getDisabledGlobalASTTransformations() { - return Optional.ofNullable(super.getDisabledGlobalASTTransformations()).map(Collections::unmodifiableSet).orElse(null); + return Optional.ofNullable(super.getDisabledGlobalASTTransformations()).map(Collections::unmodifiableSet).orElse(Collections.emptySet()); } @Override public Map getJointCompilationOptions() { - return Optional.ofNullable(super.getJointCompilationOptions()).map(Collections::unmodifiableMap).orElse(null); + return Optional.ofNullable(super.getJointCompilationOptions()).map(Collections::unmodifiableMap).orElse(Collections.emptyMap()); } @Override public Map getOptimizationOptions() { - return Optional.ofNullable(super.getOptimizationOptions()).map(Collections::unmodifiableMap).orElse(null); + return Collections.unmodifiableMap(super.getOptimizationOptions()); } @Override public Set getScriptExtensions() { - return Optional.ofNullable(super.getScriptExtensions()).map(Collections::unmodifiableSet).orElse(null); + return Collections.unmodifiableSet(super.getScriptExtensions()); } @Override diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/control/CompilerConfiguration.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/control/CompilerConfiguration.java index 2022eab294..9b709720a4 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/control/CompilerConfiguration.java @@ -139,12 +139,12 @@ public List getCompilationCustomizers() { @Override public Set getDisabledGlobalASTTransformations() { - return Collections.emptySet(); + return Optional.ofNullable(super.getDisabledGlobalASTTransformations()).map(Collections::unmodifiableSet).orElse(Collections.emptySet()); } @Override public Map getJointCompilationOptions() { - return Collections.unmodifiableMap(super.getJointCompilationOptions()); + return Optional.ofNullable(super.getJointCompilationOptions()).map(Collections::unmodifiableMap).orElse(Collections.emptyMap()); } @Override