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