[FE, IR] Store PsiElement for mismatched annotation's actual target
There is IDE quick fix which suggests to copy mismatched annotation from `expect` to `actual` (see KTIJ-26633). It needs to find `actual` PsiElement where to add annotation. Before previous commit, it was easy - just get source of `Incompatibility.actualSymbol`. After previous commit, the problem might be in value parameter, while `actualSymbol` would contain function symbol. This is solved by adding new field `Incompatibility.actualAnnotationTargetElement`. `SourceElementMarker` introduced, because it's needed to be used in abstract checker. Existing `DeclarationSymbolMarker` doesn't fit because in next PR for this issue annotations set on types will be reported, and types are not declarations. ^KT-60671
This commit is contained in:
committed by
Space Team
parent
5c95f69aef
commit
420dceb7d8
+10
-2
@@ -38,6 +38,13 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
*/
|
||||
val expectSymbol: DeclarationSymbolMarker,
|
||||
val actualSymbol: DeclarationSymbolMarker,
|
||||
|
||||
/**
|
||||
* Link to source code element (possibly holding null, if no source) from actual declaration
|
||||
* where mismatched actual annotation is set (or should be set if it is missing).
|
||||
* Needed for the implementation of IDE intention.
|
||||
*/
|
||||
val actualAnnotationTargetElement: SourceElementMarker,
|
||||
val type: IncompatibilityType<ExpectActualMatchingContext.AnnotationCallInfo>,
|
||||
)
|
||||
|
||||
@@ -122,7 +129,7 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
return expectParams.zip(actualParams).firstNotNullOfOrNull { (expectParam, actualParam) ->
|
||||
areAnnotationsSetOnDeclarationsCompatible(expectParam, actualParam)?.let {
|
||||
// Write containing declarations into diagnostic
|
||||
Incompatibility(expectSymbol, actualSymbol, it.type)
|
||||
Incompatibility(expectSymbol, actualSymbol, actualParam.getSourceElement(), it.type)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,6 +157,7 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
return Incompatibility(
|
||||
expectSymbol,
|
||||
actualSymbol,
|
||||
actualSymbol.getSourceElement(),
|
||||
IncompatibilityType.MissingOnActual(expectAnnotation)
|
||||
)
|
||||
}
|
||||
@@ -163,7 +171,7 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
// In the case of repeatable annotations, we can't choose on which to report
|
||||
IncompatibilityType.MissingOnActual(expectAnnotation)
|
||||
}
|
||||
return Incompatibility(expectSymbol, actualSymbol, incompatibilityType)
|
||||
return Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), incompatibilityType)
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
+2
@@ -213,4 +213,6 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
|
||||
actualMember: DeclarationSymbolMarker,
|
||||
checkClassScopesCompatibility: Boolean,
|
||||
): Map<out DeclarationSymbolMarker, ExpectActualCompatibility<*>>
|
||||
|
||||
fun DeclarationSymbolMarker.getSourceElement(): SourceElementMarker
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user