prettier-plugin-java 2.3.1 → 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.
Files changed (97) hide show
  1. package/dist/options.js +5 -4
  2. package/dist/printers/blocks-and-statements.js +23 -40
  3. package/dist/printers/classes.js +3 -0
  4. package/dist/printers/expressions.js +26 -18
  5. package/package.json +3 -3
  6. package/dist/src/base-cst-printer.js +0 -77
  7. package/dist/src/cst-printer.js +0 -37
  8. package/dist/src/index.js +0 -67
  9. package/dist/src/options.js +0 -256
  10. package/dist/src/parser.js +0 -7
  11. package/dist/src/printer.js +0 -28
  12. package/dist/src/printers/arrays.js +0 -49
  13. package/dist/src/printers/blocks-and-statements.js +0 -493
  14. package/dist/src/printers/classes.js +0 -724
  15. package/dist/src/printers/comments/comments-utils.js +0 -29
  16. package/dist/src/printers/comments/format-comments.js +0 -187
  17. package/dist/src/printers/comments/handle-comments.js +0 -38
  18. package/dist/src/printers/expressions.js +0 -549
  19. package/dist/src/printers/interfaces.js +0 -251
  20. package/dist/src/printers/lexical-structure.js +0 -43
  21. package/dist/src/printers/names.js +0 -53
  22. package/dist/src/printers/packages-and-modules.js +0 -185
  23. package/dist/src/printers/prettier-builder.js +0 -47
  24. package/dist/src/printers/printer-utils.js +0 -577
  25. package/dist/src/printers/types-values-and-variables.js +0 -183
  26. package/dist/src/types/utils.js +0 -29
  27. package/dist/src/utils/expressions-utils.js +0 -29
  28. package/dist/src/utils/index.js +0 -10
  29. package/dist/src/utils/printArgumentListWithBraces.js +0 -21
  30. package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
  31. package/dist/test/babel-register.js +0 -3
  32. package/dist/test/repository-test/core-test.js +0 -12
  33. package/dist/test/repository-test/jhipster-1-test.js +0 -17
  34. package/dist/test/repository-test/jhipster-2-test.js +0 -16
  35. package/dist/test/test-utils.js +0 -215
  36. package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
  37. package/dist/test/unit-test/args/args-spec.js +0 -6
  38. package/dist/test/unit-test/assert/assert-spec.js +0 -6
  39. package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
  40. package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
  41. package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
  42. package/dist/test/unit-test/cast/cast-spec.js +0 -6
  43. package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
  44. package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
  45. package/dist/test/unit-test/comments/comments-spec.js +0 -14
  46. package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
  47. package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
  48. package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
  49. package/dist/test/unit-test/enum/enum-spec.js +0 -6
  50. package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
  51. package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
  52. package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
  53. package/dist/test/unit-test/for/for-spec.js +0 -6
  54. package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
  55. package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
  56. package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
  57. package/dist/test/unit-test/if/if-spec.js +0 -6
  58. package/dist/test/unit-test/indent/indent-spec.js +0 -6
  59. package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
  60. package/dist/test/unit-test/interface/interface-spec.js +0 -6
  61. package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
  62. package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
  63. package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
  64. package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
  65. package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
  66. package/dist/test/unit-test/modules/modules-spec.js +0 -6
  67. package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
  68. package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
  69. package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
  70. package/dist/test/unit-test/records/records-spec.js +0 -6
  71. package/dist/test/unit-test/return/return-spec.js +0 -6
  72. package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
  73. package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
  74. package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
  75. package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
  76. package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
  77. package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
  78. package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
  79. package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
  80. package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
  81. package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
  82. package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
  83. package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
  84. package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
  85. package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
  86. package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
  87. package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
  88. package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
  89. package/dist/test/unit-test/switch/switch-spec.js +0 -6
  90. package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
  91. package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
  92. package/dist/test/unit-test/throws/throws-spec.js +0 -6
  93. package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
  94. package/dist/test/unit-test/types/types-spec.js +0 -6
  95. package/dist/test/unit-test/variables/variables-spec.js +0 -6
  96. package/dist/test/unit-test/while/while-spec.js +0 -6
  97. package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasComments = exports.hasTrailingLineComments = exports.hasLeadingLineComments = exports.hasTrailingComments = exports.hasLeadingComments = void 0;
