File tree 3 files changed +58
-2
lines changed
main/java/com/google/googlejavaformat/java
test/resources/com/google/googlejavaformat/java/testdata 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -471,7 +471,7 @@ public boolean visitArrayInitializer(List<? extends ExpressionTree> expressions)
471
471
if (!first ) {
472
472
builder .forcedBreak ();
473
473
}
474
- builder .open (row .iterator ().next ().getKind () == NEW_ARRAY ? ZERO : plusFour );
474
+ builder .open (row .iterator ().next ().getKind () == NEW_ARRAY || cols == 1 ? ZERO : plusFour );
475
475
boolean firstInRow = true ;
476
476
for (ExpressionTree item : row ) {
477
477
if (!firstInRow ) {
@@ -2889,7 +2889,10 @@ private int argumentsAreTabular(List<? extends ExpressionTree> arguments) {
2889
2889
while (it .hasNext () && actualColumn (it .peek ()) > start0 ) {
2890
2890
row .add (it .next ());
2891
2891
}
2892
- if (!it .hasNext () || row .size () == 1 ) {
2892
+ if (!it .hasNext ()) {
2893
+ return -1 ;
2894
+ }
2895
+ if (rowLength (row ) <= 1 ) {
2893
2896
return -1 ;
2894
2897
}
2895
2898
rows .add (row );
@@ -2934,6 +2937,23 @@ private int argumentsAreTabular(List<? extends ExpressionTree> arguments) {
2934
2937
return size0 ;
2935
2938
}
2936
2939
2940
+ static int rowLength (List <? extends ExpressionTree > row ) {
2941
+ int size = 0 ;
2942
+ for (ExpressionTree tree : row ) {
2943
+ if (tree .getKind () != NEW_ARRAY ) {
2944
+ size ++;
2945
+ continue ;
2946
+ }
2947
+ NewArrayTree array = (NewArrayTree ) tree ;
2948
+ if (array .getInitializers () == null ) {
2949
+ size ++;
2950
+ continue ;
2951
+ }
2952
+ size += rowLength (array .getInitializers ());
2953
+ }
2954
+ return size ;
2955
+ }
2956
+
2937
2957
private Integer actualColumn (ExpressionTree expression ) {
2938
2958
Map <Integer , Integer > positionToColumnMap = builder .getInput ().getPositionToColumnMap ();
2939
2959
return positionToColumnMap .get (builder .actualStartColumn (getStartPosition (expression )));
Original file line number Diff line number Diff line change
1
+ class B37895033 {
2
+ String[][] xs =
3
+ new String[][] {
4
+ {"B3", "C3", "D3"},
5
+ {"B4", "C4", "D4"},
6
+ {"B5", "C5", "D5"}
7
+ };
8
+ String[] ys =
9
+ new String[] {
10
+ "B3",
11
+ "B4",
12
+ "B5",
13
+ };
14
+ String[][] zs =
15
+ new String[][] {
16
+ {"B3"},
17
+ {"B4"},
18
+ {"B5"},
19
+ };
20
+ }
Original file line number Diff line number Diff line change
1
+ class B37895033 {
2
+ String[][] xs =
3
+ new String[][] {
4
+ {"B3", "C3", "D3"},
5
+ {"B4", "C4", "D4"},
6
+ {"B5", "C5", "D5"}
7
+ };
8
+ String[] ys =
9
+ new String[] {
10
+ "B3", "B4", "B5",
11
+ };
12
+ String[][] zs =
13
+ new String[][] {
14
+ {"B3"}, {"B4"}, {"B5"},
15
+ };
16
+ }
You can’t perform that action at this time.
0 commit comments