Skip to content

Commit

Permalink
GROOVY-9259
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 21, 2022
1 parent f785b29 commit 6644009
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4297,6 +4297,42 @@ public void testImplementingInterface9() {
runConformTest(sources, "8:30pm");
}

@Test // GROOVY-9259
public void testImplementingInterface10() {
assumeTrue(isParrotParser()); // TODO: support default in antlr2 parser?

//@formatter:off
String[] sources = {
"Script.groovy",
"print new C().m()\n",

"A.java",
"public interface A {\n" +
" String m();\n" +
"}\n",

"B.groovy",
"interface B extends A {\n" +
" default String m() {\n" +
" 'G'\n" +
" }\n" +
" static String sm() {\n" +
" 'S'\n" +
" }\n" +
"}\n",

"C.groovy",
"class C implements B {\n" +
" @Override String m() {\n" +
" 'C' + B.super.m() + sm()\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "CGS");
}

// WMTW: Groovy compilation unit scope adds the extra default import for java.util so List can be seen
@Test
public void testImplementingInterface_JavaExtendingGroovyAndImplementingMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,24 +1428,35 @@ public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) {
}
classNode.putNodeMetaData(CLASS_NAME, className);

if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) {
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())/* GRECLIPSE edit || isInterfaceWithDefaultMethods*/) {
ClassNode superClass;
if (asBoolean(ctx.scs)) {
ClassNode[] scs = this.visitTypeList(ctx.scs);
if (scs.length > 1) {
throw createParsingFailedException("Cannot extend multiple classes", ctx.EXTENDS());
}
/* GRECLIPSE edit
superClass = scs[0];
} else {
superClass = ClassHelper.OBJECT_TYPE;
}
classNode.setSuperClass(superClass);
*/
classNode.setSuperClass(scs[0]);
}
// GRECLIPSE end
classNode.setInterfaces(this.visitTypeList(ctx.is));
this.initUsingGenerics(classNode);

// GRECLIPSE add -- GROOVY-9259
} else if (isInterfaceWithDefaultMethods) {
classNode.setInterfaces(this.visitTypeList(ctx.scs));
this.initUsingGenerics(classNode);
// GRECLIPSE end
} else if (isInterface) {
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT);
/* GRECLIPSE edit
classNode.setSuperClass(ClassHelper.OBJECT_TYPE);
*/
classNode.setInterfaces(this.visitTypeList(ctx.scs));
this.initUsingGenerics(classNode);
this.hackMixins(classNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,24 +1619,23 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) {
}
classNode.putNodeMetaData(CLASS_NAME, className);

if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()) || isInterfaceWithDefaultMethods) {
ClassNode superClass;
if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())) {
if (asBoolean(ctx.scs)) {
ClassNode[] scs = this.visitTypeList(ctx.scs);
if (scs.length > 1) {
throw createParsingFailedException("Cannot extend multiple classes", ctx.EXTENDS());
}
superClass = scs[0];
} else {
superClass = ClassHelper.OBJECT_TYPE.getPlainNodeReference();
classNode.setSuperClass(scs[0]);
}
classNode.setSuperClass(superClass);
classNode.setInterfaces(this.visitTypeList(ctx.is));
this.initUsingGenerics(classNode);

} else if (isInterfaceWithDefaultMethods) { // GROOVY-9259
classNode.setInterfaces(this.visitTypeList(ctx.scs));
this.initUsingGenerics(classNode);

} else if (isInterface) {
classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT);
classNode.setSuperClass(ClassHelper.OBJECT_TYPE.getPlainNodeReference());
classNode.setInterfaces(this.visitTypeList(ctx.scs));
this.initUsingGenerics(classNode);
this.hackMixins(classNode);
Expand Down

0 comments on commit 6644009

Please sign in to comment.