#KT-10883 Fixed
This commit is contained in:
committed by
Dmitry Jemerov
parent
348125acb3
commit
e8b665f600
+20
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
@@ -27,9 +28,12 @@ import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.isReceiverExpressionWithValue
|
||||
import org.jetbrains.kotlin.idea.intentions.toResolvedCall
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.buildExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||
@@ -107,6 +111,21 @@ class ReplaceGetOrSetIntention : SelfTargetingRangeIntention<KtDotQualifiedExpre
|
||||
}
|
||||
}
|
||||
|
||||
element.replace(expression)
|
||||
val newElement = element.replace(expression)
|
||||
|
||||
if (editor != null) {
|
||||
moveCaret(editor, isSet, newElement)
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveCaret(editor: Editor, isSet: Boolean, newElement: PsiElement) {
|
||||
val arrayAccessExpression = if (isSet) {
|
||||
newElement.getChildOfType<KtArrayAccessExpression>()!!
|
||||
}
|
||||
else {
|
||||
newElement as KtArrayAccessExpression
|
||||
}
|
||||
|
||||
editor.caretModel.moveToOffset(arrayAccessExpression.leftBracket!!.startOffset)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ fun test() {
|
||||
operator fun get(a: Int, vararg b: Int, c: Int = 0) : Int = 0
|
||||
}
|
||||
val test = Test()
|
||||
test[1, 3, 4, 5]
|
||||
test<caret>[1, 3, 4, 5]
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ fun test() {
|
||||
operator fun get(a: Int, b: Int, fn: (i: Int) -> Int) : Int = 0
|
||||
}
|
||||
val test = Test()
|
||||
test[1, 2, { i ->
|
||||
test<caret>[1, 2, { i ->
|
||||
i
|
||||
}]
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ fun test() {
|
||||
operator fun Test.get(i: Int) : Int = 0
|
||||
|
||||
val test = Test()
|
||||
test[0]
|
||||
test<caret>[0]
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ fun test() {
|
||||
operator fun get(fn: (i: Int) -> Int) : Int = 0
|
||||
}
|
||||
val test = Test()
|
||||
test[{ i ->
|
||||
test<caret>[{ i ->
|
||||
i
|
||||
}]
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ fun test() {
|
||||
operator fun get(a: Int, b: Int) : Int = 0
|
||||
}
|
||||
val test = Test()
|
||||
test[1, 2]
|
||||
test<caret>[1, 2]
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ class C {
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
C["x"]
|
||||
C<caret>["x"]
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ class C {
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
C()["x"] = 1
|
||||
C()<caret>["x"] = 1
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ class C {
|
||||
|
||||
class D(val c: C) {
|
||||
fun foo() {
|
||||
this.c["x", 2] = 1
|
||||
this.c<caret>["x", 2] = 1
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ fun test() {
|
||||
operator fun get(i: Int) : Int = 0
|
||||
}
|
||||
val test = Test()
|
||||
test[0]
|
||||
test<caret>[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user