Skip to content

Commit 1760d93

Browse files
authored
Merge pull request #69 from openjavaformat/tabular-mixed-sign-initializer
Keep a tabular array initializer with mixed signs in rows
2 parents 2c63af6 + f4bf910 commit 1760d93

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,7 +3483,13 @@ private static boolean expressionsAreParallel(List<List<ExpressionTree>> rows, i
34833483
if (column >= row.size()) {
34843484
continue;
34853485
}
3486-
nodeTypes.add(row.get(column).getKind());
3486+
// Treat UnaryTree expressions as their underlying type for the comparison (so, for example
3487+
// -ve and +ve numeric literals are considered the same).
3488+
if (row.get(column) instanceof UnaryTree) {
3489+
nodeTypes.add(((UnaryTree) row.get(column)).getExpression().getKind());
3490+
} else {
3491+
nodeTypes.add(row.get(column).getKind());
3492+
}
34873493
}
34883494
for (Multiset.Entry<Tree.Kind> nodeType : nodeTypes.entrySet()) {
34893495
if (nodeType.getCount() >= atLeastM) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class T {
2+
private static final double[] f = {
3+
95.0, 75.0, -95.0, 75.0,
4+
-95.0, 75.0, +95.0, 75.0
5+
};
6+
7+
private static final int[] g = {
8+
x++, y, ++z,
9+
x, y, ~z,
10+
--x, ++y, z--
11+
};
12+
13+
private static final bool[] h = {
14+
a, b, c, d,
15+
!e, a, b, c
16+
};
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class T {
2+
private static final double[] f = {
3+
95.0, 75.0, -95.0, 75.0,
4+
-95.0, 75.0, +95.0, 75.0
5+
};
6+
7+
private static final int[] g = {
8+
x++, y, ++z,
9+
x, y, ~z,
10+
--x, ++y, z--
11+
};
12+
13+
private static final bool[] h = {
14+
a, b, c, d,
15+
!e, a, b, c
16+
};
17+
}

0 commit comments

Comments
 (0)