line feeds in method parameter list

This commit is contained in:
Max Medvedev
2013-05-01 18:24:00 +04:00
parent 79b99e1a67
commit 08e14d40bd
2 changed files with 74 additions and 2 deletions
@@ -480,8 +480,24 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
if (myType2 == mLPAREN) {
createSpaceInCode(mySettings.SPACE_BEFORE_METHOD_PARENTHESES);
}
else if (myType1 == mLPAREN || myType2 == mRPAREN) {
createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES);
else if (myType1 == mLPAREN && myType2 == mRPAREN) {
createSpaceInCode(mySettings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES);
}
else if (myType1 == mLPAREN) {
if (mySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE) {
createDependentLFSpacing(mySettings.SPACE_WITHIN_METHOD_PARENTHESES, method.getParameterList().getTextRange());
}
else {
createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES);
}
}
else if (myType2 == mRPAREN) {
if (mySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE) {
createDependentLFSpacing(mySettings.SPACE_WITHIN_METHOD_PARENTHESES, method.getParameterList().getTextRange());
}
else {
createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES);
}
}
else if (myType1 == mRPAREN && myType2 == THROW_CLAUSE) {
if (mySettings.THROWS_KEYWORD_WRAP == CommonCodeStyleSettings.WRAP_ALWAYS) {
@@ -509,6 +525,11 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
}
}
private void createDependentLFSpacing(boolean space, @NotNull TextRange range) {
myResult = Spacing
.createDependentLFSpacing(space ? 1 : 0, space ? 1 : 0, range, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
private void manageSpaceBeforeTypeParameters() {
createSpaceInCode(false);
}
@@ -478,6 +478,57 @@ def cl = {
''')
}
void testLineFeedsInMethodParams0() {
groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true
checkFormatting('''\
def foo(String s,
int x) {}
''', '''\
def foo(
String s,
int x) {}
''')
}
void testLineFeedsInMethodParams1() {
groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true
checkFormatting('''\
def foo(String s,
int x) {}
''', '''\
def foo(String s,
int x
) {}
''')
}
void testLineFeedsInMethodParams2() {
groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true
groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true
checkFormatting('''\
def foo(String s,
int x) {}
''', '''\
def foo(
String s,
int x
) {}
''')
}
void testLineFeedsInMethodParams3() {
groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true
groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true
groovySettings.SPACE_WITHIN_METHOD_PARENTHESES = true
checkFormatting('''\
def foo(String s, int x) {}
''', '''\
def foo( String s, int x ) {}
''')
}
private void doGeeseTest() {
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;