prettier-plugin-java 2.3.1 → 2.5.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 (97) hide show
  1. package/dist/options.js +5 -4
  2. package/dist/printers/blocks-and-statements.js +23 -40
  3. package/dist/printers/classes.js +3 -0
  4. package/dist/printers/expressions.js +26 -18
  5. package/package.json +3 -3
  6. package/dist/src/base-cst-printer.js +0 -77
  7. package/dist/src/cst-printer.js +0 -37
  8. package/dist/src/index.js +0 -67
  9. package/dist/src/options.js +0 -256
  10. package/dist/src/parser.js +0 -7
  11. package/dist/src/printer.js +0 -28
  12. package/dist/src/printers/arrays.js +0 -49
  13. package/dist/src/printers/blocks-and-statements.js +0 -493
  14. package/dist/src/printers/classes.js +0 -724
  15. package/dist/src/printers/comments/comments-utils.js +0 -29
  16. package/dist/src/printers/comments/format-comments.js +0 -187
  17. package/dist/src/printers/comments/handle-comments.js +0 -38
  18. package/dist/src/printers/expressions.js +0 -549
  19. package/dist/src/printers/interfaces.js +0 -251
  20. package/dist/src/printers/lexical-structure.js +0 -43
  21. package/dist/src/printers/names.js +0 -53
  22. package/dist/src/printers/packages-and-modules.js +0 -185
  23. package/dist/src/printers/prettier-builder.js +0 -47
  24. package/dist/src/printers/printer-utils.js +0 -577
  25. package/dist/src/printers/types-values-and-variables.js +0 -183
  26. package/dist/src/types/utils.js +0 -29
  27. package/dist/src/utils/expressions-utils.js +0 -29
  28. package/dist/src/utils/index.js +0 -10
  29. package/dist/src/utils/printArgumentListWithBraces.js +0 -21
  30. package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
  31. package/dist/test/babel-register.js +0 -3
  32. package/dist/test/repository-test/core-test.js +0 -12
  33. package/dist/test/repository-test/jhipster-1-test.js +0 -17
  34. package/dist/test/repository-test/jhipster-2-test.js +0 -16
  35. package/dist/test/test-utils.js +0 -215
  36. package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
  37. package/dist/test/unit-test/args/args-spec.js +0 -6
  38. package/dist/test/unit-test/assert/assert-spec.js +0 -6
  39. package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
  40. package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
  41. package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
  42. package/dist/test/unit-test/cast/cast-spec.js +0 -6
  43. package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
  44. package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
  45. package/dist/test/unit-test/comments/comments-spec.js +0 -14
  46. package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
  47. package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
  48. package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
  49. package/dist/test/unit-test/enum/enum-spec.js +0 -6
  50. package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
  51. package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
  52. package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
  53. package/dist/test/unit-test/for/for-spec.js +0 -6
  54. package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
  55. package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
  56. package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
  57. package/dist/test/unit-test/if/if-spec.js +0 -6
  58. package/dist/test/unit-test/indent/indent-spec.js +0 -6
  59. package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
  60. package/dist/test/unit-test/interface/interface-spec.js +0 -6
  61. package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
  62. package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
  63. package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
  64. package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
  65. package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
  66. package/dist/test/unit-test/modules/modules-spec.js +0 -6
  67. package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
  68. package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
  69. package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
  70. package/dist/test/unit-test/records/records-spec.js +0 -6
  71. package/dist/test/unit-test/return/return-spec.js +0 -6
  72. package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
  73. package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
  74. package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
  75. package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
  76. package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
  77. package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
  78. package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
  79. package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
  80. package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
  81. package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
  82. package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
  83. package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
  84. package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
  85. package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
  86. package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
  87. package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
  88. package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
  89. package/dist/test/unit-test/switch/switch-spec.js +0 -6
  90. package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
  91. package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
  92. package/dist/test/unit-test/throws/throws-spec.js +0 -6
  93. package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
  94. package/dist/test/unit-test/types/types-spec.js +0 -6
  95. package/dist/test/unit-test/variables/variables-spec.js +0 -6
  96. package/dist/test/unit-test/while/while-spec.js +0 -6
  97. package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
