prettier-plugin-java 2.6.7 → 2.7.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.
Files changed (47) hide show
  1. package/dist/comments.d.ts +17 -0
  2. package/dist/comments.js +199 -0
  3. package/dist/index.d.ts +543 -0
  4. package/dist/index.js +26 -63
  5. package/dist/options.d.ts +23 -0
  6. package/dist/options.js +247 -239
  7. package/dist/parser.d.ts +9 -0
  8. package/dist/parser.js +24 -4
  9. package/dist/printer.d.ts +18 -0
  10. package/dist/printer.js +39 -5
  11. package/dist/printers/arrays.d.ts +9 -0
  12. package/dist/printers/arrays.js +8 -24
  13. package/dist/printers/blocks-and-statements.d.ts +117 -0
  14. package/dist/printers/blocks-and-statements.js +316 -412
  15. package/dist/printers/classes.d.ts +157 -0
  16. package/dist/printers/classes.js +422 -688
  17. package/dist/printers/expressions.d.ts +134 -0
  18. package/dist/printers/expressions.js +548 -560
  19. package/dist/printers/helpers.d.ts +71 -0
  20. package/dist/printers/helpers.js +233 -0
  21. package/dist/printers/index.d.ts +2 -0
  22. package/dist/printers/index.js +13 -0
  23. package/dist/printers/interfaces.d.ts +62 -0
  24. package/dist/printers/interfaces.js +146 -211
  25. package/dist/printers/lexical-structure.d.ts +14 -0
  26. package/dist/printers/lexical-structure.js +26 -28
  27. package/dist/printers/names.d.ts +12 -0
  28. package/dist/printers/names.js +11 -29
  29. package/dist/printers/packages-and-modules.d.ts +46 -0
  30. package/dist/printers/packages-and-modules.js +157 -159
  31. package/dist/printers/types-values-and-variables.d.ts +46 -0
  32. package/dist/printers/types-values-and-variables.js +86 -149
  33. package/package.json +5 -8
  34. package/dist/base-cst-printer.js +0 -55
  35. package/dist/cst-printer.js +0 -29
  36. package/dist/printers/comments/comments-utils.js +0 -21
  37. package/dist/printers/comments/format-comments.js +0 -171
  38. package/dist/printers/comments/handle-comments.js +0 -102
  39. package/dist/printers/prettier-builder.js +0 -45
  40. package/dist/printers/printer-utils.js +0 -598
  41. package/dist/types/utils.js +0 -20
  42. package/dist/utils/expressions-utils.js +0 -25
  43. package/dist/utils/index.js +0 -2
  44. package/dist/utils/isEmptyDoc.js +0 -4
  45. package/dist/utils/printArgumentListWithBraces.js +0 -37
  46. package/dist/utils/printSingleLambdaInvocation.js +0 -18
  47. package/index.d.ts +0 -4
