Skip to content

Commit

Permalink
Eclipse 4.22 (M1) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 2, 2021
1 parent 298e4be commit 1c7dd66
Show file tree
Hide file tree
Showing 2,107 changed files with 1,259,336 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public void testEnum13() {
"}\n" +
"\n" +
"class A {\n" +
" public enum C2{\n" +
" enum C2{\n" +
" TEST_C2\n" +
" }\n" +
"}\n",
Expand Down Expand Up @@ -699,6 +699,26 @@ public void testEnum13() {
//@formatter:on

runConformTest(sources);

checkGCUDeclaration("A.groovy",
"package be.flow;\n" +
"public enum C1 {\n" +
" TEST_C1,\n" +
" private @groovy.transform.Generated C1() {\n" +
" }\n" +
"}\n" +
"public class A {\n" +
" public static enum C2 {\n" +
" TEST_C2,\n" +
" private @groovy.transform.Generated C2() {\n" +
" }\n" +
" }\n" +
" public @groovy.transform.Generated A() {\n" +
" }\n" +
"}");

checkDisassemblyFor("be/flow/A$C2.class",
"public static final enum be.flow.A$C2 implements ");
}

@Test
Expand Down Expand Up @@ -914,6 +934,9 @@ public void testAbstractMethodWithinEnum1() {
" }\n" +
" public abstract int foo();\n" +
"}");

checkDisassemblyFor("Good.class", "public abstract enum Good ");
checkDisassemblyFor("Good$1.class", "\nfinal enum Good$1 {\n ");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public abstract class GroovyCompilerTestSuite {
protected static final long JDK14 = (58L << 16) + ClassFileConstants.MINOR_VERSION_0;
protected static final long JDK15 = (59L << 16) + ClassFileConstants.MINOR_VERSION_0;
protected static final long JDK16 = (60L << 16) + ClassFileConstants.MINOR_VERSION_0;
protected static final long JDK17 = (60L << 17) + ClassFileConstants.MINOR_VERSION_0;
protected static final long JDK17 = (61L << 16) + ClassFileConstants.MINOR_VERSION_0;

@Parameters(name = "Java {1}")
public static Iterable<Object[]> params() {
Expand Down Expand Up @@ -170,8 +170,12 @@ public String getName() {

@Override
protected INameEnvironment getNameEnvironment(final String[] testFiles, final String[] classPaths) {
this.classpaths = (classPaths == null ? getDefaultClassPaths() : classPaths);
return new InMemoryNameEnvironment(testFiles, getClassLibs(false));
return getNameEnvironment(testFiles, classPaths, null);
}

protected INameEnvironment getNameEnvironment(final String[] testFiles, final String[] classPaths, final Map<String, String> options) {
this.classpaths = (classPaths != null ? classPaths : getDefaultClassPaths());
return new InMemoryNameEnvironment(testFiles, getClassLibs(false, options));
}

private String resolve(final URL jarRef) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ protected Expression anonymousInnerClassDef(AST node) {
ClassNode outerClass = getClassOrScript(oldNode);
String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1);
if (enumConstantBeingDef) {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
} else {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE);
} else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
}
((InnerClassNode) classNode).setAnonymous(true);
Expand Down Expand Up @@ -1035,8 +1035,9 @@ protected void enumConstantDef(AST node) {
// we have to handle an enum constant with a class overriding
// a method in which case we need to configure the inner class
innerClass.setSuperClass(classNode.getPlainNodeReference());
/* GRECLIPSE edit
innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL);
// GRECLIPSE add
*/
innerClass.setNameStart(nameStart);
innerClass.setNameEnd(nameEnd - 1);
// GRECLIPSE end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,9 @@ public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) {
this.hackMixins(classNode);

} else if (isEnum) {
/* GRECLIPSE edit -- EnumHelper#makeEnumNode does this
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL);
*/
classNode.setInterfaces(this.visitTypeList(ctx.is));
this.initUsingGenerics(classNode);

Expand Down Expand Up @@ -3657,7 +3659,7 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(AnonymousInnerClassDec

InnerClassNode anonymousInnerClass;
if (1 == ctx.t) { // anonymous enum
anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, superClass.getModifiers() | Opcodes.ACC_FINAL, superClass.getPlainNodeReference());
anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, superClass.getPlainNodeReference());
// and remove the final modifier from classNode to allow the sub class
superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL);
} else { // anonymous inner class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ protected Expression anonymousInnerClassDef(AST node) {
ClassNode outerClass = getClassOrScript(oldNode);
String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1);
if (enumConstantBeingDef) {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
} else {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE);
} else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
}
((InnerClassNode) classNode).setAnonymous(true);
Expand Down Expand Up @@ -1123,8 +1123,9 @@ protected void enumConstantDef(AST node) {
// we have to handle an enum constant with a class overriding
// a method in which case we need to configure the inner class
innerClass.setSuperClass(classNode.getPlainNodeReference());
/* GRECLIPSE edit
innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL);
// GRECLIPSE add
*/
innerClass.setNameStart(nameStart);
innerClass.setNameEnd(nameEnd - 1);
// GRECLIPSE end
Expand Down
Binary file modified base/org.codehaus.groovy40/groovy-parser2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,7 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) {

if ((isAnnotation || isEnum) && (isSealed || isNonSealed)) {
ModifierNode mn = isSealed ? sealedModifierNodeOptional.get() : nonSealedModifierNodeOptional.get();
throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed for " +
(isEnum ? "enum" : "annotation definition"), mn);
throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed for " + (isEnum ? "enum" : "annotation definition"), mn);
}

