FIR2IR: filter correct use-site target for value parameter annotations.
This commit is contained in:
committed by
Mikhail Glukhikh
parent
76e679a6ca
commit
e844c59e7e
+12
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
|||||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrVisitor
|
import org.jetbrains.kotlin.fir.backend.Fir2IrVisitor
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.util.isPropertyField
|
import org.jetbrains.kotlin.ir.util.isPropertyField
|
||||||
@@ -22,6 +23,17 @@ internal class AnnotationGenerator(private val visitor: Fir2IrVisitor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun generate(irValueParameter: IrValueParameter, firValueParameter: FirValueParameter, isInConstructor: Boolean) {
|
||||||
|
irValueParameter.annotations +=
|
||||||
|
firValueParameter.annotations
|
||||||
|
.filter {
|
||||||
|
it.useSiteTarget == null || !isInConstructor || it.useSiteTarget == AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER
|
||||||
|
}
|
||||||
|
.mapNotNull {
|
||||||
|
it.accept(visitor, null) as? IrConstructorCall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun generate(irProperty: IrProperty, property: FirProperty) {
|
fun generate(irProperty: IrProperty, property: FirProperty) {
|
||||||
irProperty.annotations +=
|
irProperty.annotations +=
|
||||||
property.annotations
|
property.annotations
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ internal class ClassMemberGenerator(
|
|||||||
}
|
}
|
||||||
for ((valueParameter, firValueParameter) in valueParameters.zip(firFunction.valueParameters)) {
|
for ((valueParameter, firValueParameter) in valueParameters.zip(firFunction.valueParameters)) {
|
||||||
valueParameter.setDefaultValue(firValueParameter)
|
valueParameter.setDefaultValue(firValueParameter)
|
||||||
annotationGenerator.generate(valueParameter, firValueParameter)
|
annotationGenerator.generate(valueParameter, firValueParameter, irFunction is IrConstructor)
|
||||||
}
|
}
|
||||||
annotationGenerator.generate(irFunction, firFunction)
|
annotationGenerator.generate(irFunction, firFunction)
|
||||||
}
|
}
|
||||||
|
|||||||
-5
@@ -31,12 +31,7 @@ FILE fqName:<root> fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
|
||||||
CONSTRUCTOR visibility:public <> (x:kotlin.Int, y:kotlin.Int) returnType:<root>.C [primary]
|
CONSTRUCTOR visibility:public <> (x:kotlin.Int, y:kotlin.Int) returnType:<root>.C [primary]
|
||||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||||
annotations:
|
|
||||||
A(x = 'C.x.get')
|
|
||||||
VALUE_PARAMETER name:y index:1 type:kotlin.Int
|
VALUE_PARAMETER name:y index:1 type:kotlin.Int
|
||||||
annotations:
|
|
||||||
A(x = 'C.y.get')
|
|
||||||
A(x = 'C.y.set')
|
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||||
|
|||||||
Vendored
-2
@@ -36,8 +36,6 @@ FILE fqName:<root> fileName:/propertySetterParameterWithAnnotations.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
|
||||||
CONSTRUCTOR visibility:public <> (p:kotlin.Int) returnType:<root>.C [primary]
|
CONSTRUCTOR visibility:public <> (p:kotlin.Int) returnType:<root>.C [primary]
|
||||||
VALUE_PARAMETER name:p index:0 type:kotlin.Int
|
VALUE_PARAMETER name:p index:0 type:kotlin.Int
|
||||||
annotations:
|
|
||||||
AnnParam
|
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||||
|
|||||||
Reference in New Issue
Block a user