prettier-plugin-java 2.4.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 +16 -21
- 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 +289 -356
- package/dist/printers/classes.js +451 -495
- 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 +378 -386
- 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
- package/dist/src/base-cst-printer.js +0 -77
- package/dist/src/cst-printer.js +0 -37
- package/dist/src/index.js +0 -67
- package/dist/src/options.js +0 -256
- package/dist/src/parser.js +0 -7
- package/dist/src/printer.js +0 -28
- package/dist/src/printers/arrays.js +0 -49
- package/dist/src/printers/blocks-and-statements.js +0 -493
- package/dist/src/printers/classes.js +0 -724
- package/dist/src/printers/comments/comments-utils.js +0 -29
- package/dist/src/printers/comments/format-comments.js +0 -187
- package/dist/src/printers/comments/handle-comments.js +0 -38
- package/dist/src/printers/expressions.js +0 -549
- package/dist/src/printers/interfaces.js +0 -251
- package/dist/src/printers/lexical-structure.js +0 -43
- package/dist/src/printers/names.js +0 -53
- package/dist/src/printers/packages-and-modules.js +0 -185
- package/dist/src/printers/prettier-builder.js +0 -47
- package/dist/src/printers/printer-utils.js +0 -577
- package/dist/src/printers/types-values-and-variables.js +0 -183
- package/dist/src/types/utils.js +0 -29
- package/dist/src/utils/expressions-utils.js +0 -29
- package/dist/src/utils/index.js +0 -10
- package/dist/src/utils/printArgumentListWithBraces.js +0 -21
- package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
- package/dist/test/babel-register.js +0 -3
- package/dist/test/repository-test/core-test.js +0 -12
- package/dist/test/repository-test/jhipster-1-test.js +0 -17
- package/dist/test/repository-test/jhipster-2-test.js +0 -16
- package/dist/test/test-utils.js +0 -215
- package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
- package/dist/test/unit-test/args/args-spec.js +0 -6
- package/dist/test/unit-test/assert/assert-spec.js +0 -6
- package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
- package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
- package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
- package/dist/test/unit-test/cast/cast-spec.js +0 -6
- package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
- package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
- package/dist/test/unit-test/comments/comments-spec.js +0 -14
- package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
- package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
- package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
- package/dist/test/unit-test/enum/enum-spec.js +0 -6
- package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
- package/dist/test/unit-test/for/for-spec.js +0 -6
- package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
- package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
- package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
- package/dist/test/unit-test/if/if-spec.js +0 -6
- package/dist/test/unit-test/indent/indent-spec.js +0 -6
- package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
- package/dist/test/unit-test/interface/interface-spec.js +0 -6
- package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
- package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
- package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
- package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
- package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
- package/dist/test/unit-test/modules/modules-spec.js +0 -6
- package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
- package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
- package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
- package/dist/test/unit-test/records/records-spec.js +0 -6
- package/dist/test/unit-test/return/return-spec.js +0 -6
- package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
- package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
- package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
- package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
- package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
- package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
- package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
- package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
- package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
- package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
- package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
- package/dist/test/unit-test/switch/switch-spec.js +0 -6
- package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
- package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
- package/dist/test/unit-test/throws/throws-spec.js +0 -6
- package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
- package/dist/test/unit-test/types/types-spec.js +0 -6
- package/dist/test/unit-test/variables/variables-spec.js +0 -6
- package/dist/test/unit-test/while/while-spec.js +0 -6
- package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
|
@@ -1,251 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
1
|
+
import { concat, group, indent } from "./prettier-builder.js";
|
|
2
|
+
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
+
import { displaySemicolon, getInterfaceBodyDeclarationsSeparator, isStatementEmptyStatement, printArrayList, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortModifiers } from "./printer-utils.js";
|
|
4
|
+
import { builders } from "prettier/doc";
|
|
5
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
6
|
+
const { line, softline, hardline } = builders;
|
|
7
|
+
export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
8
|
+
interfaceDeclaration(ctx) {
|
|
9
|
+
const modifiers = sortModifiers(ctx.interfaceModifier);
|
|
10
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
11
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
12
|
+
const declaration = ctx.normalInterfaceDeclaration
|
|
35
13
|
? this.visit(ctx.normalInterfaceDeclaration)
|
|
36
14
|
: this.visit(ctx.annotationTypeDeclaration);
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
return rejectAndJoin(hardline, [
|
|
16
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
17
|
+
rejectAndJoin(" ", [rejectAndJoin(" ", otherModifiers), declaration])
|
|
40
18
|
]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
}
|
|
20
|
+
normalInterfaceDeclaration(ctx) {
|
|
21
|
+
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
22
|
+
const typeParameters = this.visit(ctx.typeParameters);
|
|
23
|
+
const extendsInterfaces = this.visit(ctx.extendsInterfaces);
|
|
24
|
+
const optionalInterfacePermits = this.visit(ctx.interfacePermits);
|
|
25
|
+
const interfaceBody = this.visit(ctx.interfaceBody);
|
|
26
|
+
let extendsInterfacesPart = "";
|
|
49
27
|
if (extendsInterfaces) {
|
|
50
|
-
extendsInterfacesPart =
|
|
28
|
+
extendsInterfacesPart = indent(rejectAndConcat([softline, extendsInterfaces]));
|
|
51
29
|
}
|
|
52
|
-
|
|
30
|
+
let interfacePermits = "";
|
|
53
31
|
if (optionalInterfacePermits) {
|
|
54
|
-
interfacePermits =
|
|
32
|
+
interfacePermits = indent(rejectAndConcat([softline, optionalInterfacePermits]));
|
|
55
33
|
}
|
|
56
|
-
return
|
|
57
|
-
|
|
34
|
+
return rejectAndJoin(" ", [
|
|
35
|
+
group(rejectAndJoin(" ", [
|
|
58
36
|
ctx.Interface[0],
|
|
59
|
-
|
|
37
|
+
concat([typeIdentifier, typeParameters]),
|
|
60
38
|
extendsInterfacesPart,
|
|
61
39
|
interfacePermits
|
|
62
40
|
])),
|
|
63
41
|
interfaceBody
|
|
64
42
|
]);
|
|
65
|
-
}
|
|
66
|
-
|
|
43
|
+
}
|
|
44
|
+
interfaceModifier(ctx) {
|
|
67
45
|
if (ctx.annotation) {
|
|
68
46
|
return this.visitSingle(ctx);
|
|
69
47
|
}
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
48
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
49
|
+
}
|
|
50
|
+
extendsInterfaces(ctx) {
|
|
51
|
+
const interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
|
52
|
+
return group(rejectAndConcat([
|
|
75
53
|
ctx.Extends[0],
|
|
76
|
-
|
|
54
|
+
indent(rejectAndConcat([line, interfaceTypeList]))
|
|
77
55
|
]));
|
|
78
|
-
}
|
|
79
|
-
|
|
56
|
+
}
|
|
57
|
+
interfacePermits(ctx) {
|
|
80
58
|
return this.classPermits(ctx);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
59
|
+
}
|
|
60
|
+
interfaceBody(ctx) {
|
|
61
|
+
let joinedInterfaceMemberDeclaration = "";
|
|
84
62
|
if (ctx.interfaceMemberDeclaration !== undefined) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
joinedInterfaceMemberDeclaration =
|
|
63
|
+
const interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
|
|
64
|
+
const separators = getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration);
|
|
65
|
+
joinedInterfaceMemberDeclaration = rejectAndJoinSeps(separators, interfaceMemberDeclaration);
|
|
88
66
|
}
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
67
|
+
return putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
68
|
+
}
|
|
69
|
+
interfaceMemberDeclaration(ctx) {
|
|
92
70
|
if (ctx.Semicolon) {
|
|
93
|
-
return
|
|
71
|
+
return displaySemicolon(ctx.Semicolon[0]);
|
|
94
72
|
}
|
|
95
73
|
return this.visitSingle(ctx);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
74
|
+
}
|
|
75
|
+
constantDeclaration(ctx) {
|
|
76
|
+
const modifiers = sortModifiers(ctx.constantModifier);
|
|
77
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
78
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
79
|
+
const unannType = this.visit(ctx.unannType);
|
|
80
|
+
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
|
81
|
+
return rejectAndJoin(hardline, [
|
|
82
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
83
|
+
rejectAndJoin(" ", [
|
|
84
|
+
rejectAndJoin(" ", otherModifiers),
|
|
107
85
|
unannType,
|
|
108
|
-
|
|
86
|
+
rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
|
|
109
87
|
])
|
|
110
88
|
]);
|
|
111
|
-
}
|
|
112
|
-
|
|
89
|
+
}
|
|
90
|
+
constantModifier(ctx) {
|
|
113
91
|
if (ctx.annotation) {
|
|
114
92
|
return this.visitSingle(ctx);
|
|
115
93
|
}
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
94
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
95
|
+
}
|
|
96
|
+
interfaceMethodDeclaration(ctx) {
|
|
97
|
+
const modifiers = sortModifiers(ctx.interfaceMethodModifier);
|
|
98
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
99
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
100
|
+
const methodHeader = this.visit(ctx.methodHeader);
|
|
101
|
+
const methodBody = this.visit(ctx.methodBody);
|
|
102
|
+
const separator = isStatementEmptyStatement(methodBody) ? "" : " ";
|
|
103
|
+
return rejectAndJoin(hardline, [
|
|
104
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
105
|
+
rejectAndJoin(" ", [
|
|
106
|
+
rejectAndJoin(" ", otherModifiers),
|
|
107
|
+
rejectAndJoin(separator, [methodHeader, methodBody])
|
|
130
108
|
])
|
|
131
109
|
]);
|
|
132
|
-
}
|
|
133
|
-
|
|
110
|
+
}
|
|
111
|
+
interfaceMethodModifier(ctx) {
|
|
134
112
|
if (ctx.annotation) {
|
|
135
113
|
return this.visitSingle(ctx);
|
|
136
114
|
}
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return
|
|
143
|
-
|
|
115
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
116
|
+
}
|
|
117
|
+
annotationTypeDeclaration(ctx) {
|
|
118
|
+
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
119
|
+
const annotationTypeBody = this.visit(ctx.annotationTypeBody);
|
|
120
|
+
return rejectAndJoin(" ", [
|
|
121
|
+
concat([ctx.At[0], ctx.Interface[0]]),
|
|
144
122
|
typeIdentifier,
|
|
145
123
|
annotationTypeBody
|
|
146
124
|
]);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
|
|
125
|
+
}
|
|
126
|
+
annotationTypeBody(ctx) {
|
|
127
|
+
const annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration);
|
|
128
|
+
return rejectAndJoin(line, [
|
|
129
|
+
indent(rejectAndJoin(line, [
|
|
152
130
|
ctx.LCurly[0],
|
|
153
|
-
|
|
131
|
+
rejectAndJoin(concat([line, line]), annotationTypeMemberDeclaration)
|
|
154
132
|
])),
|
|
155
133
|
ctx.RCurly[0]
|
|
156
134
|
]);
|
|
157
|
-
}
|
|
158
|
-
|
|
135
|
+
}
|
|
136
|
+
annotationTypeMemberDeclaration(ctx) {
|
|
159
137
|
if (ctx.Semicolon) {
|
|
160
|
-
return
|
|
138
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
161
139
|
}
|
|
162
140
|
return this.visitSingle(ctx);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
?
|
|
141
|
+
}
|
|
142
|
+
annotationTypeElementDeclaration(ctx) {
|
|
143
|
+
const modifiers = sortModifiers(ctx.annotationTypeElementModifier);
|
|
144
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
145
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
146
|
+
const unannType = this.visit(ctx.unannType);
|
|
147
|
+
const identifier = ctx.Identifier[0];
|
|
148
|
+
const dims = this.visit(ctx.dims);
|
|
149
|
+
const defaultValue = ctx.defaultValue
|
|
150
|
+
? concat([" ", this.visit(ctx.defaultValue)])
|
|
173
151
|
: "";
|
|
174
|
-
return
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
152
|
+
return rejectAndJoin(hardline, [
|
|
153
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
154
|
+
rejectAndJoin(" ", [
|
|
155
|
+
rejectAndJoin(" ", otherModifiers),
|
|
178
156
|
unannType,
|
|
179
|
-
|
|
157
|
+
rejectAndConcat([
|
|
180
158
|
identifier,
|
|
181
|
-
|
|
159
|
+
concat([ctx.LBrace[0], ctx.RBrace[0]]),
|
|
182
160
|
dims,
|
|
183
161
|
defaultValue,
|
|
184
162
|
ctx.Semicolon[0]
|
|
185
163
|
])
|
|
186
164
|
])
|
|
187
165
|
]);
|
|
188
|
-
}
|
|
189
|
-
|
|
166
|
+
}
|
|
167
|
+
annotationTypeElementModifier(ctx) {
|
|
190
168
|
if (ctx.annotation) {
|
|
191
169
|
return this.visitSingle(ctx);
|
|
192
170
|
}
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
171
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
172
|
+
}
|
|
173
|
+
defaultValue(ctx) {
|
|
174
|
+
const elementValue = this.visit(ctx.elementValue);
|
|
175
|
+
return rejectAndJoin(" ", [ctx.Default[0], elementValue]);
|
|
176
|
+
}
|
|
177
|
+
annotation(ctx) {
|
|
178
|
+
const fqn = this.visit(ctx.typeName);
|
|
179
|
+
let annoArgs = "";
|
|
202
180
|
if (ctx.LBrace) {
|
|
203
181
|
if (ctx.elementValuePairList) {
|
|
204
|
-
annoArgs =
|
|
182
|
+
annoArgs = putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
|
205
183
|
}
|
|
206
184
|
else if (ctx.elementValue) {
|
|
207
|
-
annoArgs =
|
|
185
|
+
annoArgs = putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
|
208
186
|
}
|
|
209
187
|
}
|
|
210
|
-
return
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
|
-
|
|
188
|
+
return group(rejectAndConcat([ctx.At[0], fqn, annoArgs]));
|
|
189
|
+
}
|
|
190
|
+
elementValuePairList(ctx) {
|
|
191
|
+
const elementValuePairs = this.mapVisit(ctx.elementValuePair);
|
|
192
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
193
|
+
return rejectAndJoinSeps(commas, elementValuePairs);
|
|
194
|
+
}
|
|
195
|
+
elementValuePair(ctx) {
|
|
196
|
+
const identifier = ctx.Identifier[0];
|
|
197
|
+
const elementValue = this.visit(ctx.elementValue);
|
|
198
|
+
return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
|
|
199
|
+
}
|
|
200
|
+
elementValue(ctx) {
|
|
223
201
|
return this.visitSingle(ctx);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return
|
|
202
|
+
}
|
|
203
|
+
elementValueArrayInitializer(ctx) {
|
|
204
|
+
const elementValueList = this.visit(ctx.elementValueList);
|
|
205
|
+
return printArrayList({
|
|
228
206
|
list: elementValueList,
|
|
229
207
|
extraComma: ctx.Comma,
|
|
230
208
|
LCurly: ctx.LCurly[0],
|
|
231
209
|
RCurly: ctx.RCurly[0],
|
|
232
210
|
trailingComma: this.prettierOptions.trailingComma
|
|
233
211
|
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
|
|
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;
|
|
212
|
+
}
|
|
213
|
+
elementValueList(ctx) {
|
|
214
|
+
const elementValues = this.mapVisit(ctx.elementValue);
|
|
215
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
216
|
+
return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)]));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -1,63 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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) {
|
|
1
|
+
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
2
|
+
import { join } from "./prettier-builder.js";
|
|
3
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
+
import { builders } from "prettier/doc";
|
|
5
|
+
const { hardline } = builders;
|
|
6
|
+
export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter {
|
|
7
|
+
literal(ctx) {
|
|
39
8
|
if (ctx.TextBlock) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
9
|
+
const lines = ctx.TextBlock[0].image.split("\n");
|
|
10
|
+
const open = lines.shift();
|
|
11
|
+
const baseIndent = Math.min(...lines.map(line => line.search(/\S/)).filter(indent => indent >= 0));
|
|
12
|
+
return join(hardline, [
|
|
13
|
+
open,
|
|
14
|
+
...lines.map(line => line.slice(baseIndent))
|
|
15
|
+
]);
|
|
46
16
|
}
|
|
47
17
|
if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) {
|
|
48
|
-
return
|
|
18
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
49
19
|
}
|
|
50
20
|
return this.visitSingle(ctx);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
|
63
|
-
exports.LexicalStructurePrettierVisitor = LexicalStructurePrettierVisitor;
|
|
21
|
+
}
|
|
22
|
+
integerLiteral(ctx) {
|
|
23
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
24
|
+
}
|
|
25
|
+
floatingPointLiteral(ctx) {
|
|
26
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
27
|
+
}
|
|
28
|
+
booleanLiteral(ctx) {
|
|
29
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/printers/names.js
CHANGED
|
@@ -1,53 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
import { buildFqn } from "./printer-utils.js";
|
|
2
|
+
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
+
export class NamesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
5
|
+
typeIdentifier(ctx) {
|
|
6
|
+
return printTokenWithComments(ctx.Identifier[0]);
|
|
7
|
+
}
|
|
8
|
+
moduleName(ctx) {
|
|
9
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
10
|
+
}
|
|
11
|
+
packageName(ctx) {
|
|
12
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
13
|
+
}
|
|
14
|
+
typeName(ctx) {
|
|
15
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
16
|
+
}
|
|
17
|
+
expressionName(ctx) {
|
|
18
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
19
|
+
}
|
|
20
|
+
methodName(ctx) {
|
|
21
|
+
return printTokenWithComments(ctx.Identifier[0]);
|
|
22
|
+
}
|
|
23
|
+
packageOrTypeName(ctx) {
|
|
24
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
25
|
+
}
|
|
26
|
+
ambiguousName(ctx) {
|
|
27
|
+
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
28
|
+
}
|
|
29
|
+
}
|