Do not suggest replacing comparison to null with function call
So #KT-20620 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d7807b5ae3
commit
52df70a576
+3
-1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -58,7 +59,8 @@ class OperatorToFunctionIntention : SelfTargetingIntention<KtExpression>(KtExpre
|
|||||||
val opRef = element.operationReference
|
val opRef = element.operationReference
|
||||||
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
||||||
return when (opRef.getReferencedNameElementType()) {
|
return when (opRef.getReferencedNameElementType()) {
|
||||||
KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE, KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.EQEQ, KtTokens.EXCLEQ, KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ -> true
|
KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE, KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ -> true
|
||||||
|
KtTokens.EQEQ, KtTokens.EXCLEQ -> listOf(element.left, element.right).none { it?.node?.elementType == KtNodeTypes.NULL }
|
||||||
KtTokens.EQ -> element.left is KtArrayAccessExpression
|
KtTokens.EQ -> element.left is KtArrayAccessExpression
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun test(x: String?) {
|
||||||
|
if (null <caret>!= x) {
|
||||||
|
x.length
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun test(x: String?) {
|
||||||
|
if (x <caret>!= null) {
|
||||||
|
x.length
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun test(x: String?) {
|
||||||
|
null <caret>== x
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun test(x: String?) {
|
||||||
|
x <caret>== null
|
||||||
|
}
|
||||||
@@ -11807,6 +11807,30 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryEqEqNotNullInLeftSide.kt")
|
||||||
|
public void testBinaryEqEqNotNullInLeftSide() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNotNullInLeftSide.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryEqEqNotNullInRightSide.kt")
|
||||||
|
public void testBinaryEqEqNotNullInRightSide() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNotNullInRightSide.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryEqEqNullInLeftSide.kt")
|
||||||
|
public void testBinaryEqEqNullInLeftSide() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNullInLeftSide.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryEqEqNullInRightSide.kt")
|
||||||
|
public void testBinaryEqEqNullInRightSide() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNullInRightSide.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("binaryEqEqNullable.kt")
|
@TestMetadata("binaryEqEqNullable.kt")
|
||||||
public void testBinaryEqEqNullable() throws Exception {
|
public void testBinaryEqEqNullable() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user