mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-275893 [extract method]: align selection for switch statement rules
GitOrigin-RevId: 00c58a19d98bdc99b95cd228b1cc2fa746e9d301
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6101375b0b
commit
3d9770213b
+3
-5
@@ -41,6 +41,7 @@ class ExtractSelector {
|
||||
singleElement is PsiBlockStatement -> if (singleElement.codeBlock.firstBodyElement != null) listOf(singleElement) else emptyList()
|
||||
singleElement is PsiCodeBlock -> alignCodeBlock(singleElement)
|
||||
singleElement is PsiExpression -> listOfNotNull(alignExpression(singleElement))
|
||||
singleElement is PsiSwitchLabeledRuleStatement -> listOfNotNull(singleElement.body)
|
||||
else -> elements
|
||||
}
|
||||
return when {
|
||||
@@ -86,11 +87,8 @@ class ExtractSelector {
|
||||
val filteredStatements = statements
|
||||
.dropWhile { it is PsiSwitchLabelStatement || it is PsiWhiteSpace }
|
||||
.dropLastWhile { it is PsiSwitchLabelStatement || it is PsiWhiteSpace }
|
||||
return if (filteredStatements.any { it is PsiSwitchLabelStatement }) {
|
||||
emptyList()
|
||||
} else {
|
||||
filteredStatements
|
||||
}
|
||||
if (filteredStatements.any { it is PsiSwitchLabelStatement || it is PsiSwitchLabeledRuleStatement }) return emptyList()
|
||||
return filteredStatements
|
||||
}
|
||||
|
||||
private fun isInsideAnnotation(expression: PsiExpression): Boolean {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package test;
|
||||
|
||||
public class Test1 {
|
||||
void test(){
|
||||
String s = "sample";
|
||||
switch (s) {
|
||||
<selection>case "one" -> {
|
||||
System.out.println("one");
|
||||
System.out.println("two");
|
||||
}
|
||||
default -> System.out.println();</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package test;
|
||||
|
||||
public class Test1 {
|
||||
void test(){
|
||||
String s = "sample";
|
||||
switch (s) {
|
||||
<selection>case "one" -> {
|
||||
System.out.println("one");
|
||||
System.out.println("two");
|
||||
}</selection>
|
||||
default -> System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package test;
|
||||
|
||||
public class Test1 {
|
||||
void test(){
|
||||
String s = "sample";
|
||||
switch (s) {
|
||||
case "one" -> extracted();
|
||||
default -> System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private void extracted() {
|
||||
System.out.println("one");
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
+11
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.refactoring.RefactoringBundle
|
||||
import com.intellij.refactoring.extractMethod.newImpl.MethodExtractor
|
||||
import com.intellij.refactoring.listeners.RefactoringEventData
|
||||
import com.intellij.refactoring.listeners.RefactoringEventListener
|
||||
@@ -135,6 +136,16 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testDisabledOnSwitchRules(){
|
||||
assertThrows(RefactoringErrorHintException::class.java, RefactoringBundle.message("selected.block.should.represent.a.set.of.statements.or.an.expression")) {
|
||||
doTest()
|
||||
}
|
||||
}
|
||||
|
||||
fun testNormalizedOnSwitchRule(){
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testRefactoringListener(){
|
||||
templateTest {
|
||||
configureByFile("$BASE_PATH/${getTestName(false)}.java")
|
||||
|
||||
Reference in New Issue
Block a user