prettier-plugin-java 2.5.0 → 2.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/LICENSE +1 -1
- package/dist/base-cst-printer.js +22 -44
- package/dist/cst-printer.js +19 -27
- package/dist/index.js +19 -20
- package/dist/options.js +13 -17
- package/dist/parser.js +2 -4
- package/dist/printer.js +3 -5
- package/dist/printers/arrays.js +17 -41
- package/dist/printers/blocks-and-statements.js +281 -326
- package/dist/printers/classes.js +449 -496
- package/dist/printers/comments/comments-utils.js +5 -13
- package/dist/printers/comments/format-comments.js +34 -50
- package/dist/printers/comments/handle-comments.js +17 -23
- package/dist/printers/expressions.js +377 -391
- package/dist/printers/interfaces.js +148 -181
- package/dist/printers/lexical-structure.js +26 -58
- package/dist/printers/names.js +29 -53
- package/dist/printers/packages-and-modules.js +116 -143
- package/dist/printers/prettier-builder.js +21 -31
- package/dist/printers/printer-utils.js +173 -221
- package/dist/printers/types-values-and-variables.js +111 -149
- package/dist/types/utils.js +6 -15
- package/dist/utils/expressions-utils.js +7 -11
- package/dist/utils/index.js +2 -12
- package/dist/utils/isEmptyDoc.js +2 -4
- package/dist/utils/printArgumentListWithBraces.js +29 -19
- package/dist/utils/printSingleLambdaInvocation.js +15 -17
- package/package.json +10 -13
|
@@ -1,198 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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)
|
|
1
|
+
import { concat, join } from "./prettier-builder.js";
|
|
2
|
+
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
+
import { buildFqn, displaySemicolon, getBlankLinesSeparator, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortImports } from "./printer-utils.js";
|
|
4
|
+
import { builders } from "prettier/doc";
|
|
5
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
6
|
+
import { isOrdinaryCompilationUnitCtx } from "../types/utils.js";
|
|
7
|
+
const { line, hardline, indent, group } = builders;
|
|
8
|
+
export class PackagesAndModulesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
9
|
+
compilationUnit(ctx) {
|
|
10
|
+
const compilationUnit = isOrdinaryCompilationUnitCtx(ctx)
|
|
33
11
|
? ctx.ordinaryCompilationUnit
|
|
34
12
|
: ctx.modularCompilationUnit;
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
13
|
+
return concat([this.visit(compilationUnit[0]), line]);
|
|
14
|
+
}
|
|
15
|
+
ordinaryCompilationUnit(ctx) {
|
|
16
|
+
const packageDecl = this.visit(ctx.packageDeclaration);
|
|
17
|
+
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
18
|
+
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
19
|
+
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
20
|
+
const typesDecl = this.mapVisit(ctx.typeDeclaration);
|
|
43
21
|
// TODO: utility to add item+line (or multiple lines) but only if an item exists
|
|
44
|
-
return
|
|
45
|
-
|
|
22
|
+
return rejectAndConcat([
|
|
23
|
+
rejectAndJoin(concat([hardline, hardline]), [
|
|
46
24
|
packageDecl,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
rejectAndJoin(hardline, staticImports),
|
|
26
|
+
rejectAndJoin(hardline, nonStaticImports),
|
|
27
|
+
rejectAndJoin(concat([hardline, hardline]), typesDecl)
|
|
50
28
|
])
|
|
51
29
|
]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
}
|
|
31
|
+
modularCompilationUnit(ctx) {
|
|
32
|
+
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
33
|
+
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
34
|
+
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
35
|
+
const moduleDeclaration = this.visit(ctx.moduleDeclaration);
|
|
36
|
+
return rejectAndConcat([
|
|
37
|
+
rejectAndJoin(concat([hardline, hardline]), [
|
|
38
|
+
rejectAndJoin(hardline, staticImports),
|
|
39
|
+
rejectAndJoin(hardline, nonStaticImports),
|
|
62
40
|
moduleDeclaration
|
|
63
41
|
])
|
|
64
42
|
]);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
}
|
|
44
|
+
packageDeclaration(ctx) {
|
|
45
|
+
const modifiers = this.mapVisit(ctx.packageModifier);
|
|
46
|
+
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
47
|
+
return rejectAndJoin(hardline, [
|
|
48
|
+
rejectAndJoin(hardline, modifiers),
|
|
49
|
+
concat([ctx.Package[0], " ", name, ctx.Semicolon[0]])
|
|
72
50
|
]);
|
|
73
|
-
}
|
|
74
|
-
|
|
51
|
+
}
|
|
52
|
+
packageModifier(ctx) {
|
|
75
53
|
return this.visitSingle(ctx);
|
|
76
|
-
}
|
|
77
|
-
|
|
54
|
+
}
|
|
55
|
+
importDeclaration(ctx) {
|
|
78
56
|
if (ctx.emptyStatement !== undefined) {
|
|
79
57
|
return this.visit(ctx.emptyStatement);
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
59
|
+
const optionalStatic = ctx.Static ? ctx.Static[0] : "";
|
|
60
|
+
const packageOrTypeName = this.visit(ctx.packageOrTypeName);
|
|
61
|
+
const optionalDotStar = ctx.Dot ? concat([ctx.Dot[0], ctx.Star[0]]) : "";
|
|
62
|
+
return rejectAndJoin(" ", [
|
|
85
63
|
ctx.Import[0],
|
|
86
64
|
optionalStatic,
|
|
87
|
-
|
|
65
|
+
rejectAndConcat([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]])
|
|
88
66
|
]);
|
|
89
|
-
}
|
|
90
|
-
|
|
67
|
+
}
|
|
68
|
+
typeDeclaration(ctx) {
|
|
91
69
|
if (ctx.Semicolon) {
|
|
92
|
-
return
|
|
70
|
+
return displaySemicolon(ctx.Semicolon[0]);
|
|
93
71
|
}
|
|
94
72
|
return this.visitSingle(ctx);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
|
|
73
|
+
}
|
|
74
|
+
moduleDeclaration(ctx) {
|
|
75
|
+
const annotations = this.mapVisit(ctx.annotation);
|
|
76
|
+
const optionalOpen = ctx.Open ? ctx.Open[0] : "";
|
|
77
|
+
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
78
|
+
const moduleDirectives = this.mapVisit(ctx.moduleDirective);
|
|
79
|
+
const content = rejectAndJoinSeps(getBlankLinesSeparator(ctx.moduleDirective), moduleDirectives);
|
|
80
|
+
return rejectAndJoin(" ", [
|
|
81
|
+
join(" ", annotations),
|
|
104
82
|
optionalOpen,
|
|
105
83
|
ctx.Module[0],
|
|
106
84
|
name,
|
|
107
|
-
|
|
85
|
+
putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0])
|
|
108
86
|
]);
|
|
109
|
-
}
|
|
110
|
-
|
|
87
|
+
}
|
|
88
|
+
moduleDirective(ctx) {
|
|
111
89
|
return this.visitSingle(ctx);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return
|
|
90
|
+
}
|
|
91
|
+
requiresModuleDirective(ctx) {
|
|
92
|
+
const modifiers = this.mapVisit(ctx.requiresModifier);
|
|
93
|
+
const moduleName = this.visit(ctx.moduleName);
|
|
94
|
+
return rejectAndJoin(" ", [
|
|
117
95
|
ctx.Requires[0],
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
join(" ", modifiers),
|
|
97
|
+
concat([moduleName, ctx.Semicolon[0]])
|
|
120
98
|
]);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
99
|
+
}
|
|
100
|
+
exportsModuleDirective(ctx) {
|
|
101
|
+
const packageName = this.visit(ctx.packageName);
|
|
102
|
+
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
103
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
126
104
|
if (ctx.To) {
|
|
127
|
-
return group(
|
|
128
|
-
indent(
|
|
129
|
-
|
|
130
|
-
group(indent(
|
|
105
|
+
return group(rejectAndConcat([
|
|
106
|
+
indent(rejectAndJoin(line, [
|
|
107
|
+
rejectAndJoin(" ", [ctx.Exports[0], packageName]),
|
|
108
|
+
group(indent(rejectAndJoin(line, [
|
|
131
109
|
ctx.To[0],
|
|
132
|
-
|
|
110
|
+
rejectAndJoinSeps(commas, moduleNames)
|
|
133
111
|
])))
|
|
134
112
|
])),
|
|
135
113
|
ctx.Semicolon[0]
|
|
136
114
|
]));
|
|
137
115
|
}
|
|
138
|
-
return
|
|
139
|
-
|
|
116
|
+
return rejectAndConcat([
|
|
117
|
+
concat([ctx.Exports[0], " "]),
|
|
140
118
|
packageName,
|
|
141
119
|
ctx.Semicolon[0]
|
|
142
120
|
]);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
121
|
+
}
|
|
122
|
+
opensModuleDirective(ctx) {
|
|
123
|
+
const packageName = this.visit(ctx.packageName);
|
|
124
|
+
const to = ctx.To ? ctx.To[0] : "";
|
|
125
|
+
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
126
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
149
127
|
if (ctx.To) {
|
|
150
|
-
return group(
|
|
151
|
-
indent(
|
|
152
|
-
|
|
153
|
-
group(indent(
|
|
128
|
+
return group(rejectAndConcat([
|
|
129
|
+
indent(rejectAndJoin(line, [
|
|
130
|
+
rejectAndJoin(" ", [ctx.Opens[0], packageName]),
|
|
131
|
+
group(indent(rejectAndJoin(line, [
|
|
154
132
|
ctx.To[0],
|
|
155
|
-
|
|
133
|
+
rejectAndJoinSeps(commas, moduleNames)
|
|
156
134
|
])))
|
|
157
135
|
])),
|
|
158
136
|
ctx.Semicolon[0]
|
|
159
137
|
]));
|
|
160
138
|
}
|
|
161
|
-
return
|
|
162
|
-
|
|
139
|
+
return rejectAndConcat([
|
|
140
|
+
concat([ctx.Opens[0], " "]),
|
|
163
141
|
packageName,
|
|
164
142
|
ctx.Semicolon[0]
|
|
165
143
|
]);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return
|
|
170
|
-
|
|
144
|
+
}
|
|
145
|
+
usesModuleDirective(ctx) {
|
|
146
|
+
const typeName = this.visit(ctx.typeName);
|
|
147
|
+
return rejectAndConcat([
|
|
148
|
+
concat([ctx.Uses[0], " "]),
|
|
171
149
|
typeName,
|
|
172
150
|
ctx.Semicolon[0]
|
|
173
151
|
]);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return group(
|
|
180
|
-
indent(
|
|
181
|
-
|
|
182
|
-
group(indent(
|
|
152
|
+
}
|
|
153
|
+
providesModuleDirective(ctx) {
|
|
154
|
+
const firstTypeName = this.visit(ctx.typeName[0]);
|
|
155
|
+
const otherTypeNames = this.mapVisit(ctx.typeName.slice(1));
|
|
156
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
157
|
+
return group(rejectAndConcat([
|
|
158
|
+
indent(rejectAndJoin(line, [
|
|
159
|
+
rejectAndJoin(" ", [ctx.Provides[0], firstTypeName]),
|
|
160
|
+
group(indent(rejectAndJoin(line, [
|
|
183
161
|
ctx.With[0],
|
|
184
|
-
|
|
162
|
+
rejectAndJoinSeps(commas, otherTypeNames)
|
|
185
163
|
])))
|
|
186
164
|
])),
|
|
187
165
|
ctx.Semicolon[0]
|
|
188
166
|
]));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return "isModuleCompilationUnit";
|
|
195
|
-
};
|
|
196
|
-
return PackagesAndModulesPrettierVisitor;
|
|
197
|
-
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
|
198
|
-
exports.PackagesAndModulesPrettierVisitor = PackagesAndModulesPrettierVisitor;
|
|
167
|
+
}
|
|
168
|
+
requiresModifier(ctx) {
|
|
169
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,55 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var doc_1 = require("prettier/doc");
|
|
5
|
-
var processComments = require("./comments/format-comments").processComments;
|
|
1
|
+
import { builders } from "prettier/doc";
|
|
2
|
+
import * as formatComments from "./comments/format-comments.js";
|
|
3
|
+
const processComments = formatComments.processComments;
|
|
6
4
|
/*
|
|
7
5
|
* ------------------------------------------------------------------
|
|
8
6
|
* Wraps the Prettier builder functions to print tokens with comments
|
|
9
7
|
* ------------------------------------------------------------------
|
|
10
8
|
*/
|
|
11
|
-
function concat(docs) {
|
|
12
|
-
|
|
9
|
+
export function concat(docs) {
|
|
10
|
+
const concatenation = processComments(docs);
|
|
13
11
|
if (!Array.isArray(docs)) {
|
|
14
12
|
return "";
|
|
15
13
|
}
|
|
16
14
|
return concatenation;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return doc_1.builders.join(processComments(sep), processComments(docs));
|
|
16
|
+
export function join(sep, docs) {
|
|
17
|
+
return builders.join(processComments(sep), processComments(docs));
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var group = doc_1.builders.group(processComments(docs), opts);
|
|
19
|
+
export function group(docs, opts) {
|
|
20
|
+
const group = builders.group(processComments(docs), opts);
|
|
25
21
|
return group.contents === undefined ? "" : group;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return doc_1.builders.fill(processComments(docs));
|
|
23
|
+
export function fill(docs) {
|
|
24
|
+
return builders.fill(processComments(docs));
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var processedDoc = processComments(doc);
|
|
26
|
+
export function indent(doc) {
|
|
27
|
+
const processedDoc = processComments(doc);
|
|
34
28
|
if (processedDoc.length === 0) {
|
|
35
29
|
return "";
|
|
36
30
|
}
|
|
37
|
-
return
|
|
31
|
+
return builders.indent(processedDoc);
|
|
38
32
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var processedDoc = processComments(doc);
|
|
33
|
+
export function dedent(doc) {
|
|
34
|
+
const processedDoc = processComments(doc);
|
|
42
35
|
if (processedDoc.length === 0) {
|
|
43
36
|
return "";
|
|
44
37
|
}
|
|
45
|
-
return
|
|
38
|
+
return builders.dedent(processComments(doc));
|
|
46
39
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return doc_1.builders.ifBreak(processComments(breakContents), processComments(flatContents));
|
|
40
|
+
export function ifBreak(breakContents, flatContents) {
|
|
41
|
+
return builders.ifBreak(processComments(breakContents), processComments(flatContents));
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return doc_1.builders.indentIfBreak(processComments(contents), opts);
|
|
43
|
+
export function indentIfBreak(contents, opts) {
|
|
44
|
+
return builders.indentIfBreak(processComments(contents), opts);
|
|
54
45
|
}
|
|
55
|
-
exports.indentIfBreak = indentIfBreak;
|