Skip to content

Commit 0db55ae

Browse files
committed
GROOVY-10199
1 parent fea9315 commit 0db55ae

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/ASTTestTests.java

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;
1919

20+
import org.eclipse.core.runtime.FileLocator;
21+
import org.eclipse.core.runtime.Platform;
2022
import org.eclipse.jdt.groovy.core.tests.basic.GroovyCompilerTestSuite;
2123
import org.junit.Test;
2224

@@ -102,4 +104,25 @@ public void testASTTest4() {
102104

103105
runConformTest(sources);
104106
}
107+
108+
@Test // GROOVY-10199
109+
public void testASTTest5() throws Exception {
110+
java.net.URL bundleEntry = Platform.getBundle("org.eclipse.jdt.groovy.core.tests.compiler").getEntry("astTransformations/transforms.jar");
111+
cpAdditions = new String[] {FileLocator.toFileURL(bundleEntry).getPath()};
112+
113+
//@formatter:off
114+
String[] sources = {
115+
"Main.groovy",
116+
"@groovy.transform.ASTTest(value={\n" +
117+
" print examples.local.LoggingExample\n" + // Cannot get property 'local' on null object
118+
"})\n" +
119+
"class Main {\n" +
120+
" static main(args) {\n" +
121+
" }\n" +
122+
"}\n",
123+
};
124+
//@formatter:on
125+
126+
runConformTest(sources);
127+
}
105128
}

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/UserDefinedTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2020 the original author or authors.
2+
* Copyright 2009-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,17 +21,14 @@
2121
import org.junit.Test;
2222

2323
/**
24-
* Test cases for user-defined AST transformations. The required library (aka
25-
* <tt>astTransformations/transforms.jar</tt>) is added to compiler classpath
26-
* in {@link GroovyCompilerTestSuite}.
24+
* Test cases for user-defined AST transformations.
2725
*/
2826
public final class UserDefinedTests extends GroovyCompilerTestSuite {
2927

3028
@Test
3129
public void testWithLogging() throws Exception {
32-
cpAdditions = new String[] {
33-
FileLocator.toFileURL(Platform.getBundle("org.eclipse.jdt.groovy.core.tests.compiler").getEntry("astTransformations/transforms.jar")).getPath()
34-
};
30+
java.net.URL bundleEntry = Platform.getBundle("org.eclipse.jdt.groovy.core.tests.compiler").getEntry("astTransformations/transforms.jar");
31+
cpAdditions = new String[] {FileLocator.toFileURL(bundleEntry).getPath()};
3532

3633
//@formatter:off
3734
String[] sources = {

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/ASTTestTransformation.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ASTTestTransformation extends AbstractASTTransformation implements Compila
124124
binding['compilationUnit'] = compilationUnit
125125
binding['compilePhase'] = CompilePhase.fromPhaseNumber(phaseRef)
126126

127-
GroovyShell shell = new GroovyShell(binding, config)
127+
GroovyShell shell = new GroovyShell(/*GRECLIPSE add*/compilationUnit.transformLoader,/**/binding, config)
128128

129129
source.AST.imports.each {
130130
customizer.addImport(it.alias, it.type.name)

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/ASTTestTransformation.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ class ASTTestTransformation implements ASTTransformation, CompilationUnitAware {
140140

141141
def config = new CompilerConfiguration()
142142
config.addCompilationCustomizers(customizer)
143-
// GRECLIPSE add
144-
try {
145-
// GRECLIPSE end
143+
/* GRECLIPSE edit
146144
new GroovyShell(binding, config).evaluate(testSource)
147-
// GRECLIPSE add
145+
*/
146+
try {
147+
new GroovyShell(compilationUnit.transformLoader, binding, config).evaluate(testSource)
148148
} catch (Throwable t) {
149149
source.addErrorAndContinue(new SyntaxException(" ASTTest exception: $t.message", t,
150150
annotationNode.lineNumber, annotationNode.columnNumber, annotationNode.classNode.lastLineNumber, annotationNode.classNode.lastColumnNumber

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/ASTTestTransformation.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ class ASTTestTransformation implements ASTTransformation, CompilationUnitAware {
160160

161161
def config = new CompilerConfiguration()
162162
config.addCompilationCustomizers(customizer)
163-
// GRECLIPSE add
164-
try {
165-
// GRECLIPSE end
163+
/* GRECLIPSE edit
166164
new GroovyShell(binding, config).evaluate(testSource)
167-
// GRECLIPSE add
165+
*/
166+
try {
167+
new GroovyShell(compilationUnit.transformLoader, binding, config).evaluate(testSource)
168168
} catch (Throwable t) {
169169
sourceUnit.addErrorAndContinue(new SyntaxException(" ASTTest exception: $t.message", t, astNode.lineNumber, astNode.columnNumber))
170170
}

0 commit comments

Comments
 (0)