prettier-plugin-java 2.6.0 → 2.6.1
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/package.json +9 -4
- package/dist/base-cst-printer.js +0 -55
- package/dist/cst-printer.js +0 -29
- package/dist/index.js +0 -66
- package/dist/options.js +0 -254
- package/dist/parser.js +0 -4
- package/dist/printer.js +0 -6
- package/dist/printers/arrays.js +0 -25
- package/dist/printers/blocks-and-statements.js +0 -435
- package/dist/printers/classes.js +0 -698
- package/dist/printers/comments/comments-utils.js +0 -21
- package/dist/printers/comments/format-comments.js +0 -171
- package/dist/printers/comments/handle-comments.js +0 -73
- package/dist/printers/expressions.js +0 -543
- package/dist/printers/interfaces.js +0 -218
- package/dist/printers/lexical-structure.js +0 -31
- package/dist/printers/names.js +0 -29
- package/dist/printers/packages-and-modules.js +0 -171
- package/dist/printers/prettier-builder.js +0 -45
- package/dist/printers/printer-utils.js +0 -592
- package/dist/printers/types-values-and-variables.js +0 -153
- package/dist/types/utils.js +0 -20
- package/dist/utils/expressions-utils.js +0 -25
- package/dist/utils/index.js +0 -2
- package/dist/utils/isEmptyDoc.js +0 -4
- package/dist/utils/printArgumentListWithBraces.js +0 -31
- package/dist/utils/printSingleLambdaInvocation.js +0 -18
|
@@ -1,543 +0,0 @@
|
|
|
1
|
-
import forEach from "lodash/forEach.js";
|
|
2
|
-
import { builders } from "prettier/doc";
|
|
3
|
-
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
-
import { isAnnotationCstNode } from "../types/utils.js";
|
|
5
|
-
import { printArgumentListWithBraces } from "../utils/index.js";
|
|
6
|
-
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
7
|
-
import { handleCommentsBinaryExpression } from "./comments/handle-comments.js";
|
|
8
|
-
import { concat, dedent, group, indent } from "./prettier-builder.js";
|
|
9
|
-
import { binary, findDeepElementInPartsArray, isExplicitLambdaParameter, isUniqueMethodInvocation, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortAnnotationIdentifier, sortNodes, sortTokens } from "./printer-utils.js";
|
|
10
|
-
const { hardline, ifBreak, line, lineSuffixBoundary, softline } = builders;
|
|
11
|
-
export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter {
|
|
12
|
-
expression(ctx, params) {
|
|
13
|
-
return this.visitSingle(ctx, params);
|
|
14
|
-
}
|
|
15
|
-
lambdaExpression(ctx, params) {
|
|
16
|
-
const lambdaParameters = group(this.visit(ctx.lambdaParameters, params));
|
|
17
|
-
const lambdaBody = this.visit(ctx.lambdaBody);
|
|
18
|
-
const isLambdaBodyABlock = ctx.lambdaBody[0].children.block !== undefined;
|
|
19
|
-
if (isLambdaBodyABlock) {
|
|
20
|
-
return rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0], lambdaBody]);
|
|
21
|
-
}
|
|
22
|
-
return group(indent(rejectAndJoin(line, [
|
|
23
|
-
rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0]]),
|
|
24
|
-
lambdaBody
|
|
25
|
-
])));
|
|
26
|
-
}
|
|
27
|
-
lambdaParameters(ctx, params) {
|
|
28
|
-
if (ctx.lambdaParametersWithBraces) {
|
|
29
|
-
return this.visitSingle(ctx, params);
|
|
30
|
-
}
|
|
31
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
32
|
-
}
|
|
33
|
-
lambdaParametersWithBraces(ctx, params) {
|
|
34
|
-
const lambdaParameterList = this.visit(ctx.lambdaParameterList, params);
|
|
35
|
-
if (findDeepElementInPartsArray(lambdaParameterList, ",")) {
|
|
36
|
-
const separator = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? "" : softline;
|
|
37
|
-
const content = putIntoBraces(lambdaParameterList, separator, ctx.LBrace[0], ctx.RBrace[0]);
|
|
38
|
-
return content;
|
|
39
|
-
}
|
|
40
|
-
// removing braces when only no comments attached
|
|
41
|
-
if ((ctx.LBrace &&
|
|
42
|
-
ctx.RBrace &&
|
|
43
|
-
(!lambdaParameterList || isExplicitLambdaParameter(ctx))) ||
|
|
44
|
-
ctx.LBrace[0].leadingComments ||
|
|
45
|
-
ctx.LBrace[0].trailingComments ||
|
|
46
|
-
ctx.RBrace[0].leadingComments ||
|
|
47
|
-
ctx.RBrace[0].trailingComments) {
|
|
48
|
-
return rejectAndConcat([
|
|
49
|
-
ctx.LBrace[0],
|
|
50
|
-
lambdaParameterList,
|
|
51
|
-
ctx.RBrace[0]
|
|
52
|
-
]);
|
|
53
|
-
}
|
|
54
|
-
return lambdaParameterList;
|
|
55
|
-
}
|
|
56
|
-
lambdaParameterList(ctx, params) {
|
|
57
|
-
return this.visitSingle(ctx, params);
|
|
58
|
-
}
|
|
59
|
-
inferredLambdaParameterList(ctx, params) {
|
|
60
|
-
var _a;
|
|
61
|
-
const commaSuffix = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? " " : line;
|
|
62
|
-
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix]));
|
|
63
|
-
return rejectAndJoinSeps(commas, ctx.Identifier);
|
|
64
|
-
}
|
|
65
|
-
explicitLambdaParameterList(ctx, params) {
|
|
66
|
-
var _a;
|
|
67
|
-
const lambdaParameter = this.mapVisit(ctx.lambdaParameter);
|
|
68
|
-
const commaSuffix = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? " " : line;
|
|
69
|
-
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix]));
|
|
70
|
-
return rejectAndJoinSeps(commas, lambdaParameter);
|
|
71
|
-
}
|
|
72
|
-
lambdaParameter(ctx) {
|
|
73
|
-
return this.visitSingle(ctx);
|
|
74
|
-
}
|
|
75
|
-
regularLambdaParameter(ctx) {
|
|
76
|
-
const variableModifier = this.mapVisit(ctx.variableModifier);
|
|
77
|
-
const lambdaParameterType = this.visit(ctx.lambdaParameterType);
|
|
78
|
-
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
|
79
|
-
return rejectAndJoin(" ", [
|
|
80
|
-
rejectAndJoin(" ", variableModifier),
|
|
81
|
-
lambdaParameterType,
|
|
82
|
-
variableDeclaratorId
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
lambdaParameterType(ctx) {
|
|
86
|
-
if (ctx.unannType) {
|
|
87
|
-
return this.visitSingle(ctx);
|
|
88
|
-
}
|
|
89
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
90
|
-
}
|
|
91
|
-
lambdaBody(ctx) {
|
|
92
|
-
return this.visitSingle(ctx);
|
|
93
|
-
}
|
|
94
|
-
ternaryExpression(ctx, params) {
|
|
95
|
-
const binaryExpression = this.visit(ctx.binaryExpression, params);
|
|
96
|
-
if (ctx.QuestionMark) {
|
|
97
|
-
const expression1 = this.visit(ctx.expression[0]);
|
|
98
|
-
const expression2 = this.visit(ctx.expression[1]);
|
|
99
|
-
return indent(group(rejectAndConcat([
|
|
100
|
-
rejectAndJoin(line, [
|
|
101
|
-
binaryExpression,
|
|
102
|
-
rejectAndJoin(" ", [ctx.QuestionMark[0], expression1]),
|
|
103
|
-
rejectAndJoin(" ", [ctx.Colon[0], expression2])
|
|
104
|
-
])
|
|
105
|
-
])));
|
|
106
|
-
}
|
|
107
|
-
return binaryExpression;
|
|
108
|
-
}
|
|
109
|
-
binaryExpression(ctx, params) {
|
|
110
|
-
handleCommentsBinaryExpression(ctx);
|
|
111
|
-
const sortedNodes = sortNodes([
|
|
112
|
-
ctx.pattern,
|
|
113
|
-
ctx.referenceType,
|
|
114
|
-
ctx.expression,
|
|
115
|
-
ctx.unaryExpression
|
|
116
|
-
]);
|
|
117
|
-
const nodes = this.mapVisit(sortedNodes, sortedNodes.length === 1 ? params : undefined);
|
|
118
|
-
const tokens = sortTokens([
|
|
119
|
-
ctx.Instanceof,
|
|
120
|
-
ctx.AssignmentOperator,
|
|
121
|
-
ctx.Less,
|
|
122
|
-
ctx.Greater,
|
|
123
|
-
ctx.BinaryOperator
|
|
124
|
-
]);
|
|
125
|
-
const hasTokens = tokens.length > 0;
|
|
126
|
-
const content = binary(nodes, tokens, true);
|
|
127
|
-
return hasTokens && (params === null || params === void 0 ? void 0 : params.addParenthesisToWrapStatement)
|
|
128
|
-
? group(concat([
|
|
129
|
-
ifBreak("("),
|
|
130
|
-
indent(concat([softline, content])),
|
|
131
|
-
softline,
|
|
132
|
-
ifBreak(")")
|
|
133
|
-
]))
|
|
134
|
-
: content;
|
|
135
|
-
}
|
|
136
|
-
unaryExpression(ctx, params) {
|
|
137
|
-
const unaryPrefixOperator = ctx.UnaryPrefixOperator
|
|
138
|
-
? ctx.UnaryPrefixOperator
|
|
139
|
-
: [];
|
|
140
|
-
const primary = this.visit(ctx.primary, params);
|
|
141
|
-
const unarySuffixOperator = ctx.UnarySuffixOperator
|
|
142
|
-
? ctx.UnarySuffixOperator
|
|
143
|
-
: [];
|
|
144
|
-
return rejectAndConcat([
|
|
145
|
-
rejectAndConcat(unaryPrefixOperator),
|
|
146
|
-
primary,
|
|
147
|
-
rejectAndConcat(unarySuffixOperator)
|
|
148
|
-
]);
|
|
149
|
-
}
|
|
150
|
-
unaryExpressionNotPlusMinus(ctx) {
|
|
151
|
-
const unaryPrefixOperatorNotPlusMinus = ctx.UnaryPrefixOperatorNotPlusMinus // changed when moved to TS
|
|
152
|
-
? rejectAndJoin(" ", ctx.UnaryPrefixOperatorNotPlusMinus) // changed when moved to TS
|
|
153
|
-
: "";
|
|
154
|
-
const primary = this.visit(ctx.primary);
|
|
155
|
-
const unarySuffixOperator = ctx.UnarySuffixOperator // changed when moved to TS
|
|
156
|
-
? rejectAndJoin(" ", ctx.UnarySuffixOperator) // changed when moved to TS
|
|
157
|
-
: "";
|
|
158
|
-
return rejectAndJoin(" ", [
|
|
159
|
-
unaryPrefixOperatorNotPlusMinus,
|
|
160
|
-
primary,
|
|
161
|
-
unarySuffixOperator
|
|
162
|
-
]);
|
|
163
|
-
}
|
|
164
|
-
primary(ctx, params) {
|
|
165
|
-
var _a, _b, _c, _d;
|
|
166
|
-
const countMethodInvocation = isUniqueMethodInvocation(ctx.primarySuffix);
|
|
167
|
-
const newExpression = (_a = ctx.primaryPrefix[0].children.newExpression) === null || _a === void 0 ? void 0 : _a[0].children;
|
|
168
|
-
const isBreakableNewExpression = countMethodInvocation <= 1 &&
|
|
169
|
-
this.isBreakableNewExpression(newExpression);
|
|
170
|
-
const fqnOrRefType = (_b = ctx.primaryPrefix[0].children.fqnOrRefType) === null || _b === void 0 ? void 0 : _b[0].children;
|
|
171
|
-
const firstMethodInvocation = (_c = ctx.primarySuffix) === null || _c === void 0 ? void 0 : _c.map(suffix => { var _a; return (_a = suffix.children.methodInvocationSuffix) === null || _a === void 0 ? void 0 : _a[0].children; }).find(methodInvocationSuffix => methodInvocationSuffix);
|
|
172
|
-
const isCapitalizedIdentifier = this.isCapitalizedIdentifier(fqnOrRefType);
|
|
173
|
-
const shouldBreakBeforeFirstMethodInvocation = countMethodInvocation > 1 &&
|
|
174
|
-
!(isCapitalizedIdentifier !== null && isCapitalizedIdentifier !== void 0 ? isCapitalizedIdentifier : true) &&
|
|
175
|
-
firstMethodInvocation !== undefined;
|
|
176
|
-
const shouldBreakBeforeMethodInvocations = shouldBreakBeforeFirstMethodInvocation ||
|
|
177
|
-
countMethodInvocation > 2 ||
|
|
178
|
-
(countMethodInvocation > 1 && newExpression) ||
|
|
179
|
-
!(firstMethodInvocation === null || firstMethodInvocation === void 0 ? void 0 : firstMethodInvocation.argumentList);
|
|
180
|
-
const primaryPrefix = this.visit(ctx.primaryPrefix, Object.assign(Object.assign({}, params), { shouldBreakBeforeFirstMethodInvocation }));
|
|
181
|
-
const suffixes = [];
|
|
182
|
-
if (ctx.primarySuffix !== undefined) {
|
|
183
|
-
// edge case: https://github.com/jhipster/prettier-java/issues/381
|
|
184
|
-
let hasFirstInvocationArg = true;
|
|
185
|
-
if (ctx.primarySuffix.length > 1 &&
|
|
186
|
-
ctx.primarySuffix[1].children.methodInvocationSuffix &&
|
|
187
|
-
Object.keys(ctx.primarySuffix[1].children.methodInvocationSuffix[0].children).length === 2) {
|
|
188
|
-
hasFirstInvocationArg = false;
|
|
189
|
-
}
|
|
190
|
-
if (newExpression &&
|
|
191
|
-
!isBreakableNewExpression &&
|
|
192
|
-
ctx.primarySuffix[0].children.Dot !== undefined) {
|
|
193
|
-
suffixes.push(softline);
|
|
194
|
-
}
|
|
195
|
-
suffixes.push(this.visit(ctx.primarySuffix[0]));
|
|
196
|
-
for (let i = 1; i < ctx.primarySuffix.length; i++) {
|
|
197
|
-
if (shouldBreakBeforeMethodInvocations &&
|
|
198
|
-
ctx.primarySuffix[i].children.Dot !== undefined &&
|
|
199
|
-
ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined) {
|
|
200
|
-
suffixes.push(softline);
|
|
201
|
-
}
|
|
202
|
-
suffixes.push(this.visit(ctx.primarySuffix[i]));
|
|
203
|
-
}
|
|
204
|
-
if (!newExpression && countMethodInvocation === 1) {
|
|
205
|
-
return group(rejectAndConcat([
|
|
206
|
-
primaryPrefix,
|
|
207
|
-
hasFirstInvocationArg ? suffixes[0] : indent(suffixes[0]),
|
|
208
|
-
indent(rejectAndConcat(suffixes.slice(1)))
|
|
209
|
-
]));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const methodInvocation = (_d = ctx.primarySuffix) === null || _d === void 0 ? void 0 : _d[0].children.methodInvocationSuffix;
|
|
213
|
-
const isMethodInvocationWithArguments = (methodInvocation === null || methodInvocation === void 0 ? void 0 : methodInvocation[0].children.argumentList) !== undefined;
|
|
214
|
-
const isUnqualifiedMethodInvocation = methodInvocation !== undefined && !(fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.Dot);
|
|
215
|
-
return group(rejectAndConcat([
|
|
216
|
-
primaryPrefix,
|
|
217
|
-
isCapitalizedIdentifier || isUnqualifiedMethodInvocation
|
|
218
|
-
? suffixes.shift()
|
|
219
|
-
: "",
|
|
220
|
-
!isBreakableNewExpression &&
|
|
221
|
-
(shouldBreakBeforeMethodInvocations || !isMethodInvocationWithArguments)
|
|
222
|
-
? indent(concat(suffixes))
|
|
223
|
-
: concat(suffixes)
|
|
224
|
-
]));
|
|
225
|
-
}
|
|
226
|
-
primaryPrefix(ctx, params) {
|
|
227
|
-
if (ctx.This || ctx.Void) {
|
|
228
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
229
|
-
}
|
|
230
|
-
return this.visitSingle(ctx, params);
|
|
231
|
-
}
|
|
232
|
-
primarySuffix(ctx, params) {
|
|
233
|
-
var _a;
|
|
234
|
-
if (ctx.Dot) {
|
|
235
|
-
if (ctx.This) {
|
|
236
|
-
return rejectAndConcat([ctx.Dot[0], ctx.This[0]]);
|
|
237
|
-
}
|
|
238
|
-
else if (ctx.Identifier) {
|
|
239
|
-
const typeArguments = this.visit(ctx.typeArguments);
|
|
240
|
-
return rejectAndConcat([ctx.Dot[0], typeArguments, ctx.Identifier[0]]);
|
|
241
|
-
}
|
|
242
|
-
const suffix = this.visit((_a = ctx.unqualifiedClassInstanceCreationExpression) !== null && _a !== void 0 ? _a : ctx.templateArgument);
|
|
243
|
-
return rejectAndConcat([ctx.Dot[0], suffix]);
|
|
244
|
-
}
|
|
245
|
-
return this.visitSingle(ctx, params);
|
|
246
|
-
}
|
|
247
|
-
fqnOrRefType(ctx, params) {
|
|
248
|
-
const fqnOrRefTypePartFirst = this.visit(ctx.fqnOrRefTypePartFirst);
|
|
249
|
-
const fqnOrRefTypePartRest = this.mapVisit(ctx.fqnOrRefTypePartRest);
|
|
250
|
-
const dims = this.visit(ctx.dims);
|
|
251
|
-
const dots = ctx.Dot ? ctx.Dot : [];
|
|
252
|
-
const isMethodInvocation = ctx.Dot && ctx.Dot.length === 1;
|
|
253
|
-
if (params !== undefined &&
|
|
254
|
-
params.shouldBreakBeforeFirstMethodInvocation === true) {
|
|
255
|
-
// when fqnOrRefType is a method call from an object
|
|
256
|
-
if (isMethodInvocation) {
|
|
257
|
-
return rejectAndConcat([
|
|
258
|
-
indent(rejectAndJoin(concat([softline, dots[0]]), [
|
|
259
|
-
fqnOrRefTypePartFirst,
|
|
260
|
-
rejectAndJoinSeps(dots.slice(1), fqnOrRefTypePartRest),
|
|
261
|
-
dims
|
|
262
|
-
]))
|
|
263
|
-
]);
|
|
264
|
-
// otherwise it is a fully qualified name but we need to exclude when it is just a method call
|
|
265
|
-
}
|
|
266
|
-
else if (ctx.Dot) {
|
|
267
|
-
return indent(rejectAndConcat([
|
|
268
|
-
rejectAndJoinSeps(dots.slice(0, dots.length - 1), [
|
|
269
|
-
fqnOrRefTypePartFirst,
|
|
270
|
-
...fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1)
|
|
271
|
-
]),
|
|
272
|
-
softline,
|
|
273
|
-
rejectAndConcat([
|
|
274
|
-
dots[dots.length - 1],
|
|
275
|
-
fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1]
|
|
276
|
-
]),
|
|
277
|
-
dims
|
|
278
|
-
]));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return rejectAndConcat([
|
|
282
|
-
rejectAndJoinSeps(dots, [fqnOrRefTypePartFirst, ...fqnOrRefTypePartRest]),
|
|
283
|
-
dims
|
|
284
|
-
]);
|
|
285
|
-
}
|
|
286
|
-
fqnOrRefTypePartFirst(ctx) {
|
|
287
|
-
const annotation = this.mapVisit(ctx.annotation);
|
|
288
|
-
const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
|
|
289
|
-
return rejectAndJoin(" ", [
|
|
290
|
-
rejectAndJoin(" ", annotation),
|
|
291
|
-
fqnOrRefTypeCommon
|
|
292
|
-
]);
|
|
293
|
-
}
|
|
294
|
-
fqnOrRefTypePartRest(ctx) {
|
|
295
|
-
const annotation = this.mapVisit(ctx.annotation);
|
|
296
|
-
const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
|
|
297
|
-
const typeArguments = this.visit(ctx.typeArguments);
|
|
298
|
-
return rejectAndJoin(" ", [
|
|
299
|
-
rejectAndJoin(" ", annotation),
|
|
300
|
-
rejectAndConcat([typeArguments, fqnOrRefTypeCommon])
|
|
301
|
-
]);
|
|
302
|
-
}
|
|
303
|
-
fqnOrRefTypePartCommon(ctx) {
|
|
304
|
-
let keyWord = null;
|
|
305
|
-
if (ctx.Identifier) {
|
|
306
|
-
keyWord = ctx.Identifier[0];
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
keyWord = ctx.Super[0];
|
|
310
|
-
}
|
|
311
|
-
const typeArguments = this.visit(ctx.typeArguments);
|
|
312
|
-
return rejectAndConcat([keyWord, typeArguments]);
|
|
313
|
-
}
|
|
314
|
-
parenthesisExpression(ctx, params) {
|
|
315
|
-
const expression = this.visit(ctx.expression);
|
|
316
|
-
const separator = (params === null || params === void 0 ? void 0 : params.addParenthesisToWrapStatement) ? softline : "";
|
|
317
|
-
return putIntoBraces(expression, separator, ctx.LBrace[0], ctx.RBrace[0]);
|
|
318
|
-
}
|
|
319
|
-
castExpression(ctx) {
|
|
320
|
-
return this.visitSingle(ctx);
|
|
321
|
-
}
|
|
322
|
-
primitiveCastExpression(ctx) {
|
|
323
|
-
const primitiveType = this.visit(ctx.primitiveType);
|
|
324
|
-
const unaryExpression = this.visit(ctx.unaryExpression);
|
|
325
|
-
return rejectAndJoin(" ", [
|
|
326
|
-
rejectAndConcat([ctx.LBrace[0], primitiveType, ctx.RBrace[0]]),
|
|
327
|
-
unaryExpression
|
|
328
|
-
]);
|
|
329
|
-
}
|
|
330
|
-
referenceTypeCastExpression(ctx) {
|
|
331
|
-
const referenceType = this.visit(ctx.referenceType);
|
|
332
|
-
const hasAdditionalBounds = ctx.additionalBound !== undefined;
|
|
333
|
-
const additionalBounds = rejectAndJoin(line, this.mapVisit(ctx.additionalBound));
|
|
334
|
-
const expression = ctx.lambdaExpression
|
|
335
|
-
? this.visit(ctx.lambdaExpression)
|
|
336
|
-
: this.visit(ctx.unaryExpressionNotPlusMinus);
|
|
337
|
-
return rejectAndJoin(" ", [
|
|
338
|
-
putIntoBraces(rejectAndJoin(line, [referenceType, additionalBounds]), hasAdditionalBounds ? softline : "", ctx.LBrace[0], ctx.RBrace[0]),
|
|
339
|
-
expression
|
|
340
|
-
]);
|
|
341
|
-
}
|
|
342
|
-
newExpression(ctx) {
|
|
343
|
-
return this.visitSingle(ctx);
|
|
344
|
-
}
|
|
345
|
-
unqualifiedClassInstanceCreationExpression(ctx) {
|
|
346
|
-
const typeArguments = this.visit(ctx.typeArguments);
|
|
347
|
-
const classOrInterfaceTypeToInstantiate = this.visit(ctx.classOrInterfaceTypeToInstantiate);
|
|
348
|
-
let content = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
|
349
|
-
const classBody = this.visit(ctx.classBody);
|
|
350
|
-
return rejectAndJoin(" ", [
|
|
351
|
-
ctx.New[0],
|
|
352
|
-
rejectAndConcat([
|
|
353
|
-
typeArguments,
|
|
354
|
-
classOrInterfaceTypeToInstantiate,
|
|
355
|
-
content
|
|
356
|
-
]),
|
|
357
|
-
classBody
|
|
358
|
-
]);
|
|
359
|
-
}
|
|
360
|
-
classOrInterfaceTypeToInstantiate(ctx) {
|
|
361
|
-
const tokens = sortAnnotationIdentifier(ctx.annotation, ctx.Identifier);
|
|
362
|
-
const segments = [];
|
|
363
|
-
let currentSegment = [];
|
|
364
|
-
forEach(tokens, token => {
|
|
365
|
-
if (isAnnotationCstNode(token)) {
|
|
366
|
-
currentSegment.push(this.visit([token]));
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
currentSegment.push(token);
|
|
370
|
-
segments.push(rejectAndJoin(" ", currentSegment));
|
|
371
|
-
currentSegment = [];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
const typeArgumentsOrDiamond = this.visit(ctx.typeArgumentsOrDiamond);
|
|
375
|
-
const dots = ctx.Dot ? ctx.Dot : [];
|
|
376
|
-
return rejectAndConcat([
|
|
377
|
-
rejectAndJoinSeps(dots, segments),
|
|
378
|
-
typeArgumentsOrDiamond
|
|
379
|
-
]);
|
|
380
|
-
}
|
|
381
|
-
typeArgumentsOrDiamond(ctx) {
|
|
382
|
-
return this.visitSingle(ctx);
|
|
383
|
-
}
|
|
384
|
-
diamond(ctx) {
|
|
385
|
-
return concat([ctx.Less[0], ctx.Greater[0]]);
|
|
386
|
-
}
|
|
387
|
-
methodInvocationSuffix(ctx) {
|
|
388
|
-
return printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
|
389
|
-
}
|
|
390
|
-
argumentList(ctx, params) {
|
|
391
|
-
var _a;
|
|
392
|
-
const shouldBreak = params === null || params === void 0 ? void 0 : params.shouldBreak;
|
|
393
|
-
const expressions = this.mapVisit(ctx.expression, params);
|
|
394
|
-
const lastArgument = expressions.pop();
|
|
395
|
-
const commaSuffix = shouldBreak === true ? hardline : shouldBreak === false ? " " : line;
|
|
396
|
-
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix]));
|
|
397
|
-
const otherArguments = rejectAndJoinSeps(commas, expressions);
|
|
398
|
-
if (lastArgument && (params === null || params === void 0 ? void 0 : params.isHuggable)) {
|
|
399
|
-
const argumentListGroupId = Symbol("argumentList");
|
|
400
|
-
const separator = shouldBreak === true ? hardline : shouldBreak === false ? "" : softline;
|
|
401
|
-
return concat([
|
|
402
|
-
group([separator, otherArguments], { id: argumentListGroupId }),
|
|
403
|
-
ifBreak([lastArgument, dedent(separator)], dedent(lastArgument), {
|
|
404
|
-
groupId: argumentListGroupId
|
|
405
|
-
})
|
|
406
|
-
]);
|
|
407
|
-
}
|
|
408
|
-
return rejectAndConcat([otherArguments, lastArgument]);
|
|
409
|
-
}
|
|
410
|
-
arrayCreationExpression(ctx) {
|
|
411
|
-
const type = ctx.primitiveType
|
|
412
|
-
? this.visit(ctx.primitiveType)
|
|
413
|
-
: this.visit(ctx.classOrInterfaceType);
|
|
414
|
-
const suffix = ctx.arrayCreationDefaultInitSuffix
|
|
415
|
-
? this.visit(ctx.arrayCreationDefaultInitSuffix)
|
|
416
|
-
: this.visit(ctx.arrayCreationExplicitInitSuffix);
|
|
417
|
-
return rejectAndConcat([concat([ctx.New[0], " "]), type, suffix]);
|
|
418
|
-
}
|
|
419
|
-
arrayCreationDefaultInitSuffix(ctx) {
|
|
420
|
-
const dimExprs = this.visit(ctx.dimExprs);
|
|
421
|
-
const dims = this.visit(ctx.dims);
|
|
422
|
-
return rejectAndConcat([dimExprs, dims]);
|
|
423
|
-
}
|
|
424
|
-
arrayCreationExplicitInitSuffix(ctx) {
|
|
425
|
-
const dims = this.visit(ctx.dims);
|
|
426
|
-
const arrayInitializer = this.visit(ctx.arrayInitializer);
|
|
427
|
-
return rejectAndJoin(" ", [dims, arrayInitializer]);
|
|
428
|
-
}
|
|
429
|
-
dimExprs(ctx) {
|
|
430
|
-
const dimExpr = this.mapVisit(ctx.dimExpr);
|
|
431
|
-
return rejectAndConcat(dimExpr);
|
|
432
|
-
}
|
|
433
|
-
dimExpr(ctx) {
|
|
434
|
-
const annotations = this.mapVisit(ctx.annotation);
|
|
435
|
-
const expression = this.visit(ctx.expression);
|
|
436
|
-
return rejectAndJoin(" ", [
|
|
437
|
-
rejectAndJoin(" ", annotations),
|
|
438
|
-
rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]])
|
|
439
|
-
]);
|
|
440
|
-
}
|
|
441
|
-
classLiteralSuffix(ctx) {
|
|
442
|
-
const squares = [];
|
|
443
|
-
if (ctx.LSquare) {
|
|
444
|
-
for (let i = 0; i < ctx.LSquare.length; i++) {
|
|
445
|
-
squares.push(concat([ctx.LSquare[i], ctx.RSquare[i]]));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return rejectAndConcat([...squares, ctx.Dot[0], ctx.Class[0]]);
|
|
449
|
-
}
|
|
450
|
-
arrayAccessSuffix(ctx) {
|
|
451
|
-
const expression = this.visit(ctx.expression);
|
|
452
|
-
return rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]]);
|
|
453
|
-
}
|
|
454
|
-
methodReferenceSuffix(ctx) {
|
|
455
|
-
const typeArguments = this.visit(ctx.typeArguments);
|
|
456
|
-
const identifierOrNew = ctx.New ? ctx.New[0] : ctx.Identifier[0];
|
|
457
|
-
return rejectAndConcat([ctx.ColonColon[0], typeArguments, identifierOrNew]);
|
|
458
|
-
}
|
|
459
|
-
templateArgument(ctx) {
|
|
460
|
-
var _a;
|
|
461
|
-
return ctx.template
|
|
462
|
-
? this.visit(ctx.template)
|
|
463
|
-
: printTokenWithComments(((_a = ctx.StringLiteral) !== null && _a !== void 0 ? _a : ctx.TextBlock)[0]);
|
|
464
|
-
}
|
|
465
|
-
template(ctx) {
|
|
466
|
-
return this.visitSingle(ctx);
|
|
467
|
-
}
|
|
468
|
-
stringTemplate(ctx) {
|
|
469
|
-
const embeddedExpressions = this.mapVisit(ctx.embeddedExpression).flatMap(expression => group([softline, expression, lineSuffixBoundary, dedent(softline)]));
|
|
470
|
-
return concat([
|
|
471
|
-
ctx.StringTemplateBegin[0],
|
|
472
|
-
rejectAndJoinSeps(ctx.StringTemplateMid, embeddedExpressions),
|
|
473
|
-
ctx.StringTemplateEnd[0]
|
|
474
|
-
]);
|
|
475
|
-
}
|
|
476
|
-
textBlockTemplate(ctx) {
|
|
477
|
-
const embeddedExpressions = this.mapVisit(ctx.embeddedExpression).flatMap(expression => group([softline, expression, lineSuffixBoundary, dedent(softline)]));
|
|
478
|
-
return concat([
|
|
479
|
-
ctx.TextBlockTemplateBegin[0],
|
|
480
|
-
rejectAndJoinSeps(ctx.TextBlockTemplateMid, embeddedExpressions),
|
|
481
|
-
ctx.TextBlockTemplateEnd[0]
|
|
482
|
-
]);
|
|
483
|
-
}
|
|
484
|
-
embeddedExpression(ctx) {
|
|
485
|
-
return this.visit(ctx.expression);
|
|
486
|
-
}
|
|
487
|
-
pattern(ctx) {
|
|
488
|
-
return this.visitSingle(ctx);
|
|
489
|
-
}
|
|
490
|
-
typePattern(ctx) {
|
|
491
|
-
return this.visitSingle(ctx);
|
|
492
|
-
}
|
|
493
|
-
recordPattern(ctx) {
|
|
494
|
-
const referenceType = this.visit(ctx.referenceType);
|
|
495
|
-
const componentPatternList = this.visit(ctx.componentPatternList);
|
|
496
|
-
return concat([
|
|
497
|
-
referenceType,
|
|
498
|
-
putIntoBraces(componentPatternList, softline, ctx.LBrace[0], ctx.RBrace[0])
|
|
499
|
-
]);
|
|
500
|
-
}
|
|
501
|
-
componentPatternList(ctx) {
|
|
502
|
-
var _a, _b;
|
|
503
|
-
const componentPatterns = this.mapVisit(ctx.componentPattern);
|
|
504
|
-
const commas = (_b = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(elt => concat([elt, line]))) !== null && _b !== void 0 ? _b : [];
|
|
505
|
-
return rejectAndJoinSeps(commas, componentPatterns);
|
|
506
|
-
}
|
|
507
|
-
componentPattern(ctx) {
|
|
508
|
-
return this.visitSingle(ctx);
|
|
509
|
-
}
|
|
510
|
-
unnamedPattern(ctx) {
|
|
511
|
-
return printTokenWithComments(ctx.Underscore[0]);
|
|
512
|
-
}
|
|
513
|
-
guard(ctx) {
|
|
514
|
-
const expression = this.visit(ctx.expression, {
|
|
515
|
-
addParenthesisToWrapStatement: true
|
|
516
|
-
});
|
|
517
|
-
return concat([ctx.When[0], " ", expression]);
|
|
518
|
-
}
|
|
519
|
-
isRefTypeInMethodRef() {
|
|
520
|
-
return "isRefTypeInMethodRef";
|
|
521
|
-
}
|
|
522
|
-
isBreakableNewExpression(newExpression) {
|
|
523
|
-
var _a, _b, _c, _d, _e;
|
|
524
|
-
const arrayCreationExpression = (_a = newExpression === null || newExpression === void 0 ? void 0 : newExpression.arrayCreationExpression) === null || _a === void 0 ? void 0 : _a[0].children;
|
|
525
|
-
const classInstanceCreationExpression = (_b = newExpression === null || newExpression === void 0 ? void 0 : newExpression.unqualifiedClassInstanceCreationExpression) === null || _b === void 0 ? void 0 : _b[0].children;
|
|
526
|
-
return [
|
|
527
|
-
(_c = arrayCreationExpression === null || arrayCreationExpression === void 0 ? void 0 : arrayCreationExpression.classOrInterfaceType) === null || _c === void 0 ? void 0 : _c[0].children.classType[0].children.typeArguments,
|
|
528
|
-
(_d = arrayCreationExpression === null || arrayCreationExpression === void 0 ? void 0 : arrayCreationExpression.arrayCreationExplicitInitSuffix) === null || _d === void 0 ? void 0 : _d[0].children.arrayInitializer[0].children.variableInitializerList,
|
|
529
|
-
(_e = classInstanceCreationExpression === null || classInstanceCreationExpression === void 0 ? void 0 : classInstanceCreationExpression.classOrInterfaceTypeToInstantiate[0].children.typeArgumentsOrDiamond) === null || _e === void 0 ? void 0 : _e[0].children.typeArguments,
|
|
530
|
-
classInstanceCreationExpression === null || classInstanceCreationExpression === void 0 ? void 0 : classInstanceCreationExpression.argumentList
|
|
531
|
-
].some(breakablePart => breakablePart !== undefined);
|
|
532
|
-
}
|
|
533
|
-
isCapitalizedIdentifier(fqnOrRefType) {
|
|
534
|
-
var _a, _b, _c;
|
|
535
|
-
const fqnOrRefTypeParts = [
|
|
536
|
-
fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartFirst[0],
|
|
537
|
-
...((_a = fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartRest) !== null && _a !== void 0 ? _a : [])
|
|
538
|
-
];
|
|
539
|
-
const nextToLastIdentifier = (_c = (_b = fqnOrRefTypeParts[fqnOrRefTypeParts.length - 2]) === null || _b === void 0 ? void 0 : _b.children.fqnOrRefTypePartCommon[0].children.Identifier) === null || _c === void 0 ? void 0 : _c[0].image;
|
|
540
|
-
return (nextToLastIdentifier &&
|
|
541
|
-
/^\p{Uppercase_Letter}/u.test(nextToLastIdentifier));
|
|
542
|
-
}
|
|
543
|
-
}
|