mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Don't offer "surround with statement" actions for 'case' and 'default' clauses (IDEA-204012)
This commit is contained in:
+2
-1
@@ -24,13 +24,14 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.lang.surroundWith.Surrounder;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
abstract class JavaStatementsSurrounder implements Surrounder {
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull PsiElement[] elements) {
|
||||
return true;
|
||||
return ContainerUtil.find(elements, PsiSwitchLabelStatementBase.class::isInstance) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class C {
|
||||
void foo(int n) {
|
||||
switch (n) {
|
||||
case 1:
|
||||
<selection>break;</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class C {
|
||||
void foo(int n) {
|
||||
switch (n) {
|
||||
case 1:
|
||||
if () {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class C {
|
||||
void foo(int n) {
|
||||
switch (n) {
|
||||
<selection>case 1:</selection>
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -92,6 +92,14 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
|
||||
doTest(new JavaWithIfSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundSwitchCaseWithIf() {
|
||||
doTestNotApplicable(new JavaWithIfSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundSwitchBreakWithIf() {
|
||||
doTest(getTestName(false), new JavaWithIfSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundNonExpressionWithParenthesis() {
|
||||
doTest(new JavaWithParenthesesSurrounder());
|
||||
}
|
||||
@@ -225,6 +233,23 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
|
||||
checkResultByFile(BASE_PATH + fileName + "_after.java");
|
||||
}
|
||||
|
||||
private void doTestNotApplicable(Surrounder surrounder) {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
SelectionModel selectionModel = getEditor().getSelectionModel();
|
||||
List<SurroundDescriptor> descriptors = LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE);
|
||||
|
||||
boolean atLeastOneFound = false;
|
||||
for (SurroundDescriptor item : descriptors) {
|
||||
PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
|
||||
if (elements.length != 0) {
|
||||
assertFalse("applicable " + item, surrounder.isApplicable(elements));
|
||||
atLeastOneFound = true;
|
||||
}
|
||||
}
|
||||
assertTrue("atLeastOneFound", atLeastOneFound);
|
||||
}
|
||||
|
||||
private void doTestWithTemplateFinish(@NotNull String fileName, Surrounder surrounder, @Nullable String textToType) {
|
||||
TemplateManagerImpl.setTemplateTesting(getTestRootDisposable());
|
||||
configureByFile(BASE_PATH + fileName + ".java");
|
||||
|
||||
Reference in New Issue
Block a user