mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-14 23:09:22 +00:00
do not repeat default methods if already in super classes
This commit is contained in:
parent
c92267bcd6
commit
82ea42ddf5
@ -1523,6 +1523,13 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
|
||||
}
|
||||
defaultMethods = new HashSet<>();
|
||||
Util.findDefaultMethodsInType(defaultMethods, context, classdecl.sym);
|
||||
|
||||
if (Util.isSourceElement(classdecl.sym.getSuperclass().tsym) && !isMappedOrErasedType(classdecl.sym.getSuperclass().tsym)) {
|
||||
HashSet<Entry<JCClassDecl, JCMethodDecl>> superClassDefaultMethods = new HashSet<>();
|
||||
Util.findDefaultMethodsInType(superClassDefaultMethods, context, (ClassSymbol)classdecl.sym.getSuperclass().tsym);;
|
||||
defaultMethods.removeAll(superClassDefaultMethods);
|
||||
}
|
||||
|
||||
if (classdecl.getModifiers().getFlags().contains(Modifier.ABSTRACT)) {
|
||||
print("abstract ");
|
||||
}
|
||||
|
||||
@ -18,13 +18,18 @@ package org.jsweet.test.transpiler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jsweet.test.transpiler.util.TranspilerTestRunner;
|
||||
import org.jsweet.transpiler.JSweetContext;
|
||||
import org.jsweet.transpiler.JSweetFactory;
|
||||
import org.jsweet.transpiler.JSweetOptions;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
import org.jsweet.transpiler.SourceFile;
|
||||
import org.jsweet.transpiler.extension.Java2TypeScriptAdapter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -575,12 +580,25 @@ public class StructuralTests extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultMethodsHierarchy() {
|
||||
eval(ModuleKind.commonjs, (logHandler, r) -> {
|
||||
logHandler.assertNoProblems();
|
||||
}, getSourceFile(MyAnnotation.class), getSourceFile(II1.class), getSourceFile(CC1.class),
|
||||
SourceFile[] sourceFiles = new SourceFile[] {
|
||||
getSourceFile(MyAnnotation.class), getSourceFile(II1.class), getSourceFile(CC1.class),
|
||||
getSourceFile(CC2.class), getSourceFile(I1.class), getSourceFile(I2.class), getSourceFile(I3.class),
|
||||
getSourceFile(I4.class), getSourceFile(I5.class), getSourceFile(AbstractViewController.class),
|
||||
getSourceFile(IntermediateAbstractViewController.class), getSourceFile(FinalViewController.class));
|
||||
getSourceFile(IntermediateAbstractViewController.class), getSourceFile(FinalViewController.class)
|
||||
};
|
||||
eval(ModuleKind.commonjs, (logHandler, r) -> {
|
||||
logHandler.assertNoProblems();
|
||||
try {
|
||||
String cc1Ts = FileUtils.readFileToString(sourceFiles[2].getTsFile());
|
||||
assertTrue(cc1Ts.contains("CC1 implements I3"));
|
||||
assertTrue(cc1Ts.contains("m3() {"));
|
||||
String cc2Ts = FileUtils.readFileToString(sourceFiles[3].getTsFile());
|
||||
assertTrue(cc2Ts.contains("CC1 implements I3"));
|
||||
assertTrue(!cc2Ts.contains("m3() {"));
|
||||
} catch (IOException e) {
|
||||
fail();
|
||||
}
|
||||
}, sourceFiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package source.structural.defaultMethods;
|
||||
|
||||
public class CC1 {
|
||||
public class CC1 implements I3 {
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package source.structural.defaultMethods;
|
||||
|
||||
public class CC2 extends CC1 {
|
||||
public class CC2 extends CC1 implements I3 {
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user