Support reflection on top level properties
This commit is contained in:
@@ -23,3 +23,6 @@ package kotlin.reflect
|
|||||||
*/
|
*/
|
||||||
public val KDeclarationContainer.functions: Collection<KFunction<*>>
|
public val KDeclarationContainer.functions: Collection<KFunction<*>>
|
||||||
get() = members.filterIsInstance<KFunction<*>>()
|
get() = members.filterIsInstance<KFunction<*>>()
|
||||||
|
|
||||||
|
public val KDeclarationContainer.properties: Collection<KProperty<*>>
|
||||||
|
get() = members.filterIsInstance<KProperty<*>>()
|
||||||
|
|||||||
@@ -87,12 +87,25 @@ public val Field.kotlinProperty: KProperty<*>?
|
|||||||
get() {
|
get() {
|
||||||
if (isSynthetic()) return null
|
if (isSynthetic()) return null
|
||||||
|
|
||||||
// TODO: fields in package parts
|
|
||||||
// TODO: optimize (search by name)
|
// TODO: optimize (search by name)
|
||||||
|
|
||||||
|
val kotlinPackage = getKPackage()
|
||||||
|
if (kotlinPackage != null) {
|
||||||
|
return kotlinPackage.members.filterIsInstance<KProperty<*>>().firstOrNull { it.javaField == this }
|
||||||
|
}
|
||||||
|
|
||||||
return getDeclaringClass().kotlin.memberProperties.firstOrNull { it.javaField == this }
|
return getDeclaringClass().kotlin.memberProperties.firstOrNull { it.javaField == this }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun Member.getKPackage(): KDeclarationContainer? {
|
||||||
|
// TODO: support multifile classes
|
||||||
|
val fileFacade = declaringClass.getAnnotation(KotlinFileFacade::class.java)
|
||||||
|
return if (fileFacade != null)
|
||||||
|
Reflection.getOrCreateKotlinPackage(declaringClass, fileFacade.moduleName)
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a [KFunction] instance corresponding to the given Java [Method] instance,
|
* Returns a [KFunction] instance corresponding to the given Java [Method] instance,
|
||||||
* or `null` if this method cannot be represented by a Kotlin function
|
* or `null` if this method cannot be represented by a Kotlin function
|
||||||
@@ -103,11 +116,8 @@ public val Method.kotlinFunction: KFunction<*>?
|
|||||||
if (isSynthetic) return null
|
if (isSynthetic) return null
|
||||||
|
|
||||||
if (Modifier.isStatic(modifiers)) {
|
if (Modifier.isStatic(modifiers)) {
|
||||||
// TODO: support multifile classes
|
val kotlinPackage = getKPackage()
|
||||||
|
if (kotlinPackage != null) {
|
||||||
val fileFacade = declaringClass.getAnnotation(KotlinFileFacade::class.java)
|
|
||||||
if (fileFacade != null) {
|
|
||||||
val kotlinPackage = Reflection.getOrCreateKotlinPackage(declaringClass, fileFacade.moduleName)
|
|
||||||
return kotlinPackage.functions.firstOrNull { it.javaMethod == this }
|
return kotlinPackage.functions.firstOrNull { it.javaMethod == this }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user