prettier-plugin-java 2.5.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/package.json +15 -13
- package/dist/base-cst-printer.js +0 -77
- package/dist/cst-printer.js +0 -37
- package/dist/index.js +0 -67
- package/dist/options.js +0 -258
- package/dist/parser.js +0 -6
- package/dist/printer.js +0 -8
- package/dist/printers/arrays.js +0 -49
- package/dist/printers/blocks-and-statements.js +0 -480
- package/dist/printers/classes.js +0 -745
- package/dist/printers/comments/comments-utils.js +0 -29
- package/dist/printers/comments/format-comments.js +0 -187
- package/dist/printers/comments/handle-comments.js +0 -79
- package/dist/printers/expressions.js +0 -557
- package/dist/printers/interfaces.js +0 -251
- package/dist/printers/lexical-structure.js +0 -63
- package/dist/printers/names.js +0 -53
- package/dist/printers/packages-and-modules.js +0 -198
- package/dist/printers/prettier-builder.js +0 -55
- package/dist/printers/printer-utils.js +0 -640
- package/dist/printers/types-values-and-variables.js +0 -191
- package/dist/types/utils.js +0 -29
- package/dist/utils/expressions-utils.js +0 -29
- package/dist/utils/index.js +0 -12
- package/dist/utils/isEmptyDoc.js +0 -6
- package/dist/utils/printArgumentListWithBraces.js +0 -21
- package/dist/utils/printSingleLambdaInvocation.js +0 -20
|
@@ -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, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.processComments = exports.getTokenLeadingComments = exports.printNodeWithComments = exports.printTokenWithComments = void 0;
|
|
16
|
-
var doc_1 = require("prettier/doc");
|
|
17
|
-
var utils_1 = require("../../types/utils");
|
|
18
|
-
var isEmptyDoc_1 = __importDefault(require("../../utils/isEmptyDoc"));
|
|
19
|
-
var hardline = doc_1.builders.hardline, lineSuffix = doc_1.builders.lineSuffix, breakParent = doc_1.builders.breakParent, literalline = doc_1.builders.literalline;
|
|
20
|
-
/**
|
|
21
|
-
* Takes a token and return a doc with:
|
|
22
|
-
* - concatenated leading comments
|
|
23
|
-
* - the token image
|
|
24
|
-
* - concatenated trailing comments
|
|
25
|
-
*
|
|
26
|
-
* @param {IToken} token
|
|
27
|
-
* @return a doc with the token and its comments
|
|
28
|
-
*/
|
|
29
|
-
function printTokenWithComments(token) {
|
|
30
|
-
return printWithComments(token, token.image, getTokenLeadingComments, getTokenTrailingComments);
|
|
31
|
-
}
|
|
32
|
-
exports.printTokenWithComments = printTokenWithComments;
|
|
33
|
-
/**
|
|
34
|
-
* Takes a node and return a doc with:
|
|
35
|
-
* - concatenated leading comments
|
|
36
|
-
* - the node doc value
|
|
37
|
-
* - concatenated trailing comments
|
|
38
|
-
*
|
|
39
|
-
* @param {CstNode} node
|
|
40
|
-
* @param {Doc} value - the converted node value
|
|
41
|
-
* @return a doc with the token and its comments
|
|
42
|
-
*/
|
|
43
|
-
function printNodeWithComments(node, value) {
|
|
44
|
-
return printWithComments(node, value, getNodeLeadingComments, getNodeTrailingComments);
|
|
45
|
-
}
|
|
46
|
-
exports.printNodeWithComments = printNodeWithComments;
|
|
47
|
-
function printWithComments(nodeOrToken, value, getLeadingComments, getTrailingComments) {
|
|
48
|
-
var leadingComments = getLeadingComments(nodeOrToken);
|
|
49
|
-
var trailingComments = getTrailingComments(nodeOrToken, value);
|
|
50
|
-
return leadingComments.length === 0 && trailingComments.length === 0
|
|
51
|
-
? value
|
|
52
|
-
: __spreadArray(__spreadArray(__spreadArray([], leadingComments, true), [value], false), trailingComments, true);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @param {IToken} token
|
|
56
|
-
* @return an array containing processed leading comments and separators
|
|
57
|
-
*/
|
|
58
|
-
function getTokenLeadingComments(token) {
|
|
59
|
-
return getLeadingComments(token, token);
|
|
60
|
-
}
|
|
61
|
-
exports.getTokenLeadingComments = getTokenLeadingComments;
|
|
62
|
-
/**
|
|
63
|
-
* @param {CstNode} node
|
|
64
|
-
* @return an array containing processed leading comments and separators
|
|
65
|
-
*/
|
|
66
|
-
function getNodeLeadingComments(node) {
|
|
67
|
-
return getLeadingComments(node, node.location);
|
|
68
|
-
}
|
|
69
|
-
function getLeadingComments(nodeOrToken, location) {
|
|
70
|
-
var arr = [];
|
|
71
|
-
if (nodeOrToken.leadingComments !== undefined) {
|
|
72
|
-
var previousEndLine = nodeOrToken.leadingComments[0].endLine;
|
|
73
|
-
var step = void 0;
|
|
74
|
-
arr.push(formatComment(nodeOrToken.leadingComments[0]));
|
|
75
|
-
for (var i = 1; i < nodeOrToken.leadingComments.length; i++) {
|
|
76
|
-
step = nodeOrToken.leadingComments[i].startLine - previousEndLine;
|
|
77
|
-
if (step === 1 ||
|
|
78
|
-
nodeOrToken.leadingComments[i].startOffset > location.startOffset) {
|
|
79
|
-
arr.push(hardline);
|
|
80
|
-
}
|
|
81
|
-
else if (step > 1) {
|
|
82
|
-
arr.push(hardline, hardline);
|
|
83
|
-
}
|
|
84
|
-
arr.push(formatComment(nodeOrToken.leadingComments[i]));
|
|
85
|
-
previousEndLine = nodeOrToken.leadingComments[i].endLine;
|
|
86
|
-
}
|
|
87
|
-
step = location.startLine - previousEndLine;
|
|
88
|
-
if (step === 1 ||
|
|
89
|
-
nodeOrToken.leadingComments[nodeOrToken.leadingComments.length - 1]
|
|
90
|
-
.startOffset > location.startOffset) {
|
|
91
|
-
arr.push(hardline);
|
|
92
|
-
}
|
|
93
|
-
else if (step > 1) {
|
|
94
|
-
arr.push(hardline, hardline);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return arr;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @param {IToken} token
|
|
101
|
-
* @return an array containing processed trailing comments and separators
|
|
102
|
-
*/
|
|
103
|
-
function getTokenTrailingComments(token) {
|
|
104
|
-
return getTrailingComments(token, token.image, token);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* @param {CstNode} node
|
|
108
|
-
* @param {string} value
|
|
109
|
-
* @return an array containing processed trailing comments and separators
|
|
110
|
-
*/
|
|
111
|
-
function getNodeTrailingComments(node, value) {
|
|
112
|
-
return getTrailingComments(node, value, node.location);
|
|
113
|
-
}
|
|
114
|
-
function getTrailingComments(nodeOrToken, value, location) {
|
|
115
|
-
var arr = [];
|
|
116
|
-
var previousEndLine = location.endLine;
|
|
117
|
-
if (nodeOrToken.trailingComments !== undefined) {
|
|
118
|
-
nodeOrToken.trailingComments.forEach(function (comment, idx) {
|
|
119
|
-
var separator = "";
|
|
120
|
-
if (comment.startLine !== previousEndLine) {
|
|
121
|
-
arr.push(hardline);
|
|
122
|
-
}
|
|
123
|
-
else if (!(0, isEmptyDoc_1.default)(value) && idx === 0) {
|
|
124
|
-
separator = " ";
|
|
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 ((0, utils_1.isCstElementOrUndefinedIToken)(docs)) {
|
|
176
|
-
return printTokenWithComments(docs);
|
|
177
|
-
}
|
|
178
|
-
return docs;
|
|
179
|
-
}
|
|
180
|
-
return docs.map(function (elt) {
|
|
181
|
-
if ((0, utils_1.isCstElementOrUndefinedIToken)(elt)) {
|
|
182
|
-
return printTokenWithComments(elt);
|
|
183
|
-
}
|
|
184
|
-
return elt;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
exports.processComments = processComments;
|
|
@@ -1,79 +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
|
-
moveOperatorLeadingCommentsToNextExpression(ctx);
|
|
7
|
-
moveExpressionTrailingCommentsToNextOperator(ctx);
|
|
8
|
-
}
|
|
9
|
-
exports.handleCommentsBinaryExpression = handleCommentsBinaryExpression;
|
|
10
|
-
function moveOperatorLeadingCommentsToNextExpression(ctx) {
|
|
11
|
-
var _a;
|
|
12
|
-
var unaryExpressionIndex = 1;
|
|
13
|
-
(_a = ctx.BinaryOperator) === null || _a === void 0 ? void 0 : _a.forEach(function (binaryOperator) {
|
|
14
|
-
var _a;
|
|
15
|
-
if ((0, comments_utils_1.hasLeadingComments)(binaryOperator)) {
|
|
16
|
-
while (ctx.unaryExpression[unaryExpressionIndex].location.startOffset <
|
|
17
|
-
binaryOperator.endOffset) {
|
|
18
|
-
unaryExpressionIndex++;
|
|
19
|
-
}
|
|
20
|
-
// Adapt the position of the operator and its leading comments
|
|
21
|
-
var shiftUp = binaryOperator.leadingComments[0].startLine -
|
|
22
|
-
1 -
|
|
23
|
-
binaryOperator.startLine;
|
|
24
|
-
if (binaryOperator.startLine !==
|
|
25
|
-
ctx.unaryExpression[unaryExpressionIndex].location.startLine) {
|
|
26
|
-
binaryOperator.leadingComments.forEach(function (comment) {
|
|
27
|
-
comment.startLine += 1;
|
|
28
|
-
comment.endLine += 1;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
binaryOperator.startLine += shiftUp;
|
|
32
|
-
binaryOperator.endLine += shiftUp;
|
|
33
|
-
// Move binaryOperator's leading comments to the following
|
|
34
|
-
// unaryExpression
|
|
35
|
-
ctx.unaryExpression[unaryExpressionIndex].leadingComments =
|
|
36
|
-
ctx.unaryExpression[unaryExpressionIndex].leadingComments || [];
|
|
37
|
-
(_a = ctx.unaryExpression[unaryExpressionIndex].leadingComments).unshift.apply(_a, binaryOperator.leadingComments);
|
|
38
|
-
delete binaryOperator.leadingComments;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function moveExpressionTrailingCommentsToNextOperator(ctx) {
|
|
43
|
-
var binaryOperators = ctx.BinaryOperator;
|
|
44
|
-
var binaryOperatorIndex = 1;
|
|
45
|
-
if (binaryOperators === null || binaryOperators === void 0 ? void 0 : binaryOperators.length) {
|
|
46
|
-
ctx.unaryExpression.forEach(function (unaryExpression) {
|
|
47
|
-
var _a;
|
|
48
|
-
var _b;
|
|
49
|
-
if ((0, comments_utils_1.hasTrailingComments)(unaryExpression)) {
|
|
50
|
-
while (binaryOperatorIndex < binaryOperators.length &&
|
|
51
|
-
unaryExpression.location.endOffset &&
|
|
52
|
-
binaryOperators[binaryOperatorIndex].startOffset <
|
|
53
|
-
unaryExpression.location.endOffset) {
|
|
54
|
-
binaryOperatorIndex++;
|
|
55
|
-
}
|
|
56
|
-
var binaryOperator = binaryOperators[binaryOperatorIndex];
|
|
57
|
-
// Adapt the position of the expression and its trailing comments
|
|
58
|
-
var shiftUp = unaryExpression.trailingComments[0].startLine -
|
|
59
|
-
1 -
|
|
60
|
-
unaryExpression.location.startLine;
|
|
61
|
-
if (unaryExpression.location.startLine !== binaryOperator.startLine) {
|
|
62
|
-
unaryExpression.trailingComments.forEach(function (comment) {
|
|
63
|
-
comment.startLine += 1;
|
|
64
|
-
comment.endLine += 1;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
unaryExpression.location.startLine += shiftUp;
|
|
68
|
-
if (unaryExpression.location.endLine !== undefined) {
|
|
69
|
-
unaryExpression.location.endLine += shiftUp;
|
|
70
|
-
}
|
|
71
|
-
// Move unaryExpression's trailing comments to the following
|
|
72
|
-
// binaryOperator
|
|
73
|
-
binaryOperator.trailingComments = (_b = binaryOperator.trailingComments) !== null && _b !== void 0 ? _b : [];
|
|
74
|
-
(_a = binaryOperator.trailingComments).unshift.apply(_a, unaryExpression.trailingComments);
|
|
75
|
-
delete unaryExpression.trailingComments;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|