prettier-plugin-java 1.3.0 → 1.6.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 (46) hide show
  1. package/dist/base-cst-printer.js +77 -0
  2. package/dist/cst-printer.js +37 -0
  3. package/dist/index.js +67 -0
  4. package/dist/options.js +256 -0
  5. package/dist/parser.js +7 -0
  6. package/dist/printer.js +28 -0
  7. package/dist/printers/arrays.js +49 -0
  8. package/dist/printers/blocks-and-statements.js +493 -0
  9. package/dist/printers/classes.js +724 -0
  10. package/dist/printers/comments/comments-utils.js +29 -0
  11. package/dist/printers/comments/format-comments.js +179 -0
  12. package/dist/printers/comments/handle-comments.js +38 -0
  13. package/dist/printers/expressions.js +549 -0
  14. package/dist/printers/interfaces.js +251 -0
  15. package/dist/printers/lexical-structure.js +43 -0
  16. package/dist/printers/names.js +53 -0
  17. package/dist/printers/packages-and-modules.js +185 -0
  18. package/dist/printers/prettier-builder.js +44 -0
  19. package/dist/printers/printer-utils.js +565 -0
  20. package/dist/printers/types-values-and-variables.js +183 -0
  21. package/dist/types/utils.js +29 -0
  22. package/dist/utils/expressions-utils.js +29 -0
  23. package/dist/utils/index.js +10 -0
  24. package/dist/utils/printArgumentListWithBraces.js +21 -0
  25. package/dist/utils/printSingleLambdaInvocation.js +20 -0
  26. package/package.json +32 -10
  27. package/src/cst-printer.js +0 -145
  28. package/src/index.js +0 -79
  29. package/src/options.js +0 -256
  30. package/src/parser.js +0 -10
  31. package/src/printer.js +0 -31
  32. package/src/printers/arrays.js +0 -38
  33. package/src/printers/blocks-and-statements.js +0 -588
  34. package/src/printers/classes.js +0 -940
  35. package/src/printers/comments/comments-utils.js +0 -38
  36. package/src/printers/comments/format-comments.js +0 -223
  37. package/src/printers/comments/handle-comments.js +0 -50
  38. package/src/printers/expressions.js +0 -703
  39. package/src/printers/interfaces.js +0 -324
  40. package/src/printers/lexical-structure.js +0 -27
  41. package/src/printers/names.js +0 -42
  42. package/src/printers/packages-and-modules.js +0 -231
  43. package/src/printers/prettier-builder.js +0 -60
  44. package/src/printers/printer-utils.js +0 -715
  45. package/src/printers/types-values-and-variables.js +0 -202
  46. package/yarn-error.log +0 -8052
