Fix annotations on Java elements in reflection

#KT-10840 Fixed
This commit is contained in:
Alexander Udalov
2016-01-28 16:38:51 +03:00
parent b946d725d7
commit 2a5b4d2c83
6 changed files with 45 additions and 5 deletions
@@ -17,6 +17,8 @@
package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.load.java.components.RuntimeSourceElementFactory
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaAnnotation
import org.jetbrains.kotlin.load.kotlin.reflect.ReflectAnnotationSource
import kotlin.reflect.KAnnotatedElement
@@ -24,7 +26,16 @@ internal interface KAnnotatedElementImpl : KAnnotatedElement {
val annotated: Annotated
override val annotations: List<Annotation>
get() = annotated.annotations.map {
(it.source as? ReflectAnnotationSource)?.annotation
}.filterNotNull()
get() = annotated.annotations.mapNotNull {
val source = it.source
when (source) {
is ReflectAnnotationSource -> {
source.annotation
}
is RuntimeSourceElementFactory.RuntimeSourceElement -> {
(source.javaElement as? ReflectJavaAnnotation)?.annotation
}
else -> null
}
}
}