提交 a09c8105 编写于 作者: M Michael Bogdanov

Support reflection on top level properties

上级 e8f9a9f3
...@@ -23,3 +23,6 @@ package kotlin.reflect ...@@ -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<*>? ...@@ -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<*>? ...@@ -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 }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册