IDEA-75064 keep control statements in one line

This commit is contained in:
Max Medvedev
2013-04-30 11:49:12 +04:00
parent 35f40d8078
commit b3b3783f55
2 changed files with 44 additions and 2 deletions
@@ -302,8 +302,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
public void visitOpenBlock(GrOpenBlock block) {
final PsiElement parent = block.getParent();
boolean keepInOneLine = parent instanceof GrMethod ?
mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE :
boolean keepInOneLine = parent instanceof GrMethod ? mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE :
mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE;
if (myType1 == mLCURLY && myType2 == mRCURLY) {
@@ -717,6 +716,9 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else if (myType1 == mRPAREN) {
createSpacingBeforeElementInsideControlStatement();
}
}
private static boolean isOpenBlock(IElementType type) {
@@ -306,6 +306,46 @@ if (abc) {return 2}
if (abc) {
return 2
}
''')
}
void testControlStatementsInOneLine() {
groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true
checkFormatting('''\
if (abc) return 2
''', '''\
if (abc) return 2
''')
checkFormatting('''\
while (abc) return 2
''', '''\
while (abc) return 2
''')
checkFormatting('''\
for (abc) return 2
''', '''\
for (abc) return 2
''')
groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false
checkFormatting('''\
if (abc) return 2
''', '''\
if (abc)
return 2
''')
checkFormatting('''\
while (abc) return 2
''', '''\
while (abc)
return 2
''')
checkFormatting('''\
for (;abc;) return 2
''', '''\
for (; abc;)
return 2
''')
}