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