From 762d225bd7088719b5e0039c867c2af90985cf2e Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 27 Aug 2021 12:51:16 +0300 Subject: [PATCH] Unify Deprecation classes from :core:compiler.common and :compiler:frontend modules --- .../symbol/annotations/annotationsUtils.kt | 5 +-- .../expression/FirDeprecationChecker.kt | 6 +-- .../fir/declarations/deprecationUtils.kt | 7 +-- .../fir/resolve/calls/ResolutionStages.kt | 4 +- .../fir/resolve/diagnostics/FirDiagnostics.kt | 2 +- .../kotlin/fir/declarations/deprecations.kt | 6 +-- .../kotlin/resolve/deprecation/Deprecation.kt | 14 +++--- .../deprecation/DeprecationResolver.kt | 20 ++++----- .../resolve/deprecation/deprecationUtil.kt | 7 ++- .../kotlin/descriptors/Deprecation.kt | 27 ------------ .../kotlin/resolve/deprecation/Deprecation.kt | 33 ++++++++++++++ .../org/jetbrains/kotlin/load/java/utils.kt | 6 +-- ...ation.kt => DescriptorBasedDeprecation.kt} | 17 +++---- .../api/components/KtSymbolInfoProvider.kt | 4 +- .../api/symbols/DebugSymbolRenderer.kt | 2 +- .../fir/components/KtFirSymbolInfoProvider.kt | 4 +- .../memberScopeByFqName/java.lang.String.txt | 8 ++-- .../symbols/symbolByPsi/deprecated.txt | 44 +++++++++---------- 18 files changed, 108 insertions(+), 108 deletions(-) delete mode 100644 core/compiler.common/src/org/jetbrains/kotlin/descriptors/Deprecation.kt create mode 100644 core/compiler.common/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt rename core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/{deprecation.kt => DescriptorBasedDeprecation.kt} (59%) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/annotationsUtils.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/annotationsUtils.kt index 4921ce2b2a5..b45ee86a06b 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/annotationsUtils.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/annotationsUtils.kt @@ -10,12 +10,11 @@ import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiElement import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable -import org.jetbrains.kotlin.descriptors.DeprecationLevelValue +import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSimpleConstantValue -import org.jetbrains.kotlin.name.StandardClassIds internal fun KtAnnotatedSymbol.hasJvmSyntheticAnnotation(annotationUseSiteTarget: AnnotationUseSiteTarget? = null): Boolean = hasAnnotation("kotlin/jvm/JvmSynthetic", annotationUseSiteTarget) @@ -41,7 +40,7 @@ internal fun isHiddenByDeprecation( annotationUseSiteTarget: AnnotationUseSiteTarget? = null ): Boolean { return project.analyzeWithSymbolAsContext(symbol) { - symbol.getDeprecationStatus(annotationUseSiteTarget)?.level == DeprecationLevelValue.HIDDEN + symbol.getDeprecationStatus(annotationUseSiteTarget)?.deprecationLevel == DeprecationLevelValue.HIDDEN } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt index b604c9c9dcb..16e463def9b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirDeprecationChecker.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression -import org.jetbrains.kotlin.descriptors.Deprecation -import org.jetbrains.kotlin.descriptors.DeprecationLevelValue +import org.jetbrains.kotlin.resolve.deprecation.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirFakeSourceElementKind import org.jetbrains.kotlin.fir.FirRealSourceElementKind @@ -58,7 +58,7 @@ object FirDeprecationChecker : FirBasicExpressionChecker() { reporter: DiagnosticReporter, context: CheckerContext ) { - val diagnostic = when (deprecation.level) { + val diagnostic = when (deprecation.deprecationLevel) { DeprecationLevelValue.ERROR, DeprecationLevelValue.HIDDEN -> FirErrors.DEPRECATION_ERROR DeprecationLevelValue.WARNING -> FirErrors.DEPRECATION } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt index 1f675d8bb9b..bd7bad8c4de 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.fir.declarations import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.config.ApiVersion -import org.jetbrains.kotlin.descriptors.Deprecation -import org.jetbrains.kotlin.descriptors.DeprecationLevelValue +import org.jetbrains.kotlin.resolve.deprecation.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.fir.FirAnnotationContainer import org.jetbrains.kotlin.fir.FirElement @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.deprecation.SimpleDeprecation import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -126,7 +127,7 @@ private fun List.extractDeprecationInfoPerUseSite( appliedLevel?.let { val inheritable = !fromJavaAnnotation && !fromJava - deprecated.useSiteTarget to Deprecation(it, inheritable, deprecated.getStringArgument(MESSAGE_NAME)) + deprecated.useSiteTarget to SimpleDeprecation(it, inheritable, deprecated.getStringArgument(MESSAGE_NAME)) } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index b685448281b..39bede7a30b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.fir.resolve.calls -import org.jetbrains.kotlin.descriptors.DeprecationLevelValue +import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.FirVisibilityChecker import org.jetbrains.kotlin.fir.declarations.* @@ -310,7 +310,7 @@ internal object CheckDeprecatedSinceKotlin : ResolutionStage() { override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { val symbol = candidate.symbol as? FirCallableSymbol<*> ?: return val deprecation = symbol.getDeprecation(callInfo.callSite) - if (deprecation != null && deprecation.level == DeprecationLevelValue.HIDDEN) { + if (deprecation != null && deprecation.deprecationLevel == DeprecationLevelValue.HIDDEN) { sink.yieldDiagnostic(HiddenCandidate) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt index ecbda656554..cb634c8df10 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.fir.resolve.diagnostics import kotlinx.collections.immutable.ImmutableList -import org.jetbrains.kotlin.descriptors.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.Deprecation import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirVariable diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/deprecations.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/deprecations.kt index ab41c0b2378..d7ce2daa9fd 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/deprecations.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/deprecations.kt @@ -1,6 +1,6 @@ package org.jetbrains.kotlin.fir.declarations -import org.jetbrains.kotlin.descriptors.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.Deprecation import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.utils.keysToMap import org.jetbrains.kotlin.utils.keysToMapExceptNulls @@ -59,8 +59,8 @@ class DeprecationsPerUseSite( fun inheritableOnly(): DeprecationsPerUseSite = DeprecationsPerUseSite( - all?.takeIf { it.inheritable }, - bySpecificSite?.filterValues { it.inheritable } + all?.takeIf { it.propagatesToOverrides }, + bySpecificSite?.filterValues { it.propagatesToOverrides } ) override fun toString(): String = diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt index 5f97317faf5..2322a444dec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt @@ -25,7 +25,7 @@ internal sealed class DeprecatedByAnnotation( val annotation: AnnotationDescriptor, override val target: DeclarationDescriptor, override val propagatesToOverrides: Boolean -) : Deprecation { +) : DescriptorBasedDeprecation() { override val message: String? get() = annotation.argumentValue("message")?.safeAs()?.value @@ -111,13 +111,13 @@ internal sealed class DeprecatedByAnnotation( } } -internal data class DeprecatedByOverridden(private val deprecations: Collection) : Deprecation { +internal data class DeprecatedByOverridden(private val deprecations: Collection) : DescriptorBasedDeprecation() { init { assert(deprecations.isNotEmpty()) assert(deprecations.none { it is DeprecatedByOverridden }) } - override val deprecationLevel: DeprecationLevelValue = deprecations.map(Deprecation::deprecationLevel).minOrNull()!! + override val deprecationLevel: DeprecationLevelValue = deprecations.map(DescriptorBasedDeprecation::deprecationLevel).minOrNull()!! override val target: DeclarationDescriptor get() = deprecations.first().target @@ -134,8 +134,8 @@ internal data class DeprecatedByOverridden(private val deprecations: Collection< internal data class DeprecatedOperatorMod( val languageVersionSettings: LanguageVersionSettings, - val currentDeprecation: Deprecation -) : Deprecation { + val currentDeprecation: DescriptorBasedDeprecation +) : DescriptorBasedDeprecation() { init { assert(shouldWarnAboutDeprecatedModFromBuiltIns(languageVersionSettings)) { "Deprecation created for mod that shouldn't have any deprecations; languageVersionSettings: $languageVersionSettings" @@ -159,7 +159,7 @@ internal data class DeprecatedOperatorMod( internal data class DeprecatedByVersionRequirement( val versionRequirement: VersionRequirement, override val target: DeclarationDescriptor -) : Deprecation { +) : DescriptorBasedDeprecation() { override val deprecationLevel: DeprecationLevelValue get() = when (versionRequirement.level) { DeprecationLevel.WARNING -> WARNING @@ -189,7 +189,7 @@ internal data class DeprecatedByVersionRequirement( internal data class DeprecatedTypealiasByAnnotation( val typeAliasTarget: TypeAliasDescriptor, val nested: DeprecatedByAnnotation -) : Deprecation { +) : DescriptorBasedDeprecation() { override val target get() = typeAliasTarget override val deprecationLevel get() = nested.deprecationLevel override val message get() = nested.message diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt index c2298cc5836..29d7575e3f1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt @@ -51,7 +51,7 @@ class DeprecationResolver( descriptor.checkSinceKotlinVersionAccessibility(languageVersionSettings) } - fun getDeprecations(descriptor: DeclarationDescriptor): List = + fun getDeprecations(descriptor: DeclarationDescriptor): List = deprecations(descriptor.original) fun isDeprecatedHidden(descriptor: DeclarationDescriptor): Boolean = @@ -99,8 +99,8 @@ class DeprecationResolver( return isDeprecatedHidden(descriptor) } - private fun KotlinType.deprecationsByConstituentTypes(): List = - SmartList().also { deprecations -> + private fun KotlinType.deprecationsByConstituentTypes(): List = + SmartList().also { deprecations -> TypeUtils.contains(this) { type -> type.constructor.declarationDescriptor?.let { deprecations.addAll(getDeprecations(it)) @@ -109,9 +109,9 @@ class DeprecationResolver( } } - private fun deprecationByOverridden(root: CallableMemberDescriptor): Deprecation? { + private fun deprecationByOverridden(root: CallableMemberDescriptor): DescriptorBasedDeprecation? { val visited = HashSet() - val deprecations = LinkedHashSet() + val deprecations = LinkedHashSet() var hasUndeprecatedOverridden = false fun traverse(node: CallableMemberDescriptor) { @@ -159,12 +159,12 @@ class DeprecationResolver( // // Also, we don't ignore non-propagating deprecations in case of fake overrides // Because we don't want to depend on the choice of the base descriptor - if (root.kind.isReal && deprecations.none(Deprecation::propagatesToOverrides)) return null + if (root.kind.isReal && deprecations.none(DescriptorBasedDeprecation::propagatesToOverrides)) return null return DeprecatedByOverridden(deprecations) } - private fun DeclarationDescriptor.getOwnDeprecations(): List { + private fun DeclarationDescriptor.getOwnDeprecations(): List { // The problem is that declaration `mod` in built-ins has @Deprecated annotation but actually it was deprecated only in version 1.1 if (isBuiltInOperatorMod && !shouldWarnAboutDeprecatedModFromBuiltIns(languageVersionSettings)) { return emptyList() @@ -175,7 +175,7 @@ class DeprecationResolver( return emptyList() } - val result = SmartList() + val result = SmartList() addDeprecationIfPresent(result) @@ -197,7 +197,7 @@ class DeprecationResolver( return result.distinct() } - private fun DeclarationDescriptor.addDeprecationIfPresent(result: MutableList) { + private fun DeclarationDescriptor.addDeprecationIfPresent(result: MutableList) { val annotation = annotations.findAnnotation(StandardNames.FqNames.deprecated) ?: annotations.findAnnotation(JAVA_DEPRECATED) if (annotation != null) { val deprecatedByAnnotation = @@ -238,7 +238,7 @@ class DeprecationResolver( descriptor.valueParameters.singleOrNull()?.type?.let(KotlinBuiltIns::isInt) == true && languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3 - private fun getDeprecationFromUserData(target: DeclarationDescriptor): Deprecation? = + private fun getDeprecationFromUserData(target: DeclarationDescriptor): DescriptorBasedDeprecation? = target.safeAs()?.getUserData(DEPRECATED_FUNCTION_KEY) private fun getDeprecationByVersionRequirement(target: DeclarationDescriptor): List { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/deprecationUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/deprecationUtil.kt index a1862754132..693da9a95cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/deprecationUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/deprecationUtil.kt @@ -9,7 +9,6 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.container.DefaultImplementation -import org.jetbrains.kotlin.container.PlatformSpecificExtension import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors @@ -18,9 +17,9 @@ import org.jetbrains.kotlin.resolve.constants.StringValue import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue.* import org.jetbrains.kotlin.utils.addToStdlib.safeAs -fun Deprecation.deprecatedByOverriddenMessage(): String? = (this as? DeprecatedByOverridden)?.additionalMessage() +fun DescriptorBasedDeprecation.deprecatedByOverriddenMessage(): String? = (this as? DeprecatedByOverridden)?.additionalMessage() -fun Deprecation.deprecatedByAnnotationReplaceWithExpression(): String? = (this as? DeprecatedByAnnotation)?.replaceWithValue +fun DescriptorBasedDeprecation.deprecatedByAnnotationReplaceWithExpression(): String? = (this as? DeprecatedByAnnotation)?.replaceWithValue // The function extracts value of warningSince/errorSince/hiddenSince from DeprecatedSinceKotlin annotation fun AnnotationDescriptor.getSinceVersion(name: String): ApiVersion? = @@ -40,7 +39,7 @@ fun computeLevelForDeprecatedSinceKotlin(annotation: AnnotationDescriptor, apiVe } internal fun createDeprecationDiagnostic( - element: PsiElement, deprecation: Deprecation, languageVersionSettings: LanguageVersionSettings + element: PsiElement, deprecation: DescriptorBasedDeprecation, languageVersionSettings: LanguageVersionSettings ): Diagnostic { val targetOriginal = deprecation.target.original return when (deprecation) { diff --git a/core/compiler.common/src/org/jetbrains/kotlin/descriptors/Deprecation.kt b/core/compiler.common/src/org/jetbrains/kotlin/descriptors/Deprecation.kt deleted file mode 100644 index d94ebe25fb8..00000000000 --- a/core/compiler.common/src/org/jetbrains/kotlin/descriptors/Deprecation.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2021 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.descriptors - -data class Deprecation( - val level: DeprecationLevelValue, - val inheritable: Boolean, - val message: String? = null -) : Comparable { - override fun compareTo(other: Deprecation): Int { - val lr = level.compareTo(other.level) - //to prefer inheritable deprecation - return if (lr == 0 && !inheritable && other.inheritable) 1 - else lr - } -} - -/** - * This corresponds to [DeprecationLevel] in Kotlin standard library. A symbol annotated with [java.lang.Deprecated] is considered a - * warning. - */ -enum class DeprecationLevelValue { - WARNING, ERROR, HIDDEN -} diff --git a/core/compiler.common/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt b/core/compiler.common/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt new file mode 100644 index 00000000000..535b22e88aa --- /dev/null +++ b/core/compiler.common/src/org/jetbrains/kotlin/resolve/deprecation/Deprecation.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2021 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.resolve.deprecation + +abstract class Deprecation : Comparable { + abstract val deprecationLevel: DeprecationLevelValue + abstract val propagatesToOverrides: Boolean + abstract val message: String? + + override fun compareTo(other: Deprecation): Int { + val lr = deprecationLevel.compareTo(other.deprecationLevel) + //to prefer inheritable deprecation + return if (lr == 0 && !propagatesToOverrides && other.propagatesToOverrides) 1 + else lr + } +} + +data class SimpleDeprecation( + override val deprecationLevel: DeprecationLevelValue, + override val propagatesToOverrides: Boolean, + override val message: String? +) : Deprecation() + +/** + * This corresponds to [DeprecationLevel] in Kotlin standard library. A symbol annotated with [java.lang.Deprecated] is considered a + * warning. + */ +enum class DeprecationLevelValue { + WARNING, ERROR, HIDDEN +} diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/utils.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/utils.kt index 30a82002d09..821a698ac16 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/utils.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/utils.kt @@ -20,13 +20,13 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.Visibility -import org.jetbrains.kotlin.resolve.deprecation.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.DescriptorBasedDeprecation import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue -class DeprecationCausedByFunctionN(override val target: DeclarationDescriptor) : Deprecation { +class DeprecationCausedByFunctionN(override val target: DeclarationDescriptor) : DescriptorBasedDeprecation() { override val deprecationLevel: DeprecationLevelValue get() = DeprecationLevelValue.ERROR - override val message: String? + override val message: String get() = "Java members containing references to ${JavaToKotlinClassMap.FUNCTION_N_FQ_NAME} are not supported" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/deprecation.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/DescriptorBasedDeprecation.kt similarity index 59% rename from core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/deprecation.kt rename to core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/DescriptorBasedDeprecation.kt index ed58e345714..432822a2e1f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/deprecation.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/deprecation/DescriptorBasedDeprecation.kt @@ -8,16 +8,11 @@ package org.jetbrains.kotlin.resolve.deprecation import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -interface Deprecation { - val deprecationLevel: DeprecationLevelValue - val message: String? - val target: DeclarationDescriptor - val propagatesToOverrides: Boolean get() = true +abstract class DescriptorBasedDeprecation : Deprecation() { + override val propagatesToOverrides: Boolean + get() = true + + abstract val target: DeclarationDescriptor } -// values from kotlin.DeprecationLevel -enum class DeprecationLevelValue { - WARNING, ERROR, HIDDEN -} - -val DEPRECATED_FUNCTION_KEY = object : CallableDescriptor.UserDataKey {} +val DEPRECATED_FUNCTION_KEY = object : CallableDescriptor.UserDataKey {} diff --git a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtSymbolInfoProvider.kt b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtSymbolInfoProvider.kt index ff5e172ab54..f2c91ac89ad 100644 --- a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtSymbolInfoProvider.kt +++ b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtSymbolInfoProvider.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.frontend.api.components -import org.jetbrains.kotlin.descriptors.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.Deprecation import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPropertySymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol @@ -41,4 +41,4 @@ public interface KtSymbolInfoProviderMixIn : KtAnalysisSessionMixIn { */ public val KtPropertySymbol.setterDeprecationStatus: Deprecation? get() = analysisSession.symbolInfoProvider.getSetterDeprecation(this) -} \ No newline at end of file +} diff --git a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/DebugSymbolRenderer.kt b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/DebugSymbolRenderer.kt index 1c2ffc12fe4..ba6e707caba 100644 --- a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/DebugSymbolRenderer.kt +++ b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/symbols/DebugSymbolRenderer.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols -import org.jetbrains.kotlin.descriptors.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.Deprecation import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.components.KtSymbolInfoProviderMixIn import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.* diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirSymbolInfoProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirSymbolInfoProvider.kt index 40bbabdce1b..5befb3a6610 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirSymbolInfoProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirSymbolInfoProvider.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.components -import org.jetbrains.kotlin.descriptors.Deprecation +import org.jetbrains.kotlin.resolve.deprecation.Deprecation import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.fir.declarations.getDeprecationForCallSite import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol @@ -59,4 +59,4 @@ internal class KtFirSymbolInfoProvider( it.symbol.getDeprecationForCallSite(AnnotationUseSiteTarget.PROPERTY_SETTER, AnnotationUseSiteTarget.PROPERTY) } } -} \ No newline at end of file +} diff --git a/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt b/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt index 5cf1def82cd..981739b0488 100644 --- a/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt +++ b/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt @@ -320,7 +320,7 @@ KtFirFunctionSymbol: KtFirValueParameterSymbol(p3) ] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=false, message=Deprecated in Java) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=Deprecated in Java) KtFirFunctionSymbol: annotatedType: [] ft @@ -1721,7 +1721,7 @@ KtFirConstructorSymbol: KtFirValueParameterSymbol(p3) ] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=false, message=Deprecated in Java) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=Deprecated in Java) KtFirConstructorSymbol: annotatedType: [] java/lang/String @@ -1747,7 +1747,7 @@ KtFirConstructorSymbol: KtFirValueParameterSymbol(p1) ] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=false, message=Deprecated in Java) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=Deprecated in Java) KtFirConstructorSymbol: annotatedType: [] java/lang/String @@ -1965,4 +1965,4 @@ KtFirConstructorSymbol: KtFirValueParameterSymbol(p2) ] visibility: PackageVisibility - deprecationStatus: Deprecation(level=WARNING, inheritable=false, message=Deprecated in Java) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=Deprecated in Java) diff --git a/idea/idea-frontend-fir/testData/symbols/symbolByPsi/deprecated.txt b/idea/idea-frontend-fir/testData/symbols/symbolByPsi/deprecated.txt index 4acde93189b..50f4915f393 100644 --- a/idea/idea-frontend-fir/testData/symbols/symbolByPsi/deprecated.txt +++ b/idea/idea-frontend-fir/testData/symbols/symbolByPsi/deprecated.txt @@ -28,9 +28,9 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: TOP_LEVEL visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i) - getterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i) - setterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i) KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int @@ -63,7 +63,7 @@ KtFirKotlinPropertySymbol: symbolKind: TOP_LEVEL visibility: Public deprecationStatus: null - getterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use getter of i2) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use getter of i2) setterDeprecationStatus: null KtFirKotlinPropertySymbol: @@ -98,7 +98,7 @@ KtFirKotlinPropertySymbol: visibility: Public deprecationStatus: null getterDeprecationStatus: null - setterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use getter of i3) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use getter of i3) KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int @@ -134,8 +134,8 @@ KtFirKotlinPropertySymbol: symbolKind: TOP_LEVEL visibility: Public deprecationStatus: null - getterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use getter of i4) - setterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use getter of i4) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use getter of i4) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use getter of i4) KtFirFunctionSymbol: annotatedType: [] kotlin/Int @@ -165,7 +165,7 @@ KtFirFunctionSymbol: typeParameters: [] valueParameters: [] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use f) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use f) KtFirNamedClassOrObjectSymbol: annotationClassIds: [ @@ -192,7 +192,7 @@ KtFirNamedClassOrObjectSymbol: symbolKind: TOP_LEVEL typeParameters: [] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use MyClass) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use MyClass) KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int @@ -224,9 +224,9 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: MEMBER visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i2) - getterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i2) - setterDeprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use i2) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i2) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i2) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use i2) KtFirFunctionSymbol: annotatedType: [] kotlin/Int @@ -256,7 +256,7 @@ KtFirFunctionSymbol: typeParameters: [] valueParameters: [] visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=true, message=don't use f2) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=true, message=don't use f2) KtFirNamedClassOrObjectSymbol: annotationClassIds: [] @@ -310,9 +310,9 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: TOP_LEVEL visibility: Public - deprecationStatus: Deprecation(level=ERROR, inheritable=true, message=null) - getterDeprecationStatus: Deprecation(level=ERROR, inheritable=true, message=null) - setterDeprecationStatus: Deprecation(level=ERROR, inheritable=true, message=null) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=ERROR, propagatesToOverrides=true, message=null) KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int @@ -344,9 +344,9 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: TOP_LEVEL visibility: Public - deprecationStatus: Deprecation(level=HIDDEN, inheritable=true, message=null) - getterDeprecationStatus: Deprecation(level=HIDDEN, inheritable=true, message=null) - setterDeprecationStatus: Deprecation(level=HIDDEN, inheritable=true, message=null) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=HIDDEN, propagatesToOverrides=true, message=null) KtFirKotlinPropertySymbol: annotatedType: [] kotlin/Int @@ -378,6 +378,6 @@ KtFirKotlinPropertySymbol: setter: null symbolKind: TOP_LEVEL visibility: Public - deprecationStatus: Deprecation(level=WARNING, inheritable=false, message=null) - getterDeprecationStatus: Deprecation(level=WARNING, inheritable=false, message=null) - setterDeprecationStatus: Deprecation(level=WARNING, inheritable=false, message=null) + deprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=null) + getterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=null) + setterDeprecationStatus: SimpleDeprecationInfo(deprecationLevel=WARNING, propagatesToOverrides=false, message=null)