Skip to content

Commit 73338f7

Browse files
committed
Fix indentation
1 parent db058e1 commit 73338f7

File tree

1 file changed

+83
-83
lines changed

1 file changed

+83
-83
lines changed

src/main/java/spoon/reflect/visitor/RoundBracketAnalyzer.java

+83-83
Original file line numberDiff line numberDiff line change
@@ -18,97 +18,97 @@
1818
*/
1919
class RoundBracketAnalyzer {
2020

21-
enum EncloseInRoundBrackets {
22-
YES, NO, UNKNOWN;
23-
}
21+
enum EncloseInRoundBrackets {
22+
YES, NO, UNKNOWN;
23+
}
2424

25-
private RoundBracketAnalyzer() {
26-
}
25+
private RoundBracketAnalyzer() {
26+
}
2727

28-
/**
29-
* @param expr A unary or binary expr.
30-
* @return true if the expr should be enclosed in round brackets.
31-
*/
32-
static EncloseInRoundBrackets requiresRoundBrackets(CtExpression<?> expr) {
33-
return isNestedOperator(expr)
34-
? nestedOperatorRequiresRoundBrackets(expr)
35-
: EncloseInRoundBrackets.UNKNOWN;
36-
}
28+
/**
29+
* @param expr A unary or binary expr.
30+
* @return true if the expr should be enclosed in round brackets.
31+
*/
32+
static EncloseInRoundBrackets requiresRoundBrackets(CtExpression<?> expr) {
33+
return isNestedOperator(expr)
34+
? nestedOperatorRequiresRoundBrackets(expr)
35+
: EncloseInRoundBrackets.UNKNOWN;
36+
}
3737

38-
/**
39-
* Assuming that operator is a nested operator (i.e. both operator and its parent are
40-
* {@link CtUnaryOperator} or {@link CtBinaryOperator}), determine whether or not it must be
41-
* enclosed in round brackets.
42-
*
43-
* Given an element <code>e</code> with a parent <code>p</code>, we must parenthesize
44-
* <code>e</code> if any of the following are true.
45-
*
46-
* <ul>
47-
* <li>The parent p is a unary operator</li>
48-
* <li>The parent p is a binary operator, and <code>precedence(p) > precedence(e></code></li>
49-
* <li>The parent p is a binary operator, <code>precedence(p) == precedence(e)</code>,
50-
* e appears as the X-hand-side operand of p, and e's operator is Y-associative, where
51-
* <code>X != Y</code></li>
52-
* </ul>
53-
*
54-
* Note that the final rule is necessary to preserve syntactical structure, but it is not
55-
* required for preserving semantics.
56-
*
57-
* @param nestedOperator A nested operator.
58-
* @return Whether or not to enclose the nested operator in round brackets.
59-
*/
60-
private static EncloseInRoundBrackets nestedOperatorRequiresRoundBrackets(CtExpression<?> nestedOperator) {
61-
if (nestedOperator.getParent() instanceof CtUnaryOperator) {
62-
return EncloseInRoundBrackets.YES;
63-
}
38+
/**
39+
* Assuming that operator is a nested operator (i.e. both operator and its parent are
40+
* {@link CtUnaryOperator} or {@link CtBinaryOperator}), determine whether or not it must be
41+
* enclosed in round brackets.
42+
*
43+
* Given an element <code>e</code> with a parent <code>p</code>, we must parenthesize
44+
* <code>e</code> if any of the following are true.
45+
*
46+
* <ul>
47+
* <li>The parent p is a unary operator</li>
48+
* <li>The parent p is a binary operator, and <code>precedence(p) > precedence(e></code></li>
49+
* <li>The parent p is a binary operator, <code>precedence(p) == precedence(e)</code>,
50+
* e appears as the X-hand-side operand of p, and e's operator is Y-associative, where
51+
* <code>X != Y</code></li>
52+
* </ul>
53+
*
54+
* Note that the final rule is necessary to preserve syntactical structure, but it is not
55+
* required for preserving semantics.
56+
*
57+
* @param nestedOperator A nested operator.
58+
* @return Whether or not to enclose the nested operator in round brackets.
59+
*/
60+
private static EncloseInRoundBrackets nestedOperatorRequiresRoundBrackets(CtExpression<?> nestedOperator) {
61+
if (nestedOperator.getParent() instanceof CtUnaryOperator) {
62+
return EncloseInRoundBrackets.YES;
63+
}
6464

65-
OperatorHelper.OperatorAssociativity associativity = getOperatorAssociativity(nestedOperator);
66-
OperatorHelper.OperatorAssociativity positionInParent = getPositionInParent(nestedOperator);
65+
OperatorHelper.OperatorAssociativity associativity = getOperatorAssociativity(nestedOperator);
66+
OperatorHelper.OperatorAssociativity positionInParent = getPositionInParent(nestedOperator);
6767

68-
int parentPrecedence = getOperatorPrecedence(nestedOperator.getParent());
69-
int precedence = getOperatorPrecedence(nestedOperator);
70-
return precedence < parentPrecedence
71-
|| (precedence == parentPrecedence && associativity != positionInParent)
72-
? EncloseInRoundBrackets.YES
73-
: EncloseInRoundBrackets.NO;
74-
}
68+
int parentPrecedence = getOperatorPrecedence(nestedOperator.getParent());
69+
int precedence = getOperatorPrecedence(nestedOperator);
70+
return precedence < parentPrecedence
71+
|| (precedence == parentPrecedence && associativity != positionInParent)
72+
? EncloseInRoundBrackets.YES
73+
: EncloseInRoundBrackets.NO;
74+
}
7575

76-
private static boolean isNestedOperator(CtElement e) {
77-
return e.isParentInitialized() && isOperator(e) && isOperator(e.getParent());
78-
}
76+
private static boolean isNestedOperator(CtElement e) {
77+
return e.isParentInitialized() && isOperator(e) && isOperator(e.getParent());
78+
}
7979

80-
private static boolean isOperator(CtElement e) {
81-
return e instanceof CtBinaryOperator || e instanceof CtUnaryOperator;
82-
}
80+
private static boolean isOperator(CtElement e) {
81+
return e instanceof CtBinaryOperator || e instanceof CtUnaryOperator;
82+
}
8383

84-
private static int getOperatorPrecedence(CtElement e) {
85-
if (e instanceof CtBinaryOperator) {
86-
return OperatorHelper.getOperatorPrecedence(((CtBinaryOperator<?>) e).getKind());
87-
} else if (e instanceof CtUnaryOperator) {
88-
return OperatorHelper.getOperatorPrecedence(((CtUnaryOperator<?>) e).getKind());
89-
} else {
90-
return 0;
91-
}
92-
}
84+
private static int getOperatorPrecedence(CtElement e) {
85+
if (e instanceof CtBinaryOperator) {
86+
return OperatorHelper.getOperatorPrecedence(((CtBinaryOperator<?>) e).getKind());
87+
} else if (e instanceof CtUnaryOperator) {
88+
return OperatorHelper.getOperatorPrecedence(((CtUnaryOperator<?>) e).getKind());
89+
} else {
90+
return 0;
91+
}
92+
}
9393

94-
private static OperatorHelper.OperatorAssociativity getOperatorAssociativity(CtElement e) {
95-
if (e instanceof CtBinaryOperator) {
96-
return OperatorHelper.getOperatorAssociativity(((CtBinaryOperator<?>) e).getKind());
97-
} else if (e instanceof CtUnaryOperator) {
98-
return OperatorHelper.getOperatorAssociativity(((CtUnaryOperator<?>) e).getKind());
99-
} else {
100-
return OperatorHelper.OperatorAssociativity.NONE;
101-
}
102-
}
94+
private static OperatorHelper.OperatorAssociativity getOperatorAssociativity(CtElement e) {
95+
if (e instanceof CtBinaryOperator) {
96+
return OperatorHelper.getOperatorAssociativity(((CtBinaryOperator<?>) e).getKind());
97+
} else if (e instanceof CtUnaryOperator) {
98+
return OperatorHelper.getOperatorAssociativity(((CtUnaryOperator<?>) e).getKind());
99+
} else {
100+
return OperatorHelper.OperatorAssociativity.NONE;
101+
}
102+
}
103103

104-
private static OperatorHelper.OperatorAssociativity getPositionInParent(CtElement e) {
105-
CtElement parent = e.getParent();
106-
if (parent instanceof CtBinaryOperator) {
107-
return ((CtBinaryOperator<?>) parent).getLeftHandOperand() == e
108-
? OperatorHelper.OperatorAssociativity.LEFT
109-
: OperatorHelper.OperatorAssociativity.RIGHT;
110-
} else {
111-
return OperatorHelper.OperatorAssociativity.NONE;
112-
}
113-
}
104+
private static OperatorHelper.OperatorAssociativity getPositionInParent(CtElement e) {
105+
CtElement parent = e.getParent();
106+
if (parent instanceof CtBinaryOperator) {
107+
return ((CtBinaryOperator<?>) parent).getLeftHandOperand() == e
108+
? OperatorHelper.OperatorAssociativity.LEFT
109+
: OperatorHelper.OperatorAssociativity.RIGHT;
110+
} else {
111+
return OperatorHelper.OperatorAssociativity.NONE;
112+
}
113+
}
114114
}

0 commit comments

Comments
 (0)