Refactor getDeprecation() -> getDeprecations()
In subsequent commits, another kind of deprecation is introduced which should be reported alongside with deprecation by the `@Deprecated` annotation
This commit is contained in:
+9
-5
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.getDeprecation
|
||||
import org.jetbrains.kotlin.resolve.getDeprecations
|
||||
|
||||
object DeprecatedCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
@@ -42,13 +42,17 @@ object DeprecatedCallChecker : CallChecker {
|
||||
// Objects will be checked by DeprecatedClassifierUsageChecker
|
||||
if (targetDescriptor is FakeCallableDescriptorForObject) return
|
||||
|
||||
val deprecation = targetDescriptor.getDeprecation()
|
||||
val deprecations = targetDescriptor.getDeprecations().toMutableList()
|
||||
|
||||
// avoid duplicating diagnostic when deprecation for property effectively deprecates setter
|
||||
if (targetDescriptor is PropertySetterDescriptor && targetDescriptor.correspondingProperty.getDeprecation() == deprecation) return
|
||||
if (targetDescriptor is PropertySetterDescriptor) {
|
||||
deprecations -= targetDescriptor.correspondingProperty.getDeprecations()
|
||||
}
|
||||
|
||||
if (deprecation != null) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation))
|
||||
if (deprecations.isNotEmpty()) {
|
||||
for (deprecation in deprecations) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation))
|
||||
}
|
||||
}
|
||||
else if (targetDescriptor is PropertyDescriptor && shouldCheckPropertyGetter(element)) {
|
||||
targetDescriptor.getter?.let { check(it, trace, element) }
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.getDeprecation
|
||||
import org.jetbrains.kotlin.resolve.getDeprecations
|
||||
|
||||
class DeprecatedClassifierUsageChecker : ClassifierUsageChecker {
|
||||
override fun check(
|
||||
@@ -30,8 +30,8 @@ class DeprecatedClassifierUsageChecker : ClassifierUsageChecker {
|
||||
element: PsiElement,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
val deprecation = targetDescriptor.getDeprecation()
|
||||
if (deprecation != null) {
|
||||
val deprecations = targetDescriptor.getDeprecations()
|
||||
for (deprecation in deprecations) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,17 +89,17 @@ private data class DeprecatedByOverridden(private val deprecations: Collection<D
|
||||
internal fun additionalMessage() = "Overrides deprecated member in '${DescriptorUtils.getContainingClass(target)!!.fqNameSafe.asString()}'"
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.getDeprecation(): Deprecation? {
|
||||
fun DeclarationDescriptor.getDeprecations(): List<Deprecation> {
|
||||
val deprecation = this.getDeprecationByAnnotation()
|
||||
if (deprecation != null) {
|
||||
return deprecation
|
||||
return listOf(deprecation)
|
||||
}
|
||||
|
||||
if (this is CallableMemberDescriptor) {
|
||||
return deprecationByOverridden(this)
|
||||
return listOfNotNull(deprecationByOverridden(this))
|
||||
}
|
||||
|
||||
return null
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun deprecationByOverridden(root: CallableMemberDescriptor): Deprecation? {
|
||||
@@ -200,9 +200,8 @@ enum class DeprecationLevelValue {
|
||||
WARNING, ERROR, HIDDEN
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.isDeprecatedHidden(): Boolean {
|
||||
return getDeprecation()?.deprecationLevel == HIDDEN
|
||||
}
|
||||
fun DeclarationDescriptor.isDeprecatedHidden(): Boolean =
|
||||
getDeprecations().any { it.deprecationLevel == HIDDEN }
|
||||
|
||||
@JvmOverloads
|
||||
fun DeclarationDescriptor.isHiddenInResolution(languageVersionSettings: LanguageVersionSettings, isSuperCall: Boolean = false): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user