mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] inline: delete when condition if when contains only else branch
^KTIJ-29176 fixed GitOrigin-RevId: 52d6fbf2a12bed144caafd9b2cf3c70d4b8b2944
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e68cdb6036
commit
d8c7446aa5
+5
@@ -773,6 +773,11 @@ public abstract class InlineTestGenerated extends AbstractInlineTest {
|
||||
public void testReturnNull() throws Exception {
|
||||
runTest("testData/refactoring/inline/inlineVariableOrProperty/property/returnNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("testData/refactoring/inline/inlineVariableOrProperty/property/when.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
val x = 42
|
||||
fun callUsage() {
|
||||
when ((<caret>x)) {
|
||||
else -> { println(6) }
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun callUsage() {
|
||||
when {
|
||||
else -> { println(6) }
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.canPlaceAfterSimpleNameEntry
|
||||
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
@@ -178,7 +179,14 @@ class ExpressionReplacementPerformer(
|
||||
}
|
||||
}
|
||||
if (canDropElementToBeReplaced) {
|
||||
stub.delete()
|
||||
val parent = stub.parents.first { it !is KtParenthesizedExpression }
|
||||
if (parent is KtWhenExpression &&
|
||||
parent.subjectExpression?.safeDeparenthesize() == stub &&
|
||||
parent.leftParenthesis != null && parent.rightParenthesis != null) {
|
||||
parent.deleteChildRange(parent.leftParenthesis, parent.rightParenthesis)
|
||||
} else {
|
||||
stub.delete()
|
||||
}
|
||||
null
|
||||
} else {
|
||||
stub.replaced(psiFactory.createExpression("Unit"))
|
||||
|
||||
+5
@@ -612,6 +612,11 @@ public abstract class KotlinFirInlineTestGenerated extends AbstractKotlinFirInli
|
||||
public void testReturnNull() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/inline/inlineVariableOrProperty/property/returnNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/inline/inlineVariableOrProperty/property/when.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user