diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index c0f645654..af4e8c570 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -3190,7 +3190,13 @@ private static boolean expressionsAreParallel( if (column >= row.size()) { continue; } - nodeTypes.add(row.get(column).getKind()); + // Treat UnaryTree expressions as their underlying type for the comparison (so, for example + // -ve and +ve numeric literals are considered the same). + if (row.get(column) instanceof UnaryTree) { + nodeTypes.add(((UnaryTree) row.get(column)).getExpression().getKind()); + } else { + nodeTypes.add(row.get(column).getKind()); + } } for (Multiset.Entry nodeType : nodeTypes.entrySet()) { if (nodeType.getCount() >= atLeastM) { diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.input new file mode 100644 index 000000000..2715158b1 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.input @@ -0,0 +1,17 @@ +public class T { + private static final double[] f = { + 95.0, 75.0, -95.0, 75.0, + -95.0, 75.0, +95.0, 75.0 + }; + + private static final int[] g = { + x++, y, ++z, + x, y, ~z, + --x, ++y, z-- + }; + + private static final bool[] h = { + a, b, c, d, + !e, a, b, c + }; +} diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.output new file mode 100644 index 000000000..2715158b1 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/TabularMixedSignInitializer.output @@ -0,0 +1,17 @@ +public class T { + private static final double[] f = { + 95.0, 75.0, -95.0, 75.0, + -95.0, 75.0, +95.0, 75.0 + }; + + private static final int[] g = { + x++, y, ++z, + x, y, ~z, + --x, ++y, z-- + }; + + private static final bool[] h = { + a, b, c, d, + !e, a, b, c + }; +}