mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
format binary & parenthesized expressions
This commit is contained in:
+11
@@ -49,6 +49,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSectio
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrElvisExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
|
||||
@@ -332,6 +333,16 @@ public class GroovyIndentProcessor extends GroovyElementVisitor {
|
||||
return CodeStyleSettingsManager.getSettings(parent.getProject()).getCommonSettings(GroovyFileType.GROOVY_LANGUAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParenthesizedExpression(GrParenthesizedExpression expression) {
|
||||
if (myChildType == mLPAREN || myChildType == mRPAREN) {
|
||||
myResult = Indent.getNoneIndent();
|
||||
}
|
||||
else {
|
||||
myResult = Indent.getContinuationIndent();
|
||||
}
|
||||
}
|
||||
|
||||
public static Indent getSwitchCaseIndent(PsiElement psiParent) {
|
||||
if (getGroovySettings(psiParent).INDENT_CASE_FROM_SWITCH) {
|
||||
return Indent.getNormalIndent();
|
||||
|
||||
+14
-22
@@ -670,26 +670,19 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
|
||||
|
||||
@Override
|
||||
public void visitBinaryExpression(GrBinaryExpression expression) {
|
||||
if (isLeftOrRight(LOGICAL_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_LOGICAL_OPERATORS);
|
||||
boolean spaceAround = isLeftOrRight(LOGICAL_OPERATORS) ? mySettings.SPACE_AROUND_LOGICAL_OPERATORS :
|
||||
isLeftOrRight(EQUALITY_OPERATORS) ? mySettings.SPACE_AROUND_EQUALITY_OPERATORS :
|
||||
isLeftOrRight(RELATIONAL_OPERATORS) ? mySettings.SPACE_AROUND_RELATIONAL_OPERATORS :
|
||||
isLeftOrRight(BITWISE_OPERATORS) ? mySettings.SPACE_AROUND_BITWISE_OPERATORS :
|
||||
isLeftOrRight(ADDITIVE_OPERATORS) ? mySettings.SPACE_AROUND_ADDITIVE_OPERATORS :
|
||||
isLeftOrRight(MULTIPLICATIVE_OPERATORS) ? mySettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS :
|
||||
isLeftOrRight(SHIFT_OPERATORS) ? mySettings.SPACE_AROUND_SHIFT_OPERATORS :
|
||||
false;
|
||||
if (TokenSets.BINARY_OP_SET.contains(myType2)) {
|
||||
createDependentLFSpacing(mySettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE, spaceAround, expression.getTextRange());
|
||||
}
|
||||
else if (isLeftOrRight(EQUALITY_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_EQUALITY_OPERATORS);
|
||||
}
|
||||
else if (isLeftOrRight(RELATIONAL_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_RELATIONAL_OPERATORS);
|
||||
}
|
||||
else if (isLeftOrRight(BITWISE_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_BITWISE_OPERATORS);
|
||||
}
|
||||
else if (isLeftOrRight(ADDITIVE_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_ADDITIVE_OPERATORS);
|
||||
}
|
||||
else if (isLeftOrRight(MULTIPLICATIVE_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS);
|
||||
}
|
||||
else if (isLeftOrRight(SHIFT_OPERATORS)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_SHIFT_OPERATORS);
|
||||
else {
|
||||
createSpaceInCode(spaceAround);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -772,9 +765,8 @@ public class GroovySpacingProcessor extends GroovyElementVisitor {
|
||||
|
||||
@Override
|
||||
public void visitParenthesizedExpression(GrParenthesizedExpression expression) {
|
||||
if (myType1 == mLPAREN || myType2 == mRPAREN) {
|
||||
createSpaceInCode(mySettings.SPACE_WITHIN_PARENTHESES);
|
||||
}
|
||||
processParentheses(mLPAREN, mRPAREN, mySettings.SPACE_WITHIN_PARENTHESES, null, mySettings.PARENTHESES_EXPRESSION_LPAREN_WRAP,
|
||||
mySettings.PARENTHESES_EXPRESSION_RPAREN_WRAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -613,6 +613,74 @@ for (int i = 3;
|
||||
''')
|
||||
}
|
||||
|
||||
void testBinaryOperationSingOnNewLine() {
|
||||
groovySettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE = true
|
||||
|
||||
checkFormatting('''\
|
||||
(1 +
|
||||
2) + 3
|
||||
''', '''\
|
||||
(1
|
||||
+
|
||||
2)
|
||||
+ 3
|
||||
''')
|
||||
}
|
||||
|
||||
void testParenthesized0() {
|
||||
groovySettings.PARENTHESES_EXPRESSION_LPAREN_WRAP = true
|
||||
checkFormatting('''\
|
||||
(2+
|
||||
3)
|
||||
''', '''\
|
||||
(
|
||||
2 +
|
||||
3)
|
||||
''')
|
||||
}
|
||||
|
||||
void testParenthesized1() {
|
||||
groovySettings.PARENTHESES_EXPRESSION_RPAREN_WRAP = true
|
||||
checkFormatting('''\
|
||||
(2+
|
||||
3)
|
||||
''', '''\
|
||||
(2 +
|
||||
3
|
||||
)
|
||||
''')
|
||||
}
|
||||
|
||||
void testParenthesized2() {
|
||||
groovySettings.PARENTHESES_EXPRESSION_LPAREN_WRAP = true
|
||||
groovySettings.PARENTHESES_EXPRESSION_RPAREN_WRAP = true
|
||||
checkFormatting('''\
|
||||
(2+
|
||||
3)
|
||||
''', '''\
|
||||
(
|
||||
2 +
|
||||
3
|
||||
)
|
||||
''')
|
||||
}
|
||||
|
||||
void testParenthesized3() {
|
||||
groovySettings.PARENTHESES_EXPRESSION_LPAREN_WRAP = true
|
||||
groovySettings.PARENTHESES_EXPRESSION_RPAREN_WRAP = true
|
||||
groovySettings.ALIGN_MULTILINE_BINARY_OPERATION = true
|
||||
checkFormatting('''\
|
||||
(2+
|
||||
3)
|
||||
''', '''\
|
||||
(
|
||||
2 +
|
||||
3
|
||||
)
|
||||
''')
|
||||
}
|
||||
|
||||
|
||||
private void doGeeseTest() {
|
||||
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
|
||||
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;
|
||||
|
||||
Reference in New Issue
Block a user