Add val KClass.staticProperties: Collection<KProperty0<*>>
To get static fields from Java classes
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
|||||||
|
public class J {
|
||||||
|
public String publicMemberJ;
|
||||||
|
private String privateMemberJ;
|
||||||
|
public static String publicStaticJ;
|
||||||
|
private static String privateStaticJ;
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
import kotlin.reflect.*
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
open class K : J() {
|
||||||
|
public val publicMemberK: String = ""
|
||||||
|
private val privateMemberK: String = ""
|
||||||
|
public val Any.publicMemberExtensionK: String get() = ""
|
||||||
|
private val Any.privateMemberExtensionK: String get() = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class L : K()
|
||||||
|
|
||||||
|
fun Collection<KProperty<*>>.names(): Set<String> =
|
||||||
|
this.map { it.name }.toSet()
|
||||||
|
|
||||||
|
fun check(c: Collection<KProperty<*>>, names: Set<String>) {
|
||||||
|
assertEquals(names, c.names())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val j = J::class
|
||||||
|
|
||||||
|
check(j.staticProperties,
|
||||||
|
setOf("publicStaticJ", "privateStaticJ"))
|
||||||
|
check(j.declaredMemberProperties,
|
||||||
|
setOf("publicMemberJ", "privateMemberJ"))
|
||||||
|
check(j.declaredMemberExtensionProperties,
|
||||||
|
emptySet())
|
||||||
|
|
||||||
|
check(j.memberProperties, j.declaredMemberProperties.names())
|
||||||
|
check(j.memberExtensionProperties, emptySet())
|
||||||
|
|
||||||
|
val k = K::class
|
||||||
|
|
||||||
|
check(k.staticProperties,
|
||||||
|
emptySet())
|
||||||
|
check(k.declaredMemberProperties,
|
||||||
|
setOf("publicMemberK", "privateMemberK"))
|
||||||
|
check(k.declaredMemberExtensionProperties,
|
||||||
|
setOf("publicMemberExtensionK", "privateMemberExtensionK"))
|
||||||
|
|
||||||
|
check(k.memberProperties, setOf("publicMemberJ") + k.declaredMemberProperties.names())
|
||||||
|
check(k.memberExtensionProperties, k.declaredMemberExtensionProperties.names())
|
||||||
|
|
||||||
|
|
||||||
|
val l = L::class
|
||||||
|
|
||||||
|
check(l.staticProperties, emptySet())
|
||||||
|
check(l.declaredMemberProperties, emptySet())
|
||||||
|
check(l.declaredMemberExtensionProperties, emptySet())
|
||||||
|
check(l.memberProperties, setOf("publicMemberJ", "publicMemberK"))
|
||||||
|
check(l.memberExtensionProperties, setOf("publicMemberExtensionK"))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -291,6 +291,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("declaredVsInheritedProperties")
|
||||||
|
public void testDeclaredVsInheritedProperties() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/declaredVsInheritedProperties/");
|
||||||
|
doTestWithJava(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("functionReferenceErasedToKFunction")
|
@TestMetadata("functionReferenceErasedToKFunction")
|
||||||
public void testFunctionReferenceErasedToKFunction() throws Exception {
|
public void testFunctionReferenceErasedToKFunction() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/functionReferenceErasedToKFunction/");
|
||||||
|
|||||||
@@ -114,6 +114,16 @@ public val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>
|
|||||||
.filterIsInstance<KFunction<*>>()
|
.filterIsInstance<KFunction<*>>()
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns static properties declared in this class.
|
||||||
|
* Only properties representing static fields of Java classes are considered static.
|
||||||
|
*/
|
||||||
|
public val KClass<*>.staticProperties: Collection<KProperty0<*>>
|
||||||
|
get() = (this as KClassImpl)
|
||||||
|
.getMembers(staticScope, declaredOnly = false, nonExtensions = true, extensions = false)
|
||||||
|
.filterIsInstance<KProperty0<*>>()
|
||||||
|
.toList()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns non-extension properties declared in this class and all of its superclasses.
|
* Returns non-extension properties declared in this class and all of its superclasses.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ object RuntimeTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapPropertySignature(property: PropertyDescriptor): JvmPropertySignature {
|
fun mapPropertySignature(possiblyOverriddenProperty: PropertyDescriptor): JvmPropertySignature {
|
||||||
|
val property = DescriptorUtils.unwrapFakeOverride(possiblyOverriddenProperty)
|
||||||
if (property is DeserializedPropertyDescriptor) {
|
if (property is DeserializedPropertyDescriptor) {
|
||||||
val proto = property.proto
|
val proto = property.proto
|
||||||
if (!proto.hasExtension(JvmProtoBuf.propertySignature)) {
|
if (!proto.hasExtension(JvmProtoBuf.propertySignature)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user