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.
- package/LICENSE +1 -1
- package/dist/base-cst-printer.js +22 -44
- package/dist/cst-printer.js +19 -27
- package/dist/index.js +19 -20
- package/dist/options.js +13 -17
- package/dist/parser.js +2 -4
- package/dist/printer.js +3 -5
- package/dist/printers/arrays.js +17 -41
- package/dist/printers/blocks-and-statements.js +281 -326
- package/dist/printers/classes.js +449 -496
- package/dist/printers/comments/comments-utils.js +5 -13
- package/dist/printers/comments/format-comments.js +34 -50
- package/dist/printers/comments/handle-comments.js +17 -23
- package/dist/printers/expressions.js +377 -391
- package/dist/printers/interfaces.js +148 -181
- package/dist/printers/lexical-structure.js +26 -58
- package/dist/printers/names.js +29 -53
- package/dist/printers/packages-and-modules.js +116 -143
- package/dist/printers/prettier-builder.js +21 -31
- package/dist/printers/printer-utils.js +173 -221
- package/dist/printers/types-values-and-variables.js +111 -149
- package/dist/types/utils.js +6 -15
- package/dist/utils/expressions-utils.js +7 -11
- package/dist/utils/index.js +2 -12
- package/dist/utils/isEmptyDoc.js +2 -4
- package/dist/utils/printArgumentListWithBraces.js +29 -19
- package/dist/utils/printSingleLambdaInvocation.js +15 -17
- package/package.json +10 -13
package/dist/printers/classes.js
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
26
|
+
const classDoc = this.visit(classCST);
|
|
27
|
+
return rejectAndJoin(hardline, [
|
|
28
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
29
|
+
rejectAndJoin(" ", [join(" ", otherModifiers), classDoc])
|
|
66
30
|
]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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 =
|
|
41
|
+
superClassesPart = indent(rejectAndConcat([line, optionalSuperClasses]));
|
|
78
42
|
}
|
|
79
|
-
|
|
43
|
+
let superInterfacesPart = "";
|
|
80
44
|
if (optionalSuperInterfaces) {
|
|
81
|
-
superInterfacesPart =
|
|
45
|
+
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces]));
|
|
82
46
|
}
|
|
83
|
-
|
|
47
|
+
let classPermits = "";
|
|
84
48
|
if (optionalClassPermits) {
|
|
85
|
-
classPermits =
|
|
49
|
+
classPermits = indent(rejectAndConcat([line, optionalClassPermits]));
|
|
86
50
|
}
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
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
|
-
|
|
85
|
+
indent(rejectAndConcat([line, interfaceTypeList]))
|
|
122
86
|
]));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
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
|
-
|
|
93
|
+
indent(rejectAndConcat([line, group(rejectAndJoinSeps(commas, typeNames))]))
|
|
130
94
|
]));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
content =
|
|
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
|
-
|
|
145
|
-
ctx.classBodyDeclaration.forEach(
|
|
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
|
-
|
|
113
|
+
shouldHardline = true;
|
|
150
114
|
}
|
|
151
115
|
});
|
|
152
116
|
if ((ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
|
|
153
117
|
ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
|
|
154
|
-
|
|
118
|
+
shouldHardline &&
|
|
155
119
|
param &&
|
|
156
120
|
param.isNormalClassDeclaration) {
|
|
157
|
-
content =
|
|
121
|
+
content = rejectAndConcat([hardline, content]);
|
|
158
122
|
}
|
|
159
123
|
}
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
124
|
+
return putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
125
|
+
}
|
|
126
|
+
classBodyDeclaration(ctx) {
|
|
163
127
|
return this.visitSingle(ctx);
|
|
164
|
-
}
|
|
165
|
-
|
|
128
|
+
}
|
|
129
|
+
classMemberDeclaration(ctx) {
|
|
166
130
|
if (ctx.Semicolon) {
|
|
167
|
-
return
|
|
131
|
+
return displaySemicolon(ctx.Semicolon[0]);
|
|
168
132
|
}
|
|
169
133
|
return this.visitSingle(ctx);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
146
|
+
concat([variableDeclaratorList, ctx.Semicolon[0]])
|
|
183
147
|
])
|
|
184
148
|
]);
|
|
185
|
-
}
|
|
186
|
-
|
|
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
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
202
|
-
if (
|
|
203
|
-
return
|
|
204
|
-
|
|
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
|
-
|
|
220
|
-
return
|
|
221
|
-
|
|
183
|
+
const groupId = Symbol("assignment");
|
|
184
|
+
return group([
|
|
185
|
+
group(variableDeclaratorId),
|
|
222
186
|
" ",
|
|
223
187
|
ctx.Equals[0],
|
|
224
|
-
|
|
188
|
+
group(indent(line), { id: groupId }),
|
|
225
189
|
lineSuffixBoundary,
|
|
226
|
-
|
|
190
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
227
191
|
]);
|
|
228
192
|
}
|
|
229
193
|
if (ctx.variableInitializer[0].children.expression[0].children
|
|
230
194
|
.ternaryExpression !== undefined) {
|
|
231
|
-
|
|
195
|
+
const unaryExpressions = ctx.variableInitializer[0].children.expression[0].children
|
|
232
196
|
.ternaryExpression[0].children.binaryExpression[0].children
|
|
233
197
|
.unaryExpression;
|
|
234
|
-
|
|
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
|
-
|
|
240
|
-
return
|
|
241
|
-
|
|
203
|
+
const groupId = Symbol("assignment");
|
|
204
|
+
return group([
|
|
205
|
+
group(variableDeclaratorId),
|
|
242
206
|
" ",
|
|
243
207
|
ctx.Equals[0],
|
|
244
|
-
|
|
208
|
+
group(indent(line), { id: groupId }),
|
|
245
209
|
lineSuffixBoundary,
|
|
246
|
-
|
|
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
|
-
|
|
253
|
-
return
|
|
254
|
-
|
|
216
|
+
const groupId = Symbol("assignment");
|
|
217
|
+
return group([
|
|
218
|
+
group(variableDeclaratorId),
|
|
255
219
|
" ",
|
|
256
220
|
ctx.Equals[0],
|
|
257
|
-
|
|
221
|
+
group(indent(line), { id: groupId }),
|
|
258
222
|
lineSuffixBoundary,
|
|
259
|
-
|
|
223
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
260
224
|
]);
|
|
261
225
|
}
|
|
262
226
|
// Method Invocation
|
|
263
|
-
|
|
227
|
+
const isMethodInvocation = firstPrimary.children.primarySuffix !== undefined &&
|
|
264
228
|
firstPrimary.children.primarySuffix[0].children
|
|
265
229
|
.methodInvocationSuffix !== undefined;
|
|
266
|
-
|
|
230
|
+
const isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children
|
|
267
231
|
.ternaryExpression[0].children.binaryExpression[0].children
|
|
268
232
|
.unaryExpression.length === 1;
|
|
269
|
-
|
|
233
|
+
const isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression;
|
|
270
234
|
if (isUniqueMethodInvocation) {
|
|
271
|
-
|
|
272
|
-
return
|
|
273
|
-
|
|
235
|
+
const groupId = Symbol("assignment");
|
|
236
|
+
return group([
|
|
237
|
+
group(variableDeclaratorId),
|
|
274
238
|
" ",
|
|
275
239
|
ctx.Equals[0],
|
|
276
|
-
|
|
240
|
+
group(indent(line), { id: groupId }),
|
|
277
241
|
lineSuffixBoundary,
|
|
278
|
-
|
|
242
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
279
243
|
]);
|
|
280
244
|
}
|
|
281
245
|
}
|
|
282
|
-
return
|
|
283
|
-
|
|
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
|
-
|
|
252
|
+
}
|
|
253
|
+
variableDeclaratorId(ctx) {
|
|
290
254
|
if (ctx.Underscore) {
|
|
291
|
-
return
|
|
255
|
+
return printTokenWithComments(ctx.Underscore[0]);
|
|
292
256
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return
|
|
296
|
-
}
|
|
297
|
-
|
|
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
|
-
|
|
263
|
+
}
|
|
264
|
+
unannType(ctx) {
|
|
301
265
|
return this.visitSingle(ctx);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return
|
|
307
|
-
}
|
|
308
|
-
|
|
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
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return
|
|
318
|
-
}
|
|
319
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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 (
|
|
334
|
-
currentSegment.push(
|
|
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 && !
|
|
302
|
+
if ((i + 1 < tokens.length && !isTypeArgumentsCstNode(tokens[i + 1])) ||
|
|
340
303
|
i + 1 === tokens.length) {
|
|
341
|
-
segments.push(
|
|
304
|
+
segments.push(rejectAndConcat(currentSegment));
|
|
342
305
|
currentSegment = [];
|
|
343
306
|
}
|
|
344
307
|
}
|
|
345
308
|
});
|
|
346
|
-
return
|
|
347
|
-
}
|
|
348
|
-
|
|
309
|
+
return rejectAndJoinSeps(ctx.Dot, segments);
|
|
310
|
+
}
|
|
311
|
+
unannInterfaceType(ctx) {
|
|
349
312
|
return this.visit(ctx.unannClassType);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
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
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
return
|
|
383
|
-
|
|
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
|
-
|
|
348
|
+
rejectAndJoin(line, annotations),
|
|
386
349
|
result,
|
|
387
350
|
declarator,
|
|
388
351
|
throws
|
|
389
352
|
])
|
|
390
353
|
]));
|
|
391
|
-
}
|
|
392
|
-
|
|
354
|
+
}
|
|
355
|
+
result(ctx) {
|
|
393
356
|
if (ctx.unannType) {
|
|
394
357
|
return this.visit(ctx.unannType);
|
|
395
358
|
}
|
|
396
359
|
// void
|
|
397
|
-
return
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
var
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
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
|
-
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return
|
|
426
|
-
}
|
|
427
|
-
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return
|
|
435
|
-
|
|
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
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
?
|
|
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
|
-
|
|
413
|
+
const annotationsPrinted = ctx.annotation === undefined
|
|
449
414
|
? annotations
|
|
450
|
-
:
|
|
451
|
-
return
|
|
452
|
-
|
|
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
|
-
|
|
422
|
+
}
|
|
423
|
+
variableModifier(ctx) {
|
|
459
424
|
if (ctx.annotation) {
|
|
460
425
|
return this.visit(ctx.annotation);
|
|
461
426
|
}
|
|
462
|
-
return
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return
|
|
473
|
-
}
|
|
474
|
-
|
|
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
|
-
|
|
441
|
+
}
|
|
442
|
+
methodBody(ctx) {
|
|
478
443
|
if (ctx.block) {
|
|
479
444
|
return this.visit(ctx.block);
|
|
480
445
|
}
|
|
481
|
-
return
|
|
482
|
-
}
|
|
483
|
-
|
|
446
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
447
|
+
}
|
|
448
|
+
instanceInitializer(ctx) {
|
|
484
449
|
return this.visitSingle(ctx);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
return
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
|
|
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
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return
|
|
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
|
-
|
|
489
|
+
concat([
|
|
525
490
|
simpleTypeName,
|
|
526
|
-
|
|
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
|
-
|
|
531
|
-
return
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
return
|
|
537
|
-
}
|
|
538
|
-
|
|
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
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
return
|
|
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
|
-
|
|
516
|
+
group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
|
549
517
|
]);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return
|
|
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
|
-
|
|
528
|
+
group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
|
561
529
|
]);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
return
|
|
569
|
-
|
|
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
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
584
|
-
|
|
551
|
+
const handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations &&
|
|
552
|
+
hasLeadingComments(ctx.enumBodyDeclarations[0])
|
|
585
553
|
? hardline
|
|
586
554
|
: "";
|
|
587
|
-
|
|
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 ?
|
|
562
|
+
optionalComma = ctx.Comma ? Object.assign(Object.assign({}, ctx.Comma[0]), { image: "" }) : "";
|
|
595
563
|
}
|
|
596
|
-
return
|
|
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
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
? ctx.Comma.map(
|
|
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
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
?
|
|
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
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
596
|
+
}
|
|
597
|
+
enumConstantModifier(ctx) {
|
|
632
598
|
return this.visitSingle(ctx);
|
|
633
|
-
}
|
|
634
|
-
|
|
599
|
+
}
|
|
600
|
+
enumBodyDeclarations(ctx) {
|
|
635
601
|
if (ctx.classBodyDeclaration !== undefined) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return
|
|
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
|
-
|
|
606
|
+
rejectAndJoinSeps(separators, classBodyDeclaration)
|
|
641
607
|
]);
|
|
642
608
|
}
|
|
643
|
-
return (
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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 =
|
|
618
|
+
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces]));
|
|
653
619
|
}
|
|
654
|
-
|
|
655
|
-
return
|
|
656
|
-
|
|
657
|
-
|
|
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
|
-
|
|
666
|
-
|
|
667
|
-
return
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
? ctx.Comma.map(
|
|
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
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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
|
|
684
|
-
|
|
685
|
-
|
|
647
|
+
return group(rejectAndJoin(line, [
|
|
648
|
+
join(line, modifiers),
|
|
649
|
+
join(" ", [unannType, ctx.Identifier[0]])
|
|
686
650
|
]));
|
|
687
651
|
}
|
|
688
|
-
|
|
652
|
+
const variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent);
|
|
689
653
|
if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) {
|
|
690
|
-
return
|
|
691
|
-
|
|
692
|
-
|
|
654
|
+
return group(rejectAndJoin(line, [
|
|
655
|
+
join(line, modifiers),
|
|
656
|
+
join(" ", [unannType, variableArityRecordComponent])
|
|
693
657
|
]));
|
|
694
658
|
}
|
|
695
|
-
return
|
|
696
|
-
|
|
697
|
-
|
|
659
|
+
return group(rejectAndJoin(line, [
|
|
660
|
+
join(line, modifiers),
|
|
661
|
+
concat([unannType, variableArityRecordComponent])
|
|
698
662
|
]));
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return
|
|
704
|
-
|
|
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
|
-
|
|
671
|
+
}
|
|
672
|
+
recordComponentModifier(ctx) {
|
|
709
673
|
return this.visitSingle(ctx);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return
|
|
713
|
-
}
|
|
714
|
-
|
|
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
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
return
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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
|
-
|
|
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
|
-
|
|
741
|
-
return "isCompactConstructorDeclaration";
|
|
742
|
-
};
|
|
743
|
-
return ClassesPrettierVisitor;
|
|
744
|
-
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
|
745
|
-
exports.ClassesPrettierVisitor = ClassesPrettierVisitor;
|
|
697
|
+
}
|
|
698
|
+
}
|