KT-13430 related: add non-null assertion works also for UNSAFE_INFIX_CALL

This commit is contained in:
Mikhail Glukhikh
2016-08-12 15:58:00 +03:00
parent cf2d575eec
commit 52dacd1d49
7 changed files with 50 additions and 0 deletions
@@ -102,6 +102,7 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() {
val parent = psiElement.parent
return when (parent) {
is KtUnaryExpression -> parent.baseExpression
is KtBinaryExpression -> parent.left
else -> null
}
}
@@ -202,6 +202,7 @@ class QuickFixRegistrar : QuickFixContributor {
TYPE_MISMATCH.registerFactory(WrapWithSafeLetCallFix.TypeMismatchFactory)
UNSAFE_CALL.registerFactory(AddExclExclCallFix)
UNSAFE_INFIX_CALL.registerFactory(AddExclExclCallFix)
UNNECESSARY_NOT_NULL_ASSERTION.registerFactory(RemoveExclExclCallFix)
UNSAFE_INFIX_CALL.registerFactory(ReplaceInfixOrOperatorCallFix)
UNSAFE_CALL.registerFactory(ReplaceInfixOrOperatorCallFix) // [] only
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class SafeType {
operator fun plus(arg: Int) {}
}
fun safeB(p: SafeType?) {
val v = p <caret>+ 42
}
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class SafeType {
operator fun plus(arg: Int) {}
}
fun safeB(p: SafeType?) {
val v = p!! + 42
}
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class SafeType {
infix fun op(arg: Int) {}
}
fun safeB(p: SafeType?) {
val v = p <caret>op 42
}
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class SafeType {
infix fun op(arg: Int) {}
}
fun safeB(p: SafeType?) {
val v = p!! op 42
}
@@ -4770,6 +4770,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/expressions"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("fixNullableBinaryWithExclExcl.kt")
public void testFixNullableBinaryWithExclExcl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableBinaryWithExclExcl.kt");
doTest(fileName);
}
@TestMetadata("fixNullableInfixWithExclExcl.kt")
public void testFixNullableInfixWithExclExcl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableInfixWithExclExcl.kt");
doTest(fileName);
}
@TestMetadata("fixNullableIterableGenericWithExclExcl.kt")
public void testFixNullableIterableGenericWithExclExcl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableIterableGenericWithExclExcl.kt");