[FIR] Implement VERSION_REQUIREMENT_DEPRECATION diagnostics
This commit is contained in:
committed by
Space Team
parent
65ea9697ab
commit
09f895efe6
+30
-5
@@ -11,9 +11,11 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.caches.FirCache
|
||||
import org.jetbrains.kotlin.fir.caches.FirCachesFactory
|
||||
import org.jetbrains.kotlin.fir.caches.createCache
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirement
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.SimpleDeprecationInfo
|
||||
import org.jetbrains.kotlin.resolve.deprecation.isFulfilled
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||
|
||||
abstract class DeprecationsProvider {
|
||||
@@ -55,8 +57,8 @@ object UnresolvedDeprecationProvider : DeprecationsProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface DeprecationAnnotationInfo {
|
||||
fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo?
|
||||
sealed class DeprecationAnnotationInfo {
|
||||
abstract fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo?
|
||||
}
|
||||
|
||||
data class FutureApiDeprecationInfo(
|
||||
@@ -67,7 +69,30 @@ data class FutureApiDeprecationInfo(
|
||||
override val message: String? get() = null
|
||||
}
|
||||
|
||||
class SinceKotlinInfo(val sinceVersion: ApiVersion) : DeprecationAnnotationInfo {
|
||||
data class RequireKotlinDeprecationInfo(
|
||||
override val deprecationLevel: DeprecationLevelValue,
|
||||
val versionRequirement: VersionRequirement
|
||||
) : DeprecationInfo() {
|
||||
override val message: String? get() = versionRequirement.message
|
||||
override val propagatesToOverrides: Boolean get() = false
|
||||
}
|
||||
|
||||
class RequireKotlinInfo(private val versionRequirement: VersionRequirement) : DeprecationAnnotationInfo() {
|
||||
override fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo? {
|
||||
return runUnless(versionRequirement.isFulfilled(languageVersionSettings)) {
|
||||
RequireKotlinDeprecationInfo(
|
||||
deprecationLevel = when (versionRequirement.level) {
|
||||
DeprecationLevel.WARNING -> DeprecationLevelValue.WARNING
|
||||
DeprecationLevel.ERROR -> DeprecationLevelValue.ERROR
|
||||
DeprecationLevel.HIDDEN -> DeprecationLevelValue.HIDDEN
|
||||
},
|
||||
versionRequirement = versionRequirement
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SinceKotlinInfo(val sinceVersion: ApiVersion) : DeprecationAnnotationInfo() {
|
||||
override fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo? {
|
||||
return runUnless(sinceVersion <= languageVersionSettings.apiVersion) {
|
||||
FutureApiDeprecationInfo(
|
||||
@@ -83,7 +108,7 @@ class DeprecatedInfo(
|
||||
val level: DeprecationLevelValue,
|
||||
val propagatesToOverride: Boolean,
|
||||
val message: String?
|
||||
) : DeprecationAnnotationInfo {
|
||||
) : DeprecationAnnotationInfo() {
|
||||
override fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo {
|
||||
return SimpleDeprecationInfo(
|
||||
level,
|
||||
@@ -99,7 +124,7 @@ class DeprecatedSinceKotlinInfo(
|
||||
val hiddenVersion: ApiVersion?,
|
||||
val message: String?,
|
||||
val propagatesToOverride: Boolean
|
||||
) : DeprecationAnnotationInfo {
|
||||
) : DeprecationAnnotationInfo() {
|
||||
override fun computeDeprecationInfo(languageVersionSettings: LanguageVersionSettings): DeprecationInfo? {
|
||||
fun ApiVersion.takeLevelIfDeprecated(level: DeprecationLevelValue) = level.takeIf { this <= languageVersionSettings.apiVersion }
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirement
|
||||
|
||||
object FirVersionRequirementsTableKey : FirDeclarationDataKey()
|
||||
|
||||
var FirDeclaration.versionRequirements: List<VersionRequirement>? by FirDeclarationDataRegistry.data(FirVersionRequirementsTableKey)
|
||||
@@ -30,7 +30,7 @@ sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
||||
val name get() = classId.shortClassName
|
||||
|
||||
fun getOwnDeprecation(languageVersionSettings: LanguageVersionSettings): DeprecationsPerUseSite? {
|
||||
if (annotations.isEmpty()) return null
|
||||
if (annotations.isEmpty() && fir.versionRequirements.isNullOrEmpty()) return null
|
||||
lazyResolveToPhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS)
|
||||
return fir.deprecationsProvider.getDeprecationsInfo(languageVersionSettings)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user