Skip to content

Commit 6644009

Browse files
committed
GROOVY-9259
1 parent f785b29 commit 6644009

File tree

3 files changed

+55
-9
lines changed
  • base
  • base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic

3 files changed

+55
-9
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

+36
Original file line numberDiff line numberDiff line change
@@ -4297,6 +4297,42 @@ public void testImplementingInterface9() {
42974297
runConformTest(sources, "8:30pm");
42984298
}
42994299

4300+
@Test // GROOVY-9259
4301+
public void testImplementingInterface10() {
4302+
assumeTrue(isParrotParser()); // TODO: support default in antlr2 parser?
4303+
4304+
//@formatter:off
4305+
String[] sources = {
4306+
"Script.groovy",
4307+
"print new C().m()\n",
4308+
4309+
"A.java",
4310+
"public interface A {\n" +
4311+
" String m();\n" +
4312+
"}\n",
4313+
4314+
"B.groovy",
4315+
"interface B extends A {\n" +
4316+
" default String m() {\n" +
4317+
" 'G'\n" +
4318+
" }\n" +
4319+
" static String sm() {\n" +
4320+
" 'S'\n" +
4321+
" }\n" +
4322+
"}\n",
4323+
4324+
"C.groovy",
4325+
"class C implements B {\n" +
4326+
" @Override String m() {\n" +
4327+
" 'C' + B.super.m() + sm()\n" +
4328+
" }\n" +
4329+
"}\n",
4330+
};
4331+
//@formatter:on
4332+
4333+
runConformTest(sources, "CGS");
4334+
}
4335+
43004336
// WMTW: Groovy compilation unit scope adds the extra default import for java.util so List can be seen
43014337
@Test
43024338
public void testImplementingInterface_JavaExtendingGroovyAndImplementingMethod() {

base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1428,24 +1428,35 @@ public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) {
14281428
}
14291429
classNode.putNodeMetaData(CLASS_NAME, className);
14301430

1431-
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) {
1431+
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())/* GRECLIPSE edit || isInterfaceWithDefaultMethods*/) {
14321432
ClassNode superClass;
14331433
if (asBoolean(ctx.scs)) {
14341434
ClassNode[] scs = this.visitTypeList(ctx.scs);
14351435
if (scs.length > 1) {
14361436
throw createParsingFailedException("Cannot extend multiple classes", ctx.EXTENDS());
14371437
}
1438+
/* GRECLIPSE edit
14381439
superClass = scs[0];
14391440
} else {
14401441
superClass = ClassHelper.OBJECT_TYPE;
14411442
}
14421443
classNode.setSuperClass(superClass);
1444+
*/
1445+
classNode.setSuperClass(scs[0]);
1446+
}
1447+
// GRECLIPSE end
14431448
classNode.setInterfaces(this.visitTypeList(ctx.is));
14441449
this.initUsingGenerics(classNode);
1445-
1450+
// GRECLIPSE add -- GROOVY-9259
1451+
} else if (isInterfaceWithDefaultMethods) {
1452+
classNode.setInterfaces(this.visitTypeList(ctx.scs));
1453+
this.initUsingGenerics(classNode);
1454+
// GRECLIPSE end
14461455
} else if (isInterface) {
14471456
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT);
1457+
/* GRECLIPSE edit
14481458
classNode.setSuperClass(ClassHelper.OBJECT_TYPE);
1459+
*/
14491460
classNode.setInterfaces(this.visitTypeList(ctx.scs));
14501461
this.initUsingGenerics(classNode);
14511462
this.hackMixins(classNode);

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1619,24 +1619,23 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) {
16191619
}
16201620
classNode.putNodeMetaData(CLASS_NAME, className);
16211621

1622-
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) {
1623-
ClassNode superClass;
1622+
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())) {
16241623
if (asBoolean(ctx.scs)) {
16251624
ClassNode[] scs = this.visitTypeList(ctx.scs);
16261625
if (scs.length > 1) {
16271626
throw createParsingFailedException("Cannot extend multiple classes", ctx.EXTENDS());
16281627
}
1629-
superClass = scs[0];
1630-
} else {
1631-
superClass = ClassHelper.OBJECT_TYPE.getPlainNodeReference();
1628+
classNode.setSuperClass(scs[0]);
16321629
}
1633-
classNode.setSuperClass(superClass);
16341630
classNode.setInterfaces(this.visitTypeList(ctx.is));
16351631
this.initUsingGenerics(classNode);
16361632

1633+
} else if (isInterfaceWithDefaultMethods) { // GROOVY-9259
1634+
classNode.setInterfaces(this.visitTypeList(ctx.scs));
1635+
this.initUsingGenerics(classNode);
1636+
16371637
} else if (isInterface) {
16381638
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT);
1639-
classNode.setSuperClass(ClassHelper.OBJECT_TYPE.getPlainNodeReference());
16401639
classNode.setInterfaces(this.visitTypeList(ctx.scs));
16411640
this.initUsingGenerics(classNode);
16421641
this.hackMixins(classNode);

0 commit comments

Comments
 (0)