KT-9450 «Replace overloaded operator with function call» breaks code for index access result saved to variable

#KT-9450 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-10-20 18:15:16 +03:00
parent 6baef687ef
commit c6978d6b69
4 changed files with 15 additions and 1 deletions
@@ -168,7 +168,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<KtExpressio
val transformation : String
val replaced : KtElement
if (parent is KtBinaryExpression && parent.getOperationReference().getReferencedNameElementType() == KtTokens.EQ) {
if (parent is KtBinaryExpression && parent.getOperationReference().getReferencedNameElementType() == KtTokens.EQ && element == parent.left) {
// part of an assignment
val right = parent.getRight()!!.getText()
transformation = "$array.set($indicesText, $right)"
@@ -0,0 +1,4 @@
fun foo(map: Map<String, String>) {
val a: String?
a = map<caret>[""]
}
@@ -0,0 +1,4 @@
fun foo(map: Map<String, String>) {
val a: String?
a = map.get("")
}
@@ -5919,6 +5919,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("inRightSideOfAssignment.kt")
public void testInRightSideOfAssignment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/inRightSideOfAssignment.kt");
doTest(fileName);
}
@TestMetadata("notApplicableAssignment.kt")
public void testNotApplicableAssignment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/notApplicableAssignment.kt");