prettier-plugin-java 2.6.8 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/comments.d.ts +17 -0
  2. package/dist/comments.js +199 -0
  3. package/dist/index.d.ts +543 -0
  4. package/dist/index.js +26 -63
  5. package/dist/options.d.ts +23 -0
  6. package/dist/options.js +247 -239
  7. package/dist/parser.d.ts +9 -0
  8. package/dist/parser.js +24 -4
  9. package/dist/printer.d.ts +18 -0
  10. package/dist/printer.js +39 -5
  11. package/dist/printers/arrays.d.ts +9 -0
  12. package/dist/printers/arrays.js +8 -24
  13. package/dist/printers/blocks-and-statements.d.ts +117 -0
  14. package/dist/printers/blocks-and-statements.js +316 -412
  15. package/dist/printers/classes.d.ts +157 -0
  16. package/dist/printers/classes.js +422 -685
  17. package/dist/printers/expressions.d.ts +134 -0
  18. package/dist/printers/expressions.js +549 -555
  19. package/dist/printers/helpers.d.ts +71 -0
  20. package/dist/printers/helpers.js +233 -0
  21. package/dist/printers/index.d.ts +2 -0
  22. package/dist/printers/index.js +13 -0
  23. package/dist/printers/interfaces.d.ts +62 -0
  24. package/dist/printers/interfaces.js +146 -211
  25. package/dist/printers/lexical-structure.d.ts +14 -0
  26. package/dist/printers/lexical-structure.js +26 -28
  27. package/dist/printers/names.d.ts +12 -0
  28. package/dist/printers/names.js +11 -29
  29. package/dist/printers/packages-and-modules.d.ts +46 -0
  30. package/dist/printers/packages-and-modules.js +157 -159
  31. package/dist/printers/types-values-and-variables.d.ts +46 -0
  32. package/dist/printers/types-values-and-variables.js +86 -149
  33. package/package.json +5 -8
  34. package/dist/base-cst-printer.js +0 -55
  35. package/dist/cst-printer.js +0 -29
  36. package/dist/printers/comments/comments-utils.js +0 -21
  37. package/dist/printers/comments/format-comments.js +0 -171
  38. package/dist/printers/comments/handle-comments.js +0 -102
  39. package/dist/printers/prettier-builder.js +0 -45
  40. package/dist/printers/printer-utils.js +0 -598
  41. package/dist/types/utils.js +0 -20
  42. package/dist/utils/index.js +0 -2
  43. package/dist/utils/isEmptyDoc.js +0 -4
  44. package/dist/utils/printArgumentListWithBraces.js +0 -37
  45. package/index.d.ts +0 -4
@@ -1,709 +1,446 @@
1
- import forEach from "lodash/forEach.js";
2
- import { displaySemicolon, getBlankLinesSeparator, getClassBodyDeclarationsSeparator, isStatementEmptyStatement, putIntoBraces, reject, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortClassTypeChildren, sortModifiers } from "./printer-utils.js";
3
- import { concat, group, indent, join, indentIfBreak } from "./prettier-builder.js";
4
- import { printTokenWithComments } from "./comments/format-comments.js";
5
- import { hasLeadingComments, hasLeadingLineComments } from "./comments/comments-utils.js";
6
- import { handleCommentsParameters } from "./comments/handle-comments.js";
7
1
  import { builders } from "prettier/doc";
