prettier-plugin-java 2.8.1 → 2.9.0
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/README.md +42 -102
- package/dist/index.cjs +2215 -0
- package/dist/index.d.cts +1630 -0
- package/dist/index.d.mts +1633 -0
- package/dist/index.mjs +2215 -0
- package/dist/tree-sitter-java_orchard.wasm +0 -0
- package/package.json +62 -24
- package/dist/comments.d.ts +0 -17
- package/dist/comments.js +0 -229
- package/dist/index.d.ts +0 -563
- package/dist/index.js +0 -29
- package/dist/options.d.ts +0 -43
- package/dist/options.js +0 -284
- package/dist/parser.d.ts +0 -9
- package/dist/parser.js +0 -24
- package/dist/printer.d.ts +0 -18
- package/dist/printer.js +0 -40
- package/dist/printers/arrays.d.ts +0 -9
- package/dist/printers/arrays.js +0 -9
- package/dist/printers/blocks-and-statements.d.ts +0 -117
- package/dist/printers/blocks-and-statements.js +0 -340
- package/dist/printers/classes.d.ts +0 -157
- package/dist/printers/classes.js +0 -485
- package/dist/printers/expressions.d.ts +0 -134
- package/dist/printers/expressions.js +0 -627
- package/dist/printers/helpers.d.ts +0 -73
- package/dist/printers/helpers.js +0 -273
- package/dist/printers/index.d.ts +0 -2
- package/dist/printers/index.js +0 -13
- package/dist/printers/interfaces.d.ts +0 -62
- package/dist/printers/interfaces.js +0 -175
- package/dist/printers/lexical-structure.d.ts +0 -14
- package/dist/printers/lexical-structure.js +0 -29
- package/dist/printers/names.d.ts +0 -12
- package/dist/printers/names.js +0 -11
- package/dist/printers/packages-and-modules.d.ts +0 -46
- package/dist/printers/packages-and-modules.js +0 -169
- package/dist/printers/types-values-and-variables.d.ts +0 -46
- package/dist/printers/types-values-and-variables.js +0 -90
package/dist/printers/classes.js
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
import { builders } from "prettier/doc";
|
|
2
|
-
import { call, definedKeys, each, hasDeclarationAnnotations, hasLeadingComments, hasNonAssignmentOperators, indentInParentheses, 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 { children } = path.node;
|
|
16
|
-
const definedClauses = definedKeys(children, [
|
|
17
|
-
"classExtends",
|
|
18
|
-
"classImplements",
|
|
19
|
-
"classPermits"
|
|
20
|
-
]);
|
|
21
|
-
const hasMultipleClauses = definedClauses.length > 1;
|
|
22
|
-
const hasTypeParameters = children.typeParameters !== undefined;
|
|
23
|
-
const parts = ["class ", call(path, print, "typeIdentifier")];
|
|
24
|
-
if (hasTypeParameters) {
|
|
25
|
-
const typeParameters = call(path, print, "typeParameters");
|
|
26
|
-
parts.push(hasMultipleClauses ? group(indent(typeParameters)) : typeParameters);
|
|
27
|
-
}
|
|
28
|
-
if (definedClauses.length) {
|
|
29
|
-
const separator = hasTypeParameters && !hasMultipleClauses ? " " : line;
|
|
30
|
-
const clauses = definedClauses.flatMap(clause => [
|
|
31
|
-
separator,
|
|
32
|
-
call(path, print, clause)
|
|
33
|
-
]);
|
|
34
|
-
const hasBody = children.classBody[0].children.classBodyDeclaration !== undefined;
|
|
35
|
-
const clauseGroup = [
|
|
36
|
-
hasTypeParameters && !hasMultipleClauses ? clauses : indent(clauses),
|
|
37
|
-
hasBody ? separator : " "
|
|
38
|
-
];
|
|
39
|
-
parts.push(hasMultipleClauses ? clauseGroup : group(clauseGroup));
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
parts.push(" ");
|
|
43
|
-
}
|
|
44
|
-
return [group(parts), call(path, print, "classBody")];
|
|
45
|
-
},
|
|
46
|
-
classModifier: printSingle,
|
|
47
|
-
typeParameters(path, print) {
|
|
48
|
-
return [
|
|
49
|
-
"<",
|
|
50
|
-
indent([softline, call(path, print, "typeParameterList")]),
|
|
51
|
-
softline,
|
|
52
|
-
">"
|
|
53
|
-
];
|
|
54
|
-
},
|
|
55
|
-
typeParameterList(path, print) {
|
|
56
|
-
return printList(path, print, "typeParameter");
|
|
57
|
-
},
|
|
58
|
-
classExtends(path, print) {
|
|
59
|
-
return ["extends ", call(path, print, "classType")];
|
|
60
|
-
},
|
|
61
|
-
classImplements(path, print) {
|
|
62
|
-
return group([
|
|
63
|
-
"implements",
|
|
64
|
-
indent([line, call(path, print, "interfaceTypeList")])
|
|
65
|
-
]);
|
|
66
|
-
},
|
|
67
|
-
classPermits: printClassPermits,
|
|
68
|
-
interfaceTypeList(path, print) {
|
|
69
|
-
return printList(path, print, "interfaceType");
|
|
70
|
-
},
|
|
71
|
-
classBody(path, print) {
|
|
72
|
-
return printBlock(path, printClassBodyDeclarations(path, print));
|
|
73
|
-
},
|
|
74
|
-
classBodyDeclaration: printSingle,
|
|
75
|
-
classMemberDeclaration(path, print) {
|
|
76
|
-
const { children } = path.node;
|
|
77
|
-
return children.Semicolon
|
|
78
|
-
? ""
|
|
79
|
-
: call(path, print, onlyDefinedKey(children));
|
|
80
|
-
},
|
|
81
|
-
fieldDeclaration(path, print) {
|
|
82
|
-
const declaration = [
|
|
83
|
-
call(path, print, "unannType"),
|
|
84
|
-
" ",
|
|
85
|
-
call(path, print, "variableDeclaratorList"),
|
|
86
|
-
";"
|
|
87
|
-
];
|
|
88
|
-
return printWithModifiers(path, print, "fieldModifier", declaration);
|
|
89
|
-
},
|
|
90
|
-
fieldModifier: printSingle,
|
|
91
|
-
variableDeclaratorList(path, print) {
|
|
92
|
-
var _a;
|
|
93
|
-
const declarators = map(path, print, "variableDeclarator");
|
|
94
|
-
return declarators.length > 1 &&
|
|
95
|
-
path.node.children.variableDeclarator.some(({ children }) => children.Equals)
|
|
96
|
-
? group(indent(join([",", line], declarators)), {
|
|
97
|
-
shouldBreak: ((_a = path.getNode(4)) === null || _a === void 0 ? void 0 : _a.name) !== "forInit"
|
|
98
|
-
})
|
|
99
|
-
: join(", ", declarators);
|
|
100
|
-
},
|
|
101
|
-
variableDeclarator(path, print) {
|
|
102
|
-
var _a, _b, _c;
|
|
103
|
-
const { children } = path.node;
|
|
104
|
-
const variableInitializer = (_a = children.variableInitializer) === null || _a === void 0 ? void 0 : _a[0];
|
|
105
|
-
const declaratorId = call(path, print, "variableDeclaratorId");
|
|
106
|
-
if (!variableInitializer) {
|
|
107
|
-
return declaratorId;
|
|
108
|
-
}
|
|
109
|
-
const binaryExpression = (_c = (_b = variableInitializer.children.expression) === null || _b === void 0 ? void 0 : _b[0].children.conditionalExpression) === null || _c === void 0 ? void 0 : _c[0].children.binaryExpression[0];
|
|
110
|
-
const declarator = [declaratorId, " ", call(path, print, "Equals")];
|
|
111
|
-
const initializer = call(path, print, "variableInitializer");
|
|
112
|
-
if (hasLeadingComments(variableInitializer) ||
|
|
113
|
-
(binaryExpression && hasNonAssignmentOperators(binaryExpression))) {
|
|
114
|
-
declarator.push(group(indent([line, initializer])));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const groupId = Symbol("assignment");
|
|
118
|
-
declarator.push(group(indent(line), { id: groupId }), indentIfBreak(initializer, { groupId }));
|
|
119
|
-
}
|
|
120
|
-
return group(declarator);
|
|
121
|
-
},
|
|
122
|
-
variableDeclaratorId(path, print) {
|
|
123
|
-
const { dims, Underscore } = path.node.children;
|
|
124
|
-
if (Underscore) {
|
|
125
|
-
return "_";
|
|
126
|
-
}
|
|
127
|
-
const identifier = call(path, print, "Identifier");
|
|
128
|
-
return dims ? [identifier, call(path, print, "dims")] : identifier;
|
|
129
|
-
},
|
|
130
|
-
variableInitializer: printSingle,
|
|
131
|
-
unannType: printSingle,
|
|
132
|
-
unannPrimitiveTypeWithOptionalDimsSuffix(path, print) {
|
|
133
|
-
const type = call(path, print, "unannPrimitiveType");
|
|
134
|
-
return path.node.children.dims ? [type, call(path, print, "dims")] : type;
|
|
135
|
-
},
|
|
136
|
-
unannPrimitiveType: printSingle,
|
|
137
|
-
unannReferenceType(path, print) {
|
|
138
|
-
const type = call(path, print, "unannClassOrInterfaceType");
|
|
139
|
-
return path.node.children.dims ? [type, call(path, print, "dims")] : type;
|
|
140
|
-
},
|
|
141
|
-
unannClassOrInterfaceType: printSingle,
|
|
142
|
-
unannClassType: printClassType,
|
|
143
|
-
unannInterfaceType: printSingle,
|
|
144
|
-
unannTypeVariable: printSingle,
|
|
145
|
-
methodDeclaration(path, print) {
|
|
146
|
-
const declaration = [
|
|
147
|
-
call(path, print, "methodHeader"),
|
|
148
|
-
path.node.children.methodBody[0].children.Semicolon ? "" : " ",
|
|
149
|
-
call(path, print, "methodBody")
|
|
150
|
-
];
|
|
151
|
-
return printWithModifiers(path, print, "methodModifier", declaration);
|
|
152
|
-
},
|
|
153
|
-
methodModifier: printSingle,
|
|
154
|
-
methodHeader(path, print) {
|
|
155
|
-
const { typeParameters, annotation, throws } = path.node.children;
|
|
156
|
-
const header = [];
|
|
157
|
-
if (typeParameters) {
|
|
158
|
-
header.push(group(call(path, print, "typeParameters")));
|
|
159
|
-
}
|
|
160
|
-
if (annotation) {
|
|
161
|
-
header.push(join(line, map(path, print, "annotation")));
|
|
162
|
-
}
|
|
163
|
-
header.push(call(path, print, "result"), call(path, print, "methodDeclarator"));
|
|
164
|
-
return throws
|
|
165
|
-
? group([
|
|
166
|
-
...join(" ", header),
|
|
167
|
-
group(indent([line, call(path, print, "throws")]))
|
|
168
|
-
])
|
|
169
|
-
: group(join(" ", header));
|
|
170
|
-
},
|
|
171
|
-
result: printSingle,
|
|
172
|
-
methodDeclarator(path, print) {
|
|
173
|
-
const { dims, formalParameterList, receiverParameter } = path.node.children;
|
|
174
|
-
const declarator = [call(path, print, "Identifier")];
|
|
175
|
-
const parameters = [];
|
|
176
|
-
if (receiverParameter) {
|
|
177
|
-
parameters.push(call(path, print, "receiverParameter"));
|
|
178
|
-
}
|
|
179
|
-
if (formalParameterList) {
|
|
180
|
-
parameters.push(call(path, print, "formalParameterList"));
|
|
181
|
-
}
|
|
182
|
-
const items = parameters.length
|
|
183
|
-
? join([",", line], parameters)
|
|
184
|
-
: printDanglingComments(path);
|
|
185
|
-
declarator.push(items.length ? indentInParentheses(items) : "()");
|
|
186
|
-
if (dims) {
|
|
187
|
-
declarator.push(call(path, print, "dims"));
|
|
188
|
-
}
|
|
189
|
-
return declarator;
|
|
190
|
-
},
|
|
191
|
-
receiverParameter(path, print) {
|
|
192
|
-
return join(" ", [
|
|
193
|
-
...map(path, print, "annotation"),
|
|
194
|
-
call(path, print, "unannType"),
|
|
195
|
-
path.node.children.Identifier
|
|
196
|
-
? [call(path, print, "Identifier"), ".this"]
|
|
197
|
-
: "this"
|
|
198
|
-
]);
|
|
199
|
-
},
|
|
200
|
-
formalParameterList(path, print) {
|
|
201
|
-
return printList(path, print, "formalParameter");
|
|
202
|
-
},
|
|
203
|
-
formalParameter: printSingle,
|
|
204
|
-
variableParaRegularParameter(path, print) {
|
|
205
|
-
return join(" ", [
|
|
206
|
-
...map(path, print, "variableModifier"),
|
|
207
|
-
call(path, print, "unannType"),
|
|
208
|
-
call(path, print, "variableDeclaratorId")
|
|
209
|
-
]);
|
|
210
|
-
},
|
|
211
|
-
variableArityParameter(path, print) {
|
|
212
|
-
const type = join(" ", [
|
|
213
|
-
...map(path, print, "variableModifier"),
|
|
214
|
-
call(path, print, "unannType"),
|
|
215
|
-
...map(path, print, "annotation")
|
|
216
|
-
]);
|
|
217
|
-
return [type, "... ", call(path, print, "Identifier")];
|
|
218
|
-
},
|
|
219
|
-
variableModifier: printSingle,
|
|
220
|
-
throws(path, print) {
|
|
221
|
-
return ["throws ", call(path, print, "exceptionTypeList")];
|
|
222
|
-
},
|
|
223
|
-
exceptionTypeList(path, print) {
|
|
224
|
-
return join(", ", map(path, print, "exceptionType"));
|
|
225
|
-
},
|
|
226
|
-
exceptionType: printSingle,
|
|
227
|
-
methodBody: printSingle,
|
|
228
|
-
instanceInitializer: printSingle,
|
|
229
|
-
staticInitializer(path, print) {
|
|
230
|
-
return ["static ", call(path, print, "block")];
|
|
231
|
-
},
|
|
232
|
-
constructorDeclaration(path, print) {
|
|
233
|
-
const declaration = [call(path, print, "constructorDeclarator")];
|
|
234
|
-
if (path.node.children.throws) {
|
|
235
|
-
declaration.push(group(indent([line, call(path, print, "throws")])));
|
|
236
|
-
}
|
|
237
|
-
declaration.push(" ", call(path, print, "constructorBody"));
|
|
238
|
-
return printWithModifiers(path, print, "constructorModifier", declaration, true);
|
|
239
|
-
},
|
|
240
|
-
constructorModifier: printSingle,
|
|
241
|
-
constructorDeclarator(path, print) {
|
|
242
|
-
const { children } = path.node;
|
|
243
|
-
const parameters = [];
|
|
244
|
-
if (children.receiverParameter) {
|
|
245
|
-
parameters.push(call(path, print, "receiverParameter"));
|
|
246
|
-
}
|
|
247
|
-
if (children.formalParameterList) {
|
|
248
|
-
parameters.push(call(path, print, "formalParameterList"));
|
|
249
|
-
}
|
|
250
|
-
const header = [call(path, print, "simpleTypeName")];
|
|
251
|
-
header.push(parameters.length
|
|
252
|
-
? indentInParentheses(join([",", line], parameters))
|
|
253
|
-
: "()");
|
|
254
|
-
return children.typeParameters
|
|
255
|
-
? [group(call(path, print, "typeParameters")), " ", ...header]
|
|
256
|
-
: header;
|
|
257
|
-
},
|
|
258
|
-
simpleTypeName: printSingle,
|
|
259
|
-
constructorBody(path, print) {
|
|
260
|
-
const { children } = path.node;
|
|
261
|
-
const statements = [];
|
|
262
|
-
if (children.explicitConstructorInvocation) {
|
|
263
|
-
statements.push(call(path, print, "explicitConstructorInvocation"));
|
|
264
|
-
}
|
|
265
|
-
if (children.blockStatements) {
|
|
266
|
-
statements.push(call(path, print, "blockStatements"));
|
|
267
|
-
}
|
|
268
|
-
return printBlock(path, statements);
|
|
269
|
-
},
|
|
270
|
-
explicitConstructorInvocation: printSingle,
|
|
271
|
-
unqualifiedExplicitConstructorInvocation(path, print) {
|
|
272
|
-
const { children } = path.node;
|
|
273
|
-
const invocation = [];
|
|
274
|
-
if (children.typeArguments) {
|
|
275
|
-
invocation.push(call(path, print, "typeArguments"));
|
|
276
|
-
}
|
|
277
|
-
invocation.push(children.Super ? "super" : "this");
|
|
278
|
-
if (children.argumentList) {
|
|
279
|
-
invocation.push(group(["(", call(path, print, "argumentList"), ")"]));
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
invocation.push(indentInParentheses(printDanglingComments(path), { shouldBreak: true }));
|
|
283
|
-
}
|
|
284
|
-
invocation.push(";");
|
|
285
|
-
return invocation;
|
|
286
|
-
},
|
|
287
|
-
qualifiedExplicitConstructorInvocation(path, print) {
|
|
288
|
-
const { children } = path.node;
|
|
289
|
-
const invocation = [call(path, print, "expressionName"), "."];
|
|
290
|
-
if (children.typeArguments) {
|
|
291
|
-
invocation.push(call(path, print, "typeArguments"));
|
|
292
|
-
}
|
|
293
|
-
invocation.push("super");
|
|
294
|
-
if (children.argumentList) {
|
|
295
|
-
invocation.push(group(["(", call(path, print, "argumentList"), ")"]));
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
invocation.push(indentInParentheses(printDanglingComments(path), { shouldBreak: true }));
|
|
299
|
-
}
|
|
300
|
-
invocation.push(";");
|
|
301
|
-
return invocation;
|
|
302
|
-
},
|
|
303
|
-
enumDeclaration(path, print) {
|
|
304
|
-
const { children } = path.node;
|
|
305
|
-
const parts = ["enum ", call(path, print, "typeIdentifier")];
|
|
306
|
-
if (children.classImplements) {
|
|
307
|
-
const body = children.enumBody[0].children;
|
|
308
|
-
const hasBody = body.enumBodyDeclarations !== undefined ||
|
|
309
|
-
body.enumConstantList !== undefined;
|
|
310
|
-
parts.push(indent([line, call(path, print, "classImplements")]), hasBody ? line : " ");
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
parts.push(" ");
|
|
314
|
-
}
|
|
315
|
-
return [group(parts), call(path, print, "enumBody")];
|
|
316
|
-
},
|
|
317
|
-
enumBody(path, print, options) {
|
|
318
|
-
var _a;
|
|
319
|
-
const { children } = path.node;
|
|
320
|
-
const contents = [];
|
|
321
|
-
const hasNonEmptyDeclaration = ((_a = children.enumBodyDeclarations) !== null && _a !== void 0 ? _a : [])
|
|
322
|
-
.flatMap(({ children }) => { var _a; return (_a = children.classBodyDeclaration) !== null && _a !== void 0 ? _a : []; })
|
|
323
|
-
.some(({ children }) => { var _a; return !((_a = children.classMemberDeclaration) === null || _a === void 0 ? void 0 : _a[0].children.Semicolon); });
|
|
324
|
-
if (children.enumConstantList) {
|
|
325
|
-
contents.push(call(path, print, "enumConstantList"));
|
|
326
|
-
if (!hasNonEmptyDeclaration && options.trailingComma !== "none") {
|
|
327
|
-
contents.push(",");
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (hasNonEmptyDeclaration) {
|
|
331
|
-
contents.push(";", hardline, call(path, print, "enumBodyDeclarations"));
|
|
332
|
-
}
|
|
333
|
-
return printBlock(path, contents.length ? [contents] : []);
|
|
334
|
-
},
|
|
335
|
-
enumConstantList(path, print) {
|
|
336
|
-
return join([",", hardline], map(path, constantPath => {
|
|
337
|
-
const constant = print(constantPath);
|
|
338
|
-
const { node, previous } = constantPath;
|
|
339
|
-
return !previous ||
|
|
340
|
-
lineStartWithComments(node) <= lineEndWithComments(previous) + 1
|
|
341
|
-
? constant
|
|
342
|
-
: [hardline, constant];
|
|
343
|
-
}, "enumConstant"));
|
|
344
|
-
},
|
|
345
|
-
enumConstant(path, print) {
|
|
346
|
-
const { argumentList, classBody } = path.node.children;
|
|
347
|
-
const initializer = [call(path, print, "Identifier")];
|
|
348
|
-
if (argumentList) {
|
|
349
|
-
initializer.push(group(["(", call(path, print, "argumentList"), ")"]));
|
|
350
|
-
}
|
|
351
|
-
if (classBody) {
|
|
352
|
-
initializer.push(" ", call(path, print, "classBody"));
|
|
353
|
-
}
|
|
354
|
-
return printWithModifiers(path, print, "enumConstantModifier", initializer);
|
|
355
|
-
},
|
|
356
|
-
enumConstantModifier: printSingle,
|
|
357
|
-
enumBodyDeclarations(path, print) {
|
|
358
|
-
return join(hardline, printClassBodyDeclarations(path, print));
|
|
359
|
-
},
|
|
360
|
-
recordDeclaration(path, print) {
|
|
361
|
-
const { children } = path.node;
|
|
362
|
-
const parts = ["record ", call(path, print, "typeIdentifier")];
|
|
363
|
-
if (children.typeParameters) {
|
|
364
|
-
parts.push(group(call(path, print, "typeParameters")));
|
|
365
|
-
}
|
|
366
|
-
parts.push(call(path, print, "recordHeader"));
|
|
367
|
-
if (children.classImplements) {
|
|
368
|
-
const hasComponents = children.recordHeader[0].children.recordComponentList !== undefined;
|
|
369
|
-
const hasBody = children.recordBody[0].children.recordBodyDeclaration !== undefined;
|
|
370
|
-
const classImplements = [
|
|
371
|
-
hasComponents ? " " : line,
|
|
372
|
-
call(path, print, "classImplements")
|
|
373
|
-
];
|
|
374
|
-
parts.push(group([
|
|
375
|
-
hasComponents ? classImplements : indent(classImplements),
|
|
376
|
-
hasBody ? line : " "
|
|
377
|
-
]));
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
parts.push(" ");
|
|
381
|
-
}
|
|
382
|
-
return [group(parts), call(path, print, "recordBody")];
|
|
383
|
-
},
|
|
384
|
-
recordHeader(path, print) {
|
|
385
|
-
return path.node.children.recordComponentList
|
|
386
|
-
? [
|
|
387
|
-
"(",
|
|
388
|
-
indent([softline, call(path, print, "recordComponentList")]),
|
|
389
|
-
softline,
|
|
390
|
-
")"
|
|
391
|
-
]
|
|
392
|
-
: indentInParentheses(printDanglingComments(path), { shouldBreak: true });
|
|
393
|
-
},
|
|
394
|
-
recordComponentList(path, print) {
|
|
395
|
-
return join([",", line], map(path, componentPath => {
|
|
396
|
-
const { node, previous } = componentPath;
|
|
397
|
-
const blankLine = previous &&
|
|
398
|
-
lineStartWithComments(node) > lineEndWithComments(previous) + 1;
|
|
399
|
-
const component = print(componentPath);
|
|
400
|
-
return blankLine ? [softline, component] : component;
|
|
401
|
-
}, "recordComponent"));
|
|
402
|
-
},
|
|
403
|
-
recordComponent(path, print) {
|
|
404
|
-
const { children } = path.node;
|
|
405
|
-
const component = [call(path, print, "unannType")];
|
|
406
|
-
if (children.Identifier ||
|
|
407
|
-
children.variableArityRecordComponent[0].children.annotation) {
|
|
408
|
-
component.push(" ");
|
|
409
|
-
}
|
|
410
|
-
const suffixKey = onlyDefinedKey(children, [
|
|
411
|
-
"Identifier",
|
|
412
|
-
"variableArityRecordComponent"
|
|
413
|
-
]);
|
|
414
|
-
component.push(call(path, print, suffixKey));
|
|
415
|
-
return group(join(line, [...map(path, print, "recordComponentModifier"), component]));
|
|
416
|
-
},
|
|
417
|
-
variableArityRecordComponent(path, print) {
|
|
418
|
-
return [
|
|
419
|
-
...join(" ", map(path, print, "annotation")),
|
|
420
|
-
"... ",
|
|
421
|
-
call(path, print, "Identifier")
|
|
422
|
-
];
|
|
423
|
-
},
|
|
424
|
-
recordComponentModifier: printSingle,
|
|
425
|
-
recordBody(path, print) {
|
|
426
|
-
const declarations = [];
|
|
427
|
-
let previousRequiresPadding = false;
|
|
428
|
-
each(path, declarationPath => {
|
|
429
|
-
var _a, _b, _c, _d;
|
|
430
|
-
const declaration = print(declarationPath);
|
|
431
|
-
if (declaration === "") {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
const { node, previous } = declarationPath;
|
|
435
|
-
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;
|
|
436
|
-
const currentRequiresPadding = !fieldDeclaration ||
|
|
437
|
-
hasDeclarationAnnotations((_d = fieldDeclaration.fieldModifier) !== null && _d !== void 0 ? _d : []);
|
|
438
|
-
const blankLine = declarations.length > 0 &&
|
|
439
|
-
(previousRequiresPadding ||
|
|
440
|
-
currentRequiresPadding ||
|
|
441
|
-
lineStartWithComments(node) > lineEndWithComments(previous) + 1);
|
|
442
|
-
declarations.push(blankLine ? [hardline, declaration] : declaration);
|
|
443
|
-
previousRequiresPadding = currentRequiresPadding;
|
|
444
|
-
}, "recordBodyDeclaration");
|
|
445
|
-
return printBlock(path, declarations);
|
|
446
|
-
},
|
|
447
|
-
recordBodyDeclaration: printSingle,
|
|
448
|
-
compactConstructorDeclaration(path, print) {
|
|
449
|
-
const declaration = [
|
|
450
|
-
call(path, print, "simpleTypeName"),
|
|
451
|
-
" ",
|
|
452
|
-
call(path, print, "constructorBody")
|
|
453
|
-
];
|
|
454
|
-
return printWithModifiers(path, print, "constructorModifier", declaration, true);
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
function printClassBodyDeclarations(path, print) {
|
|
458
|
-
var _a;
|
|
459
|
-
if (!path.node.children.classBodyDeclaration) {
|
|
460
|
-
return [];
|
|
461
|
-
}
|
|
462
|
-
const declarations = [];
|
|
463
|
-
let previousRequiresPadding = path.node.name === "enumBodyDeclarations" ||
|
|
464
|
-
((_a = path.grandparent) === null || _a === void 0 ? void 0 : _a.name) ===
|
|
465
|
-
"normalClassDeclaration";
|
|
466
|
-
each(path, declarationPath => {
|
|
467
|
-
var _a, _b, _c;
|
|
468
|
-
const declaration = print(declarationPath);
|
|
469
|
-
if (declaration === "") {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
const { node, previous } = declarationPath;
|
|
473
|
-
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;
|
|
474
|
-
const currentRequiresPadding = fieldDeclaration
|
|
475
|
-
? hasDeclarationAnnotations((_c = fieldDeclaration.fieldModifier) !== null && _c !== void 0 ? _c : [])
|
|
476
|
-
: true;
|
|
477
|
-
const blankLine = previousRequiresPadding ||
|
|
478
|
-
(declarations.length > 0 &&
|
|
479
|
-
(currentRequiresPadding ||
|
|
480
|
-
lineStartWithComments(node) > lineEndWithComments(previous) + 1));
|
|
481
|
-
declarations.push(blankLine ? [hardline, declaration] : declaration);
|
|
482
|
-
previousRequiresPadding = currentRequiresPadding;
|
|
483
|
-
}, "classBodyDeclaration");
|
|
484
|
-
return declarations;
|
|
485
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { BinaryExpressionCstNode, PrimaryCstNode, StringTemplateCstNode, TextBlockTemplateCstNode } from "java-parser";
|
|
2
|
-
import type { AstPath } from "prettier";
|
|
3
|
-
import { builders } from "prettier/doc";
|
|
4
|
-
import type { JavaComment } from "../comments.js";
|
|
5
|
-
import { printSingle, type JavaPrintFn } from "./helpers.js";
|
|
6
|
-
declare const _default: {
|
|
7
|
-
expression: typeof printSingle;
|
|
8
|
-
lambdaExpression(path: AstPath<import("java-parser").LambdaExpressionCstNode & {
|
|
9
|
-
comments?: JavaComment[];
|
|
10
|
-
}>, print: JavaPrintFn, _: import("./helpers.js").JavaParserOptions, args?: unknown): builders.Doc[];
|
|
11
|
-
lambdaParameters(path: AstPath<import("java-parser").LambdaParametersCstNode & {
|
|
12
|
-
comments?: JavaComment[];
|
|
13
|
-
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
14
|
-
lambdaParametersWithBraces(path: AstPath<import("java-parser").LambdaParametersWithBracesCstNode & {
|
|
15
|
-
comments?: JavaComment[];
|
|
16
|
-
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
17
|
-
lambdaParameterList: typeof printSingle;
|
|
18
|
-
conciseLambdaParameterList(path: AstPath<import("java-parser").ConciseLambdaParameterListCstNode & {
|
|
19
|
-
comments?: JavaComment[];
|
|
20
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
21
|
-
normalLambdaParameterList(path: AstPath<import("java-parser").NormalLambdaParameterListCstNode & {
|
|
22
|
-
comments?: JavaComment[];
|
|
23
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
24
|
-
normalLambdaParameter: typeof printSingle;
|
|
25
|
-
regularLambdaParameter(path: AstPath<import("java-parser").RegularLambdaParameterCstNode & {
|
|
26
|
-
comments?: JavaComment[];
|
|
27
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
28
|
-
lambdaParameterType: typeof printSingle;
|
|
29
|
-
conciseLambdaParameter: typeof printSingle;
|
|
30
|
-
lambdaBody: typeof printSingle;
|
|
31
|
-
conditionalExpression(path: AstPath<import("java-parser").ConditionalExpressionCstNode & {
|
|
32
|
-
comments?: JavaComment[];
|
|
33
|
-
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
34
|
-
binaryExpression(path: AstPath<BinaryExpressionCstNode & {
|
|
35
|
-
comments?: JavaComment[];
|
|
36
|
-
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
37
|
-
unaryExpression(path: AstPath<import("java-parser").UnaryExpressionCstNode & {
|
|
38
|
-
comments?: JavaComment[];
|
|
39
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
40
|
-
unaryExpressionNotPlusMinus(path: AstPath<import("java-parser").UnaryExpressionNotPlusMinusCstNode & {
|
|
41
|
-
comments?: JavaComment[];
|
|
42
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
43
|
-
primary(path: AstPath<PrimaryCstNode & {
|
|
44
|
-
comments?: JavaComment[];
|
|
45
|
-
}>, print: JavaPrintFn): builders.Doc;
|
|
46
|
-
primaryPrefix: typeof printSingle;
|
|
47
|
-
primarySuffix(path: AstPath<import("java-parser").PrimarySuffixCstNode & {
|
|
48
|
-
comments?: JavaComment[];
|
|
49
|
-
}>, print: JavaPrintFn): builders.Doc;
|
|
50
|
-
fqnOrRefType(path: AstPath<import("java-parser").FqnOrRefTypeCstNode & {
|
|
51
|
-
comments?: JavaComment[];
|
|
52
|
-
}>, print: JavaPrintFn, _: import("./helpers.js").JavaParserOptions, args: unknown): builders.Doc[];
|
|
53
|
-
fqnOrRefTypePartFirst(path: AstPath<import("java-parser").FqnOrRefTypePartFirstCstNode & {
|
|
54
|
-
comments?: JavaComment[];
|
|
55
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
56
|
-
fqnOrRefTypePartRest(path: AstPath<import("java-parser").FqnOrRefTypePartRestCstNode & {
|
|
57
|
-
comments?: JavaComment[];
|
|
58
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
59
|
-
fqnOrRefTypePartCommon(path: AstPath<import("java-parser").FqnOrRefTypePartCommonCstNode & {
|
|
60
|
-
comments?: JavaComment[];
|
|
61
|
-
}>, print: JavaPrintFn): builders.Doc;
|
|
62
|
-
parenthesisExpression(path: AstPath<import("java-parser").ParenthesisExpressionCstNode & {
|
|
63
|
-
comments?: JavaComment[];
|
|
64
|
-
}>, print: JavaPrintFn): builders.Group | "()";
|
|
65
|
-
castExpression: typeof printSingle;
|
|
66
|
-
primitiveCastExpression(path: AstPath<import("java-parser").PrimitiveCastExpressionCstNode & {
|
|
67
|
-
comments?: JavaComment[];
|
|
68
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
69
|
-
referenceTypeCastExpression(path: AstPath<import("java-parser").ReferenceTypeCastExpressionCstNode & {
|
|
70
|
-
comments?: JavaComment[];
|
|
71
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
72
|
-
newExpression: typeof printSingle;
|
|
73
|
-
unqualifiedClassInstanceCreationExpression(path: AstPath<import("java-parser").UnqualifiedClassInstanceCreationExpressionCstNode & {
|
|
74
|
-
comments?: JavaComment[];
|
|
75
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
76
|
-
classOrInterfaceTypeToInstantiate(path: AstPath<import("java-parser").ClassOrInterfaceTypeToInstantiateCstNode & {
|
|
77
|
-
comments?: JavaComment[];
|
|
78
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
79
|
-
typeArgumentsOrDiamond: typeof printSingle;
|
|
80
|
-
diamond(): string;
|
|
81
|
-
methodInvocationSuffix(path: AstPath<import("java-parser").MethodInvocationSuffixCstNode & {
|
|
82
|
-
comments?: JavaComment[];
|
|
83
|
-
}>, print: JavaPrintFn): builders.Group | "()";
|
|
84
|
-
argumentList(path: AstPath<import("java-parser").ArgumentListCstNode & {
|
|
85
|
-
comments?: JavaComment[];
|
|
86
|
-
}>, print: JavaPrintFn): builders.Group | (builders.Indent | builders.Softline)[] | (builders.BreakParent | builders.Group)[];
|
|
87
|
-
arrayCreationExpression(path: AstPath<import("java-parser").ArrayCreationExpressionCstNode & {
|
|
88
|
-
comments?: JavaComment[];
|
|
89
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
90
|
-
arrayCreationExpressionWithoutInitializerSuffix(path: AstPath<import("java-parser").ArrayCreationExpressionWithoutInitializerSuffixCstNode & {
|
|
91
|
-
comments?: JavaComment[];
|
|
92
|
-
}>, print: JavaPrintFn): builders.Doc;
|
|
93
|
-
arrayCreationWithInitializerSuffix(path: AstPath<import("java-parser").ArrayCreationWithInitializerSuffixCstNode & {
|
|
94
|
-
comments?: JavaComment[];
|
|
95
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
96
|
-
dimExprs(path: AstPath<import("java-parser").DimExprsCstNode & {
|
|
97
|
-
comments?: JavaComment[];
|
|
98
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
99
|
-
dimExpr(path: AstPath<import("java-parser").DimExprCstNode & {
|
|
100
|
-
comments?: JavaComment[];
|
|
101
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
102
|
-
classLiteralSuffix(path: AstPath<import("java-parser").ClassLiteralSuffixCstNode & {
|
|
103
|
-
comments?: JavaComment[];
|
|
104
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
105
|
-
arrayAccessSuffix(path: AstPath<import("java-parser").ArrayAccessSuffixCstNode & {
|
|
106
|
-
comments?: JavaComment[];
|
|
107
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
108
|
-
methodReferenceSuffix(path: AstPath<import("java-parser").MethodReferenceSuffixCstNode & {
|
|
109
|
-
comments?: JavaComment[];
|
|
110
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
111
|
-
templateArgument: typeof printSingle;
|
|
112
|
-
template: typeof printSingle;
|
|
113
|
-
stringTemplate(path: AstPath<StringTemplateCstNode & {
|
|
114
|
-
comments?: JavaComment[];
|
|
115
|
-
}>, print: JavaPrintFn): builders.Indent;
|
|
116
|
-
textBlockTemplate(path: AstPath<TextBlockTemplateCstNode & {
|
|
117
|
-
comments?: JavaComment[];
|
|
118
|
-
}>, print: JavaPrintFn): builders.Indent;
|
|
119
|
-
embeddedExpression: typeof printSingle;
|
|
120
|
-
pattern: typeof printSingle;
|
|
121
|
-
typePattern: typeof printSingle;
|
|
122
|
-
recordPattern(path: AstPath<import("java-parser").RecordPatternCstNode & {
|
|
123
|
-
comments?: JavaComment[];
|
|
124
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
125
|
-
componentPatternList(path: AstPath<import("java-parser").ComponentPatternListCstNode & {
|
|
126
|
-
comments?: JavaComment[];
|
|
127
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
128
|
-
componentPattern: typeof printSingle;
|
|
129
|
-
matchAllPattern: typeof printSingle;
|
|
130
|
-
guard(path: AstPath<import("java-parser").GuardCstNode & {
|
|
131
|
-
comments?: JavaComment[];
|
|
132
|
-
}>, print: JavaPrintFn): builders.Doc[];
|
|
133
|
-
};
|
|
134
|
-
export default _default;
|