prettier-plugin-java 2.6.7 → 2.7.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/comments.d.ts +17 -0
- package/dist/comments.js +199 -0
- package/dist/index.d.ts +543 -0
- package/dist/index.js +26 -63
- package/dist/options.d.ts +23 -0
- package/dist/options.js +247 -239
- package/dist/parser.d.ts +9 -0
- package/dist/parser.js +24 -4
- package/dist/printer.d.ts +18 -0
- package/dist/printer.js +39 -5
- package/dist/printers/arrays.d.ts +9 -0
- package/dist/printers/arrays.js +8 -24
- package/dist/printers/blocks-and-statements.d.ts +117 -0
- package/dist/printers/blocks-and-statements.js +316 -412
- package/dist/printers/classes.d.ts +157 -0
- package/dist/printers/classes.js +422 -688
- package/dist/printers/expressions.d.ts +134 -0
- package/dist/printers/expressions.js +548 -560
- package/dist/printers/helpers.d.ts +71 -0
- package/dist/printers/helpers.js +233 -0
- package/dist/printers/index.d.ts +2 -0
- package/dist/printers/index.js +13 -0
- package/dist/printers/interfaces.d.ts +62 -0
- package/dist/printers/interfaces.js +146 -211
- package/dist/printers/lexical-structure.d.ts +14 -0
- package/dist/printers/lexical-structure.js +26 -28
- package/dist/printers/names.d.ts +12 -0
- package/dist/printers/names.js +11 -29
- package/dist/printers/packages-and-modules.d.ts +46 -0
- package/dist/printers/packages-and-modules.js +157 -159
- package/dist/printers/types-values-and-variables.d.ts +46 -0
- package/dist/printers/types-values-and-variables.js +86 -149
- package/package.json +5 -8
- package/dist/base-cst-printer.js +0 -55
- package/dist/cst-printer.js +0 -29
- package/dist/printers/comments/comments-utils.js +0 -21
- package/dist/printers/comments/format-comments.js +0 -171
- package/dist/printers/comments/handle-comments.js +0 -102
- package/dist/printers/prettier-builder.js +0 -45
- package/dist/printers/printer-utils.js +0 -598
- package/dist/types/utils.js +0 -20
- package/dist/utils/expressions-utils.js +0 -25
- package/dist/utils/index.js +0 -2
- package/dist/utils/isEmptyDoc.js +0 -4
- package/dist/utils/printArgumentListWithBraces.js +0 -37
- package/dist/utils/printSingleLambdaInvocation.js +0 -18
- package/index.d.ts +0 -4
|
@@ -1,432 +1,336 @@
|
|
|
1
1
|
import { builders } from "prettier/doc";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
localVariableDeclaration(
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const localVariableType = this.visit(ctx.localVariableType);
|
|
30
|
-
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
|
31
|
-
return rejectAndJoin(hardline, [
|
|
32
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
33
|
-
rejectAndJoin(" ", [
|
|
34
|
-
rejectAndJoin(" ", finalModifiers),
|
|
35
|
-
localVariableType,
|
|
36
|
-
variableDeclaratorList
|
|
37
|
-
])
|
|
2
|
+
import { call, definedKeys, indentInParentheses, isBinaryExpression, isEmptyStatement, lineEndWithComments, lineStartWithComments, map, onlyDefinedKey, printBlock, printDanglingComments, printSingle, printWithModifiers } from "./helpers.js";
|
|
3
|
+
const { group, hardline, ifBreak, indent, join, line, softline } = builders;
|
|
4
|
+
export default {
|
|
5
|
+
block(path, print) {
|
|
6
|
+
const statements = path.node.children.blockStatements
|
|
7
|
+
? call(path, print, "blockStatements")
|
|
8
|
+
: [];
|
|
9
|
+
return printBlock(path, statements.length ? [statements] : []);
|
|
10
|
+
},
|
|
11
|
+
blockStatements(path, print) {
|
|
12
|
+
return join(hardline, map(path, statementPath => {
|
|
13
|
+
const { node, previous } = statementPath;
|
|
14
|
+
const statement = print(statementPath);
|
|
15
|
+
return previous &&
|
|
16
|
+
lineStartWithComments(node) > lineEndWithComments(previous) + 1
|
|
17
|
+
? [hardline, statement]
|
|
18
|
+
: statement;
|
|
19
|
+
}, "blockStatement").filter(doc => doc !== ""));
|
|
20
|
+
},
|
|
21
|
+
blockStatement: printSingle,
|
|
22
|
+
localVariableDeclarationStatement(path, print) {
|
|
23
|
+
return [call(path, print, "localVariableDeclaration"), ";"];
|
|
24
|
+
},
|
|
25
|
+
localVariableDeclaration(path, print) {
|
|
26
|
+
const declaration = join(" ", [
|
|
27
|
+
call(path, print, "localVariableType"),
|
|
28
|
+
call(path, print, "variableDeclaratorList")
|
|
38
29
|
]);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
return printWithModifiers(path, print, "variableModifier", declaration);
|
|
31
|
+
},
|
|
32
|
+
localVariableType: printSingle,
|
|
33
|
+
statement: printSingle,
|
|
34
|
+
statementWithoutTrailingSubstatement: printSingle,
|
|
35
|
+
emptyStatement() {
|
|
36
|
+
return "";
|
|
37
|
+
},
|
|
38
|
+
labeledStatement(path, print) {
|
|
39
|
+
return [
|
|
40
|
+
call(path, print, "Identifier"),
|
|
41
|
+
": ",
|
|
42
|
+
call(path, print, "statement")
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
expressionStatement(path, print) {
|
|
46
|
+
return [call(path, print, "statementExpression"), ";"];
|
|
47
|
+
},
|
|
48
|
+
statementExpression: printSingle,
|
|
49
|
+
ifStatement(path, print) {
|
|
50
|
+
var _a;
|
|
51
|
+
const { children } = path.node;
|
|
52
|
+
const hasEmptyStatement = isEmptyStatement(children.statement[0]);
|
|
53
|
+
const statement = [
|
|
54
|
+
"if ",
|
|
55
|
+
indentInParentheses(call(path, print, "expression")),
|
|
56
|
+
hasEmptyStatement ? ";" : [" ", call(path, print, "statement", 0)]
|
|
57
|
+
];
|
|
58
|
+
if (children.Else) {
|
|
59
|
+
const danglingComments = printDanglingComments(path);
|
|
60
|
+
if (danglingComments.length) {
|
|
61
|
+
statement.push(hardline, ...danglingComments, hardline);
|
|
60
62
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
else {
|
|
64
|
+
const elseHasBlock = ((_a = children.statement[0].children
|
|
65
|
+
.statementWithoutTrailingSubstatement) === null || _a === void 0 ? void 0 : _a[0].children.block) !==
|
|
66
|
+
undefined;
|
|
67
|
+
statement.push(elseHasBlock ? " " : hardline);
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return this.visit([newLabelStatement]);
|
|
69
|
+
const elseHasEmptyStatement = isEmptyStatement(children.statement[1]);
|
|
70
|
+
statement.push("else", elseHasEmptyStatement ? ";" : [" ", call(path, print, "statement", 1)]);
|
|
67
71
|
}
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const statement = this.visit(ctx.statement);
|
|
79
|
-
return concat([identifier, ctx.Colon[0], " ", statement]);
|
|
80
|
-
}
|
|
81
|
-
expressionStatement(ctx) {
|
|
82
|
-
const statementExpression = this.visit(ctx.statementExpression);
|
|
83
|
-
return rejectAndConcat([statementExpression, ctx.Semicolon[0]]);
|
|
84
|
-
}
|
|
85
|
-
statementExpression(ctx) {
|
|
86
|
-
return this.visitSingle(ctx);
|
|
87
|
-
}
|
|
88
|
-
ifStatement(ctx) {
|
|
89
|
-
var _a;
|
|
90
|
-
const expression = this.visit(ctx.expression);
|
|
91
|
-
const ifStatement = this.visit(ctx.statement[0], {
|
|
92
|
-
allowEmptyStatement: true
|
|
93
|
-
});
|
|
94
|
-
const ifSeparator = isStatementEmptyStatement(ifStatement) ? "" : " ";
|
|
95
|
-
let elsePart = "";
|
|
96
|
-
if (ctx.Else !== undefined) {
|
|
97
|
-
const elseStatement = this.visit(ctx.statement[1], {
|
|
98
|
-
allowEmptyStatement: true
|
|
99
|
-
});
|
|
100
|
-
const elseSeparator = isStatementEmptyStatement(elseStatement) ? "" : " ";
|
|
101
|
-
const elseOnSameLine = hasTrailingLineComments(ctx.statement[0]) ||
|
|
102
|
-
hasLeadingLineComments(ctx.Else[0]) ||
|
|
103
|
-
!((_a = ctx.statement[0].children.statementWithoutTrailingSubstatement) === null || _a === void 0 ? void 0 : _a[0].children.block)
|
|
104
|
-
? hardline
|
|
105
|
-
: " ";
|
|
106
|
-
elsePart = rejectAndJoin(elseSeparator, [
|
|
107
|
-
concat([elseOnSameLine, ctx.Else[0]]),
|
|
108
|
-
elseStatement
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
111
|
-
return rejectAndConcat([
|
|
112
|
-
rejectAndJoin(" ", [
|
|
113
|
-
ctx.If[0],
|
|
114
|
-
concat([
|
|
115
|
-
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
|
116
|
-
ifSeparator
|
|
117
|
-
])
|
|
118
|
-
]),
|
|
119
|
-
ifStatement,
|
|
120
|
-
elsePart
|
|
72
|
+
return statement;
|
|
73
|
+
},
|
|
74
|
+
assertStatement(path, print) {
|
|
75
|
+
return ["assert ", ...join([" : "], map(path, print, "expression")), ";"];
|
|
76
|
+
},
|
|
77
|
+
switchStatement(path, print) {
|
|
78
|
+
return join(" ", [
|
|
79
|
+
"switch",
|
|
80
|
+
indentInParentheses(call(path, print, "expression")),
|
|
81
|
+
call(path, print, "switchBlock")
|
|
121
82
|
]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
rejectAndJoin(concat([" ", colon, " "]), expressions),
|
|
129
|
-
ctx.Semicolon[0]
|
|
83
|
+
},
|
|
84
|
+
switchBlock(path, print) {
|
|
85
|
+
const { children } = path.node;
|
|
86
|
+
const caseKeys = definedKeys(children, [
|
|
87
|
+
"switchBlockStatementGroup",
|
|
88
|
+
"switchRule"
|
|
130
89
|
]);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
:
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
switchBlockStatementGroup(ctx) {
|
|
148
|
-
var _a, _b, _c;
|
|
149
|
-
const switchLabel = this.visit(ctx.switchLabel);
|
|
150
|
-
const blockStatements = this.visit(ctx.blockStatements);
|
|
151
|
-
const statements = (_a = ctx.blockStatements) === null || _a === void 0 ? void 0 : _a[0].children.blockStatement;
|
|
152
|
-
const hasSingleStatementBlock = (statements === null || statements === void 0 ? void 0 : statements.length) === 1 &&
|
|
153
|
-
((_c = (_b = statements[0].children.statement) === null || _b === void 0 ? void 0 : _b[0].children.statementWithoutTrailingSubstatement) === null || _c === void 0 ? void 0 : _c[0].children.block) !== undefined;
|
|
154
|
-
return concat([
|
|
90
|
+
const cases = caseKeys.length === 1 ? map(path, print, caseKeys[0]) : [];
|
|
91
|
+
return printBlock(path, cases);
|
|
92
|
+
},
|
|
93
|
+
switchBlockStatementGroup(path, print) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const { children } = path.node;
|
|
96
|
+
const switchLabel = call(path, print, "switchLabel");
|
|
97
|
+
if (!children.blockStatements) {
|
|
98
|
+
return [switchLabel, ":"];
|
|
99
|
+
}
|
|
100
|
+
const blockStatements = call(path, print, "blockStatements");
|
|
101
|
+
const statements = children.blockStatements[0].children.blockStatement;
|
|
102
|
+
const onlyStatementIsBlock = statements.length === 1 &&
|
|
103
|
+
((_b = (_a = statements[0].children.statement) === null || _a === void 0 ? void 0 : _a[0].children.statementWithoutTrailingSubstatement) === null || _b === void 0 ? void 0 : _b[0].children.block) !== undefined;
|
|
104
|
+
return [
|
|
155
105
|
switchLabel,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
?
|
|
159
|
-
:
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
switchLabel(
|
|
163
|
-
var _a, _b
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
106
|
+
":",
|
|
107
|
+
onlyStatementIsBlock
|
|
108
|
+
? [" ", blockStatements]
|
|
109
|
+
: indent([hardline, blockStatements])
|
|
110
|
+
];
|
|
111
|
+
},
|
|
112
|
+
switchLabel(path, print) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
const { children } = path.node;
|
|
115
|
+
if (!((_b = (_a = children.caseConstant) !== null && _a !== void 0 ? _a : children.casePattern) !== null && _b !== void 0 ? _b : children.Null)) {
|
|
116
|
+
return "default";
|
|
117
|
+
}
|
|
118
|
+
const values = [];
|
|
119
|
+
if (children.Null) {
|
|
120
|
+
values.push("null");
|
|
121
|
+
if (children.Default) {
|
|
122
|
+
values.push("default");
|
|
123
|
+
}
|
|
171
124
|
}
|
|
172
|
-
else
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const separator = multiplePatterns ? line : " ";
|
|
177
|
-
const contents = join(separator, [
|
|
178
|
-
Case,
|
|
179
|
-
rejectAndJoinSeps(commas, casePatterns)
|
|
125
|
+
else {
|
|
126
|
+
const valuesKey = onlyDefinedKey(children, [
|
|
127
|
+
"caseConstant",
|
|
128
|
+
"casePattern"
|
|
180
129
|
]);
|
|
181
|
-
|
|
182
|
-
multiplePatterns ? indent(contents) : contents,
|
|
183
|
-
guard
|
|
184
|
-
]));
|
|
130
|
+
values.push(...map(path, print, valuesKey));
|
|
185
131
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
132
|
+
const hasMultipleValues = values.length > 1;
|
|
133
|
+
const label = hasMultipleValues
|
|
134
|
+
? ["case", indent([line, ...join([",", line], values)])]
|
|
135
|
+
: ["case ", values[0]];
|
|
136
|
+
return children.guard
|
|
137
|
+
? [
|
|
138
|
+
group([...label, hasMultipleValues ? line : " "]),
|
|
139
|
+
call(path, print, "guard")
|
|
140
|
+
]
|
|
141
|
+
: group(label);
|
|
142
|
+
},
|
|
143
|
+
switchRule(path, print) {
|
|
144
|
+
const { children } = path.node;
|
|
145
|
+
const bodyKey = onlyDefinedKey(children, [
|
|
146
|
+
"block",
|
|
147
|
+
"expression",
|
|
148
|
+
"throwStatement"
|
|
149
|
+
]);
|
|
150
|
+
const parts = [
|
|
151
|
+
call(path, print, "switchLabel"),
|
|
152
|
+
" -> ",
|
|
153
|
+
call(path, print, bodyKey)
|
|
154
|
+
];
|
|
155
|
+
if (children.Semicolon) {
|
|
156
|
+
parts.push(";");
|
|
157
|
+
}
|
|
158
|
+
return parts;
|
|
159
|
+
},
|
|
160
|
+
caseConstant: printSingle,
|
|
161
|
+
casePattern: printSingle,
|
|
162
|
+
whileStatement(path, print) {
|
|
163
|
+
const statement = call(path, print, "statement");
|
|
164
|
+
const hasEmptyStatement = isEmptyStatement(path.node.children.statement[0]);
|
|
165
|
+
return [
|
|
166
|
+
"while ",
|
|
167
|
+
indentInParentheses(call(path, print, "expression")),
|
|
168
|
+
...[hasEmptyStatement ? ";" : " ", statement]
|
|
169
|
+
];
|
|
170
|
+
},
|
|
171
|
+
doStatement(path, print) {
|
|
172
|
+
const hasEmptyStatement = isEmptyStatement(path.node.children.statement[0]);
|
|
173
|
+
return [
|
|
174
|
+
"do",
|
|
175
|
+
hasEmptyStatement ? ";" : [" ", call(path, print, "statement")],
|
|
176
|
+
" while ",
|
|
177
|
+
indentInParentheses(call(path, print, "expression")),
|
|
178
|
+
";"
|
|
179
|
+
];
|
|
180
|
+
},
|
|
181
|
+
forStatement: printSingle,
|
|
182
|
+
basicForStatement(path, print) {
|
|
183
|
+
const { children } = path.node;
|
|
184
|
+
const danglingComments = printDanglingComments(path);
|
|
185
|
+
if (danglingComments.length) {
|
|
186
|
+
danglingComments.push(hardline);
|
|
193
187
|
}
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
const expressions = ["forInit", "expression", "forUpdate"].map(expressionKey => expressionKey in children ? call(path, print, expressionKey) : "");
|
|
189
|
+
const hasEmptyStatement = isEmptyStatement(children.statement[0]);
|
|
190
|
+
return [
|
|
191
|
+
...danglingComments,
|
|
192
|
+
"for ",
|
|
193
|
+
expressions.some(expression => expression !== "")
|
|
194
|
+
? indentInParentheses(join([";", line], expressions))
|
|
195
|
+
: "(;;)",
|
|
196
|
+
hasEmptyStatement ? ";" : [" ", call(path, print, "statement")]
|
|
197
|
+
];
|
|
198
|
+
},
|
|
199
|
+
forInit: printSingle,
|
|
200
|
+
forUpdate: printSingle,
|
|
201
|
+
statementExpressionList(path, print) {
|
|
202
|
+
return group(map(path, print, "statementExpression").map((expression, index) => index === 0 ? expression : [",", indent([line, expression])]));
|
|
203
|
+
},
|
|
204
|
+
enhancedForStatement(path, print) {
|
|
205
|
+
var _a;
|
|
206
|
+
const statementNode = path.node.children.statement[0];
|
|
207
|
+
const forStatement = [
|
|
208
|
+
printDanglingComments(path),
|
|
209
|
+
"for ",
|
|
210
|
+
"(",
|
|
211
|
+
call(path, print, "localVariableDeclaration"),
|
|
212
|
+
" : ",
|
|
213
|
+
call(path, print, "expression"),
|
|
214
|
+
")"
|
|
215
|
+
];
|
|
216
|
+
if (isEmptyStatement(statementNode)) {
|
|
217
|
+
forStatement.push(";");
|
|
196
218
|
}
|
|
197
219
|
else {
|
|
198
|
-
|
|
220
|
+
const hasStatementBlock = ((_a = statementNode.children.statementWithoutTrailingSubstatement) === null || _a === void 0 ? void 0 : _a[0].children.block) !== undefined;
|
|
221
|
+
const statement = call(path, print, "statement");
|
|
222
|
+
forStatement.push(hasStatementBlock ? [" ", statement] : indent([line, statement]));
|
|
199
223
|
}
|
|
200
|
-
return
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
rejectAndJoin(statementSeparator, [ctx.Do[0], statement]),
|
|
230
|
-
ctx.While[0],
|
|
231
|
-
rejectAndConcat([
|
|
232
|
-
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
|
233
|
-
ctx.Semicolon[0]
|
|
234
|
-
])
|
|
235
|
-
]);
|
|
236
|
-
}
|
|
237
|
-
forStatement(ctx) {
|
|
238
|
-
return this.visitSingle(ctx);
|
|
239
|
-
}
|
|
240
|
-
basicForStatement(ctx) {
|
|
241
|
-
const forInit = this.visit(ctx.forInit);
|
|
242
|
-
const expression = this.visit(ctx.expression);
|
|
243
|
-
const forUpdate = this.visit(ctx.forUpdate);
|
|
244
|
-
const statement = this.visit(ctx.statement[0], {
|
|
245
|
-
allowEmptyStatement: true
|
|
246
|
-
});
|
|
247
|
-
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
|
|
248
|
-
return rejectAndConcat([
|
|
249
|
-
rejectAndJoin(" ", [
|
|
250
|
-
ctx.For[0],
|
|
251
|
-
putIntoBraces(rejectAndConcat([
|
|
252
|
-
forInit,
|
|
253
|
-
rejectAndJoin(line, [ctx.Semicolon[0], expression]),
|
|
254
|
-
rejectAndJoin(line, [ctx.Semicolon[1], forUpdate])
|
|
255
|
-
]), softline, ctx.LBrace[0], ctx.RBrace[0])
|
|
256
|
-
]),
|
|
257
|
-
statementSeparator,
|
|
258
|
-
statement
|
|
259
|
-
]);
|
|
260
|
-
}
|
|
261
|
-
forInit(ctx) {
|
|
262
|
-
return this.visitSingle(ctx);
|
|
263
|
-
}
|
|
264
|
-
forUpdate(ctx) {
|
|
265
|
-
return this.visitSingle(ctx);
|
|
266
|
-
}
|
|
267
|
-
statementExpressionList(ctx) {
|
|
268
|
-
const statementExpressions = this.mapVisit(ctx.statementExpression);
|
|
269
|
-
const commas = ctx.Comma
|
|
270
|
-
? ctx.Comma.map(elt => {
|
|
271
|
-
return concat([printTokenWithComments(elt), " "]);
|
|
272
|
-
})
|
|
273
|
-
: [];
|
|
274
|
-
return rejectAndJoinSeps(commas, statementExpressions);
|
|
275
|
-
}
|
|
276
|
-
enhancedForStatement(ctx) {
|
|
277
|
-
const localVariableDeclaration = this.visit(ctx.localVariableDeclaration);
|
|
278
|
-
const expression = this.visit(ctx.expression);
|
|
279
|
-
const statement = this.visit(ctx.statement[0], {
|
|
280
|
-
allowEmptyStatement: true
|
|
281
|
-
});
|
|
282
|
-
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " ";
|
|
283
|
-
return rejectAndConcat([
|
|
284
|
-
rejectAndJoin(" ", [ctx.For[0], ctx.LBrace[0]]),
|
|
285
|
-
localVariableDeclaration,
|
|
286
|
-
concat([" ", ctx.Colon[0], " "]),
|
|
287
|
-
expression,
|
|
288
|
-
concat([ctx.RBrace[0], statementSeparator]),
|
|
289
|
-
statement
|
|
290
|
-
]);
|
|
291
|
-
}
|
|
292
|
-
breakStatement(ctx) {
|
|
293
|
-
if (ctx.Identifier) {
|
|
294
|
-
const identifier = ctx.Identifier[0];
|
|
295
|
-
return rejectAndConcat([
|
|
296
|
-
concat([ctx.Break[0], " "]),
|
|
297
|
-
identifier,
|
|
298
|
-
ctx.Semicolon[0]
|
|
299
|
-
]);
|
|
224
|
+
return group(forStatement);
|
|
225
|
+
},
|
|
226
|
+
breakStatement(path, print) {
|
|
227
|
+
return path.node.children.Identifier
|
|
228
|
+
? ["break ", call(path, print, "Identifier"), ";"]
|
|
229
|
+
: "break;";
|
|
230
|
+
},
|
|
231
|
+
continueStatement(path, print) {
|
|
232
|
+
return path.node.children.Identifier
|
|
233
|
+
? ["continue ", call(path, print, "Identifier"), ";"]
|
|
234
|
+
: "continue;";
|
|
235
|
+
},
|
|
236
|
+
returnStatement(path, print) {
|
|
237
|
+
const { children } = path.node;
|
|
238
|
+
const statement = ["return"];
|
|
239
|
+
if (children.expression) {
|
|
240
|
+
statement.push(" ");
|
|
241
|
+
const expression = call(path, print, "expression");
|
|
242
|
+
if (isBinaryExpression(children.expression[0])) {
|
|
243
|
+
statement.push(group([
|
|
244
|
+
ifBreak("("),
|
|
245
|
+
indent([softline, expression]),
|
|
246
|
+
softline,
|
|
247
|
+
ifBreak(")")
|
|
248
|
+
]));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
statement.push(expression);
|
|
252
|
+
}
|
|
300
253
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
254
|
+
statement.push(";");
|
|
255
|
+
return statement;
|
|
256
|
+
},
|
|
257
|
+
throwStatement(path, print) {
|
|
258
|
+
return ["throw ", call(path, print, "expression"), ";"];
|
|
259
|
+
},
|
|
260
|
+
synchronizedStatement(path, print) {
|
|
261
|
+
return [
|
|
262
|
+
"synchronized ",
|
|
263
|
+
indentInParentheses(call(path, print, "expression")),
|
|
264
|
+
" ",
|
|
265
|
+
call(path, print, "block")
|
|
266
|
+
];
|
|
267
|
+
},
|
|
268
|
+
tryStatement(path, print) {
|
|
269
|
+
const { children } = path.node;
|
|
270
|
+
if (children.tryWithResourcesStatement) {
|
|
271
|
+
return call(path, print, "tryWithResourcesStatement");
|
|
311
272
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (ctx.expression) {
|
|
316
|
-
const expression = this.visit(ctx.expression, {
|
|
317
|
-
addParenthesisToWrapStatement: true
|
|
318
|
-
});
|
|
319
|
-
return rejectAndConcat([
|
|
320
|
-
concat([ctx.Return[0], " "]),
|
|
321
|
-
expression,
|
|
322
|
-
ctx.Semicolon[0]
|
|
323
|
-
]);
|
|
273
|
+
const blocks = ["try", call(path, print, "block")];
|
|
274
|
+
if (children.catches) {
|
|
275
|
+
blocks.push(call(path, print, "catches"));
|
|
324
276
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
throwStatement(ctx) {
|
|
328
|
-
const expression = this.visit(ctx.expression);
|
|
329
|
-
return rejectAndConcat([
|
|
330
|
-
concat([ctx.Throw[0], " "]),
|
|
331
|
-
expression,
|
|
332
|
-
ctx.Semicolon[0]
|
|
333
|
-
]);
|
|
334
|
-
}
|
|
335
|
-
synchronizedStatement(ctx) {
|
|
336
|
-
const expression = this.visit(ctx.expression);
|
|
337
|
-
const block = this.visit(ctx.block);
|
|
338
|
-
return rejectAndConcat([
|
|
339
|
-
join(" ", [
|
|
340
|
-
ctx.Synchronized[0],
|
|
341
|
-
concat([
|
|
342
|
-
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
|
343
|
-
" "
|
|
344
|
-
])
|
|
345
|
-
]),
|
|
346
|
-
block
|
|
347
|
-
]);
|
|
348
|
-
}
|
|
349
|
-
tryStatement(ctx) {
|
|
350
|
-
if (ctx.tryWithResourcesStatement) {
|
|
351
|
-
return this.visit(ctx.tryWithResourcesStatement);
|
|
277
|
+
if (children.finally) {
|
|
278
|
+
blocks.push(call(path, print, "finally"));
|
|
352
279
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
])),
|
|
372
|
-
block
|
|
373
|
-
]);
|
|
374
|
-
}
|
|
375
|
-
catchFormalParameter(ctx) {
|
|
376
|
-
const variableModifiers = this.mapVisit(ctx.variableModifier);
|
|
377
|
-
const catchType = this.visit(ctx.catchType);
|
|
378
|
-
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
|
379
|
-
return rejectAndJoin(" ", [
|
|
380
|
-
rejectAndJoin(" ", variableModifiers),
|
|
381
|
-
catchType,
|
|
382
|
-
variableDeclaratorId
|
|
280
|
+
return join(" ", blocks);
|
|
281
|
+
},
|
|
282
|
+
catches(path, print) {
|
|
283
|
+
return join(" ", map(path, print, "catchClause"));
|
|
284
|
+
},
|
|
285
|
+
catchClause(path, print) {
|
|
286
|
+
return [
|
|
287
|
+
"catch ",
|
|
288
|
+
indentInParentheses(call(path, print, "catchFormalParameter")),
|
|
289
|
+
" ",
|
|
290
|
+
call(path, print, "block")
|
|
291
|
+
];
|
|
292
|
+
},
|
|
293
|
+
catchFormalParameter(path, print) {
|
|
294
|
+
return join(" ", [
|
|
295
|
+
...map(path, print, "variableModifier"),
|
|
296
|
+
call(path, print, "catchType"),
|
|
297
|
+
call(path, print, "variableDeclaratorId")
|
|
383
298
|
]);
|
|
384
|
-
}
|
|
385
|
-
catchType(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
resourceList(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
resource(ctx) {
|
|
423
|
-
return this.visitSingle(ctx);
|
|
424
|
-
}
|
|
425
|
-
yieldStatement(ctx) {
|
|
426
|
-
const expression = this.visit(ctx.expression);
|
|
427
|
-
return join(" ", [ctx.Yield[0], concat([expression, ctx.Semicolon[0]])]);
|
|
428
|
-
}
|
|
429
|
-
variableAccess(ctx) {
|
|
430
|
-
return this.visitSingle(ctx);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
299
|
+
},
|
|
300
|
+
catchType(path, print) {
|
|
301
|
+
return join([line, "| "], [call(path, print, "unannClassType"), ...map(path, print, "classType")]);
|
|
302
|
+
},
|
|
303
|
+
finally(path, print) {
|
|
304
|
+
return ["finally ", call(path, print, "block")];
|
|
305
|
+
},
|
|
306
|
+
tryWithResourcesStatement(path, print) {
|
|
307
|
+
const { children } = path.node;
|
|
308
|
+
const blocks = [
|
|
309
|
+
"try",
|
|
310
|
+
call(path, print, "resourceSpecification"),
|
|
311
|
+
call(path, print, "block")
|
|
312
|
+
];
|
|
313
|
+
if (children.catches) {
|
|
314
|
+
blocks.push(call(path, print, "catches"));
|
|
315
|
+
}
|
|
316
|
+
if (children.finally) {
|
|
317
|
+
blocks.push(call(path, print, "finally"));
|
|
318
|
+
}
|
|
319
|
+
return join(" ", blocks);
|
|
320
|
+
},
|
|
321
|
+
resourceSpecification(path, print, options) {
|
|
322
|
+
const resources = [call(path, print, "resourceList")];
|
|
323
|
+
if (options.trailingComma !== "none") {
|
|
324
|
+
resources.push(ifBreak(";"));
|
|
325
|
+
}
|
|
326
|
+
return indentInParentheses(resources);
|
|
327
|
+
},
|
|
328
|
+
resourceList(path, print) {
|
|
329
|
+
return join([";", line], map(path, print, "resource"));
|
|
330
|
+
},
|
|
331
|
+
resource: printSingle,
|
|
332
|
+
yieldStatement(path, print) {
|
|
333
|
+
return ["yield ", call(path, print, "expression"), ";"];
|
|
334
|
+
},
|
|
335
|
+
variableAccess: printSingle
|
|
336
|
+
};
|