[FIR] Generate annotations to data class copy method parameters

#KT-57003 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-15 13:45:27 +02:00
committed by Space Team
parent 5ae3a93084
commit 0ac02be534
25 changed files with 255 additions and 43 deletions
@@ -164,18 +164,21 @@ internal fun deserializeClassToSymbol(
if (classOrObject.isData() && firPrimaryConstructor != null) {
val zippedParameters =
classOrObject.primaryConstructorParameters.filter { it.hasValOrVar() } zip declarations.filterIsInstance<FirProperty>()
addDeclaration(createDataClassCopyFunction(classId, classOrObject, context.dispatchReceiver, zippedParameters,
createClassTypeRefWithSourceKind = {
firPrimaryConstructor.returnTypeRef.copyWithNewSourceKind(
it
)
},
createParameterTypeRefWithSourceKind = { property, newKind ->
property.returnTypeRef.copyWithNewSourceKind(newKind)
}) { src, kind ->
KtFakeSourceElement(src as PsiElement, kind)
})
classOrObject.primaryConstructorParameters zip declarations.filterIsInstance<FirProperty>()
addDeclaration(
createDataClassCopyFunction(
classId,
classOrObject,
context.dispatchReceiver,
zippedParameters,
createClassTypeRefWithSourceKind = { firPrimaryConstructor.returnTypeRef.copyWithNewSourceKind(it) },
createParameterTypeRefWithSourceKind = { property, newKind ->
property.returnTypeRef.copyWithNewSourceKind(newKind)
},
toFirSource = { src, kind -> KtFakeSourceElement(src as PsiElement, kind) },
addValueParameterAnnotations = { annotations += context.annotationDeserializer.loadAnnotations(it) },
)
)
}
addCloneForArrayIfNeeded(classId, context.dispatchReceiver)
@@ -1446,6 +1446,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt");
}
@Test
@TestMetadata("annotationsOnDataClassCopy.kt")
public void testAnnotationsOnDataClassCopy() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/annotationsOnDataClassCopy.kt");
}
@Test
@TestMetadata("annotationsOnLambdaAsCallArgument.kt")
public void testAnnotationsOnLambdaAsCallArgument() throws Exception {
@@ -1446,6 +1446,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt");
}
@Test
@TestMetadata("annotationsOnDataClassCopy.kt")
public void testAnnotationsOnDataClassCopy() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/annotationsOnDataClassCopy.kt");
}
@Test
@TestMetadata("annotationsOnLambdaAsCallArgument.kt")
public void testAnnotationsOnLambdaAsCallArgument() throws Exception {