We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e931a9 commit d11d362Copy full SHA for d11d362
3 files changed
packages/prettier-plugin-java/src/printers/helpers.ts
@@ -249,14 +249,16 @@ export function printArrayInitializer<
249
T extends JavaNonTerminal,
250
P extends IterProperties<T["children"]>
251
>(path: AstPath<T>, print: JavaPrintFn, options: JavaParserOptions, child: P) {
252
- const list: Doc[] = [];
253
- if (child && child in path.node.children) {
254
- list.push(call(path, print, child));
255
- if (options.trailingComma !== "none") {
256
- list.push(ifBreak(","));
257
- }
+ if (!(child && child in path.node.children)) {
+ const danglingComments = printDanglingComments(path);
+ return danglingComments.length
+ ? ["{", indent([hardline, ...danglingComments]), hardline, "}"]
+ : "{}";
+ }
258
+ const list = [call(path, print, child)];
259
+ if (options.trailingComma !== "none") {
260
+ list.push(ifBreak(","));
261
}
- list.push(...printDanglingComments(path));
262
return list.length ? group(["{", indent([line, ...list]), line, "}"]) : "{}";
263
264
packages/prettier-plugin-java/test/unit-test/arrays/_input.java
@@ -4,4 +4,8 @@ class Array {
4
Class<?> aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa<Bbbbbbbbbbbbbbbb>[1].getClass();
5
Class<?> aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[1111111111111111111].getClass();
6
Class<?> aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[]{ new Aaaaaaaaaaaaaaaa() }.getClass();
7
+
8
+ String[] DATA = {
9
+ // nothing yet
10
+ };
11
packages/prettier-plugin-java/test/unit-test/arrays/_output.java
@@ -10,4 +10,8 @@ class Array {
Class<?> aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[] {
new Aaaaaaaaaaaaaaaa(),
12
}.getClass();
13
14
15
16
17
0 commit comments