Bug Fix for KT-4652 Replace with Infix Call
This commit is contained in:
@@ -34,6 +34,20 @@ import org.jetbrains.jet.lang.psi.JetFile
|
|||||||
|
|
||||||
public class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
|
public class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetCallExpression): Boolean {
|
override fun isApplicableTo(element: JetCallExpression): Boolean {
|
||||||
|
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isApplicableTo(element: JetCallExpression, editor: Editor): Boolean {
|
||||||
|
val caretLocation = editor.getCaretModel().getOffset()
|
||||||
|
|
||||||
|
val calleeExpr = element.getCalleeExpression()
|
||||||
|
if (calleeExpr == null) return false
|
||||||
|
|
||||||
|
val textRange = calleeExpr.getTextRange()
|
||||||
|
if (textRange == null) return false
|
||||||
|
|
||||||
|
if (caretLocation !in textRange) return false
|
||||||
|
|
||||||
val parent = element.getParent()
|
val parent = element.getParent()
|
||||||
|
|
||||||
if (parent is JetDotQualifiedExpression) {
|
if (parent is JetDotQualifiedExpression) {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(x: Int) {
|
||||||
|
x.tim<caret>es(1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(x: Int) {
|
||||||
|
x times 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo(num: Int) {
|
||||||
|
n<caret>um.times(1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo(x: Int) {
|
||||||
|
x.times(<caret>1)
|
||||||
|
}
|
||||||
@@ -1751,6 +1751,16 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/binaryExpressionArgument.kt");
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/binaryExpressionArgument.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("caretInsideCalleeExpr.kt")
|
||||||
|
public void testCaretInsideCalleeExpr() throws Exception {
|
||||||
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/caretInsideCalleeExpr.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("caretInsideReceiverExpr.kt")
|
||||||
|
public void testCaretInsideReceiverExpr() throws Exception {
|
||||||
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/caretInsideReceiverExpr.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleFunctionCall.kt")
|
@TestMetadata("doubleFunctionCall.kt")
|
||||||
public void testDoubleFunctionCall() throws Exception {
|
public void testDoubleFunctionCall() throws Exception {
|
||||||
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/doubleFunctionCall.kt");
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/doubleFunctionCall.kt");
|
||||||
@@ -1776,6 +1786,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/functionSafeCall.kt");
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/functionSafeCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inapplicableCaretPosition.kt")
|
||||||
|
public void testInapplicableCaretPosition() throws Exception {
|
||||||
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/inapplicableCaretPosition.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multipleArguments.kt")
|
@TestMetadata("multipleArguments.kt")
|
||||||
public void testMultipleArguments() throws Exception {
|
public void testMultipleArguments() throws Exception {
|
||||||
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/multipleArguments.kt");
|
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/multipleArguments.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user