align method parentheses

This commit is contained in:
Max Medvedev
2013-05-01 18:24:01 +04:00
parent 0f117e3a31
commit 2ff1ca341a
2 changed files with 27 additions and 0 deletions
@@ -62,6 +62,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrM
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import java.util.ArrayList;
@@ -243,6 +244,19 @@ public class GroovyBlockGenerator implements GroovyElementTypes {
return generateSubBlockForCodeBlocks(classLevel, visibleChildren(myNode));
}
if (blockPsi instanceof GrMethod) {
final AlignmentProvider.Aligner parenthesesAligner = mySettings.ALIGN_MULTILINE_METHOD_BRACKETS ? myAlignmentProvider.createAligner(false) : null;
final ArrayList<Block> subBlocks = new ArrayList<Block>();
for (ASTNode childNode : visibleChildren(myNode)) {
final Indent indent = new GroovyIndentProcessor().getChildIndent(myBlock, childNode);
if (childNode.getElementType() == mLPAREN && parenthesesAligner != null) parenthesesAligner.append(childNode.getPsi());
if (childNode.getElementType() == mRPAREN && parenthesesAligner != null) parenthesesAligner.append(childNode.getPsi());
subBlocks.add(new GroovyBlock(childNode, indent, myWrap, mySettings, myGroovySettings, myAlignmentProvider));
}
return subBlocks;
}
// For other cases
final ArrayList<Block> subBlocks = new ArrayList<Block>();
for (ASTNode childNode : visibleChildren(myNode)) {
@@ -587,6 +587,19 @@ foo( )
''')
}
void testAlignMethodParentheses() {
groovySettings.ALIGN_MULTILINE_METHOD_BRACKETS = true
checkFormatting('''\
def foooo(
String s
) {}
''', '''\
def foooo(
String s
) {}
''')
}
private void doGeeseTest() {
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;