Support type use annotations on fields
This commit is contained in:
+29
@@ -25,6 +25,35 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
import org.jetbrains.org.objectweb.asm.*
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
import java.lang.reflect.Array
|
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(
|
internal class AnnotationsAndParameterCollectorMethodVisitor(
|
||||||
private val member: BinaryJavaMethodBase,
|
private val member: BinaryJavaMethodBase,
|
||||||
private val context: ClassifierResolutionContext,
|
private val context: ClassifierResolutionContext,
|
||||||
|
|||||||
+3
-14
@@ -211,23 +211,12 @@ class BinaryJavaClass(
|
|||||||
if (access.isSet(Opcodes.ACC_SYNTHETIC)) return null
|
if (access.isSet(Opcodes.ACC_SYNTHETIC)) return null
|
||||||
|
|
||||||
val type = signatureParser.parseTypeString(StringCharacterIterator(signature ?: desc), context)
|
val type = signatureParser.parseTypeString(StringCharacterIterator(signature ?: desc), context)
|
||||||
|
|
||||||
val processedValue = processValue(value, type)
|
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(filed)
|
||||||
fields.add(this)
|
|
||||||
|
|
||||||
object : FieldVisitor(ASM_API_VERSION_FOR_CLASS_READING) {
|
return AnnotationsCollectorFieldVisitor(filed, context, signatureParser)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user