Support annotations as annotation arguments in reflection, add test
A follow-up to 281acb8 where this was supported in the compiler
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ public interface KotlinJvmBinaryClass {
|
||||
}
|
||||
|
||||
interface AnnotationArgumentVisitor {
|
||||
// TODO: annotations, java.lang.Class
|
||||
// TODO: class literals
|
||||
void visit(@Nullable Name name, @Nullable Object value);
|
||||
|
||||
void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName);
|
||||
|
||||
+8
-7
@@ -182,25 +182,26 @@ private object ReflectClassStructure {
|
||||
val classId = (if (clazz.isEnum()) clazz else clazz.getEnclosingClass()).classId
|
||||
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name()))
|
||||
}
|
||||
clazz.isAnnotation() -> {
|
||||
// TODO: support values of annotation types
|
||||
throw UnsupportedOperationException("Values of annotation types are not yet supported in Kotlin reflection: $value")
|
||||
javaClass<Annotation>().isAssignableFrom(clazz) -> {
|
||||
val annotationClass = clazz.getInterfaces().single()
|
||||
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
|
||||
processAnnotationArguments(v, value as Annotation, annotationClass)
|
||||
}
|
||||
clazz.isArray() -> {
|
||||
val elementVisitor = visitor.visitArray(name) ?: return
|
||||
val v = visitor.visitArray(name) ?: return
|
||||
val componentType = clazz.getComponentType()
|
||||
if (componentType.isEnum()) {
|
||||
val enumClassId = componentType.classId
|
||||
for (element in value as Array<*>) {
|
||||
elementVisitor.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name()))
|
||||
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name()))
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (element in value as Array<*>) {
|
||||
elementVisitor.visit(element)
|
||||
v.visit(element)
|
||||
}
|
||||
}
|
||||
elementVisitor.visitEnd()
|
||||
v.visitEnd()
|
||||
}
|
||||
else -> {
|
||||
throw UnsupportedOperationException("Unsupported annotation argument value ($clazz): $value")
|
||||
|
||||
Reference in New Issue
Block a user