mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-207858 Completion: default: should be indented correctly
GitOrigin-RevId: 03061981d39a54eaa807cd3bb280e028fca0e681
This commit is contained in:
committed by
intellij-monorepo-bot
parent
82c097a55b
commit
fcf2058fab
@@ -13,6 +13,7 @@ import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PsiElementPattern;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.filters.FilterPositionUtil;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
@@ -43,6 +44,11 @@ public class JavaKeywordCompletion {
|
||||
psiElement(PsiJavaCodeReferenceElement.class).insideStarting(
|
||||
psiElement().withTreeParent(
|
||||
psiElement(PsiParameterList.class).andNot(psiElement(PsiAnnotationParameterList.class)))));
|
||||
private static final InsertHandler<LookupElementDecorator<?>> ADJUST_LINE_OFFSET = (context, item) -> {
|
||||
item.getDelegate().handleInsert(context);
|
||||
context.commitDocument();
|
||||
CodeStyleManager.getInstance(context.getProject()).adjustLineIndent(context.getFile(), context.getStartOffset());
|
||||
};
|
||||
|
||||
private static boolean isStatementCodeFragment(PsiFile file) {
|
||||
return file instanceof JavaCodeFragment &&
|
||||
@@ -307,7 +313,9 @@ public class JavaKeywordCompletion {
|
||||
PsiSwitchBlock switchBlock = getSwitchFromLabelPosition(myPosition);
|
||||
if (switchBlock != null) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.CASE), TailType.INSERT_SPACE));
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.DEFAULT), TailTypes.forSwitchLabel(switchBlock)));
|
||||
addKeyword(LookupElementDecorator.withInsertHandler(
|
||||
new OverridableSpace(createKeyword(PsiKeyword.DEFAULT), TailTypes.forSwitchLabel(switchBlock)),
|
||||
ADJUST_LINE_OFFSET));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class StructuredConfigKey {
|
||||
{
|
||||
switch (x) {
|
||||
case 2:
|
||||
def<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
public class StructuredConfigKey {
|
||||
{
|
||||
switch (x) {
|
||||
case 2:
|
||||
default:<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -144,6 +144,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testFinalAfterParameterAnno2() { doTest(2, "final", "float", "class"); }
|
||||
public void testFinalAfterCase() { doTest(3, "final", "float", "class"); }
|
||||
public void testNoCaseInsideWhileInSwitch() { doTest(0, "case", "default"); }
|
||||
public void testIndentDefaultInSwitch() { doTest(); }
|
||||
public void testFinalInCatch() { doTest(1, "final"); }
|
||||
public void testFinalInIncompleteCatch() { doTest(1, "final"); }
|
||||
public void testFinalInCompleteCatch() { doTest(1, "final"); }
|
||||
|
||||
Reference in New Issue
Block a user