align conditional expression

This commit is contained in:
Max Medvedev
2013-05-01 18:24:04 +04:00
parent ee84029266
commit b78164399d
2 changed files with 36 additions and 0 deletions
@@ -289,6 +289,18 @@ public class GroovyBlockGenerator implements GroovyElementTypes {
}
}
else if (blockPsi instanceof GrConditionalExpression) {
if (mySettings.ALIGN_MULTILINE_TERNARY_OPERATION) {
final GrConditionalExpression conditional = (GrConditionalExpression)blockPsi;
final AlignmentProvider.Aligner aligner = myAlignmentProvider.createAligner(false);
aligner.append(conditional.getCondition());
if (!(conditional instanceof GrElvisExpression)) {
aligner.append(conditional.getThenBranch());
}
aligner.append(conditional.getElseBranch());
}
}
// For other cases
final ArrayList<Block> subBlocks = new ArrayList<Block>();
@@ -694,6 +694,30 @@ for (int i = 3;
}
void testConditional0() {
groovySettings.ALIGN_MULTILINE_TERNARY_OPERATION = true
checkFormatting '''\
print abc ?
cde:
xyz
''', '''\
print abc ?
cde :
xyz
'''
}
void testConditional1() {
groovySettings.ALIGN_MULTILINE_TERNARY_OPERATION = true
checkFormatting '''\
print abc ?:
xyz
''', '''\
print abc ?:
xyz
'''
}
private void doGeeseTest() {
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;