mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] KTIJ-35524 Fix "Safe delete" of variable in when condition deleting the whole condition
GitOrigin-RevId: a9243ac23571cc19ad9ca6ec27297ce9d14147bf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
20eb5d3c95
commit
b708ab3f4d
+5
@@ -554,6 +554,11 @@ public abstract class SafeDeleteTestGenerated extends AbstractSafeDeleteTest {
|
||||
public void testPropertyInLocalObject2() throws Exception {
|
||||
runTest("testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("testData/refactoring/safeDelete/deleteProperty/kotlinProperty/when.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IGNORE_K1
|
||||
enum class Direction {
|
||||
NORTH, SOUTH, WEST, EAST
|
||||
}
|
||||
|
||||
fun foo(direction: Direction): String {
|
||||
return when (/* lead */ val x<caret> /* mid */ = /* rhs */ direction /* trail */) {
|
||||
Direction.NORTH -> "north"
|
||||
Direction.SOUTH -> "south"
|
||||
Direction.WEST -> "west"
|
||||
Direction.EAST -> "east"
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IGNORE_K1
|
||||
enum class Direction {
|
||||
NORTH, SOUTH, WEST, EAST
|
||||
}
|
||||
|
||||
fun foo(direction: Direction): String {
|
||||
return when (/* lead */ /* mid */ /* rhs */ direction /* trail */) {
|
||||
Direction.NORTH -> "north"
|
||||
Direction.SOUTH -> "south"
|
||||
Direction.WEST -> "west"
|
||||
Direction.EAST -> "east"
|
||||
}
|
||||
}
|
||||
+9
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.search.ExpectActualUtils
|
||||
import org.jetbrains.kotlin.idea.searching.inheritors.DirectKotlinClassInheritorsSearch
|
||||
import org.jetbrains.kotlin.idea.searching.inheritors.findAllOverridings
|
||||
import org.jetbrains.kotlin.idea.util.CommentSaver
|
||||
import org.jetbrains.kotlin.idea.util.application.isUnitTestMode
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -357,6 +358,14 @@ class KotlinFirSafeDeleteProcessor : SafeDeleteProcessorDelegateBase() {
|
||||
deleteBracesAroundEmptyList(element)
|
||||
}
|
||||
|
||||
is KtProperty if ((element.parent as? KtWhenExpression)?.subjectVariable === element) -> {
|
||||
val commentSaver = CommentSaver(element)
|
||||
element.initializer?.let { initializer ->
|
||||
val replaced = element.replace(initializer.copy())
|
||||
commentSaver.restore(replaced)
|
||||
}
|
||||
}
|
||||
|
||||
is KtParameter -> {
|
||||
element.ownerFunction?.let {
|
||||
with(KotlinSafeDeleteSettings) {
|
||||
|
||||
+5
@@ -525,6 +525,11 @@ public abstract class K2SafeDeleteTestGenerated extends AbstractK2SafeDeleteTest
|
||||
public void testPropertyInLocalObject2() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/when.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user