Fix supertypes for reflected Java classes, always include j.l.Object

equals/hashCode/toString had not appeared in Java classes' "members" because of
this
This commit is contained in:
Alexander Udalov
2015-07-30 21:02:26 +03:00
parent af9ae46f9a
commit d1e67805fc
4 changed files with 30 additions and 8 deletions
@@ -0,0 +1,10 @@
public class J {
public J() {
}
public void member(String s) {
}
public static void staticMethod(int x) {
}
}
@@ -0,0 +1,12 @@
import kotlin.reflect.*
import kotlin.test.assertEquals
fun box(): String {
assertEquals(listOf("equals", "hashCode", "member", "staticMethod", "toString"), J::class.members.map { it.name }.toSortedList())
assertEquals(listOf("equals", "hashCode", "member", "staticMethod", "toString"), J::class.functions.map { it.name }.toSortedList())
assertEquals(listOf("member", "staticMethod"), J::class.declaredFunctions.map { it.name }.toSortedList())
assertEquals(1, J::class.constructors.size())
return "OK"
}
@@ -273,6 +273,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava(fileName);
}
@TestMetadata("javaClassGetFunctions")
public void testJavaClassGetFunctions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/javaClassGetFunctions/");
doTestWithJava(fileName);
}
@TestMetadata("javaMethodsSmokeTest")
public void testJavaMethodsSmokeTest() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/javaMethodsSmokeTest/");
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
import org.jetbrains.kotlin.load.java.structure.JavaType
import org.jetbrains.kotlin.load.java.structure.JavaTypeSubstitutor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.emptyOrSingletonList
import java.lang.reflect.AnnotatedElement
import java.lang.reflect.Method
import java.util.Arrays
@@ -49,12 +47,8 @@ public class ReflectJavaClass(
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
override fun getSupertypes(): Collection<JavaClassifierType> {
val supertype = klass.getGenericSuperclass()
val superClassName = (supertype as? Class<*>)?.getName()
val supertypes =
(if (superClassName == "java.lang.Object") emptyList() else emptyOrSingletonList(supertype)) +
klass.getGenericInterfaces()
return supertypes.map(::ReflectJavaClassifierType)
if (klass == javaClass<Any>()) return emptyList()
return listOf(klass.genericSuperclass ?: javaClass<Any>(), *klass.genericInterfaces).map(::ReflectJavaClassifierType)
}
override fun getMethods() = klass.getDeclaredMethods()