From 24865ba26a245b681750a1e9ad8da41a13460cf7 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 27 Jul 2017 20:31:07 +0300 Subject: [PATCH] Allow deprecated fix for TYPEALIAS_EXPANSION_DEPRECATION --- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 2 ++ .../replaceWith/DeprecatedSymbolUsageFixBase.kt | 11 ++++++++++- .../typeAliases/constructorUsageWithConflict1.kt | 2 +- .../constructorUsageWithConflict1.kt.after | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 4f03b8cd378..c7e0a75870e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -394,6 +394,8 @@ class QuickFixRegistrar : QuickFixContributor { DEPRECATION.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix, MigrateExternalExtensionFix) DEPRECATION_ERROR.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix, MigrateExternalExtensionFix) + TYPEALIAS_EXPANSION_DEPRECATION.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix, MigrateExternalExtensionFix) + TYPEALIAS_EXPANSION_DEPRECATION_ERROR.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix, MigrateExternalExtensionFix) PROTECTED_CALL_FROM_PUBLIC_INLINE.registerFactory(ReplaceProtectedToPublishedApiCallFix) POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION.registerFactory(ReplaceJavaAnnotationPositionedArgumentsFix) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt index 8ff07b6186c..baa42113ad9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt @@ -116,7 +116,16 @@ abstract class DeprecatedSymbolUsageFixBase( else -> null } ?: return null - val descriptor = DiagnosticFactory.cast(deprecatedDiagnostic, Errors.DEPRECATION, Errors.DEPRECATION_ERROR).a + val descriptor = when (deprecatedDiagnostic.factory) { + Errors.DEPRECATION -> DiagnosticFactory.cast(deprecatedDiagnostic, Errors.DEPRECATION).a + Errors.DEPRECATION_ERROR -> DiagnosticFactory.cast(deprecatedDiagnostic, Errors.DEPRECATION_ERROR).a + Errors.TYPEALIAS_EXPANSION_DEPRECATION -> + DiagnosticFactory.cast(deprecatedDiagnostic, Errors.TYPEALIAS_EXPANSION_DEPRECATION).b + Errors.TYPEALIAS_EXPANSION_DEPRECATION_ERROR -> + DiagnosticFactory.cast(deprecatedDiagnostic, Errors.TYPEALIAS_EXPANSION_DEPRECATION_ERROR).b + else -> throw IllegalStateException("Bad QuickFixRegistrar configuration") + } + val replacement = DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(descriptor, nameExpression.project) ?: return null return Data(nameExpression, replacement, descriptor) } diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt b/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt index d697cac310c..72ecc220ef7 100644 --- a/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt +++ b/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt @@ -1,7 +1,7 @@ // "Replace with 'NewClass(12)'" "true" @Deprecated("Use NewClass", replaceWith = ReplaceWith("NewClass")) -class OldClass @Deprecated("Use NewClass(12)", replaceWith = ReplaceWith("NewClass(12)")) constructor() +class OldClass @Deprecated("Use NewClass(12)", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("NewClass(12)")) constructor() @Deprecated("Use New", replaceWith = ReplaceWith("New")) typealias Old = OldClass diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt.after index 900478199b5..df7280490af 100644 --- a/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt.after +++ b/idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt.after @@ -1,7 +1,7 @@ // "Replace with 'NewClass(12)'" "true" @Deprecated("Use NewClass", replaceWith = ReplaceWith("NewClass")) -class OldClass @Deprecated("Use NewClass(12)", replaceWith = ReplaceWith("NewClass(12)")) constructor() +class OldClass @Deprecated("Use NewClass(12)", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("NewClass(12)")) constructor() @Deprecated("Use New", replaceWith = ReplaceWith("New")) typealias Old = OldClass