prettier-plugin-java 2.4.0 → 2.5.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/dist/options.js +3 -4
- package/dist/printers/blocks-and-statements.js +20 -42
- package/dist/printers/classes.js +3 -0
- package/dist/printers/expressions.js +12 -6
- package/package.json +3 -3
- package/dist/src/base-cst-printer.js +0 -77
- package/dist/src/cst-printer.js +0 -37
- package/dist/src/index.js +0 -67
- package/dist/src/options.js +0 -256
- package/dist/src/parser.js +0 -7
- package/dist/src/printer.js +0 -28
- package/dist/src/printers/arrays.js +0 -49
- package/dist/src/printers/blocks-and-statements.js +0 -493
- package/dist/src/printers/classes.js +0 -724
- package/dist/src/printers/comments/comments-utils.js +0 -29
- package/dist/src/printers/comments/format-comments.js +0 -187
- package/dist/src/printers/comments/handle-comments.js +0 -38
- package/dist/src/printers/expressions.js +0 -549
- package/dist/src/printers/interfaces.js +0 -251
- package/dist/src/printers/lexical-structure.js +0 -43
- package/dist/src/printers/names.js +0 -53
- package/dist/src/printers/packages-and-modules.js +0 -185
- package/dist/src/printers/prettier-builder.js +0 -47
- package/dist/src/printers/printer-utils.js +0 -577
- package/dist/src/printers/types-values-and-variables.js +0 -183
- package/dist/src/types/utils.js +0 -29
- package/dist/src/utils/expressions-utils.js +0 -29
- package/dist/src/utils/index.js +0 -10
- package/dist/src/utils/printArgumentListWithBraces.js +0 -21
- package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
- package/dist/test/babel-register.js +0 -3
- package/dist/test/repository-test/core-test.js +0 -12
- package/dist/test/repository-test/jhipster-1-test.js +0 -17
- package/dist/test/repository-test/jhipster-2-test.js +0 -16
- package/dist/test/test-utils.js +0 -215
- package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
- package/dist/test/unit-test/args/args-spec.js +0 -6
- package/dist/test/unit-test/assert/assert-spec.js +0 -6
- package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
- package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
- package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
- package/dist/test/unit-test/cast/cast-spec.js +0 -6
- package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
- package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
- package/dist/test/unit-test/comments/comments-spec.js +0 -14
- package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
- package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
- package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
- package/dist/test/unit-test/enum/enum-spec.js +0 -6
- package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
- package/dist/test/unit-test/for/for-spec.js +0 -6
- package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
- package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
- package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
- package/dist/test/unit-test/if/if-spec.js +0 -6
- package/dist/test/unit-test/indent/indent-spec.js +0 -6
- package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
- package/dist/test/unit-test/interface/interface-spec.js +0 -6
- package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
- package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
- package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
- package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
- package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
- package/dist/test/unit-test/modules/modules-spec.js +0 -6
- package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
- package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
- package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
- package/dist/test/unit-test/records/records-spec.js +0 -6
- package/dist/test/unit-test/return/return-spec.js +0 -6
- package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
- package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
- package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
- package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
- package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
- package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
- package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
- package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
- package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
- package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
- package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
- package/dist/test/unit-test/switch/switch-spec.js +0 -6
- package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
- package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
- package/dist/test/unit-test/throws/throws-spec.js +0 -6
- package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
- package/dist/test/unit-test/types/types-spec.js +0 -6
- package/dist/test/unit-test/variables/variables-spec.js +0 -6
- package/dist/test/unit-test/while/while-spec.js +0 -6
- package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
14
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
15
|
-
to[j] = from[i];
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.printArrayList = exports.isUniqueMethodInvocation = exports.sortImports = exports.isStatementEmptyStatement = exports.isShiftOperator = exports.separateTokensIntoGroups = exports.putIntoBraces = exports.getInterfaceBodyDeclarationsSeparator = exports.getClassBodyDeclarationsSeparator = exports.getBlankLinesSeparator = exports.isExplicitLambdaParameter = exports.displaySemicolon = exports.findDeepElementInPartsArray = exports.sortModifiers = exports.sortClassTypeChildren = exports.matchCategory = exports.sortNodes = exports.sortAnnotationIdentifier = exports.rejectAndConcat = exports.rejectAndJoin = exports.rejectSeparators = exports.reject = exports.rejectAndJoinSeps = exports.buildFqn = void 0;
|
|
23
|
-
var forEach_1 = __importDefault(require("lodash/forEach"));
|
|
24
|
-
var forEachRight_1 = __importDefault(require("lodash/forEachRight"));
|
|
25
|
-
var findLastIndex_1 = __importDefault(require("lodash/findLastIndex"));
|
|
26
|
-
var findIndex_1 = __importDefault(require("lodash/findIndex"));
|
|
27
|
-
var includes_1 = __importDefault(require("lodash/includes"));
|
|
28
|
-
var prettier_builder_1 = require("./prettier-builder");
|
|
29
|
-
var format_comments_1 = require("./comments/format-comments");
|
|
30
|
-
var comments_utils_1 = require("./comments/comments-utils");
|
|
31
|
-
var doc_1 = require("prettier/doc");
|
|
32
|
-
var utils_1 = require("../types/utils");
|
|
33
|
-
var indent = doc_1.builders.indent, hardline = doc_1.builders.hardline, line = doc_1.builders.line;
|
|
34
|
-
var orderedModifiers = [
|
|
35
|
-
"Public",
|
|
36
|
-
"Protected",
|
|
37
|
-
"Private",
|
|
38
|
-
"Abstract",
|
|
39
|
-
"Default",
|
|
40
|
-
"Static",
|
|
41
|
-
"Final",
|
|
42
|
-
"Transient",
|
|
43
|
-
"Volatile",
|
|
44
|
-
"Synchronized",
|
|
45
|
-
"Native",
|
|
46
|
-
"Sealed",
|
|
47
|
-
"NonSealed",
|
|
48
|
-
"Strictfp"
|
|
49
|
-
];
|
|
50
|
-
function buildFqn(tokens, dots) {
|
|
51
|
-
return rejectAndJoinSeps(dots ? dots : [], tokens);
|
|
52
|
-
}
|
|
53
|
-
exports.buildFqn = buildFqn;
|
|
54
|
-
function rejectAndJoinSeps(sepTokens, elems, sep) {
|
|
55
|
-
if (!Array.isArray(sepTokens)) {
|
|
56
|
-
return rejectAndJoin(sepTokens, elems);
|
|
57
|
-
}
|
|
58
|
-
var actualElements = reject(elems);
|
|
59
|
-
var res = [];
|
|
60
|
-
for (var i = 0; i < sepTokens.length; i++) {
|
|
61
|
-
res.push(actualElements[i], sepTokens[i]);
|
|
62
|
-
if (sep) {
|
|
63
|
-
res.push(sep);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
res.push.apply(res, actualElements.slice(sepTokens.length));
|
|
67
|
-
return prettier_builder_1.concat(res);
|
|
68
|
-
}
|
|
69
|
-
exports.rejectAndJoinSeps = rejectAndJoinSeps;
|
|
70
|
-
function reject(elems) {
|
|
71
|
-
return elems.filter(function (item) {
|
|
72
|
-
if (typeof item === "string") {
|
|
73
|
-
return item !== "";
|
|
74
|
-
}
|
|
75
|
-
// eslint-ignore next - We want the conversion to boolean!
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
return item != false && item !== undefined;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
exports.reject = reject;
|
|
81
|
-
function rejectSeparators(separators, elems) {
|
|
82
|
-
var realElements = reject(elems);
|
|
83
|
-
var realSeparators = [];
|
|
84
|
-
for (var i = 0; i < realElements.length - 1; i++) {
|
|
85
|
-
if (realElements[i] !== "") {
|
|
86
|
-
realSeparators.push(separators[i]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return realSeparators;
|
|
90
|
-
}
|
|
91
|
-
exports.rejectSeparators = rejectSeparators;
|
|
92
|
-
function rejectAndJoin(sep, elems) {
|
|
93
|
-
var actualElements = reject(elems);
|
|
94
|
-
return prettier_builder_1.join(sep, actualElements);
|
|
95
|
-
}
|
|
96
|
-
exports.rejectAndJoin = rejectAndJoin;
|
|
97
|
-
function rejectAndConcat(elems) {
|
|
98
|
-
var actualElements = reject(elems);
|
|
99
|
-
return prettier_builder_1.concat(actualElements);
|
|
100
|
-
}
|
|
101
|
-
exports.rejectAndConcat = rejectAndConcat;
|
|
102
|
-
function sortAnnotationIdentifier(annotations, identifiers) {
|
|
103
|
-
var tokens = __spreadArray([], identifiers);
|
|
104
|
-
if (annotations && annotations.length > 0) {
|
|
105
|
-
tokens = __spreadArray(__spreadArray([], tokens), annotations);
|
|
106
|
-
}
|
|
107
|
-
return tokens.sort(function (a, b) {
|
|
108
|
-
var startOffset1 = utils_1.isCstNode(a)
|
|
109
|
-
? a.children.At[0].startOffset
|
|
110
|
-
: a.startOffset;
|
|
111
|
-
var startOffset2 = utils_1.isCstNode(b)
|
|
112
|
-
? b.children.At[0].startOffset
|
|
113
|
-
: b.startOffset;
|
|
114
|
-
return startOffset1 - startOffset2;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
exports.sortAnnotationIdentifier = sortAnnotationIdentifier;
|
|
118
|
-
function sortTokens(values) {
|
|
119
|
-
var tokens = [];
|
|
120
|
-
forEach_1.default(values, function (argument) {
|
|
121
|
-
if (argument) {
|
|
122
|
-
tokens = tokens.concat(argument);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return tokens.sort(function (a, b) {
|
|
126
|
-
return a.startOffset - b.startOffset;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function sortNodes(values) {
|
|
130
|
-
var nodes = [];
|
|
131
|
-
forEach_1.default(values, function (argument) {
|
|
132
|
-
if (argument) {
|
|
133
|
-
nodes = nodes.concat(argument);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return nodes.sort(function (a, b) {
|
|
137
|
-
var aOffset = a.location.startOffset;
|
|
138
|
-
var bOffset = b.location.startOffset;
|
|
139
|
-
return aOffset - bOffset;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
exports.sortNodes = sortNodes;
|
|
143
|
-
function matchCategory(token, categoryName) {
|
|
144
|
-
var labels = (token.tokenType.CATEGORIES || []).map(function (category) {
|
|
145
|
-
return category.LABEL;
|
|
146
|
-
});
|
|
147
|
-
return labels.indexOf(categoryName) !== -1;
|
|
148
|
-
}
|
|
149
|
-
exports.matchCategory = matchCategory;
|
|
150
|
-
function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
|
|
151
|
-
var tokens = __spreadArray([], identifiers);
|
|
152
|
-
if (annotations && annotations.length > 0) {
|
|
153
|
-
tokens = __spreadArray(__spreadArray([], tokens), annotations);
|
|
154
|
-
}
|
|
155
|
-
if (typeArguments && typeArguments.length > 0) {
|
|
156
|
-
tokens = __spreadArray(__spreadArray([], tokens), typeArguments);
|
|
157
|
-
}
|
|
158
|
-
if (dots && dots.length > 0) {
|
|
159
|
-
tokens = __spreadArray(__spreadArray([], tokens), dots);
|
|
160
|
-
}
|
|
161
|
-
return tokens.sort(function (a, b) {
|
|
162
|
-
var startOffsetA = utils_1.isCstNode(a)
|
|
163
|
-
? a.children.At
|
|
164
|
-
? a.children.At[0].startOffset
|
|
165
|
-
: a.children.Less[0].startOffset
|
|
166
|
-
: a.startOffset;
|
|
167
|
-
var startOffsetB = utils_1.isCstNode(b)
|
|
168
|
-
? b.children.At
|
|
169
|
-
? b.children.At[0].startOffset
|
|
170
|
-
: b.children.Less[0].startOffset
|
|
171
|
-
: b.startOffset;
|
|
172
|
-
return startOffsetA - startOffsetB;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
exports.sortClassTypeChildren = sortClassTypeChildren;
|
|
176
|
-
function sortModifiers(modifiers) {
|
|
177
|
-
var firstAnnotations = [];
|
|
178
|
-
var otherModifiers = [];
|
|
179
|
-
var lastAnnotations = [];
|
|
180
|
-
var hasOtherModifier = false;
|
|
181
|
-
/**
|
|
182
|
-
* iterate in reverse order because we special-case
|
|
183
|
-
* method annotations which come after all other
|
|
184
|
-
* modifiers
|
|
185
|
-
*/
|
|
186
|
-
forEachRight_1.default(modifiers, function (modifier) {
|
|
187
|
-
var isAnnotation = modifier.children.annotation !== undefined;
|
|
188
|
-
var isMethodAnnotation = isAnnotation &&
|
|
189
|
-
(modifier.name === "methodModifier" ||
|
|
190
|
-
modifier.name === "interfaceMethodModifier");
|
|
191
|
-
if (isAnnotation) {
|
|
192
|
-
if (isMethodAnnotation && !hasOtherModifier) {
|
|
193
|
-
lastAnnotations.unshift(modifier);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
firstAnnotations.unshift(modifier);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
otherModifiers.unshift(modifier);
|
|
201
|
-
hasOtherModifier = true;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
/**
|
|
205
|
-
* if there are only annotations, move everything from
|
|
206
|
-
* lastAnnotations to firstAnnotations
|
|
207
|
-
*/
|
|
208
|
-
if (!hasOtherModifier) {
|
|
209
|
-
firstAnnotations = firstAnnotations.concat(lastAnnotations);
|
|
210
|
-
lastAnnotations = [];
|
|
211
|
-
}
|
|
212
|
-
otherModifiers.sort(function (a, b) {
|
|
213
|
-
var modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]);
|
|
214
|
-
var modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]);
|
|
215
|
-
return modifierIndexA - modifierIndexB;
|
|
216
|
-
});
|
|
217
|
-
return [firstAnnotations, otherModifiers.concat(lastAnnotations)];
|
|
218
|
-
}
|
|
219
|
-
exports.sortModifiers = sortModifiers;
|
|
220
|
-
function findDeepElementInPartsArray(item, elt) {
|
|
221
|
-
if (Array.isArray(item)) {
|
|
222
|
-
if (includes_1.default(item, elt)) {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
for (var i = 0; i < item.length; i++) {
|
|
226
|
-
if (findDeepElementInPartsArray(item[i], elt)) {
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
for (var key in item) {
|
|
233
|
-
if (typeof item[key] === "object" &&
|
|
234
|
-
findDeepElementInPartsArray(item[key], elt)) {
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
exports.findDeepElementInPartsArray = findDeepElementInPartsArray;
|
|
242
|
-
function displaySemicolon(token, params) {
|
|
243
|
-
if (params !== undefined && params.allowEmptyStatement) {
|
|
244
|
-
return format_comments_1.printTokenWithComments(token);
|
|
245
|
-
}
|
|
246
|
-
if (!comments_utils_1.hasComments(token)) {
|
|
247
|
-
return "";
|
|
248
|
-
}
|
|
249
|
-
token.image = "";
|
|
250
|
-
return format_comments_1.printTokenWithComments(token);
|
|
251
|
-
}
|
|
252
|
-
exports.displaySemicolon = displaySemicolon;
|
|
253
|
-
function isExplicitLambdaParameter(ctx) {
|
|
254
|
-
return (ctx &&
|
|
255
|
-
ctx.lambdaParameterList &&
|
|
256
|
-
ctx.lambdaParameterList[0] &&
|
|
257
|
-
ctx.lambdaParameterList[0].children &&
|
|
258
|
-
ctx.lambdaParameterList[0].children.explicitLambdaParameterList);
|
|
259
|
-
}
|
|
260
|
-
exports.isExplicitLambdaParameter = isExplicitLambdaParameter;
|
|
261
|
-
function getBlankLinesSeparator(ctx, separator) {
|
|
262
|
-
if (separator === void 0) { separator = hardline; }
|
|
263
|
-
if (ctx === undefined) {
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
var separators = [];
|
|
267
|
-
for (var i = 0; i < ctx.length - 1; i++) {
|
|
268
|
-
var node = ctx[i];
|
|
269
|
-
var previousRuleEndLineWithComment = comments_utils_1.hasTrailingComments(node)
|
|
270
|
-
? node.trailingComments[node.trailingComments.length - 1].endLine
|
|
271
|
-
: node.location.endLine;
|
|
272
|
-
var nextNode = ctx[i + 1];
|
|
273
|
-
var nextRuleStartLineWithComment = comments_utils_1.hasLeadingComments(nextNode)
|
|
274
|
-
? nextNode.leadingComments[0].startLine
|
|
275
|
-
: nextNode.location.startLine;
|
|
276
|
-
if (nextRuleStartLineWithComment - previousRuleEndLineWithComment > 1) {
|
|
277
|
-
separators.push([hardline, hardline]);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
separators.push(separator);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return separators;
|
|
284
|
-
}
|
|
285
|
-
exports.getBlankLinesSeparator = getBlankLinesSeparator;
|
|
286
|
-
// TODO: CLEAN THIS UP
|
|
287
|
-
function isTwoHardLineMethod(userBlankLinesSeparators, indexNextNotEmptyDeclaration) {
|
|
288
|
-
if (userBlankLinesSeparators === undefined) {
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
var nextNotEmptyDeclarationSeparator = userBlankLinesSeparators[indexNextNotEmptyDeclaration];
|
|
292
|
-
if (Array.isArray(nextNotEmptyDeclarationSeparator)) {
|
|
293
|
-
return (nextNotEmptyDeclarationSeparator.length === 2 &&
|
|
294
|
-
nextNotEmptyDeclarationSeparator[0] === hardline &&
|
|
295
|
-
nextNotEmptyDeclarationSeparator[1] === hardline);
|
|
296
|
-
}
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
function getDeclarationsSeparator(declarations, needLineDeclaration, isSemicolon) {
|
|
300
|
-
var declarationsWithoutEmptyStatements = declarations.filter(function (declaration) { return !isSemicolon(declaration); });
|
|
301
|
-
var userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements);
|
|
302
|
-
var additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration);
|
|
303
|
-
var separators = [];
|
|
304
|
-
var indexNextNotEmptyDeclaration = 0;
|
|
305
|
-
for (var i = 0; i < declarations.length - 1; i++) {
|
|
306
|
-
// if the empty statement has comments
|
|
307
|
-
// we want to print them on their own line
|
|
308
|
-
if (isSemicolon(declarations[i])) {
|
|
309
|
-
if (comments_utils_1.hasComments(declarations[i])) {
|
|
310
|
-
separators.push(hardline);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else if (indexNextNotEmptyDeclaration <
|
|
314
|
-
declarationsWithoutEmptyStatements.length - 1) {
|
|
315
|
-
var isTwoHardLines = isTwoHardLineMethod(userBlankLinesSeparators, indexNextNotEmptyDeclaration);
|
|
316
|
-
// @ts-ignore
|
|
317
|
-
var additionalSep = !isTwoHardLines &&
|
|
318
|
-
(additionalBlankLines[indexNextNotEmptyDeclaration + 1] ||
|
|
319
|
-
additionalBlankLines[indexNextNotEmptyDeclaration])
|
|
320
|
-
? hardline
|
|
321
|
-
: "";
|
|
322
|
-
separators.push(prettier_builder_1.concat([
|
|
323
|
-
userBlankLinesSeparators[indexNextNotEmptyDeclaration],
|
|
324
|
-
additionalSep
|
|
325
|
-
]));
|
|
326
|
-
indexNextNotEmptyDeclaration += 1;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return separators;
|
|
330
|
-
}
|
|
331
|
-
function needLineClassBodyDeclaration(declaration) {
|
|
332
|
-
if (declaration.children.classMemberDeclaration === undefined) {
|
|
333
|
-
return true;
|
|
334
|
-
}
|
|
335
|
-
var classMemberDeclaration = declaration.children.classMemberDeclaration[0];
|
|
336
|
-
if (classMemberDeclaration.children.fieldDeclaration !== undefined) {
|
|
337
|
-
var fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0];
|
|
338
|
-
if (fieldDeclaration.children.fieldModifier !== undefined &&
|
|
339
|
-
hasAnnotation(fieldDeclaration.children.fieldModifier)) {
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
else if (classMemberDeclaration.children.Semicolon !== undefined) {
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
|
-
function needLineInterfaceMemberDeclaration(declaration) {
|
|
350
|
-
if (declaration.children.constantDeclaration !== undefined) {
|
|
351
|
-
var constantDeclaration = declaration.children.constantDeclaration[0];
|
|
352
|
-
if (constantDeclaration.children.constantModifier !== undefined &&
|
|
353
|
-
hasAnnotation(constantDeclaration.children.constantModifier)) {
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
else if (declaration.children.interfaceMethodDeclaration !== undefined) {
|
|
359
|
-
var interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0];
|
|
360
|
-
if (interfaceMethodDeclaration.children.interfaceMethodModifier !==
|
|
361
|
-
undefined &&
|
|
362
|
-
hasNonTrailingAnnotation(interfaceMethodDeclaration.children.interfaceMethodModifier)) {
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
function isClassBodyDeclarationASemicolon(classBodyDeclaration) {
|
|
370
|
-
if (classBodyDeclaration.children.classMemberDeclaration) {
|
|
371
|
-
if (classBodyDeclaration.children.classMemberDeclaration[0].children
|
|
372
|
-
.Semicolon !== undefined) {
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
function isInterfaceMemberASemicolon(interfaceMemberDeclaration) {
|
|
379
|
-
return interfaceMemberDeclaration.children.Semicolon !== undefined;
|
|
380
|
-
}
|
|
381
|
-
function hasAnnotation(modifiers) {
|
|
382
|
-
return modifiers.some(function (modifier) { return modifier.children.annotation !== undefined; });
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Return true if there is a method modifier that does not come after all other modifiers
|
|
386
|
-
* It is useful to know if sortModifiers will add an annotation before other modifiers
|
|
387
|
-
*
|
|
388
|
-
* @param methodModifiers
|
|
389
|
-
* @returns {boolean}
|
|
390
|
-
*/
|
|
391
|
-
function hasNonTrailingAnnotation(methodModifiers) {
|
|
392
|
-
var firstAnnotationIndex = findIndex_1.default(methodModifiers, function (modifier) { return modifier.children.annotation !== undefined; });
|
|
393
|
-
var lastNonAnnotationIndex = findLastIndex_1.default(methodModifiers, function (modifier) { return modifier.children.annotation === undefined; });
|
|
394
|
-
return (firstAnnotationIndex < lastNonAnnotationIndex ||
|
|
395
|
-
lastNonAnnotationIndex === -1);
|
|
396
|
-
}
|
|
397
|
-
function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) {
|
|
398
|
-
return getDeclarationsSeparator(classBodyDeclarationContext, needLineClassBodyDeclaration, isClassBodyDeclarationASemicolon);
|
|
399
|
-
}
|
|
400
|
-
exports.getClassBodyDeclarationsSeparator = getClassBodyDeclarationsSeparator;
|
|
401
|
-
function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) {
|
|
402
|
-
return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon);
|
|
403
|
-
}
|
|
404
|
-
exports.getInterfaceBodyDeclarationsSeparator = getInterfaceBodyDeclarationsSeparator;
|
|
405
|
-
function putIntoBraces(argument, separator, LBrace, RBrace) {
|
|
406
|
-
var rightBraceLeadingComments = format_comments_1.getTokenLeadingComments(RBrace);
|
|
407
|
-
var lastBreakLine =
|
|
408
|
-
// check if last element of the array is a line
|
|
409
|
-
rightBraceLeadingComments.length !== 0 &&
|
|
410
|
-
rightBraceLeadingComments[rightBraceLeadingComments.length - 1] === hardline
|
|
411
|
-
? rightBraceLeadingComments.pop()
|
|
412
|
-
: separator;
|
|
413
|
-
delete RBrace.leadingComments;
|
|
414
|
-
var contentInsideBraces;
|
|
415
|
-
// TODO: remove ts-ignore
|
|
416
|
-
// @ts-ignore
|
|
417
|
-
if (argument === undefined || argument === "" || argument.length === 0) {
|
|
418
|
-
if (rightBraceLeadingComments.length === 0) {
|
|
419
|
-
return prettier_builder_1.concat([LBrace, RBrace]);
|
|
420
|
-
}
|
|
421
|
-
contentInsideBraces = __spreadArray([separator], rightBraceLeadingComments);
|
|
422
|
-
}
|
|
423
|
-
else if (rightBraceLeadingComments.length !== 0) {
|
|
424
|
-
contentInsideBraces = __spreadArray([
|
|
425
|
-
separator,
|
|
426
|
-
argument,
|
|
427
|
-
separator
|
|
428
|
-
], rightBraceLeadingComments);
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
contentInsideBraces = [separator, argument];
|
|
432
|
-
}
|
|
433
|
-
return prettier_builder_1.group(rejectAndConcat([
|
|
434
|
-
LBrace,
|
|
435
|
-
indent(prettier_builder_1.concat(contentInsideBraces)),
|
|
436
|
-
lastBreakLine,
|
|
437
|
-
RBrace
|
|
438
|
-
]));
|
|
439
|
-
}
|
|
440
|
-
exports.putIntoBraces = putIntoBraces;
|
|
441
|
-
var andOrBinaryOperators = ["&&", "||", "&", "|", "^"];
|
|
442
|
-
function separateTokensIntoGroups(ctx) {
|
|
443
|
-
/**
|
|
444
|
-
* separate tokens into groups by andOrBinaryOperators ("&&", "||", "&", "|", "^")
|
|
445
|
-
* in order to break those operators in priority.
|
|
446
|
-
*/
|
|
447
|
-
var tokens = sortTokens([
|
|
448
|
-
ctx.Instanceof,
|
|
449
|
-
ctx.AssignmentOperator,
|
|
450
|
-
ctx.Less,
|
|
451
|
-
ctx.Greater,
|
|
452
|
-
ctx.BinaryOperator
|
|
453
|
-
]);
|
|
454
|
-
var groupsOfOperator = [];
|
|
455
|
-
var sortedBinaryOperators = [];
|
|
456
|
-
var tmpGroup = [];
|
|
457
|
-
tokens.forEach(function (token) {
|
|
458
|
-
if (matchCategory(token, "'BinaryOperator'") &&
|
|
459
|
-
includes_1.default(andOrBinaryOperators, token.image)) {
|
|
460
|
-
sortedBinaryOperators.push(token);
|
|
461
|
-
groupsOfOperator.push(tmpGroup);
|
|
462
|
-
tmpGroup = [];
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
tmpGroup.push(token);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
groupsOfOperator.push(tmpGroup);
|
|
469
|
-
return {
|
|
470
|
-
groupsOfOperator: groupsOfOperator,
|
|
471
|
-
sortedBinaryOperators: sortedBinaryOperators
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
exports.separateTokensIntoGroups = separateTokensIntoGroups;
|
|
475
|
-
function isShiftOperator(tokens, index) {
|
|
476
|
-
if (tokens.length <= index + 1) {
|
|
477
|
-
return "none";
|
|
478
|
-
}
|
|
479
|
-
if (tokens[index].image === "<" &&
|
|
480
|
-
tokens[index + 1].image === "<" &&
|
|
481
|
-
tokens[index].startOffset === tokens[index + 1].startOffset - 1) {
|
|
482
|
-
return "leftShift";
|
|
483
|
-
}
|
|
484
|
-
if (tokens[index].image === ">" &&
|
|
485
|
-
tokens[index + 1].image === ">" &&
|
|
486
|
-
tokens[index].startOffset === tokens[index + 1].startOffset - 1) {
|
|
487
|
-
if (tokens.length > index + 2 &&
|
|
488
|
-
tokens[index + 2].image === ">" &&
|
|
489
|
-
tokens[index + 1].startOffset === tokens[index + 2].startOffset - 1) {
|
|
490
|
-
return "doubleRightShift";
|
|
491
|
-
}
|
|
492
|
-
return "rightShift";
|
|
493
|
-
}
|
|
494
|
-
return "none";
|
|
495
|
-
}
|
|
496
|
-
exports.isShiftOperator = isShiftOperator;
|
|
497
|
-
function isStatementEmptyStatement(statement) {
|
|
498
|
-
return (statement === ";" ||
|
|
499
|
-
// @ts-ignore
|
|
500
|
-
statement[0] === ";");
|
|
501
|
-
}
|
|
502
|
-
exports.isStatementEmptyStatement = isStatementEmptyStatement;
|
|
503
|
-
function sortImports(imports) {
|
|
504
|
-
var staticImports = [];
|
|
505
|
-
var nonStaticImports = [];
|
|
506
|
-
if (imports !== undefined) {
|
|
507
|
-
for (var i = 0; i < imports.length; i++) {
|
|
508
|
-
if (imports[i].children.Static !== undefined) {
|
|
509
|
-
staticImports.push(imports[i]);
|
|
510
|
-
}
|
|
511
|
-
else if (imports[i].children.emptyStatement === undefined) {
|
|
512
|
-
nonStaticImports.push(imports[i]);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
// TODO: Could be optimized as we could expect that the array is already almost sorted
|
|
516
|
-
var comparator = function (first, second) {
|
|
517
|
-
return compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]);
|
|
518
|
-
};
|
|
519
|
-
staticImports.sort(comparator);
|
|
520
|
-
nonStaticImports.sort(comparator);
|
|
521
|
-
}
|
|
522
|
-
return {
|
|
523
|
-
staticImports: staticImports,
|
|
524
|
-
nonStaticImports: nonStaticImports
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
exports.sortImports = sortImports;
|
|
528
|
-
function compareFqn(packageOrTypeNameFirst, packageOrTypeNameSecond) {
|
|
529
|
-
var identifiersFirst = packageOrTypeNameFirst.children.Identifier;
|
|
530
|
-
var identifiersSecond = packageOrTypeNameSecond.children.Identifier;
|
|
531
|
-
var minParts = Math.min(identifiersFirst.length, identifiersSecond.length);
|
|
532
|
-
for (var i = 0; i < minParts; i++) {
|
|
533
|
-
if (identifiersFirst[i].image < identifiersSecond[i].image) {
|
|
534
|
-
return -1;
|
|
535
|
-
}
|
|
536
|
-
else if (identifiersFirst[i].image > identifiersSecond[i].image) {
|
|
537
|
-
return 1;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
if (identifiersFirst.length < identifiersSecond.length) {
|
|
541
|
-
return -1;
|
|
542
|
-
}
|
|
543
|
-
else if (identifiersFirst.length > identifiersSecond.length) {
|
|
544
|
-
return 1;
|
|
545
|
-
}
|
|
546
|
-
return 0;
|
|
547
|
-
}
|
|
548
|
-
function isUniqueMethodInvocation(primarySuffixes) {
|
|
549
|
-
if (primarySuffixes === undefined) {
|
|
550
|
-
return 0;
|
|
551
|
-
}
|
|
552
|
-
var count = 0;
|
|
553
|
-
primarySuffixes.forEach(function (primarySuffix) {
|
|
554
|
-
if (primarySuffix.children.methodInvocationSuffix !== undefined) {
|
|
555
|
-
count++;
|
|
556
|
-
if (count > 1) {
|
|
557
|
-
return 2;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
return count;
|
|
562
|
-
}
|
|
563
|
-
exports.isUniqueMethodInvocation = isUniqueMethodInvocation;
|
|
564
|
-
function printArrayList(_a) {
|
|
565
|
-
var list = _a.list, extraComma = _a.extraComma, LCurly = _a.LCurly, RCurly = _a.RCurly, trailingComma = _a.trailingComma;
|
|
566
|
-
var optionalComma;
|
|
567
|
-
if (trailingComma !== "none" && list !== "") {
|
|
568
|
-
optionalComma = extraComma
|
|
569
|
-
? prettier_builder_1.ifBreak(extraComma[0], __assign(__assign({}, extraComma[0]), { image: "" }))
|
|
570
|
-
: prettier_builder_1.ifBreak(",", "");
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
optionalComma = extraComma ? __assign(__assign({}, extraComma[0]), { image: "" }) : "";
|
|
574
|
-
}
|
|
575
|
-
return putIntoBraces(rejectAndConcat([list, optionalComma]), line, LCurly, RCurly);
|
|
576
|
-
}
|
|
577
|
-
exports.printArrayList = printArrayList;
|