prettier-plugin-java 1.3.0 → 1.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/dist/base-cst-printer.js +77 -0
- package/dist/cst-printer.js +37 -0
- package/dist/index.js +67 -0
- package/dist/options.js +256 -0
- package/dist/parser.js +7 -0
- package/dist/printer.js +28 -0
- package/dist/printers/arrays.js +49 -0
- package/dist/printers/blocks-and-statements.js +493 -0
- package/dist/printers/classes.js +724 -0
- package/dist/printers/comments/comments-utils.js +29 -0
- package/dist/printers/comments/format-comments.js +179 -0
- package/dist/printers/comments/handle-comments.js +38 -0
- package/dist/printers/expressions.js +549 -0
- package/dist/printers/interfaces.js +251 -0
- package/dist/printers/lexical-structure.js +43 -0
- package/dist/printers/names.js +53 -0
- package/dist/printers/packages-and-modules.js +185 -0
- package/dist/printers/prettier-builder.js +44 -0
- package/dist/printers/printer-utils.js +565 -0
- package/dist/printers/types-values-and-variables.js +183 -0
- package/dist/types/utils.js +29 -0
- package/dist/utils/expressions-utils.js +29 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/printArgumentListWithBraces.js +21 -0
- package/dist/utils/printSingleLambdaInvocation.js +20 -0
- package/package.json +32 -10
- package/src/cst-printer.js +0 -145
- package/src/index.js +0 -79
- package/src/options.js +0 -256
- package/src/parser.js +0 -10
- package/src/printer.js +0 -31
- package/src/printers/arrays.js +0 -38
- package/src/printers/blocks-and-statements.js +0 -588
- package/src/printers/classes.js +0 -940
- package/src/printers/comments/comments-utils.js +0 -38
- package/src/printers/comments/format-comments.js +0 -223
- package/src/printers/comments/handle-comments.js +0 -50
- package/src/printers/expressions.js +0 -703
- package/src/printers/interfaces.js +0 -324
- package/src/printers/lexical-structure.js +0 -27
- package/src/printers/names.js +0 -42
- package/src/printers/packages-and-modules.js +0 -231
- package/src/printers/prettier-builder.js +0 -60
- package/src/printers/printer-utils.js +0 -715
- package/src/printers/types-values-and-variables.js +0 -202
- package/yarn-error.log +0 -8052
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function hasLeadingComments(token) {
|
|
4
|
-
return token.leadingComments !== undefined;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function hasTrailingComments(token) {
|
|
8
|
-
return token.trailingComments !== undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function hasLeadingLineComments(token) {
|
|
12
|
-
return (
|
|
13
|
-
token.leadingComments !== undefined &&
|
|
14
|
-
token.leadingComments.length !== 0 &&
|
|
15
|
-
token.leadingComments[token.leadingComments.length - 1].tokenType.name ===
|
|
16
|
-
"LineComment"
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function hasTrailingLineComments(token) {
|
|
21
|
-
return (
|
|
22
|
-
token.trailingComments !== undefined &&
|
|
23
|
-
token.trailingComments.length !== 0 &&
|
|
24
|
-
token.trailingComments[token.trailingComments.length - 1].tokenType.name ===
|
|
25
|
-
"LineComment"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function hasComments(token) {
|
|
30
|
-
return hasLeadingComments(token) || hasTrailingComments(token);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
hasComments,
|
|
35
|
-
hasLeadingComments,
|
|
36
|
-
hasLeadingLineComments,
|
|
37
|
-
hasTrailingLineComments
|
|
38
|
-
};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { concat, hardline, lineSuffix, breakParent, literalline } =
|
|
3
|
-
require("prettier").doc.builders;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Takes a token and return a doc with:
|
|
7
|
-
* - concatenated leading comments
|
|
8
|
-
* - the token image
|
|
9
|
-
* - concatenated trailing comments
|
|
10
|
-
*
|
|
11
|
-
* @param {Token} token
|
|
12
|
-
* @return a doc with the token and its comments
|
|
13
|
-
*/
|
|
14
|
-
function printTokenWithComments(token) {
|
|
15
|
-
return printWithComments(
|
|
16
|
-
token,
|
|
17
|
-
token.image,
|
|
18
|
-
getTokenLeadingComments,
|
|
19
|
-
getTokenTrailingComments
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Takes a node and return a doc with:
|
|
25
|
-
* - concatenated leading comments
|
|
26
|
-
* - the node doc value
|
|
27
|
-
* - concatenated trailing comments
|
|
28
|
-
*
|
|
29
|
-
* @param {CSTNode} node
|
|
30
|
-
* @param {Doc} value - the converted node value
|
|
31
|
-
* @return a doc with the token and its comments
|
|
32
|
-
*/
|
|
33
|
-
function printNodeWithComments(node, value) {
|
|
34
|
-
return printWithComments(
|
|
35
|
-
node,
|
|
36
|
-
value,
|
|
37
|
-
getNodeLeadingComments,
|
|
38
|
-
getNodeTrailingComments
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function printWithComments(
|
|
43
|
-
nodeOrToken,
|
|
44
|
-
value,
|
|
45
|
-
getLeadingComments,
|
|
46
|
-
getTrailingComments
|
|
47
|
-
) {
|
|
48
|
-
const leadingComments = getLeadingComments(nodeOrToken);
|
|
49
|
-
const trailingComments = getTrailingComments(nodeOrToken, value);
|
|
50
|
-
|
|
51
|
-
return leadingComments.length === 0 && trailingComments.length === 0
|
|
52
|
-
? value
|
|
53
|
-
: concat([...leadingComments, value, ...trailingComments]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {Token} token
|
|
58
|
-
* @return an array containing processed leading comments and separators
|
|
59
|
-
*/
|
|
60
|
-
function getTokenLeadingComments(token) {
|
|
61
|
-
return getLeadingComments(token, token);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {CSTNode} node
|
|
66
|
-
* @return an array containing processed leading comments and separators
|
|
67
|
-
*/
|
|
68
|
-
function getNodeLeadingComments(node) {
|
|
69
|
-
return getLeadingComments(node, node.location);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function getLeadingComments(nodeOrToken, location) {
|
|
73
|
-
const arr = [];
|
|
74
|
-
if (Object.prototype.hasOwnProperty.call(nodeOrToken, "leadingComments")) {
|
|
75
|
-
let previousEndLine = nodeOrToken.leadingComments[0].endLine;
|
|
76
|
-
let step;
|
|
77
|
-
arr.push(concat(formatComment(nodeOrToken.leadingComments[0])));
|
|
78
|
-
for (let i = 1; i < nodeOrToken.leadingComments.length; i++) {
|
|
79
|
-
step = nodeOrToken.leadingComments[i].startLine - previousEndLine;
|
|
80
|
-
if (
|
|
81
|
-
step === 1 ||
|
|
82
|
-
nodeOrToken.leadingComments[i].startOffset > location.startOffset
|
|
83
|
-
) {
|
|
84
|
-
arr.push(hardline);
|
|
85
|
-
} else if (step > 1) {
|
|
86
|
-
arr.push(hardline, hardline);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
arr.push(concat(formatComment(nodeOrToken.leadingComments[i])));
|
|
90
|
-
previousEndLine = nodeOrToken.leadingComments[i].endLine;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
step = location.startLine - previousEndLine;
|
|
94
|
-
if (
|
|
95
|
-
step === 1 ||
|
|
96
|
-
nodeOrToken.leadingComments[nodeOrToken.leadingComments.length - 1]
|
|
97
|
-
.startOffset > location.startOffset
|
|
98
|
-
) {
|
|
99
|
-
arr.push(hardline);
|
|
100
|
-
} else if (step > 1) {
|
|
101
|
-
arr.push(hardline, hardline);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return arr;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {Token} token
|
|
110
|
-
* @return an array containing processed trailing comments and separators
|
|
111
|
-
*/
|
|
112
|
-
function getTokenTrailingComments(token) {
|
|
113
|
-
return getTrailingComments(token, token.image, token);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @param {CSTNode} node
|
|
118
|
-
* @return an array containing processed trailing comments and separators
|
|
119
|
-
*/
|
|
120
|
-
function getNodeTrailingComments(node, value) {
|
|
121
|
-
return getTrailingComments(node, value, node.location);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getTrailingComments(nodeOrToken, value, location) {
|
|
125
|
-
const arr = [];
|
|
126
|
-
let previousEndLine = location.endLine;
|
|
127
|
-
if (Object.prototype.hasOwnProperty.call(nodeOrToken, "trailingComments")) {
|
|
128
|
-
nodeOrToken.trailingComments.forEach((comment, idx) => {
|
|
129
|
-
let separator = "";
|
|
130
|
-
|
|
131
|
-
if (comment.startLine !== previousEndLine) {
|
|
132
|
-
arr.push(hardline);
|
|
133
|
-
} else if (value !== "" && idx === 0) {
|
|
134
|
-
separator = " ";
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (comment.tokenType.name === "LineComment") {
|
|
138
|
-
arr.push(
|
|
139
|
-
lineSuffix(
|
|
140
|
-
concat([separator, concat(formatComment(comment)), breakParent])
|
|
141
|
-
)
|
|
142
|
-
);
|
|
143
|
-
} else {
|
|
144
|
-
arr.push(concat(formatComment(comment)));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
previousEndLine = comment.endLine;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return arr;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function isJavaDoc(comment, lines) {
|
|
155
|
-
let isJavaDoc = true;
|
|
156
|
-
if (comment.tokenType.name === "TraditionalComment" && lines.length > 1) {
|
|
157
|
-
for (let i = 1; i < lines.length; i++) {
|
|
158
|
-
if (lines[i].trim().charAt(0) !== "*") {
|
|
159
|
-
isJavaDoc = false;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
isJavaDoc = false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return isJavaDoc;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function formatJavaDoc(lines) {
|
|
171
|
-
const res = [lines[0].trim()];
|
|
172
|
-
|
|
173
|
-
for (let i = 1; i < lines.length; i++) {
|
|
174
|
-
res.push(hardline);
|
|
175
|
-
res.push(" " + lines[i].trim());
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return res;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function formatComment(comment) {
|
|
182
|
-
const res = [];
|
|
183
|
-
const lines = comment.image.split("\n");
|
|
184
|
-
|
|
185
|
-
if (isJavaDoc(comment, lines)) {
|
|
186
|
-
return formatJavaDoc(lines);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
lines.forEach(line => {
|
|
190
|
-
res.push(line);
|
|
191
|
-
res.push(literalline);
|
|
192
|
-
});
|
|
193
|
-
res.pop();
|
|
194
|
-
return res;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function isToken(doc) {
|
|
198
|
-
return (
|
|
199
|
-
doc && Object.prototype.hasOwnProperty.call(doc, "image") && doc.tokenType
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function processComments(docs) {
|
|
204
|
-
if (!Array.isArray(docs)) {
|
|
205
|
-
if (isToken(docs)) {
|
|
206
|
-
return printTokenWithComments(docs);
|
|
207
|
-
}
|
|
208
|
-
return docs;
|
|
209
|
-
}
|
|
210
|
-
return docs.map(elt => {
|
|
211
|
-
if (isToken(elt)) {
|
|
212
|
-
return printTokenWithComments(elt);
|
|
213
|
-
}
|
|
214
|
-
return elt;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
module.exports = {
|
|
219
|
-
getTokenLeadingComments,
|
|
220
|
-
processComments,
|
|
221
|
-
printTokenWithComments,
|
|
222
|
-
printNodeWithComments
|
|
223
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { hasLeadingComments } = require("./comments-utils");
|
|
4
|
-
|
|
5
|
-
function handleCommentsBinaryExpression(ctx) {
|
|
6
|
-
let unaryExpressionIndex = 1;
|
|
7
|
-
if (ctx.BinaryOperator !== undefined) {
|
|
8
|
-
ctx.BinaryOperator.forEach(binaryOperator => {
|
|
9
|
-
if (hasLeadingComments(binaryOperator)) {
|
|
10
|
-
while (
|
|
11
|
-
ctx.unaryExpression[unaryExpressionIndex].location.startOffset <
|
|
12
|
-
binaryOperator.endOffset
|
|
13
|
-
) {
|
|
14
|
-
unaryExpressionIndex++;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Adapt the position of the operator and its leading comments
|
|
18
|
-
const shiftUp =
|
|
19
|
-
binaryOperator.leadingComments[0].startLine -
|
|
20
|
-
1 -
|
|
21
|
-
ctx.BinaryOperator.startLine;
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
binaryOperator.startLine !==
|
|
25
|
-
ctx.unaryExpression[unaryExpressionIndex].location.startLine
|
|
26
|
-
) {
|
|
27
|
-
binaryOperator.leadingComments.forEach(comment => {
|
|
28
|
-
comment.startLine += 1;
|
|
29
|
-
comment.endLine += 1;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
binaryOperator.startLine += shiftUp;
|
|
33
|
-
binaryOperator.endLine += shiftUp;
|
|
34
|
-
|
|
35
|
-
// Assign the leading comments & trailing comments of the binaryOperator
|
|
36
|
-
// to the following unaryExpression as leading comments
|
|
37
|
-
ctx.unaryExpression[unaryExpressionIndex].leadingComments =
|
|
38
|
-
ctx.unaryExpression[unaryExpressionIndex].leadingComments || [];
|
|
39
|
-
ctx.unaryExpression[unaryExpressionIndex].leadingComments.unshift(
|
|
40
|
-
...binaryOperator.leadingComments
|
|
41
|
-
);
|
|
42
|
-
delete binaryOperator.leadingComments;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
handleCommentsBinaryExpression
|
|
50
|
-
};
|