DeprecatedCallableAddReplaceWithInspection: add argument name if needed

#KT-34297 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-10-11 17:33:27 +09:00
committed by Mikhail Glukhikh
parent 23749bdde7
commit f8f50b2131
5 changed files with 23 additions and 0 deletions
@@ -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("\"")
@@ -0,0 +1,4 @@
class Foo {
<caret>@Deprecated(message = "")
fun foo(someString: String) = someString
}
@@ -0,0 +1,4 @@
class Foo {
@Deprecated(message = "", replaceWith = ReplaceWith("someString"))
fun foo(someString: String) = someString
}
@@ -125,4 +125,13 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@Deprecated annotation without 'replaceWith' argument</problem_class>
<description>@Deprecated annotation without 'replaceWith' argument</description>
</problem>
<problem>
<file>ReplaceWithHasNamedArgument.kt</file>
<line>2</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="ReplaceWithHasNamedArgument.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">@Deprecated annotation without 'replaceWith' argument</problem_class>
<description>@Deprecated annotation without 'replaceWith' argument</description>
</problem>
</problems>
@@ -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");