prettier-plugin-java 2.6.1 → 2.6.2
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.
- package/dist/base-cst-printer.js +55 -0
- package/dist/cst-printer.js +29 -0
- package/dist/index.js +66 -0
- package/dist/options.js +256 -0
- package/dist/parser.js +4 -0
- package/dist/printer.js +6 -0
- package/dist/printers/arrays.js +25 -0
- package/dist/printers/blocks-and-statements.js +432 -0
- package/dist/printers/classes.js +709 -0
- package/dist/printers/comments/comments-utils.js +21 -0
- package/dist/printers/comments/format-comments.js +171 -0
- package/dist/printers/comments/handle-comments.js +102 -0
- package/dist/printers/expressions.js +590 -0
- package/dist/printers/interfaces.js +222 -0
- package/dist/printers/lexical-structure.js +31 -0
- package/dist/printers/names.js +29 -0
- package/dist/printers/packages-and-modules.js +171 -0
- package/dist/printers/prettier-builder.js +45 -0
- package/dist/printers/printer-utils.js +596 -0
- package/dist/printers/types-values-and-variables.js +153 -0
- package/dist/types/utils.js +20 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/isEmptyDoc.js +4 -0
- package/dist/utils/printArgumentListWithBraces.js +37 -0
- package/package.json +3 -3
|
@@ -0,0 +1,709 @@
|
|
|
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
|
+
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;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
classCST = ctx.recordDeclaration;
|
|
26
|
+
}
|
|
27
|
+
const classDoc = this.visit(classCST);
|
|
28
|
+
return rejectAndJoin(hardline, [
|
|
29
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
30
|
+
rejectAndJoin(" ", [join(" ", otherModifiers), classDoc])
|
|
31
|
+
]);
|
|
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
|
|
61
|
+
]);
|
|
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
|
+
}
|
|
124
|
+
}
|
|
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]);
|
|
133
|
+
}
|
|
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);
|
|
154
|
+
}
|
|
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
|
+
])));
|
|
251
|
+
}
|
|
252
|
+
return variableDeclaratorId;
|
|
253
|
+
}
|
|
254
|
+
variableDeclaratorId(ctx) {
|
|
255
|
+
if (ctx.Underscore) {
|
|
256
|
+
return printTokenWithComments(ctx.Underscore[0]);
|
|
257
|
+
}
|
|
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);
|
|
276
|
+
}
|
|
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])
|
|
330
|
+
])
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
methodModifier(ctx) {
|
|
334
|
+
if (ctx.annotation) {
|
|
335
|
+
return this.visit(ctx.annotation);
|
|
336
|
+
}
|
|
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);
|
|
359
|
+
}
|
|
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
|
|
381
|
+
]);
|
|
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]])
|
|
391
|
+
]);
|
|
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
|
|
427
|
+
]);
|
|
428
|
+
}
|
|
429
|
+
variableModifier(ctx) {
|
|
430
|
+
if (ctx.annotation) {
|
|
431
|
+
return this.visit(ctx.annotation);
|
|
432
|
+
}
|
|
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);
|
|
451
|
+
}
|
|
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);
|
|
483
|
+
}
|
|
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] : ",";
|
|
568
|
+
}
|
|
569
|
+
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
|
|
704
|
+
]);
|
|
705
|
+
}
|
|
706
|
+
isDims() {
|
|
707
|
+
return "isDims";
|
|
708
|
+
}
|
|
709
|
+
}
|