Fix 'in' operator intention for Strings (KT-13974)

This commit is contained in:
takahirom
2016-09-27 01:56:05 +09:00
committed by Dmitry Jemerov
parent 93c2e7dfc0
commit 925c48c2f0
8 changed files with 42 additions and 10 deletions
@@ -48,7 +48,8 @@ class ReplaceContainsIntention : SelfTargetingRangeIntention<KtDotQualifiedExpre
if (!element.isReceiverExpressionWithValue()) return null
val functionDescriptor = getFunctionDescriptor(element) ?: return null
if (!functionDescriptor.isOperator || !OperatorChecks.check(functionDescriptor).isSuccess) return null
if (!functionDescriptor.isOperator && !OperatorChecks.check(functionDescriptor).isSuccess) return null
return element.callExpression!!.calleeExpression!!.textRange
}
@@ -0,0 +1,6 @@
@Suppress("INAPPLICABLE_OPERATOR_MODIFIER")
public operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boolean = false): Boolean = false
fun test() {
val foo = "foo"
foo.c<caret>ontains("bar")
}
@@ -0,0 +1,6 @@
@Suppress("INAPPLICABLE_OPERATOR_MODIFIER")
public operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boolean = false): Boolean = false
fun test() {
val foo = "foo"
"bar" in foo
}
@@ -0,0 +1,5 @@
class Container {
public boolean contains(int x, int y) {
return true;
}
}
@@ -0,0 +1,5 @@
class Container {
public boolean contains(int x, int y) {
return true;
}
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
fun foo() {
val c = Container()
c.cont<caret>ains(1, 2)
}
@@ -1,9 +0,0 @@
// IS_APPLICABLE: false
fun test() {
class Test{
fun contains(a: Int) : Boolean = true
}
val test = Test()
test.c<caret>ontains(0)
}
@@ -3140,12 +3140,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("simpleStringLiteral.kt")
public void testSimpleStringLiteral() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceContains/simpleStringLiteral.kt");
doTest(fileName);
}
@TestMetadata("super.kt")
public void testSuper() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceContains/super.kt");
doTest(fileName);
}
@TestMetadata("twoArgsContainsFromJava.kt")
public void testTwoArgsContainsFromJava() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceContains/twoArgsContainsFromJava.kt");
doTest(fileName);
}
@TestMetadata("typeArguments.kt")
public void testTypeArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceContains/typeArguments.kt");