Refactor JavaEnumValueAnnotationArgument and implementations

Only require implementations to be able to compute the enum class name
and the corresponding entry name. Only this should be necessary to
correctly resolve the argument; the resolvers will find the
corresponding class descriptor if necessary
This commit is contained in:
Alexander Udalov
2017-12-29 16:21:58 +01:00
parent 907f53e539
commit 899002b681
12 changed files with 76 additions and 77 deletions
@@ -17,6 +17,7 @@
package kotlin.reflect.jvm.internal.structure
import org.jetbrains.kotlin.load.java.structure.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
abstract class ReflectJavaAnnotationArgument(
@@ -51,11 +52,12 @@ class ReflectJavaEnumValueAnnotationArgument(
name: Name?,
private val value: Enum<*>
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
override fun resolve(): ReflectJavaField {
val clazz = value::class.java
val enumClass = if (clazz.isEnum) clazz else clazz.enclosingClass
return ReflectJavaField(enumClass.getDeclaredField(value.name))
}
override val enumClassId: ClassId?
get() {
val clazz = value::class.java
val enumClass = if (clazz.isEnum) clazz else clazz.enclosingClass
return enumClass.classId
}
override val entryName: Name?
get() = Name.identifier(value.name)