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,103 +1,61 @@
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
1
+ import { builders } from "prettier/doc";
2
+ import { concat, group, indent, join } from "./prettier-builder.js";
3
+ import { printTokenWithComments } from "./comments/format-comments.js";
4
+ import { hasLeadingLineComments, hasTrailingLineComments } from "./comments/comments-utils.js";
5
+ import { displaySemicolon, getBlankLinesSeparator, isStatementEmptyStatement, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, rejectSeparators, sortModifiers } from "./printer-utils.js";
6
+ import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
7
+ const { line, softline, hardline } = builders;
8
+ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter {
9
+ block(ctx) {
10
+ const blockStatements = this.visit(ctx.blockStatements);
11
+ return putIntoBraces(blockStatements, hardline, ctx.LCurly[0], ctx.RCurly[0]);
12
+ }
13
+ blockStatements(ctx) {
14
+ const blockStatement = this.mapVisit(ctx.blockStatement);
15
+ const separators = rejectSeparators(getBlankLinesSeparator(ctx.blockStatement), blockStatement);
16
+ return rejectAndJoinSeps(separators, blockStatement);
34
17
  }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.BlocksAndStatementPrettierVisitor = void 0;
39
- var doc_1 = require("prettier/doc");
40
- var prettier_builder_1 = require("./prettier-builder");
41
- var format_comments_1 = require("./comments/format-comments");
42
- var comments_utils_1 = require("./comments/comments-utils");
43
- var printer_utils_1 = require("./printer-utils");
44
- var base_cst_printer_1 = require("../base-cst-printer");
45
- var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
46
- var BlocksAndStatementPrettierVisitor = /** @class */ (function (_super) {
47
- __extends(BlocksAndStatementPrettierVisitor, _super);
48
- function BlocksAndStatementPrettierVisitor() {
49
- return _super !== null && _super.apply(this, arguments) || this;
50
- }
51
- BlocksAndStatementPrettierVisitor.prototype.block = function (ctx) {
52
- var blockStatements = this.visit(ctx.blockStatements);
53
- return (0, printer_utils_1.putIntoBraces)(blockStatements, hardline, ctx.LCurly[0], ctx.RCurly[0]);
54
- };
55
- BlocksAndStatementPrettierVisitor.prototype.blockStatements = function (ctx) {
56
- var blockStatement = this.mapVisit(ctx.blockStatement);
57
- var separators = (0, printer_utils_1.rejectSeparators)((0, printer_utils_1.getBlankLinesSeparator)(ctx.blockStatement), blockStatement);
58
- return (0, printer_utils_1.rejectAndJoinSeps)(separators, blockStatement);
59
- };
60
- BlocksAndStatementPrettierVisitor.prototype.blockStatement = function (ctx) {
18
+ blockStatement(ctx) {
61
19
  return this.visitSingle(ctx);
62
- };
63
- BlocksAndStatementPrettierVisitor.prototype.localVariableDeclarationStatement = function (ctx) {
64
- var localVariableDeclaration = this.visit(ctx.localVariableDeclaration);
65
- return (0, printer_utils_1.rejectAndConcat)([localVariableDeclaration, ctx.Semicolon[0]]);
66
- };
67
- BlocksAndStatementPrettierVisitor.prototype.localVariableDeclaration = function (ctx) {
68
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.variableModifier);
69
- var firstAnnotations = this.mapVisit(modifiers[0]);
70
- var finalModifiers = this.mapVisit(modifiers[1]);
71
- var localVariableType = this.visit(ctx.localVariableType);
72
- var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
73
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
74
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
75
- (0, printer_utils_1.rejectAndJoin)(" ", [
76
- (0, printer_utils_1.rejectAndJoin)(" ", finalModifiers),
20
+ }
21
+ localVariableDeclarationStatement(ctx) {
22
+ const localVariableDeclaration = this.visit(ctx.localVariableDeclaration);
23
+ return rejectAndConcat([localVariableDeclaration, ctx.Semicolon[0]]);
24
+ }
25
+ localVariableDeclaration(ctx) {
26
+ const modifiers = sortModifiers(ctx.variableModifier);
27
+ const firstAnnotations = this.mapVisit(modifiers[0]);
28
+ const finalModifiers = this.mapVisit(modifiers[1]);
29
+ const localVariableType = this.visit(ctx.localVariableType);
30
+ const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
31
+ return rejectAndJoin(hardline, [
32
+ rejectAndJoin(hardline, firstAnnotations),
33
+ rejectAndJoin(" ", [
34
+ rejectAndJoin(" ", finalModifiers),
77
35
  localVariableType,
78
36
  variableDeclaratorList
79
37
  ])
80
38
  ]);
81
- };
82
- BlocksAndStatementPrettierVisitor.prototype.localVariableType = function (ctx) {
39
+ }
40
+ localVariableType(ctx) {
83
41
  if (ctx.unannType) {
84
42
  return this.visitSingle(ctx);
85
43
  }
86
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
87
- };
88
- BlocksAndStatementPrettierVisitor.prototype.statement = function (ctx, params) {
44
+ return printTokenWithComments(this.getSingle(ctx));
45
+ }
46
+ statement(ctx, params) {
89
47
  // handling Labeled statements comments
90
48
  if (ctx.labeledStatement !== undefined) {
91
- var newLabelStatement = __assign({}, ctx.labeledStatement[0]);
92
- var newColon = __assign({}, ctx.labeledStatement[0].children.Colon[0]);
93
- var newStatement = __assign({}, ctx.labeledStatement[0].children.statement[0]);
94
- var labeledStatementLeadingComments = [];
49
+ const newLabelStatement = Object.assign({}, ctx.labeledStatement[0]);
50
+ const newColon = Object.assign({}, ctx.labeledStatement[0].children.Colon[0]);
51
+ const newStatement = Object.assign({}, ctx.labeledStatement[0].children.statement[0]);
52
+ const labeledStatementLeadingComments = [];
95
53
  if (newColon.trailingComments !== undefined) {
96
- labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newColon.trailingComments);
54
+ labeledStatementLeadingComments.push(...newColon.trailingComments);
97
55
  delete newColon.trailingComments;
98
56
  }
99
57
  if (newStatement.leadingComments !== undefined) {
100
- labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newStatement.leadingComments);
58
+ labeledStatementLeadingComments.push(...newStatement.leadingComments);
101
59
  delete newStatement.leadingComments;
102
60
  }
103
61
  if (labeledStatementLeadingComments.length !== 0) {
@@ -108,120 +66,128 @@ var BlocksAndStatementPrettierVisitor = /** @class */ (function (_super) {
108
66
  return this.visit([newLabelStatement]);
109
67
  }
110
68
  return this.visitSingle(ctx, params);
111
- };
112
- BlocksAndStatementPrettierVisitor.prototype.statementWithoutTrailingSubstatement = function (ctx, params) {
69
+ }
70
+ statementWithoutTrailingSubstatement(ctx, params) {
113
71
  return this.visitSingle(ctx, params);
114
- };
115
- BlocksAndStatementPrettierVisitor.prototype.emptyStatement = function (ctx, params) {
116
- return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0], params);
117
- };
118
- BlocksAndStatementPrettierVisitor.prototype.labeledStatement = function (ctx) {
119
- var identifier = ctx.Identifier[0];
120
- var statement = this.visit(ctx.statement);
121
- return (0, printer_utils_1.rejectAndJoin)(ctx.Colon[0], [identifier, statement]);
122
- };
123
- BlocksAndStatementPrettierVisitor.prototype.expressionStatement = function (ctx) {
124
- var statementExpression = this.visit(ctx.statementExpression);
125
- return (0, printer_utils_1.rejectAndConcat)([statementExpression, ctx.Semicolon[0]]);
126
- };
127
- BlocksAndStatementPrettierVisitor.prototype.statementExpression = function (ctx) {
72
+ }
73
+ emptyStatement(ctx, params) {
74
+ return displaySemicolon(ctx.Semicolon[0], params);
75
+ }
76
+ labeledStatement(ctx) {
77
+ const identifier = ctx.Identifier[0];
78
+ const statement = this.visit(ctx.statement);
79
+ return rejectAndJoin(ctx.Colon[0], [identifier, statement]);
80
+ }
81
+ expressionStatement(ctx) {
82
+ const statementExpression = this.visit(ctx.statementExpression);
83
+ return rejectAndConcat([statementExpression, ctx.Semicolon[0]]);
84
+ }
85
+ statementExpression(ctx) {
128
86
  return this.visitSingle(ctx);
129
- };
130
- BlocksAndStatementPrettierVisitor.prototype.ifStatement = function (ctx) {
131
- var expression = this.visit(ctx.expression);
132
- var ifStatement = this.visit(ctx.statement[0], {
87
+ }
88
+ ifStatement(ctx) {
89
+ var _a;
90
+ const expression = this.visit(ctx.expression);
91
+ const ifStatement = this.visit(ctx.statement[0], {
133
92
  allowEmptyStatement: true
134
93
  });
135
- var ifSeparator = (0, printer_utils_1.isStatementEmptyStatement)(ifStatement) ? "" : " ";
136
- var elsePart = "";
94
+ const ifSeparator = isStatementEmptyStatement(ifStatement) ? "" : " ";
95
+ let elsePart = "";
137
96
  if (ctx.Else !== undefined) {
138
- var elseStatement = this.visit(ctx.statement[1], {
97
+ const elseStatement = this.visit(ctx.statement[1], {
139
98
  allowEmptyStatement: true
140
99
  });
141
- var elseSeparator = (0, printer_utils_1.isStatementEmptyStatement)(elseStatement) ? "" : " ";
142
- var elseOnSameLine = (0, comments_utils_1.hasTrailingLineComments)(ctx.statement[0]) ||
143
- (0, comments_utils_1.hasLeadingLineComments)(ctx.Else[0])
100
+ const elseSeparator = isStatementEmptyStatement(elseStatement) ? "" : " ";
101
+ const elseOnSameLine = hasTrailingLineComments(ctx.statement[0]) ||
102
+ hasLeadingLineComments(ctx.Else[0]) ||
103
+ !((_a = ctx.statement[0].children.statementWithoutTrailingSubstatement) === null || _a === void 0 ? void 0 : _a[0].children.block)
144
104
  ? hardline
145
105
  : " ";
146
- elsePart = (0, printer_utils_1.rejectAndJoin)(elseSeparator, [
147
- (0, prettier_builder_1.concat)([elseOnSameLine, ctx.Else[0]]),
106
+ elsePart = rejectAndJoin(elseSeparator, [
107
+ concat([elseOnSameLine, ctx.Else[0]]),
148
108
  elseStatement
149
109
  ]);
150
110
  }
151
- return (0, printer_utils_1.rejectAndConcat)([
152
- (0, printer_utils_1.rejectAndJoin)(" ", [
111
+ return rejectAndConcat([
112
+ rejectAndJoin(" ", [
153
113
  ctx.If[0],
154
- (0, prettier_builder_1.concat)([
155
- (0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
114
+ concat([
115
+ putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
156
116
  ifSeparator
157
117
  ])
158
118
  ]),
159
119
  ifStatement,
160
120
  elsePart
161
121
  ]);
162
- };
163
- BlocksAndStatementPrettierVisitor.prototype.assertStatement = function (ctx) {
164
- var expressions = this.mapVisit(ctx.expression);
165
- var colon = ctx.Colon ? ctx.Colon[0] : ":";
166
- return (0, printer_utils_1.rejectAndConcat)([
167
- (0, prettier_builder_1.concat)([ctx.Assert[0], " "]),
168
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([" ", colon, " "]), expressions),
122
+ }
123
+ assertStatement(ctx) {
124
+ const expressions = this.mapVisit(ctx.expression);
125
+ const colon = ctx.Colon ? ctx.Colon[0] : ":";
126
+ return rejectAndConcat([
127
+ concat([ctx.Assert[0], " "]),
128
+ rejectAndJoin(concat([" ", colon, " "]), expressions),
169
129
  ctx.Semicolon[0]
170
130
  ]);
171
- };
172
- BlocksAndStatementPrettierVisitor.prototype.switchStatement = function (ctx) {
173
- var expression = this.visit(ctx.expression);
174
- var switchBlock = this.visit(ctx.switchBlock);
175
- return (0, printer_utils_1.rejectAndJoin)(" ", [
131
+ }
132
+ switchStatement(ctx) {
133
+ const expression = this.visit(ctx.expression);
134
+ const switchBlock = this.visit(ctx.switchBlock);
135
+ return rejectAndJoin(" ", [
176
136
  ctx.Switch[0],
177
- (0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
137
+ putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
178
138
  switchBlock
179
139
  ]);
180
- };
181
- BlocksAndStatementPrettierVisitor.prototype.switchBlock = function (ctx) {
182
- var switchCases = ctx.switchBlockStatementGroup !== undefined
140
+ }
141
+ switchBlock(ctx) {
142
+ const switchCases = ctx.switchBlockStatementGroup !== undefined
183
143
  ? this.mapVisit(ctx.switchBlockStatementGroup)
184
144
  : this.mapVisit(ctx.switchRule);
185
- return (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndJoin)(hardline, switchCases), hardline, ctx.LCurly[0], ctx.RCurly[0]);
186
- };
187
- BlocksAndStatementPrettierVisitor.prototype.switchBlockStatementGroup = function (ctx) {
188
- var switchLabel = this.visit(ctx.switchLabel);
189
- var blockStatements = this.visit(ctx.blockStatements);
190
- return (0, prettier_builder_1.concat)([
145
+ return putIntoBraces(rejectAndJoin(hardline, switchCases), hardline, ctx.LCurly[0], ctx.RCurly[0]);
146
+ }
147
+ switchBlockStatementGroup(ctx) {
148
+ var _a, _b, _c;
149
+ const switchLabel = this.visit(ctx.switchLabel);
150
+ const blockStatements = this.visit(ctx.blockStatements);
151
+ const statements = (_a = ctx.blockStatements) === null || _a === void 0 ? void 0 : _a[0].children.blockStatement;
152
+ const hasSingleStatementBlock = (statements === null || statements === void 0 ? void 0 : statements.length) === 1 &&
153
+ ((_c = (_b = statements[0].children.statement) === null || _b === void 0 ? void 0 : _b[0].children.statementWithoutTrailingSubstatement) === null || _c === void 0 ? void 0 : _c[0].children.block) !== undefined;
154
+ return concat([
191
155
  switchLabel,
192
156
  ctx.Colon[0],
193
- blockStatements && (0, prettier_builder_1.indent)([hardline, blockStatements])
157
+ hasSingleStatementBlock
158
+ ? concat([" ", blockStatements])
159
+ : blockStatements && indent([hardline, blockStatements])
194
160
  ]);
195
- };
196
- BlocksAndStatementPrettierVisitor.prototype.switchLabel = function (ctx) {
161
+ }
162
+ switchLabel(ctx) {
197
163
  var _a, _b, _c;
198
- var Case = (_a = ctx.Case) === null || _a === void 0 ? void 0 : _a[0];
199
- var commas = (_b = ctx.Comma) === null || _b === void 0 ? void 0 : _b.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); });
164
+ const Case = (_a = ctx.Case) === null || _a === void 0 ? void 0 : _a[0];
165
+ const commas = (_b = ctx.Comma) === null || _b === void 0 ? void 0 : _b.map(elt => concat([elt, line]));
200
166
  if (ctx.caseConstant || ctx.Null) {
201
- var caseConstants = ctx.Null
167
+ const caseConstants = ctx.Null
202
168
  ? [ctx.Null[0], (_c = ctx.Default) === null || _c === void 0 ? void 0 : _c[0]]
203
169
  : this.mapVisit(ctx.caseConstant);
204
- return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, prettier_builder_1.join)(" ", [Case, (0, printer_utils_1.rejectAndJoinSeps)(commas, caseConstants)])));
170
+ return group(indent(join(" ", [Case, rejectAndJoinSeps(commas, caseConstants)])));
205
171
  }
206
172
  else if (ctx.pattern) {
207
- var patterns = this.mapVisit(ctx.pattern);
208
- var guard = this.visit(ctx.guard);
209
- var multiplePatterns = ctx.pattern.length > 1;
210
- var separator = multiplePatterns ? line : " ";
211
- var contents = (0, prettier_builder_1.join)(separator, [
173
+ const patterns = this.mapVisit(ctx.pattern);
174
+ const guard = this.visit(ctx.guard);
175
+ const multiplePatterns = ctx.pattern.length > 1;
176
+ const separator = multiplePatterns ? line : " ";
177
+ const contents = join(separator, [
212
178
  Case,
213
- (0, printer_utils_1.rejectAndJoinSeps)(commas, patterns)
179
+ rejectAndJoinSeps(commas, patterns)
214
180
  ]);
215
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(separator, [
216
- multiplePatterns ? (0, prettier_builder_1.indent)(contents) : contents,
181
+ return group(rejectAndJoin(separator, [
182
+ multiplePatterns ? indent(contents) : contents,
217
183
  guard
218
184
  ]));
219
185
  }
220
- return (0, format_comments_1.printTokenWithComments)(ctx.Default[0]);
221
- };
222
- BlocksAndStatementPrettierVisitor.prototype.switchRule = function (ctx) {
223
- var switchLabel = this.visit(ctx.switchLabel);
224
- var caseInstruction;
186
+ return printTokenWithComments(ctx.Default[0]);
187
+ }
188
+ switchRule(ctx) {
189
+ const switchLabel = this.visit(ctx.switchLabel);
190
+ let caseInstruction;
225
191
  if (ctx.throwStatement !== undefined) {
226
192
  caseInstruction = this.visit(ctx.throwStatement);
227
193
  }
@@ -229,252 +195,241 @@ var BlocksAndStatementPrettierVisitor = /** @class */ (function (_super) {
229
195
  caseInstruction = this.visit(ctx.block);
230
196
  }
231
197
  else {
232
- caseInstruction = (0, prettier_builder_1.concat)([this.visit(ctx.expression), ctx.Semicolon[0]]);
198
+ caseInstruction = concat([this.visit(ctx.expression), ctx.Semicolon[0]]);
233
199
  }
234
- return (0, prettier_builder_1.concat)([switchLabel, " ", ctx.Arrow[0], " ", caseInstruction]);
235
- };
236
- BlocksAndStatementPrettierVisitor.prototype.caseConstant = function (ctx) {
200
+ return concat([switchLabel, " ", ctx.Arrow[0], " ", caseInstruction]);
201
+ }
202
+ caseConstant(ctx) {
237
203
  return this.visitSingle(ctx);
238
- };
239
- BlocksAndStatementPrettierVisitor.prototype.whileStatement = function (ctx) {
240
- var expression = this.visit(ctx.expression);
241
- var statement = this.visit(ctx.statement[0], {
204
+ }
205
+ whileStatement(ctx) {
206
+ const expression = this.visit(ctx.expression);
207
+ const statement = this.visit(ctx.statement[0], {
242
208
  allowEmptyStatement: true
243
209
  });
244
- var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " ";
245
- return (0, printer_utils_1.rejectAndJoin)(" ", [
210
+ const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
211
+ return rejectAndJoin(" ", [
246
212
  ctx.While[0],
247
- (0, printer_utils_1.rejectAndJoin)(statementSeparator, [
248
- (0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
213
+ rejectAndJoin(statementSeparator, [
214
+ putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
249
215
  statement
250
216
  ])
251
217
  ]);
252
- };
253
- BlocksAndStatementPrettierVisitor.prototype.doStatement = function (ctx) {
254
- var statement = this.visit(ctx.statement[0], {
218
+ }
219
+ doStatement(ctx) {
220
+ const statement = this.visit(ctx.statement[0], {
255
221
  allowEmptyStatement: true
256
222
  });
257
- var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " ";
258
- var expression = this.visit(ctx.expression);
259
- return (0, printer_utils_1.rejectAndJoin)(" ", [
260
- (0, printer_utils_1.rejectAndJoin)(statementSeparator, [ctx.Do[0], statement]),
223
+ const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
224
+ const expression = this.visit(ctx.expression);
225
+ return rejectAndJoin(" ", [
226
+ rejectAndJoin(statementSeparator, [ctx.Do[0], statement]),
261
227
  ctx.While[0],
262
- (0, printer_utils_1.rejectAndConcat)([
263
- (0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
228
+ rejectAndConcat([
229
+ putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
264
230
  ctx.Semicolon[0]
265
231
  ])
266
232
  ]);
267
- };
268
- BlocksAndStatementPrettierVisitor.prototype.forStatement = function (ctx) {
233
+ }
234
+ forStatement(ctx) {
269
235
  return this.visitSingle(ctx);
270
- };
271
- BlocksAndStatementPrettierVisitor.prototype.basicForStatement = function (ctx) {
272
- var forInit = this.visit(ctx.forInit);
273
- var expression = this.visit(ctx.expression);
274
- var forUpdate = this.visit(ctx.forUpdate);
275
- var statement = this.visit(ctx.statement[0], {
236
+ }
237
+ basicForStatement(ctx) {
238
+ const forInit = this.visit(ctx.forInit);
239
+ const expression = this.visit(ctx.expression);
240
+ const forUpdate = this.visit(ctx.forUpdate);
241
+ const statement = this.visit(ctx.statement[0], {
276
242
  allowEmptyStatement: true
277
243
  });
278
- var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " ";
279
- return (0, printer_utils_1.rejectAndConcat)([
280
- (0, printer_utils_1.rejectAndJoin)(" ", [
244
+ const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
245
+ return rejectAndConcat([
246
+ rejectAndJoin(" ", [
281
247
  ctx.For[0],
282
- (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndConcat)([
248
+ putIntoBraces(rejectAndConcat([
283
249
  forInit,
284
- (0, printer_utils_1.rejectAndJoin)(line, [ctx.Semicolon[0], expression]),
285
- (0, printer_utils_1.rejectAndJoin)(line, [ctx.Semicolon[1], forUpdate])
250
+ rejectAndJoin(line, [ctx.Semicolon[0], expression]),
251
+ rejectAndJoin(line, [ctx.Semicolon[1], forUpdate])
286
252
  ]), softline, ctx.LBrace[0], ctx.RBrace[0])
287
253
  ]),
288
254
  statementSeparator,
289
255
  statement
290
256
  ]);
291
- };
292
- BlocksAndStatementPrettierVisitor.prototype.forInit = function (ctx) {
257
+ }
258
+ forInit(ctx) {
293
259
  return this.visitSingle(ctx);
294
- };
295
- BlocksAndStatementPrettierVisitor.prototype.forUpdate = function (ctx) {
260
+ }
261
+ forUpdate(ctx) {
296
262
  return this.visitSingle(ctx);
297
- };
298
- BlocksAndStatementPrettierVisitor.prototype.statementExpressionList = function (ctx) {
299
- var statementExpressions = this.mapVisit(ctx.statementExpression);
300
- var commas = ctx.Comma
301
- ? ctx.Comma.map(function (elt) {
302
- return (0, prettier_builder_1.concat)([(0, format_comments_1.printTokenWithComments)(elt), " "]);
263
+ }
264
+ statementExpressionList(ctx) {
265
+ const statementExpressions = this.mapVisit(ctx.statementExpression);
266
+ const commas = ctx.Comma
267
+ ? ctx.Comma.map(elt => {
268
+ return concat([printTokenWithComments(elt), " "]);
303
269
  })
304
270
  : [];
305
- return (0, printer_utils_1.rejectAndJoinSeps)(commas, statementExpressions);
306
- };
307
- BlocksAndStatementPrettierVisitor.prototype.enhancedForStatement = function (ctx) {
308
- var variableModifiers = this.mapVisit(ctx.variableModifier);
309
- var localVariableType = this.visit(ctx.localVariableType);
310
- var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
311
- var expression = this.visit(ctx.expression);
312
- var statement = this.visit(ctx.statement[0], {
271
+ return rejectAndJoinSeps(commas, statementExpressions);
272
+ }
273
+ enhancedForStatement(ctx) {
274
+ const variableModifiers = this.mapVisit(ctx.variableModifier);
275
+ const localVariableType = this.visit(ctx.localVariableType);
276
+ const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
277
+ const expression = this.visit(ctx.expression);
278
+ const statement = this.visit(ctx.statement[0], {
313
279
  allowEmptyStatement: true
314
280
  });
315
- var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " ";
316
- return (0, printer_utils_1.rejectAndConcat)([
317
- (0, printer_utils_1.rejectAndJoin)(" ", [ctx.For[0], ctx.LBrace[0]]),
318
- (0, printer_utils_1.rejectAndJoin)(" ", [
319
- (0, printer_utils_1.rejectAndJoin)(" ", variableModifiers),
281
+ const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
282
+ return rejectAndConcat([
283
+ rejectAndJoin(" ", [ctx.For[0], ctx.LBrace[0]]),
284
+ rejectAndJoin(" ", [
285
+ rejectAndJoin(" ", variableModifiers),
320
286
  localVariableType,
321
287
  variableDeclaratorId
322
288
  ]),
323
- (0, prettier_builder_1.concat)([" ", ctx.Colon[0], " "]),
289
+ concat([" ", ctx.Colon[0], " "]),
324
290
  expression,
325
- (0, prettier_builder_1.concat)([ctx.RBrace[0], statementSeparator]),
291
+ concat([ctx.RBrace[0], statementSeparator]),
326
292
  statement
327
293
  ]);
328
- };
329
- BlocksAndStatementPrettierVisitor.prototype.breakStatement = function (ctx) {
294
+ }
295
+ breakStatement(ctx) {
330
296
  if (ctx.Identifier) {
331
- var identifier = ctx.Identifier[0];
332
- return (0, printer_utils_1.rejectAndConcat)([
333
- (0, prettier_builder_1.concat)([ctx.Break[0], " "]),
297
+ const identifier = ctx.Identifier[0];
298
+ return rejectAndConcat([
299
+ concat([ctx.Break[0], " "]),
334
300
  identifier,
335
301
  ctx.Semicolon[0]
336
302
  ]);
337
303
  }
338
- return (0, prettier_builder_1.concat)([ctx.Break[0], ctx.Semicolon[0]]);
339
- };
340
- BlocksAndStatementPrettierVisitor.prototype.continueStatement = function (ctx) {
304
+ return concat([ctx.Break[0], ctx.Semicolon[0]]);
305
+ }
306
+ continueStatement(ctx) {
341
307
  if (ctx.Identifier) {
342
- var identifier = ctx.Identifier[0];
343
- return (0, printer_utils_1.rejectAndConcat)([
344
- (0, prettier_builder_1.concat)([ctx.Continue[0], " "]),
308
+ const identifier = ctx.Identifier[0];
309
+ return rejectAndConcat([
310
+ concat([ctx.Continue[0], " "]),
345
311
  identifier,
346
312
  ctx.Semicolon[0]
347
313
  ]);
348
314
  }
349
- return (0, printer_utils_1.rejectAndConcat)([ctx.Continue[0], ctx.Semicolon[0]]);
350
- };
351
- BlocksAndStatementPrettierVisitor.prototype.returnStatement = function (ctx) {
315
+ return rejectAndConcat([ctx.Continue[0], ctx.Semicolon[0]]);
316
+ }
317
+ returnStatement(ctx) {
352
318
  if (ctx.expression) {
353
- var expression = this.visit(ctx.expression, {
319
+ const expression = this.visit(ctx.expression, {
354
320
  addParenthesisToWrapStatement: true
355
321
  });
356
- return (0, printer_utils_1.rejectAndConcat)([
357
- (0, prettier_builder_1.concat)([ctx.Return[0], " "]),
322
+ return rejectAndConcat([
323
+ concat([ctx.Return[0], " "]),
358
324
  expression,
359
325
  ctx.Semicolon[0]
360
326
  ]);
361
327
  }
362
- return (0, printer_utils_1.rejectAndConcat)([ctx.Return[0], ctx.Semicolon[0]]);
363
- };
364
- BlocksAndStatementPrettierVisitor.prototype.throwStatement = function (ctx) {
365
- var expression = this.visit(ctx.expression);
366
- return (0, printer_utils_1.rejectAndConcat)([
367
- (0, prettier_builder_1.concat)([ctx.Throw[0], " "]),
328
+ return rejectAndConcat([ctx.Return[0], ctx.Semicolon[0]]);
329
+ }
330
+ throwStatement(ctx) {
331
+ const expression = this.visit(ctx.expression);
332
+ return rejectAndConcat([
333
+ concat([ctx.Throw[0], " "]),
368
334
  expression,
369
335
  ctx.Semicolon[0]
370
336
  ]);
371
- };
372
- BlocksAndStatementPrettierVisitor.prototype.synchronizedStatement = function (ctx) {
373
- var expression = this.visit(ctx.expression);
374
- var block = this.visit(ctx.block);
375
- return (0, printer_utils_1.rejectAndConcat)([
376
- (0, prettier_builder_1.join)(" ", [
337
+ }
338
+ synchronizedStatement(ctx) {
339
+ const expression = this.visit(ctx.expression);
340
+ const block = this.visit(ctx.block);
341
+ return rejectAndConcat([
342
+ join(" ", [
377
343
  ctx.Synchronized[0],
378
- (0, prettier_builder_1.concat)([
379
- (0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
344
+ concat([
345
+ putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
380
346
  " "
381
347
  ])
382
348
  ]),
383
349
  block
384
350
  ]);
385
- };
386
- BlocksAndStatementPrettierVisitor.prototype.tryStatement = function (ctx) {
351
+ }
352
+ tryStatement(ctx) {
387
353
  if (ctx.tryWithResourcesStatement) {
388
354
  return this.visit(ctx.tryWithResourcesStatement);
389
355
  }
390
- var block = this.visit(ctx.block);
391
- var catches = this.visit(ctx.catches);
392
- var finallyBlock = this.visit(ctx.finally);
393
- return (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Try[0], block, catches, finallyBlock]);
394
- };
395
- BlocksAndStatementPrettierVisitor.prototype.catches = function (ctx) {
396
- var catchClauses = this.mapVisit(ctx.catchClause);
397
- return (0, printer_utils_1.rejectAndJoin)(" ", catchClauses);
398
- };
399
- BlocksAndStatementPrettierVisitor.prototype.catchClause = function (ctx) {
400
- var catchFormalParameter = this.visit(ctx.catchFormalParameter);
401
- var block = this.visit(ctx.block);
402
- return (0, printer_utils_1.rejectAndConcat)([
403
- (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([
404
- (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Catch[0], ctx.LBrace[0]]),
405
- (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, catchFormalParameter])),
356
+ const block = this.visit(ctx.block);
357
+ const catches = this.visit(ctx.catches);
358
+ const finallyBlock = this.visit(ctx.finally);
359
+ return rejectAndJoin(" ", [ctx.Try[0], block, catches, finallyBlock]);
360
+ }
361
+ catches(ctx) {
362
+ const catchClauses = this.mapVisit(ctx.catchClause);
363
+ return rejectAndJoin(" ", catchClauses);
364
+ }
365
+ catchClause(ctx) {
366
+ const catchFormalParameter = this.visit(ctx.catchFormalParameter);
367
+ const block = this.visit(ctx.block);
368
+ return rejectAndConcat([
369
+ group(rejectAndConcat([
370
+ rejectAndJoin(" ", [ctx.Catch[0], ctx.LBrace[0]]),
371
+ indent(rejectAndConcat([softline, catchFormalParameter])),
406
372
  softline,
407
- (0, prettier_builder_1.concat)([ctx.RBrace[0], " "])
373
+ concat([ctx.RBrace[0], " "])
408
374
  ])),
409
375
  block
410
376
  ]);
411
- };
412
- BlocksAndStatementPrettierVisitor.prototype.catchFormalParameter = function (ctx) {
413
- var variableModifiers = this.mapVisit(ctx.variableModifier);
414
- var catchType = this.visit(ctx.catchType);
415
- var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
416
- return (0, printer_utils_1.rejectAndJoin)(" ", [
417
- (0, printer_utils_1.rejectAndJoin)(" ", variableModifiers),
377
+ }
378
+ catchFormalParameter(ctx) {
379
+ const variableModifiers = this.mapVisit(ctx.variableModifier);
380
+ const catchType = this.visit(ctx.catchType);
381
+ const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
382
+ return rejectAndJoin(" ", [
383
+ rejectAndJoin(" ", variableModifiers),
418
384
  catchType,
419
385
  variableDeclaratorId
420
386
  ]);
421
- };
422
- BlocksAndStatementPrettierVisitor.prototype.catchType = function (ctx) {
423
- var unannClassType = this.visit(ctx.unannClassType);
424
- var classTypes = this.mapVisit(ctx.classType);
425
- var ors = ctx.Or ? ctx.Or.map(function (elt) { return (0, prettier_builder_1.concat)([line, elt, " "]); }) : [];
426
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(ors, __spreadArray([unannClassType], classTypes, true)));
427
- };
428
- BlocksAndStatementPrettierVisitor.prototype.finally = function (ctx) {
429
- var block = this.visit(ctx.block);
430
- return (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Finally[0], block]);
431
- };
432
- BlocksAndStatementPrettierVisitor.prototype.tryWithResourcesStatement = function (ctx) {
433
- var resourceSpecification = this.visit(ctx.resourceSpecification);
434
- var block = this.visit(ctx.block);
435
- var catches = this.visit(ctx.catches);
436
- var finallyBlock = this.visit(ctx.finally);
437
- return (0, printer_utils_1.rejectAndJoin)(" ", [
387
+ }
388
+ catchType(ctx) {
389
+ const unannClassType = this.visit(ctx.unannClassType);
390
+ const classTypes = this.mapVisit(ctx.classType);
391
+ const ors = ctx.Or ? ctx.Or.map(elt => concat([line, elt, " "])) : [];
392
+ return group(rejectAndJoinSeps(ors, [unannClassType, ...classTypes]));
393
+ }
394
+ finally(ctx) {
395
+ const block = this.visit(ctx.block);
396
+ return rejectAndJoin(" ", [ctx.Finally[0], block]);
397
+ }
398
+ tryWithResourcesStatement(ctx) {
399
+ const resourceSpecification = this.visit(ctx.resourceSpecification);
400
+ const block = this.visit(ctx.block);
401
+ const catches = this.visit(ctx.catches);
402
+ const finallyBlock = this.visit(ctx.finally);
403
+ return rejectAndJoin(" ", [
438
404
  ctx.Try[0],
439
405
  resourceSpecification,
440
406
  block,
441
407
  catches,
442
408
  finallyBlock
443
409
  ]);
444
- };
445
- BlocksAndStatementPrettierVisitor.prototype.resourceSpecification = function (ctx) {
446
- var resourceList = this.visit(ctx.resourceList);
447
- var optionalSemicolon = ctx.Semicolon ? ctx.Semicolon[0] : "";
448
- return (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndConcat)([resourceList, optionalSemicolon]), softline, ctx.LBrace[0], ctx.RBrace[0]);
449
- };
450
- BlocksAndStatementPrettierVisitor.prototype.resourceList = function (ctx) {
451
- var resources = this.mapVisit(ctx.resource);
452
- var semicolons = ctx.Semicolon
453
- ? ctx.Semicolon.map(function (elt) {
454
- return (0, prettier_builder_1.concat)([elt, line]);
410
+ }
411
+ resourceSpecification(ctx) {
412
+ const resourceList = this.visit(ctx.resourceList);
413
+ const optionalSemicolon = ctx.Semicolon ? ctx.Semicolon[0] : "";
414
+ return putIntoBraces(rejectAndConcat([resourceList, optionalSemicolon]), softline, ctx.LBrace[0], ctx.RBrace[0]);
415
+ }
416
+ resourceList(ctx) {
417
+ const resources = this.mapVisit(ctx.resource);
418
+ const semicolons = ctx.Semicolon
419
+ ? ctx.Semicolon.map(elt => {
420
+ return concat([elt, line]);
455
421
  })
456
422
  : [""];
457
- return (0, printer_utils_1.rejectAndJoinSeps)(semicolons, resources);
458
- };
459
- BlocksAndStatementPrettierVisitor.prototype.resource = function (ctx) {
423
+ return rejectAndJoinSeps(semicolons, resources);
424
+ }
425
+ resource(ctx) {
460
426
  return this.visitSingle(ctx);
461
- };
462
- BlocksAndStatementPrettierVisitor.prototype.yieldStatement = function (ctx) {
463
- var expression = this.visit(ctx.expression);
464
- return (0, prettier_builder_1.join)(" ", [ctx.Yield[0], (0, prettier_builder_1.concat)([expression, ctx.Semicolon[0]])]);
465
- };
466
- BlocksAndStatementPrettierVisitor.prototype.variableAccess = function (ctx) {
427
+ }
428
+ yieldStatement(ctx) {
429
+ const expression = this.visit(ctx.expression);
430
+ return join(" ", [ctx.Yield[0], concat([expression, ctx.Semicolon[0]])]);
431
+ }
432
+ variableAccess(ctx) {
467
433
  return this.visitSingle(ctx);
468
- };
469
- BlocksAndStatementPrettierVisitor.prototype.isBasicForStatement = function () {
470
- return "isBasicForStatement";
471
- };
472
- BlocksAndStatementPrettierVisitor.prototype.isLocalVariableDeclaration = function () {
473
- return "isLocalVariableDeclaration";
474
- };
475
- BlocksAndStatementPrettierVisitor.prototype.isClassicSwitchLabel = function () {
476
- return "isClassicSwitchLabel";
477
- };
478
- return BlocksAndStatementPrettierVisitor;
479
- }(base_cst_printer_1.BaseCstPrettierPrinter));
480
- exports.BlocksAndStatementPrettierVisitor = BlocksAndStatementPrettierVisitor;
434
+ }
435
+ }