@@ -1,598 +0,0 @@
1
- import findIndex from "lodash/findIndex.js";
2
- import findLastIndex from "lodash/findLastIndex.js";
3
- import forEach from "lodash/forEach.js";
4
- import forEachRight from "lodash/forEachRight.js";
5
- import includes from "lodash/includes.js";
6
- import { builders } from "prettier/doc";
7
- import { isCstNode } from "../types/utils.js";
8
- import { isEmptyDoc } from "../utils/index.js";
9
- import { hasComments, hasLeadingComments, hasTrailingComments } from "./comments/comments-utils.js";
10
- import { getTokenLeadingComments, printTokenWithComments } from "./comments/format-comments.js";
11
- import { concat, group, ifBreak, join } from "./prettier-builder.js";
12
- const { indent, hardline, line, lineSuffixBoundary, softline } = builders;
13
- const orderedModifiers = [
14
- "Public",
15
- "Protected",
16
- "Private",
17
- "Abstract",
18
- "Default",
19
- "Static",
20
- "Final",
21
- "Transient",
22
- "Volatile",
23
- "Synchronized",
24
- "Native",
25
- "Sealed",
26
- "NonSealed",
27
- "Strictfp"
28
- ];
29
- export function buildFqn(tokens, dots) {
30
- return rejectAndJoinSeps(dots ? dots : [], tokens);
31
- }
32
- export function rejectAndJoinSeps(sepTokens, elems, sep) {
33
- if (!Array.isArray(sepTokens)) {
34
- return rejectAndJoin(sepTokens, elems);
35
- }
36
- const actualElements = reject(elems);
37
- const res = [];
38
- for (let i = 0; i < sepTokens.length; i++) {
39
- res.push(actualElements[i], sepTokens[i]);
40
- if (sep) {
41
- res.push(sep);
42
- }
43
- }
44
- res.push(...actualElements.slice(sepTokens.length));
45
- return concat(res);
46
- }
47
- export function reject(elems) {
48
- return elems.filter(item => {
49
- if (typeof item === "string") {
50
- return item !== "";
51
- }
52
- // eslint-ignore next - We want the conversion to boolean!
53
- // @ts-ignore
54
- return item != false && item !== undefined;
55
- });
56
- }
57
- export function rejectSeparators(separators, elems) {
58
- const realElements = reject(elems);
59
- const realSeparators = [];
60
- for (let i = 0; i < realElements.length - 1; i++) {
61
- if (realElements[i] !== "") {
62
- realSeparators.push(separators[i]);
63
- }
64
- }
65
- return realSeparators;
66
- }
67
- export function rejectAndJoin(sep, elems) {
68
- const actualElements = reject(elems);
69
- return join(sep, actualElements);
70
- }
71
- export function rejectAndConcat(elems) {
72
- const actualElements = reject(elems);
73
- return concat(actualElements);
74
- }
75
- export function sortAnnotationIdentifier(annotations, identifiers) {
76
- let tokens = [...identifiers];
77
- if (annotations && annotations.length > 0) {
78
- tokens = [...tokens, ...annotations];
79
- }
80
- return tokens.sort((a, b) => {
81
- const startOffset1 = isCstNode(a)
82
- ? a.children.At[0].startOffset
83
- : a.startOffset;
84
- const startOffset2 = isCstNode(b)
85
- ? b.children.At[0].startOffset
86
- : b.startOffset;
87
- return startOffset1 - startOffset2;
88
- });
89
- }
90
- export function sortTokens(values) {
91
- let tokens = [];
92
- forEach(values, argument => {
93
- if (argument) {
94
- tokens = tokens.concat(argument);
95
- }
96
- });
97
- return tokens.sort((a, b) => {
98
- return a.startOffset - b.startOffset;
99
- });
100
- }
101
- export function sortNodes(values) {
102
- let nodes = [];
103
- forEach(values, argument => {
104
- if (argument) {
105
- nodes = nodes.concat(argument);
106
- }
107
- });
108
- return nodes.sort((a, b) => {
109
- const aOffset = a.location.startOffset;
110
- const bOffset = b.location.startOffset;
111
- return aOffset - bOffset;
112
- });
113
- }
114
- export function matchCategory(token, categoryName) {
115
- const labels = (token.tokenType.CATEGORIES || []).map(category => {
116
- return category.LABEL;
117
- });
118
- return labels.indexOf(categoryName) !== -1;
119
- }
120
- export function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
121
- let tokens = [...identifiers];
122
- if (annotations && annotations.length > 0) {
123
- tokens = [...tokens, ...annotations];
124
- }
125
- if (typeArguments && typeArguments.length > 0) {
126
- tokens = [...tokens, ...typeArguments];
127
- }
128
- if (dots && dots.length > 0) {
129
- tokens = [...tokens, ...dots];
130
- }
131
- return tokens.sort((a, b) => {
132
- const startOffsetA = isCstNode(a)
133
- ? a.children.At
134
- ? a.children.At[0].startOffset
135
- : a.children.Less[0].startOffset
136
- : a.startOffset;
137
- const startOffsetB = isCstNode(b)
138
- ? b.children.At
139
- ? b.children.At[0].startOffset
140
- : b.children.Less[0].startOffset
141
- : b.startOffset;
142
- return startOffsetA - startOffsetB;
143
- });
144
- }
145
- export function sortModifiers(modifiers) {
146
- let firstAnnotations = [];
147
- const otherModifiers = [];
148
- let lastAnnotations = [];
149
- let hasOtherModifier = false;
150
- /**
151
- * iterate in reverse order because we special-case
152
- * type annotations which come after all other
153
- * modifiers
154
- */
155
- forEachRight(modifiers, modifier => {
156
- const isAnnotation = modifier.children.annotation !== undefined;
157
- const isTypeAnnotation = isAnnotation &&
158
- (modifier.name === "methodModifier" ||
159
- modifier.name === "interfaceMethodModifier" ||
160
- modifier.name === "fieldModifier");
161
- if (isAnnotation) {
162
- if (isTypeAnnotation && !hasOtherModifier) {
163
- lastAnnotations.unshift(modifier);
164
- }
165
- else {
166
- firstAnnotations.unshift(modifier);
167
- }
168
- }
169
- else {
170
- otherModifiers.unshift(modifier);
171
- hasOtherModifier = true;
172
- }
173
- });
174
- /**
175
- * if there are only annotations, move everything from
176
- * lastAnnotations to firstAnnotations
177
- */
178
- if (!hasOtherModifier) {
179
- firstAnnotations = firstAnnotations.concat(lastAnnotations);
180
- lastAnnotations = [];
181
- }
182
- otherModifiers.sort((a, b) => {
183
- const modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]);
184
- const modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]);
185
- return modifierIndexA - modifierIndexB;
186
- });
187
- return [firstAnnotations, otherModifiers.concat(lastAnnotations)];
188
- }
189
- export function findDeepElementInPartsArray(item, elt) {
190
- if (Array.isArray(item)) {
191
- if (includes(item, elt)) {
192
- return true;
193
- }
194
- for (let i = 0; i < item.length; i++) {
195
- if (findDeepElementInPartsArray(item[i], elt)) {
196
- return true;
197
- }
198
- }
199
- }
200
- else {
201
- for (const key in item) {
202
- if (typeof item[key] === "object" &&
203
- findDeepElementInPartsArray(item[key], elt)) {
204
- return true;
205
- }
206
- }
207
- }
208
- return false;
209
- }
210
- export function displaySemicolon(token, params) {
211
- if (params !== undefined && params.allowEmptyStatement) {
212
- return printTokenWithComments(token);
213
- }
214
- if (!hasComments(token)) {
215
- return "";
216
- }
217
- token.image = "";
218
- return printTokenWithComments(token);
219
- }
220
- export function isExplicitLambdaParameter(ctx) {
221
- return (ctx &&
222
- ctx.lambdaParameterList &&
223
- ctx.lambdaParameterList[0] &&
224
- ctx.lambdaParameterList[0].children &&
225
- ctx.lambdaParameterList[0].children.normalLambdaParameterList);
226
- }
227
- export function getBlankLinesSeparator(ctx, separator = hardline) {
228
- if (ctx === undefined) {
229
- return [];
230
- }
231
- const separators = [];
232
- for (let i = 0; i < ctx.length - 1; i++) {
233
- const node = ctx[i];
234
- const previousRuleEndLineWithComment = hasTrailingComments(node)
235
- ? node.trailingComments[node.trailingComments.length - 1].endLine
236
- : node.location.endLine;
237
- const nextNode = ctx[i + 1];
238
- const nextRuleStartLineWithComment = hasLeadingComments(nextNode)
239
- ? nextNode.leadingComments[0].startLine
240
- : nextNode.location.startLine;
241
- if (nextRuleStartLineWithComment - previousRuleEndLineWithComment > 1) {
242
- separators.push([hardline, hardline]);
243
- }
244
- else {
245
- separators.push(separator);
246
- }
247
- }
248
- return separators;
249
- }
250
- const isTwoHardLine = (userBlankLinesSeparator) => {
251
- if (!Array.isArray(userBlankLinesSeparator)) {
252
- return false;
253
- }
254
- return (userBlankLinesSeparator.length === 2 &&
255
- userBlankLinesSeparator[0] === hardline &&
256
- userBlankLinesSeparator[1] === hardline);
257
- };
258
- function getDeclarationsSeparator(declarations, needLineDeclaration, isSemicolon) {
259
- const declarationsWithoutEmptyStatements = declarations.filter(declaration => !isSemicolon(declaration));
260
- const userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements);
261
- const additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration);
262
- const separators = [];
263
- let indexNextNotEmptyDeclaration = 0;
264
- for (let i = 0; i < declarations.length - 1; i++) {
265
- // if the empty statement has comments
266
- // we want to print them on their own line
267
- if (isSemicolon(declarations[i])) {
268
- if (hasComments(declarations[i])) {
269
- separators.push(hardline);
270
- }
271
- }
272
- else if (indexNextNotEmptyDeclaration <
273
- declarationsWithoutEmptyStatements.length - 1) {
274
- const isNextSeparatorTwoHardLine = isTwoHardLine(userBlankLinesSeparators[indexNextNotEmptyDeclaration]);
275
- const additionalSep = !isNextSeparatorTwoHardLine &&
276
- (additionalBlankLines[indexNextNotEmptyDeclaration + 1] ||
277
- additionalBlankLines[indexNextNotEmptyDeclaration])
278
- ? hardline
279
- : "";
280
- separators.push(concat([
281
- userBlankLinesSeparators[indexNextNotEmptyDeclaration],
282
- additionalSep
283
- ]));
284
- indexNextNotEmptyDeclaration += 1;
285
- }
286
- }
287
- return separators;
288
- }
289
- function needLineClassBodyDeclaration(declaration) {
290
- if (declaration.children.classMemberDeclaration === undefined) {
291
- return true;
292
- }
293
- const classMemberDeclaration = declaration.children.classMemberDeclaration[0];
294
- if (classMemberDeclaration.children.fieldDeclaration !== undefined) {
295
- const fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0];
296
- if (fieldDeclaration.children.fieldModifier !== undefined &&
297
- hasAnnotation(fieldDeclaration.children.fieldModifier) &&
298
- hasNonTrailingAnnotation(fieldDeclaration.children.fieldModifier)) {
299
- return true;
300
- }
301
- return false;
302
- }
303
- else if (classMemberDeclaration.children.Semicolon !== undefined) {
304
- return false;
305
- }
306
- return true;
307
- }
308
- function needLineInterfaceMemberDeclaration(declaration) {
309
- if (declaration.children.constantDeclaration !== undefined) {
310
- const constantDeclaration = declaration.children.constantDeclaration[0];
311
- if (constantDeclaration.children.constantModifier !== undefined &&
312
- hasAnnotation(constantDeclaration.children.constantModifier) &&
313
- hasNonTrailingAnnotation(constantDeclaration.children.constantModifier)) {
314
- return true;
315
- }
316
- return false;
317
- }
318
- else if (declaration.children.interfaceMethodDeclaration !== undefined) {
319
- const interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0];
320
- if (interfaceMethodDeclaration.children.interfaceMethodModifier !==
321
- undefined &&
322
- hasNonTrailingAnnotation(interfaceMethodDeclaration.children.interfaceMethodModifier)) {
323
- return true;
324
- }
325
- return false;
326
- }
327
- return true;
328
- }
329
- function isClassBodyDeclarationASemicolon(classBodyDeclaration) {
330
- if (classBodyDeclaration.children.classMemberDeclaration) {
331
- if (classBodyDeclaration.children.classMemberDeclaration[0].children
332
- .Semicolon !== undefined) {
333
- return true;
334
- }
335
- }
336
- return false;
337
- }
338
- function isInterfaceMemberASemicolon(interfaceMemberDeclaration) {
339
- return interfaceMemberDeclaration.children.Semicolon !== undefined;
340
- }
341
- function hasAnnotation(modifiers) {
342
- return modifiers.some(modifier => modifier.children.annotation !== undefined);
343
- }
344
- /**
345
- * Return true if there is a modifier that does not come after all other modifiers
346
- * It is useful to know if sortModifiers will add an annotation before other modifiers
347
- *
348
- * @param modifiers
349
- * @returns {boolean}
350
- */
351
- function hasNonTrailingAnnotation(modifiers) {
352
- const firstAnnotationIndex = findIndex(modifiers, modifier => modifier.children.annotation !== undefined);
353
- const lastNonAnnotationIndex = findLastIndex(modifiers, modifier => modifier.children.annotation === undefined);
354
- return (firstAnnotationIndex < lastNonAnnotationIndex ||
355
- lastNonAnnotationIndex === -1);
356
- }
357
- export function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) {
358
- return getDeclarationsSeparator(classBodyDeclarationContext, needLineClassBodyDeclaration, isClassBodyDeclarationASemicolon);
359
- }
360
- export function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) {
361
- return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon);
362
- }
363
- function getAndRemoveLeadingComment(doc) {
364
- const isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc;
365
- if (!isTokenWithLeadingComment) {
366
- return [];
367
- }
368
- const leadingComments = getTokenLeadingComments(doc);
369
- delete doc.leadingComments;
370
- return leadingComments;
371
- }
372
- export function putIntoBraces(argument, separator, LBrace, RBrace) {
373
- const rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace);
374
- const lastBreakLine =
375
- // check if last element of the array is a line
376
- rightBraceLeadingComments.length !== 0 &&
377
- rightBraceLeadingComments[rightBraceLeadingComments.length - 1] === hardline
378
- ? rightBraceLeadingComments.pop()
379
- : separator;
380
- let contentInsideBraces;
381
- if (isEmptyDoc(argument)) {
382
- if (rightBraceLeadingComments.length === 0) {
383
- return group([
384
- indent(printTokenWithComments(LBrace)),
385
- ...(LBrace.trailingComments ? [softline, lineSuffixBoundary] : []),
386
- RBrace
387
- ]);
388
- }
389
- contentInsideBraces = [separator, ...rightBraceLeadingComments];
390
- }
391
- else if (rightBraceLeadingComments.length !== 0) {
392
- contentInsideBraces = [
393
- separator,
394
- argument,
395
- separator,
396
- ...rightBraceLeadingComments
397
- ];
398
- }
399
- else {
400
- contentInsideBraces = [separator, argument];
401
- }
402
- return group(rejectAndConcat([
403
- LBrace,
404
- indent(concat(contentInsideBraces)),
405
- lastBreakLine,
406
- RBrace
407
- ]));
408
- }
409
- export function binary(nodes, tokens, isRoot = false) {
410
- let levelOperator;
411
- let levelPrecedence;
412
- let level = [];
413
- while (tokens.length) {
414
- const nextOperator = getOperator(tokens);
415
- const nextPrecedence = getOperatorPrecedence(nextOperator);
416
- if (levelPrecedence === undefined || nextPrecedence === levelPrecedence) {
417
- const tokenLength = ["<<", ">>", ">>>"].includes(nextOperator)
418
- ? nextOperator.length
419
- : 1;
420
- const operator = concat(tokens.splice(0, tokenLength));
421
- if (levelOperator !== undefined &&
422
- needsParentheses(levelOperator, nextOperator)) {
423
- level.push(nodes.shift());
424
- level = [
425
- concat(["(", group(indent(join(line, level))), ") ", operator])
426
- ];
427
- }
428
- else {
429
- level.push(join(" ", [nodes.shift(), operator]));
430
- }
431
- levelOperator = nextOperator;
432
- levelPrecedence = nextPrecedence;
433
- }
434
- else if (nextPrecedence < levelPrecedence) {
435
- level.push(nodes.shift());
436
- if (isRoot) {
437
- const content = group(indent(join(line, level)));
438
- nodes.unshift(levelOperator !== undefined &&
439
- needsParentheses(levelOperator, nextOperator)
440
- ? concat(["(", content, ")"])
441
- : content);
442
- level = [];
443
- levelOperator = undefined;
444
- levelPrecedence = undefined;
445
- }
446
- else {
447
- return group(join(line, level));
448
- }
449
- }
450
- else {
451
- const content = binary(nodes, tokens);
452
- nodes.unshift(levelOperator !== undefined &&
453
- needsParentheses(nextOperator, levelOperator)
454
- ? concat(["(", indent(content), ")"])
455
- : content);
456
- }
457
- }
458
- level.push(nodes.shift());
459
- return group(join(line, level));
460
- }
461
- export function getOperators(ctx) {
462
- return [
463
- ctx.AssignmentOperator,
464
- ctx.BinaryOperator,
465
- ctx.Greater,
466
- ctx.Instanceof,
467
- ctx.Less
468
- ].filter(token => token !== undefined);
469
- }
470
- function getOperator(tokens) {
471
- if (!tokens.length) {
472
- return "";
473
- }
474
- const [{ image, startOffset }] = tokens;
475
- if (!["<", ">"].includes(image)) {
476
- return image;
477
- }
478
- let repeatedTokenCount = 1;
479
- for (let i = 1; i < Math.min(3, tokens.length); i++) {
480
- const token = tokens[i];
481
- if (token.image !== image || token.startOffset !== startOffset + i) {
482
- break;
483
- }
484
- repeatedTokenCount++;
485
- }
486
- if (repeatedTokenCount === 1) {
487
- return image;
488
- }
489
- if (image === "<") {
490
- return "<<";
491
- }
492
- else if (repeatedTokenCount == 2) {
493
- return ">>";
494
- }
495
- else {
496
- return ">>>";
497
- }
498
- }
499
- const PRECEDENCES_BY_OPERATOR = new Map([
500
- ["||"],
501
- ["&&"],
502
- ["|"],
503
- ["^"],
504
- ["&"],
505
- ["==", "!="],
506
- ["<", ">", "<=", ">=", "instanceof"],
507
- ["<<", ">>", ">>>"],
508
- ["+", "-"],
509
- ["*", "/", "%"]
510
- ].flatMap((operators, index) => operators.map(operator => [operator, index])));
511
- function getOperatorPrecedence(operator) {
512
- var _a;
513
- return (_a = PRECEDENCES_BY_OPERATOR.get(operator)) !== null && _a !== void 0 ? _a : -1;
514
- }
515
- function needsParentheses(operator, parentOperator) {
516
- return ((operator === "&&" && parentOperator === "||") ||
517
- (["|", "^", "&", "<<", ">>", ">>>"].includes(parentOperator) &&
518
- getOperatorPrecedence(operator) >
519
- getOperatorPrecedence(parentOperator)) ||
520
- [operator, parentOperator].every(o => ["==", "!="].includes(o)) ||
521
- [operator, parentOperator].every(o => ["<<", ">>", ">>>"].includes(o)) ||
522
- (operator === "*" && parentOperator === "/") ||
523
- (operator === "/" && parentOperator === "*") ||
524
- (operator === "%" && ["+", "-", "*", "/"].includes(parentOperator)) ||
525
- (["*", "/"].includes(operator) && parentOperator === "%"));
526
- }
527
- export function isStatementEmptyStatement(statement) {
528
- return (statement === ";" || (Array.isArray(statement) && statement[0] === ";"));
529
- }
530
- export function sortImports(imports) {
531
- const staticImports = [];
532
- const nonStaticImports = [];
533
- if (imports !== undefined) {
534
- for (let i = 0; i < imports.length; i++) {
535
- if (imports[i].children.Static !== undefined) {
536
- staticImports.push(imports[i]);
537
- }
538
- else if (imports[i].children.emptyStatement === undefined) {
539
- nonStaticImports.push(imports[i]);
540
- }
541
- }
542
- // TODO: Could be optimized as we could expect that the array is already almost sorted
543
- const comparator = (first, second) => compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]);
544
- staticImports.sort(comparator);
545
- nonStaticImports.sort(comparator);
546
- }
547
- return {
548
- staticImports,
549
- nonStaticImports
550
- };
551
- }
552
- function compareFqn(packageOrTypeNameFirst, packageOrTypeNameSecond) {
553
- const identifiersFirst = packageOrTypeNameFirst.children.Identifier;
554
- const identifiersSecond = packageOrTypeNameSecond.children.Identifier;
555
- const minParts = Math.min(identifiersFirst.length, identifiersSecond.length);
556
- for (let i = 0; i < minParts; i++) {
557
- if (identifiersFirst[i].image < identifiersSecond[i].image) {
558
- return -1;
559
- }
560
- else if (identifiersFirst[i].image > identifiersSecond[i].image) {
561
- return 1;
562
- }
563
- }
564
- if (identifiersFirst.length < identifiersSecond.length) {
565
- return -1;
566
- }
567
- else if (identifiersFirst.length > identifiersSecond.length) {
568
- return 1;
569
- }
570
- return 0;
571
- }
572
- export function isUniqueMethodInvocation(primarySuffixes) {
573
- if (primarySuffixes === undefined) {
574
- return 0;
575
- }
576
- let count = 0;
577
- primarySuffixes.forEach(primarySuffix => {
578
- if (primarySuffix.children.methodInvocationSuffix !== undefined) {
579
- count++;
580
- if (count > 1) {
581
- return 2;
582
- }
583
- }
584
- });
585
- return count;
586
- }
587
- export function printArrayList({ list, extraComma, LCurly, RCurly, trailingComma }) {
588
- let optionalComma;
589
- if (trailingComma !== "none" && list !== "") {
590
- optionalComma = extraComma
591
- ? ifBreak(extraComma[0], Object.assign(Object.assign({}, extraComma[0]), { image: "" }))
592
- : ifBreak(",", "");
593
- }
594
- else {
595
- optionalComma = extraComma ? Object.assign(Object.assign({}, extraComma[0]), { image: "" }) : "";
596
- }
597
- return putIntoBraces(rejectAndConcat([list, optionalComma]), line, LCurly, RCurly);
598
- }
@@ -1,20 +0,0 @@
1
- export function isCstNode(tokenOrNode) {
2
- return !isIToken(tokenOrNode);
3
- }
4
- export function isIToken(tokenOrNode) {
5
- return (tokenOrNode.tokenType !== undefined &&
6
- tokenOrNode.image !== undefined);
7
- }
8
- export function isCstElementOrUndefinedIToken(tokenOrNode) {
9
- return tokenOrNode !== undefined && isIToken(tokenOrNode);
10
- }
11
- export const isTypeArgumentsCstNode = (cstElement) => {
12
- return cstElement.name === "typeArguments";
13
- };
14
- export const isAnnotationCstNode = (cstElement) => {
15
- return cstElement.name === "annotation";
16
- };
17
- export const isOrdinaryCompilationUnitCtx = (ctx) => {
18
- return (ctx.ordinaryCompilationUnit !==
19
- undefined);
20
- };
@@ -1,25 +0,0 @@
1
- export function isArgumentListSingleLambda(argumentList) {
2
- if (argumentList === undefined) {
3
- return false;
4
- }
5
- const args = argumentList[0].children.expression;
6
- if (args.length !== 1) {
7
- return false;
8
- }
9
- const argument = args[0];
10
- return argument.children.lambdaExpression !== undefined;
11
- }
12
- export const isSingleArgumentLambdaExpressionWithBlock = (argumentList) => {
13
- if (argumentList === undefined) {
14
- return false;
15
- }
16
- const args = argumentList[0].children.expression;
17
- if (args.length !== 1) {
18
- return false;
19
- }
20
- const argument = args[0];
21
- return (argument.children.lambdaExpression !== undefined &&
22
- argument.children.lambdaExpression[0].children.lambdaBody[0].children
23
- .block !== undefined);
24
- };
25
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhwcmVzc2lvbnMtdXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvZXhwcmVzc2lvbnMtdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsTUFBTSxVQUFVLDBCQUEwQixDQUN4QyxZQUErQztJQUUvQyxJQUFJLFlBQVksS0FBSyxTQUFTLEVBQUU7UUFDOUIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUFDO0lBQ2pELElBQUksSUFBSSxDQUFDLE1BQU0sS0FBSyxDQUFDLEVBQUU7UUFDckIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sUUFBUSxHQUFHLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN6QixPQUFPLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUyxDQUFDO0FBQzFELENBQUM7QUFFRCxNQUFNLENBQUMsTUFBTSx5Q0FBeUMsR0FBRyxDQUN2RCxZQUErQyxFQUMvQyxFQUFFO0lBQ0YsSUFBSSxZQUFZLEtBQUssU0FBUyxFQUFFO1FBQzlCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLElBQUksR0FBRyxZQUFZLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLFVBQVUsQ0FBQztJQUNqRCxJQUFJLElBQUksQ0FBQyxNQUFNLEtBQUssQ0FBQyxFQUFFO1FBQ3JCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLFFBQVEsR0FBRyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDekIsT0FBTyxDQUNMLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUztRQUNoRCxRQUFRLENBQUMsUUFBUSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUTthQUNsRSxLQUFLLEtBQUssU0FBUyxDQUN2QixDQUFDO0FBQ0osQ0FBQyxDQUFDIn0=
@@ -1,2 +0,0 @@
1
- export { default as printArgumentListWithBraces } from "./printArgumentListWithBraces.js";
2
- export { default as isEmptyDoc } from "./isEmptyDoc.js";
@@ -1,4 +0,0 @@
1
- const isEmptyDoc = (argument) => {
2
- return argument === "" || (Array.isArray(argument) && argument.length) === 0;
3
- };
4
- export default isEmptyDoc;
@@ -1,37 +0,0 @@
1
- import { builders } from "prettier/doc";
2
- import { handleCommentsParameters } from "../printers/comments/handle-comments.js";
3
- import { indent } from "../printers/prettier-builder.js";
4
- import { rejectAndConcat } from "../printers/printer-utils.js";
5
- const { lineSuffixBoundary, softline } = builders;
6
- export default function printArgumentListWithBraces(argumentListNodes, rBrace, lBrace) {
7
- var _a, _b, _c;
8
- const argumentListNode = argumentListNodes === null || argumentListNodes === void 0 ? void 0 : argumentListNodes[0];
9
- const expressions = (_a = argumentListNode === null || argumentListNode === void 0 ? void 0 : argumentListNode.children.expression) !== null && _a !== void 0 ? _a : [];
10
- if (argumentListNode) {
11
- const { leadingComments, trailingComments } = argumentListNode;
12
- delete argumentListNode.leadingComments;
13
- delete argumentListNode.trailingComments;
14
- if (leadingComments) {
15
- const firstExpression = expressions[0];
16
- firstExpression.leadingComments = [
17
- ...leadingComments,
18
- ...((_b = firstExpression.leadingComments) !== null && _b !== void 0 ? _b : [])
19
- ];
20
- }
21
- if (trailingComments) {
22
- const lastExpression = expressions.at(-1);
23
- lastExpression.trailingComments = [
24
- ...((_c = lastExpression.trailingComments) !== null && _c !== void 0 ? _c : []),
25
- ...trailingComments
26
- ];
27
- }
28
- }
29
- handleCommentsParameters(lBrace, expressions, rBrace);
30
- const argumentList = this.visit(argumentListNodes);
31
- const contents = argumentList
32
- ? [argumentList]
33
- : lBrace.trailingComments
34
- ? [softline, lineSuffixBoundary]
35
- : [];
36
- return rejectAndConcat([indent(lBrace), ...contents, rBrace]);
37
- }