KT-9981 Code cleanup replace usages of !in incorrectly
#KT-9981 Fixed
This commit is contained in:
+9
-2
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||||
import org.jetbrains.kotlin.idea.core.*
|
import org.jetbrains.kotlin.idea.core.*
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention
|
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.setType
|
import org.jetbrains.kotlin.idea.intentions.setType
|
||||||
import org.jetbrains.kotlin.idea.util.*
|
import org.jetbrains.kotlin.idea.util.*
|
||||||
@@ -65,8 +66,14 @@ class CallableUsageReplacementStrategy(
|
|||||||
if (!callTypeHandler.precheckReplacementPattern(replacement)) return null
|
if (!callTypeHandler.precheckReplacementPattern(replacement)) return null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// copy replacement expression because it is modified by performCallReplacement
|
if (usage is KtOperationReferenceExpression && usage.getReferencedNameElementType() != KtTokens.IDENTIFIER) {
|
||||||
performCallReplacement(usage, bindingContext, resolvedCall, callElement, callTypeHandler, replacement.copy())
|
val nameExpression = OperatorToFunctionIntention.convert(usage.parent as KtExpression).second
|
||||||
|
createReplacer(nameExpression)!!.invoke()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// copy replacement expression because it is modified by performCallReplacement
|
||||||
|
performCallReplacement(usage, bindingContext, resolvedCall, callElement, callTypeHandler, replacement.copy())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// "Replace usages of 'contains(String) on C: Boolean' in whole project" "true"
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("checkContains(s)"))
|
||||||
|
operator fun C.contains(s: String) = true
|
||||||
|
|
||||||
|
fun C.checkContains(s: String) = true
|
||||||
|
|
||||||
|
fun f(c: C) {
|
||||||
|
if ("" <caret>!in c) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun g(c: C) {
|
||||||
|
if ("" in c) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// "Replace usages of 'contains(String) on C: Boolean' in whole project" "true"
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("checkContains(s)"))
|
||||||
|
operator fun C.contains(s: String) = true
|
||||||
|
|
||||||
|
fun C.checkContains(s: String) = true
|
||||||
|
|
||||||
|
fun f(c: C) {
|
||||||
|
if (!c.checkContains("")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun g(c: C) {
|
||||||
|
if (c.checkContains("")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// "Replace with 'add(c)'" "true"
|
||||||
|
class C
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("add(c)"))
|
||||||
|
operator fun C.plus(c: C) = C()
|
||||||
|
|
||||||
|
fun C.add(c: C) = C()
|
||||||
|
|
||||||
|
fun f() {
|
||||||
|
var c1 = C()
|
||||||
|
c1 <caret>+= C()
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// "Replace with 'add(c)'" "true"
|
||||||
|
class C
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("add(c)"))
|
||||||
|
operator fun C.plus(c: C) = C()
|
||||||
|
|
||||||
|
fun C.add(c: C) = C()
|
||||||
|
|
||||||
|
fun f() {
|
||||||
|
var c1 = C()
|
||||||
|
c1 = c1.add(C())
|
||||||
|
}
|
||||||
@@ -3730,6 +3730,27 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class OperatorCalls extends AbstractQuickFixTest {
|
||||||
|
public void testAllFilesPresentInOperatorCalls() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("in.kt")
|
||||||
|
public void testIn() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/in.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("plusAssign.kt")
|
||||||
|
public void testPlusAssign() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/plusAssign.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/optionalParameters")
|
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/optionalParameters")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user