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