From f8f50b2131edcbae8c5f859f2415dcb0b329c163 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Fri, 11 Oct 2019 17:33:27 +0900 Subject: [PATCH] DeprecatedCallableAddReplaceWithInspection: add argument name if needed #KT-34297 Fixed --- .../DeprecatedCallableAddReplaceWithInspection.kt | 1 + .../ReplaceWithHasNamedArgument.kt | 4 ++++ .../ReplaceWithHasNamedArgument.kt.after | 4 ++++ .../inspectionData/expected.xml | 9 +++++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 5 files changed, 23 insertions(+) create mode 100644 idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt create mode 100644 idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/DeprecatedCallableAddReplaceWithInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/DeprecatedCallableAddReplaceWithInspection.kt index eeaa5ba529b..0fbc5f6f3cb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/DeprecatedCallableAddReplaceWithInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/DeprecatedCallableAddReplaceWithInspection.kt @@ -81,6 +81,7 @@ class DeprecatedCallableAddReplaceWithInspection : AbstractApplicabilityBasedIns } val argumentText = StringBuilder().apply { + if (annotationEntry.valueArguments.any { it.isNamed() }) append("replaceWith = ") append("kotlin.ReplaceWith(\"") append(escapedText) append("\"") diff --git a/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt new file mode 100644 index 00000000000..fbbb97f4630 --- /dev/null +++ b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt @@ -0,0 +1,4 @@ +class Foo { + @Deprecated(message = "") + fun foo(someString: String) = someString +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt.after b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt.after new file mode 100644 index 00000000000..068363510a3 --- /dev/null +++ b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt.after @@ -0,0 +1,4 @@ +class Foo { + @Deprecated(message = "", replaceWith = ReplaceWith("someString")) + fun foo(someString: String) = someString +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/inspectionData/expected.xml b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/inspectionData/expected.xml index caa8b824b00..6552d8216ab 100644 --- a/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/inspectionData/expected.xml +++ b/idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/inspectionData/expected.xml @@ -125,4 +125,13 @@ @Deprecated annotation without 'replaceWith' argument @Deprecated annotation without 'replaceWith' argument + + + ReplaceWithHasNamedArgument.kt + 2 + light_idea_test_case + + @Deprecated annotation without 'replaceWith' argument + @Deprecated annotation without 'replaceWith' argument + \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index a5a2abfff15..da20465094f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -4108,6 +4108,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/QualifiedCall.kt"); } + @TestMetadata("ReplaceWithHasNamedArgument.kt") + public void testReplaceWithHasNamedArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/ReplaceWithHasNamedArgument.kt"); + } + @TestMetadata("Return.kt") public void testReturn() throws Exception { runTest("idea/testData/inspectionsLocal/deprecatedCallableAddReplaceWith/Return.kt");