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
package/dist/printers/classes.js
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.ClassesPrettierVisitor = void 0;
|
|
33
|
-
var forEach_1 = __importDefault(require("lodash/forEach"));
|
|
34
|
-
var printer_utils_1 = require("./printer-utils");
|
|
35
|
-
var prettier_builder_1 = require("./prettier-builder");
|
|
36
|
-
var format_comments_1 = require("./comments/format-comments");
|
|
37
|
-
var comments_utils_1 = require("./comments/comments-utils");
|
|
38
|
-
var doc_1 = require("prettier/doc");
|
|
39
|
-
var base_cst_printer_1 = require("../base-cst-printer");
|
|
40
|
-
var utils_1 = require("../types/utils");
|
|
41
|
-
var utils_2 = require("../utils");
|
|
42
|
-
var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline, lineSuffixBoundary = doc_1.builders.lineSuffixBoundary;
|
|
43
|
-
var ClassesPrettierVisitor = /** @class */ (function (_super) {
|
|
44
|
-
__extends(ClassesPrettierVisitor, _super);
|
|
45
|
-
function ClassesPrettierVisitor() {
|
|
46
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
47
|
-
}
|
|
48
|
-
ClassesPrettierVisitor.prototype.classDeclaration = function (ctx) {
|
|
49
|
-
var modifiers = (0, printer_utils_1.sortModifiers)(ctx.classModifier);
|
|
50
|
-
var firstAnnotations = this.mapVisit(modifiers[0]);
|
|
51
|
-
var otherModifiers = this.mapVisit(modifiers[1]);
|
|
52
|
-
var classCST;
|
|
1
|
+
import forEach from "lodash/forEach.js";
|
|
2
|
+
import { displaySemicolon, getBlankLinesSeparator, getClassBodyDeclarationsSeparator, isStatementEmptyStatement, putIntoBraces, reject, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortClassTypeChildren, sortModifiers } from "./printer-utils.js";
|
|
3
|
+
import { concat, group, indent, join, indentIfBreak } from "./prettier-builder.js";
|
|
4
|
+
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
5
|
+
import { hasLeadingComments, hasLeadingLineComments } from "./comments/comments-utils.js";
|
|
6
|
+
import { builders } from "prettier/doc";
|
|
7
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
8
|
+
import { isAnnotationCstNode, isTypeArgumentsCstNode } from "../types/utils.js";
|
|
9
|
+
import { printArgumentListWithBraces } from "../utils/index.js";
|
|
10
|
+
const { line, softline, hardline, lineSuffixBoundary } = builders;
|
|
11
|
+
export class ClassesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
12
|
+
classDeclaration(ctx) {
|
|
13
|
+
const modifiers = sortModifiers(ctx.classModifier);
|
|
14
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
15
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
16
|
+
let classCST;
|
|
53
17
|
if (ctx.normalClassDeclaration !== undefined) {
|
|
54
18
|
classCST = ctx.normalClassDeclaration;
|
|
55
19
|
}
|
|
@@ -59,34 +23,34 @@ var ClassesPrettierVisitor = /** @class */ (function (_super) {
|
|
|
59
23
|
else {
|
|
60
24
|
classCST = ctx.recordDeclaration;
|
|
61
25
|
}
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
26
|
+
const classDoc = this.visit(classCST);
|
|
27
|
+
return rejectAndJoin(hardline, [
|
|
28
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
29
|
+
rejectAndJoin(" ", [join(" ", otherModifiers), classDoc])
|
|
66
30
|
]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
31
|
+
}
|
|
32
|
+
normalClassDeclaration(ctx) {
|
|
33
|
+
const name = this.visit(ctx.typeIdentifier);
|
|
34
|
+
const optionalTypeParams = this.visit(ctx.typeParameters);
|
|
35
|
+
const optionalSuperClasses = this.visit(ctx.superclass);
|
|
36
|
+
const optionalSuperInterfaces = this.visit(ctx.superinterfaces);
|
|
37
|
+
const optionalClassPermits = this.visit(ctx.classPermits);
|
|
38
|
+
const body = this.visit(ctx.classBody, { isNormalClassDeclaration: true });
|
|
39
|
+
let superClassesPart = "";
|
|
76
40
|
if (optionalSuperClasses) {
|
|
77
|
-
superClassesPart =
|
|
41
|
+
superClassesPart = indent(rejectAndConcat([line, optionalSuperClasses]));
|
|
78
42
|
}
|
|
79
|
-
|
|
43
|
+
let superInterfacesPart = "";
|
|
80
44
|
if (optionalSuperInterfaces) {
|
|
81
|
-
superInterfacesPart =
|
|
45
|
+
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces]));
|
|
82
46
|
}
|
|
83
|
-
|
|
47
|
+
let classPermits = "";
|
|
84
48
|
if (optionalClassPermits) {
|
|
85
|
-
classPermits =
|
|
49
|
+
classPermits = indent(rejectAndConcat([line, optionalClassPermits]));
|
|
86
50
|
}
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
51
|
+
return rejectAndJoin(" ", [
|
|
52
|
+
group(rejectAndConcat([
|
|
53
|
+
rejectAndJoin(" ", [ctx.Class[0], name]),
|
|
90
54
|
optionalTypeParams,
|
|
91
55
|
superClassesPart,
|
|
92
56
|
superInterfacesPart,
|
|
@@ -94,114 +58,114 @@ var ClassesPrettierVisitor = /** @class */ (function (_super) {
|
|
|
94
58
|
])),
|
|
95
59
|
body
|
|
96
60
|
]);
|
|
97
|
-
}
|
|
98
|
-
|
|
61
|
+
}
|
|
62
|
+
classModifier(ctx) {
|
|
99
63
|
if (ctx.annotation) {
|
|
100
64
|
return this.visit(ctx.annotation);
|
|
101
65
|
}
|
|
102
66
|
// public | protected | private | ...
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
67
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
68
|
+
}
|
|
69
|
+
typeParameters(ctx) {
|
|
70
|
+
const typeParameterList = this.visit(ctx.typeParameterList);
|
|
71
|
+
return putIntoBraces(typeParameterList, softline, ctx.Less[0], ctx.Greater[0]);
|
|
72
|
+
}
|
|
73
|
+
typeParameterList(ctx) {
|
|
74
|
+
const typeParameter = this.mapVisit(ctx.typeParameter);
|
|
75
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
76
|
+
return group(rejectAndJoinSeps(commas, typeParameter));
|
|
77
|
+
}
|
|
78
|
+
superclass(ctx) {
|
|
79
|
+
return join(" ", [ctx.Extends[0], this.visit(ctx.classType)]);
|
|
80
|
+
}
|
|
81
|
+
superinterfaces(ctx) {
|
|
82
|
+
const interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
|
83
|
+
return group(rejectAndConcat([
|
|
120
84
|
ctx.Implements[0],
|
|
121
|
-
|
|
85
|
+
indent(rejectAndConcat([line, interfaceTypeList]))
|
|
122
86
|
]));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
87
|
+
}
|
|
88
|
+
classPermits(ctx) {
|
|
89
|
+
const typeNames = this.mapVisit(ctx.typeName);
|
|
90
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
91
|
+
return group(rejectAndConcat([
|
|
128
92
|
ctx.Permits[0],
|
|
129
|
-
|
|
93
|
+
indent(rejectAndConcat([line, group(rejectAndJoinSeps(commas, typeNames))]))
|
|
130
94
|
]));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
95
|
+
}
|
|
96
|
+
interfaceTypeList(ctx) {
|
|
97
|
+
const interfaceType = this.mapVisit(ctx.interfaceType);
|
|
98
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
99
|
+
return group(rejectAndJoinSeps(commas, interfaceType));
|
|
100
|
+
}
|
|
101
|
+
classBody(ctx, param) {
|
|
102
|
+
let content = "";
|
|
139
103
|
if (ctx.classBodyDeclaration !== undefined) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
content =
|
|
104
|
+
const classBodyDeclsVisited = reject(this.mapVisit(ctx.classBodyDeclaration));
|
|
105
|
+
const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
|
|
106
|
+
content = rejectAndJoinSeps(separators, classBodyDeclsVisited);
|
|
143
107
|
// edge case when we have SemiColons
|
|
144
|
-
|
|
145
|
-
ctx.classBodyDeclaration.forEach(
|
|
108
|
+
let shouldHardline = false;
|
|
109
|
+
ctx.classBodyDeclaration.forEach(elt => {
|
|
146
110
|
if ((elt.children.classMemberDeclaration &&
|
|
147
111
|
!elt.children.classMemberDeclaration[0].children.Semicolon) ||
|
|
148
112
|
elt.children.constructorDeclaration) {
|
|
149
|
-
|
|
113
|
+
shouldHardline = true;
|
|
150
114
|
}
|
|
151
115
|
});
|
|
152
116
|
if ((ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
|
|
153
117
|
ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
|
|
154
|
-
|
|
118
|
+
shouldHardline &&
|
|
155
119
|
param &&
|
|
156
120
|
param.isNormalClassDeclaration) {
|
|
157
|
-
content =
|
|
121
|
+
content = rejectAndConcat([hardline, content]);
|
|
158
122
|
}
|
|
159
123
|
}
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
|
|
124
|
+
return putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
125
|
+
}
|
|
126
|
+
classBodyDeclaration(ctx) {
|
|
163
127
|
return this.visitSingle(ctx);
|
|
164
|
-
}
|
|
165
|
-
|
|
128
|
+
}
|
|
129
|
+
classMemberDeclaration(ctx) {
|
|
166
130
|
if (ctx.Semicolon) {
|
|
167
|
-
return
|
|
131
|
+
return displaySemicolon(ctx.Semicolon[0]);
|
|
168
132
|
}
|
|
169
133
|
return this.visitSingle(ctx);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
134
|
+
}
|
|
135
|
+
fieldDeclaration(ctx) {
|
|
136
|
+
const modifiers = sortModifiers(ctx.fieldModifier);
|
|
137
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
138
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
139
|
+
const unannType = this.visit(ctx.unannType);
|
|
140
|
+
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
|
141
|
+
return rejectAndJoin(hardline, [
|
|
142
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
143
|
+
rejectAndJoin(" ", [
|
|
144
|
+
rejectAndJoin(" ", otherModifiers),
|
|
181
145
|
unannType,
|
|
182
|
-
|
|
146
|
+
concat([variableDeclaratorList, ctx.Semicolon[0]])
|
|
183
147
|
])
|
|
184
148
|
]);
|
|
185
|
-
}
|
|
186
|
-
|
|
149
|
+
}
|
|
150
|
+
fieldModifier(ctx) {
|
|
187
151
|
if (ctx.annotation) {
|
|
188
152
|
return this.visit(ctx.annotation);
|
|
189
153
|
}
|
|
190
154
|
// public | protected | private | ...
|
|
191
|
-
return
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
155
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
156
|
+
}
|
|
157
|
+
variableDeclaratorList(ctx) {
|
|
158
|
+
const variableDeclarators = this.mapVisit(ctx.variableDeclarator);
|
|
159
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : [];
|
|
160
|
+
return rejectAndJoinSeps(commas, variableDeclarators);
|
|
161
|
+
}
|
|
162
|
+
variableDeclarator(ctx) {
|
|
163
|
+
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
|
200
164
|
if (ctx.Equals) {
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
return
|
|
204
|
-
|
|
165
|
+
const variableInitializer = this.visit(ctx.variableInitializer);
|
|
166
|
+
if (hasLeadingLineComments(ctx.variableInitializer[0])) {
|
|
167
|
+
return group(indent(rejectAndJoin(hardline, [
|
|
168
|
+
rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
|
|
205
169
|
variableInitializer
|
|
206
170
|
])));
|
|
207
171
|
}
|
|
@@ -216,527 +180,519 @@ var ClassesPrettierVisitor = /** @class */ (function (_super) {
|
|
|
216
180
|
.ternaryExpression !== undefined &&
|
|
217
181
|
ctx.variableInitializer[0].children.expression[0].children
|
|
218
182
|
.ternaryExpression[0].children.QuestionMark !== undefined)) {
|
|
219
|
-
|
|
220
|
-
return
|
|
221
|
-
|
|
183
|
+
const groupId = Symbol("assignment");
|
|
184
|
+
return group([
|
|
185
|
+
group(variableDeclaratorId),
|
|
222
186
|
" ",
|
|
223
187
|
ctx.Equals[0],
|
|
224
|
-
|
|
188
|
+
group(indent(line), { id: groupId }),
|
|
225
189
|
lineSuffixBoundary,
|
|
226
|
-
|
|
190
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
227
191
|
]);
|
|
228
192
|
}
|
|
229
193
|
if (ctx.variableInitializer[0].children.expression[0].children
|
|
230
194
|
.ternaryExpression !== undefined) {
|
|
231
|
-
|
|
195
|
+
const unaryExpressions = ctx.variableInitializer[0].children.expression[0].children
|
|
232
196
|
.ternaryExpression[0].children.binaryExpression[0].children
|
|
233
197
|
.unaryExpression;
|
|
234
|
-
|
|
198
|
+
const firstPrimary = unaryExpressions[0].children.primary[0];
|
|
235
199
|
// Cast Expression
|
|
236
200
|
if (firstPrimary.children.primaryPrefix[0].children.castExpression !==
|
|
237
201
|
undefined &&
|
|
238
202
|
unaryExpressions.length === 1) {
|
|
239
|
-
|
|
240
|
-
return
|
|
241
|
-
|
|
203
|
+
const groupId = Symbol("assignment");
|
|
204
|
+
return group([
|
|
205
|
+
group(variableDeclaratorId),
|
|
242
206
|
" ",
|
|
243
207
|
ctx.Equals[0],
|
|
244
|
-
|
|
208
|
+
group(indent(line), { id: groupId }),
|
|
245
209
|
lineSuffixBoundary,
|
|
246
|
-
|
|
210
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
247
211
|
]);
|
|
248
212
|
}
|
|
249
213
|
// New Expression
|
|
250
214
|
if (firstPrimary.children.primaryPrefix[0].children.newExpression !==
|
|
251
215
|
undefined) {
|
|
252
|
-
|
|
253
|
-
return
|
|
254
|
-
|
|
216
|
+
const groupId = Symbol("assignment");
|
|
217
|
+
return group([
|
|
218
|
+
group(variableDeclaratorId),
|
|
255
219
|
" ",
|
|
256
220
|
ctx.Equals[0],
|
|
257
|
-
|
|
221
|
+
group(indent(line), { id: groupId }),
|
|
258
222
|
lineSuffixBoundary,
|
|
259
|
-
|
|
223
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
260
224
|
]);
|
|
261
225
|
}
|
|
262
226
|
// Method Invocation
|
|
263
|
-
|
|
227
|
+
const isMethodInvocation = firstPrimary.children.primarySuffix !== undefined &&
|
|
264
228
|
firstPrimary.children.primarySuffix[0].children
|
|
265
229
|
.methodInvocationSuffix !== undefined;
|
|
266
|
-
|
|
230
|
+
const isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children
|
|
267
231
|
.ternaryExpression[0].children.binaryExpression[0].children
|
|
268
232
|
.unaryExpression.length === 1;
|
|
269
|
-
|
|
233
|
+
const isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression;
|
|
270
234
|
if (isUniqueMethodInvocation) {
|
|
271
|
-
|
|
272
|
-
return
|
|
273
|
-
|
|
235
|
+
const groupId = Symbol("assignment");
|
|
236
|
+
return group([
|
|
237
|
+
group(variableDeclaratorId),
|
|
274
238
|
" ",
|
|
275
239
|
ctx.Equals[0],
|
|
276
|
-
|
|
240
|
+
group(indent(line), { id: groupId }),
|
|
277
241
|
lineSuffixBoundary,
|
|
278
|
-
|
|
242
|
+
indentIfBreak(variableInitializer, { groupId })
|
|
279
243
|
]);
|
|
280
244
|
}
|
|
281
245
|
}
|
|
282
|
-
return
|
|
283
|
-
|
|
246
|
+
return group(indent(rejectAndJoin(line, [
|
|
247
|
+
rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
|
|
284
248
|
variableInitializer
|
|
285
249
|
])));
|
|
286
250
|
}
|
|
287
251
|
return variableDeclaratorId;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
252
|
+
}
|
|
253
|
+
variableDeclaratorId(ctx) {
|
|
254
|
+
if (ctx.Underscore) {
|
|
255
|
+
return printTokenWithComments(ctx.Underscore[0]);
|
|
256
|
+
}
|
|
257
|
+
const identifier = ctx.Identifier[0];
|
|
258
|
+
const dims = this.visit(ctx.dims);
|
|
259
|
+
return rejectAndConcat([identifier, dims]);
|
|
260
|
+
}
|
|
261
|
+
variableInitializer(ctx) {
|
|
295
262
|
return this.visitSingle(ctx);
|
|
296
|
-
}
|
|
297
|
-
|
|
263
|
+
}
|
|
264
|
+
unannType(ctx) {
|
|
298
265
|
return this.visitSingle(ctx);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return
|
|
304
|
-
}
|
|
305
|
-
|
|
266
|
+
}
|
|
267
|
+
unannPrimitiveTypeWithOptionalDimsSuffix(ctx) {
|
|
268
|
+
const unannPrimitiveType = this.visit(ctx.unannPrimitiveType);
|
|
269
|
+
const dims = this.visit(ctx.dims);
|
|
270
|
+
return rejectAndConcat([unannPrimitiveType, dims]);
|
|
271
|
+
}
|
|
272
|
+
unannPrimitiveType(ctx) {
|
|
306
273
|
if (ctx.numericType) {
|
|
307
274
|
return this.visitSingle(ctx);
|
|
308
275
|
}
|
|
309
|
-
return
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return
|
|
315
|
-
}
|
|
316
|
-
|
|
276
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
277
|
+
}
|
|
278
|
+
unannReferenceType(ctx) {
|
|
279
|
+
const unannClassOrInterfaceType = this.visit(ctx.unannClassOrInterfaceType);
|
|
280
|
+
const dims = this.visit(ctx.dims);
|
|
281
|
+
return rejectAndConcat([unannClassOrInterfaceType, dims]);
|
|
282
|
+
}
|
|
283
|
+
unannClassOrInterfaceType(ctx) {
|
|
317
284
|
return this.visit(ctx.unannClassType);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
segments.push((0, printer_utils_1.rejectAndConcat)(currentSegment));
|
|
285
|
+
}
|
|
286
|
+
unannClassType(ctx) {
|
|
287
|
+
const tokens = sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier);
|
|
288
|
+
const segments = [];
|
|
289
|
+
let currentSegment = [];
|
|
290
|
+
forEach(tokens, (token, i) => {
|
|
291
|
+
if (isTypeArgumentsCstNode(token)) {
|
|
292
|
+
currentSegment.push(this.visit([token]));
|
|
293
|
+
segments.push(rejectAndConcat(currentSegment));
|
|
328
294
|
currentSegment = [];
|
|
329
295
|
}
|
|
330
|
-
else if (
|
|
331
|
-
currentSegment.push(
|
|
296
|
+
else if (isAnnotationCstNode(token)) {
|
|
297
|
+
currentSegment.push(this.visit([token]));
|
|
332
298
|
currentSegment.push(" ");
|
|
333
299
|
}
|
|
334
300
|
else {
|
|
335
301
|
currentSegment.push(token);
|
|
336
|
-
if ((i + 1 < tokens.length && !
|
|
302
|
+
if ((i + 1 < tokens.length && !isTypeArgumentsCstNode(tokens[i + 1])) ||
|
|
337
303
|
i + 1 === tokens.length) {
|
|
338
|
-
segments.push(
|
|
304
|
+
segments.push(rejectAndConcat(currentSegment));
|
|
339
305
|
currentSegment = [];
|
|
340
306
|
}
|
|
341
307
|
}
|
|
342
308
|
});
|
|
343
|
-
return
|
|
344
|
-
}
|
|
345
|
-
|
|
309
|
+
return rejectAndJoinSeps(ctx.Dot, segments);
|
|
310
|
+
}
|
|
311
|
+
unannInterfaceType(ctx) {
|
|
346
312
|
return this.visit(ctx.unannClassType);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
313
|
+
}
|
|
314
|
+
unannTypeVariable(ctx) {
|
|
315
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
316
|
+
}
|
|
317
|
+
methodDeclaration(ctx) {
|
|
318
|
+
const modifiers = sortModifiers(ctx.methodModifier);
|
|
319
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
320
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
321
|
+
const header = this.visit(ctx.methodHeader);
|
|
322
|
+
const body = this.visit(ctx.methodBody);
|
|
323
|
+
const headerBodySeparator = isStatementEmptyStatement(body) ? "" : " ";
|
|
324
|
+
return rejectAndJoin(hardline, [
|
|
325
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
326
|
+
rejectAndJoin(" ", [
|
|
327
|
+
rejectAndJoin(" ", otherModifiers),
|
|
328
|
+
rejectAndJoin(headerBodySeparator, [header, body])
|
|
363
329
|
])
|
|
364
330
|
]);
|
|
365
|
-
}
|
|
366
|
-
|
|
331
|
+
}
|
|
332
|
+
methodModifier(ctx) {
|
|
367
333
|
if (ctx.annotation) {
|
|
368
334
|
return this.visit(ctx.annotation);
|
|
369
335
|
}
|
|
370
336
|
// public | protected | private | Synchronized | ...
|
|
371
|
-
return
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return
|
|
380
|
-
|
|
337
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
338
|
+
}
|
|
339
|
+
methodHeader(ctx) {
|
|
340
|
+
const typeParameters = this.visit(ctx.typeParameters);
|
|
341
|
+
const annotations = this.mapVisit(ctx.annotation);
|
|
342
|
+
const result = this.visit(ctx.result);
|
|
343
|
+
const declarator = this.visit(ctx.methodDeclarator);
|
|
344
|
+
const throws = this.visit(ctx.throws);
|
|
345
|
+
return group(concat([
|
|
346
|
+
rejectAndJoin(" ", [
|
|
381
347
|
typeParameters,
|
|
382
|
-
|
|
348
|
+
rejectAndJoin(line, annotations),
|
|
383
349
|
result,
|
|
384
350
|
declarator,
|
|
385
351
|
throws
|
|
386
352
|
])
|
|
387
353
|
]));
|
|
388
|
-
}
|
|
389
|
-
|
|
354
|
+
}
|
|
355
|
+
result(ctx) {
|
|
390
356
|
if (ctx.unannType) {
|
|
391
357
|
return this.visit(ctx.unannType);
|
|
392
358
|
}
|
|
393
359
|
// void
|
|
394
|
-
return
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
var
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
360
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
361
|
+
}
|
|
362
|
+
methodDeclarator(ctx) {
|
|
363
|
+
var _a;
|
|
364
|
+
const identifier = printTokenWithComments(ctx.Identifier[0]);
|
|
365
|
+
const receiverParameter = this.visit(ctx.receiverParameter);
|
|
366
|
+
const formalParameterList = this.visit(ctx.formalParameterList);
|
|
367
|
+
const dims = this.visit(ctx.dims);
|
|
368
|
+
return rejectAndConcat([
|
|
401
369
|
identifier,
|
|
402
|
-
|
|
370
|
+
putIntoBraces(rejectAndJoin(line, [
|
|
371
|
+
rejectAndConcat([receiverParameter, (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a[0]]),
|
|
372
|
+
formalParameterList
|
|
373
|
+
]), softline, ctx.LBrace[0], ctx.RBrace[0]),
|
|
403
374
|
dims
|
|
404
375
|
]);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
var
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return (0, printer_utils_1.rejectAndJoin)("", [
|
|
413
|
-
(0, printer_utils_1.rejectAndJoin)(" ", annotations),
|
|
376
|
+
}
|
|
377
|
+
receiverParameter(ctx) {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
const annotations = this.mapVisit(ctx.annotation);
|
|
380
|
+
const unannType = this.visit(ctx.unannType);
|
|
381
|
+
return rejectAndJoin(" ", [
|
|
382
|
+
...annotations,
|
|
414
383
|
unannType,
|
|
415
|
-
|
|
416
|
-
ctx.This[0]
|
|
384
|
+
rejectAndConcat([(_a = ctx.Identifier) === null || _a === void 0 ? void 0 : _a[0], (_b = ctx.Dot) === null || _b === void 0 ? void 0 : _b[0], ctx.This[0]])
|
|
417
385
|
]);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
|
|
386
|
+
}
|
|
387
|
+
formalParameterList(ctx) {
|
|
388
|
+
const formalParameter = this.mapVisit(ctx.formalParameter);
|
|
389
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
390
|
+
return rejectAndJoinSeps(commas, formalParameter);
|
|
391
|
+
}
|
|
392
|
+
formalParameter(ctx) {
|
|
425
393
|
return this.visitSingle(ctx);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return
|
|
432
|
-
|
|
394
|
+
}
|
|
395
|
+
variableParaRegularParameter(ctx) {
|
|
396
|
+
const variableModifier = this.mapVisit(ctx.variableModifier);
|
|
397
|
+
const unannType = this.visit(ctx.unannType);
|
|
398
|
+
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
|
399
|
+
return rejectAndJoin(" ", [
|
|
400
|
+
rejectAndJoin(" ", variableModifier),
|
|
433
401
|
unannType,
|
|
434
402
|
variableDeclaratorId
|
|
435
403
|
]);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
?
|
|
404
|
+
}
|
|
405
|
+
variableArityParameter(ctx) {
|
|
406
|
+
const variableModifier = this.mapVisit(ctx.variableModifier);
|
|
407
|
+
const unannType = this.visit(ctx.unannType);
|
|
408
|
+
const annotations = this.mapVisit(ctx.annotation);
|
|
409
|
+
const identifier = ctx.Identifier[0];
|
|
410
|
+
const unannTypePrinted = ctx.annotation === undefined
|
|
411
|
+
? concat([unannType, ctx.DotDotDot[0]])
|
|
444
412
|
: unannType;
|
|
445
|
-
|
|
413
|
+
const annotationsPrinted = ctx.annotation === undefined
|
|
446
414
|
? annotations
|
|
447
|
-
:
|
|
448
|
-
return
|
|
449
|
-
|
|
415
|
+
: concat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]);
|
|
416
|
+
return rejectAndJoin(" ", [
|
|
417
|
+
join(" ", variableModifier),
|
|
450
418
|
unannTypePrinted,
|
|
451
419
|
annotationsPrinted,
|
|
452
420
|
identifier
|
|
453
421
|
]);
|
|
454
|
-
}
|
|
455
|
-
|
|
422
|
+
}
|
|
423
|
+
variableModifier(ctx) {
|
|
456
424
|
if (ctx.annotation) {
|
|
457
425
|
return this.visit(ctx.annotation);
|
|
458
426
|
}
|
|
459
|
-
return
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
return
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return
|
|
470
|
-
}
|
|
471
|
-
|
|
427
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
428
|
+
}
|
|
429
|
+
throws(ctx) {
|
|
430
|
+
const exceptionTypeList = this.visit(ctx.exceptionTypeList);
|
|
431
|
+
const throwsDeclaration = join(" ", [ctx.Throws[0], exceptionTypeList]);
|
|
432
|
+
return group(indent(rejectAndConcat([softline, throwsDeclaration])));
|
|
433
|
+
}
|
|
434
|
+
exceptionTypeList(ctx) {
|
|
435
|
+
const exceptionTypes = this.mapVisit(ctx.exceptionType);
|
|
436
|
+
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : [];
|
|
437
|
+
return rejectAndJoinSeps(commas, exceptionTypes);
|
|
438
|
+
}
|
|
439
|
+
exceptionType(ctx) {
|
|
472
440
|
return this.visitSingle(ctx);
|
|
473
|
-
}
|
|
474
|
-
|
|
441
|
+
}
|
|
442
|
+
methodBody(ctx) {
|
|
475
443
|
if (ctx.block) {
|
|
476
444
|
return this.visit(ctx.block);
|
|
477
445
|
}
|
|
478
|
-
return
|
|
479
|
-
}
|
|
480
|
-
|
|
446
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
447
|
+
}
|
|
448
|
+
instanceInitializer(ctx) {
|
|
481
449
|
return this.visitSingle(ctx);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
return
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
450
|
+
}
|
|
451
|
+
staticInitializer(ctx) {
|
|
452
|
+
const block = this.visit(ctx.block);
|
|
453
|
+
return join(" ", [ctx.Static[0], block]);
|
|
454
|
+
}
|
|
455
|
+
constructorDeclaration(ctx) {
|
|
456
|
+
const modifiers = sortModifiers(ctx.constructorModifier);
|
|
457
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
458
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
459
|
+
const constructorDeclarator = this.visit(ctx.constructorDeclarator);
|
|
460
|
+
const throws = this.visit(ctx.throws);
|
|
461
|
+
const constructorBody = this.visit(ctx.constructorBody);
|
|
462
|
+
return rejectAndJoin(" ", [
|
|
463
|
+
group(rejectAndJoin(hardline, [
|
|
464
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
465
|
+
rejectAndJoin(" ", [
|
|
466
|
+
join(" ", otherModifiers),
|
|
499
467
|
constructorDeclarator,
|
|
500
468
|
throws
|
|
501
469
|
])
|
|
502
470
|
])),
|
|
503
471
|
constructorBody
|
|
504
472
|
]);
|
|
505
|
-
}
|
|
506
|
-
|
|
473
|
+
}
|
|
474
|
+
constructorModifier(ctx) {
|
|
507
475
|
if (ctx.annotation) {
|
|
508
476
|
return this.visit(ctx.annotation);
|
|
509
477
|
}
|
|
510
478
|
// public | protected | private | Synchronized | ...
|
|
511
|
-
return
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
var
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return
|
|
479
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
480
|
+
}
|
|
481
|
+
constructorDeclarator(ctx) {
|
|
482
|
+
var _a;
|
|
483
|
+
const typeParameters = this.visit(ctx.typeParameters);
|
|
484
|
+
const simpleTypeName = this.visit(ctx.simpleTypeName);
|
|
485
|
+
const receiverParameter = this.visit(ctx.receiverParameter);
|
|
486
|
+
const formalParameterList = this.visit(ctx.formalParameterList);
|
|
487
|
+
return rejectAndJoin(" ", [
|
|
520
488
|
typeParameters,
|
|
521
|
-
|
|
489
|
+
concat([
|
|
522
490
|
simpleTypeName,
|
|
523
|
-
|
|
491
|
+
putIntoBraces(rejectAndJoin(line, [
|
|
492
|
+
rejectAndConcat([receiverParameter, (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a[0]]),
|
|
493
|
+
formalParameterList
|
|
494
|
+
]), softline, ctx.LBrace[0], ctx.RBrace[0])
|
|
524
495
|
])
|
|
525
496
|
]);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
return
|
|
534
|
-
}
|
|
535
|
-
|
|
497
|
+
}
|
|
498
|
+
simpleTypeName(ctx) {
|
|
499
|
+
return printTokenWithComments(this.getSingle(ctx));
|
|
500
|
+
}
|
|
501
|
+
constructorBody(ctx) {
|
|
502
|
+
const explicitConstructorInvocation = this.visit(ctx.explicitConstructorInvocation);
|
|
503
|
+
const blockStatements = this.visit(ctx.blockStatements);
|
|
504
|
+
return putIntoBraces(rejectAndJoin(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
505
|
+
}
|
|
506
|
+
explicitConstructorInvocation(ctx) {
|
|
536
507
|
return this.visitSingle(ctx);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return
|
|
508
|
+
}
|
|
509
|
+
unqualifiedExplicitConstructorInvocation(ctx) {
|
|
510
|
+
const typeArguments = this.visit(ctx.typeArguments);
|
|
511
|
+
const keyWord = ctx.This ? ctx.This[0] : ctx.Super[0];
|
|
512
|
+
const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
|
513
|
+
return rejectAndConcat([
|
|
543
514
|
typeArguments,
|
|
544
515
|
keyWord,
|
|
545
|
-
|
|
516
|
+
group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
|
546
517
|
]);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
return
|
|
518
|
+
}
|
|
519
|
+
qualifiedExplicitConstructorInvocation(ctx) {
|
|
520
|
+
const expressionName = this.visit(ctx.expressionName);
|
|
521
|
+
const typeArguments = this.visit(ctx.typeArguments);
|
|
522
|
+
const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
|
523
|
+
return rejectAndConcat([
|
|
553
524
|
expressionName,
|
|
554
525
|
ctx.Dot[0],
|
|
555
526
|
typeArguments,
|
|
556
527
|
ctx.Super[0],
|
|
557
|
-
|
|
528
|
+
group(rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
|
558
529
|
]);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return
|
|
566
|
-
|
|
530
|
+
}
|
|
531
|
+
enumDeclaration(ctx) {
|
|
532
|
+
const classModifier = this.mapVisit(ctx.classModifier);
|
|
533
|
+
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
534
|
+
const superinterfaces = this.visit(ctx.superinterfaces);
|
|
535
|
+
const enumBody = this.visit(ctx.enumBody);
|
|
536
|
+
return rejectAndJoin(" ", [
|
|
537
|
+
join(" ", classModifier),
|
|
567
538
|
ctx.Enum[0],
|
|
568
539
|
typeIdentifier,
|
|
569
540
|
superinterfaces,
|
|
570
541
|
enumBody
|
|
571
542
|
]);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
543
|
+
}
|
|
544
|
+
enumBody(ctx) {
|
|
545
|
+
const enumConstantList = this.visit(ctx.enumConstantList);
|
|
546
|
+
const enumBodyDeclarations = this.visit(ctx.enumBodyDeclarations);
|
|
547
|
+
const hasEnumConstants = ctx.enumConstantList !== undefined;
|
|
548
|
+
const hasNoClassBodyDeclarations = ctx.enumBodyDeclarations === undefined ||
|
|
578
549
|
ctx.enumBodyDeclarations[0].children.classBodyDeclaration === undefined;
|
|
579
550
|
// edge case: https://github.com/jhipster/prettier-java/issues/383
|
|
580
|
-
|
|
581
|
-
|
|
551
|
+
const handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations &&
|
|
552
|
+
hasLeadingComments(ctx.enumBodyDeclarations[0])
|
|
582
553
|
? hardline
|
|
583
554
|
: "";
|
|
584
|
-
|
|
555
|
+
let optionalComma;
|
|
585
556
|
if (hasEnumConstants &&
|
|
586
557
|
hasNoClassBodyDeclarations &&
|
|
587
558
|
this.prettierOptions.trailingComma !== "none") {
|
|
588
559
|
optionalComma = ctx.Comma ? ctx.Comma[0] : ",";
|
|
589
560
|
}
|
|
590
561
|
else {
|
|
591
|
-
optionalComma = ctx.Comma ?
|
|
562
|
+
optionalComma = ctx.Comma ? Object.assign(Object.assign({}, ctx.Comma[0]), { image: "" }) : "";
|
|
592
563
|
}
|
|
593
|
-
return
|
|
564
|
+
return putIntoBraces(rejectAndConcat([
|
|
594
565
|
enumConstantList,
|
|
595
566
|
optionalComma,
|
|
596
567
|
handleEnumBodyDeclarationsLeadingComments,
|
|
597
568
|
enumBodyDeclarations
|
|
598
569
|
]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
? ctx.Comma.map(
|
|
605
|
-
return (0, prettier_builder_1.concat)([elt, blankLineSeparators[index]]);
|
|
606
|
-
})
|
|
570
|
+
}
|
|
571
|
+
enumConstantList(ctx) {
|
|
572
|
+
const enumConstants = this.mapVisit(ctx.enumConstant);
|
|
573
|
+
const blankLineSeparators = getBlankLinesSeparator(ctx.enumConstant);
|
|
574
|
+
const commas = ctx.Comma
|
|
575
|
+
? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]]))
|
|
607
576
|
: [];
|
|
608
|
-
return
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
?
|
|
577
|
+
return group(rejectAndJoinSeps(commas, enumConstants));
|
|
578
|
+
}
|
|
579
|
+
enumConstant(ctx) {
|
|
580
|
+
const modifiers = sortModifiers(ctx.enumConstantModifier);
|
|
581
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
582
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
583
|
+
const identifier = ctx.Identifier[0];
|
|
584
|
+
const classBody = this.visit(ctx.classBody);
|
|
585
|
+
const optionalBracesAndArgumentList = ctx.LBrace
|
|
586
|
+
? printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0])
|
|
618
587
|
: "";
|
|
619
|
-
return
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
588
|
+
return rejectAndJoin(hardline, [
|
|
589
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
590
|
+
rejectAndJoin(" ", [
|
|
591
|
+
rejectAndJoin(" ", otherModifiers),
|
|
592
|
+
rejectAndConcat([identifier, optionalBracesAndArgumentList]),
|
|
624
593
|
classBody
|
|
625
594
|
])
|
|
626
595
|
]);
|
|
627
|
-
}
|
|
628
|
-
|
|
596
|
+
}
|
|
597
|
+
enumConstantModifier(ctx) {
|
|
629
598
|
return this.visitSingle(ctx);
|
|
630
|
-
}
|
|
631
|
-
|
|
599
|
+
}
|
|
600
|
+
enumBodyDeclarations(ctx) {
|
|
632
601
|
if (ctx.classBodyDeclaration !== undefined) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
return
|
|
602
|
+
const classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration);
|
|
603
|
+
const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
|
|
604
|
+
return rejectAndJoin(concat([hardline, hardline]), [
|
|
636
605
|
ctx.Semicolon[0],
|
|
637
|
-
|
|
606
|
+
rejectAndJoinSeps(separators, classBodyDeclaration)
|
|
638
607
|
]);
|
|
639
608
|
}
|
|
640
|
-
return (
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
609
|
+
return printTokenWithComments(Object.assign(Object.assign({}, ctx.Semicolon[0]), { image: "" }));
|
|
610
|
+
}
|
|
611
|
+
recordDeclaration(ctx) {
|
|
612
|
+
const name = this.visit(ctx.typeIdentifier);
|
|
613
|
+
const optionalTypeParams = this.visit(ctx.typeParameters);
|
|
614
|
+
const recordHeader = this.visit(ctx.recordHeader);
|
|
615
|
+
let superInterfacesPart = "";
|
|
616
|
+
const optionalSuperInterfaces = this.visit(ctx.superinterfaces);
|
|
648
617
|
if (optionalSuperInterfaces) {
|
|
649
|
-
superInterfacesPart =
|
|
618
|
+
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces]));
|
|
650
619
|
}
|
|
651
|
-
|
|
652
|
-
return
|
|
653
|
-
|
|
654
|
-
|
|
620
|
+
const body = this.visit(ctx.recordBody);
|
|
621
|
+
return rejectAndJoin(" ", [
|
|
622
|
+
group(rejectAndConcat([
|
|
623
|
+
rejectAndJoin(" ", [ctx.Record[0], name]),
|
|
655
624
|
optionalTypeParams,
|
|
656
625
|
recordHeader,
|
|
657
626
|
superInterfacesPart
|
|
658
627
|
])),
|
|
659
628
|
body
|
|
660
629
|
]);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
return
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
? ctx.Comma.map(
|
|
671
|
-
return (0, prettier_builder_1.concat)([elt, blankLineSeparators[index]]);
|
|
672
|
-
})
|
|
630
|
+
}
|
|
631
|
+
recordHeader(ctx) {
|
|
632
|
+
const recordComponentList = this.visit(ctx.recordComponentList);
|
|
633
|
+
return putIntoBraces(recordComponentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
|
|
634
|
+
}
|
|
635
|
+
recordComponentList(ctx) {
|
|
636
|
+
const recordComponents = this.mapVisit(ctx.recordComponent);
|
|
637
|
+
const blankLineSeparators = getBlankLinesSeparator(ctx.recordComponent, line);
|
|
638
|
+
const commas = ctx.Comma
|
|
639
|
+
? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]]))
|
|
673
640
|
: [];
|
|
674
|
-
return
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
641
|
+
return rejectAndJoinSeps(commas, recordComponents);
|
|
642
|
+
}
|
|
643
|
+
recordComponent(ctx) {
|
|
644
|
+
const modifiers = this.mapVisit(ctx.recordComponentModifier);
|
|
645
|
+
const unannType = this.visit(ctx.unannType);
|
|
679
646
|
if (ctx.Identifier !== undefined) {
|
|
680
|
-
return
|
|
681
|
-
|
|
682
|
-
|
|
647
|
+
return group(rejectAndJoin(line, [
|
|
648
|
+
join(line, modifiers),
|
|
649
|
+
join(" ", [unannType, ctx.Identifier[0]])
|
|
683
650
|
]));
|
|
684
651
|
}
|
|
685
|
-
|
|
652
|
+
const variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent);
|
|
686
653
|
if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) {
|
|
687
|
-
return
|
|
688
|
-
|
|
689
|
-
|
|
654
|
+
return group(rejectAndJoin(line, [
|
|
655
|
+
join(line, modifiers),
|
|
656
|
+
join(" ", [unannType, variableArityRecordComponent])
|
|
690
657
|
]));
|
|
691
658
|
}
|
|
692
|
-
return
|
|
693
|
-
|
|
694
|
-
|
|
659
|
+
return group(rejectAndJoin(line, [
|
|
660
|
+
join(line, modifiers),
|
|
661
|
+
concat([unannType, variableArityRecordComponent])
|
|
695
662
|
]));
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
return
|
|
701
|
-
|
|
663
|
+
}
|
|
664
|
+
variableArityRecordComponent(ctx) {
|
|
665
|
+
const annotations = this.mapVisit(ctx.annotation);
|
|
666
|
+
const identifier = ctx.Identifier[0];
|
|
667
|
+
return rejectAndJoin(" ", [
|
|
668
|
+
rejectAndConcat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]),
|
|
702
669
|
identifier
|
|
703
670
|
]);
|
|
704
|
-
}
|
|
705
|
-
|
|
671
|
+
}
|
|
672
|
+
recordComponentModifier(ctx) {
|
|
706
673
|
return this.visitSingle(ctx);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
return
|
|
710
|
-
}
|
|
711
|
-
|
|
674
|
+
}
|
|
675
|
+
recordBody(ctx) {
|
|
676
|
+
return putIntoBraces(rejectAndJoinSeps(getBlankLinesSeparator(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
677
|
+
}
|
|
678
|
+
recordBodyDeclaration(ctx) {
|
|
712
679
|
return this.visitSingle(ctx);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
return
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
680
|
+
}
|
|
681
|
+
compactConstructorDeclaration(ctx) {
|
|
682
|
+
const modifiers = sortModifiers(ctx.constructorModifier);
|
|
683
|
+
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
684
|
+
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
685
|
+
const name = this.visit(ctx.simpleTypeName);
|
|
686
|
+
const constructorBody = this.visit(ctx.constructorBody);
|
|
687
|
+
return rejectAndJoin(" ", [
|
|
688
|
+
group(rejectAndJoin(hardline, [
|
|
689
|
+
rejectAndJoin(hardline, firstAnnotations),
|
|
690
|
+
rejectAndJoin(" ", [join(" ", otherModifiers), name])
|
|
724
691
|
])),
|
|
725
692
|
constructorBody
|
|
726
693
|
]);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
return "isClassDeclaration";
|
|
730
|
-
};
|
|
731
|
-
ClassesPrettierVisitor.prototype.identifyClassBodyDeclarationType = function () {
|
|
732
|
-
return "identifyClassBodyDeclarationType";
|
|
733
|
-
};
|
|
734
|
-
ClassesPrettierVisitor.prototype.isDims = function () {
|
|
694
|
+
}
|
|
695
|
+
isDims() {
|
|
735
696
|
return "isDims";
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
return "isCompactConstructorDeclaration";
|
|
739
|
-
};
|
|
740
|
-
return ClassesPrettierVisitor;
|
|
741
|
-
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
|
742
|
-
exports.ClassesPrettierVisitor = ClassesPrettierVisitor;
|
|
697
|
+
}
|
|
698
|
+
}
|