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:
+10
@@ -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"
|
||||||
|
}
|
||||||
+6
@@ -273,6 +273,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javaClassGetFunctions")
|
||||||
|
public void testJavaClassGetFunctions() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/javaClassGetFunctions/");
|
||||||
|
doTestWithJava(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("javaMethodsSmokeTest")
|
@TestMetadata("javaMethodsSmokeTest")
|
||||||
public void testJavaMethodsSmokeTest() throws Exception {
|
public void testJavaMethodsSmokeTest() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/javaMethodsSmokeTest/");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/javaMethodsSmokeTest/");
|
||||||
|
|||||||
+2
-8
@@ -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.JavaType
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeSubstitutor
|
import org.jetbrains.kotlin.load.java.structure.JavaTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
|
||||||
import java.lang.reflect.AnnotatedElement
|
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
|
|
||||||
@@ -49,12 +47,8 @@ public class ReflectJavaClass(
|
|||||||
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
|
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
|
||||||
|
|
||||||
override fun getSupertypes(): Collection<JavaClassifierType> {
|
override fun getSupertypes(): Collection<JavaClassifierType> {
|
||||||
val supertype = klass.getGenericSuperclass()
|
if (klass == javaClass<Any>()) return emptyList()
|
||||||
val superClassName = (supertype as? Class<*>)?.getName()
|
return listOf(klass.genericSuperclass ?: javaClass<Any>(), *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
||||||
val supertypes =
|
|
||||||
(if (superClassName == "java.lang.Object") emptyList() else emptyOrSingletonList(supertype)) +
|
|
||||||
klass.getGenericInterfaces()
|
|
||||||
return supertypes.map(::ReflectJavaClassifierType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMethods() = klass.getDeclaredMethods()
|
override fun getMethods() = klass.getDeclaredMethods()
|
||||||
|
|||||||
Reference in New Issue
Block a user