[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:
committed by
Space Team
parent
d092e99ae8
commit
ab2c129466
+15
-12
@@ -188,12 +188,21 @@ object AbstractExpectActualAnnotationMatchChecker {
|
|||||||
expectSymbol: DeclarationSymbolMarker,
|
expectSymbol: DeclarationSymbolMarker,
|
||||||
actualSymbol: DeclarationSymbolMarker,
|
actualSymbol: DeclarationSymbolMarker,
|
||||||
): Incompatibility? {
|
): 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
|
// TODO(Roman.Efremov, KT-60671): check annotations set on types
|
||||||
|
val skipSourceAnnotations = actualContainerSymbol.hasSourceAnnotationsErased
|
||||||
|
val actualAnnotationsByName = actualAnnotations.groupBy { it.classId }
|
||||||
|
|
||||||
val skipSourceAnnotations = actualSymbol.hasSourceAnnotationsErased
|
for (expectAnnotation in expectAnnotations) {
|
||||||
val actualAnnotationsByName = actualSymbol.annotations.groupBy { it.classId }
|
|
||||||
|
|
||||||
for (expectAnnotation in expectSymbol.annotations) {
|
|
||||||
val expectClassId = expectAnnotation.classId ?: continue
|
val expectClassId = expectAnnotation.classId ?: continue
|
||||||
if (expectClassId in SKIPPED_CLASS_IDS || expectAnnotation.isOptIn) {
|
if (expectClassId in SKIPPED_CLASS_IDS || expectAnnotation.isOptIn) {
|
||||||
continue
|
continue
|
||||||
@@ -203,24 +212,18 @@ object AbstractExpectActualAnnotationMatchChecker {
|
|||||||
}
|
}
|
||||||
val actualAnnotationsWithSameClassId = actualAnnotationsByName[expectClassId] ?: emptyList()
|
val actualAnnotationsWithSameClassId = actualAnnotationsByName[expectClassId] ?: emptyList()
|
||||||
if (actualAnnotationsWithSameClassId.isEmpty()) {
|
if (actualAnnotationsWithSameClassId.isEmpty()) {
|
||||||
return Incompatibility(
|
return IncompatibilityType.MissingOnActual(expectAnnotation)
|
||||||
expectSymbol,
|
|
||||||
actualSymbol,
|
|
||||||
actualSymbol.getSourceElement(),
|
|
||||||
IncompatibilityType.MissingOnActual(expectAnnotation)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
val collectionCompatibilityChecker = getAnnotationCollectionArgumentsCompatibilityChecker(expectClassId)
|
val collectionCompatibilityChecker = getAnnotationCollectionArgumentsCompatibilityChecker(expectClassId)
|
||||||
if (actualAnnotationsWithSameClassId.none {
|
if (actualAnnotationsWithSameClassId.none {
|
||||||
areAnnotationArgumentsEqual(expectAnnotation, it, collectionCompatibilityChecker)
|
areAnnotationArgumentsEqual(expectAnnotation, it, collectionCompatibilityChecker)
|
||||||
}) {
|
}) {
|
||||||
val incompatibilityType = if (actualAnnotationsWithSameClassId.size == 1) {
|
return if (actualAnnotationsWithSameClassId.size == 1) {
|
||||||
IncompatibilityType.DifferentOnActual(expectAnnotation, actualAnnotationsWithSameClassId.single())
|
IncompatibilityType.DifferentOnActual(expectAnnotation, actualAnnotationsWithSameClassId.single())
|
||||||
} else {
|
} else {
|
||||||
// In the case of repeatable annotations, we can't choose on which to report
|
// In the case of repeatable annotations, we can't choose on which to report
|
||||||
IncompatibilityType.MissingOnActual(expectAnnotation)
|
IncompatibilityType.MissingOnActual(expectAnnotation)
|
||||||
}
|
}
|
||||||
return Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), incompatibilityType)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user