Fix incorrect behaviour of Class.getInterfaces

fix #635
This commit is contained in:
Alexey Andreev 2022-11-04 16:15:30 +01:00
parent 752ec040b0
commit d5cdd740f5
3 changed files with 32 additions and 4 deletions

View File

@ -651,7 +651,7 @@ public class TClass<T> extends TObject implements TAnnotatedElement, TType {
int j = 0; int j = 0;
for (int i = 0; i < supertypes.getLength(); ++i) { for (int i = 0; i < supertypes.getLength(); ++i) {
if (supertypes.get(i) != platformClass.getMetadata().getSuperclass()) { if (supertypes.get(i) != platformClass.getMetadata().getSuperclass()) {
filteredSupertypes[j++] = (TClass<? super T>) getClass(supertypes.get(j)); filteredSupertypes[j++] = (TClass<? super T>) getClass(supertypes.get(i));
} }
} }

View File

@ -474,8 +474,9 @@ class DependencyGraphBuilder {
DependencyNode instanceNode = getNode(instance); DependencyNode instanceNode = getNode(instance);
DependencyNode receiverNode = getNode(receiver); DependencyNode receiverNode = getNode(receiver);
receiverNode.propagate(dependencyAnalyzer.classType); receiverNode.propagate(dependencyAnalyzer.getType("[java/lang/Class;"));
instanceNode.getClassValueNode().addConsumer(type -> { receiverNode.getArrayItem().propagate(dependencyAnalyzer.classType);
instanceNode.getArrayItem().getClassValueNode().addConsumer(type -> {
String className = type.getName(); String className = type.getName();
if (className.startsWith("[")) { if (className.startsWith("[")) {
return; return;

View File

@ -23,6 +23,8 @@ import static org.junit.Assert.assertTrue;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.teavm.junit.TeaVMTestRunner; import org.teavm.junit.TeaVMTestRunner;
@ -39,7 +41,12 @@ public class ClassTest {
@Test @Test
public void classSimpleNameEvaluated() { public void classSimpleNameEvaluated() {
assertEquals("Object", Object.class.getSimpleName());
assertEquals("Object[]", Object[].class.getSimpleName());
assertEquals("int", int.class.getSimpleName());
assertEquals("int[]", int[].class.getSimpleName());
assertEquals("InnerClass", InnerClass.class.getSimpleName());
assertEquals("", new Object() { }.getClass().getSimpleName());
} }
@Test @Test
@ -188,6 +195,26 @@ public class ClassTest {
assertEquals(Integer.class, annot.n()); assertEquals(Integer.class, annot.n());
} }
@Test
public void getInterfaces() {
assertEquals(0, SuperclassWithoutInterfaces.class.getInterfaces().length);
assertEquals(Set.of(TestInterface1.class, TestInterface2.class),
Set.of(ClassWithInterfaces.class.getInterfaces()));
}
private static class SuperclassWithoutInterfaces {
}
private static class ClassWithInterfaces extends SuperclassWithoutInterfaces
implements TestInterface1, TestInterface2 {
}
private interface TestInterface1 {
}
private interface TestInterface2 {
}
@TestAnnot @TestAnnot
private static class A { private static class A {
} }