boolean hasPermits = asBoolean(ctx.PERMITS());
Expand Down Expand Up @@ -1613,7 +1612,9 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) {
this.hackMixins(classNode);

} else if (isEnum) {
/* GRECLIPSE edit -- EnumHelper#makeEnumNode does this
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL);
*/
classNode.setInterfaces(this.visitTypeList(ctx.is));
this.initUsingGenerics(classNode);

Expand Down Expand Up @@ -3829,7 +3830,7 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(final AnonymousInnerCl

InnerClassNode anonymousInnerClass;
if (1 == ctx.t) { // anonymous enum
anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, superClass.getModifiers() | Opcodes.ACC_FINAL, superClass.getPlainNodeReference());
anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, superClass.getPlainNodeReference());
// and remove the final modifier from classNode to allow the sub class
superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL);
} else { // anonymous inner class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ protected Expression anonymousInnerClassDef(AST node) {
ClassNode outerClass = getClassOrScript(oldNode);
String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1);
if (enumConstantBeingDef) {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
} else {
classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE);
} else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
}
((InnerClassNode) classNode).setAnonymous(true);
Expand Down Expand Up @@ -1123,8 +1123,9 @@ protected void enumConstantDef(AST node) {
// we have to handle an enum constant with a class overriding
// a method in which case we need to configure the inner class
innerClass.setSuperClass(classNode.getPlainNodeReference());
/* GRECLIPSE edit
innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL);
// GRECLIPSE add
*/
innerClass.setNameStart(nameStart);
innerClass.setNameEnd(nameEnd - 1);
// GRECLIPSE end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ private void createTypeDeclarations(ModuleNode moduleNode) {
}

