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.
- package/dist/comments.d.ts +17 -0
- package/dist/comments.js +199 -0
- package/dist/index.d.ts +543 -0
- package/dist/index.js +26 -63
- package/dist/options.d.ts +23 -0
- package/dist/options.js +247 -239
- package/dist/parser.d.ts +9 -0
- package/dist/parser.js +24 -4
- package/dist/printer.d.ts +18 -0
- package/dist/printer.js +39 -5
- package/dist/printers/arrays.d.ts +9 -0
- package/dist/printers/arrays.js +8 -24
- package/dist/printers/blocks-and-statements.d.ts +117 -0
- package/dist/printers/blocks-and-statements.js +316 -412
- package/dist/printers/classes.d.ts +157 -0
- package/dist/printers/classes.js +422 -685
- package/dist/printers/expressions.d.ts +134 -0
- package/dist/printers/expressions.js +549 -555
- package/dist/printers/helpers.d.ts +71 -0
- package/dist/printers/helpers.js +233 -0
- package/dist/printers/index.d.ts +2 -0
- package/dist/printers/index.js +13 -0
- package/dist/printers/interfaces.d.ts +62 -0
- package/dist/printers/interfaces.js +146 -211
- package/dist/printers/lexical-structure.d.ts +14 -0
- package/dist/printers/lexical-structure.js +26 -28
- package/dist/printers/names.d.ts +12 -0
- package/dist/printers/names.js +11 -29
- package/dist/printers/packages-and-modules.d.ts +46 -0
- package/dist/printers/packages-and-modules.js +157 -159
- package/dist/printers/types-values-and-variables.d.ts +46 -0
- package/dist/printers/types-values-and-variables.js +86 -149
- package/package.json +5 -8
- package/dist/base-cst-printer.js +0 -55
- package/dist/cst-printer.js +0 -29
- package/dist/printers/comments/comments-utils.js +0 -21
- package/dist/printers/comments/format-comments.js +0 -171
- package/dist/printers/comments/handle-comments.js +0 -102
- package/dist/printers/prettier-builder.js +0 -45
- package/dist/printers/printer-utils.js +0 -598
- package/dist/types/utils.js +0 -20
- package/dist/utils/index.js +0 -2
- package/dist/utils/isEmptyDoc.js +0 -4
- package/dist/utils/printArgumentListWithBraces.js +0 -37
- package/index.d.ts +0 -4
package/dist/printers/classes.js
CHANGED
|
@@ -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 {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
259
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
338
|
-
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
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
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
return
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
return
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
628
|
-
const
|
|
629
|
-
|
|
630
|
-
group(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
-
|
|
707
|
-
|
|
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
|
}
|