@@ -1,703 +0,0 @@
1
- "use strict";
2
-
3
- const forEach = require("lodash/forEach");
4
- const { ifBreak, line, softline } = require("prettier").doc.builders;
5
- const { concat, group, indent, dedent } = require("./prettier-builder");
6
- const { printTokenWithComments } = require("./comments/format-comments");
7
- const {
8
- handleCommentsBinaryExpression
9
- } = require("./comments/handle-comments");
10
- const {
11
- matchCategory,
12
- rejectAndJoin,
13
- rejectAndConcat,
14
- sortAnnotationIdentifier,
15
- sortNodes,
16
- rejectAndJoinSeps,
17
- findDeepElementInPartsArray,
18
- isExplicitLambdaParameter,
19
- putIntoBraces,
20
- separateTokensIntoGroups,
21
- isShiftOperator,
22
- isUniqueMethodInvocation
23
- } = require("./printer-utils");
24
-
25
- class ExpressionsPrettierVisitor {
26
- expression(ctx, params) {
27
- return this.visitSingle(ctx, params);
28
- }
29
-
30
- lambdaExpression(ctx) {
31
- const lambdaParameters = this.visit(ctx.lambdaParameters);
32
- const lambdaBody = this.visit(ctx.lambdaBody);
33
-
34
- const isLambdaBodyABlock = ctx.lambdaBody[0].children.block !== undefined;
35
- if (isLambdaBodyABlock) {
36
- return rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0], lambdaBody]);
37
- }
38
-
39
- return group(
40
- indent(
41
- rejectAndJoin(line, [
42
- rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0]]),
43
- lambdaBody
44
- ])
45
- )
46
- );
47
- }
48
-
49
- lambdaParameters(ctx) {
50
- if (ctx.lambdaParametersWithBraces) {
51
- return this.visitSingle(ctx);
52
- }
53
-
54
- return printTokenWithComments(this.getSingle(ctx));
55
- }
56
-
57
- lambdaParametersWithBraces(ctx) {
58
- const lambdaParameterList = this.visit(ctx.lambdaParameterList);
59
-
60
- if (findDeepElementInPartsArray(lambdaParameterList, ",")) {
61
- return rejectAndConcat([
62
- ctx.LBrace[0],
63
- lambdaParameterList,
64
- ctx.RBrace[0]
65
- ]);
66
- }
67
-
68
- // removing braces when only no comments attached
69
- if (
70
- (ctx.LBrace &&
71
- ctx.RBrace &&
72
- (!lambdaParameterList || isExplicitLambdaParameter(ctx))) ||
73
- ctx.LBrace[0].leadingComments ||
74
- ctx.LBrace[0].trailingComments ||
75
- ctx.RBrace[0].leadingComments ||
76
- ctx.RBrace[0].trailingComments
77
- ) {
78
- return rejectAndConcat([
79
- ctx.LBrace[0],
80
- lambdaParameterList,
81
- ctx.RBrace[0]
82
- ]);
83
- }
84
-
85
- return lambdaParameterList;
86
- }
87
-
88
- lambdaParameterList(ctx) {
89
- return this.visitSingle(ctx);
90
- }
91
-
92
- inferredLambdaParameterList(ctx) {
93
- const commas = ctx.Comma
94
- ? ctx.Comma.map(elt => {
95
- return concat([elt, " "]);
96
- })
97
- : [];
98
-
99
- return rejectAndJoinSeps(commas, ctx.Identifier);
100
- }
101
-
102
- explicitLambdaParameterList(ctx) {
103
- const lambdaParameter = this.mapVisit(ctx.lambdaParameter);
104
- const commas = ctx.Comma
105
- ? ctx.Comma.map(elt => {
106
- return concat([elt, " "]);
107
- })
108
- : [];
109
- return rejectAndJoinSeps(commas, lambdaParameter);
110
- }
111
-
112
- lambdaParameter(ctx) {
113
- return this.visitSingle(ctx);
114
- }
115
-
116
- regularLambdaParameter(ctx) {
117
- const variableModifier = this.mapVisit(ctx.variableModifier);
118
- const lambdaParameterType = this.visit(ctx.lambdaParameterType);
119
- const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
120
-
121
- return rejectAndJoin(" ", [
122
- rejectAndJoin(" ", variableModifier),
123
- lambdaParameterType,
124
- variableDeclaratorId
125
- ]);
126
- }
127
-
128
- lambdaParameterType(ctx) {
129
- if (ctx.unannType) {
130
- return this.visitSingle(ctx);
131
- }
132
- return printTokenWithComments(this.getSingle(ctx));
133
- }
134
-
135
- lambdaBody(ctx) {
136
- return this.visitSingle(ctx);
137
- }
138
-
139
- ternaryExpression(ctx, params) {
140
- const binaryExpression = this.visit(ctx.binaryExpression, params);
141
- if (ctx.QuestionMark) {
142
- const expression1 = this.visit(ctx.expression[0]);
143
- const expression2 = this.visit(ctx.expression[1]);
144
-
145
- return indent(
146
- group(
147
- rejectAndConcat([
148
- rejectAndJoin(line, [
149
- binaryExpression,
150
- rejectAndJoin(" ", [ctx.QuestionMark[0], expression1]),
151
- rejectAndJoin(" ", [ctx.Colon[0], expression2])
152
- ])
153
- ])
154
- )
155
- );
156
- }
157
- return binaryExpression;
158
- }
159
-
160
- binaryExpression(ctx, params) {
161
- handleCommentsBinaryExpression(ctx);
162
-
163
- const instanceofReferences = this.mapVisit(
164
- sortNodes(ctx.pattern, ctx.referenceType)
165
- );
166
- const expression = this.mapVisit(ctx.expression);
167
- const unaryExpression = this.mapVisit(ctx.unaryExpression);
168
-
169
- const { groupsOfOperator, sortedBinaryOperators } =
170
- separateTokensIntoGroups(ctx);
171
- const segmentsSplitByBinaryOperator = [];
172
- let currentSegment = [];
173
-
174
- if (groupsOfOperator.length === 1 && groupsOfOperator[0].length === 0) {
175
- return unaryExpression.shift();
176
- }
177
-
178
- groupsOfOperator.forEach(subgroup => {
179
- currentSegment = [unaryExpression.shift()];
180
- for (let i = 0; i < subgroup.length; i++) {
181
- const token = subgroup[i];
182
- const shiftOperator = isShiftOperator(subgroup, i);
183
- if (token.tokenType.name === "Instanceof") {
184
- currentSegment.push(
185
- rejectAndJoin(" ", [
186
- ctx.Instanceof[0],
187
- instanceofReferences.shift()
188
- ])
189
- );
190
- } else if (matchCategory(token, "'AssignmentOperator'")) {
191
- currentSegment.push(
192
- indent(rejectAndJoin(line, [token, expression.shift()]))
193
- );
194
- } else if (
195
- shiftOperator === "leftShift" ||
196
- shiftOperator === "rightShift"
197
- ) {
198
- currentSegment.push(
199
- rejectAndJoin(" ", [
200
- rejectAndConcat([token, subgroup[i + 1]]),
201
- unaryExpression.shift()
202
- ])
203
- );
204
- i++;
205
- } else if (shiftOperator === "doubleRightShift") {
206
- currentSegment.push(
207
- rejectAndJoin(" ", [
208
- rejectAndConcat([token, subgroup[i + 1], subgroup[i + 2]]),
209
- unaryExpression.shift()
210
- ])
211
- );
212
- i += 2;
213
- } else if (matchCategory(token, "'BinaryOperator'")) {
214
- currentSegment.push(
215
- rejectAndJoin(line, [token, unaryExpression.shift()])
216
- );
217
- }
218
- }
219
- segmentsSplitByBinaryOperator.push(
220
- group(rejectAndJoin(" ", currentSegment))
221
- );
222
- });
223
-
224
- if (params !== undefined && params.addParenthesisToWrapStatement) {
225
- return group(
226
- concat([
227
- ifBreak("(", ""),
228
- indent(
229
- concat([
230
- softline,
231
- group(
232
- rejectAndJoinSeps(
233
- sortedBinaryOperators.map(elt => concat([" ", elt, line])),
234
- segmentsSplitByBinaryOperator
235
- )
236
- )
237
- ])
238
- ),
239
- softline,
240
- ifBreak(")")
241
- ])
242
- );
243
- }
244
-
245
- return group(
246
- rejectAndJoinSeps(
247
- sortedBinaryOperators.map(elt => concat([" ", elt, line])),
248
- segmentsSplitByBinaryOperator
249
- )
250
- );
251
- }
252
-
253
- unaryExpression(ctx) {
254
- const unaryPrefixOperator = ctx.UnaryPrefixOperator
255
- ? ctx.UnaryPrefixOperator
256
- : [];
257
- const primary = this.visit(ctx.primary);
258
- const unarySuffixOperator = ctx.UnarySuffixOperator
259
- ? ctx.UnarySuffixOperator
260
- : [];
261
- return rejectAndConcat([
262
- rejectAndConcat(unaryPrefixOperator),
263
- primary,
264
- rejectAndConcat(unarySuffixOperator)
265
- ]);
266
- }
267
-
268
- unaryExpressionNotPlusMinus(ctx) {
269
- const unaryPrefixOperatorNotPlusMinus = ctx.unaryPrefixOperatorNotPlusMinus
270
- ? rejectAndJoin(" ", ctx.unaryPrefixOperatorNotPlusMinus)
271
- : "";
272
-
273
- const primary = this.visit(ctx.primary);
274
- const unarySuffixOperator = ctx.unarySuffixOperator
275
- ? rejectAndJoin(" ", ctx.unarySuffixOperator)
276
- : "";
277
-
278
- return rejectAndJoin(" ", [
279
- unaryPrefixOperatorNotPlusMinus,
280
- primary,
281
- unarySuffixOperator
282
- ]);
283
- }
284
-
285
- primary(ctx) {
286
- const countMethodInvocation = isUniqueMethodInvocation(ctx.primarySuffix);
287
-
288
- const primaryPrefix = this.visit(ctx.primaryPrefix, {
289
- shouldBreakBeforeFirstMethodInvocation: countMethodInvocation > 1
290
- });
291
-
292
- const suffixes = [];
293
-
294
- if (ctx.primarySuffix !== undefined) {
295
- // edge case: https://github.com/jhipster/prettier-java/issues/381
296
- let hasFirstInvocationArg = true;
297
-
298
- if (
299
- ctx.primarySuffix.length > 1 &&
300
- ctx.primarySuffix[1].children.methodInvocationSuffix &&
301
- Object.keys(
302
- ctx.primarySuffix[1].children.methodInvocationSuffix[0].children
303
- ).length === 2
304
- ) {
305
- hasFirstInvocationArg = false;
306
- }
307
-
308
- if (
309
- ctx.primarySuffix[0].children.Dot !== undefined &&
310
- ctx.primaryPrefix[0].children.newExpression !== undefined
311
- ) {
312
- suffixes.push(softline);
313
- }
314
- suffixes.push(
315
- this.visit(ctx.primarySuffix[0], {
316
- shouldDedent:
317
- // dedent when simple method invocation
318
- countMethodInvocation !== 1 &&
319
- // dedent when (chain) method invocation
320
- ctx.primaryPrefix[0] &&
321
- ctx.primaryPrefix[0].children.fqnOrRefType &&
322
- !(
323
- ctx.primaryPrefix[0].children.fqnOrRefType[0].children.Dot !==
324
- undefined
325
- ) &&
326
- // indent when lambdaExpression
327
- ctx.primarySuffix[0].children.methodInvocationSuffix &&
328
- ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
329
- .argumentList &&
330
- ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
331
- .argumentList[0].children.expression &&
332
- ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
333
- .argumentList[0].children.expression[0].children
334
- .lambdaExpression === undefined
335
- })
336
- );
337
-
338
- for (let i = 1; i < ctx.primarySuffix.length; i++) {
339
- if (
340
- ctx.primarySuffix[i].children.Dot !== undefined &&
341
- ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined
342
- ) {
343
- suffixes.push(softline);
344
- }
345
- suffixes.push(this.visit(ctx.primarySuffix[i]));
346
- }
347
-
348
- if (
349
- countMethodInvocation === 1 &&
350
- ctx.primaryPrefix[0].children.newExpression === undefined
351
- ) {
352
- return group(
353
- rejectAndConcat([
354
- primaryPrefix,
355
- hasFirstInvocationArg ? suffixes[0] : indent(suffixes[0]),
356
- indent(rejectAndConcat(suffixes.slice(1)))
357
- ])
358
- );
359
- }
360
- }
361
-
362
- return group(
363
- rejectAndConcat([primaryPrefix, indent(rejectAndConcat(suffixes))])
364
- );
365
- }
366
-
367
- primaryPrefix(ctx, params) {
368
- if (ctx.This || ctx.Void) {
369
- return printTokenWithComments(this.getSingle(ctx));
370
- }
371
-
372
- return this.visitSingle(ctx, params);
373
- }
374
-
375
- primarySuffix(ctx, params) {
376
- if (ctx.Dot) {
377
- if (ctx.This) {
378
- return rejectAndConcat([ctx.Dot[0], ctx.This[0]]);
379
- } else if (ctx.Identifier) {
380
- const typeArguments = this.visit(ctx.typeArguments);
381
- return rejectAndConcat([ctx.Dot[0], typeArguments, ctx.Identifier[0]]);
382
- }
383
-
384
- const unqualifiedClassInstanceCreationExpression = this.visit(
385
- ctx.unqualifiedClassInstanceCreationExpression
386
- );
387
- return rejectAndConcat([
388
- ctx.Dot[0],
389
- unqualifiedClassInstanceCreationExpression
390
- ]);
391
- }
392
- return this.visitSingle(ctx, params);
393
- }
394
-
395
- fqnOrRefType(ctx, params) {
396
- const fqnOrRefTypePartFirst = this.visit(ctx.fqnOrRefTypePartFirst);
397
- const fqnOrRefTypePartRest = this.mapVisit(ctx.fqnOrRefTypePartRest);
398
- const dims = this.visit(ctx.dims);
399
- const dots = ctx.Dot ? ctx.Dot : [];
400
- const isMethodInvocation = ctx.Dot && ctx.Dot.length === 1;
401
-
402
- if (
403
- params !== undefined &&
404
- params.shouldBreakBeforeFirstMethodInvocation === true
405
- ) {
406
- // when fqnOrRefType is a method call from an object
407
- if (isMethodInvocation) {
408
- return rejectAndConcat([
409
- indent(
410
- rejectAndJoin(concat([softline, dots[0]]), [
411
- fqnOrRefTypePartFirst,
412
- rejectAndJoinSeps(dots.slice(1), fqnOrRefTypePartRest),
413
- dims
414
- ])
415
- )
416
- ]);
417
- // otherwise it is a fully qualified name but we need to exclude when it is just a method call
418
- } else if (ctx.Dot) {
419
- return indent(
420
- rejectAndConcat([
421
- rejectAndJoinSeps(dots.slice(0, dots.length - 1), [
422
- fqnOrRefTypePartFirst,
423
- ...fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1)
424
- ]),
425
- softline,
426
- rejectAndConcat([
427
- dots[dots.length - 1],
428
- fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1]
429
- ]),
430
- dims
431
- ])
432
- );
433
- }
434
- }
435
-
436
- return rejectAndConcat([
437
- rejectAndJoinSeps(dots, [fqnOrRefTypePartFirst, ...fqnOrRefTypePartRest]),
438
- dims
439
- ]);
440
- }
441
-
442
- fqnOrRefTypePartFirst(ctx) {
443
- const annotation = this.mapVisit(ctx.annotation);
444
- const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
445
-
446
- return rejectAndJoin(" ", [
447
- rejectAndJoin(" ", annotation),
448
- fqnOrRefTypeCommon
449
- ]);
450
- }
451
-
452
- fqnOrRefTypePartRest(ctx) {
453
- const annotation = this.mapVisit(ctx.annotation);
454
- const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
455
-
456
- let fqnOrRefTypePart$methodTypeArguments = "";
457
- if (
458
- ctx.$methodTypeArguments &&
459
- ctx.$methodTypeArguments[0].children &&
460
- ctx.$methodTypeArguments[0].children.typeArguments
461
- ) {
462
- fqnOrRefTypePart$methodTypeArguments = this.visit(
463
- ctx.$methodTypeArguments
464
- );
465
- }
466
-
467
- return rejectAndJoin(" ", [
468
- rejectAndJoin(" ", annotation),
469
- rejectAndConcat([
470
- fqnOrRefTypePart$methodTypeArguments,
471
- fqnOrRefTypeCommon
472
- ])
473
- ]);
474
- }
475
-
476
- fqnOrRefTypePartCommon(ctx) {
477
- let keyWord = null;
478
- if (ctx.Identifier) {
479
- keyWord = ctx.Identifier[0];
480
- } else {
481
- keyWord = ctx.Super[0];
482
- }
483
-
484
- let fqnOrRefTypePart$classTypeArguments = "";
485
- if (
486
- ctx.$classTypeArguments &&
487
- ctx.$classTypeArguments[0].children &&
488
- ctx.$classTypeArguments[0].children.typeArguments
489
- ) {
490
- fqnOrRefTypePart$classTypeArguments = this.visit(ctx.$classTypeArguments);
491
- }
492
-
493
- return rejectAndConcat([keyWord, fqnOrRefTypePart$classTypeArguments]);
494
- }
495
-
496
- fqnOrRefTypePartRest$methodTypeArguments(ctx) {
497
- return this.visitSingle(ctx);
498
- }
499
-
500
- fqnOrRefTypePartCommon$classTypeArguments(ctx) {
501
- return this.visitSingle(ctx);
502
- }
503
-
504
- parenthesisExpression(ctx) {
505
- const expression = this.visit(ctx.expression);
506
- return putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]);
507
- }
508
-
509
- castExpression(ctx) {
510
- return this.visitSingle(ctx);
511
- }
512
-
513
- primitiveCastExpression(ctx) {
514
- const primitiveType = this.visit(ctx.primitiveType);
515
- const unaryExpression = this.visit(ctx.unaryExpression);
516
- return rejectAndJoin(" ", [
517
- rejectAndConcat([ctx.LBrace[0], primitiveType, ctx.RBrace[0]]),
518
- unaryExpression
519
- ]);
520
- }
521
-
522
- referenceTypeCastExpression(ctx) {
523
- const referenceType = this.visit(ctx.referenceType);
524
- const additionalBound = this.mapVisit(ctx.additionalBound);
525
-
526
- const expression = ctx.lambdaExpression
527
- ? this.visit(ctx.lambdaExpression)
528
- : this.visit(ctx.unaryExpressionNotPlusMinus);
529
-
530
- return rejectAndJoin(" ", [
531
- rejectAndConcat([ctx.LBrace[0], referenceType, ctx.RBrace[0]]),
532
- additionalBound,
533
- expression
534
- ]);
535
- }
536
-
537
- newExpression(ctx) {
538
- return this.visitSingle(ctx);
539
- }
540
-
541
- unqualifiedClassInstanceCreationExpression(ctx) {
542
- const typeArguments = this.visit(ctx.typeArguments);
543
- const classOrInterfaceTypeToInstantiate = this.visit(
544
- ctx.classOrInterfaceTypeToInstantiate
545
- );
546
- const argumentList = this.visit(ctx.argumentList);
547
- const classBody = this.visit(ctx.classBody);
548
-
549
- return rejectAndJoin(" ", [
550
- ctx.New[0],
551
- rejectAndConcat([
552
- typeArguments,
553
- classOrInterfaceTypeToInstantiate,
554
- putIntoBraces(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0])
555
- ]),
556
- classBody
557
- ]);
558
- }
559
-
560
- classOrInterfaceTypeToInstantiate(ctx) {
561
- const tokens = sortAnnotationIdentifier(ctx.annotation, ctx.Identifier);
562
-
563
- const segments = [];
564
- let currentSegment = [];
565
-
566
- forEach(tokens, token => {
567
- if (token.name) {
568
- currentSegment.push(this.visit([token]));
569
- } else {
570
- currentSegment.push(token);
571
- segments.push(rejectAndJoin(" ", currentSegment));
572
- currentSegment = [];
573
- }
574
- });
575
-
576
- const typeArgumentsOrDiamond = this.visit(ctx.typeArgumentsOrDiamond);
577
- const dots = ctx.Dot ? ctx.Dot : [];
578
- return rejectAndConcat([
579
- rejectAndJoinSeps(dots, segments),
580
- typeArgumentsOrDiamond
581
- ]);
582
- }
583
-
584
- typeArgumentsOrDiamond(ctx) {
585
- return this.visitSingle(ctx);
586
- }
587
-
588
- diamond(ctx) {
589
- return concat([ctx.Less[0], ctx.Greater[0]]);
590
- }
591
-
592
- methodInvocationSuffix(ctx, params) {
593
- const argumentList = this.visit(ctx.argumentList);
594
- if (params && params.shouldDedent) {
595
- return dedent(
596
- putIntoBraces(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0])
597
- );
598
- }
599
- return putIntoBraces(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
600
- }
601
-
602
- argumentList(ctx) {
603
- const expressions = this.mapVisit(ctx.expression);
604
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
605
- return rejectAndJoinSeps(commas, expressions);
606
- }
607
-
608
- arrayCreationExpression(ctx) {
609
- const type = ctx.primitiveType
610
- ? this.visit(ctx.primitiveType)
611
- : this.visit(ctx.classOrInterfaceType);
612
- const suffix = ctx.arrayCreationDefaultInitSuffix
613
- ? this.visit(ctx.arrayCreationDefaultInitSuffix)
614
- : this.visit(ctx.arrayCreationExplicitInitSuffix);
615
-
616
- return rejectAndConcat([concat([ctx.New[0], " "]), type, suffix]);
617
- }
618
-
619
- arrayCreationDefaultInitSuffix(ctx) {
620
- const dimExprs = this.visit(ctx.dimExprs);
621
- const dims = this.visit(ctx.dims);
622
- return rejectAndConcat([dimExprs, dims]);
623
- }
624
-
625
- arrayCreationExplicitInitSuffix(ctx) {
626
- const dims = this.visit(ctx.dims);
627
- const arrayInitializer = this.visit(ctx.arrayInitializer);
628
-
629
- return rejectAndJoin(" ", [dims, arrayInitializer]);
630
- }
631
-
632
- dimExprs(ctx) {
633
- const dimExpr = this.mapVisit(ctx.dimExpr);
634
- return rejectAndConcat(dimExpr);
635
- }
636
-
637
- dimExpr(ctx) {
638
- const annotations = this.mapVisit(ctx.annotation);
639
- const expression = this.visit(ctx.expression);
640
-
641
- return rejectAndJoin(" ", [
642
- rejectAndJoin(" ", annotations),
643
- rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]])
644
- ]);
645
- }
646
-
647
- classLiteralSuffix(ctx) {
648
- const squares = [];
649
- if (ctx.LSquare) {
650
- for (let i = 0; i < ctx.LSquare.length; i++) {
651
- squares.push(concat([ctx.LSquare[i], ctx.RSquare[i]]));
652
- }
653
- }
654
- return rejectAndConcat([...squares, ctx.Dot[0], ctx.Class[0]]);
655
- }
656
-
657
- arrayAccessSuffix(ctx) {
658
- const expression = this.visit(ctx.expression);
659
- return rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]]);
660
- }
661
-
662
- methodReferenceSuffix(ctx) {
663
- const typeArguments = this.visit(ctx.typeArguments);
664
- const identifierOrNew = ctx.New ? ctx.New[0] : ctx.Identifier[0];
665
- return rejectAndConcat([ctx.ColonColon[0], typeArguments, identifierOrNew]);
666
- }
667
-
668
- pattern(ctx) {
669
- return this.visitSingle(ctx);
670
- }
671
-
672
- typePattern(ctx) {
673
- return this.visitSingle(ctx);
674
- }
675
-
676
- identifyNewExpressionType() {
677
- return "identifyNewExpressionType";
678
- }
679
-
680
- isLambdaExpression() {
681
- return "isLambdaExpression";
682
- }
683
-
684
- isCastExpression() {
685
- return "isCastExpression";
686
- }
687
-
688
- isPrimitiveCastExpression() {
689
- return "isPrimitiveCastExpression";
690
- }
691
-
692
- isReferenceTypeCastExpression() {
693
- return "isReferenceTypeCastExpression";
694
- }
695
-
696
- isRefTypeInMethodRef() {
697
- return "isRefTypeInMethodRef";
698
- }
699
- }
700
-
701
- module.exports = {
702
- ExpressionsPrettierVisitor
703
- };