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 {
|
||||
|
||||
@@ -18,15 +18,12 @@ package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.google.common.html.HtmlEscapers
|
||||
import com.intellij.codeInsight.documentation.DocumentationManagerUtil
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||
import com.intellij.lang.java.JavaDocumentationProvider
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
@@ -51,7 +48,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.deprecatedByAnnotationReplaceWithExpression
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.getDeprecation
|
||||
import org.jetbrains.kotlin.resolve.getDeprecations
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
|
||||
@@ -196,7 +193,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
}
|
||||
|
||||
private fun renderDeprecationInfo(declarationDescriptor: DeclarationDescriptor): String {
|
||||
val deprecation = declarationDescriptor.getDeprecation() ?: return ""
|
||||
val deprecation = declarationDescriptor.getDeprecations().firstOrNull() ?: return ""
|
||||
|
||||
return buildString {
|
||||
wrapTag("DL") {
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.deprecatedByOverriddenMessage
|
||||
import org.jetbrains.kotlin.resolve.getDeprecation
|
||||
import org.jetbrains.kotlin.resolve.getDeprecations
|
||||
|
||||
class OverridingDeprecatedMemberInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||
@@ -41,7 +41,7 @@ class OverridingDeprecatedMemberInspection : AbstractKotlinInspection() {
|
||||
if (declaration is KtDestructuringDeclarationEntry) return
|
||||
val accessorDescriptor = declaration.resolveToDescriptor() as? CallableMemberDescriptor ?: return
|
||||
|
||||
val message = accessorDescriptor.getDeprecation()?.deprecatedByOverriddenMessage() ?: return
|
||||
val message = accessorDescriptor.getDeprecations().firstOrNull()?.deprecatedByOverriddenMessage() ?: return
|
||||
val problem = holder.manager.createProblemDescriptor(
|
||||
targetForProblem,
|
||||
message,
|
||||
@@ -53,4 +53,4 @@ class OverridingDeprecatedMemberInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user