Reflection: support Java anonymous/local classes
Local classes and anonymous objects are normal classes and kotlin-reflect can load all declarations and modifiers from them, and support calling members, exactly in the same way as it does for normal non-local classes. #KT-41373 In Progress
This commit is contained in:
committed by
Space Team
parent
1e031d9fb8
commit
d833b732c9
+8
-1
@@ -105,7 +105,14 @@ class ReflectJavaClass(
|
||||
get() = null
|
||||
|
||||
override val name: Name
|
||||
get() = Name.identifier(klass.simpleName)
|
||||
get() = if (klass.isAnonymousClass) {
|
||||
// For anonymous classes, `Class.simpleName` returns an empty string in Java reflection.
|
||||
// We don't want that because it breaks all sorts of invariants on names which cannot be empty in Kotlin.
|
||||
// So we extract the simple name from the full JVM binary name, e.g. "org.test.Foo$1" -> "Foo$1".
|
||||
Name.identifier(klass.name.substringAfterLast("."))
|
||||
} else {
|
||||
Name.identifier(klass.simpleName)
|
||||
}
|
||||
|
||||
override val typeParameters: List<ReflectJavaTypeParameter>
|
||||
get() = klass.typeParameters.map(::ReflectJavaTypeParameter)
|
||||
|
||||
Reference in New Issue
Block a user