diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt index 2cae0ecc160..119d42ab717 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt @@ -25,6 +25,35 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.org.objectweb.asm.* import java.lang.reflect.Array +internal class AnnotationsCollectorFieldVisitor( + private val field: BinaryJavaField, + private val context: ClassifierResolutionContext, + private val signatureParser: BinaryClassSignatureParser, +) : FieldVisitor(ASM_API_VERSION_FOR_CLASS_READING) { + override fun visitAnnotation(desc: String, visible: Boolean) = + BinaryJavaAnnotation.addAnnotation(field, desc, context, signatureParser) + + override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, desc: String, visible: Boolean): AnnotationVisitor? { + val typeReference = TypeReference(typeRef) + + if (typePath != null) { + val translatedPath = translatePath(typePath) + + when (typeReference.sort) { + TypeReference.FIELD -> { + val targetType = computeTargetType(field.type, translatedPath) + return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, desc, context, signatureParser) + } + } + } + + return when (typeReference.sort) { + TypeReference.FIELD -> BinaryJavaAnnotation.addAnnotation(field.type as JavaPlainType, desc, context, signatureParser) + else -> null + } + } +} + internal class AnnotationsAndParameterCollectorMethodVisitor( private val member: BinaryJavaMethodBase, private val context: ClassifierResolutionContext, diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt index 06db541e6c2..171e53919f3 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt @@ -211,23 +211,12 @@ class BinaryJavaClass( if (access.isSet(Opcodes.ACC_SYNTHETIC)) return null val type = signatureParser.parseTypeString(StringCharacterIterator(signature ?: desc), context) - val processedValue = processValue(value, type) + val filed = BinaryJavaField(Name.identifier(name), access, this, access.isSet(Opcodes.ACC_ENUM), type, processedValue) - return BinaryJavaField(Name.identifier(name), access, this, access.isSet(Opcodes.ACC_ENUM), type, processedValue).run { - fields.add(this) + fields.add(filed) - object : FieldVisitor(ASM_API_VERSION_FOR_CLASS_READING) { - override fun visitAnnotation(desc: String, visible: Boolean) = - BinaryJavaAnnotation.addAnnotation(this@run, desc, context, signatureParser) - - override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, desc: String, visible: Boolean) = - if (typePath == null) - BinaryJavaAnnotation.addAnnotation(type as JavaPlainType, desc, context, signatureParser) - else - null - } - } + return AnnotationsCollectorFieldVisitor(filed, context, signatureParser) }