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,324 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { line, softline, hardline } = require("prettier").doc.builders;
|
|
4
|
-
const { concat, group, indent } = require("./prettier-builder");
|
|
5
|
-
const { printTokenWithComments } = require("./comments/format-comments");
|
|
6
|
-
const {
|
|
7
|
-
rejectAndConcat,
|
|
8
|
-
rejectAndJoin,
|
|
9
|
-
sortModifiers,
|
|
10
|
-
rejectAndJoinSeps,
|
|
11
|
-
getInterfaceBodyDeclarationsSeparator,
|
|
12
|
-
putIntoBraces,
|
|
13
|
-
displaySemicolon,
|
|
14
|
-
isStatementEmptyStatement,
|
|
15
|
-
printArrayList
|
|
16
|
-
} = require("./printer-utils");
|
|
17
|
-
|
|
18
|
-
class InterfacesPrettierVisitor {
|
|
19
|
-
interfaceDeclaration(ctx) {
|
|
20
|
-
const modifiers = sortModifiers(ctx.interfaceModifier);
|
|
21
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
22
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
23
|
-
|
|
24
|
-
const declaration = ctx.normalInterfaceDeclaration
|
|
25
|
-
? this.visit(ctx.normalInterfaceDeclaration)
|
|
26
|
-
: this.visit(ctx.annotationTypeDeclaration);
|
|
27
|
-
|
|
28
|
-
return rejectAndJoin(hardline, [
|
|
29
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
30
|
-
rejectAndJoin(" ", [rejectAndJoin(" ", otherModifiers), declaration])
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
normalInterfaceDeclaration(ctx) {
|
|
35
|
-
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
36
|
-
const typeParameters = this.visit(ctx.typeParameters);
|
|
37
|
-
const extendsInterfaces = this.visit(ctx.extendsInterfaces);
|
|
38
|
-
const optionalInterfacePermits = this.visit(ctx.interfacePermits);
|
|
39
|
-
const interfaceBody = this.visit(ctx.interfaceBody);
|
|
40
|
-
|
|
41
|
-
let extendsInterfacesPart = "";
|
|
42
|
-
if (extendsInterfaces) {
|
|
43
|
-
extendsInterfacesPart = indent(
|
|
44
|
-
rejectAndConcat([softline, extendsInterfaces])
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let interfacePermits = "";
|
|
49
|
-
if (optionalInterfacePermits) {
|
|
50
|
-
interfacePermits = indent(
|
|
51
|
-
rejectAndConcat([softline, optionalInterfacePermits])
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return rejectAndJoin(" ", [
|
|
56
|
-
group(
|
|
57
|
-
rejectAndJoin(" ", [
|
|
58
|
-
ctx.Interface[0],
|
|
59
|
-
concat([typeIdentifier, typeParameters]),
|
|
60
|
-
extendsInterfacesPart,
|
|
61
|
-
interfacePermits
|
|
62
|
-
])
|
|
63
|
-
),
|
|
64
|
-
interfaceBody
|
|
65
|
-
]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interfaceModifier(ctx) {
|
|
69
|
-
if (ctx.annotation) {
|
|
70
|
-
return this.visitSingle(ctx);
|
|
71
|
-
}
|
|
72
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
extendsInterfaces(ctx) {
|
|
76
|
-
const interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
|
77
|
-
|
|
78
|
-
return group(
|
|
79
|
-
rejectAndConcat([
|
|
80
|
-
ctx.Extends[0],
|
|
81
|
-
indent(rejectAndConcat([line, interfaceTypeList]))
|
|
82
|
-
])
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interfacePermits(ctx) {
|
|
87
|
-
return this.classPermits(ctx);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interfaceBody(ctx) {
|
|
91
|
-
let joinedInterfaceMemberDeclaration = "";
|
|
92
|
-
|
|
93
|
-
if (ctx.interfaceMemberDeclaration !== undefined) {
|
|
94
|
-
const interfaceMemberDeclaration = this.mapVisit(
|
|
95
|
-
ctx.interfaceMemberDeclaration
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const separators = getInterfaceBodyDeclarationsSeparator(
|
|
99
|
-
ctx.interfaceMemberDeclaration
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
joinedInterfaceMemberDeclaration = rejectAndJoinSeps(
|
|
103
|
-
separators,
|
|
104
|
-
interfaceMemberDeclaration
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return putIntoBraces(
|
|
108
|
-
joinedInterfaceMemberDeclaration,
|
|
109
|
-
hardline,
|
|
110
|
-
ctx.LCurly[0],
|
|
111
|
-
ctx.RCurly[0]
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
interfaceMemberDeclaration(ctx) {
|
|
116
|
-
if (ctx.Semicolon) {
|
|
117
|
-
return displaySemicolon(ctx.Semicolon[0]);
|
|
118
|
-
}
|
|
119
|
-
return this.visitSingle(ctx);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
constantDeclaration(ctx) {
|
|
123
|
-
const modifiers = sortModifiers(ctx.constantModifier);
|
|
124
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
125
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
126
|
-
|
|
127
|
-
const unannType = this.visit(ctx.unannType);
|
|
128
|
-
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
|
129
|
-
|
|
130
|
-
return rejectAndJoin(hardline, [
|
|
131
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
132
|
-
rejectAndJoin(" ", [
|
|
133
|
-
rejectAndJoin(" ", otherModifiers),
|
|
134
|
-
unannType,
|
|
135
|
-
rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
|
|
136
|
-
])
|
|
137
|
-
]);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
constantModifier(ctx) {
|
|
141
|
-
if (ctx.annotation) {
|
|
142
|
-
return this.visitSingle(ctx);
|
|
143
|
-
}
|
|
144
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
interfaceMethodDeclaration(ctx) {
|
|
148
|
-
const modifiers = sortModifiers(ctx.interfaceMethodModifier);
|
|
149
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
150
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
151
|
-
|
|
152
|
-
const methodHeader = this.visit(ctx.methodHeader);
|
|
153
|
-
const methodBody = this.visit(ctx.methodBody);
|
|
154
|
-
const separator = isStatementEmptyStatement(methodBody) ? "" : " ";
|
|
155
|
-
|
|
156
|
-
return rejectAndJoin(hardline, [
|
|
157
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
158
|
-
rejectAndJoin(" ", [
|
|
159
|
-
rejectAndJoin(" ", otherModifiers),
|
|
160
|
-
rejectAndJoin(separator, [methodHeader, methodBody])
|
|
161
|
-
])
|
|
162
|
-
]);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
interfaceMethodModifier(ctx) {
|
|
166
|
-
if (ctx.annotation) {
|
|
167
|
-
return this.visitSingle(ctx);
|
|
168
|
-
}
|
|
169
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
annotationTypeDeclaration(ctx) {
|
|
173
|
-
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
174
|
-
const annotationTypeBody = this.visit(ctx.annotationTypeBody);
|
|
175
|
-
|
|
176
|
-
return rejectAndJoin(" ", [
|
|
177
|
-
concat([ctx.At[0], ctx.Interface[0]]),
|
|
178
|
-
typeIdentifier,
|
|
179
|
-
annotationTypeBody
|
|
180
|
-
]);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
annotationTypeBody(ctx) {
|
|
184
|
-
const annotationTypeMemberDeclaration = this.mapVisit(
|
|
185
|
-
ctx.annotationTypeMemberDeclaration
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
return rejectAndJoin(line, [
|
|
189
|
-
indent(
|
|
190
|
-
rejectAndJoin(line, [
|
|
191
|
-
ctx.LCurly[0],
|
|
192
|
-
rejectAndJoin(concat([line, line]), annotationTypeMemberDeclaration)
|
|
193
|
-
])
|
|
194
|
-
),
|
|
195
|
-
ctx.RCurly[0]
|
|
196
|
-
]);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
annotationTypeMemberDeclaration(ctx) {
|
|
200
|
-
if (ctx.Semicolon) {
|
|
201
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
202
|
-
}
|
|
203
|
-
return this.visitSingle(ctx);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
annotationTypeElementDeclaration(ctx) {
|
|
207
|
-
const modifiers = sortModifiers(ctx.annotationTypeElementModifier);
|
|
208
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
209
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
210
|
-
|
|
211
|
-
const unannType = this.visit(ctx.unannType);
|
|
212
|
-
const identifier = ctx.Identifier[0];
|
|
213
|
-
const dims = this.visit(ctx.dims);
|
|
214
|
-
const defaultValue = ctx.defaultValue
|
|
215
|
-
? concat([" ", this.visit(ctx.defaultValue)])
|
|
216
|
-
: "";
|
|
217
|
-
|
|
218
|
-
return rejectAndJoin(hardline, [
|
|
219
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
220
|
-
rejectAndJoin(" ", [
|
|
221
|
-
rejectAndJoin(" ", otherModifiers),
|
|
222
|
-
unannType,
|
|
223
|
-
rejectAndConcat([
|
|
224
|
-
identifier,
|
|
225
|
-
concat([ctx.LBrace[0], ctx.RBrace[0]]),
|
|
226
|
-
dims,
|
|
227
|
-
defaultValue,
|
|
228
|
-
ctx.Semicolon[0]
|
|
229
|
-
])
|
|
230
|
-
])
|
|
231
|
-
]);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
annotationTypeElementModifier(ctx) {
|
|
235
|
-
if (ctx.annotation) {
|
|
236
|
-
return this.visitSingle(ctx);
|
|
237
|
-
}
|
|
238
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
defaultValue(ctx) {
|
|
242
|
-
const elementValue = this.visit(ctx.elementValue);
|
|
243
|
-
|
|
244
|
-
return rejectAndJoin(" ", [ctx.Default[0], elementValue]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
annotation(ctx) {
|
|
248
|
-
const fqn = this.visit(ctx.typeName);
|
|
249
|
-
|
|
250
|
-
let annoArgs = "";
|
|
251
|
-
if (ctx.LBrace) {
|
|
252
|
-
if (ctx.elementValuePairList) {
|
|
253
|
-
annoArgs = putIntoBraces(
|
|
254
|
-
this.visit(ctx.elementValuePairList),
|
|
255
|
-
softline,
|
|
256
|
-
ctx.LBrace[0],
|
|
257
|
-
ctx.RBrace[0]
|
|
258
|
-
);
|
|
259
|
-
} else if (ctx.elementValue) {
|
|
260
|
-
annoArgs = putIntoBraces(
|
|
261
|
-
this.visit(ctx.elementValue),
|
|
262
|
-
softline,
|
|
263
|
-
ctx.LBrace[0],
|
|
264
|
-
ctx.RBrace[0]
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return group(rejectAndConcat([ctx.At[0], fqn, annoArgs]));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
elementValuePairList(ctx) {
|
|
273
|
-
const elementValuePairs = this.mapVisit(ctx.elementValuePair);
|
|
274
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
275
|
-
|
|
276
|
-
return rejectAndJoinSeps(commas, elementValuePairs);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
elementValuePair(ctx) {
|
|
280
|
-
const identifier = ctx.Identifier[0];
|
|
281
|
-
const elementValue = this.visit(ctx.elementValue);
|
|
282
|
-
|
|
283
|
-
return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
elementValue(ctx) {
|
|
287
|
-
return this.visitSingle(ctx);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
elementValueArrayInitializer(ctx) {
|
|
291
|
-
const elementValueList = this.visit(ctx.elementValueList);
|
|
292
|
-
|
|
293
|
-
return printArrayList({
|
|
294
|
-
list: elementValueList,
|
|
295
|
-
extraComma: ctx.Comma,
|
|
296
|
-
LCurly: ctx.LCurly[0],
|
|
297
|
-
RCurly: ctx.RCurly[0],
|
|
298
|
-
trailingComma: this.prettierOptions.trailingComma
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
elementValueList(ctx) {
|
|
303
|
-
const elementValues = this.mapVisit(ctx.elementValue);
|
|
304
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
305
|
-
|
|
306
|
-
return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)]));
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
identifyInterfaceBodyDeclarationType() {
|
|
310
|
-
return "identifyInterfaceBodyDeclarationType";
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
identifyAnnotationBodyDeclarationType() {
|
|
314
|
-
return "identifyAnnotationBodyDeclarationType";
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
isSimpleElementValueAnnotation() {
|
|
318
|
-
return "isSimpleElementValueAnnotation";
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
module.exports = {
|
|
323
|
-
InterfacesPrettierVisitor
|
|
324
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { printTokenWithComments } = require("./comments/format-comments");
|
|
3
|
-
|
|
4
|
-
class LexicalStructurePrettierVisitor {
|
|
5
|
-
literal(ctx) {
|
|
6
|
-
if (ctx.CharLiteral || ctx.TextBlock || ctx.StringLiteral || ctx.Null) {
|
|
7
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
8
|
-
}
|
|
9
|
-
return this.visitSingle(ctx);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
integerLiteral(ctx) {
|
|
13
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
floatingPointLiteral(ctx) {
|
|
17
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
booleanLiteral(ctx) {
|
|
21
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
LexicalStructurePrettierVisitor
|
|
27
|
-
};
|
package/src/printers/names.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { buildFqn } = require("./printer-utils");
|
|
4
|
-
const { printTokenWithComments } = require("./comments/format-comments");
|
|
5
|
-
|
|
6
|
-
class NamesPrettierVisitor {
|
|
7
|
-
typeIdentifier(ctx) {
|
|
8
|
-
return printTokenWithComments(ctx.Identifier[0]);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
moduleName(ctx) {
|
|
12
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
packageName(ctx) {
|
|
16
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
typeName(ctx) {
|
|
20
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
expressionName(ctx) {
|
|
24
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
methodName(ctx) {
|
|
28
|
-
return printTokenWithComments(ctx.Identifier[0]);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
packageOrTypeName(ctx) {
|
|
32
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
ambiguousName(ctx) {
|
|
36
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
NamesPrettierVisitor
|
|
42
|
-
};
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { line, hardline, indent, group } = require("prettier").doc.builders;
|
|
4
|
-
const { concat, join } = require("./prettier-builder");
|
|
5
|
-
const { printTokenWithComments } = require("./comments/format-comments");
|
|
6
|
-
const {
|
|
7
|
-
buildFqn,
|
|
8
|
-
rejectAndJoin,
|
|
9
|
-
rejectAndConcat,
|
|
10
|
-
rejectAndJoinSeps,
|
|
11
|
-
displaySemicolon,
|
|
12
|
-
putIntoBraces,
|
|
13
|
-
getBlankLinesSeparator,
|
|
14
|
-
sortImports
|
|
15
|
-
} = require("./printer-utils");
|
|
16
|
-
|
|
17
|
-
class PackagesAndModulesPrettierVisitor {
|
|
18
|
-
compilationUnit(ctx) {
|
|
19
|
-
const compilationUnit =
|
|
20
|
-
ctx.ordinaryCompilationUnit || ctx.modularCompilationUnit;
|
|
21
|
-
|
|
22
|
-
return concat([this.visit(compilationUnit[0]), line]);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
ordinaryCompilationUnit(ctx) {
|
|
26
|
-
const packageDecl = this.visit(ctx.packageDeclaration);
|
|
27
|
-
|
|
28
|
-
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
29
|
-
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
30
|
-
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
31
|
-
|
|
32
|
-
const typesDecl = this.mapVisit(ctx.typeDeclaration);
|
|
33
|
-
// TODO: utility to add item+line (or multiple lines) but only if an item exists
|
|
34
|
-
return rejectAndConcat([
|
|
35
|
-
rejectAndJoin(concat([hardline, hardline]), [
|
|
36
|
-
packageDecl,
|
|
37
|
-
rejectAndJoin(hardline, staticImports),
|
|
38
|
-
rejectAndJoin(hardline, nonStaticImports),
|
|
39
|
-
rejectAndJoin(concat([hardline, hardline]), typesDecl)
|
|
40
|
-
])
|
|
41
|
-
]);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
modularCompilationUnit(ctx) {
|
|
45
|
-
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
46
|
-
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
47
|
-
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
48
|
-
|
|
49
|
-
const moduleDeclaration = this.visit(ctx.moduleDeclaration);
|
|
50
|
-
|
|
51
|
-
return rejectAndConcat([
|
|
52
|
-
rejectAndJoin(concat([hardline, hardline]), [
|
|
53
|
-
rejectAndJoin(hardline, staticImports),
|
|
54
|
-
rejectAndJoin(hardline, nonStaticImports),
|
|
55
|
-
moduleDeclaration
|
|
56
|
-
])
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
packageDeclaration(ctx) {
|
|
61
|
-
const modifiers = this.mapVisit(ctx.packageModifier);
|
|
62
|
-
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
63
|
-
|
|
64
|
-
return rejectAndJoin(hardline, [
|
|
65
|
-
rejectAndJoin(hardline, modifiers),
|
|
66
|
-
concat([ctx.Package[0], " ", name, ctx.Semicolon[0]])
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
packageModifier(ctx) {
|
|
71
|
-
return this.visitSingle(ctx);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
importDeclaration(ctx) {
|
|
75
|
-
if (ctx.emptyStatement !== undefined) {
|
|
76
|
-
return this.visit(ctx.emptyStatement);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const optionalStatic = ctx.Static ? ctx.Static[0] : "";
|
|
80
|
-
const packageOrTypeName = this.visit(ctx.packageOrTypeName);
|
|
81
|
-
|
|
82
|
-
const optionalDotStar = ctx.Dot ? concat([ctx.Dot[0], ctx.Star[0]]) : "";
|
|
83
|
-
|
|
84
|
-
return rejectAndJoin(" ", [
|
|
85
|
-
ctx.Import[0],
|
|
86
|
-
optionalStatic,
|
|
87
|
-
rejectAndConcat([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]])
|
|
88
|
-
]);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
typeDeclaration(ctx) {
|
|
92
|
-
if (ctx.Semicolon) {
|
|
93
|
-
return displaySemicolon(ctx.Semicolon[0]);
|
|
94
|
-
}
|
|
95
|
-
return this.visitSingle(ctx);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
moduleDeclaration(ctx) {
|
|
99
|
-
const annotations = this.mapVisit(ctx.annotation);
|
|
100
|
-
const optionalOpen = ctx.Open ? ctx.Open[0] : "";
|
|
101
|
-
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
102
|
-
const moduleDirectives = this.mapVisit(ctx.moduleDirective);
|
|
103
|
-
|
|
104
|
-
const content = rejectAndJoinSeps(
|
|
105
|
-
getBlankLinesSeparator(ctx.moduleDirective),
|
|
106
|
-
moduleDirectives
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return rejectAndJoin(" ", [
|
|
110
|
-
join(" ", annotations),
|
|
111
|
-
optionalOpen,
|
|
112
|
-
ctx.Module[0],
|
|
113
|
-
name,
|
|
114
|
-
putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0])
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
moduleDirective(ctx) {
|
|
119
|
-
return this.visitSingle(ctx);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
requiresModuleDirective(ctx) {
|
|
123
|
-
const modifiers = this.mapVisit(ctx.requiresModifier);
|
|
124
|
-
const moduleName = this.visit(ctx.moduleName);
|
|
125
|
-
|
|
126
|
-
return rejectAndJoin(" ", [
|
|
127
|
-
ctx.Requires[0],
|
|
128
|
-
join(" ", modifiers),
|
|
129
|
-
concat([moduleName, ctx.Semicolon[0]])
|
|
130
|
-
]);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
exportsModuleDirective(ctx) {
|
|
134
|
-
const packageName = this.visit(ctx.packageName);
|
|
135
|
-
const to = ctx.To ? ctx.To[0] : "";
|
|
136
|
-
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
137
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
138
|
-
|
|
139
|
-
return group(
|
|
140
|
-
rejectAndConcat([
|
|
141
|
-
indent(
|
|
142
|
-
rejectAndJoin(line, [
|
|
143
|
-
rejectAndJoin(" ", [ctx.Exports[0], packageName]),
|
|
144
|
-
group(
|
|
145
|
-
indent(
|
|
146
|
-
rejectAndJoin(line, [
|
|
147
|
-
to,
|
|
148
|
-
rejectAndJoinSeps(commas, moduleNames)
|
|
149
|
-
])
|
|
150
|
-
)
|
|
151
|
-
)
|
|
152
|
-
])
|
|
153
|
-
),
|
|
154
|
-
ctx.Semicolon[0]
|
|
155
|
-
])
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
opensModuleDirective(ctx) {
|
|
160
|
-
const packageName = this.visit(ctx.packageName);
|
|
161
|
-
const to = ctx.To ? ctx.To[0] : "";
|
|
162
|
-
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
163
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
164
|
-
|
|
165
|
-
return group(
|
|
166
|
-
rejectAndConcat([
|
|
167
|
-
indent(
|
|
168
|
-
rejectAndJoin(line, [
|
|
169
|
-
rejectAndJoin(" ", [ctx.Opens[0], packageName]),
|
|
170
|
-
group(
|
|
171
|
-
indent(
|
|
172
|
-
rejectAndJoin(line, [
|
|
173
|
-
to,
|
|
174
|
-
rejectAndJoinSeps(commas, moduleNames)
|
|
175
|
-
])
|
|
176
|
-
)
|
|
177
|
-
)
|
|
178
|
-
])
|
|
179
|
-
),
|
|
180
|
-
ctx.Semicolon[0]
|
|
181
|
-
])
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
usesModuleDirective(ctx) {
|
|
186
|
-
const typeName = this.visit(ctx.typeName);
|
|
187
|
-
|
|
188
|
-
return rejectAndConcat([
|
|
189
|
-
concat([ctx.Uses[0], " "]),
|
|
190
|
-
typeName,
|
|
191
|
-
ctx.Semicolon[0]
|
|
192
|
-
]);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
providesModuleDirective(ctx) {
|
|
196
|
-
const firstTypeName = this.visit(ctx.typeName[0]);
|
|
197
|
-
const otherTypeNames = this.mapVisit(ctx.typeName.slice(1));
|
|
198
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
199
|
-
|
|
200
|
-
return group(
|
|
201
|
-
rejectAndConcat([
|
|
202
|
-
indent(
|
|
203
|
-
rejectAndJoin(line, [
|
|
204
|
-
rejectAndJoin(" ", [ctx.Provides[0], firstTypeName]),
|
|
205
|
-
group(
|
|
206
|
-
indent(
|
|
207
|
-
rejectAndJoin(line, [
|
|
208
|
-
ctx.With[0],
|
|
209
|
-
rejectAndJoinSeps(commas, otherTypeNames)
|
|
210
|
-
])
|
|
211
|
-
)
|
|
212
|
-
)
|
|
213
|
-
])
|
|
214
|
-
),
|
|
215
|
-
ctx.Semicolon[0]
|
|
216
|
-
])
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
requiresModifier(ctx) {
|
|
221
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
isModuleCompilationUnit() {
|
|
225
|
-
return "isModuleCompilationUnit";
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
module.exports = {
|
|
230
|
-
PackagesAndModulesPrettierVisitor
|
|
231
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const prettier = require("prettier").doc.builders;
|
|
3
|
-
|
|
4
|
-
const { processComments } = require("./comments/format-comments");
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* ------------------------------------------------------------------
|
|
8
|
-
* Wraps the Prettier builder functions to print tokens with comments
|
|
9
|
-
* ------------------------------------------------------------------
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
function concat(docs) {
|
|
13
|
-
const concatenation = prettier.concat(processComments(docs));
|
|
14
|
-
return concatenation.parts.length === 0 ? "" : concatenation;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function join(sep, docs) {
|
|
18
|
-
const concatenation = prettier.join(
|
|
19
|
-
processComments(sep),
|
|
20
|
-
processComments(docs)
|
|
21
|
-
);
|
|
22
|
-
return concatenation.parts.length === 0 ? "" : concatenation;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function group(doc, opts) {
|
|
26
|
-
const group = prettier.group(processComments(doc), opts);
|
|
27
|
-
return group.contents === undefined ? "" : group;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function fill(docs) {
|
|
31
|
-
const fill = prettier.fill(processComments(docs));
|
|
32
|
-
return fill.parts.length === 0 ? "" : fill;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function indent(doc) {
|
|
36
|
-
const indentedDoc = prettier.indent(processComments(doc));
|
|
37
|
-
return indentedDoc.contents.length === 0 ? "" : indentedDoc;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function dedent(doc) {
|
|
41
|
-
const indentedDoc = prettier.dedent(processComments(doc));
|
|
42
|
-
return indentedDoc.contents.length === 0 ? "" : indentedDoc;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function ifBreak(breakContents, flatContents) {
|
|
46
|
-
return prettier.ifBreak(
|
|
47
|
-
processComments(breakContents),
|
|
48
|
-
processComments(flatContents)
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
module.exports = {
|
|
53
|
-
concat,
|
|
54
|
-
join,
|
|
55
|
-
group,
|
|
56
|
-
fill,
|
|
57
|
-
indent,
|
|
58
|
-
dedent,
|
|
59
|
-
ifBreak
|
|
60
|
-
};
|