mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-62837 Incorrect caret column after Enter in 'case'
This commit is contained in:
@@ -35,7 +35,14 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSwitchStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrBreakStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrContinueStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
@@ -121,15 +128,33 @@ public class GroovyBlock implements Block, GroovyElementTypes {
|
||||
|
||||
@NotNull
|
||||
public ChildAttributes getChildAttributes(final int newChildIndex) {
|
||||
return getAttributesByParent();
|
||||
}
|
||||
|
||||
private ChildAttributes getAttributesByParent() {
|
||||
ASTNode astNode = getNode();
|
||||
final PsiElement psiParent = astNode.getPsi();
|
||||
if (psiParent instanceof GroovyFileBase) {
|
||||
return new ChildAttributes(Indent.getNoneIndent(), null);
|
||||
}
|
||||
if (psiParent instanceof GrSwitchStatement) {
|
||||
List<Block> subBlocks = getSubBlocks();
|
||||
if (newChildIndex > 0) {
|
||||
Block block = subBlocks.get(newChildIndex - 1);
|
||||
if (block instanceof GroovyBlock) {
|
||||
PsiElement anchorPsi = ((GroovyBlock)block).getNode().getPsi();
|
||||
if (anchorPsi instanceof GrCaseSection) {
|
||||
for (GrStatement statement : ((GrCaseSection)anchorPsi).getStatements()) {
|
||||
if (statement instanceof GrBreakStatement ||
|
||||
statement instanceof GrContinueStatement ||
|
||||
statement instanceof GrReturnStatement ||
|
||||
statement instanceof GrThrowStatement) {
|
||||
return new ChildAttributes(GroovyIndentProcessor.getSwitchCaseIndent(anchorPsi), null);
|
||||
}
|
||||
}
|
||||
int indentSize = mySettings.getAdditionalIndentOptions(anchorPsi.getContainingFile().getFileType()).INDENT_SIZE;
|
||||
return new ChildAttributes(Indent.getSpaceIndent(mySettings.INDENT_CASE_FROM_SWITCH ? 2 * indentSize : indentSize), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (BLOCK_SET.contains(astNode.getElementType()) ||
|
||||
SWITCH_STATEMENT.equals(astNode.getElementType())) {
|
||||
return new ChildAttributes(Indent.getNormalIndent(), null);
|
||||
|
||||
+9
-2
@@ -232,10 +232,17 @@ public abstract class GroovyIndentProcessor implements GroovyElementTypes {
|
||||
}
|
||||
|
||||
private static Indent indentForSwitchStatement(PsiElement psiParent, ASTNode child) {
|
||||
if (CASE_SECTION.equals(child.getElementType()) && CodeStyleSettingsManager.getSettings(psiParent.getProject()).INDENT_CASE_FROM_SWITCH) {
|
||||
return Indent.getNormalIndent();
|
||||
if (CASE_SECTION.equals(child.getElementType())) {
|
||||
return getSwitchCaseIndent(psiParent);
|
||||
}
|
||||
return Indent.getNoneIndent();
|
||||
}
|
||||
|
||||
public static Indent getSwitchCaseIndent(PsiElement psiParent) {
|
||||
if (CodeStyleSettingsManager.getSettings(psiParent.getProject()).INDENT_CASE_FROM_SWITCH) {
|
||||
return Indent.getNormalIndent();
|
||||
}
|
||||
return Indent.getNoneIndent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+53
-1
@@ -139,7 +139,59 @@ switch(x) {
|
||||
<caret>
|
||||
}"""
|
||||
}
|
||||
|
||||
|
||||
public void testCaseBeforeReturn() {
|
||||
doTest """
|
||||
switch(x) {
|
||||
case 0: <caret>
|
||||
return x
|
||||
}""", """
|
||||
switch(x) {
|
||||
case 0:
|
||||
<caret>
|
||||
return x
|
||||
}"""
|
||||
}
|
||||
|
||||
public void testCaseAfterBreak() {
|
||||
doTest """
|
||||
switch(x) {
|
||||
case 0:
|
||||
break<caret>
|
||||
}""", """
|
||||
switch(x) {
|
||||
case 0:
|
||||
break
|
||||
<caret>
|
||||
}"""
|
||||
}
|
||||
|
||||
public void testCaseAfterCall() {
|
||||
doTest """
|
||||
switch(x) {
|
||||
case 0:
|
||||
foo()<caret>
|
||||
}""", """
|
||||
switch(x) {
|
||||
case 0:
|
||||
foo()
|
||||
<caret>
|
||||
}"""
|
||||
}
|
||||
|
||||
public void testCaseAfterReturn() {
|
||||
doTest """
|
||||
switch(x) {
|
||||
case 0:
|
||||
return 2<caret>
|
||||
}""", """
|
||||
switch(x) {
|
||||
case 0:
|
||||
return 2
|
||||
<caret>
|
||||
}"""
|
||||
}
|
||||
|
||||
public void testAlmostBeforeClosingClosureBrace() throws Throwable {
|
||||
doTest """
|
||||
def c = { a ->
|
||||
|
||||
Reference in New Issue
Block a user