Revert "Additional minor fixes for KT-33594: avoid using hard-coded annotation name, simplify hasAnnotationToSuppressDeprecation()"

This reverts commit 2a841550
This commit is contained in:
Yan Zhulanow
2020-10-24 00:21:27 +09:00
parent 9320637efe
commit 839c30d04b
@@ -20,11 +20,8 @@ import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy 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.core.targetDescriptors
import org.jetbrains.kotlin.idea.quickfix.CleanupFix import org.jetbrains.kotlin.idea.quickfix.CleanupFix
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory 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.calls.callUtil.getCalleeExpressionIfAny
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -66,34 +66,16 @@ class DeprecatedSymbolUsageFix(
} }
private fun KtFile.hasAnnotationToSuppressDeprecation(): Boolean { private fun KtFile.hasAnnotationToSuppressDeprecation(): Boolean {
val suppressAnnotation = annotationEntries.firstOrNull { it.isSuppress() } ?: return false val suppressAnnotationEntry = annotationEntries.firstOrNull {
it.shortName?.asString() == "Suppress"
for (valueArgument in suppressAnnotation.valueArguments) { && it.resolveToCall()?.resultingDescriptor?.containingDeclaration?.fqNameSafe == KotlinBuiltIns.FQ_NAMES.suppress
val template = valueArgument.getArgumentExpression() as? KtStringTemplateExpression ?: continue } ?: return false
val text = template.entries.singleOrNull()?.text ?: continue return suppressAnnotationEntry.valueArguments.any {
if (text == Errors.DEPRECATION.name || text == Errors.DEPRECATION_ERROR.name) {
return true
}
}
return suppressAnnotation.valueArguments.any {
val text = (it.getArgumentExpression() as? KtStringTemplateExpression)?.entries?.singleOrNull()?.text ?: return@any false val text = (it.getArgumentExpression() as? KtStringTemplateExpression)?.entries?.singleOrNull()?.text ?: return@any false
text.equals("DEPRECATION", ignoreCase = true) 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 { private fun isImportToBeRemoved(import: KtImportDirective): Boolean {
if (import.isAllUnder) return false if (import.isAllUnder) return false