Bug Fix for KT-4652 Replace with Infix Call

This commit is contained in:
Lingzhang
2014-04-03 15:57:56 -04:00
parent d28ca5bdfa
commit 6feee57d5e
6 changed files with 43 additions and 0 deletions
@@ -34,6 +34,20 @@ import org.jetbrains.jet.lang.psi.JetFile
public class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
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()
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");
}
@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")
public void testDoubleFunctionCall() throws Exception {
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/doubleFunctionCall.kt");
@@ -1776,6 +1786,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
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")
public void testMultipleArguments() throws Exception {
doTestReplaceWithInfixFunctionCall("idea/testData/intentions/replaceWithInfixFunctionCall/multipleArguments.kt");