From 839c30d04b7a150935beb4f8423124cecf0b2d82 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Sat, 24 Oct 2020 00:21:27 +0900 Subject: [PATCH] Revert "Additional minor fixes for KT-33594: avoid using hard-coded annotation name, simplify hasAnnotationToSuppressDeprecation()" This reverts commit 2a841550 --- .../replaceWith/DeprecatedSymbolUsageFix.kt | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt index ef4ca4eb977..2c9eb967ff2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFix.kt @@ -20,11 +20,8 @@ import com.intellij.codeInsight.intention.HighPriorityAction import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.builtins.StandardNames -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy @@ -32,7 +29,10 @@ import org.jetbrains.kotlin.idea.core.moveCaret import org.jetbrains.kotlin.idea.core.targetDescriptors import org.jetbrains.kotlin.idea.quickfix.CleanupFix import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtReferenceExpression +import org.jetbrains.kotlin.psi.KtStringTemplateExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe @@ -66,34 +66,16 @@ class DeprecatedSymbolUsageFix( } private fun KtFile.hasAnnotationToSuppressDeprecation(): Boolean { - val suppressAnnotation = annotationEntries.firstOrNull { it.isSuppress() } ?: return false - - for (valueArgument in suppressAnnotation.valueArguments) { - val template = valueArgument.getArgumentExpression() as? KtStringTemplateExpression ?: continue - val text = template.entries.singleOrNull()?.text ?: continue - - if (text == Errors.DEPRECATION.name || text == Errors.DEPRECATION_ERROR.name) { - return true - } - } - - return suppressAnnotation.valueArguments.any { + val suppressAnnotationEntry = annotationEntries.firstOrNull { + it.shortName?.asString() == "Suppress" + && it.resolveToCall()?.resultingDescriptor?.containingDeclaration?.fqNameSafe == KotlinBuiltIns.FQ_NAMES.suppress + } ?: return false + return suppressAnnotationEntry.valueArguments.any { val text = (it.getArgumentExpression() as? KtStringTemplateExpression)?.entries?.singleOrNull()?.text ?: return@any false text.equals("DEPRECATION", ignoreCase = true) } } - private fun KtAnnotationEntry.isSuppress(): Boolean { - val suppressName = StandardNames.FqNames.suppress - - if (shortName != suppressName.shortName()) { - return false - } - - val annotationDescriptor = resolveToCall()?.resultingDescriptor?.containingDeclaration as? ClassDescriptor ?: return false - return annotationDescriptor.kind == ClassKind.ANNOTATION_CLASS && annotationDescriptor.fqNameSafe == suppressName - } - private fun isImportToBeRemoved(import: KtImportDirective): Boolean { if (import.isAllUnder) return false