[FIR, IR] Refactor: move annotation retention helper functions
Will be needed in subsequent commit to be accessible in ExpectActualMatchingContext implementations. ^KT-58551
This commit is contained in:
committed by
Space Team
parent
454756a2b5
commit
59f1a0dd8e
-2
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.jvm.lower
|
||||
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getAnnotationRetention
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
@@ -27,7 +26,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import java.lang.annotation.ElementType
|
||||
|
||||
internal val additionalClassAnnotationPhase = makeIrFilePhase(
|
||||
|
||||
@@ -453,22 +453,6 @@ val IrDeclaration.fileParentOrNull: IrFile?
|
||||
else -> null
|
||||
}
|
||||
|
||||
private val RETENTION_PARAMETER_NAME = Name.identifier("value")
|
||||
|
||||
fun IrClass.getAnnotationRetention(): KotlinRetention? {
|
||||
val retentionArgument =
|
||||
getAnnotation(StandardNames.FqNames.retention)?.getValueArgument(RETENTION_PARAMETER_NAME)
|
||||
as? IrGetEnumValue ?: return null
|
||||
val retentionArgumentValue = retentionArgument.symbol.owner
|
||||
return KotlinRetention.valueOf(retentionArgumentValue.name.asString())
|
||||
}
|
||||
|
||||
// To be generalized to IrMemberAccessExpression as soon as properties get symbols.
|
||||
fun IrConstructorCall.getValueArgument(name: Name): IrExpression? {
|
||||
val index = symbol.owner.valueParameters.find { it.name == name }?.index ?: return null
|
||||
return getValueArgument(index)
|
||||
}
|
||||
|
||||
val IrMemberWithContainerSource.parentClassId: ClassId?
|
||||
get() = ((this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner ?: this).let { directMember ->
|
||||
(directMember.containerSource as? JvmPackagePartSource)?.classId ?: (directMember.parent as? IrClass)?.classId
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
@@ -29,6 +31,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.*
|
||||
import java.io.StringWriter
|
||||
@@ -348,6 +351,20 @@ fun IrAnnotationContainer.hasAnnotation(symbol: IrClassSymbol) =
|
||||
it.symbol.owner.parentAsClass.symbol == symbol
|
||||
}
|
||||
|
||||
fun IrClass.getAnnotationRetention(): KotlinRetention? {
|
||||
val retentionArgument =
|
||||
getAnnotation(StandardNames.FqNames.retention)?.getValueArgument(StandardClassIds.Annotations.ParameterNames.retentionValue)
|
||||
as? IrGetEnumValue ?: return null
|
||||
val retentionArgumentValue = retentionArgument.symbol.owner
|
||||
return KotlinRetention.valueOf(retentionArgumentValue.name.asString())
|
||||
}
|
||||
|
||||
// To be generalized to IrMemberAccessExpression as soon as properties get symbols.
|
||||
fun IrConstructorCall.getValueArgument(name: Name): IrExpression? {
|
||||
val index = symbol.owner.valueParameters.find { it.name == name }?.index ?: return null
|
||||
return getValueArgument(index)
|
||||
}
|
||||
|
||||
|
||||
val IrConstructor.constructedClassType get() = (parent as IrClass).thisReceiver?.type!!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user