prettier-plugin-java 2.7.4 → 2.7.6
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/comments.d.ts +2 -2
- package/dist/comments.js +20 -18
- package/dist/printers/arrays.d.ts +1 -1
- package/dist/printers/blocks-and-statements.d.ts +2 -2
- package/dist/printers/blocks-and-statements.js +12 -8
- package/dist/printers/classes.d.ts +4 -4
- package/dist/printers/expressions.d.ts +3 -3
- package/dist/printers/expressions.js +35 -17
- package/dist/printers/helpers.d.ts +4 -4
- package/dist/printers/helpers.js +14 -12
- package/dist/printers/interfaces.d.ts +3 -3
- package/package.json +2 -2
package/dist/comments.d.ts
CHANGED
package/dist/comments.js
CHANGED
|
@@ -67,6 +67,7 @@ export function canAttachComment(node) {
|
|
|
67
67
|
export function handleLineComment(commentNode, _, options) {
|
|
68
68
|
return [
|
|
69
69
|
handleBinaryExpressionComments,
|
|
70
|
+
handleConditionalExpressionComments,
|
|
70
71
|
handleFqnOrRefTypeComments,
|
|
71
72
|
handleIfStatementComments,
|
|
72
73
|
handleJumpStatementComments,
|
|
@@ -84,9 +85,7 @@ export function handleRemainingComment(commentNode) {
|
|
|
84
85
|
}
|
|
85
86
|
function handleBinaryExpressionComments(commentNode, options) {
|
|
86
87
|
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
87
|
-
if (enclosingNode
|
|
88
|
-
isNonTerminal(enclosingNode) &&
|
|
89
|
-
enclosingNode.name === "binaryExpression") {
|
|
88
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "binaryExpression") {
|
|
90
89
|
if (isBinaryOperator(followingNode)) {
|
|
91
90
|
if (options.experimentalOperatorPosition === "start") {
|
|
92
91
|
util.addLeadingComment(followingNode, commentNode);
|
|
@@ -104,12 +103,23 @@ function handleBinaryExpressionComments(commentNode, options) {
|
|
|
104
103
|
}
|
|
105
104
|
return false;
|
|
106
105
|
}
|
|
106
|
+
function handleConditionalExpressionComments(commentNode) {
|
|
107
|
+
const { startLine, endLine, enclosingNode, precedingNode, followingNode } = commentNode;
|
|
108
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "conditionalExpression" &&
|
|
109
|
+
precedingNode &&
|
|
110
|
+
followingNode &&
|
|
111
|
+
isNonTerminal(precedingNode) &&
|
|
112
|
+
isNonTerminal(followingNode) &&
|
|
113
|
+
precedingNode.location.endLine < startLine &&
|
|
114
|
+
endLine < followingNode.location.startLine) {
|
|
115
|
+
util.addLeadingComment(followingNode, commentNode);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
107
120
|
function handleFqnOrRefTypeComments(commentNode) {
|
|
108
121
|
const { enclosingNode, followingNode } = commentNode;
|
|
109
|
-
if (enclosingNode &&
|
|
110
|
-
isNonTerminal(enclosingNode) &&
|
|
111
|
-
enclosingNode.name === "fqnOrRefType" &&
|
|
112
|
-
followingNode) {
|
|
122
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "fqnOrRefType" && followingNode) {
|
|
113
123
|
util.addLeadingComment(followingNode, commentNode);
|
|
114
124
|
return true;
|
|
115
125
|
}
|
|
@@ -117,9 +127,7 @@ function handleFqnOrRefTypeComments(commentNode) {
|
|
|
117
127
|
}
|
|
118
128
|
function handleIfStatementComments(commentNode) {
|
|
119
129
|
const { enclosingNode, precedingNode } = commentNode;
|
|
120
|
-
if (enclosingNode &&
|
|
121
|
-
isNonTerminal(enclosingNode) &&
|
|
122
|
-
enclosingNode.name === "ifStatement" &&
|
|
130
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "ifStatement" &&
|
|
123
131
|
precedingNode &&
|
|
124
132
|
isNonTerminal(precedingNode) &&
|
|
125
133
|
precedingNode.name === "statement") {
|
|
@@ -133,7 +141,6 @@ function handleJumpStatementComments(commentNode) {
|
|
|
133
141
|
if (enclosingNode &&
|
|
134
142
|
!precedingNode &&
|
|
135
143
|
!followingNode &&
|
|
136
|
-
isNonTerminal(enclosingNode) &&
|
|
137
144
|
["breakStatement", "continueStatement", "returnStatement"].includes(enclosingNode.name)) {
|
|
138
145
|
util.addTrailingComment(enclosingNode, commentNode);
|
|
139
146
|
return true;
|
|
@@ -142,10 +149,8 @@ function handleJumpStatementComments(commentNode) {
|
|
|
142
149
|
}
|
|
143
150
|
function handleLabeledStatementComments(commentNode) {
|
|
144
151
|
const { enclosingNode, precedingNode } = commentNode;
|
|
145
|
-
if (enclosingNode &&
|
|
152
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "labeledStatement" &&
|
|
146
153
|
precedingNode &&
|
|
147
|
-
isNonTerminal(enclosingNode) &&
|
|
148
|
-
enclosingNode.name === "labeledStatement" &&
|
|
149
154
|
isTerminal(precedingNode) &&
|
|
150
155
|
precedingNode.tokenType.name === "Identifier") {
|
|
151
156
|
util.addLeadingComment(precedingNode, commentNode);
|
|
@@ -155,9 +160,7 @@ function handleLabeledStatementComments(commentNode) {
|
|
|
155
160
|
}
|
|
156
161
|
function handleMethodDeclaratorComments(commentNode) {
|
|
157
162
|
const { enclosingNode } = commentNode;
|
|
158
|
-
if (enclosingNode &&
|
|
159
|
-
isNonTerminal(enclosingNode) &&
|
|
160
|
-
enclosingNode.name === "methodDeclarator" &&
|
|
163
|
+
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "methodDeclarator" &&
|
|
161
164
|
!enclosingNode.children.receiverParameter &&
|
|
162
165
|
!enclosingNode.children.formalParameterList &&
|
|
163
166
|
enclosingNode.children.LBrace[0].startOffset < commentNode.startOffset &&
|
|
@@ -171,7 +174,6 @@ function handleNameComments(commentNode) {
|
|
|
171
174
|
const { enclosingNode, precedingNode } = commentNode;
|
|
172
175
|
if (enclosingNode &&
|
|
173
176
|
precedingNode &&
|
|
174
|
-
isNonTerminal(enclosingNode) &&
|
|
175
177
|
isTerminal(precedingNode) &&
|
|
176
178
|
precedingNode.tokenType.name === "Identifier" &&
|
|
177
179
|
[
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
arrayInitializer(path: import("prettier").AstPath<import("java-parser").ArrayInitializerCstNode & {
|
|
3
3
|
comments?: import("../comments.js").JavaComment[];
|
|
4
|
-
}>, print: import("./helpers.js").JavaPrintFn, options: import("./helpers.js").JavaParserOptions): import("prettier/doc.js").builders.Group | "{}";
|
|
4
|
+
}>, print: import("./helpers.js").JavaPrintFn, options: import("./helpers.js").JavaParserOptions): import("prettier/doc.js").builders.Group | (string | import("prettier/doc.js").builders.Indent | import("prettier/doc.js").builders.Hardline)[] | "{}";
|
|
5
5
|
variableInitializerList(path: import("prettier").AstPath<import("java-parser").VariableInitializerListCstNode & {
|
|
6
6
|
comments?: import("../comments.js").JavaComment[];
|
|
7
7
|
}>, print: import("./helpers.js").JavaPrintFn): import("prettier/doc.js").builders.Doc[];
|
|
@@ -3,7 +3,7 @@ import { printSingle } from "./helpers.js";
|
|
|
3
3
|
declare const _default: {
|
|
4
4
|
block(path: import("prettier").AstPath<import("java-parser").BlockCstNode & {
|
|
5
5
|
comments?: import("../comments.js").JavaComment[];
|
|
6
|
-
}>, print: import("./helpers.js").JavaPrintFn): builders.Group |
|
|
6
|
+
}>, print: import("./helpers.js").JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
7
7
|
blockStatements(path: import("prettier").AstPath<import("java-parser").BlockStatementsCstNode & {
|
|
8
8
|
comments?: import("../comments.js").JavaComment[];
|
|
9
9
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
|
|
@@ -36,7 +36,7 @@ declare const _default: {
|
|
|
36
36
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
|
|
37
37
|
switchBlock(path: import("prettier").AstPath<import("java-parser").SwitchBlockCstNode & {
|
|
38
38
|
comments?: import("../comments.js").JavaComment[];
|
|
39
|
-
}>, print: import("./helpers.js").JavaPrintFn): builders.Group |
|
|
39
|
+
}>, print: import("./helpers.js").JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
40
40
|
switchBlockStatementGroup(path: import("prettier").AstPath<import("java-parser").SwitchBlockStatementGroupCstNode & {
|
|
41
41
|
comments?: import("../comments.js").JavaComment[];
|
|
42
42
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { builders } from "prettier/doc";
|
|
2
|
-
import { call, definedKeys, indentInParentheses, isBinaryExpression, isEmptyStatement, lineEndWithComments, lineStartWithComments, map, onlyDefinedKey, printBlock, printDanglingComments, printSingle, printWithModifiers } from "./helpers.js";
|
|
2
|
+
import { call, definedKeys, hasLeadingComments, indentInParentheses, isBinaryExpression, isEmptyStatement, lineEndWithComments, lineStartWithComments, map, onlyDefinedKey, printBlock, printDanglingComments, printSingle, printWithModifiers } from "./helpers.js";
|
|
3
3
|
const { group, hardline, ifBreak, indent, join, line, softline } = builders;
|
|
4
4
|
export default {
|
|
5
5
|
block(path, print) {
|
|
@@ -50,10 +50,11 @@ export default {
|
|
|
50
50
|
var _a;
|
|
51
51
|
const { children } = path.node;
|
|
52
52
|
const hasEmptyStatement = isEmptyStatement(children.statement[0]);
|
|
53
|
+
const statements = map(path, print, "statement");
|
|
53
54
|
const statement = [
|
|
54
55
|
"if ",
|
|
55
56
|
indentInParentheses(call(path, print, "expression")),
|
|
56
|
-
hasEmptyStatement ? ";" : [" ",
|
|
57
|
+
hasEmptyStatement ? ";" : [" ", statements[0]]
|
|
57
58
|
];
|
|
58
59
|
if (children.Else) {
|
|
59
60
|
const danglingComments = printDanglingComments(path);
|
|
@@ -67,7 +68,7 @@ export default {
|
|
|
67
68
|
statement.push(elseHasBlock ? " " : hardline);
|
|
68
69
|
}
|
|
69
70
|
const elseHasEmptyStatement = isEmptyStatement(children.statement[1]);
|
|
70
|
-
statement.push("else", elseHasEmptyStatement ? ";" : [" ",
|
|
71
|
+
statement.push("else", elseHasEmptyStatement ? ";" : [" ", statements[1]]);
|
|
71
72
|
}
|
|
72
73
|
return statement;
|
|
73
74
|
},
|
|
@@ -147,11 +148,14 @@ export default {
|
|
|
147
148
|
"expression",
|
|
148
149
|
"throwStatement"
|
|
149
150
|
]);
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
const body = call(path, print, bodyKey);
|
|
152
|
+
const parts = [call(path, print, "switchLabel"), " ->"];
|
|
153
|
+
if (bodyKey !== "block" && hasLeadingComments(children[bodyKey][0])) {
|
|
154
|
+
parts.push(indent([hardline, body]));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
parts.push(" ", body);
|
|
158
|
+
}
|
|
155
159
|
if (children.Semicolon) {
|
|
156
160
|
parts.push(";");
|
|
157
161
|
}
|
|
@@ -28,7 +28,7 @@ declare const _default: {
|
|
|
28
28
|
}>, print: JavaPrintFn): builders.Group;
|
|
29
29
|
classBody(path: AstPath<ClassBodyCstNode & {
|
|
30
30
|
comments?: import("../comments.js").JavaComment[];
|
|
31
|
-
}>, print: JavaPrintFn): builders.Group |
|
|
31
|
+
}>, print: JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
32
32
|
classBodyDeclaration: typeof printSingle;
|
|
33
33
|
classMemberDeclaration(path: AstPath<import("java-parser").ClassMemberDeclarationCstNode & {
|
|
34
34
|
comments?: import("../comments.js").JavaComment[];
|
|
@@ -106,7 +106,7 @@ declare const _default: {
|
|
|
106
106
|
simpleTypeName: typeof printSingle;
|
|
107
107
|
constructorBody(path: AstPath<import("java-parser").ConstructorBodyCstNode & {
|
|
108
108
|
comments?: import("../comments.js").JavaComment[];
|
|
109
|
-
}>, print: JavaPrintFn): builders.Group |
|
|
109
|
+
}>, print: JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
110
110
|
explicitConstructorInvocation: typeof printSingle;
|
|
111
111
|
unqualifiedExplicitConstructorInvocation(path: AstPath<import("java-parser").UnqualifiedExplicitConstructorInvocationCstNode & {
|
|
112
112
|
comments?: import("../comments.js").JavaComment[];
|
|
@@ -119,7 +119,7 @@ declare const _default: {
|
|
|
119
119
|
}>, print: JavaPrintFn): builders.Doc[];
|
|
120
120
|
enumBody(path: AstPath<import("java-parser").EnumBodyCstNode & {
|
|
121
121
|
comments?: import("../comments.js").JavaComment[];
|
|
122
|
-
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Group |
|
|
122
|
+
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
123
123
|
enumConstantList(path: AstPath<import("java-parser").EnumConstantListCstNode & {
|
|
124
124
|
comments?: import("../comments.js").JavaComment[];
|
|
125
125
|
}>, print: JavaPrintFn): builders.Doc[];
|
|
@@ -148,7 +148,7 @@ declare const _default: {
|
|
|
148
148
|
recordComponentModifier: typeof printSingle;
|
|
149
149
|
recordBody(path: AstPath<import("java-parser").RecordBodyCstNode & {
|
|
150
150
|
comments?: import("../comments.js").JavaComment[];
|
|
151
|
-
}>, print: JavaPrintFn): builders.Group |
|
|
151
|
+
}>, print: JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
152
152
|
recordBodyDeclaration: typeof printSingle;
|
|
153
153
|
compactConstructorDeclaration(path: AstPath<import("java-parser").CompactConstructorDeclarationCstNode & {
|
|
154
154
|
comments?: import("../comments.js").JavaComment[];
|
|
@@ -30,7 +30,7 @@ declare const _default: {
|
|
|
30
30
|
lambdaBody: typeof printSingle;
|
|
31
31
|
conditionalExpression(path: AstPath<import("java-parser").ConditionalExpressionCstNode & {
|
|
32
32
|
comments?: JavaComment[];
|
|
33
|
-
}>, print: JavaPrintFn): builders.Doc;
|
|
33
|
+
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
34
34
|
binaryExpression(path: AstPath<import("java-parser").BinaryExpressionCstNode & {
|
|
35
35
|
comments?: JavaComment[];
|
|
36
36
|
}>, print: JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Doc;
|
|
@@ -112,10 +112,10 @@ declare const _default: {
|
|
|
112
112
|
template: typeof printSingle;
|
|
113
113
|
stringTemplate(path: AstPath<StringTemplateCstNode & {
|
|
114
114
|
comments?: JavaComment[];
|
|
115
|
-
}>, print: JavaPrintFn):
|
|
115
|
+
}>, print: JavaPrintFn): builders.Indent;
|
|
116
116
|
textBlockTemplate(path: AstPath<TextBlockTemplateCstNode & {
|
|
117
117
|
comments?: JavaComment[];
|
|
118
|
-
}>, print: JavaPrintFn):
|
|
118
|
+
}>, print: JavaPrintFn): builders.Indent;
|
|
119
119
|
embeddedExpression: typeof printSingle;
|
|
120
120
|
pattern: typeof printSingle;
|
|
121
121
|
typePattern: typeof printSingle;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { builders, utils } from "prettier/doc";
|
|
2
|
-
import { call, definedKeys, each, findBaseIndent, flatMap, indentInParentheses, isBinaryExpression, isNonTerminal, isTerminal, map, onlyDefinedKey, printDanglingComments, printList, printName, printSingle } from "./helpers.js";
|
|
3
|
-
const { breakParent, conditionalGroup, group, hardline, ifBreak, indent, indentIfBreak, join, line, lineSuffixBoundary, softline } = builders;
|
|
2
|
+
import { call, definedKeys, each, findBaseIndent, flatMap, hasLeadingComments, indentInParentheses, isBinaryExpression, isNonTerminal, isTerminal, map, onlyDefinedKey, printDanglingComments, printList, printName, printSingle } from "./helpers.js";
|
|
3
|
+
const { align, breakParent, conditionalGroup, group, hardline, ifBreak, indent, indentIfBreak, join, line, lineSuffixBoundary, softline } = builders;
|
|
4
4
|
const { removeLines, willBreak } = utils;
|
|
5
5
|
export default {
|
|
6
6
|
expression: printSingle,
|
|
@@ -61,17 +61,29 @@ export default {
|
|
|
61
61
|
lambdaParameterType: printSingle,
|
|
62
62
|
conciseLambdaParameter: printSingle,
|
|
63
63
|
lambdaBody: printSingle,
|
|
64
|
-
conditionalExpression(path, print) {
|
|
64
|
+
conditionalExpression(path, print, options) {
|
|
65
|
+
var _a;
|
|
65
66
|
const binaryExpression = call(path, print, "binaryExpression");
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
if (!path.node.children.QuestionMark) {
|
|
68
|
+
return binaryExpression;
|
|
69
|
+
}
|
|
70
|
+
const [consequent, alternate] = map(path, print, "expression");
|
|
71
|
+
const parts = [binaryExpression];
|
|
72
|
+
const part = [
|
|
73
|
+
line,
|
|
74
|
+
["? ", options.useTabs ? indent(consequent) : align(2, consequent)],
|
|
75
|
+
line,
|
|
76
|
+
[": ", options.useTabs ? indent(alternate) : align(2, alternate)]
|
|
77
|
+
];
|
|
78
|
+
const isNestedTernary = ((_a = path.getNode(4)) === null || _a === void 0 ? void 0 : _a.name) ===
|
|
79
|
+
"conditionalExpression";
|
|
80
|
+
parts.push(!isNestedTernary || options.useTabs
|
|
81
|
+
? part
|
|
82
|
+
: align(Math.max(0, options.tabWidth - 2), part));
|
|
83
|
+
return isNestedTernary ? parts : group(indent(parts));
|
|
73
84
|
},
|
|
74
85
|
binaryExpression(path, print, options) {
|
|
86
|
+
var _a, _b;
|
|
75
87
|
const { children } = path.node;
|
|
76
88
|
const operands = flatMap(path, print, definedKeys(children, [
|
|
77
89
|
"expression",
|
|
@@ -101,8 +113,11 @@ export default {
|
|
|
101
113
|
const hasNonAssignmentOperators = (operators.length > 0 && !children.AssignmentOperator) ||
|
|
102
114
|
(children.expression !== undefined &&
|
|
103
115
|
isBinaryExpression(children.expression[0]));
|
|
116
|
+
const isInList = ((_a = path.getNode(4)) === null || _a === void 0 ? void 0 : _a.name) === "elementValue" ||
|
|
117
|
+
((_b = path.getNode(6)) === null || _b === void 0 ? void 0 : _b.name) === "argumentList";
|
|
104
118
|
return binary(operands, operators, {
|
|
105
119
|
hasNonAssignmentOperators,
|
|
120
|
+
isInList,
|
|
106
121
|
isRoot: true,
|
|
107
122
|
operatorPosition: options.experimentalOperatorPosition
|
|
108
123
|
});
|
|
@@ -181,7 +196,8 @@ export default {
|
|
|
181
196
|
: suffix);
|
|
182
197
|
}
|
|
183
198
|
}, "primarySuffix");
|
|
184
|
-
|
|
199
|
+
const hasSuffixComments = children.primarySuffix.some(suffix => hasLeadingComments(suffix));
|
|
200
|
+
return group(canBreakForCallExpressions || hasSuffixComments
|
|
185
201
|
? [prefix, indent(suffixes)]
|
|
186
202
|
: [prefix, ...suffixes]);
|
|
187
203
|
},
|
|
@@ -340,7 +356,7 @@ export default {
|
|
|
340
356
|
return allArgsExpandable;
|
|
341
357
|
}
|
|
342
358
|
const headArgs = args.slice(0, -1);
|
|
343
|
-
const huggedLastArg = call(
|
|
359
|
+
const huggedLastArg = path.call(argPath => print(argPath, { hug: true }), "children", "expression", args.length - 1);
|
|
344
360
|
const lastArgExpanded = join(", ", [
|
|
345
361
|
...headArgs,
|
|
346
362
|
group(huggedLastArg, { shouldBreak: true })
|
|
@@ -451,7 +467,7 @@ export default {
|
|
|
451
467
|
];
|
|
452
468
|
}
|
|
453
469
|
};
|
|
454
|
-
function binary(operands, operators, { hasNonAssignmentOperators = false, isRoot = false, operatorPosition }) {
|
|
470
|
+
function binary(operands, operators, { hasNonAssignmentOperators = false, isInList = false, isRoot = false, operatorPosition }) {
|
|
455
471
|
let levelOperator;
|
|
456
472
|
let levelPrecedence;
|
|
457
473
|
let level = [];
|
|
@@ -496,7 +512,10 @@ function binary(operands, operators, { hasNonAssignmentOperators = false, isRoot
|
|
|
496
512
|
}
|
|
497
513
|
}
|
|
498
514
|
level.push(operands.shift());
|
|
499
|
-
if (!levelOperator ||
|
|
515
|
+
if (!levelOperator ||
|
|
516
|
+
(!isInList &&
|
|
517
|
+
!isAssignmentOperator(levelOperator) &&
|
|
518
|
+
levelOperator !== "instanceof")) {
|
|
500
519
|
return group(level);
|
|
501
520
|
}
|
|
502
521
|
if (!isRoot || hasNonAssignmentOperators) {
|
|
@@ -563,7 +582,6 @@ function isCapitalizedIdentifier(fqnOrRefType) {
|
|
|
563
582
|
return /^\p{Uppercase_Letter}/u.test(nextToLastIdentifier !== null && nextToLastIdentifier !== void 0 ? nextToLastIdentifier : "");
|
|
564
583
|
}
|
|
565
584
|
function printTemplate(path, print, beginKey, midKey, endKey) {
|
|
566
|
-
const { children } = path.node;
|
|
567
585
|
const begin = call(path, ({ node }) => node.image, beginKey);
|
|
568
586
|
const mids = map(path, ({ node }) => node.image, midKey);
|
|
569
587
|
const end = call(path, ({ node }) => node.image, endKey);
|
|
@@ -571,7 +589,7 @@ function printTemplate(path, print, beginKey, midKey, endKey) {
|
|
|
571
589
|
const baseIndent = findBaseIndent(lines);
|
|
572
590
|
const prefix = "\n" + " ".repeat(baseIndent);
|
|
573
591
|
const parts = [begin, ...mids, end].map(image => join(hardline, image.split(prefix)));
|
|
574
|
-
return [
|
|
592
|
+
return indent([
|
|
575
593
|
parts[0],
|
|
576
594
|
...map(path, (expressionPath, index) => {
|
|
577
595
|
const expression = group([
|
|
@@ -581,5 +599,5 @@ function printTemplate(path, print, beginKey, midKey, endKey) {
|
|
|
581
599
|
return index === 0 ? expression : [parts[index], expression];
|
|
582
600
|
}, "embeddedExpression"),
|
|
583
601
|
parts.at(-1)
|
|
584
|
-
];
|
|
602
|
+
]);
|
|
585
603
|
}
|
|
@@ -6,7 +6,7 @@ export declare function onlyDefinedKey<T extends Record<string, any>, K extends
|
|
|
6
6
|
export declare function definedKeys<T extends Record<string, any>, K extends Key<T> & string>(obj: T, options?: K[]): K[];
|
|
7
7
|
export declare function printWithModifiers<T extends CstNode, P extends IterProperties<T["children"]>>(path: AstPath<T>, print: JavaPrintFn, modifierChild: P, contents: Doc, noTypeAnnotations?: boolean): builders.Doc[];
|
|
8
8
|
export declare function hasDeclarationAnnotations(modifiers: ModifierNode[]): boolean;
|
|
9
|
-
export declare function call<T extends CstNode, U, P extends IterProperties<T["children"]>>(path: AstPath<T>, callback: MapCallback<IndexValue<IndexValue<T, "children">, P>, U>, child: P
|
|
9
|
+
export declare function call<T extends CstNode, U, P extends IterProperties<T["children"]>>(path: AstPath<T>, callback: MapCallback<IndexValue<IndexValue<T, "children">, P>, U>, child: P): U;
|
|
10
10
|
export declare function each<T extends CstNode, P extends IterProperties<T["children"]>>(path: AstPath<T>, callback: MapCallback<IndexValue<IndexValue<T, "children">, P>, void>, child: P): void;
|
|
11
11
|
export declare function map<T extends CstNode, U, P extends IterProperties<T["children"]>>(path: AstPath<T>, callback: MapCallback<IndexValue<IndexValue<T, "children">, P>, U>, child: P): U[];
|
|
12
12
|
export declare function flatMap<T extends CstNode, U, P extends IterProperties<T["children"]>>(path: AstPath<T>, callback: MapCallback<IndexValue<IndexValue<T, "children">, P>, U>, children: P[]): U[];
|
|
@@ -15,12 +15,12 @@ export declare function lineStartWithComments(node: JavaNonTerminal): number;
|
|
|
15
15
|
export declare function lineEndWithComments(node: JavaNonTerminal): number;
|
|
16
16
|
export declare function printDanglingComments(path: AstPath<JavaNonTerminal>): builders.Doc[];
|
|
17
17
|
export declare function printComment(node: JavaTerminal): string | builders.Doc[];
|
|
18
|
-
export declare function hasLeadingComments(node: JavaNode): boolean
|
|
18
|
+
export declare function hasLeadingComments(node: JavaNode): boolean;
|
|
19
19
|
export declare function indentInParentheses(contents: Doc, opts?: {
|
|
20
20
|
shouldBreak?: boolean;
|
|
21
21
|
}): builders.Group | "()";
|
|
22
|
-
export declare function printArrayInitializer<T extends JavaNonTerminal, P extends IterProperties<T["children"]>>(path: AstPath<T>, print: JavaPrintFn, options: JavaParserOptions, child: P): builders.Group | "{}";
|
|
23
|
-
export declare function printBlock(path: AstPath<JavaNonTerminal>, contents: Doc[]): builders.Group |
|
|
22
|
+
export declare function printArrayInitializer<T extends JavaNonTerminal, P extends IterProperties<T["children"]>>(path: AstPath<T>, print: JavaPrintFn, options: JavaParserOptions, child: P): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
23
|
+
export declare function printBlock(path: AstPath<JavaNonTerminal>, contents: Doc[]): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
24
24
|
export declare function printName(path: AstPath<JavaNonTerminal & {
|
|
25
25
|
children: {
|
|
26
26
|
Identifier: IToken[];
|
package/dist/printers/helpers.js
CHANGED
|
@@ -71,8 +71,8 @@ export function hasDeclarationAnnotations(modifiers) {
|
|
|
71
71
|
}
|
|
72
72
|
return hasAnnotation && !hasNonAnnotation;
|
|
73
73
|
}
|
|
74
|
-
export function call(path, callback, child
|
|
75
|
-
return path.map(callback, "children", child)[
|
|
74
|
+
export function call(path, callback, child) {
|
|
75
|
+
return path.map(callback, "children", child)[0];
|
|
76
76
|
}
|
|
77
77
|
export function each(path, callback, child) {
|
|
78
78
|
if (path.node.children[child]) {
|
|
@@ -135,8 +135,8 @@ export function printComment(node) {
|
|
|
135
135
|
: image;
|
|
136
136
|
}
|
|
137
137
|
export function hasLeadingComments(node) {
|
|
138
|
-
var _a;
|
|
139
|
-
return (_a = node.comments) === null || _a === void 0 ? void 0 : _a.some(({ leading }) => leading);
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return (_b = (_a = node.comments) === null || _a === void 0 ? void 0 : _a.some(({ leading }) => leading)) !== null && _b !== void 0 ? _b : false;
|
|
140
140
|
}
|
|
141
141
|
export function indentInParentheses(contents, opts) {
|
|
142
142
|
return !Array.isArray(contents) || contents.length
|
|
@@ -144,14 +144,16 @@ export function indentInParentheses(contents, opts) {
|
|
|
144
144
|
: "()";
|
|
145
145
|
}
|
|
146
146
|
export function printArrayInitializer(path, print, options, child) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
if (!(child && child in path.node.children)) {
|
|
148
|
+
const danglingComments = printDanglingComments(path);
|
|
149
|
+
return danglingComments.length
|
|
150
|
+
? ["{", indent([hardline, ...danglingComments]), hardline, "}"]
|
|
151
|
+
: "{}";
|
|
152
|
+
}
|
|
153
|
+
const list = [call(path, print, child)];
|
|
154
|
+
if (options.trailingComma !== "none") {
|
|
155
|
+
list.push(ifBreak(","));
|
|
153
156
|
}
|
|
154
|
-
list.push(...printDanglingComments(path));
|
|
155
157
|
return list.length ? group(["{", indent([line, ...list]), line, "}"]) : "{}";
|
|
156
158
|
}
|
|
157
159
|
export function printBlock(path, contents) {
|
|
@@ -193,7 +195,7 @@ export function printClassType(path, print) {
|
|
|
193
195
|
const node = children[child][childIndex];
|
|
194
196
|
const next = array.at(index + 1);
|
|
195
197
|
const nextNode = next && children[next.child][next.index];
|
|
196
|
-
const docs = [call(
|
|
198
|
+
const docs = [path.call(print, "children", child, childIndex)];
|
|
197
199
|
if (nextNode) {
|
|
198
200
|
if (isNonTerminal(node)) {
|
|
199
201
|
docs.push(node.name === "annotation" ? " " : ".");
|
|
@@ -14,7 +14,7 @@ declare const _default: {
|
|
|
14
14
|
interfacePermits: typeof printClassPermits;
|
|
15
15
|
interfaceBody(path: import("prettier").AstPath<import("java-parser").InterfaceBodyCstNode & {
|
|
16
16
|
comments?: import("../comments.js").JavaComment[];
|
|
17
|
-
}>, print: import("./helpers.js").JavaPrintFn): builders.Group |
|
|
17
|
+
}>, print: import("./helpers.js").JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
18
18
|
interfaceMemberDeclaration(path: import("prettier").AstPath<import("java-parser").InterfaceMemberDeclarationCstNode & {
|
|
19
19
|
comments?: import("../comments.js").JavaComment[];
|
|
20
20
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc;
|
|
@@ -31,7 +31,7 @@ declare const _default: {
|
|
|
31
31
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
|
|
32
32
|
annotationInterfaceBody(path: import("prettier").AstPath<import("java-parser").AnnotationInterfaceBodyCstNode & {
|
|
33
33
|
comments?: import("../comments.js").JavaComment[];
|
|
34
|
-
}>, print: import("./helpers.js").JavaPrintFn): builders.Group |
|
|
34
|
+
}>, print: import("./helpers.js").JavaPrintFn): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
35
35
|
annotationInterfaceMemberDeclaration(path: import("prettier").AstPath<import("java-parser").AnnotationInterfaceMemberDeclarationCstNode & {
|
|
36
36
|
comments?: import("../comments.js").JavaComment[];
|
|
37
37
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Doc;
|
|
@@ -54,7 +54,7 @@ declare const _default: {
|
|
|
54
54
|
elementValue: typeof printSingle;
|
|
55
55
|
elementValueArrayInitializer(path: import("prettier").AstPath<import("java-parser").ElementValueArrayInitializerCstNode & {
|
|
56
56
|
comments?: import("../comments.js").JavaComment[];
|
|
57
|
-
}>, print: import("./helpers.js").JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Group | "{}";
|
|
57
|
+
}>, print: import("./helpers.js").JavaPrintFn, options: import("./helpers.js").JavaParserOptions): builders.Group | (string | builders.Indent | builders.Hardline)[] | "{}";
|
|
58
58
|
elementValueList(path: import("prettier").AstPath<import("java-parser").ElementValueListCstNode & {
|
|
59
59
|
comments?: import("../comments.js").JavaComment[];
|
|
60
60
|
}>, print: import("./helpers.js").JavaPrintFn): builders.Group;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-java",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.6",
|
|
4
4
|
"description": "Prettier Java Plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"prettier": "^3.0.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "9f2ba5e304a7e2d744fa20f1f3617cc4a4651f88"
|
|
45
45
|
}
|