[FIR] Implement DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS diagnostics, fix tests, merge and refactor annotation checkers

This commit is contained in:
Ivan Kochurkin
2021-05-11 15:21:38 +03:00
committed by TeamCityServer
parent dc99a673a5
commit 3191e0b925
14 changed files with 141 additions and 142 deletions
@@ -102,5 +102,3 @@ class NullForNotNullType(
class ManyLambdaExpressionArguments(
val argument: FirExpression
) : ResolutionDiagnostic(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR)
object DeprecatedSinceKotlinWithUnorderedVersions : ResolutionDiagnostic(INAPPLICABLE)
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirSymbolOwner
import org.jetbrains.kotlin.fir.FirVisibilityChecker
@@ -157,8 +156,6 @@ internal object CheckArguments : CheckerStage() {
)
}
checkDeprecatedSinceKotlinArgs(candidate, argumentMapping, sink)
if (candidate.system.hasContradiction && callInfo.arguments.isNotEmpty()) {
sink.yieldDiagnostic(InapplicableCandidate)
}
@@ -169,57 +166,6 @@ internal object CheckArguments : CheckerStage() {
FqName("DeprecatedSinceKotlin"),
Name.identifier("DeprecatedSinceKotlin")
)
private suspend fun checkDeprecatedSinceKotlinArgs(
candidate: Candidate,
argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>,
sink: CheckerSink
) {
val symbol = candidate.symbol
if (symbol is FirFunctionSymbol<*>) {
if (symbol.callableId == deprecatedSinceKotlin) {
var warningSince: ApiVersion? = null
var errorSince: ApiVersion? = null
var hiddenSince: ApiVersion? = null
for (argument in argumentMapping) {
val identifier = argument.value.name.identifier
if (identifier == "warningSince" || identifier == "errorSince" || identifier == "hiddenSince") {
val argKey = argument.key
val constExpression = (argKey as? FirConstExpression<*>)
?: ((argKey as? FirNamedArgumentExpression)?.expression as? FirConstExpression<*>)
val stringValue = constExpression?.value as? String
if (stringValue != null) {
val version = ApiVersion.parse(stringValue)
when (identifier) {
"warningSince" -> warningSince = version
"errorSince" -> errorSince = version
"hiddenSince" -> hiddenSince = version
}
}
}
}
var isReportDeprecatedSinceKotlinWithUnorderedVersions = false
if (warningSince != null) {
if (errorSince != null) {
isReportDeprecatedSinceKotlinWithUnorderedVersions = warningSince > errorSince
}
if (hiddenSince != null && !isReportDeprecatedSinceKotlinWithUnorderedVersions) {
isReportDeprecatedSinceKotlinWithUnorderedVersions = warningSince > hiddenSince
}
}
if (errorSince != null && hiddenSince != null && !isReportDeprecatedSinceKotlinWithUnorderedVersions) {
isReportDeprecatedSinceKotlinWithUnorderedVersions = errorSince > hiddenSince
}
if (isReportDeprecatedSinceKotlinWithUnorderedVersions) {
sink.yieldDiagnostic(DeprecatedSinceKotlinWithUnorderedVersions)
}
}
}
}
}
internal object EagerResolveOfCallableReferences : CheckerStage() {