4
- function hasLeadingComments(token) {
5
- return token.leadingComments !== undefined;
6
- }
7
- exports.hasLeadingComments = hasLeadingComments;
8
- function hasTrailingComments(token) {
9
- return token.trailingComments !== undefined;
10
- }
11
- exports.hasTrailingComments = hasTrailingComments;
12
- function hasLeadingLineComments(token) {
13
- return (token.leadingComments !== undefined &&
14
- token.leadingComments.length !== 0 &&
15
- token.leadingComments[token.leadingComments.length - 1].tokenType.name ===
16
- "LineComment");
17
- }
18
- exports.hasLeadingLineComments = hasLeadingLineComments;
19
- function hasTrailingLineComments(token) {
20
- return (token.trailingComments !== undefined &&
21
- token.trailingComments.length !== 0 &&
22
- token.trailingComments[token.trailingComments.length - 1].tokenType.name ===
23
- "LineComment");
24
- }
25
- exports.hasTrailingLineComments = hasTrailingLineComments;
26
- function hasComments(token) {
27
- return hasLeadingComments(token) || hasTrailingComments(token);
28
- }
29
- exports.hasComments = hasComments;
@@ -1,187 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4
- to[j] = from[i];
5
- return to;
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.processComments = exports.getTokenLeadingComments = exports.printNodeWithComments = exports.printTokenWithComments = void 0;
9
- var doc_1 = require("prettier/doc");
10
- var utils_1 = require("../../types/utils");
11
- var hardline = doc_1.builders.hardline, lineSuffix = doc_1.builders.lineSuffix, breakParent = doc_1.builders.breakParent, literalline = doc_1.builders.literalline;
12
- /**
13
- * Takes a token and return a doc with:
14
- * - concatenated leading comments
15
- * - the token image
16
- * - concatenated trailing comments
17
- *
18
- * @param {IToken} token
19
- * @return a doc with the token and its comments
20
- */
21
- function printTokenWithComments(token) {
22
- return printWithComments(token, token.image, getTokenLeadingComments, getTokenTrailingComments);
23
- }
24
- exports.printTokenWithComments = printTokenWithComments;
25
- /**
26
- * Takes a node and return a doc with:
27
- * - concatenated leading comments
28
- * - the node doc value
29
- * - concatenated trailing comments
30
- *
31
- * @param {CstNode} node
32
- * @param {Doc} value - the converted node value
33
- * @return a doc with the token and its comments
34
- */
35
- function printNodeWithComments(node, value) {
36
- return printWithComments(node, value, getNodeLeadingComments, getNodeTrailingComments);
37
- }
38
- exports.printNodeWithComments = printNodeWithComments;
39
- function printWithComments(nodeOrToken, value, getLeadingComments, getTrailingComments) {
40
- var leadingComments = getLeadingComments(nodeOrToken);
41
- var trailingComments = getTrailingComments(nodeOrToken, value);
42
- return leadingComments.length === 0 && trailingComments.length === 0
43
- ? value
44
- : __spreadArray(__spreadArray(__spreadArray([], leadingComments), [value]), trailingComments);
45
- }
46
- /**
47
- * @param {IToken} token
48
- * @return an array containing processed leading comments and separators
49
- */
50
- function getTokenLeadingComments(token) {
51
- return getLeadingComments(token, token);
52
- }
53
- exports.getTokenLeadingComments = getTokenLeadingComments;
54
- /**
55
- * @param {CstNode} node
56
- * @return an array containing processed leading comments and separators
57
- */
58
- function getNodeLeadingComments(node) {
59
- return getLeadingComments(node, node.location);
60
- }
61
- function getLeadingComments(nodeOrToken, location) {
62
- var arr = [];
63
- if (nodeOrToken.leadingComments !== undefined) {
64
- var previousEndLine = nodeOrToken.leadingComments[0].endLine;
65
- var step = void 0;
66
- arr.push(formatComment(nodeOrToken.leadingComments[0]));
67
- for (var i = 1; i < nodeOrToken.leadingComments.length; i++) {
68
- step = nodeOrToken.leadingComments[i].startLine - previousEndLine;
69
- if (step === 1 ||
70
- nodeOrToken.leadingComments[i].startOffset > location.startOffset) {
71
- arr.push(hardline);
72
- }
73
- else if (step > 1) {
74
- arr.push(hardline, hardline);
75
- }
76
- arr.push(formatComment(nodeOrToken.leadingComments[i]));
77
- previousEndLine = nodeOrToken.leadingComments[i].endLine;
78
- }
79
- step = location.startLine - previousEndLine;
80
- if (step === 1 ||
81
- nodeOrToken.leadingComments[nodeOrToken.leadingComments.length - 1]
82
- .startOffset > location.startOffset) {
83
- arr.push(hardline);
84
- }
85
- else if (step > 1) {
86
- arr.push(hardline, hardline);
87
- }
88
- }
89
- return arr;
90
- }
91
- /**
92
- * @param {IToken} token
93
- * @return an array containing processed trailing comments and separators
94
- */
95
- function getTokenTrailingComments(token) {
96
- return getTrailingComments(token, token.image, token);
97
- }
98
- /**
99
- * @param {CstNode} node
100
- * @param {string} value
101
- * @return an array containing processed trailing comments and separators
102
- */
103
- function getNodeTrailingComments(node, value) {
104
- return getTrailingComments(node, value, node.location);
105
- }
106
- function getTrailingComments(nodeOrToken, value, location) {
107
- var arr = [];
108
- var previousEndLine = location.endLine;
109
- if (nodeOrToken.trailingComments !== undefined) {
110
- nodeOrToken.trailingComments.forEach(function (comment, idx) {
111
- var separator = "";
112
- if (comment.startLine !== previousEndLine) {
113
- arr.push(hardline);
114
- }
115
- else if (
116
- // TODO: CLEAN THIS UP
117
- value !== "" &&
118
- !(Array.isArray(value) && value.length === 0) &&
119
- idx === 0) {
120
- separator = " ";
121
- }
122
- else {
123
- console.log("value", value);
124
- console.log("nodeOrToken", nodeOrToken);
125
- }
126
- if (comment.tokenType.name === "LineComment") {
127
- arr.push(lineSuffix([separator, formatComment(comment), breakParent]));
128
- }
129
- else {
130
- arr.push(formatComment(comment));
131
- }
132
- previousEndLine = comment.endLine;
133
- });
134
- }
135
- return arr;
136
- }
137
- function isJavaDoc(comment, lines) {
138
- var isJavaDoc = true;
139
- if (comment.tokenType.name === "TraditionalComment" && lines.length > 1) {
140
- for (var i = 1; i < lines.length; i++) {
141
- if (lines[i].trim().charAt(0) !== "*") {
142
- isJavaDoc = false;
143
- break;
144
- }
145
- }
146
- }
147
- else {
148
- isJavaDoc = false;
149
- }
150
- return isJavaDoc;
151
- }
152
- function formatJavaDoc(lines) {
153
- var res = [lines[0].trim()];
154
- for (var i = 1; i < lines.length; i++) {
155
- res.push(hardline);
156
- res.push(" " + lines[i].trim());
157
- }
158
- return res;
159
- }
160
- function formatComment(comment) {
161
- var res = [];
162
- var lines = comment.image.split("\n");
163
- if (isJavaDoc(comment, lines)) {
164
- return formatJavaDoc(lines);
165
- }
166
- lines.forEach(function (line) {
167
- res.push(line);
168
- res.push(literalline);
169
- });
170
- res.pop();
171
- return res;
172
- }
173
- function processComments(docs) {
174
- if (!Array.isArray(docs)) {
175
- if (utils_1.isCstElementOrUndefinedIToken(docs)) {
176
- return printTokenWithComments(docs);
177
- }
178
- return docs;
179
- }
180
- return docs.map(function (elt) {
181
- if (utils_1.isCstElementOrUndefinedIToken(elt)) {
182
- return printTokenWithComments(elt);
183
- }
184
- return elt;
185
- });
186
- }
187
- exports.processComments = processComments;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleCommentsBinaryExpression = void 0;
4
- var comments_utils_1 = require("./comments-utils");
5
- function handleCommentsBinaryExpression(ctx) {
6
- var unaryExpressionIndex = 1;
7
- if (ctx.BinaryOperator !== undefined) {
8
- ctx.BinaryOperator.forEach(function (binaryOperator) {
9
- var _a;
10
- if (comments_utils_1.hasLeadingComments(binaryOperator)) {
11
- while (ctx.unaryExpression[unaryExpressionIndex].location.startOffset <
12
- binaryOperator.endOffset) {
13
- unaryExpressionIndex++;
14
- }
15
- // Adapt the position of the operator and its leading comments
16
- var shiftUp = binaryOperator.leadingComments[0].startLine -
17
- 1 -
18
- binaryOperator.startLine;
19
- if (binaryOperator.startLine !==
20
- ctx.unaryExpression[unaryExpressionIndex].location.startLine) {
21
- binaryOperator.leadingComments.forEach(function (comment) {
22
- comment.startLine += 1;
23
- comment.endLine += 1;
24
- });
25
- }
26
- binaryOperator.startLine += shiftUp;
27
- binaryOperator.endLine += shiftUp;
28
- // Assign the leading comments & trailing comments of the binaryOperator
29
- // to the following unaryExpression as leading comments
30
- ctx.unaryExpression[unaryExpressionIndex].leadingComments =
31
- ctx.unaryExpression[unaryExpressionIndex].leadingComments || [];
32
- (_a = ctx.unaryExpression[unaryExpressionIndex].leadingComments).unshift.apply(_a, binaryOperator.leadingComments);
33
- delete binaryOperator.leadingComments;
34
- }
35
- });
36
- }
37
- }
38
- exports.handleCommentsBinaryExpression = handleCommentsBinaryExpression;