KT-11975 Invert if-condition intention does not simplify "is" expresssion
#KT-11975 Fixed
This commit is contained in:
@@ -23,9 +23,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
||||
@@ -164,6 +164,13 @@ private fun KtExpression.specialNegation(): KtExpression? {
|
||||
return factory.createExpressionByPattern("$0 $1 $2", left, getNegatedOperatorText(operator), right)
|
||||
}
|
||||
|
||||
is KtIsExpression -> {
|
||||
return factory.createExpressionByPattern("$0 $1 $2",
|
||||
leftHandSide,
|
||||
if (isNegated) "is" else "!is",
|
||||
typeReference ?: return null)
|
||||
}
|
||||
|
||||
is KtConstantExpression -> {
|
||||
return when (text) {
|
||||
"true" -> factory.createExpression("false")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun f(p: Any, set: Set<Any>) {
|
||||
<caret>if (p in set) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun f(p: Any, set: Set<Any>) {
|
||||
if (p !in set) return
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun f(p: Any) {
|
||||
<caret>if (p is String) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun f(p: Any) {
|
||||
if (p !is String) return
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun f(p: Any) {
|
||||
<caret>if (p !is String) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun f(p: Any) {
|
||||
if (p is String) return
|
||||
//TODO
|
||||
}
|
||||
@@ -6381,12 +6381,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("in.kt")
|
||||
public void testIn() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/in.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("invertableOperator.kt")
|
||||
public void testInvertableOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/invertableOperator.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("is.kt")
|
||||
public void testIs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/is.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lastStatement1.kt")
|
||||
public void testLastStatement1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatement1.kt");
|
||||
@@ -6453,6 +6465,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notIs.kt")
|
||||
public void testNotIs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/notIs.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("returnIfExpression.kt")
|
||||
public void testReturnIfExpression() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/returnIfExpression.kt");
|
||||
|
||||
Reference in New Issue
Block a user