[FE, IR] Refactor: extract compatibility check of two annotation lists to separate method

This is needed for subsequent checks of annotations
set on types, while currently method accepts only
declarations.

MR: KT-MR-12245

^KT-60671
This commit is contained in:
Roman Efremov
2023-08-04 16:01:10 +02:00
committed by Space Team
parent d092e99ae8
commit ab2c129466
@@ -188,12 +188,21 @@ object AbstractExpectActualAnnotationMatchChecker {
expectSymbol: DeclarationSymbolMarker,
actualSymbol: DeclarationSymbolMarker,
): Incompatibility? {
return areAnnotationListsCompatible(expectSymbol.annotations, actualSymbol.annotations, actualSymbol)
?.let { Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), it) }
}
context (ExpectActualMatchingContext<*>)
private fun areAnnotationListsCompatible(
expectAnnotations: List<ExpectActualMatchingContext.AnnotationCallInfo>,
actualAnnotations: List<ExpectActualMatchingContext.AnnotationCallInfo>,
actualContainerSymbol: DeclarationSymbolMarker,
): IncompatibilityType<ExpectActualMatchingContext.AnnotationCallInfo>? {
// TODO(Roman.Efremov, KT-60671): check annotations set on types
val skipSourceAnnotations = actualContainerSymbol.hasSourceAnnotationsErased
val actualAnnotationsByName = actualAnnotations.groupBy { it.classId }
val skipSourceAnnotations = actualSymbol.hasSourceAnnotationsErased
val actualAnnotationsByName = actualSymbol.annotations.groupBy { it.classId }
for (expectAnnotation in expectSymbol.annotations) {
for (expectAnnotation in expectAnnotations) {
val expectClassId = expectAnnotation.classId ?: continue
if (expectClassId in SKIPPED_CLASS_IDS || expectAnnotation.isOptIn) {
continue
@@ -203,24 +212,18 @@ object AbstractExpectActualAnnotationMatchChecker {
}
val actualAnnotationsWithSameClassId = actualAnnotationsByName[expectClassId] ?: emptyList()
if (actualAnnotationsWithSameClassId.isEmpty()) {
return Incompatibility(
expectSymbol,
actualSymbol,
actualSymbol.getSourceElement(),
IncompatibilityType.MissingOnActual(expectAnnotation)
)
return IncompatibilityType.MissingOnActual(expectAnnotation)
}
val collectionCompatibilityChecker = getAnnotationCollectionArgumentsCompatibilityChecker(expectClassId)
if (actualAnnotationsWithSameClassId.none {
areAnnotationArgumentsEqual(expectAnnotation, it, collectionCompatibilityChecker)
}) {
val incompatibilityType = if (actualAnnotationsWithSameClassId.size == 1) {
return if (actualAnnotationsWithSameClassId.size == 1) {
IncompatibilityType.DifferentOnActual(expectAnnotation, actualAnnotationsWithSameClassId.single())
} else {
// In the case of repeatable annotations, we can't choose on which to report
IncompatibilityType.MissingOnActual(expectAnnotation)
}
return Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), incompatibilityType)
}
}
return null