Check language version for deprecation via SinceKotlinInfo
This commit is contained in:
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmStringTable;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
||||
@@ -236,9 +237,13 @@ public class AsmUtil {
|
||||
int flags = getVisibilityAccessFlag(functionDescriptor);
|
||||
flags |= getVarargsFlag(functionDescriptor);
|
||||
flags |= getDeprecatedAccessFlag(functionDescriptor);
|
||||
if (DeprecationUtilKt.isDeprecatedHidden(functionDescriptor)
|
||||
if (DeprecationUtilKt.isDeprecatedHidden(functionDescriptor, LanguageVersionSettingsImpl.DEFAULT)
|
||||
|| functionDescriptor instanceof PropertyAccessorDescriptor
|
||||
&& DeprecationUtilKt.isDeprecatedHidden(((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty())) {
|
||||
&& DeprecationUtilKt.isDeprecatedHidden(
|
||||
((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty(),
|
||||
LanguageVersionSettingsImpl.DEFAULT
|
||||
)
|
||||
) {
|
||||
flags |= ACC_SYNTHETIC;
|
||||
}
|
||||
return flags;
|
||||
|
||||
+2
-2
@@ -45,11 +45,11 @@ object DeprecatedCallChecker : CallChecker {
|
||||
// Objects will be checked by DeprecatedClassifierUsageChecker
|
||||
if (targetDescriptor is FakeCallableDescriptorForObject) return
|
||||
|
||||
val deprecations = targetDescriptor.getDeprecations().toMutableList()
|
||||
val deprecations = targetDescriptor.getDeprecations(languageVersionSettings).toMutableList()
|
||||
|
||||
// avoid duplicating diagnostic when deprecation for property effectively deprecates setter
|
||||
if (targetDescriptor is PropertySetterDescriptor) {
|
||||
deprecations -= targetDescriptor.correspondingProperty.getDeprecations()
|
||||
deprecations -= targetDescriptor.correspondingProperty.getDeprecations(languageVersionSettings)
|
||||
}
|
||||
|
||||
if (deprecations.isNotEmpty()) {
|
||||
|
||||
+1
-2
@@ -30,8 +30,7 @@ class DeprecatedClassifierUsageChecker : ClassifierUsageChecker {
|
||||
element: PsiElement,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
val deprecations = targetDescriptor.getDeprecations()
|
||||
for (deprecation in deprecations) {
|
||||
for (deprecation in targetDescriptor.getDeprecations(languageVersionSettings)) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation, languageVersionSettings))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
@@ -125,20 +126,20 @@ private data class DeprecatedBySinceKotlinInfo(
|
||||
get() = sinceKotlinInfo.version.asString()
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.getDeprecations(): List<Deprecation> {
|
||||
val deprecations = this.getOwnDeprecations()
|
||||
fun DeclarationDescriptor.getDeprecations(languageVersionSettings: LanguageVersionSettings): List<Deprecation> {
|
||||
val deprecations = this.getOwnDeprecations(languageVersionSettings)
|
||||
if (deprecations.isNotEmpty()) {
|
||||
return deprecations
|
||||
}
|
||||
|
||||
if (this is CallableMemberDescriptor) {
|
||||
return listOfNotNull(deprecationByOverridden(this))
|
||||
return listOfNotNull(deprecationByOverridden(this, languageVersionSettings))
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun deprecationByOverridden(root: CallableMemberDescriptor): Deprecation? {
|
||||
private fun deprecationByOverridden(root: CallableMemberDescriptor, languageVersionSettings: LanguageVersionSettings): Deprecation? {
|
||||
val visited = HashSet<CallableMemberDescriptor>()
|
||||
val deprecations = LinkedHashSet<Deprecation>()
|
||||
var hasUndeprecatedOverridden = false
|
||||
@@ -148,7 +149,7 @@ private fun deprecationByOverridden(root: CallableMemberDescriptor): Deprecation
|
||||
|
||||
visited.add(node)
|
||||
|
||||
val deprecationsByAnnotation = node.getOwnDeprecations()
|
||||
val deprecationsByAnnotation = node.getOwnDeprecations(languageVersionSettings)
|
||||
val overriddenDescriptors = node.original.overriddenDescriptors
|
||||
when {
|
||||
deprecationsByAnnotation.isNotEmpty() -> {
|
||||
@@ -171,11 +172,12 @@ private fun deprecationByOverridden(root: CallableMemberDescriptor): Deprecation
|
||||
return DeprecatedByOverridden(deprecations)
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.getOwnDeprecations(): List<Deprecation> {
|
||||
private fun DeclarationDescriptor.getOwnDeprecations(languageVersionSettings: LanguageVersionSettings): List<Deprecation> {
|
||||
if (this is TypeAliasConstructorDescriptor) {
|
||||
// Constructor of type alias has no annotations by itself, all its annotations come from the aliased constructor
|
||||
// and from the typealias declaration
|
||||
return underlyingConstructorDescriptor.getOwnDeprecations() + typeAliasDescriptor.getOwnDeprecations()
|
||||
return underlyingConstructorDescriptor.getOwnDeprecations(languageVersionSettings) +
|
||||
typeAliasDescriptor.getOwnDeprecations(languageVersionSettings)
|
||||
}
|
||||
|
||||
val result = SmartList<Deprecation>()
|
||||
@@ -190,7 +192,12 @@ private fun DeclarationDescriptor.getOwnDeprecations(): List<Deprecation> {
|
||||
if (target is DeserializedMemberDescriptor) {
|
||||
val sinceKotlinInfo = target.sinceKotlinInfo
|
||||
if (sinceKotlinInfo != null) {
|
||||
result.add(DeprecatedBySinceKotlinInfo(sinceKotlinInfo, target))
|
||||
// We're using ApiVersion because it's convenient to compare versions, "-api-version" is not involved in any way
|
||||
// TODO: usage of ApiVersion is confusing here, refactor
|
||||
if (ApiVersion.createBySinceKotlinInfo(sinceKotlinInfo) >
|
||||
ApiVersion.createByLanguageVersion(languageVersionSettings.languageVersion)) {
|
||||
result.add(DeprecatedBySinceKotlinInfo(sinceKotlinInfo, target))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,8 +257,8 @@ enum class DeprecationLevelValue {
|
||||
WARNING, ERROR, HIDDEN
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.isDeprecatedHidden(): Boolean =
|
||||
getDeprecations().any { it.deprecationLevel == HIDDEN }
|
||||
fun DeclarationDescriptor.isDeprecatedHidden(languageVersionSettings: LanguageVersionSettings): Boolean =
|
||||
getDeprecations(languageVersionSettings).any { it.deprecationLevel == HIDDEN }
|
||||
|
||||
@JvmOverloads
|
||||
fun DeclarationDescriptor.isHiddenInResolution(languageVersionSettings: LanguageVersionSettings, isSuperCall: Boolean = false): Boolean {
|
||||
@@ -262,5 +269,5 @@ fun DeclarationDescriptor.isHiddenInResolution(languageVersionSettings: Language
|
||||
|
||||
if (!checkSinceKotlinVersionAccessibility(languageVersionSettings)) return true
|
||||
|
||||
return isDeprecatedHidden()
|
||||
return isDeprecatedHidden(languageVersionSettings)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user