prettier-plugin-java 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,251 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.InterfacesPrettierVisitor = void 0;
19
- var prettier_builder_1 = require("./prettier-builder");
20
- var format_comments_1 = require("./comments/format-comments");
21
- var printer_utils_1 = require("./printer-utils");
22
- var doc_1 = require("prettier/doc");
23
- var base_cst_printer_1 = require("../base-cst-printer");
24
- var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
25
- var InterfacesPrettierVisitor = /** @class */ (function (_super) {
26
- __extends(InterfacesPrettierVisitor, _super);
27
- function InterfacesPrettierVisitor() {
28
- return _super !== null && _super.apply(this, arguments) || this;
29
- }
30
- InterfacesPrettierVisitor.prototype.interfaceDeclaration = function (ctx) {
31
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.interfaceModifier);
32
- var firstAnnotations = this.mapVisit(modifiers[0]);
33
- var otherModifiers = this.mapVisit(modifiers[1]);
34
- var declaration = ctx.normalInterfaceDeclaration
35
- ? this.visit(ctx.normalInterfaceDeclaration)
36
- : this.visit(ctx.annotationTypeDeclaration);
37
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
38
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
39
- (0, printer_utils_1.rejectAndJoin)(" ", [(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), declaration])
40
- ]);
41
- };
42
- InterfacesPrettierVisitor.prototype.normalInterfaceDeclaration = function (ctx) {
43
- var typeIdentifier = this.visit(ctx.typeIdentifier);
44
- var typeParameters = this.visit(ctx.typeParameters);
45
- var extendsInterfaces = this.visit(ctx.extendsInterfaces);
46
- var optionalInterfacePermits = this.visit(ctx.interfacePermits);
47
- var interfaceBody = this.visit(ctx.interfaceBody);
48
- var extendsInterfacesPart = "";
49
- if (extendsInterfaces) {
50
- extendsInterfacesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, extendsInterfaces]));
51
- }
52
- var interfacePermits = "";
53
- if (optionalInterfacePermits) {
54
- interfacePermits = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, optionalInterfacePermits]));
55
- }
56
- return (0, printer_utils_1.rejectAndJoin)(" ", [
57
- (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(" ", [
58
- ctx.Interface[0],
59
- (0, prettier_builder_1.concat)([typeIdentifier, typeParameters]),
60
- extendsInterfacesPart,
61
- interfacePermits
62
- ])),
63
- interfaceBody
64
- ]);
65
- };
66
- InterfacesPrettierVisitor.prototype.interfaceModifier = function (ctx) {
67
- if (ctx.annotation) {
68
- return this.visitSingle(ctx);
69
- }
70
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
71
- };
72
- InterfacesPrettierVisitor.prototype.extendsInterfaces = function (ctx) {
73
- var interfaceTypeList = this.visit(ctx.interfaceTypeList);
74
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([
75
- ctx.Extends[0],
76
- (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, interfaceTypeList]))
77
- ]));
78
- };
79
- InterfacesPrettierVisitor.prototype.interfacePermits = function (ctx) {
80
- return this.classPermits(ctx);
81
- };
82
- InterfacesPrettierVisitor.prototype.interfaceBody = function (ctx) {
83
- var joinedInterfaceMemberDeclaration = "";
84
- if (ctx.interfaceMemberDeclaration !== undefined) {
85
- var interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
86
- var separators = (0, printer_utils_1.getInterfaceBodyDeclarationsSeparator)(ctx.interfaceMemberDeclaration);
87
- joinedInterfaceMemberDeclaration = (0, printer_utils_1.rejectAndJoinSeps)(separators, interfaceMemberDeclaration);
88
- }
89
- return (0, printer_utils_1.putIntoBraces)(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
90
- };
91
- InterfacesPrettierVisitor.prototype.interfaceMemberDeclaration = function (ctx) {
92
- if (ctx.Semicolon) {
93
- return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]);
94
- }
95
- return this.visitSingle(ctx);
96
- };
97
- InterfacesPrettierVisitor.prototype.constantDeclaration = function (ctx) {
98
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.constantModifier);
99
- var firstAnnotations = this.mapVisit(modifiers[0]);
100
- var otherModifiers = this.mapVisit(modifiers[1]);
101
- var unannType = this.visit(ctx.unannType);
102
- var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
103
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
104
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
105
- (0, printer_utils_1.rejectAndJoin)(" ", [
106
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
107
- unannType,
108
- (0, printer_utils_1.rejectAndConcat)([variableDeclaratorList, ctx.Semicolon[0]])
109
- ])
110
- ]);
111
- };
112
- InterfacesPrettierVisitor.prototype.constantModifier = function (ctx) {
113
- if (ctx.annotation) {
114
- return this.visitSingle(ctx);
115
- }
116
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
117
- };
118
- InterfacesPrettierVisitor.prototype.interfaceMethodDeclaration = function (ctx) {
119
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.interfaceMethodModifier);
120
- var firstAnnotations = this.mapVisit(modifiers[0]);
121
- var otherModifiers = this.mapVisit(modifiers[1]);
122
- var methodHeader = this.visit(ctx.methodHeader);
123
- var methodBody = this.visit(ctx.methodBody);
124
- var separator = (0, printer_utils_1.isStatementEmptyStatement)(methodBody) ? "" : " ";
125
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
126
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
127
- (0, printer_utils_1.rejectAndJoin)(" ", [
128
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
129
- (0, printer_utils_1.rejectAndJoin)(separator, [methodHeader, methodBody])
130
- ])
131
- ]);
132
- };
133
- InterfacesPrettierVisitor.prototype.interfaceMethodModifier = function (ctx) {
134
- if (ctx.annotation) {
135
- return this.visitSingle(ctx);
136
- }
137
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
138
- };
139
- InterfacesPrettierVisitor.prototype.annotationTypeDeclaration = function (ctx) {
140
- var typeIdentifier = this.visit(ctx.typeIdentifier);
141
- var annotationTypeBody = this.visit(ctx.annotationTypeBody);
142
- return (0, printer_utils_1.rejectAndJoin)(" ", [
143
- (0, prettier_builder_1.concat)([ctx.At[0], ctx.Interface[0]]),
144
- typeIdentifier,
145
- annotationTypeBody
146
- ]);
147
- };
148
- InterfacesPrettierVisitor.prototype.annotationTypeBody = function (ctx) {
149
- var annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration);
150
- return (0, printer_utils_1.rejectAndJoin)(line, [
151
- (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(line, [
152
- ctx.LCurly[0],
153
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([line, line]), annotationTypeMemberDeclaration)
154
- ])),
155
- ctx.RCurly[0]
156
- ]);
157
- };
158
- InterfacesPrettierVisitor.prototype.annotationTypeMemberDeclaration = function (ctx) {
159
- if (ctx.Semicolon) {
160
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
161
- }
162
- return this.visitSingle(ctx);
163
- };
164
- InterfacesPrettierVisitor.prototype.annotationTypeElementDeclaration = function (ctx) {
165
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.annotationTypeElementModifier);
166
- var firstAnnotations = this.mapVisit(modifiers[0]);
167
- var otherModifiers = this.mapVisit(modifiers[1]);
168
- var unannType = this.visit(ctx.unannType);
169
- var identifier = ctx.Identifier[0];
170
- var dims = this.visit(ctx.dims);
171
- var defaultValue = ctx.defaultValue
172
- ? (0, prettier_builder_1.concat)([" ", this.visit(ctx.defaultValue)])
173
- : "";
174
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
175
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
176
- (0, printer_utils_1.rejectAndJoin)(" ", [
177
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
178
- unannType,
179
- (0, printer_utils_1.rejectAndConcat)([
180
- identifier,
181
- (0, prettier_builder_1.concat)([ctx.LBrace[0], ctx.RBrace[0]]),
182
- dims,
183
- defaultValue,
184
- ctx.Semicolon[0]
185
- ])
186
- ])
187
- ]);
188
- };
189
- InterfacesPrettierVisitor.prototype.annotationTypeElementModifier = function (ctx) {
190
- if (ctx.annotation) {
191
- return this.visitSingle(ctx);
192
- }
193
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
194
- };
195
- InterfacesPrettierVisitor.prototype.defaultValue = function (ctx) {
196
- var elementValue = this.visit(ctx.elementValue);
197
- return (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Default[0], elementValue]);
198
- };
199
- InterfacesPrettierVisitor.prototype.annotation = function (ctx) {
200
- var fqn = this.visit(ctx.typeName);
201
- var annoArgs = "";
202
- if (ctx.LBrace) {
203
- if (ctx.elementValuePairList) {
204
- annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
205
- }
206
- else if (ctx.elementValue) {
207
- annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
208
- }
209
- }
210
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ctx.At[0], fqn, annoArgs]));
211
- };
212
- InterfacesPrettierVisitor.prototype.elementValuePairList = function (ctx) {
213
- var elementValuePairs = this.mapVisit(ctx.elementValuePair);
214
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
215
- return (0, printer_utils_1.rejectAndJoinSeps)(commas, elementValuePairs);
216
- };
217
- InterfacesPrettierVisitor.prototype.elementValuePair = function (ctx) {
218
- var identifier = ctx.Identifier[0];
219
- var elementValue = this.visit(ctx.elementValue);
220
- return (0, printer_utils_1.rejectAndJoin)(" ", [identifier, ctx.Equals[0], elementValue]);
221
- };
222
- InterfacesPrettierVisitor.prototype.elementValue = function (ctx) {
223
- return this.visitSingle(ctx);
224
- };
225
- InterfacesPrettierVisitor.prototype.elementValueArrayInitializer = function (ctx) {
226
- var elementValueList = this.visit(ctx.elementValueList);
227
- return (0, printer_utils_1.printArrayList)({
228
- list: elementValueList,
229
- extraComma: ctx.Comma,
230
- LCurly: ctx.LCurly[0],
231
- RCurly: ctx.RCurly[0],
232
- trailingComma: this.prettierOptions.trailingComma
233
- });
234
- };
235
- InterfacesPrettierVisitor.prototype.elementValueList = function (ctx) {
236
- var elementValues = this.mapVisit(ctx.elementValue);
237
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
238
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([(0, printer_utils_1.rejectAndJoinSeps)(commas, elementValues)]));
239
- };
240
- InterfacesPrettierVisitor.prototype.identifyInterfaceBodyDeclarationType = function () {
241
- return "identifyInterfaceBodyDeclarationType";
242
- };
243
- InterfacesPrettierVisitor.prototype.identifyAnnotationBodyDeclarationType = function () {
244
- return "identifyAnnotationBodyDeclarationType";
245
- };
246
- InterfacesPrettierVisitor.prototype.isSimpleElementValueAnnotation = function () {
247
- return "isSimpleElementValueAnnotation";
248
- };
249
- return InterfacesPrettierVisitor;
250
- }(base_cst_printer_1.BaseCstPrettierPrinter));
251
- exports.InterfacesPrettierVisitor = InterfacesPrettierVisitor;
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.LexicalStructurePrettierVisitor = void 0;
28
- var format_comments_1 = require("./comments/format-comments");
29
- var prettier_builder_1 = require("./prettier-builder");
30
- var base_cst_printer_1 = require("../base-cst-printer");
31
- var doc_1 = require("prettier/doc");
32
- var hardline = doc_1.builders.hardline;
33
- var LexicalStructurePrettierVisitor = /** @class */ (function (_super) {
34
- __extends(LexicalStructurePrettierVisitor, _super);
35
- function LexicalStructurePrettierVisitor() {
36
- return _super !== null && _super.apply(this, arguments) || this;
37
- }
38
- LexicalStructurePrettierVisitor.prototype.literal = function (ctx) {
39
- if (ctx.TextBlock) {
40
- var lines = ctx.TextBlock[0].image.split("\n");
41
- var open_1 = lines.shift();
42
- var baseIndent_1 = Math.min.apply(Math, lines.map(function (line) { return line.search(/\S/); }).filter(function (indent) { return indent >= 0; }));
43
- return (0, prettier_builder_1.join)(hardline, __spreadArray([
44
- open_1
45
- ], lines.map(function (line) { return line.slice(baseIndent_1); }), true));
46
- }
47
- if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) {
48
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
49
- }
50
- return this.visitSingle(ctx);
51
- };
52
- LexicalStructurePrettierVisitor.prototype.integerLiteral = function (ctx) {
53
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
54
- };
55
- LexicalStructurePrettierVisitor.prototype.floatingPointLiteral = function (ctx) {
56
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
57
- };
58
- LexicalStructurePrettierVisitor.prototype.booleanLiteral = function (ctx) {
59
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
60
- };
61
- return LexicalStructurePrettierVisitor;
62
- }(base_cst_printer_1.BaseCstPrettierPrinter));
63
- exports.LexicalStructurePrettierVisitor = LexicalStructurePrettierVisitor;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.NamesPrettierVisitor = void 0;
19
- var printer_utils_1 = require("./printer-utils");
20
- var format_comments_1 = require("./comments/format-comments");
21
- var base_cst_printer_1 = require("../base-cst-printer");
22
- var NamesPrettierVisitor = /** @class */ (function (_super) {
23
- __extends(NamesPrettierVisitor, _super);
24
- function NamesPrettierVisitor() {
25
- return _super !== null && _super.apply(this, arguments) || this;
26
- }
27
- NamesPrettierVisitor.prototype.typeIdentifier = function (ctx) {
28
- return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]);
29
- };
30
- NamesPrettierVisitor.prototype.moduleName = function (ctx) {
31
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
32
- };
33
- NamesPrettierVisitor.prototype.packageName = function (ctx) {
34
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
35
- };
36
- NamesPrettierVisitor.prototype.typeName = function (ctx) {
37
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
38
- };
39
- NamesPrettierVisitor.prototype.expressionName = function (ctx) {
40
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
41
- };
42
- NamesPrettierVisitor.prototype.methodName = function (ctx) {
43
- return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]);
44
- };
45
- NamesPrettierVisitor.prototype.packageOrTypeName = function (ctx) {
46
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
47
- };
48
- NamesPrettierVisitor.prototype.ambiguousName = function (ctx) {
49
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
50
- };
51
- return NamesPrettierVisitor;
52
- }(base_cst_printer_1.BaseCstPrettierPrinter));
53
- exports.NamesPrettierVisitor = NamesPrettierVisitor;
@@ -1,198 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.PackagesAndModulesPrettierVisitor = void 0;
19
- var prettier_builder_1 = require("./prettier-builder");
20
- var format_comments_1 = require("./comments/format-comments");
21
- var printer_utils_1 = require("./printer-utils");
22
- var doc_1 = require("prettier/doc");
23
- var base_cst_printer_1 = require("../base-cst-printer");
24
- var utils_1 = require("../types/utils");
25
- var line = doc_1.builders.line, hardline = doc_1.builders.hardline, indent = doc_1.builders.indent, group = doc_1.builders.group;
26
- var PackagesAndModulesPrettierVisitor = /** @class */ (function (_super) {
27
- __extends(PackagesAndModulesPrettierVisitor, _super);
28
- function PackagesAndModulesPrettierVisitor() {
29
- return _super !== null && _super.apply(this, arguments) || this;
30
- }
31
- PackagesAndModulesPrettierVisitor.prototype.compilationUnit = function (ctx) {
32
- var compilationUnit = (0, utils_1.isOrdinaryCompilationUnitCtx)(ctx)
33
- ? ctx.ordinaryCompilationUnit
34
- : ctx.modularCompilationUnit;
35
- return (0, prettier_builder_1.concat)([this.visit(compilationUnit[0]), line]);
36
- };
37
- PackagesAndModulesPrettierVisitor.prototype.ordinaryCompilationUnit = function (ctx) {
38
- var packageDecl = this.visit(ctx.packageDeclaration);
39
- var sortedImportsDecl = (0, printer_utils_1.sortImports)(ctx.importDeclaration);
40
- var nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
41
- var staticImports = this.mapVisit(sortedImportsDecl.staticImports);
42
- var typesDecl = this.mapVisit(ctx.typeDeclaration);
43
- // TODO: utility to add item+line (or multiple lines) but only if an item exists
44
- return (0, printer_utils_1.rejectAndConcat)([
45
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), [
46
- packageDecl,
47
- (0, printer_utils_1.rejectAndJoin)(hardline, staticImports),
48
- (0, printer_utils_1.rejectAndJoin)(hardline, nonStaticImports),
49
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), typesDecl)
50
- ])
51
- ]);
52
- };
53
- PackagesAndModulesPrettierVisitor.prototype.modularCompilationUnit = function (ctx) {
54
- var sortedImportsDecl = (0, printer_utils_1.sortImports)(ctx.importDeclaration);
55
- var nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
56
- var staticImports = this.mapVisit(sortedImportsDecl.staticImports);
57
- var moduleDeclaration = this.visit(ctx.moduleDeclaration);
58
- return (0, printer_utils_1.rejectAndConcat)([
59
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), [
60
- (0, printer_utils_1.rejectAndJoin)(hardline, staticImports),
61
- (0, printer_utils_1.rejectAndJoin)(hardline, nonStaticImports),
62
- moduleDeclaration
63
- ])
64
- ]);
65
- };
66
- PackagesAndModulesPrettierVisitor.prototype.packageDeclaration = function (ctx) {
67
- var modifiers = this.mapVisit(ctx.packageModifier);
68
- var name = (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
69
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
70
- (0, printer_utils_1.rejectAndJoin)(hardline, modifiers),
71
- (0, prettier_builder_1.concat)([ctx.Package[0], " ", name, ctx.Semicolon[0]])
72
- ]);
73
- };
74
- PackagesAndModulesPrettierVisitor.prototype.packageModifier = function (ctx) {
75
- return this.visitSingle(ctx);
76
- };
77
- PackagesAndModulesPrettierVisitor.prototype.importDeclaration = function (ctx) {
78
- if (ctx.emptyStatement !== undefined) {
79
- return this.visit(ctx.emptyStatement);
80
- }
81
- var optionalStatic = ctx.Static ? ctx.Static[0] : "";
82
- var packageOrTypeName = this.visit(ctx.packageOrTypeName);
83
- var optionalDotStar = ctx.Dot ? (0, prettier_builder_1.concat)([ctx.Dot[0], ctx.Star[0]]) : "";
84
- return (0, printer_utils_1.rejectAndJoin)(" ", [
85
- ctx.Import[0],
86
- optionalStatic,
87
- (0, printer_utils_1.rejectAndConcat)([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]])
88
- ]);
89
- };
90
- PackagesAndModulesPrettierVisitor.prototype.typeDeclaration = function (ctx) {
91
- if (ctx.Semicolon) {
92
- return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]);
93
- }
94
- return this.visitSingle(ctx);
95
- };
96
- PackagesAndModulesPrettierVisitor.prototype.moduleDeclaration = function (ctx) {
97
- var annotations = this.mapVisit(ctx.annotation);
98
- var optionalOpen = ctx.Open ? ctx.Open[0] : "";
99
- var name = (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
100
- var moduleDirectives = this.mapVisit(ctx.moduleDirective);
101
- var content = (0, printer_utils_1.rejectAndJoinSeps)((0, printer_utils_1.getBlankLinesSeparator)(ctx.moduleDirective), moduleDirectives);
102
- return (0, printer_utils_1.rejectAndJoin)(" ", [
103
- (0, prettier_builder_1.join)(" ", annotations),
104
- optionalOpen,
105
- ctx.Module[0],
106
- name,
107
- (0, printer_utils_1.putIntoBraces)(content, hardline, ctx.LCurly[0], ctx.RCurly[0])
108
- ]);
109
- };
110
- PackagesAndModulesPrettierVisitor.prototype.moduleDirective = function (ctx) {
111
- return this.visitSingle(ctx);
112
- };
113
- PackagesAndModulesPrettierVisitor.prototype.requiresModuleDirective = function (ctx) {
114
- var modifiers = this.mapVisit(ctx.requiresModifier);
115
- var moduleName = this.visit(ctx.moduleName);
116
- return (0, printer_utils_1.rejectAndJoin)(" ", [
117
- ctx.Requires[0],
118
- (0, prettier_builder_1.join)(" ", modifiers),
119
- (0, prettier_builder_1.concat)([moduleName, ctx.Semicolon[0]])
120
- ]);
121
- };
122
- PackagesAndModulesPrettierVisitor.prototype.exportsModuleDirective = function (ctx) {
123
- var packageName = this.visit(ctx.packageName);
124
- var moduleNames = this.mapVisit(ctx.moduleName);
125
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
126
- if (ctx.To) {
127
- return group((0, printer_utils_1.rejectAndConcat)([
128
- indent((0, printer_utils_1.rejectAndJoin)(line, [
129
- (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Exports[0], packageName]),
130
- group(indent((0, printer_utils_1.rejectAndJoin)(line, [
131
- ctx.To[0],
132
- (0, printer_utils_1.rejectAndJoinSeps)(commas, moduleNames)
133
- ])))
134
- ])),
135
- ctx.Semicolon[0]
136
- ]));
137
- }
138
- return (0, printer_utils_1.rejectAndConcat)([
139
- (0, prettier_builder_1.concat)([ctx.Exports[0], " "]),
140
- packageName,
141
- ctx.Semicolon[0]
142
- ]);
143
- };
144
- PackagesAndModulesPrettierVisitor.prototype.opensModuleDirective = function (ctx) {
145
- var packageName = this.visit(ctx.packageName);
146
- var to = ctx.To ? ctx.To[0] : "";
147
- var moduleNames = this.mapVisit(ctx.moduleName);
148
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
149
- if (ctx.To) {
150
- return group((0, printer_utils_1.rejectAndConcat)([
151
- indent((0, printer_utils_1.rejectAndJoin)(line, [
152
- (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Opens[0], packageName]),
153
- group(indent((0, printer_utils_1.rejectAndJoin)(line, [
154
- ctx.To[0],
155
- (0, printer_utils_1.rejectAndJoinSeps)(commas, moduleNames)
156
- ])))
157
- ])),
158
- ctx.Semicolon[0]
159
- ]));
160
- }
161
- return (0, printer_utils_1.rejectAndConcat)([
162
- (0, prettier_builder_1.concat)([ctx.Opens[0], " "]),
163
- packageName,
164
- ctx.Semicolon[0]
165
- ]);
166
- };
167
- PackagesAndModulesPrettierVisitor.prototype.usesModuleDirective = function (ctx) {
168
- var typeName = this.visit(ctx.typeName);
169
- return (0, printer_utils_1.rejectAndConcat)([
170
- (0, prettier_builder_1.concat)([ctx.Uses[0], " "]),
171
- typeName,
172
- ctx.Semicolon[0]
173
- ]);
174
- };
175
- PackagesAndModulesPrettierVisitor.prototype.providesModuleDirective = function (ctx) {
176
- var firstTypeName = this.visit(ctx.typeName[0]);
177
- var otherTypeNames = this.mapVisit(ctx.typeName.slice(1));
178
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
179
- return group((0, printer_utils_1.rejectAndConcat)([
180
- indent((0, printer_utils_1.rejectAndJoin)(line, [
181
- (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Provides[0], firstTypeName]),
182
- group(indent((0, printer_utils_1.rejectAndJoin)(line, [
183
- ctx.With[0],
184
- (0, printer_utils_1.rejectAndJoinSeps)(commas, otherTypeNames)
185
- ])))
186
- ])),
187
- ctx.Semicolon[0]
188
- ]));
189
- };
190
- PackagesAndModulesPrettierVisitor.prototype.requiresModifier = function (ctx) {
191
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
192
- };
193
- PackagesAndModulesPrettierVisitor.prototype.isModuleCompilationUnit = function () {
194
- return "isModuleCompilationUnit";
195
- };
196
- return PackagesAndModulesPrettierVisitor;
197
- }(base_cst_printer_1.BaseCstPrettierPrinter));
198
- exports.PackagesAndModulesPrettierVisitor = PackagesAndModulesPrettierVisitor;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.indentIfBreak = exports.ifBreak = exports.dedent = exports.indent = exports.fill = exports.group = exports.join = exports.concat = void 0;
4
- var doc_1 = require("prettier/doc");
5
- var processComments = require("./comments/format-comments").processComments;
6
- /*
7
- * ------------------------------------------------------------------
8
- * Wraps the Prettier builder functions to print tokens with comments
9
- * ------------------------------------------------------------------
10
- */
11
- function concat(docs) {
12
- var concatenation = processComments(docs);
13
- if (!Array.isArray(docs)) {
14
- return "";
15
- }
16
- return concatenation;
17
- }
18
- exports.concat = concat;
19
- function join(sep, docs) {
20
- return doc_1.builders.join(processComments(sep), processComments(docs));
21
- }
22
- exports.join = join;
23
- function group(docs, opts) {
24
- var group = doc_1.builders.group(processComments(docs), opts);
25
- return group.contents === undefined ? "" : group;
26
- }
27
- exports.group = group;
28
- function fill(docs) {
29
- return doc_1.builders.fill(processComments(docs));
30
- }
31
- exports.fill = fill;
32
- function indent(doc) {
33
- var processedDoc = processComments(doc);
34
- if (processedDoc.length === 0) {
35
- return "";
36
- }
37
- return doc_1.builders.indent(processedDoc);
38
- }
39
- exports.indent = indent;
40
- function dedent(doc) {
41
- var processedDoc = processComments(doc);
42
- if (processedDoc.length === 0) {
43
- return "";
44
- }
45
- return doc_1.builders.dedent(processComments(doc));
46
- }
47
- exports.dedent = dedent;
48
- function ifBreak(breakContents, flatContents) {
49
- return doc_1.builders.ifBreak(processComments(breakContents), processComments(flatContents));
50
- }
51
- exports.ifBreak = ifBreak;
52
- function indentIfBreak(contents, opts) {
53
- return doc_1.builders.indentIfBreak(processComments(contents), opts);
54
- }
55
- exports.indentIfBreak = indentIfBreak;