From 8089d2e9e36dff45934d20e56e65ac52b70366f6 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Fri, 16 Nov 2018 14:20:47 +0900 Subject: [PATCH] Replace deprecated symbol usage in whole project: enable on annotation declared without parentheses #KT-12479 Fixed --- .../DeprecatedSymbolUsageInWholeProjectFix.kt | 1 + .../noParenthesesAnnotation.after.Declaration.kt | 9 +++++++++ .../noParenthesesAnnotation.after.Other.kt | 9 +++++++++ .../wholeProject/noParenthesesAnnotation.after.kt | 11 +++++++++++ .../noParenthesesAnnotation.before.Declaration.kt | 9 +++++++++ .../noParenthesesAnnotation.before.Main.kt | 11 +++++++++++ .../noParenthesesAnnotation.before.Other.kt | 9 +++++++++ .../idea/quickfix/QuickFixMultiFileTestGenerated.java | 5 +++++ 8 files changed, 64 insertions(+) create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Declaration.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Other.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Declaration.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Main.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Other.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt index 7423ac734c8..a1c0916d703 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt @@ -58,6 +58,7 @@ class DeprecatedSymbolUsageInWholeProjectFix( is KtProperty -> referenceTarget is KtTypeAlias -> referenceTarget is KtConstructor<*> -> referenceTarget.getContainingClassOrObject() //TODO: constructor can be deprecated itself + is KtClass -> referenceTarget.takeIf { it.isAnnotation() } else -> null } } diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Declaration.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Declaration.kt new file mode 100644 index 00000000000..191bf1c68a4 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Declaration.kt @@ -0,0 +1,9 @@ +package dependency + +@Deprecated("", ReplaceWith("dependency.NewAnnotation")) +annotation class OldAnnotation + +annotation class NewAnnotation() + +@NewAnnotation +class C \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Other.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Other.kt new file mode 100644 index 00000000000..158c43ab01a --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.Other.kt @@ -0,0 +1,9 @@ +// "Replace with 'test.Bar'" "true" + +package x + +import dependency.* + +annotation class A(val a: NewAnnotation) + +@A(NewAnnotation()) class Y diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.kt new file mode 100644 index 00000000000..c3e3c719f34 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.after.kt @@ -0,0 +1,11 @@ +// "Replace usages of 'OldAnnotation' in whole project" "true" + +package test + +import dependency.NewAnnotation + +fun foo(a: NewAnnotation) { +} + +@NewAnnotation +class X \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Declaration.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Declaration.kt new file mode 100644 index 00000000000..8c9631a3a15 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Declaration.kt @@ -0,0 +1,9 @@ +package dependency + +@Deprecated("", ReplaceWith("dependency.NewAnnotation")) +annotation class OldAnnotation + +annotation class NewAnnotation() + +@OldAnnotation +class C \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Main.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Main.kt new file mode 100644 index 00000000000..e015001f476 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Main.kt @@ -0,0 +1,11 @@ +// "Replace usages of 'OldAnnotation' in whole project" "true" + +package test + +import dependency.OldAnnotation + +fun foo(a: OldAnnotation) { +} + +@OldAnnotation +class X \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Other.kt b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Other.kt new file mode 100644 index 00000000000..f17a4ce2084 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Other.kt @@ -0,0 +1,9 @@ +// "Replace with 'test.Bar'" "true" + +package x + +import dependency.* + +annotation class A(val a: OldAnnotation) + +@A(OldAnnotation()) class Y diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 954d12782a1..7ff2c247133 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -2395,6 +2395,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes public void testAnnotation() throws Exception { runTest("idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/annotation.before.Main.kt"); } + + @TestMetadata("noParenthesesAnnotation.before.Main.kt") + public void testNoParenthesesAnnotation() throws Exception { + runTest("idea/testData/quickfix/deprecatedSymbolUsage/classUsages/wholeProject/noParenthesesAnnotation.before.Main.kt"); + } } }