@@ -1,724 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.ClassesPrettierVisitor = void 0;
33
- var forEach_1 = __importDefault(require("lodash/forEach"));
34
- var printer_utils_1 = require("./printer-utils");
35
- var prettier_builder_1 = require("./prettier-builder");
36
- var format_comments_1 = require("./comments/format-comments");
37
- var comments_utils_1 = require("./comments/comments-utils");
38
- var doc_1 = require("prettier/doc");
39
- var base_cst_printer_1 = require("../base-cst-printer");
40
- var utils_1 = require("../types/utils");
41
- var utils_2 = require("../utils");
42
- var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
43
- var ClassesPrettierVisitor = /** @class */ (function (_super) {
44
- __extends(ClassesPrettierVisitor, _super);
45
- function ClassesPrettierVisitor() {
46
- return _super !== null && _super.apply(this, arguments) || this;
47
- }
48
- ClassesPrettierVisitor.prototype.classDeclaration = function (ctx) {
49
- var modifiers = printer_utils_1.sortModifiers(ctx.classModifier);
50
- var firstAnnotations = this.mapVisit(modifiers[0]);
51
- var otherModifiers = this.mapVisit(modifiers[1]);
52
- var classCST;
53
- if (ctx.normalClassDeclaration !== undefined) {
54
- classCST = ctx.normalClassDeclaration;
55
- }
56
- else if (ctx.enumDeclaration !== undefined) {
57
- classCST = ctx.enumDeclaration;
58
- }
59
- else {
60
- classCST = ctx.recordDeclaration;
61
- }
62
- var classDoc = this.visit(classCST);
63
- return printer_utils_1.rejectAndJoin(hardline, [
64
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
65
- printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", otherModifiers), classDoc])
66
- ]);
67
- };
68
- ClassesPrettierVisitor.prototype.normalClassDeclaration = function (ctx) {
69
- var name = this.visit(ctx.typeIdentifier);
70
- var optionalTypeParams = this.visit(ctx.typeParameters);
71
- var optionalSuperClasses = this.visit(ctx.superclass);
72
- var optionalSuperInterfaces = this.visit(ctx.superinterfaces);
73
- var optionalClassPermits = this.visit(ctx.classPermits);
74
- var body = this.visit(ctx.classBody, { isNormalClassDeclaration: true });
75
- var superClassesPart = "";
76
- if (optionalSuperClasses) {
77
- superClassesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperClasses]));
78
- }
79
- var superInterfacesPart = "";
80
- if (optionalSuperInterfaces) {
81
- superInterfacesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperInterfaces]));
82
- }
83
- var classPermits = "";
84
- if (optionalClassPermits) {
85
- classPermits = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalClassPermits]));
86
- }
87
- return printer_utils_1.rejectAndJoin(" ", [
88
- prettier_builder_1.group(printer_utils_1.rejectAndConcat([
89
- printer_utils_1.rejectAndJoin(" ", [ctx.Class[0], name]),
90
- optionalTypeParams,
91
- superClassesPart,
92
- superInterfacesPart,
93
- classPermits
94
- ])),
95
- body
96
- ]);
97
- };
98
- ClassesPrettierVisitor.prototype.classModifier = function (ctx) {
99
- if (ctx.annotation) {
100
- return this.visit(ctx.annotation);
101
- }
102
- // public | protected | private | ...
103
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
104
- };
105
- ClassesPrettierVisitor.prototype.typeParameters = function (ctx) {
106
- var typeParameterList = this.visit(ctx.typeParameterList);
107
- return printer_utils_1.putIntoBraces(typeParameterList, softline, ctx.Less[0], ctx.Greater[0]);
108
- };
109
- ClassesPrettierVisitor.prototype.typeParameterList = function (ctx) {
110
- var typeParameter = this.mapVisit(ctx.typeParameter);
111
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
112
- return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, typeParameter));
113
- };
114
- ClassesPrettierVisitor.prototype.superclass = function (ctx) {
115
- return prettier_builder_1.join(" ", [ctx.Extends[0], this.visit(ctx.classType)]);
116
- };
117
- ClassesPrettierVisitor.prototype.superinterfaces = function (ctx) {
118
- var interfaceTypeList = this.visit(ctx.interfaceTypeList);
119
- return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
120
- ctx.Implements[0],
121
- prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, interfaceTypeList]))
122
- ]));
123
- };
124
- ClassesPrettierVisitor.prototype.classPermits = function (ctx) {
125
- var typeNames = this.mapVisit(ctx.typeName);
126
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
127
- return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
128
- ctx.Permits[0],
129
- prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, typeNames))]))
130
- ]));
131
- };
132
- ClassesPrettierVisitor.prototype.interfaceTypeList = function (ctx) {
133
- var interfaceType = this.mapVisit(ctx.interfaceType);
134
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
135
- return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, interfaceType));
136
- };
137
- ClassesPrettierVisitor.prototype.classBody = function (ctx, param) {
138
- var content = "";
139
- if (ctx.classBodyDeclaration !== undefined) {
140
- var classBodyDeclsVisited = printer_utils_1.reject(this.mapVisit(ctx.classBodyDeclaration));
141
- var separators = printer_utils_1.getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
142
- content = printer_utils_1.rejectAndJoinSeps(separators, classBodyDeclsVisited);
143
- // edge case when we have SemiColons
144
- var shouldHardline_1 = false;
145
- ctx.classBodyDeclaration.forEach(function (elt) {
146
- if ((elt.children.classMemberDeclaration &&
147
- !elt.children.classMemberDeclaration[0].children.Semicolon) ||
148
- elt.children.constructorDeclaration) {
149
- shouldHardline_1 = true;
150
- }
151
- });
152
- if ((ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
153
- ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
154
- shouldHardline_1 &&
155
- param &&
156
- param.isNormalClassDeclaration) {
157
- content = printer_utils_1.rejectAndConcat([hardline, content]);
158
- }
159
- }
160
- return printer_utils_1.putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]);
161
- };
162
- ClassesPrettierVisitor.prototype.classBodyDeclaration = function (ctx) {
163
- return this.visitSingle(ctx);
164
- };
165
- ClassesPrettierVisitor.prototype.classMemberDeclaration = function (ctx) {
166
- if (ctx.Semicolon) {
167
- return printer_utils_1.displaySemicolon(ctx.Semicolon[0]);
168
- }
169
- return this.visitSingle(ctx);
170
- };
171
- ClassesPrettierVisitor.prototype.fieldDeclaration = function (ctx) {
172
- var modifiers = printer_utils_1.sortModifiers(ctx.fieldModifier);
173
- var firstAnnotations = this.mapVisit(modifiers[0]);
174
- var otherModifiers = this.mapVisit(modifiers[1]);
175
- var unannType = this.visit(ctx.unannType);
176
- var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
177
- return printer_utils_1.rejectAndJoin(hardline, [
178
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
179
- printer_utils_1.rejectAndJoin(" ", [
180
- printer_utils_1.rejectAndJoin(" ", otherModifiers),
181
- unannType,
182
- prettier_builder_1.concat([variableDeclaratorList, ctx.Semicolon[0]])
183
- ])
184
- ]);
185
- };
186
- ClassesPrettierVisitor.prototype.fieldModifier = function (ctx) {
187
- if (ctx.annotation) {
188
- return this.visit(ctx.annotation);
189
- }
190
- // public | protected | private | ...
191
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
192
- };
193
- ClassesPrettierVisitor.prototype.variableDeclaratorList = function (ctx) {
194
- var variableDeclarators = this.mapVisit(ctx.variableDeclarator);
195
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
196
- return printer_utils_1.rejectAndJoinSeps(commas, variableDeclarators);
197
- };
198
- ClassesPrettierVisitor.prototype.variableDeclarator = function (ctx) {
199
- var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
200
- if (ctx.Equals) {
201
- var variableInitializer = this.visit(ctx.variableInitializer);
202
- if (comments_utils_1.hasLeadingLineComments(ctx.variableInitializer[0])) {
203
- return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(hardline, [
204
- printer_utils_1.rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
205
- variableInitializer
206
- ])));
207
- }
208
- if (
209
- // Array Initialisation
210
- ctx.variableInitializer[0].children.arrayInitializer !== undefined ||
211
- // Lambda expression
212
- ctx.variableInitializer[0].children.expression[0].children
213
- .lambdaExpression !== undefined ||
214
- // Ternary Expression
215
- (ctx.variableInitializer[0].children.expression[0].children
216
- .ternaryExpression !== undefined &&
217
- ctx.variableInitializer[0].children.expression[0].children
218
- .ternaryExpression[0].children.QuestionMark !== undefined)) {
219
- return printer_utils_1.rejectAndJoin(" ", [
220
- variableDeclaratorId,
221
- ctx.Equals[0],
222
- variableInitializer
223
- ]);
224
- }
225
- if (ctx.variableInitializer[0].children.expression[0].children
226
- .ternaryExpression !== undefined) {
227
- var firstPrimary = ctx.variableInitializer[0].children.expression[0].children
228
- .ternaryExpression[0].children.binaryExpression[0].children
229
- .unaryExpression[0].children.primary[0];
230
- // Cast Expression
231
- if (firstPrimary.children.primaryPrefix[0].children.castExpression !==
232
- undefined) {
233
- return printer_utils_1.rejectAndJoin(" ", [
234
- variableDeclaratorId,
235
- ctx.Equals[0],
236
- variableInitializer
237
- ]);
238
- }
239
- // New Expression
240
- if (firstPrimary.children.primaryPrefix[0].children.newExpression !==
241
- undefined) {
242
- return printer_utils_1.rejectAndJoin(" ", [
243
- variableDeclaratorId,
244
- ctx.Equals[0],
245
- variableInitializer
246
- ]);
247
- }
248
- // Method Invocation
249
- var isMethodInvocation = firstPrimary.children.primarySuffix !== undefined &&
250
- firstPrimary.children.primarySuffix[0].children
251
- .methodInvocationSuffix !== undefined;
252
- var isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children
253
- .ternaryExpression[0].children.binaryExpression[0].children
254
- .unaryExpression.length === 1;
255
- var isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression;
256
- if (isUniqueMethodInvocation) {
257
- return printer_utils_1.rejectAndJoin(" ", [
258
- variableDeclaratorId,
259
- ctx.Equals[0],
260
- variableInitializer
261
- ]);
262
- }
263
- }
264
- return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(line, [
265
- printer_utils_1.rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
266
- variableInitializer
267
- ])));
268
- }
269
- return variableDeclaratorId;
270
- };
271
- ClassesPrettierVisitor.prototype.variableDeclaratorId = function (ctx) {
272
- var identifier = ctx.Identifier[0];
273
- var dims = this.visit(ctx.dims);
274
- return printer_utils_1.rejectAndConcat([identifier, dims]);
275
- };
276
- ClassesPrettierVisitor.prototype.variableInitializer = function (ctx) {
277
- return this.visitSingle(ctx);
278
- };
279
- ClassesPrettierVisitor.prototype.unannType = function (ctx) {
280
- return this.visitSingle(ctx);
281
- };
282
- ClassesPrettierVisitor.prototype.unannPrimitiveTypeWithOptionalDimsSuffix = function (ctx) {
283
- var unannPrimitiveType = this.visit(ctx.unannPrimitiveType);
284
- var dims = this.visit(ctx.dims);
285
- return printer_utils_1.rejectAndConcat([unannPrimitiveType, dims]);
286
- };
287
- ClassesPrettierVisitor.prototype.unannPrimitiveType = function (ctx) {
288
- if (ctx.numericType) {
289
- return this.visitSingle(ctx);
290
- }
291
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
292
- };
293
- ClassesPrettierVisitor.prototype.unannReferenceType = function (ctx) {
294
- var unannClassOrInterfaceType = this.visit(ctx.unannClassOrInterfaceType);
295
- var dims = this.visit(ctx.dims);
296
- return printer_utils_1.rejectAndConcat([unannClassOrInterfaceType, dims]);
297
- };
298
- ClassesPrettierVisitor.prototype.unannClassOrInterfaceType = function (ctx) {
299
- return this.visit(ctx.unannClassType);
300
- };
301
- ClassesPrettierVisitor.prototype.unannClassType = function (ctx) {
302
- var _this = this;
303
- var tokens = printer_utils_1.sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier);
304
- var segments = [];
305
- var currentSegment = [];
306
- forEach_1.default(tokens, function (token, i) {
307
- if (utils_1.isTypeArgumentsCstNode(token)) {
308
- currentSegment.push(_this.visit([token]));
309
- segments.push(printer_utils_1.rejectAndConcat(currentSegment));
310
- currentSegment = [];
311
- }
312
- else if (utils_1.isAnnotationCstNode(token)) {
313
- currentSegment.push(_this.visit([token]));
314
- currentSegment.push(" ");
315
- }
316
- else {
317
- currentSegment.push(token);
318
- if ((i + 1 < tokens.length && !utils_1.isTypeArgumentsCstNode(tokens[i + 1])) ||
319
- i + 1 === tokens.length) {
320
- segments.push(printer_utils_1.rejectAndConcat(currentSegment));
321
- currentSegment = [];
322
- }
323
- }
324
- });
325
- return printer_utils_1.rejectAndJoinSeps(ctx.Dot, segments);
326
- };
327
- ClassesPrettierVisitor.prototype.unannInterfaceType = function (ctx) {
328
- return this.visit(ctx.unannClassType);
329
- };
330
- ClassesPrettierVisitor.prototype.unannTypeVariable = function (ctx) {
331
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
332
- };
333
- ClassesPrettierVisitor.prototype.methodDeclaration = function (ctx) {
334
- var modifiers = printer_utils_1.sortModifiers(ctx.methodModifier);
335
- var firstAnnotations = this.mapVisit(modifiers[0]);
336
- var otherModifiers = this.mapVisit(modifiers[1]);
337
- var header = this.visit(ctx.methodHeader);
338
- var body = this.visit(ctx.methodBody);
339
- var headerBodySeparator = printer_utils_1.isStatementEmptyStatement(body) ? "" : " ";
340
- return printer_utils_1.rejectAndJoin(hardline, [
341
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
342
- printer_utils_1.rejectAndJoin(" ", [
343
- printer_utils_1.rejectAndJoin(" ", otherModifiers),
344
- printer_utils_1.rejectAndJoin(headerBodySeparator, [header, body])
345
- ])
346
- ]);
347
- };
348
- ClassesPrettierVisitor.prototype.methodModifier = function (ctx) {
349
- if (ctx.annotation) {
350
- return this.visit(ctx.annotation);
351
- }
352
- // public | protected | private | Synchronized | ...
353
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
354
- };
355
- ClassesPrettierVisitor.prototype.methodHeader = function (ctx) {
356
- var typeParameters = this.visit(ctx.typeParameters);
357
- var annotations = this.mapVisit(ctx.annotation);
358
- var result = this.visit(ctx.result);
359
- var declarator = this.visit(ctx.methodDeclarator);
360
- var throws = this.visit(ctx.throws);
361
- return prettier_builder_1.group(prettier_builder_1.concat([
362
- printer_utils_1.rejectAndJoin(" ", [
363
- typeParameters,
364
- printer_utils_1.rejectAndJoin(line, annotations),
365
- result,
366
- declarator,
367
- throws
368
- ])
369
- ]));
370
- };
371
- ClassesPrettierVisitor.prototype.result = function (ctx) {
372
- if (ctx.unannType) {
373
- return this.visit(ctx.unannType);
374
- }
375
- // void
376
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
377
- };
378
- ClassesPrettierVisitor.prototype.methodDeclarator = function (ctx) {
379
- var identifier = format_comments_1.printTokenWithComments(ctx.Identifier[0]);
380
- var formalParameterList = this.visit(ctx.formalParameterList);
381
- var dims = this.visit(ctx.dims);
382
- return printer_utils_1.rejectAndConcat([
383
- identifier,
384
- printer_utils_1.putIntoBraces(formalParameterList, softline, ctx.LBrace[0], ctx.RBrace[0]),
385
- dims
386
- ]);
387
- };
388
- ClassesPrettierVisitor.prototype.receiverParameter = function (ctx) {
389
- var annotations = this.mapVisit(ctx.annotation);
390
- var unannType = this.visit(ctx.unannType);
391
- var identifier = ctx.Identifier
392
- ? prettier_builder_1.concat([ctx.Identifier[0], ctx.Dot[0]])
393
- : "";
394
- return printer_utils_1.rejectAndJoin("", [
395
- printer_utils_1.rejectAndJoin(" ", annotations),
396
- unannType,
397
- identifier,
398
- ctx.This[0]
399
- ]);
400
- };
401
- ClassesPrettierVisitor.prototype.formalParameterList = function (ctx) {
402
- var formalParameter = this.mapVisit(ctx.formalParameter);
403
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
404
- return printer_utils_1.rejectAndJoinSeps(commas, formalParameter);
405
- };
406
- ClassesPrettierVisitor.prototype.formalParameter = function (ctx) {
407
- return this.visitSingle(ctx);
408
- };
409
- ClassesPrettierVisitor.prototype.variableParaRegularParameter = function (ctx) {
410
- var variableModifier = this.mapVisit(ctx.variableModifier);
411
- var unannType = this.visit(ctx.unannType);
412
- var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
413
- return printer_utils_1.rejectAndJoin(" ", [
414
- printer_utils_1.rejectAndJoin(" ", variableModifier),
415
- unannType,
416
- variableDeclaratorId
417
- ]);
418
- };
419
- ClassesPrettierVisitor.prototype.variableArityParameter = function (ctx) {
420
- var variableModifier = this.mapVisit(ctx.variableModifier);
421
- var unannType = this.visit(ctx.unannType);
422
- var annotations = this.mapVisit(ctx.annotation);
423
- var identifier = ctx.Identifier[0];
424
- var unannTypePrinted = ctx.annotation === undefined
425
- ? prettier_builder_1.concat([unannType, ctx.DotDotDot[0]])
426
- : unannType;
427
- var annotationsPrinted = ctx.annotation === undefined
428
- ? annotations
429
- : prettier_builder_1.concat([printer_utils_1.rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]);
430
- return printer_utils_1.rejectAndJoin(" ", [
431
- prettier_builder_1.join(" ", variableModifier),
432
- unannTypePrinted,
433
- annotationsPrinted,
434
- identifier
435
- ]);
436
- };
437
- ClassesPrettierVisitor.prototype.variableModifier = function (ctx) {
438
- if (ctx.annotation) {
439
- return this.visit(ctx.annotation);
440
- }
441
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
442
- };
443
- ClassesPrettierVisitor.prototype.throws = function (ctx) {
444
- var exceptionTypeList = this.visit(ctx.exceptionTypeList);
445
- var throwsDeclaration = prettier_builder_1.join(" ", [ctx.Throws[0], exceptionTypeList]);
446
- return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndConcat([softline, throwsDeclaration])));
447
- };
448
- ClassesPrettierVisitor.prototype.exceptionTypeList = function (ctx) {
449
- var exceptionTypes = this.mapVisit(ctx.exceptionType);
450
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
451
- return printer_utils_1.rejectAndJoinSeps(commas, exceptionTypes);
452
- };
453
- ClassesPrettierVisitor.prototype.exceptionType = function (ctx) {
454
- return this.visitSingle(ctx);
455
- };
456
- ClassesPrettierVisitor.prototype.methodBody = function (ctx) {
457
- if (ctx.block) {
458
- return this.visit(ctx.block);
459
- }
460
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
461
- };
462
- ClassesPrettierVisitor.prototype.instanceInitializer = function (ctx) {
463
- return this.visitSingle(ctx);
464
- };
465
- ClassesPrettierVisitor.prototype.staticInitializer = function (ctx) {
466
- var block = this.visit(ctx.block);
467
- return prettier_builder_1.join(" ", [ctx.Static[0], block]);
468
- };
469
- ClassesPrettierVisitor.prototype.constructorDeclaration = function (ctx) {
470
- var modifiers = printer_utils_1.sortModifiers(ctx.constructorModifier);
471
- var firstAnnotations = this.mapVisit(modifiers[0]);
472
- var otherModifiers = this.mapVisit(modifiers[1]);
473
- var constructorDeclarator = this.visit(ctx.constructorDeclarator);
474
- var throws = this.visit(ctx.throws);
475
- var constructorBody = this.visit(ctx.constructorBody);
476
- return printer_utils_1.rejectAndJoin(" ", [
477
- prettier_builder_1.group(printer_utils_1.rejectAndJoin(hardline, [
478
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
479
- printer_utils_1.rejectAndJoin(" ", [
480
- prettier_builder_1.join(" ", otherModifiers),
481
- constructorDeclarator,
482
- throws
483
- ])
484
- ])),
485
- constructorBody
486
- ]);
487
- };
488
- ClassesPrettierVisitor.prototype.constructorModifier = function (ctx) {
489
- if (ctx.annotation) {
490
- return this.visit(ctx.annotation);
491
- }
492
- // public | protected | private | Synchronized | ...
493
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
494
- };
495
- ClassesPrettierVisitor.prototype.constructorDeclarator = function (ctx) {
496
- var typeParameters = this.visit(ctx.typeParameters);
497
- var simpleTypeName = this.visit(ctx.simpleTypeName);
498
- var receiverParameter = this.visit(ctx.receiverParameter);
499
- var formalParameterList = this.visit(ctx.formalParameterList);
500
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
501
- return printer_utils_1.rejectAndJoin(" ", [
502
- typeParameters,
503
- prettier_builder_1.concat([
504
- simpleTypeName,
505
- printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoinSeps(commas, [receiverParameter, formalParameterList]), softline, ctx.LBrace[0], ctx.RBrace[0])
506
- ])
507
- ]);
508
- };
509
- ClassesPrettierVisitor.prototype.simpleTypeName = function (ctx) {
510
- return format_comments_1.printTokenWithComments(this.getSingle(ctx));
511
- };
512
- ClassesPrettierVisitor.prototype.constructorBody = function (ctx) {
513
- var explicitConstructorInvocation = this.visit(ctx.explicitConstructorInvocation);
514
- var blockStatements = this.visit(ctx.blockStatements);
515
- return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoin(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
516
- };
517
- ClassesPrettierVisitor.prototype.explicitConstructorInvocation = function (ctx) {
518
- return this.visitSingle(ctx);
519
- };
520
- ClassesPrettierVisitor.prototype.unqualifiedExplicitConstructorInvocation = function (ctx) {
521
- var typeArguments = this.visit(ctx.typeArguments);
522
- var keyWord = ctx.This ? ctx.This[0] : ctx.Super[0];
523
- var argumentList = utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
524
- return printer_utils_1.rejectAndConcat([
525
- typeArguments,
526
- keyWord,
527
- prettier_builder_1.group(printer_utils_1.rejectAndConcat([argumentList, ctx.Semicolon[0]]))
528
- ]);
529
- };
530
- ClassesPrettierVisitor.prototype.qualifiedExplicitConstructorInvocation = function (ctx) {
531
- var expressionName = this.visit(ctx.expressionName);
532
- var typeArguments = this.visit(ctx.typeArguments);
533
- var argumentList = utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
534
- return printer_utils_1.rejectAndConcat([
535
- expressionName,
536
- ctx.Dot[0],
537
- typeArguments,
538
- ctx.Super[0],
539
- prettier_builder_1.group(printer_utils_1.rejectAndConcat([argumentList, ctx.Semicolon[0]]))
540
- ]);
541
- };
542
- ClassesPrettierVisitor.prototype.enumDeclaration = function (ctx) {
543
- var classModifier = this.mapVisit(ctx.classModifier);
544
- var typeIdentifier = this.visit(ctx.typeIdentifier);
545
- var superinterfaces = this.visit(ctx.superinterfaces);
546
- var enumBody = this.visit(ctx.enumBody);
547
- return printer_utils_1.rejectAndJoin(" ", [
548
- prettier_builder_1.join(" ", classModifier),
549
- ctx.Enum[0],
550
- typeIdentifier,
551
- superinterfaces,
552
- enumBody
553
- ]);
554
- };
555
- ClassesPrettierVisitor.prototype.enumBody = function (ctx) {
556
- var enumConstantList = this.visit(ctx.enumConstantList);
557
- var enumBodyDeclarations = this.visit(ctx.enumBodyDeclarations);
558
- var hasEnumConstants = ctx.enumConstantList !== undefined;
559
- var hasNoClassBodyDeclarations = ctx.enumBodyDeclarations === undefined ||
560
- ctx.enumBodyDeclarations[0].children.classBodyDeclaration === undefined;
561
- // edge case: https://github.com/jhipster/prettier-java/issues/383
562
- var handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations &&
563
- comments_utils_1.hasLeadingComments(ctx.enumBodyDeclarations[0])
564
- ? hardline
565
- : "";
566
- var optionalComma;
567
- if (hasEnumConstants &&
568
- hasNoClassBodyDeclarations &&
569
- this.prettierOptions.trailingComma !== "none") {
570
- optionalComma = ctx.Comma ? ctx.Comma[0] : ",";
571
- }
572
- else {
573
- optionalComma = ctx.Comma ? __assign(__assign({}, ctx.Comma[0]), { image: "" }) : "";
574
- }
575
- return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndConcat([
576
- enumConstantList,
577
- optionalComma,
578
- handleEnumBodyDeclarationsLeadingComments,
579
- enumBodyDeclarations
580
- ]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
581
- };
582
- ClassesPrettierVisitor.prototype.enumConstantList = function (ctx) {
583
- var enumConstants = this.mapVisit(ctx.enumConstant);
584
- var blankLineSeparators = printer_utils_1.getBlankLinesSeparator(ctx.enumConstant);
585
- var commas = ctx.Comma
586
- ? ctx.Comma.map(function (elt, index) {
587
- return prettier_builder_1.concat([elt, blankLineSeparators[index]]);
588
- })
589
- : [];
590
- return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, enumConstants));
591
- };
592
- ClassesPrettierVisitor.prototype.enumConstant = function (ctx) {
593
- var modifiers = printer_utils_1.sortModifiers(ctx.enumConstantModifier);
594
- var firstAnnotations = this.mapVisit(modifiers[0]);
595
- var otherModifiers = this.mapVisit(modifiers[1]);
596
- var identifier = ctx.Identifier[0];
597
- var classBody = this.visit(ctx.classBody);
598
- var optionalBracesAndArgumentList = ctx.LBrace
599
- ? utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0])
600
- : "";
601
- return printer_utils_1.rejectAndJoin(hardline, [
602
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
603
- printer_utils_1.rejectAndJoin(" ", [
604
- printer_utils_1.rejectAndJoin(" ", otherModifiers),
605
- printer_utils_1.rejectAndConcat([identifier, optionalBracesAndArgumentList]),
606
- classBody
607
- ])
608
- ]);
609
- };
610
- ClassesPrettierVisitor.prototype.enumConstantModifier = function (ctx) {
611
- return this.visitSingle(ctx);
612
- };
613
- ClassesPrettierVisitor.prototype.enumBodyDeclarations = function (ctx) {
614
- if (ctx.classBodyDeclaration !== undefined) {
615
- var classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration);
616
- var separators = printer_utils_1.getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
617
- return printer_utils_1.rejectAndJoin(prettier_builder_1.concat([hardline, hardline]), [
618
- ctx.Semicolon[0],
619
- printer_utils_1.rejectAndJoinSeps(separators, classBodyDeclaration)
620
- ]);
621
- }
622
- return format_comments_1.printTokenWithComments(__assign(__assign({}, ctx.Semicolon[0]), { image: "" }));
623
- };
624
- ClassesPrettierVisitor.prototype.recordDeclaration = function (ctx) {
625
- var name = this.visit(ctx.typeIdentifier);
626
- var optionalTypeParams = this.visit(ctx.typeParameters);
627
- var recordHeader = this.visit(ctx.recordHeader);
628
- var superInterfacesPart = "";
629
- var optionalSuperInterfaces = this.visit(ctx.superinterfaces);
630
- if (optionalSuperInterfaces) {
631
- superInterfacesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperInterfaces]));
632
- }
633
- var body = this.visit(ctx.recordBody);
634
- return printer_utils_1.rejectAndJoin(" ", [
635
- prettier_builder_1.group(printer_utils_1.rejectAndConcat([
636
- printer_utils_1.rejectAndJoin(" ", [ctx.Record[0], name]),
637
- optionalTypeParams,
638
- recordHeader,
639
- superInterfacesPart
640
- ])),
641
- body
642
- ]);
643
- };
644
- ClassesPrettierVisitor.prototype.recordHeader = function (ctx) {
645
- var recordComponentList = this.visit(ctx.recordComponentList);
646
- return printer_utils_1.putIntoBraces(recordComponentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
647
- };
648
- ClassesPrettierVisitor.prototype.recordComponentList = function (ctx) {
649
- var recordComponents = this.mapVisit(ctx.recordComponent);
650
- var blankLineSeparators = printer_utils_1.getBlankLinesSeparator(ctx.recordComponent, line);
651
- var commas = ctx.Comma
652
- ? ctx.Comma.map(function (elt, index) {
653
- return prettier_builder_1.concat([elt, blankLineSeparators[index]]);
654
- })
655
- : [];
656
- return printer_utils_1.rejectAndJoinSeps(commas, recordComponents);
657
- };
658
- ClassesPrettierVisitor.prototype.recordComponent = function (ctx) {
659
- var modifiers = this.mapVisit(ctx.recordComponentModifier);
660
- var unannType = this.visit(ctx.unannType);
661
- if (ctx.Identifier !== undefined) {
662
- return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
663
- prettier_builder_1.join(line, modifiers),
664
- prettier_builder_1.join(" ", [unannType, ctx.Identifier[0]])
665
- ]));
666
- }
667
- var variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent);
668
- if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) {
669
- return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
670
- prettier_builder_1.join(line, modifiers),
671
- prettier_builder_1.join(" ", [unannType, variableArityRecordComponent])
672
- ]));
673
- }
674
- return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
675
- prettier_builder_1.join(line, modifiers),
676
- prettier_builder_1.concat([unannType, variableArityRecordComponent])
677
- ]));
678
- };
679
- ClassesPrettierVisitor.prototype.variableArityRecordComponent = function (ctx) {
680
- var annotations = this.mapVisit(ctx.annotation);
681
- var identifier = ctx.Identifier[0];
682
- return printer_utils_1.rejectAndJoin(" ", [
683
- printer_utils_1.rejectAndConcat([printer_utils_1.rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]),
684
- identifier
685
- ]);
686
- };
687
- ClassesPrettierVisitor.prototype.recordComponentModifier = function (ctx) {
688
- return this.visitSingle(ctx);
689
- };
690
- ClassesPrettierVisitor.prototype.recordBody = function (ctx) {
691
- return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoinSeps(printer_utils_1.getBlankLinesSeparator(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]);
692
- };
693
- ClassesPrettierVisitor.prototype.recordBodyDeclaration = function (ctx) {
694
- return this.visitSingle(ctx);
695
- };
696
- ClassesPrettierVisitor.prototype.compactConstructorDeclaration = function (ctx) {
697
- var modifiers = printer_utils_1.sortModifiers(ctx.constructorModifier);
698
- var firstAnnotations = this.mapVisit(modifiers[0]);
699
- var otherModifiers = this.mapVisit(modifiers[1]);
700
- var name = this.visit(ctx.simpleTypeName);
701
- var constructorBody = this.visit(ctx.constructorBody);
702
- return printer_utils_1.rejectAndJoin(" ", [
703
- prettier_builder_1.group(printer_utils_1.rejectAndJoin(hardline, [
704
- printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
705
- printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", otherModifiers), name])
706
- ])),
707
- constructorBody
708
- ]);
709
- };
710
- ClassesPrettierVisitor.prototype.isClassDeclaration = function () {
711
- return "isClassDeclaration";
712
- };
713
- ClassesPrettierVisitor.prototype.identifyClassBodyDeclarationType = function () {
714
- return "identifyClassBodyDeclarationType";
715
- };
716
- ClassesPrettierVisitor.prototype.isDims = function () {
717
- return "isDims";
718
- };
719
- ClassesPrettierVisitor.prototype.isCompactConstructorDeclaration = function () {
720
- return "isCompactConstructorDeclaration";
721
- };
722
- return ClassesPrettierVisitor;
723
- }(base_cst_printer_1.BaseCstPrettierPrinter));
724
- exports.ClassesPrettierVisitor = ClassesPrettierVisitor;