8
- import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
9
- import { isAnnotationCstNode, isTypeArgumentsCstNode } from "../types/utils.js";
10
- import { printArgumentListWithBraces } from "../utils/index.js";
11
- const { line, softline, hardline, lineSuffixBoundary } = builders;
12
- export class ClassesPrettierVisitor extends BaseCstPrettierPrinter {
13
- classDeclaration(ctx) {
14
- const modifiers = sortModifiers(ctx.classModifier);
15
- const firstAnnotations = this.mapVisit(modifiers[0]);
16
- const otherModifiers = this.mapVisit(modifiers[1]);
17
- let classCST;
18
- if (ctx.normalClassDeclaration !== undefined) {
19
- classCST = ctx.normalClassDeclaration;
20
- }
21
- else if (ctx.enumDeclaration !== undefined) {
22
- classCST = ctx.enumDeclaration;
2
+ import { call, each, hasDeclarationAnnotations, hasLeadingComments, indentInParentheses, isBinaryExpression, lineEndWithComments, lineStartWithComments, map, onlyDefinedKey, printBlock, printClassPermits, printClassType, printDanglingComments, printList, printSingle, printWithModifiers } from "./helpers.js";
3
+ const { group, hardline, indent, indentIfBreak, join, line, softline } = builders;
4
+ export default {
5
+ classDeclaration(path, print) {
6
+ const declarationKey = onlyDefinedKey(path.node.children, [
7
+ "enumDeclaration",
8
+ "normalClassDeclaration",
9
+ "recordDeclaration"
10
+ ]);
11
+ const declaration = call(path, print, declarationKey);
12
+ return printWithModifiers(path, print, "classModifier", declaration, true);
13
+ },
14
+ normalClassDeclaration(path, print) {
15
+ const { classExtends, classImplements, classPermits, typeParameters } = path.node.children;
16
+ const header = ["class ", call(path, print, "typeIdentifier")];
17
+ if (typeParameters) {
18
+ header.push(call(path, print, "typeParameters"));
23
19
  }
24
- else {
25
- classCST = ctx.recordDeclaration;
20
+ if (classExtends) {
21
+ header.push(indent([line, call(path, print, "classExtends")]));
22
+ }
23
+ if (classImplements) {
24
+ header.push(indent([line, call(path, print, "classImplements")]));
25
+ }
26
+ if (classPermits) {
27
+ header.push(indent([line, call(path, print, "classPermits")]));
26
28
  }
27
- const classDoc = this.visit(classCST);
28
- return rejectAndJoin(hardline, [
29
- rejectAndJoin(hardline, firstAnnotations),
30
- rejectAndJoin(" ", [join(" ", otherModifiers), classDoc])
29
+ return [group(header), " ", call(path, print, "classBody")];
30
+ },
31
+ classModifier: printSingle,
32
+ typeParameters(path, print) {
33
+ return group([
34
+ "<",
35
+ indent([softline, call(path, print, "typeParameterList")]),
36
+ softline,
37
+ ">"
31
38
  ]);
32
- }
33
- normalClassDeclaration(ctx) {
34
- const name = this.visit(ctx.typeIdentifier);
35
- const optionalTypeParams = this.visit(ctx.typeParameters);
36
- const optionalClassExtends = this.visit(ctx.classExtends);
37
- const optionalClassImplements = this.visit(ctx.classImplements);
38
- const optionalClassPermits = this.visit(ctx.classPermits);
39
- const body = this.visit(ctx.classBody, { isNormalClassDeclaration: true });
40
- let superClassesPart = "";
41
- if (optionalClassExtends) {
42
- superClassesPart = indent(rejectAndConcat([line, optionalClassExtends]));
43
- }
44
- let superInterfacesPart = "";
45
- if (optionalClassImplements) {
46
- superInterfacesPart = indent(rejectAndConcat([line, optionalClassImplements]));
47
- }
48
- let classPermits = "";
49
- if (optionalClassPermits) {
50
- classPermits = indent(rejectAndConcat([line, optionalClassPermits]));
51
- }
52
- return rejectAndJoin(" ", [
53
- group(rejectAndConcat([
54
- rejectAndJoin(" ", [ctx.Class[0], name]),
55
- optionalTypeParams,
56
- superClassesPart,
57
- superInterfacesPart,
58
- classPermits
59
- ])),
60
- body
39
+ },
40
+ typeParameterList(path, print) {
41
+ return printList(path, print, "typeParameter");
42
+ },
43
+ classExtends(path, print) {
44
+ return ["extends ", call(path, print, "classType")];
45
+ },
46
+ classImplements(path, print) {
47
+ return group([
48
+ "implements",
49
+ indent([line, call(path, print, "interfaceTypeList")])
61
50
  ]);
62
- }
63
- classModifier(ctx) {
64
- if (ctx.annotation) {
65
- return this.visit(ctx.annotation);
66
- }
67
- // public | protected | private | ...
68
- return printTokenWithComments(this.getSingle(ctx));
69
- }
70
- typeParameters(ctx) {
71
- const typeParameterList = this.visit(ctx.typeParameterList);
72
- return putIntoBraces(typeParameterList, softline, ctx.Less[0], ctx.Greater[0]);
73
- }
74
- typeParameterList(ctx) {
75
- const typeParameter = this.mapVisit(ctx.typeParameter);
76
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
77
- return group(rejectAndJoinSeps(commas, typeParameter));
78
- }
79
- classExtends(ctx) {
80
- return join(" ", [ctx.Extends[0], this.visit(ctx.classType)]);
81
- }
82
- classImplements(ctx) {
83
- const interfaceTypeList = this.visit(ctx.interfaceTypeList);
84
- return group(rejectAndConcat([
85
- ctx.Implements[0],
86
- indent(rejectAndConcat([line, interfaceTypeList]))
87
- ]));
88
- }
89
- classPermits(ctx) {
90
- const typeNames = this.mapVisit(ctx.typeName);
91
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
92
- return group(rejectAndConcat([
93
- ctx.Permits[0],
94
- indent(rejectAndConcat([line, group(rejectAndJoinSeps(commas, typeNames))]))
95
- ]));
96
- }
97
- interfaceTypeList(ctx) {
98
- const interfaceType = this.mapVisit(ctx.interfaceType);
99
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
100
- return group(rejectAndJoinSeps(commas, interfaceType));
101
- }
102
- classBody(ctx, param) {
103
- let content = "";
104
- if (ctx.classBodyDeclaration !== undefined) {
105
- const classBodyDeclsVisited = reject(this.mapVisit(ctx.classBodyDeclaration));
106
- const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
107
- content = rejectAndJoinSeps(separators, classBodyDeclsVisited);
108
- // edge case when we have SemiColons
109
- let shouldHardline = false;
110
- ctx.classBodyDeclaration.forEach(elt => {
111
- if ((elt.children.classMemberDeclaration &&
112
- !elt.children.classMemberDeclaration[0].children.Semicolon) ||
113
- elt.children.constructorDeclaration) {
114
- shouldHardline = true;
115
- }
116
- });
117
- if ((ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
118
- ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
119
- shouldHardline &&
120
- param &&
121
- param.isNormalClassDeclaration) {
122
- content = rejectAndConcat([hardline, content]);
123
- }
51
+ },
52
+ classPermits: printClassPermits,
53
+ interfaceTypeList(path, print) {
54
+ return group(printList(path, print, "interfaceType"));
55
+ },
56
+ classBody(path, print) {
57
+ return printBlock(path, printClassBodyDeclarations(path, print));
58
+ },
59
+ classBodyDeclaration: printSingle,
60
+ classMemberDeclaration(path, print) {
61
+ const { children } = path.node;
62
+ return children.Semicolon
63
+ ? ""
64
+ : call(path, print, onlyDefinedKey(children));
65
+ },
66
+ fieldDeclaration(path, print) {
67
+ const declaration = [
68
+ call(path, print, "unannType"),
69
+ " ",
70
+ call(path, print, "variableDeclaratorList"),
71
+ ";"
72
+ ];
73
+ return printWithModifiers(path, print, "fieldModifier", declaration);
74
+ },
75
+ fieldModifier: printSingle,
76
+ variableDeclaratorList(path, print) {
77
+ var _a;
78
+ const declarators = map(path, print, "variableDeclarator");
79
+ return declarators.length > 1 &&
80
+ path.node.children.variableDeclarator.some(({ children }) => children.Equals)
81
+ ? group(indent(join([",", line], declarators)), {
82
+ shouldBreak: ((_a = path.getNode(4)) === null || _a === void 0 ? void 0 : _a.name) !== "forInit"
83
+ })
84
+ : join(", ", declarators);
85
+ },
86
+ variableDeclarator(path, print) {
87
+ var _a, _b;
88
+ const { children } = path.node;
89
+ const variableInitializer = (_a = children.variableInitializer) === null || _a === void 0 ? void 0 : _a[0];
90
+ const declaratorId = call(path, print, "variableDeclaratorId");
91
+ if (!variableInitializer) {
92
+ return declaratorId;
124
93
  }
125
- return putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]);
126
- }
127
- classBodyDeclaration(ctx) {
128
- return this.visitSingle(ctx);
129
- }
130
- classMemberDeclaration(ctx) {
131
- if (ctx.Semicolon) {
132
- return displaySemicolon(ctx.Semicolon[0]);
94
+ const expression = (_b = variableInitializer.children.expression) === null || _b === void 0 ? void 0 : _b[0];
95
+ const declarator = [declaratorId, " ", call(path, print, "Equals")];
96
+ const initializer = call(path, print, "variableInitializer");
97
+ if (hasLeadingComments(variableInitializer) ||
98
+ (expression && isBinaryExpression(expression))) {
99
+ declarator.push(group(indent([line, initializer])));
133
100
  }
134
- return this.visitSingle(ctx);
135
- }
136
- fieldDeclaration(ctx) {
137
- const modifiers = sortModifiers(ctx.fieldModifier);
138
- const firstAnnotations = this.mapVisit(modifiers[0]);
139
- const otherModifiers = this.mapVisit(modifiers[1]);
140
- const unannType = this.visit(ctx.unannType);
141
- const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
142
- return rejectAndJoin(hardline, [
143
- rejectAndJoin(hardline, firstAnnotations),
144
- rejectAndJoin(" ", [
145
- rejectAndJoin(" ", otherModifiers),
146
- unannType,
147
- concat([variableDeclaratorList, ctx.Semicolon[0]])
148
- ])
149
- ]);
150
- }
151
- fieldModifier(ctx) {
152
- if (ctx.annotation) {
153
- return this.visit(ctx.annotation);
101
+ else {
102
+ const groupId = Symbol("assignment");
103
+ declarator.push(group(indent(line), { id: groupId }), indentIfBreak(initializer, { groupId }));
154
104
  }
155
- // public | protected | private | ...
156
- return printTokenWithComments(this.getSingle(ctx));
157
- }
158
- variableDeclaratorList(ctx) {
159
- const variableDeclarators = this.mapVisit(ctx.variableDeclarator);
160
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : [];
161
- return rejectAndJoinSeps(commas, variableDeclarators);
162
- }
163
- variableDeclarator(ctx) {
164
- const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
165
- if (ctx.Equals) {
166
- const variableInitializer = this.visit(ctx.variableInitializer);
167
- if (hasLeadingLineComments(ctx.variableInitializer[0])) {
168
- return group(indent(rejectAndJoin(hardline, [
169
- rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
170
- variableInitializer
171
- ])));
172
- }
173
- if (
174
- // Array Initialisation
175
- ctx.variableInitializer[0].children.arrayInitializer !== undefined ||
176
- // Lambda expression
177
- ctx.variableInitializer[0].children.expression[0].children
178
- .lambdaExpression !== undefined ||
179
- // Ternary Expression
180
- (ctx.variableInitializer[0].children.expression[0].children
181
- .conditionalExpression !== undefined &&
182
- ctx.variableInitializer[0].children.expression[0].children
183
- .conditionalExpression[0].children.QuestionMark !== undefined)) {
184
- const groupId = Symbol("assignment");
185
- return group([
186
- group(variableDeclaratorId),
187
- " ",
188
- ctx.Equals[0],
189
- group(indent(line), { id: groupId }),
190
- lineSuffixBoundary,
191
- indentIfBreak(variableInitializer, { groupId })
192
- ]);
193
- }
194
- if (ctx.variableInitializer[0].children.expression[0].children
195
- .conditionalExpression !== undefined) {
196
- const unaryExpressions = ctx.variableInitializer[0].children.expression[0].children
197
- .conditionalExpression[0].children.binaryExpression[0].children
198
- .unaryExpression;
199
- const firstPrimary = unaryExpressions[0].children.primary[0];
200
- // Cast Expression
201
- if (firstPrimary.children.primaryPrefix[0].children.castExpression !==
202
- undefined &&
203
- unaryExpressions.length === 1) {
204
- const groupId = Symbol("assignment");
205
- return group([
206
- group(variableDeclaratorId),
207
- " ",
208
- ctx.Equals[0],
209
- group(indent(line), { id: groupId }),
210
- lineSuffixBoundary,
211
- indentIfBreak(variableInitializer, { groupId })
212
- ]);
213
- }
214
- // New Expression
215
- if (firstPrimary.children.primaryPrefix[0].children.newExpression !==
216
- undefined) {
217
- const groupId = Symbol("assignment");
218
- return group([
219
- group(variableDeclaratorId),
220
- " ",
221
- ctx.Equals[0],
222
- group(indent(line), { id: groupId }),
223
- lineSuffixBoundary,
224
- indentIfBreak(variableInitializer, { groupId })
225
- ]);
226
- }
227
- // Method Invocation
228
- const isMethodInvocation = firstPrimary.children.primarySuffix !== undefined &&
229
- firstPrimary.children.primarySuffix[0].children
230
- .methodInvocationSuffix !== undefined;
231
- const isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children
232
- .conditionalExpression[0].children.binaryExpression[0].children
233
- .unaryExpression.length === 1;
234
- const isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression;
235
- if (isUniqueMethodInvocation) {
236
- const groupId = Symbol("assignment");
237
- return group([
238
- group(variableDeclaratorId),
239
- " ",
240
- ctx.Equals[0],
241
- group(indent(line), { id: groupId }),
242
- lineSuffixBoundary,
243
- indentIfBreak(variableInitializer, { groupId })
244
- ]);
245
- }
246
- }
247
- return group(indent(rejectAndJoin(line, [
248
- rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
249
- variableInitializer
250
- ])));
105
+ return group(declarator);
106
+ },
107
+ variableDeclaratorId(path, print) {
108
+ const { dims, Underscore } = path.node.children;
109
+ if (Underscore) {
110
+ return "_";
251
111
  }
252
- return variableDeclaratorId;
253
- }
254
- variableDeclaratorId(ctx) {
255
- if (ctx.Underscore) {
256
- return printTokenWithComments(ctx.Underscore[0]);
112
+ const identifier = call(path, print, "Identifier");
113
+ return dims ? [identifier, call(path, print, "dims")] : identifier;
114
+ },
115
+ variableInitializer: printSingle,
116
+ unannType: printSingle,
117
+ unannPrimitiveTypeWithOptionalDimsSuffix(path, print) {
118
+ const type = call(path, print, "unannPrimitiveType");
119
+ return path.node.children.dims ? [type, call(path, print, "dims")] : type;
120
+ },
121
+ unannPrimitiveType: printSingle,
122
+ unannReferenceType(path, print) {
123
+ const type = call(path, print, "unannClassOrInterfaceType");
124
+ return path.node.children.dims ? [type, call(path, print, "dims")] : type;
125
+ },
126
+ unannClassOrInterfaceType: printSingle,
127
+ unannClassType: printClassType,
128
+ unannInterfaceType: printSingle,
129
+ unannTypeVariable: printSingle,
130
+ methodDeclaration(path, print) {
131
+ const declaration = [
132
+ call(path, print, "methodHeader"),
133
+ path.node.children.methodBody[0].children.Semicolon ? "" : " ",
134
+ call(path, print, "methodBody")
135
+ ];
136
+ return printWithModifiers(path, print, "methodModifier", declaration);
137
+ },
138
+ methodModifier: printSingle,
139
+ methodHeader(path, print) {
140
+ const { typeParameters, annotation, throws } = path.node.children;
141
+ const header = [];
142
+ if (typeParameters) {
143
+ header.push(call(path, print, "typeParameters"));
257
144
  }
258
- const identifier = ctx.Identifier[0];
259
- const dims = this.visit(ctx.dims);
260
- return rejectAndConcat([identifier, dims]);
261
- }
262
- variableInitializer(ctx) {
263
- return this.visitSingle(ctx);
264
- }
265
- unannType(ctx) {
266
- return this.visitSingle(ctx);
267
- }
268
- unannPrimitiveTypeWithOptionalDimsSuffix(ctx) {
269
- const unannPrimitiveType = this.visit(ctx.unannPrimitiveType);
270
- const dims = this.visit(ctx.dims);
271
- return rejectAndConcat([unannPrimitiveType, dims]);
272
- }
273
- unannPrimitiveType(ctx) {
274
- if (ctx.numericType) {
275
- return this.visitSingle(ctx);
145
+ if (annotation) {
146
+ header.push(join(line, map(path, print, "annotation")));
276
147
  }
277
- return printTokenWithComments(this.getSingle(ctx));
278
- }
279
- unannReferenceType(ctx) {
280
- const unannClassOrInterfaceType = this.visit(ctx.unannClassOrInterfaceType);
281
- const dims = this.visit(ctx.dims);
282
- return rejectAndConcat([unannClassOrInterfaceType, dims]);
283
- }
284
- unannClassOrInterfaceType(ctx) {
285
- return this.visit(ctx.unannClassType);
286
- }
287
- unannClassType(ctx) {
288
- const tokens = sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier);
289
- const segments = [];
290
- let currentSegment = [];
291
- forEach(tokens, (token, i) => {
292
- if (isTypeArgumentsCstNode(token)) {
293
- currentSegment.push(this.visit([token]));
294
- segments.push(rejectAndConcat(currentSegment));
295
- currentSegment = [];
296
- }
297
- else if (isAnnotationCstNode(token)) {
298
- currentSegment.push(this.visit([token]));
299
- currentSegment.push(" ");
300
- }
301
- else {
302
- currentSegment.push(token);
303
- if ((i + 1 < tokens.length && !isTypeArgumentsCstNode(tokens[i + 1])) ||
304
- i + 1 === tokens.length) {
305
- segments.push(rejectAndConcat(currentSegment));
306
- currentSegment = [];
307
- }
308
- }
309
- });
310
- return rejectAndJoinSeps(ctx.Dot, segments);
311
- }
312
- unannInterfaceType(ctx) {
313
- return this.visit(ctx.unannClassType);
314
- }
315
- unannTypeVariable(ctx) {
316
- return printTokenWithComments(this.getSingle(ctx));
317
- }
318
- methodDeclaration(ctx) {
319
- const modifiers = sortModifiers(ctx.methodModifier);
320
- const firstAnnotations = this.mapVisit(modifiers[0]);
321
- const otherModifiers = this.mapVisit(modifiers[1]);
322
- const header = this.visit(ctx.methodHeader);
323
- const body = this.visit(ctx.methodBody);
324
- const headerBodySeparator = isStatementEmptyStatement(body) ? "" : " ";
325
- return rejectAndJoin(hardline, [
326
- rejectAndJoin(hardline, firstAnnotations),
327
- rejectAndJoin(" ", [
328
- rejectAndJoin(" ", otherModifiers),
329
- rejectAndJoin(headerBodySeparator, [header, body])
148
+ header.push(call(path, print, "result"), call(path, print, "methodDeclarator"));
149
+ return throws
150
+ ? group([
151
+ ...join(" ", header),
152
+ group(indent([line, call(path, print, "throws")]))
330
153
  ])
331
- ]);
332
- }
333
- methodModifier(ctx) {
334
- if (ctx.annotation) {
335
- return this.visit(ctx.annotation);
154
+ : group(join(" ", header));
155
+ },
156
+ result: printSingle,
157
+ methodDeclarator(path, print) {
158
+ const { dims, formalParameterList, receiverParameter } = path.node.children;
159
+ const declarator = [call(path, print, "Identifier")];
160
+ const parameters = [];
161
+ if (receiverParameter) {
162
+ parameters.push(call(path, print, "receiverParameter"));
336
163
  }
337
- // public | protected | private | Synchronized | ...
338
- return printTokenWithComments(this.getSingle(ctx));
339
- }
340
- methodHeader(ctx) {
341
- const typeParameters = this.visit(ctx.typeParameters);
342
- const annotations = this.mapVisit(ctx.annotation);
343
- const result = this.visit(ctx.result);
344
- const declarator = this.visit(ctx.methodDeclarator);
345
- const throws = this.visit(ctx.throws);
346
- return group(concat([
347
- rejectAndJoin(" ", [
348
- typeParameters,
349
- rejectAndJoin(line, annotations),
350
- result,
351
- declarator,
352
- throws
353
- ])
354
- ]));
355
- }
356
- result(ctx) {
357
- if (ctx.unannType) {
358
- return this.visit(ctx.unannType);
164
+ if (formalParameterList) {
165
+ parameters.push(call(path, print, "formalParameterList"));
359
166
  }
360
- // void
361
- return printTokenWithComments(this.getSingle(ctx));
362
- }
363
- methodDeclarator(ctx) {
364
- var _a, _b, _c, _d;
365
- const parameters = [
366
- ...((_a = ctx.receiverParameter) !== null && _a !== void 0 ? _a : []),
367
- ...((_c = (_b = ctx.formalParameterList) === null || _b === void 0 ? void 0 : _b[0].children.formalParameter) !== null && _c !== void 0 ? _c : [])
368
- ];
369
- handleCommentsParameters(ctx.LBrace[0], parameters, ctx.RBrace[0]);
370
- const identifier = printTokenWithComments(ctx.Identifier[0]);
371
- const receiverParameter = this.visit(ctx.receiverParameter);
372
- const formalParameterList = this.visit(ctx.formalParameterList);
373
- const dims = this.visit(ctx.dims);
374
- return rejectAndConcat([
375
- identifier,
376
- putIntoBraces(rejectAndJoin(line, [
377
- rejectAndConcat([receiverParameter, (_d = ctx.Comma) === null || _d === void 0 ? void 0 : _d[0]]),
378
- formalParameterList
379
- ]), softline, ctx.LBrace[0], ctx.RBrace[0]),
380
- dims
167
+ const items = parameters.length
168
+ ? join([",", line], parameters)
169
+ : printDanglingComments(path);
170
+ declarator.push(items.length ? indentInParentheses(items) : "()");
171
+ if (dims) {
172
+ declarator.push(call(path, print, "dims"));
173
+ }
174
+ return declarator;
175
+ },
176
+ receiverParameter(path, print) {
177
+ return join(" ", [
178
+ ...map(path, print, "annotation"),
179
+ call(path, print, "unannType"),
180
+ path.node.children.Identifier
181
+ ? [call(path, print, "Identifier"), ".this"]
182
+ : "this"
381
183
  ]);
382
- }
383
- receiverParameter(ctx) {
384
- var _a, _b;
385
- const annotations = this.mapVisit(ctx.annotation);
386
- const unannType = this.visit(ctx.unannType);
387
- return rejectAndJoin(" ", [
388
- ...annotations,
389
- unannType,
390
- rejectAndConcat([(_a = ctx.Identifier) === null || _a === void 0 ? void 0 : _a[0], (_b = ctx.Dot) === null || _b === void 0 ? void 0 : _b[0], ctx.This[0]])
184
+ },
185
+ formalParameterList(path, print) {
186
+ return printList(path, print, "formalParameter");
187
+ },
188
+ formalParameter: printSingle,
189
+ variableParaRegularParameter(path, print) {
190
+ return join(" ", [
191
+ ...map(path, print, "variableModifier"),
192
+ call(path, print, "unannType"),
193
+ call(path, print, "variableDeclaratorId")
391
194
  ]);
392
- }
393
- formalParameterList(ctx) {
394
- const formalParameter = this.mapVisit(ctx.formalParameter);
395
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
396
- return rejectAndJoinSeps(commas, formalParameter);
397
- }
398
- formalParameter(ctx) {
399
- return this.visitSingle(ctx);
400
- }
401
- variableParaRegularParameter(ctx) {
402
- const variableModifier = this.mapVisit(ctx.variableModifier);
403
- const unannType = this.visit(ctx.unannType);
404
- const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
405
- return rejectAndJoin(" ", [
406
- rejectAndJoin(" ", variableModifier),
407
- unannType,
408
- variableDeclaratorId
409
- ]);
410
- }
411
- variableArityParameter(ctx) {
412
- const variableModifier = this.mapVisit(ctx.variableModifier);
413
- const unannType = this.visit(ctx.unannType);
414
- const annotations = this.mapVisit(ctx.annotation);
415
- const identifier = ctx.Identifier[0];
416
- const unannTypePrinted = ctx.annotation === undefined
417
- ? concat([unannType, ctx.DotDotDot[0]])
418
- : unannType;
419
- const annotationsPrinted = ctx.annotation === undefined
420
- ? annotations
421
- : concat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]);
422
- return rejectAndJoin(" ", [
423
- join(" ", variableModifier),
424
- unannTypePrinted,
425
- annotationsPrinted,
426
- identifier
195
+ },
196
+ variableArityParameter(path, print) {
197
+ const type = join(" ", [
198
+ ...map(path, print, "variableModifier"),
199
+ call(path, print, "unannType"),
200
+ ...map(path, print, "annotation")
427
201
  ]);
428
- }
429
- variableModifier(ctx) {
430
- if (ctx.annotation) {
431
- return this.visit(ctx.annotation);
202
+ return [type, "... ", call(path, print, "Identifier")];
203
+ },
204
+ variableModifier: printSingle,
205
+ throws(path, print) {
206
+ return ["throws ", call(path, print, "exceptionTypeList")];
207
+ },
208
+ exceptionTypeList(path, print) {
209
+ return join(", ", map(path, print, "exceptionType"));
210
+ },
211
+ exceptionType: printSingle,
212
+ methodBody: printSingle,
213
+ instanceInitializer: printSingle,
214
+ staticInitializer(path, print) {
215
+ return ["static ", call(path, print, "block")];
216
+ },
217
+ constructorDeclaration(path, print) {
218
+ const declaration = [call(path, print, "constructorDeclarator")];
219
+ if (path.node.children.throws) {
220
+ declaration.push(group(indent([line, call(path, print, "throws")])));
432
221
  }
433
- return printTokenWithComments(this.getSingle(ctx));
434
- }
435
- throws(ctx) {
436
- const exceptionTypeList = this.visit(ctx.exceptionTypeList);
437
- const throwsDeclaration = join(" ", [ctx.Throws[0], exceptionTypeList]);
438
- return group(indent(rejectAndConcat([softline, throwsDeclaration])));
439
- }
440
- exceptionTypeList(ctx) {
441
- const exceptionTypes = this.mapVisit(ctx.exceptionType);
442
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : [];
443
- return rejectAndJoinSeps(commas, exceptionTypes);
444
- }
445
- exceptionType(ctx) {
446
- return this.visitSingle(ctx);
447
- }
448
- methodBody(ctx) {
449
- if (ctx.block) {
450
- return this.visit(ctx.block);
222
+ declaration.push(" ", call(path, print, "constructorBody"));
223
+ return printWithModifiers(path, print, "constructorModifier", declaration, true);
224
+ },
225
+ constructorModifier: printSingle,
226
+ constructorDeclarator(path, print) {
227
+ const { children } = path.node;
228
+ const parameters = [];
229
+ if (children.receiverParameter) {
230
+ parameters.push(call(path, print, "receiverParameter"));
451
231
  }
452
- return printTokenWithComments(this.getSingle(ctx));
453
- }
454
- instanceInitializer(ctx) {
455
- return this.visitSingle(ctx);
456
- }
457
- staticInitializer(ctx) {
458
- const block = this.visit(ctx.block);
459
- return join(" ", [ctx.Static[0], block]);
460
- }
461
- constructorDeclaration(ctx) {
462
- const modifiers = sortModifiers(ctx.constructorModifier);
463
- const firstAnnotations = this.mapVisit(modifiers[0]);
464
- const otherModifiers = this.mapVisit(modifiers[1]);
465
- const constructorDeclarator = this.visit(ctx.constructorDeclarator);
466
- const throws = this.visit(ctx.throws);
467
- const constructorBody = this.visit(ctx.constructorBody);
468
- return rejectAndJoin(" ", [
469
- group(rejectAndJoin(hardline, [
470
- rejectAndJoin(hardline, firstAnnotations),
471
- rejectAndJoin(" ", [
472
- join(" ", otherModifiers),
473
- constructorDeclarator,
474
- throws
475
- ])
476
- ])),
477
- constructorBody
478
- ]);
479
- }
480
- constructorModifier(ctx) {
481
- if (ctx.annotation) {
482
- return this.visit(ctx.annotation);
232
+ if (children.formalParameterList) {
233
+ parameters.push(call(path, print, "formalParameterList"));
483
234
  }
484
- // public | protected | private | Synchronized | ...
485
- return printTokenWithComments(this.getSingle(ctx));
486
- }
487
- constructorDeclarator(ctx) {
488
- var _a, _b, _c, _d;
489
- const parameters = (_c = (_a = ctx.receiverParameter) !== null && _a !== void 0 ? _a : (_b = ctx.formalParameterList) === null || _b === void 0 ? void 0 : _b[0].children.formalParameter) !== null && _c !== void 0 ? _c : [];
490
- handleCommentsParameters(ctx.LBrace[0], parameters, ctx.RBrace[0]);
491
- const typeParameters = this.visit(ctx.typeParameters);
492
- const simpleTypeName = this.visit(ctx.simpleTypeName);
493
- const receiverParameter = this.visit(ctx.receiverParameter);
494
- const formalParameterList = this.visit(ctx.formalParameterList);
495
- return rejectAndJoin(" ", [
496
- typeParameters,
497
- concat([
498
- simpleTypeName,
499
- putIntoBraces(rejectAndJoin(line, [
500
- rejectAndConcat([receiverParameter, (_d = ctx.Comma) === null || _d === void 0 ? void 0 : _d[0]]),
501
- formalParameterList
502
- ]), softline, ctx.LBrace[0], ctx.RBrace[0])
503
- ])
504
- ]);
505
- }
506
- simpleTypeName(ctx) {
507
- return this.visitSingle(ctx);
508
- }
509
- constructorBody(ctx) {
510
- const explicitConstructorInvocation = this.visit(ctx.explicitConstructorInvocation);
511
- const blockStatements = this.visit(ctx.blockStatements);
512
- return putIntoBraces(rejectAndJoin(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
513
- }
514
- explicitConstructorInvocation(ctx) {
515
- return this.visitSingle(ctx);
516
- }
517
- unqualifiedExplicitConstructorInvocation(ctx) {
518
- const typeArguments = this.visit(ctx.typeArguments);
519
- const keyWord = ctx.This ? ctx.This[0] : ctx.Super[0];
520
- const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
521
- return rejectAndConcat([
522
- typeArguments,
523
- keyWord,
524
- group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
525
- ]);
526
- }
527
- qualifiedExplicitConstructorInvocation(ctx) {
528
- const expressionName = this.visit(ctx.expressionName);
529
- const typeArguments = this.visit(ctx.typeArguments);
530
- const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
531
- return rejectAndConcat([
532
- expressionName,
533
- ctx.Dot[0],
534
- typeArguments,
535
- ctx.Super[0],
536
- group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
537
- ]);
538
- }
539
- enumDeclaration(ctx) {
540
- const classModifier = this.mapVisit(ctx.classModifier);
541
- const typeIdentifier = this.visit(ctx.typeIdentifier);
542
- const classImplements = this.visit(ctx.classImplements);
543
- const enumBody = this.visit(ctx.enumBody);
544
- return rejectAndJoin(" ", [
545
- join(" ", classModifier),
546
- ctx.Enum[0],
547
- typeIdentifier,
548
- classImplements,
549
- enumBody
550
- ]);
551
- }
552
- enumBody(ctx) {
553
- const enumConstantList = this.visit(ctx.enumConstantList);
554
- const enumBodyDeclarations = this.visit(ctx.enumBodyDeclarations);
555
- const hasEnumConstants = ctx.enumConstantList !== undefined;
556
- const hasNoClassBodyDeclarations = ctx.enumBodyDeclarations === undefined ||
557
- ctx.enumBodyDeclarations[0].children.classBodyDeclaration === undefined;
558
- // edge case: https://github.com/jhipster/prettier-java/issues/383
559
- const handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations &&
560
- hasLeadingComments(ctx.enumBodyDeclarations[0])
561
- ? hardline
562
- : "";
563
- let optionalComma;
564
- if (hasEnumConstants &&
565
- hasNoClassBodyDeclarations &&
566
- this.prettierOptions.trailingComma !== "none") {
567
- optionalComma = ctx.Comma ? ctx.Comma[0] : ",";
235
+ const header = [call(path, print, "simpleTypeName")];
236
+ header.push(parameters.length
237
+ ? indentInParentheses(join([",", line], parameters))
238
+ : "()");
239
+ return children.typeParameters
240
+ ? [call(path, print, "typeParameters"), " ", ...header]
241
+ : header;
242
+ },
243
+ simpleTypeName: printSingle,
244
+ constructorBody(path, print) {
245
+ const { children } = path.node;
246
+ const statements = [];
247
+ if (children.explicitConstructorInvocation) {
248
+ statements.push(call(path, print, "explicitConstructorInvocation"));
249
+ }
250
+ if (children.blockStatements) {
251
+ statements.push(call(path, print, "blockStatements"));
252
+ }
253
+ return printBlock(path, statements);
254
+ },
255
+ explicitConstructorInvocation: printSingle,
256
+ unqualifiedExplicitConstructorInvocation(path, print) {
257
+ const { children } = path.node;
258
+ const invocation = [];
259
+ if (children.typeArguments) {
260
+ invocation.push(call(path, print, "typeArguments"));
261
+ }
262
+ invocation.push(children.Super ? "super" : "this");
263
+ if (children.argumentList) {
264
+ invocation.push(group(["(", call(path, print, "argumentList"), ")"]));
568
265
  }
569
266
  else {
570
- optionalComma = ctx.Comma ? Object.assign(Object.assign({}, ctx.Comma[0]), { image: "" }) : "";
571
- }
572
- return putIntoBraces(rejectAndConcat([
573
- enumConstantList,
574
- optionalComma,
575
- handleEnumBodyDeclarationsLeadingComments,
576
- enumBodyDeclarations
577
- ]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
578
- }
579
- enumConstantList(ctx) {
580
- const enumConstants = this.mapVisit(ctx.enumConstant);
581
- const blankLineSeparators = getBlankLinesSeparator(ctx.enumConstant);
582
- const commas = ctx.Comma
583
- ? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]]))
584
- : [];
585
- return group(rejectAndJoinSeps(commas, enumConstants));
586
- }
587
- enumConstant(ctx) {
588
- const modifiers = sortModifiers(ctx.enumConstantModifier);
589
- const firstAnnotations = this.mapVisit(modifiers[0]);
590
- const otherModifiers = this.mapVisit(modifiers[1]);
591
- const identifier = ctx.Identifier[0];
592
- const classBody = this.visit(ctx.classBody);
593
- const optionalBracesAndArgumentList = ctx.LBrace
594
- ? printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0])
595
- : "";
596
- return rejectAndJoin(hardline, [
597
- rejectAndJoin(hardline, firstAnnotations),
598
- rejectAndJoin(" ", [
599
- rejectAndJoin(" ", otherModifiers),
600
- rejectAndConcat([identifier, optionalBracesAndArgumentList]),
601
- classBody
602
- ])
603
- ]);
604
- }
605
- enumConstantModifier(ctx) {
606
- return this.visitSingle(ctx);
607
- }
608
- enumBodyDeclarations(ctx) {
609
- if (ctx.classBodyDeclaration !== undefined) {
610
- const classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration);
611
- const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
612
- return rejectAndJoin(concat([hardline, hardline]), [
613
- ctx.Semicolon[0],
614
- rejectAndJoinSeps(separators, classBodyDeclaration)
615
- ]);
616
- }
617
- return printTokenWithComments(Object.assign(Object.assign({}, ctx.Semicolon[0]), { image: "" }));
618
- }
619
- recordDeclaration(ctx) {
620
- const name = this.visit(ctx.typeIdentifier);
621
- const optionalTypeParams = this.visit(ctx.typeParameters);
622
- const recordHeader = this.visit(ctx.recordHeader);
623
- let superInterfacesPart = "";
624
- const optionalClassImplements = this.visit(ctx.classImplements);
625
- if (optionalClassImplements) {
626
- superInterfacesPart = indent(rejectAndConcat([line, optionalClassImplements]));
627
- }
628
- const body = this.visit(ctx.recordBody);
629
- return rejectAndJoin(" ", [
630
- group(rejectAndConcat([
631
- rejectAndJoin(" ", [ctx.Record[0], name]),
632
- optionalTypeParams,
633
- recordHeader,
634
- superInterfacesPart
635
- ])),
636
- body
637
- ]);
638
- }
639
- recordHeader(ctx) {
640
- var _a, _b;
641
- const recordComponents = (_b = (_a = ctx.recordComponentList) === null || _a === void 0 ? void 0 : _a[0].children.recordComponent) !== null && _b !== void 0 ? _b : [];
642
- handleCommentsParameters(ctx.LBrace[0], recordComponents, ctx.RBrace[0]);
643
- const recordComponentList = this.visit(ctx.recordComponentList);
644
- return putIntoBraces(recordComponentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
645
- }
646
- recordComponentList(ctx) {
647
- const recordComponents = this.mapVisit(ctx.recordComponent);
648
- const blankLineSeparators = getBlankLinesSeparator(ctx.recordComponent, line);
649
- const commas = ctx.Comma
650
- ? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]]))
651
- : [];
652
- return rejectAndJoinSeps(commas, recordComponents);
653
- }
654
- recordComponent(ctx) {
655
- const modifiers = this.mapVisit(ctx.recordComponentModifier);
656
- const unannType = this.visit(ctx.unannType);
657
- if (ctx.Identifier !== undefined) {
658
- return group(rejectAndJoin(line, [
659
- join(line, modifiers),
660
- join(" ", [unannType, ctx.Identifier[0]])
661
- ]));
662
- }
663
- const variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent);
664
- if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) {
665
- return group(rejectAndJoin(line, [
666
- join(line, modifiers),
667
- join(" ", [unannType, variableArityRecordComponent])
668
- ]));
669
- }
670
- return group(rejectAndJoin(line, [
671
- join(line, modifiers),
672
- concat([unannType, variableArityRecordComponent])
673
- ]));
674
- }
675
- variableArityRecordComponent(ctx) {
676
- const annotations = this.mapVisit(ctx.annotation);
677
- const identifier = ctx.Identifier[0];
678
- return rejectAndJoin(" ", [
679
- rejectAndConcat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]),
680
- identifier
681
- ]);
682
- }
683
- recordComponentModifier(ctx) {
684
- return this.visitSingle(ctx);
685
- }
686
- recordBody(ctx) {
687
- return putIntoBraces(rejectAndJoinSeps(getBlankLinesSeparator(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]);
688
- }
689
- recordBodyDeclaration(ctx) {
690
- return this.visitSingle(ctx);
691
- }
692
- compactConstructorDeclaration(ctx) {
693
- const modifiers = sortModifiers(ctx.constructorModifier);
694
- const firstAnnotations = this.mapVisit(modifiers[0]);
695
- const otherModifiers = this.mapVisit(modifiers[1]);
696
- const name = this.visit(ctx.simpleTypeName);
697
- const constructorBody = this.visit(ctx.constructorBody);
698
- return rejectAndJoin(" ", [
699
- group(rejectAndJoin(hardline, [
700
- rejectAndJoin(hardline, firstAnnotations),
701
- rejectAndJoin(" ", [join(" ", otherModifiers), name])
702
- ])),
703
- constructorBody
267
+ invocation.push(indentInParentheses(printDanglingComments(path), { shouldBreak: true }));
268
+ }
269
+ invocation.push(";");
270
+ return invocation;
271
+ },
272
+ qualifiedExplicitConstructorInvocation(path, print) {
273
+ const { children } = path.node;
274
+ const invocation = [call(path, print, "expressionName"), "."];
275
+ if (children.typeArguments) {
276
+ invocation.push(call(path, print, "typeArguments"));
277
+ }
278
+ invocation.push("super");
279
+ if (children.argumentList) {
280
+ invocation.push(group(["(", call(path, print, "argumentList"), ")"]));
281
+ }
282
+ else {
283
+ invocation.push(indentInParentheses(printDanglingComments(path), { shouldBreak: true }));
284
+ }
285
+ invocation.push(";");
286
+ return invocation;
287
+ },
288
+ enumDeclaration(path, print) {
289
+ const header = ["enum", call(path, print, "typeIdentifier")];
290
+ if (path.node.children.classImplements) {
291
+ header.push(call(path, print, "classImplements"));
292
+ }
293
+ return join(" ", [...header, call(path, print, "enumBody")]);
294
+ },
295
+ enumBody(path, print, options) {
296
+ var _a;
297
+ const { children } = path.node;
298
+ const contents = [];
299
+ const hasNonEmptyDeclaration = ((_a = children.enumBodyDeclarations) !== null && _a !== void 0 ? _a : [])
300
+ .flatMap(({ children }) => { var _a; return (_a = children.classBodyDeclaration) !== null && _a !== void 0 ? _a : []; })
301
+ .some(({ children }) => { var _a; return !((_a = children.classMemberDeclaration) === null || _a === void 0 ? void 0 : _a[0].children.Semicolon); });
302
+ if (children.enumConstantList) {
303
+ contents.push(call(path, print, "enumConstantList"));
304
+ if (!hasNonEmptyDeclaration && options.trailingComma !== "none") {
305
+ contents.push(",");
306
+ }
307
+ }
308
+ if (hasNonEmptyDeclaration) {
309
+ contents.push(";", hardline, call(path, print, "enumBodyDeclarations"));
310
+ }
311
+ return printBlock(path, contents.length ? [contents] : []);
312
+ },
313
+ enumConstantList(path, print) {
314
+ return join([",", hardline], map(path, constantPath => {
315
+ const constant = print(constantPath);
316
+ const { node, previous } = constantPath;
317
+ return !previous ||
318
+ lineStartWithComments(node) <= lineEndWithComments(previous) + 1
319
+ ? constant
320
+ : [hardline, constant];
321
+ }, "enumConstant"));
322
+ },
323
+ enumConstant(path, print) {
324
+ const { argumentList, classBody } = path.node.children;
325
+ const initializer = [call(path, print, "Identifier")];
326
+ if (argumentList) {
327
+ initializer.push(group(["(", call(path, print, "argumentList"), ")"]));
328
+ }
329
+ if (classBody) {
330
+ initializer.push(" ", call(path, print, "classBody"));
331
+ }
332
+ return printWithModifiers(path, print, "enumConstantModifier", initializer);
333
+ },
334
+ enumConstantModifier: printSingle,
335
+ enumBodyDeclarations(path, print) {
336
+ return join(hardline, printClassBodyDeclarations(path, print));
337
+ },
338
+ recordDeclaration(path, print) {
339
+ const { children } = path.node;
340
+ const header = ["record ", call(path, print, "typeIdentifier")];
341
+ if (children.typeParameters) {
342
+ header.push(call(path, print, "typeParameters"));
343
+ }
344
+ header.push(call(path, print, "recordHeader"));
345
+ if (children.classImplements) {
346
+ header.push(" ", call(path, print, "classImplements"));
347
+ }
348
+ return [group(header), " ", call(path, print, "recordBody")];
349
+ },
350
+ recordHeader(path, print) {
351
+ return path.node.children.recordComponentList
352
+ ? indentInParentheses(call(path, print, "recordComponentList"))
353
+ : indentInParentheses(printDanglingComments(path), { shouldBreak: true });
354
+ },
355
+ recordComponentList(path, print) {
356
+ return join([",", line], map(path, componentPath => {
357
+ const { node, previous } = componentPath;
358
+ const blankLine = previous &&
359
+ lineStartWithComments(node) > lineEndWithComments(previous) + 1;
360
+ const component = print(componentPath);
361
+ return blankLine ? [softline, component] : component;
362
+ }, "recordComponent"));
363
+ },
364
+ recordComponent(path, print) {
365
+ const { children } = path.node;
366
+ const component = [call(path, print, "unannType")];
367
+ if (children.Identifier ||
368
+ children.variableArityRecordComponent[0].children.annotation) {
369
+ component.push(" ");
370
+ }
371
+ const suffixKey = onlyDefinedKey(children, [
372
+ "Identifier",
373
+ "variableArityRecordComponent"
704
374
  ]);
705
- }
706
- isDims() {
707
- return "isDims";
708
- }
375
+ component.push(call(path, print, suffixKey));
376
+ return group(join(line, [...map(path, print, "recordComponentModifier"), component]));
377
+ },
378
+ variableArityRecordComponent(path, print) {
379
+ return [
380
+ ...join(" ", map(path, print, "annotation")),
381
+ "... ",
382
+ call(path, print, "Identifier")
383
+ ];
384
+ },
385
+ recordComponentModifier: printSingle,
386
+ recordBody(path, print) {
387
+ const declarations = [];
388
+ let previousRequiresPadding = false;
389
+ each(path, declarationPath => {
390
+ var _a, _b, _c, _d;
391
+ const declaration = print(declarationPath);
392
+ if (declaration === "") {
393
+ return;
394
+ }
395
+ const { node, previous } = declarationPath;
396
+ const fieldDeclaration = (_c = (_b = (_a = node.children.classBodyDeclaration) === null || _a === void 0 ? void 0 : _a[0].children.classMemberDeclaration) === null || _b === void 0 ? void 0 : _b[0].children.fieldDeclaration) === null || _c === void 0 ? void 0 : _c[0].children;
397
+ const currentRequiresPadding = !fieldDeclaration ||
398
+ hasDeclarationAnnotations((_d = fieldDeclaration.fieldModifier) !== null && _d !== void 0 ? _d : []);
399
+ const blankLine = declarations.length > 0 &&
400
+ (previousRequiresPadding ||
401
+ currentRequiresPadding ||
402
+ lineStartWithComments(node) > lineEndWithComments(previous) + 1);
403
+ declarations.push(blankLine ? [hardline, declaration] : declaration);
404
+ previousRequiresPadding = currentRequiresPadding;
405
+ }, "recordBodyDeclaration");
406
+ return printBlock(path, declarations);
407
+ },
408
+ recordBodyDeclaration: printSingle,
409
+ compactConstructorDeclaration(path, print) {
410
+ const declaration = [
411
+ call(path, print, "simpleTypeName"),
412
+ " ",
413
+ call(path, print, "constructorBody")
414
+ ];
415
+ return printWithModifiers(path, print, "constructorModifier", declaration, true);
416
+ }
417
+ };
418
+ function printClassBodyDeclarations(path, print) {
419
+ var _a;
420
+ if (!path.node.children.classBodyDeclaration) {
421
+ return [];
422
+ }
423
+ const declarations = [];
424
+ let previousRequiresPadding = path.node.name === "enumBodyDeclarations" ||
425
+ ((_a = path.grandparent) === null || _a === void 0 ? void 0 : _a.name) ===
426
+ "normalClassDeclaration";
427
+ each(path, declarationPath => {
428
+ var _a, _b, _c;
429
+ const declaration = print(declarationPath);
430
+ if (declaration === "") {
431
+ return;
432
+ }
433
+ const { node, previous } = declarationPath;
434
+ const fieldDeclaration = (_b = (_a = node.children.classMemberDeclaration) === null || _a === void 0 ? void 0 : _a[0].children.fieldDeclaration) === null || _b === void 0 ? void 0 : _b[0].children;
435
+ const currentRequiresPadding = fieldDeclaration
436
+ ? hasDeclarationAnnotations((_c = fieldDeclaration.fieldModifier) !== null && _c !== void 0 ? _c : [])
437
+ : true;
438
+ const blankLine = previousRequiresPadding ||
439
+ (declarations.length > 0 &&
440
+ (currentRequiresPadding ||
441
+ lineStartWithComments(node) > lineEndWithComments(previous) + 1));
442
+ declarations.push(blankLine ? [hardline, declaration] : declaration);
443
+ previousRequiresPadding = currentRequiresPadding;
444
+ }, "classBodyDeclaration");
445
+ return declarations;
709
446
  }