Surround with null check: fix incorrect check for 'in' expression
#KT-31749 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
1188f4617a
commit
11044a3ab5
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.diagnostics.Errors
|
|||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableSimpleExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableSimpleExpression
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
||||||
@@ -68,7 +69,7 @@ class SurroundWithNullCheckFix(
|
|||||||
val nullableExpression =
|
val nullableExpression =
|
||||||
when (parent) {
|
when (parent) {
|
||||||
is KtDotQualifiedExpression -> parent.receiverExpression
|
is KtDotQualifiedExpression -> parent.receiverExpression
|
||||||
is KtBinaryExpression -> parent.left
|
is KtBinaryExpression -> if (parent.operationToken == KtTokens.IN_KEYWORD) parent.right else parent.left
|
||||||
is KtCallExpression -> parent.calleeExpression
|
is KtCallExpression -> parent.calleeExpression
|
||||||
else -> return null
|
else -> return null
|
||||||
} as? KtReferenceExpression ?: return null
|
} as? KtReferenceExpression ?: return null
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Surround with null check" "true"
|
||||||
|
fun test(a: String, b: List<String>?) {
|
||||||
|
a <caret>in b
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Surround with null check" "true"
|
||||||
|
fun test(a: String, b: List<String>?) {
|
||||||
|
if (b != null) {
|
||||||
|
a in b
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13161,6 +13161,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/surroundWithNullCheck/expressionUnsafeCall.kt");
|
runTest("idea/testData/quickfix/surroundWithNullCheck/expressionUnsafeCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("in.kt")
|
||||||
|
public void testIn() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/surroundWithNullCheck/in.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("infixUnsafeCall.kt")
|
@TestMetadata("infixUnsafeCall.kt")
|
||||||
public void testInfixUnsafeCall() throws Exception {
|
public void testInfixUnsafeCall() throws Exception {
|
||||||
runTest("idea/testData/quickfix/surroundWithNullCheck/infixUnsafeCall.kt");
|
runTest("idea/testData/quickfix/surroundWithNullCheck/infixUnsafeCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user