JVM_IR: handle @JvmName on annotation getters

This commit is contained in:
pyos
2019-12-02 16:55:44 +01:00
committed by Georgy Bronnikov
parent ac7d9fa90d
commit 69033b7b15
4 changed files with 10 additions and 14 deletions
@@ -32,10 +32,7 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.isMarkedNullable
import org.jetbrains.kotlin.ir.types.isNullable
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.getAnnotation
import org.jetbrains.kotlin.ir.util.isAnnotationClass
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.synthetic.isVisibleOutside
@@ -185,11 +182,15 @@ class AnnotationCodegen(
private fun getAnnotationArgumentJvmName(annotationClass: IrClass?, parameterName: Name): String {
if (annotationClass == null) return parameterName.asString()
val field =
annotationClass.declarations.filterIsInstance<IrField>().singleOrNull { it.name == parameterName }
?: return parameterName.asString()
return methodSignatureMapper.mapAnnotationParameterName(field)
val propertyOrGetter = annotationClass.declarations.singleOrNull {
// IrSimpleFunction if lowered, IrProperty with a getter if imported
(it is IrSimpleFunction && it.correspondingPropertySymbol?.owner?.name == parameterName) ||
(it is IrProperty && it.name == parameterName)
} ?: return parameterName.asString()
val getter = propertyOrGetter as? IrSimpleFunction
?: (propertyOrGetter as IrProperty).getter
?: error("No getter for annotation property: ${propertyOrGetter.render()}")
return methodSignatureMapper.mapFunctionName(getter)
}
private fun genCompileTimeValue(
@@ -125,9 +125,6 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
private fun IrFunction.isPublishedApi(): Boolean =
propertyIfAccessor.annotations.hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)
fun mapAnnotationParameterName(field: IrField): String =
mapFunctionName(field.correspondingPropertySymbol!!.owner.getter ?: error("No getter for annotation property: ${field.render()}"))
fun mapReturnType(declaration: IrDeclaration, sw: JvmSignatureWriter? = null): Type {
if (declaration !is IrFunction) {
require(declaration is IrField) { "Unsupported declaration: $declaration" }
@@ -1,6 +1,5 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// WITH_REFLECT
package test
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: A.kt
package lib