[FIR] Resolve annotations as calls

This commit is contained in:
Dmitriy Novozhilov
2020-07-23 17:47:38 +03:00
committed by Mikhail Glukhikh
parent bc1fa8ed7f
commit 721b9b4d8c
99 changed files with 529 additions and 232 deletions
@@ -19,12 +19,12 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.references.FirSuperReference
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
import org.jetbrains.kotlin.fir.resolve.getCorrespondingConstructorReferenceOrNull
import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.*
@@ -420,16 +420,14 @@ class CallAndReferenceGenerator(
fun convertToIrConstructorCall(annotationCall: FirAnnotationCall): IrExpression {
val coneType = annotationCall.annotationTypeRef.coneTypeSafe<ConeLookupTagBasedType>()
val firSymbol = coneType?.lookupTag?.toSymbol(session) as? FirClassSymbol
val type = coneType?.toIrType()
val symbol = type?.classifierOrNull
return annotationCall.convertWithOffsets { startOffset, endOffset ->
when (symbol) {
is IrClassSymbol -> {
val irClass = symbol.owner
val fir = firSymbol?.fir as? FirClass<*>
val irConstructor = fir?.getPrimaryConstructorIfAny()?.let { firConstructor ->
this.declarationStorage.getIrConstructorSymbol(firConstructor.symbol)
val irConstructor = (annotationCall.toResolvedCallableSymbol() as? FirConstructorSymbol)?.let {
this.declarationStorage.getIrConstructorSymbol(it)
}
if (irConstructor == null) {
IrErrorCallExpressionImpl(startOffset, endOffset, type, "No annotation constructor found: ${irClass.name}")
@@ -492,13 +490,13 @@ class CallAndReferenceGenerator(
val calleeReference = when (call) {
is FirFunctionCall -> call.calleeReference
is FirDelegatedConstructorCall -> call.calleeReference
is FirAnnotationCall -> call.getCorrespondingConstructorReferenceOrNull(session)
is FirAnnotationCall -> call.calleeReference
else -> null
} as? FirResolvedNamedReference
val function = (calleeReference?.resolvedSymbol as? FirFunctionSymbol<*>)?.fir
val valueParameters = function?.valueParameters
val argumentMapping = call.argumentMapping
if (argumentMapping != null && argumentMapping.isNotEmpty()) {
if (argumentMapping != null && (annotationMode || argumentMapping.isNotEmpty())) {
if (valueParameters != null) {
return applyArgumentsWithReorderingIfNeeded(call, argumentMapping, valueParameters, annotationMode)
}