[FIR] Support of type arguments in annotations ^KT-48444 Fixed
This commit is contained in:
+6
@@ -1446,6 +1446,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/typeAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgumentsInAnnotation.kt")
|
||||
public void testTypeArgumentsInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/typeArgumentsInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterAsAnnotation.kt")
|
||||
public void testTypeParameterAsAnnotation() throws Exception {
|
||||
|
||||
+6
@@ -1446,6 +1446,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/typeAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgumentsInAnnotation.kt")
|
||||
public void testTypeArgumentsInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/typeArgumentsInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterAsAnnotation.kt")
|
||||
public void testTypeParameterAsAnnotation() throws Exception {
|
||||
|
||||
+3
-1
@@ -377,7 +377,8 @@ class DeclarationsConverter(
|
||||
CONSTRUCTOR_CALLEE -> constructorCalleePair = convertConstructorInvocation(unescapedAnnotation)
|
||||
}
|
||||
}
|
||||
val name = (constructorCalleePair.first as? FirUserTypeRef)?.qualifier?.last()?.name ?: Name.special("<no-annotation-name>")
|
||||
val qualifier = (constructorCalleePair.first as? FirUserTypeRef)?.qualifier?.last()
|
||||
val name = qualifier?.name ?: Name.special("<no-annotation-name>")
|
||||
return buildAnnotationCall {
|
||||
source = unescapedAnnotation.toFirSourceElement()
|
||||
useSiteTarget = annotationUseSiteTarget ?: defaultAnnotationUseSiteTarget
|
||||
@@ -392,6 +393,7 @@ class DeclarationsConverter(
|
||||
this.name = name
|
||||
}
|
||||
extractArgumentsFrom(constructorCalleePair.second)
|
||||
typeArguments += qualifier?.typeArgumentList?.typeArguments ?: listOf()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1738,9 +1738,7 @@ open class RawFirBuilder(
|
||||
referenceExpression!!.toFirSourceElement(),
|
||||
referenceExpression!!.getReferencedNameAsName(),
|
||||
FirTypeArgumentListImpl(ktQualifier?.typeArgumentList?.toKtPsiSourceElement() ?: source).apply {
|
||||
for (typeArgument in ktQualifier!!.typeArguments) {
|
||||
typeArguments += typeArgument.convert<FirTypeProjection>()
|
||||
}
|
||||
typeArguments.appendTypeArguments(ktQualifier!!.typeArguments)
|
||||
}
|
||||
)
|
||||
qualifier.add(firQualifier)
|
||||
@@ -1809,6 +1807,7 @@ open class RawFirBuilder(
|
||||
source = (annotationEntry.typeReference?.typeElement as? KtUserType)?.referenceExpression?.toFirSourceElement()
|
||||
this.name = name
|
||||
}
|
||||
typeArguments.appendTypeArguments(annotationEntry.typeArguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2358,9 +2357,7 @@ open class RawFirBuilder(
|
||||
|
||||
return result.apply {
|
||||
this.explicitReceiver = explicitReceiver
|
||||
for (typeArgument in expression.typeArguments) {
|
||||
typeArguments += typeArgument.convert<FirTypeProjection>()
|
||||
}
|
||||
typeArguments.appendTypeArguments(expression.typeArguments)
|
||||
}.build()
|
||||
}
|
||||
|
||||
@@ -2537,6 +2534,12 @@ open class RawFirBuilder(
|
||||
source = expression.toFirSourceElement()
|
||||
}
|
||||
}
|
||||
|
||||
private fun MutableList<FirTypeProjection>.appendTypeArguments(args: List<KtTypeProjection>) {
|
||||
for (typeArgument in args) {
|
||||
this += typeArgument.convert<FirTypeProjection>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -555,7 +555,7 @@ class FirCallResolver(
|
||||
explicitReceiver = null,
|
||||
annotation.argumentList,
|
||||
isImplicitInvoke = false,
|
||||
typeArguments = emptyList(),
|
||||
typeArguments = annotation.typeArguments,
|
||||
session,
|
||||
components.file,
|
||||
components.containingDeclarations
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.expressions
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
@@ -23,6 +24,7 @@ abstract class FirAnnotation : FirExpression() {
|
||||
abstract val useSiteTarget: AnnotationUseSiteTarget?
|
||||
abstract val annotationTypeRef: FirTypeRef
|
||||
abstract val argumentMapping: FirAnnotationArgumentMapping
|
||||
abstract val typeArguments: List<FirTypeProjection>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitAnnotation(this, data)
|
||||
|
||||
@@ -34,7 +36,11 @@ abstract class FirAnnotation : FirExpression() {
|
||||
|
||||
abstract fun replaceArgumentMapping(newArgumentMapping: FirAnnotationArgumentMapping)
|
||||
|
||||
abstract fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>)
|
||||
|
||||
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirAnnotation
|
||||
|
||||
abstract fun <D> transformAnnotationTypeRef(transformer: FirTransformer<D>, data: D): FirAnnotation
|
||||
|
||||
abstract fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirAnnotation
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
@@ -23,6 +24,7 @@ abstract class FirAnnotationCall : FirAnnotation(), FirCall, FirResolvable {
|
||||
abstract override val annotations: List<FirAnnotation>
|
||||
abstract override val useSiteTarget: AnnotationUseSiteTarget?
|
||||
abstract override val annotationTypeRef: FirTypeRef
|
||||
abstract override val typeArguments: List<FirTypeProjection>
|
||||
abstract override val argumentList: FirArgumentList
|
||||
abstract override val calleeReference: FirReference
|
||||
abstract override val argumentMapping: FirAnnotationArgumentMapping
|
||||
@@ -35,6 +37,8 @@ abstract class FirAnnotationCall : FirAnnotation(), FirCall, FirResolvable {
|
||||
|
||||
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
|
||||
|
||||
abstract override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>)
|
||||
|
||||
abstract override fun replaceArgumentList(newArgumentList: FirArgumentList)
|
||||
|
||||
abstract override fun replaceCalleeReference(newCalleeReference: FirReference)
|
||||
@@ -45,5 +49,7 @@ abstract class FirAnnotationCall : FirAnnotation(), FirCall, FirResolvable {
|
||||
|
||||
abstract override fun <D> transformAnnotationTypeRef(transformer: FirTransformer<D>, data: D): FirAnnotationCall
|
||||
|
||||
abstract override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirAnnotationCall
|
||||
|
||||
abstract override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirAnnotationCall
|
||||
}
|
||||
|
||||
+3
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationArgumentMapping
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAnnotationImpl
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
@@ -28,6 +29,7 @@ class FirAnnotationBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder
|
||||
var useSiteTarget: AnnotationUseSiteTarget? = null
|
||||
lateinit var annotationTypeRef: FirTypeRef
|
||||
lateinit var argumentMapping: FirAnnotationArgumentMapping
|
||||
val typeArguments: MutableList<FirTypeProjection> = mutableListOf()
|
||||
|
||||
override fun build(): FirAnnotation {
|
||||
return FirAnnotationImpl(
|
||||
@@ -35,6 +37,7 @@ class FirAnnotationBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder
|
||||
useSiteTarget,
|
||||
annotationTypeRef,
|
||||
argumentMapping,
|
||||
typeArguments,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAnnotationCallImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyAnnotationArgumentMapping
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
@@ -34,6 +35,7 @@ class FirAnnotationCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder,
|
||||
override var source: KtSourceElement? = null
|
||||
var useSiteTarget: AnnotationUseSiteTarget? = null
|
||||
var annotationTypeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
|
||||
val typeArguments: MutableList<FirTypeProjection> = mutableListOf()
|
||||
override var argumentList: FirArgumentList = FirEmptyArgumentList
|
||||
lateinit var calleeReference: FirReference
|
||||
var argumentMapping: FirAnnotationArgumentMapping = FirEmptyAnnotationArgumentMapping
|
||||
@@ -43,6 +45,7 @@ class FirAnnotationCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder,
|
||||
source,
|
||||
useSiteTarget,
|
||||
annotationTypeRef,
|
||||
typeArguments,
|
||||
argumentList,
|
||||
calleeReference,
|
||||
argumentMapping,
|
||||
|
||||
+14
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationArgumentMapping
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
@@ -24,6 +25,7 @@ internal class FirAnnotationCallImpl(
|
||||
override val source: KtSourceElement?,
|
||||
override val useSiteTarget: AnnotationUseSiteTarget?,
|
||||
override var annotationTypeRef: FirTypeRef,
|
||||
override val typeArguments: MutableList<FirTypeProjection>,
|
||||
override var argumentList: FirArgumentList,
|
||||
override var calleeReference: FirReference,
|
||||
override var argumentMapping: FirAnnotationArgumentMapping,
|
||||
@@ -33,12 +35,14 @@ internal class FirAnnotationCallImpl(
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotationTypeRef.accept(visitor, data)
|
||||
typeArguments.forEach { it.accept(visitor, data) }
|
||||
argumentList.accept(visitor, data)
|
||||
calleeReference.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirAnnotationCallImpl {
|
||||
transformAnnotationTypeRef(transformer, data)
|
||||
transformTypeArguments(transformer, data)
|
||||
argumentList = argumentList.transform(transformer, data)
|
||||
transformCalleeReference(transformer, data)
|
||||
return this
|
||||
@@ -53,6 +57,11 @@ internal class FirAnnotationCallImpl(
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirAnnotationCallImpl {
|
||||
typeArguments.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirAnnotationCallImpl {
|
||||
calleeReference = calleeReference.transform(transformer, data)
|
||||
return this
|
||||
@@ -60,6 +69,11 @@ internal class FirAnnotationCallImpl(
|
||||
|
||||
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
|
||||
|
||||
override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>) {
|
||||
typeArguments.clear()
|
||||
typeArguments.addAll(newTypeArguments)
|
||||
}
|
||||
|
||||
override fun replaceArgumentList(newArgumentList: FirArgumentList) {
|
||||
argumentList = newArgumentList
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationArgumentMapping
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
@@ -22,6 +23,7 @@ internal class FirAnnotationImpl(
|
||||
override val useSiteTarget: AnnotationUseSiteTarget?,
|
||||
override var annotationTypeRef: FirTypeRef,
|
||||
override var argumentMapping: FirAnnotationArgumentMapping,
|
||||
override val typeArguments: MutableList<FirTypeProjection>,
|
||||
) : FirAnnotation() {
|
||||
override val typeRef: FirTypeRef get() = annotationTypeRef
|
||||
override val annotations: List<FirAnnotation> get() = emptyList()
|
||||
@@ -29,11 +31,13 @@ internal class FirAnnotationImpl(
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotationTypeRef.accept(visitor, data)
|
||||
argumentMapping.accept(visitor, data)
|
||||
typeArguments.forEach { it.accept(visitor, data) }
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirAnnotationImpl {
|
||||
transformAnnotationTypeRef(transformer, data)
|
||||
argumentMapping = argumentMapping.transform(transformer, data)
|
||||
transformTypeArguments(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -46,9 +50,19 @@ internal class FirAnnotationImpl(
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirAnnotationImpl {
|
||||
typeArguments.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
|
||||
|
||||
override fun replaceArgumentMapping(newArgumentMapping: FirAnnotationArgumentMapping) {
|
||||
argumentMapping = newArgumentMapping
|
||||
}
|
||||
|
||||
override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>) {
|
||||
typeArguments.clear()
|
||||
typeArguments.addAll(newTypeArguments)
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -458,6 +458,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
+field("useSiteTarget", annotationUseSiteTargetType, nullable = true)
|
||||
+field("annotationTypeRef", typeRef).withTransform()
|
||||
+field("argumentMapping", annotationArgumentMapping, withReplace = true)
|
||||
+typeArguments.withTransform()
|
||||
}
|
||||
|
||||
annotationCall.configure {
|
||||
|
||||
Reference in New Issue
Block a user