boolean isEnum = classNode.isEnum();
configureSuperClass(typeDeclaration, classNode.getSuperClass(), isEnum, isTrait(classNode));
if (!isEnum && !isTrait(classNode)) configureSuperClass(typeDeclaration, classNode.getSuperClass());
configureSuperInterfaces(typeDeclaration, classNode);
typeDeclaration.fields = createFieldDeclarations(classNode, isEnum);
typeDeclaration.methods = createConstructorAndMethodDeclarations(classNode, isEnum, typeDeclaration);
Expand Down Expand Up @@ -1546,15 +1546,9 @@ private AbstractMethodDeclaration createMethodDeclaration(ClassNode classNode, M

//----------------------------------------------------------------------

private void configureSuperClass(TypeDeclaration typeDeclaration, ClassNode superclass, boolean isEnum, boolean isTrait) {
if ((isEnum && superclass.getName().equals("java.lang.Enum")) || isTrait) {
// Don't wire it in, JDT will do it
typeDeclaration.superclass = null;
} else {
// If the start position is 0 the superclass wasn't actually declared, it was added by Groovy
if (!(superclass.getStart() == 0 && superclass.equals(ClassHelper.OBJECT_TYPE))) {
typeDeclaration.superclass = createTypeReferenceForClassNode(superclass);
}
private void configureSuperClass(TypeDeclaration typeDeclaration, ClassNode superclass) {
if (!(superclass.getStart() == 0 && superclass.equals(ClassHelper.OBJECT_TYPE))) {
typeDeclaration.superclass = createTypeReferenceForClassNode(superclass);
}
}

Expand Down
9 changes: 5 additions & 4 deletions docs/Getting-Started-with-Groovy-Eclipse-Source-Code.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ This minimal project set should be open in your workspace:
* org.eclipse.jdt.groovy.core.tests.builder
* org.eclipse.jdt.groovy.core.tests.compiler

Note: Only one JDT patch should be imported (`org.eclipse.jdt.core`, `org.eclipse.jdt.core.tests.builder`, `org.eclipse.jdt.core.tests.compiler`) and it should be matched to the target platform of your workspace. For example, the patch in the `/e421` folder is for Eclipse 4.21 (2021-09).
Note: Only one JDT patch should be imported (`org.eclipse.jdt.core`, `org.eclipse.jdt.core.tests.builder`, `org.eclipse.jdt.core.tests.compiler`) and it should be matched to the target platform of your workspace. For example, the patch in the `/e422` folder is for Eclipse 4.22 (2021-12).


## Test with Eclipse
Expand All @@ -185,14 +185,15 @@ For manual testing and debugging, right-click on the org.codehaus.groovy.eclipse

[Download and install Maven](https://maven.apache.org/).

From the root directory of the repository, execute the following command to build Groovy-Eclipse for Eclipse 4.21 (2021-09).
From the root directory of the repository, execute the following command to build Groovy-Eclipse for Eclipse 4.22 (2021-12).

```
mvn -Pe4.21 clean install
mvn -Pe4.22 clean install
```

Replace e4.21 with a different option to build it for another Eclipse version:
Replace e4.22 with a different option to build it for another Eclipse version:

* e4.21
* e4.20
* e4.19
* e4.18
Expand Down
54 changes: 28 additions & 26 deletions groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
defaultValue="2020-06"
storageURI="scope://Workspace"
label="Target Platform">
<choice
value="2021-12"
label="Eclipse 4.22 (2021-12)"/>
<choice
value="2021-09"
label="Eclipse 4.21 (2021-09)"/>
Expand All @@ -87,9 +90,6 @@
<choice
value="2020-09"
label="Eclipse 4.17 (2020-09)"/>
<choice
value="2020-06"
label="Eclipse 4.16 (2020-06)"/>
<description>Choose the compatibility level of the target platform</description>
</setupTask>
<setupTask
Expand Down Expand Up @@ -126,7 +126,15 @@
</setupTask>
<setupTask
xsi:type="setup.p2:P2Task"
filter="(| (scope.product.version.name=2021-09) (scope.product.version.name=latest) (scope.product.version.name=latest.released))">
filter="(| (scope.product.version.name=2021-12) (scope.product.version.name=latest))">
<requirement
name="org.codehaus.groovy.m2eclipse.feature.feature.group"/>
<repository
url="https://dist.springsource.org/snapshot/GRECLIPSE/e4.22"/>
</setupTask>
<setupTask
xsi:type="setup.p2:P2Task"
filter="(| (scope.product.version.name=2021-09) (scope.product.version.name=latest.released))">
<requirement
name="org.codehaus.groovy.m2eclipse.feature.feature.group"/>
<repository
Expand Down Expand Up @@ -164,14 +172,6 @@
<repository
url="https://dist.springsource.org/snapshot/GRECLIPSE/e4.17"/>
</setupTask>
<setupTask
xsi:type="setup.p2:P2Task"
filter="(scope.product.version.name=2020-06)">
<requirement
name="org.codehaus.groovy.m2eclipse.feature.feature.group"/>
<repository
url="https://dist.springsource.org/snapshot/GRECLIPSE/e4.16"/>
</setupTask>
<setupTask
xsi:type="git:GitCloneTask"
id="git.clone.Groovy-Eclipse"
Expand Down Expand Up @@ -225,6 +225,13 @@
<sourceLocator
rootFolder="${git.clone.Groovy-Eclipse.location}/Site-org.codehaus.groovy.eclipse"/>
</setupTask>
<setupTask
xsi:type="projects:ProjectsImportTask"
filter="(eclipse.target.platform=2021-12)">
<sourceLocator
rootFolder="${git.clone.Groovy-Eclipse.location}/jdt-patch/e422"
locateNestedProjects="true"/>
</setupTask>
<setupTask
xsi:type="projects:ProjectsImportTask"
filter="(eclipse.target.platform=2021-09)">
Expand Down Expand Up @@ -260,13 +267,6 @@
rootFolder="${git.clone.Groovy-Eclipse.location}/jdt-patch/e417"
locateNestedProjects="true"/>
</setupTask>
<setupTask
xsi:type="projects:ProjectsImportTask"
filter="(eclipse.target.platform=2020-06)">
<sourceLocator
rootFolder="${git.clone.Groovy-Eclipse.location}/jdt-patch/e416"
locateNestedProjects="true"/>
</setupTask>
<setupTask
xsi:type="setup.targlets:TargletTask">
<targlet
Expand All @@ -286,6 +286,15 @@
name="org.eclipse.buildship.feature.group"/>
<requirement
name="org.eclipse.test.feature.group"/>
<repositoryList
name="2020-06">
<repository
url="https://download.eclipse.org/releases/2021-12"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.22"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.22-I-builds/I20210929-1800"/>
</repositoryList>
<repositoryList
name="2021-09">
<repository
Expand Down Expand Up @@ -321,13 +330,6 @@
<repository
url="https://download.eclipse.org/eclipse/updates/4.17"/>
</repositoryList>
<repositoryList
name="2020-06">
<repository
url="https://download.eclipse.org/releases/2020-06"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.16"/>
</repositoryList>
</targlet>
</setupTask>
<setupTask
Expand Down
4 changes: 2 additions & 2 deletions ide-test/org.codehaus.groovy.alltests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

<!-- Useful references:
https://wiki.eclipse.org/Tycho/Packaging_Types#eclipse-test-plugin
https://www.eclipse.org/tycho/sitedocs/tycho-surefire/tycho-surefire-plugin/test-mojo.html
https://www.eclipse.org/tycho/sitedocs/tycho-surefire-plugin/test-mojo.html
-->
<configuration>
<argLine>-Xmx1G -XX:-OmitStackTraceInFastThrow</argLine>
<forkedProcessTimeoutInSeconds>9000</forkedProcessTimeoutInSeconds>
<forkedProcessTimeoutInSeconds>7200</forkedProcessTimeoutInSeconds>
<showEclipseLog>true</showEclipseLog>
<testFailureIgnore>true</testFailureIgnore>
<useUIHarness>true</useUIHarness>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className)
}

protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
return getClassLibs(useDefaultClasspaths, null);
}
protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map<String, String> options) {
String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding);
if ("".equals(encoding))
encoding = null;
if (useDefaultClasspaths && encoding == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className)
}

protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
return getClassLibs(useDefaultClasspaths, null);
}
protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map<String, String> options) {
String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding);
if ("".equals(encoding))
encoding = null;
if (useDefaultClasspaths && encoding == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className)
}

protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
return getClassLibs(useDefaultClasspaths, null);
}
protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map<String, String> options) {
String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding);
if ("".equals(encoding))
encoding = null;
if (useDefaultClasspaths && encoding == null)
Expand Down
Loading

0 comments on commit 1c7dd66

Please sign in to comment.