@openrewrite/rewrite 8.72.2 → 8.72.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/execution.js +3 -16
- package/dist/execution.js.map +1 -1
- package/dist/index.js +34 -49
- package/dist/index.js.map +1 -1
- package/dist/java/markers.js +12 -29
- package/dist/java/markers.js.map +1 -1
- package/dist/java/print.js +2 -13
- package/dist/java/print.js.map +1 -1
- package/dist/java/rpc.js +1344 -1725
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/type-visitor.js +143 -184
- package/dist/java/type-visitor.js.map +1 -1
- package/dist/java/visitor.js +1072 -1249
- package/dist/java/visitor.js.map +1 -1
- package/dist/javascript/add-import.js +495 -534
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/autodetect.js +116 -159
- package/dist/javascript/autodetect.js.map +1 -1
- package/dist/javascript/cleanup/add-parse-int-radix.js +41 -57
- package/dist/javascript/cleanup/add-parse-int-radix.js.map +1 -1
- package/dist/javascript/cleanup/prefer-optional-chain.js +89 -105
- package/dist/javascript/cleanup/prefer-optional-chain.js.map +1 -1
- package/dist/javascript/cleanup/use-object-property-shorthand.js +74 -95
- package/dist/javascript/cleanup/use-object-property-shorthand.js.map +1 -1
- package/dist/javascript/comparator.js +815 -1167
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/dependency-workspace.js +206 -219
- package/dist/javascript/dependency-workspace.js.map +1 -1
- package/dist/javascript/format/format.js +682 -908
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +152 -231
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
- package/dist/javascript/format/normalize-whitespace-visitor.js +12 -31
- package/dist/javascript/format/normalize-whitespace-visitor.js.map +1 -1
- package/dist/javascript/format/prettier-config-loader.js +134 -153
- package/dist/javascript/format/prettier-config-loader.js.map +1 -1
- package/dist/javascript/format/prettier-format.js +112 -129
- package/dist/javascript/format/prettier-format.js.map +1 -1
- package/dist/javascript/format/tabs-and-indents-visitor.js +112 -136
- package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
- package/dist/javascript/markers.js +59 -92
- package/dist/javascript/markers.js.map +1 -1
- package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js +39 -52
- package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js.map +1 -1
- package/dist/javascript/migrate/es6/modernize-octal-literals.js +25 -38
- package/dist/javascript/migrate/es6/modernize-octal-literals.js.map +1 -1
- package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js +66 -82
- package/dist/javascript/migrate/es6/remove-duplicate-object-keys.js.map +1 -1
- package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js +10 -23
- package/dist/javascript/migrate/typescript/export-assignment-to-export-default.js.map +1 -1
- package/dist/javascript/node-resolution-result.js +137 -166
- package/dist/javascript/node-resolution-result.js.map +1 -1
- package/dist/javascript/package-json-parser.js +312 -343
- package/dist/javascript/package-json-parser.js.map +1 -1
- package/dist/javascript/package-manager.js +145 -170
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +94 -68
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.js +1572 -1835
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/project-parser.js +151 -172
- package/dist/javascript/project-parser.js.map +1 -1
- package/dist/javascript/recipes/add-dependency.js +140 -175
- package/dist/javascript/recipes/add-dependency.js.map +1 -1
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js +20 -36
- package/dist/javascript/recipes/async-callback-in-sync-array-method.js.map +1 -1
- package/dist/javascript/recipes/auto-format.js +3 -14
- package/dist/javascript/recipes/auto-format.js.map +1 -1
- package/dist/javascript/recipes/change-import.js +447 -495
- package/dist/javascript/recipes/change-import.js.map +1 -1
- package/dist/javascript/recipes/order-imports.js +162 -175
- package/dist/javascript/recipes/order-imports.js.map +1 -1
- package/dist/javascript/recipes/upgrade-dependency-version.js +167 -197
- package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +166 -193
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
- package/dist/javascript/remove-import.js +689 -724
- package/dist/javascript/remove-import.js.map +1 -1
- package/dist/javascript/rpc.js +1007 -1332
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/search/find-dependency.js +84 -110
- package/dist/javascript/search/find-dependency.js.map +1 -1
- package/dist/javascript/search/uses-method.js +5 -19
- package/dist/javascript/search/uses-method.js.map +1 -1
- package/dist/javascript/search/uses-type.js +9 -20
- package/dist/javascript/search/uses-type.js.map +1 -1
- package/dist/javascript/templating/comparator.js +737 -822
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/engine.js +211 -245
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/pattern.js +169 -190
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +172 -210
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/rewrite.js +75 -97
- package/dist/javascript/templating/rewrite.js.map +1 -1
- package/dist/javascript/templating/template.js +69 -82
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/tree-debug.js +109 -137
- package/dist/javascript/tree-debug.js.map +1 -1
- package/dist/javascript/visitor.js +1090 -1254
- package/dist/javascript/visitor.js.map +1 -1
- package/dist/json/print.js +72 -103
- package/dist/json/print.js.map +1 -1
- package/dist/json/rpc.js +120 -181
- package/dist/json/rpc.js.map +1 -1
- package/dist/json/visitor.js +69 -100
- package/dist/json/visitor.js.map +1 -1
- package/dist/marketplace.js +20 -33
- package/dist/marketplace.js.map +1 -1
- package/dist/parse-error.js +41 -62
- package/dist/parse-error.js.map +1 -1
- package/dist/parser.js +7 -18
- package/dist/parser.js.map +1 -1
- package/dist/path-utils.js +46 -59
- package/dist/path-utils.js.map +1 -1
- package/dist/preconditions.js +30 -47
- package/dist/preconditions.js.map +1 -1
- package/dist/print.js +6 -19
- package/dist/print.js.map +1 -1
- package/dist/recipe.js +42 -73
- package/dist/recipe.js.map +1 -1
- package/dist/rpc/index.js +74 -115
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/queue.js +71 -90
- package/dist/rpc/queue.js.map +1 -1
- package/dist/rpc/recipe.js +32 -57
- package/dist/rpc/recipe.js.map +1 -1
- package/dist/rpc/request/generate.js +4 -13
- package/dist/rpc/request/generate.js.map +1 -1
- package/dist/rpc/request/get-languages.js +2 -11
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/request/get-marketplace.js +9 -20
- package/dist/rpc/request/get-marketplace.js.map +1 -1
- package/dist/rpc/request/get-object.js +4 -13
- package/dist/rpc/request/get-object.js.map +1 -1
- package/dist/rpc/request/install-recipes.js +25 -36
- package/dist/rpc/request/install-recipes.js.map +1 -1
- package/dist/rpc/request/metrics.js +8 -17
- package/dist/rpc/request/metrics.js.map +1 -1
- package/dist/rpc/request/parse-project.js +36 -45
- package/dist/rpc/request/parse-project.js.map +1 -1
- package/dist/rpc/request/parse.js +5 -14
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/request/prepare-recipe.js +37 -52
- package/dist/rpc/request/prepare-recipe.js.map +1 -1
- package/dist/rpc/request/print.js +5 -14
- package/dist/rpc/request/print.js.map +1 -1
- package/dist/rpc/request/visit.js +56 -71
- package/dist/rpc/request/visit.js.map +1 -1
- package/dist/rpc/rewrite-rpc.js +70 -97
- package/dist/rpc/rewrite-rpc.js.map +1 -1
- package/dist/rpc/server.js +76 -89
- package/dist/rpc/server.js.map +1 -1
- package/dist/run.js +47 -66
- package/dist/run.js.map +1 -1
- package/dist/search/is-source-file.js +8 -19
- package/dist/search/is-source-file.js.map +1 -1
- package/dist/test/rewrite-test.js +154 -188
- package/dist/test/rewrite-test.js.map +1 -1
- package/dist/text/print.js +23 -38
- package/dist/text/print.js.map +1 -1
- package/dist/text/rpc.js +29 -44
- package/dist/text/rpc.js.map +1 -1
- package/dist/text/visitor.js +16 -33
- package/dist/text/visitor.js.map +1 -1
- package/dist/util.js +13 -24
- package/dist/util.js.map +1 -1
- package/dist/version.txt +1 -1
- package/dist/visitor.js +84 -115
- package/dist/visitor.js.map +1 -1
- package/dist/yaml/index.d.ts +2 -0
- package/dist/yaml/index.d.ts.map +1 -1
- package/dist/yaml/index.js +2 -0
- package/dist/yaml/index.js.map +1 -1
- package/dist/yaml/markers.d.ts +21 -0
- package/dist/yaml/markers.d.ts.map +1 -0
- package/dist/yaml/markers.js +37 -0
- package/dist/yaml/markers.js.map +1 -0
- package/dist/yaml/parser.d.ts.map +1 -1
- package/dist/yaml/parser.js +4 -1
- package/dist/yaml/parser.js.map +1 -1
- package/dist/yaml/print.d.ts +1 -1
- package/dist/yaml/print.d.ts.map +1 -1
- package/dist/yaml/print.js +175 -208
- package/dist/yaml/print.js.map +1 -1
- package/dist/yaml/rpc.js +154 -219
- package/dist/yaml/rpc.js.map +1 -1
- package/dist/yaml/visitor.js +78 -113
- package/dist/yaml/visitor.js.map +1 -1
- package/package.json +1 -1
- package/src/javascript/parser.ts +56 -14
- package/src/yaml/index.ts +2 -0
- package/src/yaml/markers.ts +70 -0
- package/src/yaml/parser.ts +5 -1
- package/src/yaml/print.ts +5 -2
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.prettierFormat = exports.BlankLinesVisitor = exports.WrappingAndBracesVisitor = exports.SpacesVisitor = exports.AutoformatVisitor = exports.autoFormat = exports.maybeAutoFormat = exports.MinimumViableSpacingVisitor = exports.NormalizeWhitespaceVisitor = exports.TabsAndIndentsVisitor = void 0;
|
|
13
4
|
/*
|
|
@@ -42,14 +33,14 @@ var normalize_whitespace_visitor_2 = require("./normalize-whitespace-visitor");
|
|
|
42
33
|
Object.defineProperty(exports, "NormalizeWhitespaceVisitor", { enumerable: true, get: function () { return normalize_whitespace_visitor_2.NormalizeWhitespaceVisitor; } });
|
|
43
34
|
var minimum_viable_spacing_visitor_2 = require("./minimum-viable-spacing-visitor");
|
|
44
35
|
Object.defineProperty(exports, "MinimumViableSpacingVisitor", { enumerable: true, get: function () { return minimum_viable_spacing_visitor_2.MinimumViableSpacingVisitor; } });
|
|
45
|
-
const maybeAutoFormat = (before, after, p, stopAfter, parent) =>
|
|
36
|
+
const maybeAutoFormat = async (before, after, p, stopAfter, parent) => {
|
|
46
37
|
if (before !== after) {
|
|
47
38
|
return (0, exports.autoFormat)(after, p, stopAfter, parent);
|
|
48
39
|
}
|
|
49
40
|
return after;
|
|
50
|
-
}
|
|
41
|
+
};
|
|
51
42
|
exports.maybeAutoFormat = maybeAutoFormat;
|
|
52
|
-
const autoFormat = (j, p, stopAfter, parent, styles) =>
|
|
43
|
+
const autoFormat = async (j, p, stopAfter, parent, styles) => await new AutoformatVisitor(stopAfter, styles).visit(j, p, parent);
|
|
53
44
|
exports.autoFormat = autoFormat;
|
|
54
45
|
/**
|
|
55
46
|
* Formats JavaScript/TypeScript code using a comprehensive set of formatting rules.
|
|
@@ -68,31 +59,29 @@ class AutoformatVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
68
59
|
this.stopAfter = stopAfter;
|
|
69
60
|
this.styles = styles;
|
|
70
61
|
}
|
|
71
|
-
visit(tree, p, cursor) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
62
|
+
async visit(tree, p, cursor) {
|
|
63
|
+
// Check for PrettierStyle in styles array or as marker on source file
|
|
64
|
+
// If found, delegate entirely to Prettier (skip other formatting visitors)
|
|
65
|
+
const prettierStyle = (0, prettier_format_1.getPrettierStyle)(tree, cursor, this.styles);
|
|
66
|
+
if (prettierStyle) {
|
|
67
|
+
return (0, prettier_format_1.applyPrettierFormatting)(tree, prettierStyle, p, cursor, this.stopAfter);
|
|
68
|
+
}
|
|
69
|
+
const visitors = [
|
|
70
|
+
new normalize_whitespace_visitor_1.NormalizeWhitespaceVisitor(this.stopAfter),
|
|
71
|
+
new minimum_viable_spacing_visitor_1.MinimumViableSpacingVisitor(this.stopAfter),
|
|
72
|
+
new BlankLinesVisitor((0, style_1.getStyle)(style_1.StyleKind.BlankLinesStyle, tree, this.styles), this.stopAfter),
|
|
73
|
+
new WrappingAndBracesVisitor((0, style_1.getStyle)(style_1.StyleKind.WrappingAndBracesStyle, tree, this.styles), this.stopAfter),
|
|
74
|
+
new SpacesVisitor((0, style_1.getStyle)(style_1.StyleKind.SpacesStyle, tree, this.styles), this.stopAfter),
|
|
75
|
+
new tabs_and_indents_visitor_1.TabsAndIndentsVisitor((0, style_1.getStyle)(style_1.StyleKind.TabsAndIndentsStyle, tree, this.styles), this.stopAfter),
|
|
76
|
+
];
|
|
77
|
+
let t = tree;
|
|
78
|
+
for (const visitor of visitors) {
|
|
79
|
+
t = await visitor.visit(t, p, cursor);
|
|
80
|
+
if (t === undefined) {
|
|
81
|
+
return undefined;
|
|
93
82
|
}
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
}
|
|
84
|
+
return t;
|
|
96
85
|
}
|
|
97
86
|
}
|
|
98
87
|
exports.AutoformatVisitor = AutoformatVisitor;
|
|
@@ -102,479 +91,440 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
102
91
|
this.style = style;
|
|
103
92
|
this.stopAfter = stopAfter;
|
|
104
93
|
}
|
|
105
|
-
visit(tree, p, parent) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
|
|
112
|
-
return tree;
|
|
113
|
-
}
|
|
114
|
-
return _super.visit.call(this, tree, p, parent);
|
|
115
|
-
});
|
|
94
|
+
async visit(tree, p, parent) {
|
|
95
|
+
var _a;
|
|
96
|
+
if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
|
|
97
|
+
return tree;
|
|
98
|
+
}
|
|
99
|
+
return super.visit(tree, p, parent);
|
|
116
100
|
}
|
|
117
|
-
postVisit(tree, p) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
124
|
-
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
125
|
-
}
|
|
126
|
-
return _super.postVisit.call(this, tree, p);
|
|
127
|
-
});
|
|
101
|
+
async postVisit(tree, p) {
|
|
102
|
+
var _a;
|
|
103
|
+
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
104
|
+
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
105
|
+
}
|
|
106
|
+
return super.postVisit(tree, p);
|
|
128
107
|
}
|
|
129
|
-
visitAlias(alias, p) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const ret = yield _super.visitAlias.call(this, alias, p);
|
|
135
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
136
|
-
draft.propertyName.after.whitespace = " ";
|
|
137
|
-
});
|
|
108
|
+
async visitAlias(alias, p) {
|
|
109
|
+
const ret = await super.visitAlias(alias, p);
|
|
110
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
111
|
+
draft.propertyName.after.whitespace = " ";
|
|
138
112
|
});
|
|
139
113
|
}
|
|
140
|
-
visitArrayAccess(arrayAccess, p) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
if (!draft.dimension.index.after.whitespace.includes("\n")) {
|
|
152
|
-
draft.dimension.index.after.whitespace = this.style.within.arrayBrackets ? " " : "";
|
|
153
|
-
}
|
|
154
|
-
});
|
|
114
|
+
async visitArrayAccess(arrayAccess, p) {
|
|
115
|
+
const ret = await super.visitArrayAccess(arrayAccess, p);
|
|
116
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
117
|
+
// Preserve newlines - only modify if no newlines present
|
|
118
|
+
if (!draft.dimension.index.element.prefix.whitespace.includes("\n")) {
|
|
119
|
+
draft.dimension.index.element.prefix.whitespace = this.style.within.arrayBrackets ? " " : "";
|
|
120
|
+
}
|
|
121
|
+
if (!draft.dimension.index.after.whitespace.includes("\n")) {
|
|
122
|
+
draft.dimension.index.after.whitespace = this.style.within.arrayBrackets ? " " : "";
|
|
123
|
+
}
|
|
155
124
|
});
|
|
156
125
|
}
|
|
157
|
-
visitAssignment(assignment, p) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
if (!draft.assignment.element.prefix.whitespace.includes("\n")) {
|
|
169
|
-
draft.assignment.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
170
|
-
}
|
|
171
|
-
});
|
|
126
|
+
async visitAssignment(assignment, p) {
|
|
127
|
+
const ret = await super.visitAssignment(assignment, p);
|
|
128
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
129
|
+
// Preserve newlines - only modify if no newlines present
|
|
130
|
+
if (!draft.assignment.before.whitespace.includes("\n")) {
|
|
131
|
+
draft.assignment.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
132
|
+
}
|
|
133
|
+
if (!draft.assignment.element.prefix.whitespace.includes("\n")) {
|
|
134
|
+
draft.assignment.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
135
|
+
}
|
|
172
136
|
});
|
|
173
137
|
}
|
|
174
|
-
visitBinary(binary, p) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
138
|
+
async visitBinary(binary, p) {
|
|
139
|
+
const ret = await super.visitBinary(binary, p);
|
|
140
|
+
let property = false;
|
|
141
|
+
switch (ret.operator.element.valueOf()) {
|
|
142
|
+
case java_1.J.Binary.Type.And:
|
|
143
|
+
case java_1.J.Binary.Type.Or:
|
|
144
|
+
property = this.style.aroundOperators.logical;
|
|
145
|
+
break;
|
|
146
|
+
case java_1.J.Binary.Type.Equal:
|
|
147
|
+
case java_1.J.Binary.Type.NotEqual:
|
|
148
|
+
property = this.style.aroundOperators.equality;
|
|
149
|
+
break;
|
|
150
|
+
case java_1.J.Binary.Type.LessThan:
|
|
151
|
+
case java_1.J.Binary.Type.LessThanOrEqual:
|
|
152
|
+
case java_1.J.Binary.Type.GreaterThan:
|
|
153
|
+
case java_1.J.Binary.Type.GreaterThanOrEqual:
|
|
154
|
+
property = this.style.aroundOperators.relational;
|
|
155
|
+
break;
|
|
156
|
+
case java_1.J.Binary.Type.BitAnd:
|
|
157
|
+
case java_1.J.Binary.Type.BitOr:
|
|
158
|
+
case java_1.J.Binary.Type.BitXor:
|
|
159
|
+
property = this.style.aroundOperators.bitwise;
|
|
160
|
+
break;
|
|
161
|
+
case java_1.J.Binary.Type.Addition:
|
|
162
|
+
case java_1.J.Binary.Type.Subtraction:
|
|
163
|
+
property = this.style.aroundOperators.additive;
|
|
164
|
+
break;
|
|
165
|
+
case java_1.J.Binary.Type.Multiplication:
|
|
166
|
+
case java_1.J.Binary.Type.Division:
|
|
167
|
+
case java_1.J.Binary.Type.Modulo:
|
|
168
|
+
property = this.style.aroundOperators.multiplicative;
|
|
169
|
+
break;
|
|
170
|
+
case java_1.J.Binary.Type.LeftShift:
|
|
171
|
+
case java_1.J.Binary.Type.RightShift:
|
|
172
|
+
case java_1.J.Binary.Type.UnsignedRightShift:
|
|
173
|
+
property = this.style.aroundOperators.shift;
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
throw new Error("Unsupported operator type " + ret.operator.element.valueOf());
|
|
177
|
+
}
|
|
178
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
179
|
+
// Preserve newlines - only modify if no newlines present
|
|
180
|
+
if (!draft.operator.before.whitespace.includes("\n")) {
|
|
181
|
+
draft.operator.before.whitespace = property ? " " : "";
|
|
182
|
+
}
|
|
183
|
+
if (!draft.right.prefix.whitespace.includes("\n")) {
|
|
184
|
+
draft.right.prefix.whitespace = property ? " " : "";
|
|
217
185
|
}
|
|
218
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
219
|
-
// Preserve newlines - only modify if no newlines present
|
|
220
|
-
if (!draft.operator.before.whitespace.includes("\n")) {
|
|
221
|
-
draft.operator.before.whitespace = property ? " " : "";
|
|
222
|
-
}
|
|
223
|
-
if (!draft.right.prefix.whitespace.includes("\n")) {
|
|
224
|
-
draft.right.prefix.whitespace = property ? " " : "";
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
186
|
});
|
|
228
187
|
}
|
|
229
|
-
visitCase(aCase, p) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (draft.caseLabels.elements[0].element.kind != java_1.J.Kind.Identifier || draft.caseLabels.elements[0].element.simpleName != "default") {
|
|
237
|
-
// Preserve newlines - only set to space if no newline exists
|
|
238
|
-
if (!draft.caseLabels.before.whitespace.includes("\n")) {
|
|
239
|
-
draft.caseLabels.before.whitespace = " ";
|
|
240
|
-
}
|
|
188
|
+
async visitCase(aCase, p) {
|
|
189
|
+
const ret = await super.visitCase(aCase, p);
|
|
190
|
+
return ret && (0, mutative_1.create)(ret, draft => {
|
|
191
|
+
if (draft.caseLabels.elements[0].element.kind != java_1.J.Kind.Identifier || draft.caseLabels.elements[0].element.simpleName != "default") {
|
|
192
|
+
// Preserve newlines - only set to space if no newline exists
|
|
193
|
+
if (!draft.caseLabels.before.whitespace.includes("\n")) {
|
|
194
|
+
draft.caseLabels.before.whitespace = " ";
|
|
241
195
|
}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
visitClassDeclaration(classDecl, p) {
|
|
246
|
-
const _super = Object.create(null, {
|
|
247
|
-
visitClassDeclaration: { get: () => super.visitClassDeclaration }
|
|
248
|
-
});
|
|
249
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
const ret = yield _super.visitClassDeclaration.call(this, classDecl, p);
|
|
251
|
-
// TODO typeParameters - IntelliJ doesn't seem to provide a setting for angleBrackets spacing for Typescript (while it does for Java),
|
|
252
|
-
// thus we either introduce our own setting or just enforce the natural spacing with no setting
|
|
253
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
254
|
-
draft.body.prefix.whitespace = this.style.beforeLeftBrace.classInterfaceModuleLeftBrace ? " " : "";
|
|
255
|
-
});
|
|
196
|
+
}
|
|
256
197
|
});
|
|
257
198
|
}
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
199
|
+
async visitClassDeclaration(classDecl, p) {
|
|
200
|
+
const ret = await super.visitClassDeclaration(classDecl, p);
|
|
201
|
+
// TODO typeParameters - IntelliJ doesn't seem to provide a setting for angleBrackets spacing for Typescript (while it does for Java),
|
|
202
|
+
// thus we either introduce our own setting or just enforce the natural spacing with no setting
|
|
203
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
204
|
+
draft.body.prefix.whitespace = this.style.beforeLeftBrace.classInterfaceModuleLeftBrace ? " " : "";
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
async visitContainer(container, p) {
|
|
208
|
+
const ret = await super.visitContainer(container, p);
|
|
209
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
210
|
+
if (draft.elements.length > 0) {
|
|
211
|
+
// Apply beforeComma rule to all elements except the last
|
|
212
|
+
// (last element's after is before closing bracket, not a comma)
|
|
213
|
+
for (let i = 0; i < draft.elements.length - 1; i++) {
|
|
214
|
+
const afterWs = draft.elements[i].after.whitespace;
|
|
215
|
+
// Preserve newlines - only adjust when on same line
|
|
216
|
+
if (!afterWs.includes("\n")) {
|
|
217
|
+
draft.elements[i].after.whitespace = this.style.other.beforeComma ? " " : "";
|
|
274
218
|
}
|
|
275
219
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
220
|
+
}
|
|
221
|
+
if (draft.elements.length > 1) {
|
|
222
|
+
// Apply afterComma rule to elements after the first
|
|
223
|
+
for (let i = 1; i < draft.elements.length; i++) {
|
|
224
|
+
const currentWs = draft.elements[i].element.prefix.whitespace;
|
|
225
|
+
// Preserve original newlines - only adjust spacing when elements are on same line
|
|
226
|
+
if (!currentWs.includes("\n")) {
|
|
227
|
+
draft.elements[i].element.prefix.whitespace = this.style.other.afterComma ? " " : "";
|
|
284
228
|
}
|
|
285
229
|
}
|
|
286
|
-
}
|
|
230
|
+
}
|
|
287
231
|
});
|
|
288
232
|
}
|
|
289
|
-
visitExportDeclaration(exportDeclaration, p) {
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// If it has only spaces (no newline), it's the space before a trailing comma
|
|
311
|
-
const lastAfter = ne.elements.elements[ne.elements.elements.length - 1].after.whitespace;
|
|
312
|
-
if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
|
|
313
|
-
ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
|
|
314
|
-
}
|
|
233
|
+
async visitExportDeclaration(exportDeclaration, p) {
|
|
234
|
+
const ret = await super.visitExportDeclaration(exportDeclaration, p);
|
|
235
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
236
|
+
if (draft.exportClause) {
|
|
237
|
+
draft.exportClause.prefix.whitespace = " ";
|
|
238
|
+
if (draft.exportClause.kind == tree_1.JS.Kind.NamedExports) {
|
|
239
|
+
const ne = draft.exportClause;
|
|
240
|
+
if (ne.elements.elements.length > 0) {
|
|
241
|
+
// Check if this is a multi-line export (any element's prefix has a newline)
|
|
242
|
+
const isMultiLine = ne.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
|
|
243
|
+
if (!isMultiLine) {
|
|
244
|
+
// Single-line: adjust brace spacing
|
|
245
|
+
ne.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
|
|
246
|
+
ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// Multi-line: apply beforeComma rule to last element's after (for trailing commas)
|
|
250
|
+
// If it has only spaces (no newline), it's the space before a trailing comma
|
|
251
|
+
const lastAfter = ne.elements.elements[ne.elements.elements.length - 1].after.whitespace;
|
|
252
|
+
if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
|
|
253
|
+
ne.elements.elements[ne.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
|
|
315
254
|
}
|
|
316
255
|
}
|
|
317
256
|
}
|
|
318
257
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
258
|
+
}
|
|
259
|
+
draft.typeOnly.before.whitespace = draft.typeOnly.element ? " " : "";
|
|
260
|
+
if (draft.moduleSpecifier) {
|
|
261
|
+
draft.moduleSpecifier.before.whitespace = " ";
|
|
262
|
+
draft.moduleSpecifier.element.prefix.whitespace = " ";
|
|
263
|
+
}
|
|
325
264
|
});
|
|
326
265
|
}
|
|
327
|
-
visitForLoop(forLoop, p) {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (oneInit.element.kind === java_1.J.Kind.VariableDeclarations) {
|
|
337
|
-
const vd = oneInit.element;
|
|
338
|
-
if (vd.modifiers && vd.modifiers.length > 0) {
|
|
339
|
-
vd.modifiers[0].prefix.whitespace = "";
|
|
340
|
-
}
|
|
266
|
+
async visitForLoop(forLoop, p) {
|
|
267
|
+
const ret = await super.visitForLoop(forLoop, p);
|
|
268
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
269
|
+
draft.control.prefix.whitespace = this.style.beforeParentheses.forParentheses ? " " : "";
|
|
270
|
+
draft.control.init = await Promise.all(draft.control.init.map(async (oneInit, index) => {
|
|
271
|
+
if (oneInit.element.kind === java_1.J.Kind.VariableDeclarations) {
|
|
272
|
+
const vd = oneInit.element;
|
|
273
|
+
if (vd.modifiers && vd.modifiers.length > 0) {
|
|
274
|
+
vd.modifiers[0].prefix.whitespace = "";
|
|
341
275
|
}
|
|
342
|
-
oneInit.after.whitespace = "";
|
|
343
|
-
this.spaceBeforeRightPaddedElementDraft(oneInit, index === 0 ? this.style.within.forParentheses : true);
|
|
344
|
-
return oneInit;
|
|
345
|
-
})));
|
|
346
|
-
if (draft.control.condition) {
|
|
347
|
-
draft.control.condition.element.prefix.whitespace = " ";
|
|
348
|
-
draft.control.condition.after.whitespace = this.style.other.beforeForSemicolon ? " " : "";
|
|
349
276
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.forLeftBrace);
|
|
355
|
-
this.spaceAfterRightPaddedDraft(draft.body, false);
|
|
277
|
+
oneInit.after.whitespace = "";
|
|
278
|
+
this.spaceBeforeRightPaddedElementDraft(oneInit, index === 0 ? this.style.within.forParentheses : true);
|
|
279
|
+
return oneInit;
|
|
356
280
|
}));
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
281
|
+
if (draft.control.condition) {
|
|
282
|
+
draft.control.condition.element.prefix.whitespace = " ";
|
|
283
|
+
draft.control.condition.after.whitespace = this.style.other.beforeForSemicolon ? " " : "";
|
|
284
|
+
}
|
|
285
|
+
draft.control.update.forEach((oneUpdate, index) => {
|
|
286
|
+
oneUpdate.element.prefix.whitespace = " ";
|
|
287
|
+
oneUpdate.after.whitespace = (index === draft.control.update.length - 1 ? this.style.within.forParentheses : this.style.other.beforeForSemicolon) ? " " : "";
|
|
288
|
+
});
|
|
289
|
+
this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.forLeftBrace);
|
|
290
|
+
this.spaceAfterRightPaddedDraft(draft.body, false);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async visitIf(iff, p) {
|
|
294
|
+
const ret = await super.visitIf(iff, p);
|
|
295
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
296
|
+
this.spaceBeforeDraft(draft.ifCondition, this.style.beforeParentheses.ifParentheses);
|
|
297
|
+
this.spaceBeforeRightPaddedElementDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
|
|
298
|
+
this.spaceAfterRightPaddedDraft(draft.ifCondition.tree, this.style.within.ifParentheses);
|
|
299
|
+
this.spaceBeforeRightPaddedElementDraft(draft.thenPart, this.style.beforeLeftBrace.ifLeftBrace);
|
|
300
|
+
this.spaceAfterRightPaddedDraft(draft.thenPart, false);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
async visitImportDeclaration(jsImport, p) {
|
|
304
|
+
const ret = await super.visitImportDeclaration(jsImport, p);
|
|
305
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
306
|
+
if (draft.importClause) {
|
|
307
|
+
// Space after 'import' keyword:
|
|
308
|
+
// - If there's a default import (name), space goes in importClause.prefix
|
|
309
|
+
// - If typeOnly (import type ...), space goes in importClause.prefix (before 'type')
|
|
310
|
+
// - If only namedBindings (no default, no type), space goes in namedBindings.prefix (importClause.prefix is empty)
|
|
311
|
+
const hasDefaultImport = !!draft.importClause.name;
|
|
312
|
+
draft.importClause.prefix.whitespace = (hasDefaultImport || draft.importClause.typeOnly) ? " " : "";
|
|
313
|
+
if (draft.importClause.name) {
|
|
314
|
+
// For import equals declarations (import X = Y), use assignment spacing
|
|
315
|
+
// For regular imports (import X from 'Y'), no space after name
|
|
316
|
+
draft.importClause.name.after.whitespace = draft.initializer
|
|
317
|
+
? (this.style.aroundOperators.assignment ? " " : "")
|
|
318
|
+
: "";
|
|
319
|
+
}
|
|
320
|
+
if (draft.importClause.namedBindings) {
|
|
321
|
+
// Space before namedBindings - always needed
|
|
322
|
+
draft.importClause.namedBindings.prefix.whitespace = " ";
|
|
323
|
+
if (draft.importClause.namedBindings.kind == tree_1.JS.Kind.NamedImports) {
|
|
324
|
+
const ni = draft.importClause.namedBindings;
|
|
325
|
+
// Check if this is a multi-line import (any element's prefix has a newline)
|
|
326
|
+
const isMultiLine = ni.elements.elements.some(e => e.element.prefix.whitespace.includes("\n"));
|
|
327
|
+
if (!isMultiLine) {
|
|
328
|
+
// Single-line: adjust brace spacing
|
|
329
|
+
ni.elements.elements[0].element.prefix.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
|
|
330
|
+
ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.within.es6ImportExportBraces ? " " : "";
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
// Multi-line: apply beforeComma rule to last element's after (for trailing commas)
|
|
334
|
+
// If it has only spaces (no newline), it's the space before a trailing comma
|
|
335
|
+
const lastAfter = ni.elements.elements[ni.elements.elements.length - 1].after.whitespace;
|
|
336
|
+
if (!lastAfter.includes("\n") && lastAfter.trim() === "") {
|
|
337
|
+
ni.elements.elements[ni.elements.elements.length - 1].after.whitespace = this.style.other.beforeComma ? " " : "";
|
|
414
338
|
}
|
|
415
339
|
}
|
|
416
340
|
}
|
|
417
341
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
visitIndexSignatureDeclaration(indexSignatureDeclaration, p) {
|
|
426
|
-
const _super = Object.create(null, {
|
|
427
|
-
visitIndexSignatureDeclaration: { get: () => super.visitIndexSignatureDeclaration }
|
|
428
|
-
});
|
|
429
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
-
const ret = yield _super.visitIndexSignatureDeclaration.call(this, indexSignatureDeclaration, p);
|
|
431
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
432
|
-
draft.typeExpression.before.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
|
|
433
|
-
draft.typeExpression.element.prefix.whitespace = this.style.other.afterTypeReferenceColon ? " " : "";
|
|
434
|
-
});
|
|
342
|
+
}
|
|
343
|
+
if (draft.moduleSpecifier) {
|
|
344
|
+
draft.moduleSpecifier.before.whitespace = " ";
|
|
345
|
+
draft.moduleSpecifier.element.prefix.whitespace = draft.importClause ? " " : "";
|
|
346
|
+
}
|
|
435
347
|
});
|
|
436
348
|
}
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const ret = yield _super.visitMethodDeclaration.call(this, methodDecl, p);
|
|
443
|
-
return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
444
|
-
if (draft.body) {
|
|
445
|
-
this.spaceBeforeDraft(draft.body, this.style.beforeLeftBrace.functionLeftBrace);
|
|
446
|
-
}
|
|
447
|
-
if (draft.parameters.elements.length > 0 && draft.parameters.elements[0].element.kind != java_1.J.Kind.Empty) {
|
|
448
|
-
draft.parameters.elements.forEach((param, index) => {
|
|
449
|
-
this.spaceAfterRightPaddedDraft(param, index === draft.parameters.elements.length - 1 ? this.style.within.functionDeclarationParentheses : this.style.other.beforeComma);
|
|
450
|
-
this.spaceBeforeDraft(param.element, index === 0 ? this.style.within.functionDeclarationParentheses : this.style.other.afterComma);
|
|
451
|
-
param.element.variables[0].element.name.prefix.whitespace = "";
|
|
452
|
-
param.element.variables[0].after.whitespace = "";
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
else if (draft.parameters.elements.length == 1) {
|
|
456
|
-
this.spaceBeforeRightPaddedElementDraft(draft.parameters.elements[0], this.style.within.functionDeclarationParentheses);
|
|
457
|
-
this.spaceAfterRightPaddedDraft(draft.parameters.elements[0], false);
|
|
458
|
-
}
|
|
459
|
-
this.spaceBeforeContainerDraft(draft.parameters, this.style.beforeParentheses.functionDeclarationParentheses);
|
|
460
|
-
// Handle generator asterisk spacing
|
|
461
|
-
// - space before * is in the Generator marker's prefix
|
|
462
|
-
// - space after * is in the method name's prefix
|
|
463
|
-
const generatorIndex = ret.markers.markers.findIndex(m => m.kind === tree_1.JS.Markers.Generator);
|
|
464
|
-
if (generatorIndex >= 0) {
|
|
465
|
-
const generator = draft.markers.markers[generatorIndex];
|
|
466
|
-
generator.prefix.whitespace = this.style.other.beforeAsteriskInGenerator ? " " : "";
|
|
467
|
-
draft.name.prefix.whitespace = this.style.other.afterAsteriskInGenerator ? " " : "";
|
|
468
|
-
}
|
|
469
|
-
// TODO typeParameters handling - see visitClassDeclaration
|
|
470
|
-
}));
|
|
349
|
+
async visitIndexSignatureDeclaration(indexSignatureDeclaration, p) {
|
|
350
|
+
const ret = await super.visitIndexSignatureDeclaration(indexSignatureDeclaration, p);
|
|
351
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
352
|
+
draft.typeExpression.before.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
|
|
353
|
+
draft.typeExpression.element.prefix.whitespace = this.style.other.afterTypeReferenceColon ? " " : "";
|
|
471
354
|
});
|
|
472
355
|
}
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
this.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
356
|
+
async visitMethodDeclaration(methodDecl, p) {
|
|
357
|
+
const ret = await super.visitMethodDeclaration(methodDecl, p);
|
|
358
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
359
|
+
if (draft.body) {
|
|
360
|
+
this.spaceBeforeDraft(draft.body, this.style.beforeLeftBrace.functionLeftBrace);
|
|
361
|
+
}
|
|
362
|
+
if (draft.parameters.elements.length > 0 && draft.parameters.elements[0].element.kind != java_1.J.Kind.Empty) {
|
|
363
|
+
draft.parameters.elements.forEach((param, index) => {
|
|
364
|
+
this.spaceAfterRightPaddedDraft(param, index === draft.parameters.elements.length - 1 ? this.style.within.functionDeclarationParentheses : this.style.other.beforeComma);
|
|
365
|
+
this.spaceBeforeDraft(param.element, index === 0 ? this.style.within.functionDeclarationParentheses : this.style.other.afterComma);
|
|
366
|
+
param.element.variables[0].element.name.prefix.whitespace = "";
|
|
367
|
+
param.element.variables[0].after.whitespace = "";
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
else if (draft.parameters.elements.length == 1) {
|
|
371
|
+
this.spaceBeforeRightPaddedElementDraft(draft.parameters.elements[0], this.style.within.functionDeclarationParentheses);
|
|
372
|
+
this.spaceAfterRightPaddedDraft(draft.parameters.elements[0], false);
|
|
373
|
+
}
|
|
374
|
+
this.spaceBeforeContainerDraft(draft.parameters, this.style.beforeParentheses.functionDeclarationParentheses);
|
|
375
|
+
// Handle generator asterisk spacing
|
|
376
|
+
// - space before * is in the Generator marker's prefix
|
|
377
|
+
// - space after * is in the method name's prefix
|
|
378
|
+
const generatorIndex = ret.markers.markers.findIndex(m => m.kind === tree_1.JS.Markers.Generator);
|
|
379
|
+
if (generatorIndex >= 0) {
|
|
380
|
+
const generator = draft.markers.markers[generatorIndex];
|
|
381
|
+
generator.prefix.whitespace = this.style.other.beforeAsteriskInGenerator ? " " : "";
|
|
382
|
+
draft.name.prefix.whitespace = this.style.other.afterAsteriskInGenerator ? " " : "";
|
|
383
|
+
}
|
|
384
|
+
// TODO typeParameters handling - see visitClassDeclaration
|
|
495
385
|
});
|
|
496
386
|
}
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
387
|
+
async visitMethodInvocation(methodInv, p) {
|
|
388
|
+
const ret = await super.visitMethodInvocation(methodInv, p);
|
|
389
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
390
|
+
if (draft.select) {
|
|
391
|
+
this.spaceBeforeContainerDraft(draft.arguments, this.style.beforeParentheses.functionCallParentheses);
|
|
392
|
+
}
|
|
393
|
+
if (ret.arguments.elements.length > 0 && ret.arguments.elements[0].element.kind != java_1.J.Kind.Empty) {
|
|
394
|
+
draft.arguments.elements.forEach((arg, index) => {
|
|
395
|
+
this.spaceAfterRightPaddedDraft(arg, index === draft.arguments.elements.length - 1 ? this.style.within.functionCallParentheses : this.style.other.beforeComma);
|
|
396
|
+
this.spaceBeforeDraft(arg.element, index === 0 ? this.style.within.functionCallParentheses : this.style.other.afterComma);
|
|
507
397
|
});
|
|
508
398
|
}
|
|
509
|
-
|
|
399
|
+
else if (ret.arguments.elements.length == 1) {
|
|
400
|
+
this.spaceBeforeRightPaddedElementDraft(draft.arguments.elements[0], this.style.within.functionCallParentheses);
|
|
401
|
+
this.spaceAfterRightPaddedDraft(draft.arguments.elements[0], false);
|
|
402
|
+
}
|
|
403
|
+
// TODO typeParameters handling - see visitClassDeclaration
|
|
510
404
|
});
|
|
511
405
|
}
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
406
|
+
async visitPropertyAssignment(propertyAssignment, p) {
|
|
407
|
+
const pa = await super.visitPropertyAssignment(propertyAssignment, p);
|
|
408
|
+
// Only adjust the space before the colon/equals if there's an initializer (not a shorthand property)
|
|
409
|
+
if (pa.initializer) {
|
|
410
|
+
return (0, visitor_2.produceAsync)(pa, draft => {
|
|
411
|
+
draft.name.after.whitespace = this.style.other.beforePropertyNameValueSeparator ? " " : "";
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return pa;
|
|
415
|
+
}
|
|
416
|
+
async visitSwitch(switchNode, p) {
|
|
417
|
+
const ret = await super.visitSwitch(switchNode, p);
|
|
418
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
419
|
+
this.spaceBeforeDraft(draft.selector, this.style.beforeParentheses.switchParentheses);
|
|
420
|
+
this.spaceBeforeRightPaddedElementDraft(draft.selector.tree, this.style.within.switchParentheses);
|
|
421
|
+
this.spaceAfterRightPaddedDraft(draft.selector.tree, this.style.within.switchParentheses);
|
|
422
|
+
this.spaceBeforeDraft(draft.cases, this.style.beforeLeftBrace.switchLeftBrace);
|
|
423
|
+
for (const case_ of draft.cases.statements) {
|
|
424
|
+
if (case_.element.kind === java_1.J.Kind.Case) {
|
|
425
|
+
case_.element.caseLabels.elements[0].after.whitespace = "";
|
|
527
426
|
}
|
|
528
|
-
}
|
|
427
|
+
}
|
|
529
428
|
});
|
|
530
429
|
}
|
|
531
|
-
visitTernary(ternary, p) {
|
|
532
|
-
const
|
|
533
|
-
|
|
430
|
+
async visitTernary(ternary, p) {
|
|
431
|
+
const ret = await super.visitTernary(ternary, p);
|
|
432
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
433
|
+
this.spaceBeforeLeftPaddedElementDraft(draft.truePart, this.style.ternaryOperator.beforeQuestionMark, this.style.ternaryOperator.afterQuestionMark);
|
|
434
|
+
this.spaceBeforeLeftPaddedElementDraft(draft.falsePart, this.style.ternaryOperator.beforeColon, this.style.ternaryOperator.afterColon);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
async visitTry(try_, p) {
|
|
438
|
+
const ret = await super.visitTry(try_, p);
|
|
439
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
440
|
+
draft.body.prefix.whitespace = this.style.beforeLeftBrace.tryLeftBrace ? " " : "";
|
|
441
|
+
draft.catches.forEach(catch_ => {
|
|
442
|
+
this.spaceBeforeDraft(catch_, this.style.beforeKeywords.catchKeyword);
|
|
443
|
+
catch_.parameter.prefix.whitespace = this.style.beforeParentheses.catchParentheses ? " " : "";
|
|
444
|
+
this.spaceBeforeRightPaddedElementDraft(catch_.parameter.tree, this.style.within.catchParentheses);
|
|
445
|
+
this.spaceAfterRightPaddedDraft(catch_.parameter.tree, this.style.within.catchParentheses);
|
|
446
|
+
if (catch_.parameter.tree.element.variables.length > 0) {
|
|
447
|
+
catch_.parameter.tree.element.variables[catch_.parameter.tree.element.variables.length - 1].after.whitespace = "";
|
|
448
|
+
}
|
|
449
|
+
catch_.body.prefix.whitespace = this.style.beforeLeftBrace.catchLeftBrace ? " " : "";
|
|
450
|
+
});
|
|
451
|
+
if (draft.finally) {
|
|
452
|
+
this.spaceBeforeLeftPaddedElementDraft(draft.finally, this.style.beforeKeywords.finallyKeyword, this.style.beforeLeftBrace.finallyLeftBrace);
|
|
453
|
+
}
|
|
534
454
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
455
|
+
}
|
|
456
|
+
async visitTypeDeclaration(typeDeclaration, p) {
|
|
457
|
+
const ret = await super.visitTypeDeclaration(typeDeclaration, p);
|
|
458
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
459
|
+
if (draft.modifiers.length > 0) {
|
|
460
|
+
draft.name.before.whitespace = " ";
|
|
461
|
+
}
|
|
462
|
+
draft.name.element.prefix.whitespace = " ";
|
|
463
|
+
// Preserve newlines - only modify if no newlines present
|
|
464
|
+
if (!draft.initializer.before.whitespace.includes("\n")) {
|
|
465
|
+
draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
466
|
+
}
|
|
467
|
+
if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
|
|
468
|
+
draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
469
|
+
}
|
|
541
470
|
});
|
|
542
471
|
}
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
|
|
472
|
+
async visitTypeInfo(typeInfo, p) {
|
|
473
|
+
const ret = await super.visitTypeInfo(typeInfo, p);
|
|
474
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
475
|
+
draft.prefix.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
|
|
476
|
+
this.spaceBeforeDraft(draft.typeIdentifier, this.style.other.afterTypeReferenceColon);
|
|
546
477
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
478
|
+
}
|
|
479
|
+
async visitTypeLiteral(typeLiteral, p) {
|
|
480
|
+
const ret = await super.visitTypeLiteral(typeLiteral, p);
|
|
481
|
+
// Apply objectLiteralTypeBraces spacing for single-line type literals
|
|
482
|
+
if (ret.members && ret.members.statements.length > 0) {
|
|
483
|
+
const stmts = ret.members.statements;
|
|
484
|
+
const isSingleLine = !ret.members.end.whitespace.includes("\n") &&
|
|
485
|
+
stmts.every(s => !s.element.prefix.whitespace.includes("\n"));
|
|
486
|
+
if (isSingleLine) {
|
|
487
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
488
|
+
const space = this.style.within.objectLiteralTypeBraces ? " " : "";
|
|
489
|
+
draft.members.statements[0].element.prefix.whitespace = space;
|
|
490
|
+
// For type literals, the space before } is in members.end, not in last statement's after
|
|
491
|
+
draft.members.end.whitespace = space;
|
|
560
492
|
});
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return ret;
|
|
496
|
+
}
|
|
497
|
+
async visitUnary(unary, p) {
|
|
498
|
+
const ret = await super.visitUnary(unary, p);
|
|
499
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
500
|
+
const spacing = this.style.aroundOperators.unary;
|
|
501
|
+
switch (draft.operator.element) {
|
|
502
|
+
case java_1.J.Unary.Type.Not:
|
|
503
|
+
draft.expression.prefix.whitespace = this.style.aroundOperators.afterUnaryNotAndNotNull ? " " : "";
|
|
504
|
+
break;
|
|
505
|
+
case java_1.J.Unary.Type.PreIncrement:
|
|
506
|
+
case java_1.J.Unary.Type.PreDecrement:
|
|
507
|
+
case java_1.J.Unary.Type.Negative:
|
|
508
|
+
case java_1.J.Unary.Type.Positive:
|
|
509
|
+
case java_1.J.Unary.Type.Complement:
|
|
510
|
+
draft.expression.prefix.whitespace = spacing ? " " : "";
|
|
511
|
+
break;
|
|
512
|
+
case java_1.J.Unary.Type.PostIncrement:
|
|
513
|
+
case java_1.J.Unary.Type.PostDecrement:
|
|
514
|
+
// postfix: don't add space after operand
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
565
517
|
});
|
|
566
518
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
draft.name.element.prefix.whitespace = " ";
|
|
519
|
+
async visitVariable(variable, p) {
|
|
520
|
+
var _a, _b;
|
|
521
|
+
const ret = await super.visitVariable(variable, p);
|
|
522
|
+
if (((_b = (_a = variable.initializer) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.kind) == tree_1.JS.Kind.StatementExpression
|
|
523
|
+
&& variable.initializer.element.statement.kind == java_1.J.Kind.MethodDeclaration) {
|
|
524
|
+
return ret;
|
|
525
|
+
}
|
|
526
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
527
|
+
if (draft.initializer) {
|
|
578
528
|
// Preserve newlines - only modify if no newlines present
|
|
579
529
|
if (!draft.initializer.before.whitespace.includes("\n")) {
|
|
580
530
|
draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
@@ -582,136 +532,40 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
582
532
|
if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
|
|
583
533
|
draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
584
534
|
}
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
visitTypeInfo(typeInfo, p) {
|
|
589
|
-
const _super = Object.create(null, {
|
|
590
|
-
visitTypeInfo: { get: () => super.visitTypeInfo }
|
|
591
|
-
});
|
|
592
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
-
const ret = yield _super.visitTypeInfo.call(this, typeInfo, p);
|
|
594
|
-
return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
595
|
-
draft.prefix.whitespace = this.style.other.beforeTypeReferenceColon ? " " : "";
|
|
596
|
-
this.spaceBeforeDraft(draft.typeIdentifier, this.style.other.afterTypeReferenceColon);
|
|
597
|
-
}));
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
visitTypeLiteral(typeLiteral, p) {
|
|
601
|
-
const _super = Object.create(null, {
|
|
602
|
-
visitTypeLiteral: { get: () => super.visitTypeLiteral }
|
|
603
|
-
});
|
|
604
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
605
|
-
const ret = yield _super.visitTypeLiteral.call(this, typeLiteral, p);
|
|
606
|
-
// Apply objectLiteralTypeBraces spacing for single-line type literals
|
|
607
|
-
if (ret.members && ret.members.statements.length > 0) {
|
|
608
|
-
const stmts = ret.members.statements;
|
|
609
|
-
const isSingleLine = !ret.members.end.whitespace.includes("\n") &&
|
|
610
|
-
stmts.every(s => !s.element.prefix.whitespace.includes("\n"));
|
|
611
|
-
if (isSingleLine) {
|
|
612
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
613
|
-
const space = this.style.within.objectLiteralTypeBraces ? " " : "";
|
|
614
|
-
draft.members.statements[0].element.prefix.whitespace = space;
|
|
615
|
-
// For type literals, the space before } is in members.end, not in last statement's after
|
|
616
|
-
draft.members.end.whitespace = space;
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
535
|
}
|
|
620
|
-
return ret;
|
|
621
536
|
});
|
|
622
537
|
}
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
visitVariable(variable, p) {
|
|
651
|
-
const _super = Object.create(null, {
|
|
652
|
-
visitVariable: { get: () => super.visitVariable }
|
|
653
|
-
});
|
|
654
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
655
|
-
var _a, _b;
|
|
656
|
-
const ret = yield _super.visitVariable.call(this, variable, p);
|
|
657
|
-
if (((_b = (_a = variable.initializer) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.kind) == tree_1.JS.Kind.StatementExpression
|
|
658
|
-
&& variable.initializer.element.statement.kind == java_1.J.Kind.MethodDeclaration) {
|
|
659
|
-
return ret;
|
|
660
|
-
}
|
|
661
|
-
return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
662
|
-
if (draft.initializer) {
|
|
663
|
-
// Preserve newlines - only modify if no newlines present
|
|
664
|
-
if (!draft.initializer.before.whitespace.includes("\n")) {
|
|
665
|
-
draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
666
|
-
}
|
|
667
|
-
if (!draft.initializer.element.prefix.whitespace.includes("\n")) {
|
|
668
|
-
draft.initializer.element.prefix.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
538
|
+
async visitWhileLoop(whileLoop, p) {
|
|
539
|
+
const ret = await super.visitWhileLoop(whileLoop, p);
|
|
540
|
+
return (0, visitor_2.produceAsync)(ret, async (draft) => {
|
|
541
|
+
this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.whileLeftBrace);
|
|
542
|
+
this.spaceAfterRightPaddedDraft(draft.body, false);
|
|
543
|
+
this.spaceBeforeDraft(draft.condition, this.style.beforeParentheses.whileParentheses);
|
|
544
|
+
this.spaceBeforeRightPaddedElementDraft(draft.condition.tree, this.style.within.whileParentheses);
|
|
545
|
+
this.spaceAfterRightPaddedDraft(draft.condition.tree, this.style.within.whileParentheses);
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
async visitTypeParameter(typeParam, p) {
|
|
549
|
+
const ret = await super.visitTypeParameter(typeParam, p);
|
|
550
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
551
|
+
if (draft.bounds && draft.bounds.elements.length >= 2) {
|
|
552
|
+
const constraintType = draft.bounds.elements[0];
|
|
553
|
+
const defaultType = draft.bounds.elements[1];
|
|
554
|
+
const hasConstraint = constraintType.element.kind !== java_1.J.Kind.Empty;
|
|
555
|
+
const hasDefault = defaultType.element.kind !== java_1.J.Kind.Empty;
|
|
556
|
+
if (hasConstraint) {
|
|
557
|
+
// Space before '=' for default type (in the `after` of constraint type)
|
|
558
|
+
if (hasDefault && !constraintType.after.whitespace.includes("\n")) {
|
|
559
|
+
constraintType.after.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
669
560
|
}
|
|
670
561
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const _super = Object.create(null, {
|
|
676
|
-
visitWhileLoop: { get: () => super.visitWhileLoop }
|
|
677
|
-
});
|
|
678
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
679
|
-
const ret = yield _super.visitWhileLoop.call(this, whileLoop, p);
|
|
680
|
-
return (0, visitor_2.produceAsync)(ret, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
681
|
-
this.spaceBeforeRightPaddedElementDraft(draft.body, this.style.beforeLeftBrace.whileLeftBrace);
|
|
682
|
-
this.spaceAfterRightPaddedDraft(draft.body, false);
|
|
683
|
-
this.spaceBeforeDraft(draft.condition, this.style.beforeParentheses.whileParentheses);
|
|
684
|
-
this.spaceBeforeRightPaddedElementDraft(draft.condition.tree, this.style.within.whileParentheses);
|
|
685
|
-
this.spaceAfterRightPaddedDraft(draft.condition.tree, this.style.within.whileParentheses);
|
|
686
|
-
}));
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
visitTypeParameter(typeParam, p) {
|
|
690
|
-
const _super = Object.create(null, {
|
|
691
|
-
visitTypeParameter: { get: () => super.visitTypeParameter }
|
|
692
|
-
});
|
|
693
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
694
|
-
const ret = yield _super.visitTypeParameter.call(this, typeParam, p);
|
|
695
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
696
|
-
if (draft.bounds && draft.bounds.elements.length >= 2) {
|
|
697
|
-
const constraintType = draft.bounds.elements[0];
|
|
698
|
-
const defaultType = draft.bounds.elements[1];
|
|
699
|
-
const hasConstraint = constraintType.element.kind !== java_1.J.Kind.Empty;
|
|
700
|
-
const hasDefault = defaultType.element.kind !== java_1.J.Kind.Empty;
|
|
701
|
-
if (hasConstraint) {
|
|
702
|
-
// Space before '=' for default type (in the `after` of constraint type)
|
|
703
|
-
if (hasDefault && !constraintType.after.whitespace.includes("\n")) {
|
|
704
|
-
constraintType.after.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
else if (hasDefault) {
|
|
708
|
-
// No constraint, just default: space before '=' is in bounds.before
|
|
709
|
-
if (!draft.bounds.before.whitespace.includes("\n")) {
|
|
710
|
-
draft.bounds.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
711
|
-
}
|
|
562
|
+
else if (hasDefault) {
|
|
563
|
+
// No constraint, just default: space before '=' is in bounds.before
|
|
564
|
+
if (!draft.bounds.before.whitespace.includes("\n")) {
|
|
565
|
+
draft.bounds.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
|
|
712
566
|
}
|
|
713
567
|
}
|
|
714
|
-
}
|
|
568
|
+
}
|
|
715
569
|
});
|
|
716
570
|
}
|
|
717
571
|
/**
|
|
@@ -804,33 +658,28 @@ class SpacesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
804
658
|
static isNotSingleSpace(str) {
|
|
805
659
|
return this.isOnlySpaces(str) && str !== " ";
|
|
806
660
|
}
|
|
807
|
-
visitNewClass(newClass, p) {
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
812
|
-
const ret = yield _super.visitNewClass.call(this, newClass, p);
|
|
813
|
-
// Only handle object literals (NewClass with no class/constructor)
|
|
814
|
-
if (ret.class) {
|
|
815
|
-
return ret;
|
|
816
|
-
}
|
|
817
|
-
// Handle object literal brace spacing: { foo: 1 } vs {foo: 1}
|
|
818
|
-
if (ret.body && ret.body.statements.length > 0) {
|
|
819
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
820
|
-
const stmts = draft.body.statements;
|
|
821
|
-
// Check if this is a multi-line object literal
|
|
822
|
-
const isMultiLine = stmts.some(s => s.element.prefix.whitespace.includes("\n")) ||
|
|
823
|
-
draft.body.end.whitespace.includes("\n");
|
|
824
|
-
if (!isMultiLine) {
|
|
825
|
-
// Single-line: apply objectLiteralBraces spacing
|
|
826
|
-
const space = this.style.within.objectLiteralBraces ? " " : "";
|
|
827
|
-
stmts[0].element.prefix.whitespace = space;
|
|
828
|
-
draft.body.end.whitespace = space;
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
}
|
|
661
|
+
async visitNewClass(newClass, p) {
|
|
662
|
+
const ret = await super.visitNewClass(newClass, p);
|
|
663
|
+
// Only handle object literals (NewClass with no class/constructor)
|
|
664
|
+
if (ret.class) {
|
|
832
665
|
return ret;
|
|
833
|
-
}
|
|
666
|
+
}
|
|
667
|
+
// Handle object literal brace spacing: { foo: 1 } vs {foo: 1}
|
|
668
|
+
if (ret.body && ret.body.statements.length > 0) {
|
|
669
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
670
|
+
const stmts = draft.body.statements;
|
|
671
|
+
// Check if this is a multi-line object literal
|
|
672
|
+
const isMultiLine = stmts.some(s => s.element.prefix.whitespace.includes("\n")) ||
|
|
673
|
+
draft.body.end.whitespace.includes("\n");
|
|
674
|
+
if (!isMultiLine) {
|
|
675
|
+
// Single-line: apply objectLiteralBraces spacing
|
|
676
|
+
const space = this.style.within.objectLiteralBraces ? " " : "";
|
|
677
|
+
stmts[0].element.prefix.whitespace = space;
|
|
678
|
+
draft.body.end.whitespace = space;
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
return ret;
|
|
834
683
|
}
|
|
835
684
|
}
|
|
836
685
|
exports.SpacesVisitor = SpacesVisitor;
|
|
@@ -840,190 +689,150 @@ class WrappingAndBracesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
840
689
|
this.style = style;
|
|
841
690
|
this.stopAfter = stopAfter;
|
|
842
691
|
}
|
|
843
|
-
visit(tree, p, parent) {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
|
|
850
|
-
return tree;
|
|
851
|
-
}
|
|
852
|
-
return _super.visit.call(this, tree, p, parent);
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
postVisit(tree, p) {
|
|
856
|
-
const _super = Object.create(null, {
|
|
857
|
-
postVisit: { get: () => super.postVisit }
|
|
858
|
-
});
|
|
859
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
860
|
-
var _a;
|
|
861
|
-
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
862
|
-
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
863
|
-
}
|
|
864
|
-
return _super.postVisit.call(this, tree, p);
|
|
865
|
-
});
|
|
692
|
+
async visit(tree, p, parent) {
|
|
693
|
+
var _a;
|
|
694
|
+
if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
|
|
695
|
+
return tree;
|
|
696
|
+
}
|
|
697
|
+
return super.visit(tree, p, parent);
|
|
866
698
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const v = yield _super.visitVariableDeclarations.call(this, multiVariable, p);
|
|
874
|
-
const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
|
|
875
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
|
|
876
|
-
return (0, mutative_1.create)(v, draft => {
|
|
877
|
-
draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
|
|
878
|
-
if (draft.leadingAnnotations.length > 0) {
|
|
879
|
-
if (draft.modifiers.length > 0) {
|
|
880
|
-
draft.modifiers = this.withNewlineModifiers(draft.modifiers);
|
|
881
|
-
}
|
|
882
|
-
else if (draft.typeExpression && !draft.typeExpression.prefix.whitespace.includes("\n")) {
|
|
883
|
-
draft.typeExpression.prefix.whitespace = "\n" + draft.typeExpression.prefix.whitespace;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
return v;
|
|
889
|
-
});
|
|
699
|
+
async postVisit(tree, p) {
|
|
700
|
+
var _a;
|
|
701
|
+
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
702
|
+
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
703
|
+
}
|
|
704
|
+
return super.postVisit(tree, p);
|
|
890
705
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
return (0, mutative_1.create)(m, draft => {
|
|
706
|
+
async visitVariableDeclarations(multiVariable, p) {
|
|
707
|
+
var _a;
|
|
708
|
+
const v = await super.visitVariableDeclarations(multiVariable, p);
|
|
709
|
+
const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
|
|
710
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
|
|
711
|
+
return (0, mutative_1.create)(v, draft => {
|
|
898
712
|
draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
|
|
899
713
|
if (draft.leadingAnnotations.length > 0) {
|
|
900
714
|
if (draft.modifiers.length > 0) {
|
|
901
715
|
draft.modifiers = this.withNewlineModifiers(draft.modifiers);
|
|
902
716
|
}
|
|
903
|
-
else if (draft.
|
|
904
|
-
draft.
|
|
905
|
-
}
|
|
906
|
-
else if (draft.returnTypeExpression && !draft.returnTypeExpression.prefix.whitespace.includes("\n")) {
|
|
907
|
-
draft.returnTypeExpression.prefix.whitespace = "\n" + draft.returnTypeExpression.prefix.whitespace;
|
|
908
|
-
}
|
|
909
|
-
else if (!draft.name.prefix.whitespace.includes("\n")) {
|
|
910
|
-
draft.name.prefix.whitespace = "\n" + draft.name.prefix.whitespace;
|
|
717
|
+
else if (draft.typeExpression && !draft.typeExpression.prefix.whitespace.includes("\n")) {
|
|
718
|
+
draft.typeExpression.prefix.whitespace = "\n" + draft.typeExpression.prefix.whitespace;
|
|
911
719
|
}
|
|
912
720
|
}
|
|
913
721
|
});
|
|
914
|
-
}
|
|
722
|
+
}
|
|
723
|
+
return v;
|
|
915
724
|
}
|
|
916
|
-
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
return (0, mutative_1.create)(e, draft => {
|
|
924
|
-
if (hasBody) {
|
|
925
|
-
const shouldHaveNewline = this.style.ifStatement.elseOnNewLine;
|
|
926
|
-
const hasNewline = draft.prefix.whitespace.includes("\n");
|
|
927
|
-
if (shouldHaveNewline && !hasNewline) {
|
|
928
|
-
draft.prefix.whitespace = "\n" + draft.prefix.whitespace;
|
|
929
|
-
}
|
|
930
|
-
else if (!shouldHaveNewline && hasNewline) {
|
|
931
|
-
draft.prefix.whitespace = "";
|
|
932
|
-
}
|
|
725
|
+
async visitMethodDeclaration(method, p) {
|
|
726
|
+
const m = await super.visitMethodDeclaration(method, p);
|
|
727
|
+
return (0, mutative_1.create)(m, draft => {
|
|
728
|
+
draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
|
|
729
|
+
if (draft.leadingAnnotations.length > 0) {
|
|
730
|
+
if (draft.modifiers.length > 0) {
|
|
731
|
+
draft.modifiers = this.withNewlineModifiers(draft.modifiers);
|
|
933
732
|
}
|
|
934
|
-
|
|
733
|
+
else if (draft.typeParameters && !draft.typeParameters.prefix.whitespace.includes("\n")) {
|
|
734
|
+
draft.typeParameters.prefix.whitespace = "\n" + draft.typeParameters.prefix.whitespace;
|
|
735
|
+
}
|
|
736
|
+
else if (draft.returnTypeExpression && !draft.returnTypeExpression.prefix.whitespace.includes("\n")) {
|
|
737
|
+
draft.returnTypeExpression.prefix.whitespace = "\n" + draft.returnTypeExpression.prefix.whitespace;
|
|
738
|
+
}
|
|
739
|
+
else if (!draft.name.prefix.whitespace.includes("\n")) {
|
|
740
|
+
draft.name.prefix.whitespace = "\n" + draft.name.prefix.whitespace;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
935
743
|
});
|
|
936
744
|
}
|
|
937
|
-
|
|
938
|
-
const
|
|
939
|
-
|
|
745
|
+
async visitElse(elsePart, p) {
|
|
746
|
+
const e = await super.visitElse(elsePart, p);
|
|
747
|
+
const hasBody = e.body.element.kind === java_1.J.Kind.Block || e.body.element.kind === java_1.J.Kind.If;
|
|
748
|
+
return (0, mutative_1.create)(e, draft => {
|
|
749
|
+
if (hasBody) {
|
|
750
|
+
const shouldHaveNewline = this.style.ifStatement.elseOnNewLine;
|
|
751
|
+
const hasNewline = draft.prefix.whitespace.includes("\n");
|
|
752
|
+
if (shouldHaveNewline && !hasNewline) {
|
|
753
|
+
draft.prefix.whitespace = "\n" + draft.prefix.whitespace;
|
|
754
|
+
}
|
|
755
|
+
else if (!shouldHaveNewline && hasNewline) {
|
|
756
|
+
draft.prefix.whitespace = "";
|
|
757
|
+
}
|
|
758
|
+
}
|
|
940
759
|
});
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
760
|
+
}
|
|
761
|
+
async visitClassDeclaration(classDecl, p) {
|
|
762
|
+
const j = await super.visitClassDeclaration(classDecl, p);
|
|
763
|
+
return (0, mutative_1.create)(j, draft => {
|
|
764
|
+
draft.leadingAnnotations = this.withNewlines(draft.leadingAnnotations);
|
|
765
|
+
if (draft.leadingAnnotations.length > 0) {
|
|
766
|
+
if (draft.modifiers.length > 0) {
|
|
767
|
+
draft.modifiers = this.withNewlineModifiers(draft.modifiers);
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
const kind = draft.classKind;
|
|
771
|
+
if (!kind.prefix.whitespace.includes("\n")) {
|
|
772
|
+
kind.prefix.whitespace = "\n" + kind.prefix.whitespace;
|
|
954
773
|
}
|
|
955
774
|
}
|
|
956
|
-
}
|
|
775
|
+
}
|
|
957
776
|
});
|
|
958
777
|
}
|
|
959
|
-
visitBlock(block, p) {
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
// Also remove newlines from statement padding if there's a J.Empty
|
|
978
|
-
if (draft.statements.length === 1) {
|
|
979
|
-
if (draft.statements[0].element.prefix.whitespace.includes("\n")) {
|
|
980
|
-
draft.statements[0].element.prefix.whitespace = "";
|
|
981
|
-
}
|
|
982
|
-
if (draft.statements[0].after.whitespace.includes("\n")) {
|
|
983
|
-
draft.statements[0].after.whitespace = "";
|
|
984
|
-
}
|
|
778
|
+
async visitBlock(block, p) {
|
|
779
|
+
const b = await super.visitBlock(block, p);
|
|
780
|
+
return (0, mutative_1.create)(b, draft => {
|
|
781
|
+
var _a;
|
|
782
|
+
const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
|
|
783
|
+
// Check if this is a "simple" block (empty or contains only a single J.Empty)
|
|
784
|
+
const isSimpleBlock = draft.statements.length === 0 ||
|
|
785
|
+
(draft.statements.length === 1 && draft.statements[0].element.kind === java_1.J.Kind.Empty);
|
|
786
|
+
// Helper to format block on one line
|
|
787
|
+
const formatOnOneLine = () => {
|
|
788
|
+
// Format as {} - remove any newlines from end whitespace
|
|
789
|
+
if (draft.end.whitespace.includes("\n")) {
|
|
790
|
+
draft.end.whitespace = draft.end.whitespace.replace(/\n\s*/g, "");
|
|
791
|
+
}
|
|
792
|
+
// Also remove newlines from statement padding if there's a J.Empty
|
|
793
|
+
if (draft.statements.length === 1) {
|
|
794
|
+
if (draft.statements[0].element.prefix.whitespace.includes("\n")) {
|
|
795
|
+
draft.statements[0].element.prefix.whitespace = "";
|
|
985
796
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
if (parentKind === java_1.J.Kind.NewClass || parentKind === tree_1.JS.Kind.TypeLiteral) {
|
|
989
|
-
if (isSimpleBlock) {
|
|
990
|
-
formatOnOneLine();
|
|
797
|
+
if (draft.statements[0].after.whitespace.includes("\n")) {
|
|
798
|
+
draft.statements[0].after.whitespace = "";
|
|
991
799
|
}
|
|
992
|
-
return;
|
|
993
800
|
}
|
|
801
|
+
};
|
|
802
|
+
// Object literals and type literals: always format empty ones as {} on single line
|
|
803
|
+
if (parentKind === java_1.J.Kind.NewClass || parentKind === tree_1.JS.Kind.TypeLiteral) {
|
|
994
804
|
if (isSimpleBlock) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
805
|
+
formatOnOneLine();
|
|
806
|
+
}
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (isSimpleBlock) {
|
|
810
|
+
// Determine which style option applies based on parent
|
|
811
|
+
const isMethodOrFunctionBody = parentKind === java_1.J.Kind.Lambda ||
|
|
812
|
+
parentKind === java_1.J.Kind.MethodDeclaration;
|
|
813
|
+
const keepInOneLine = isMethodOrFunctionBody
|
|
814
|
+
? this.style.keepWhenReformatting.simpleMethodsInOneLine
|
|
815
|
+
: this.style.keepWhenReformatting.simpleBlocksInOneLine;
|
|
816
|
+
if (keepInOneLine) {
|
|
817
|
+
formatOnOneLine();
|
|
1010
818
|
}
|
|
1011
819
|
else {
|
|
1012
|
-
//
|
|
1013
|
-
if (!draft.end.whitespace.includes("\n")
|
|
820
|
+
// Format with newline between { and }
|
|
821
|
+
if (!draft.end.whitespace.includes("\n")) {
|
|
1014
822
|
draft.end = this.withNewlineSpace(draft.end);
|
|
1015
823
|
}
|
|
1016
824
|
}
|
|
1017
|
-
}
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
// Non-simple blocks: ensure closing brace is on its own line
|
|
828
|
+
if (!draft.end.whitespace.includes("\n") && !draft.statements[draft.statements.length - 1].after.whitespace.includes("\n")) {
|
|
829
|
+
draft.end = this.withNewlineSpace(draft.end);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
1018
832
|
});
|
|
1019
833
|
}
|
|
1020
|
-
visitSwitch(aSwitch, p) {
|
|
1021
|
-
|
|
1022
|
-
visitSwitch: { get: () => super.visitSwitch }
|
|
1023
|
-
});
|
|
1024
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1025
|
-
return _super.visitSwitch.call(this, aSwitch, p);
|
|
1026
|
-
});
|
|
834
|
+
async visitSwitch(aSwitch, p) {
|
|
835
|
+
return super.visitSwitch(aSwitch, p);
|
|
1027
836
|
}
|
|
1028
837
|
withNewlines(list) {
|
|
1029
838
|
return list.map((a, index) => {
|
|
@@ -1070,161 +879,131 @@ class BlankLinesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
1070
879
|
this.style = style;
|
|
1071
880
|
this.stopAfter = stopAfter;
|
|
1072
881
|
}
|
|
1073
|
-
preVisit(tree, p) {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
882
|
+
async preVisit(tree, p) {
|
|
883
|
+
var _a, _b, _c;
|
|
884
|
+
let ret = await super.preVisit(tree, p);
|
|
885
|
+
if (ret.kind === tree_1.JS.Kind.CompilationUnit) {
|
|
886
|
+
ret = (0, mutative_1.create)(ret, draft => {
|
|
887
|
+
if (draft.prefix.comments.length == 0) {
|
|
888
|
+
draft.prefix.whitespace = "";
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
if (ret.kind === java_1.J.Kind.MethodDeclaration
|
|
893
|
+
&& ((_c = (_b = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value.kind) === java_1.J.Kind.ClassDeclaration) {
|
|
894
|
+
ret = (0, mutative_1.create)(ret, draft => {
|
|
895
|
+
this.ensurePrefixHasNewLine(draft);
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
return ret;
|
|
899
|
+
}
|
|
900
|
+
async visit(tree, p, cursor) {
|
|
901
|
+
var _a;
|
|
902
|
+
if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
|
|
903
|
+
return tree;
|
|
904
|
+
}
|
|
905
|
+
return super.visit(tree, p, cursor);
|
|
906
|
+
}
|
|
907
|
+
async visitClassDeclaration(classDecl, p) {
|
|
908
|
+
let ret = await super.visitClassDeclaration(classDecl, p);
|
|
909
|
+
if (!ret.body)
|
|
910
|
+
return ret;
|
|
911
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
1078
912
|
var _a, _b, _c;
|
|
1079
|
-
|
|
1080
|
-
if (
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
913
|
+
const statements = draft.body.statements;
|
|
914
|
+
if (statements.length > 0) {
|
|
915
|
+
this.keepMaximumBlankLines(draft.body.statements[0].element, 0);
|
|
916
|
+
const isInterface = draft.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface;
|
|
917
|
+
for (let i = 1; i < statements.length; i++) {
|
|
918
|
+
const previousElement = statements[i - 1].element;
|
|
919
|
+
let currentElement = statements[i].element;
|
|
920
|
+
if (previousElement.kind == java_1.J.Kind.VariableDeclarations || currentElement.kind == java_1.J.Kind.VariableDeclarations) {
|
|
921
|
+
const fieldBlankLines = isInterface
|
|
922
|
+
? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
|
|
923
|
+
: this.style.minimum.aroundField;
|
|
924
|
+
this.minimumBlankLines(currentElement, fieldBlankLines);
|
|
1084
925
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
926
|
+
if (previousElement.kind == java_1.J.Kind.MethodDeclaration || currentElement.kind == java_1.J.Kind.MethodDeclaration) {
|
|
927
|
+
const methodBlankLines = isInterface
|
|
928
|
+
? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
|
|
929
|
+
: this.style.minimum.aroundMethod;
|
|
930
|
+
this.minimumBlankLines(currentElement, methodBlankLines);
|
|
931
|
+
}
|
|
932
|
+
this.keepMaximumBlankLines(currentElement, this.style.keepMaximum.inCode);
|
|
933
|
+
draft.body.statements[i].element = currentElement;
|
|
934
|
+
}
|
|
1092
935
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
936
|
+
const cu = this.cursor.firstEnclosing((x) => x.kind === tree_1.JS.Kind.CompilationUnit);
|
|
937
|
+
const topLevelIndex = cu === null || cu === void 0 ? void 0 : cu.statements.findIndex(s => s.element.id == draft.id);
|
|
938
|
+
if (topLevelIndex !== undefined) {
|
|
939
|
+
const isImportJustBeforeThis = topLevelIndex > 0 && (cu === null || cu === void 0 ? void 0 : cu.statements[topLevelIndex - 1].element.kind) === tree_1.JS.Kind.Import;
|
|
940
|
+
if (isImportJustBeforeThis) {
|
|
941
|
+
this.minimumBlankLines(draft, (_c = this.style.minimum.afterImports) !== null && _c !== void 0 ? _c : 0);
|
|
942
|
+
}
|
|
943
|
+
if (topLevelIndex > 0) {
|
|
944
|
+
this.minimumBlankLines(draft, this.style.minimum.aroundClass);
|
|
945
|
+
}
|
|
946
|
+
this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
|
|
1104
947
|
}
|
|
1105
|
-
return _super.visit.call(this, tree, p, cursor);
|
|
1106
948
|
});
|
|
1107
949
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
const
|
|
1119
|
-
if (
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
if (previousElement.kind == java_1.J.Kind.VariableDeclarations || currentElement.kind == java_1.J.Kind.VariableDeclarations) {
|
|
1126
|
-
const fieldBlankLines = isInterface
|
|
1127
|
-
? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
|
|
1128
|
-
: this.style.minimum.aroundField;
|
|
1129
|
-
this.minimumBlankLines(currentElement, fieldBlankLines);
|
|
1130
|
-
}
|
|
1131
|
-
if (previousElement.kind == java_1.J.Kind.MethodDeclaration || currentElement.kind == java_1.J.Kind.MethodDeclaration) {
|
|
1132
|
-
const methodBlankLines = isInterface
|
|
1133
|
-
? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
|
|
1134
|
-
: this.style.minimum.aroundMethod;
|
|
1135
|
-
this.minimumBlankLines(currentElement, methodBlankLines);
|
|
1136
|
-
}
|
|
1137
|
-
this.keepMaximumBlankLines(currentElement, this.style.keepMaximum.inCode);
|
|
1138
|
-
draft.body.statements[i].element = currentElement;
|
|
950
|
+
async visitStatement(statement, p) {
|
|
951
|
+
var _a, _b, _c;
|
|
952
|
+
const ret = await super.visitStatement(statement, p);
|
|
953
|
+
const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
|
|
954
|
+
const grandparent = (_c = (_b = this.cursor.parentTree()) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value;
|
|
955
|
+
return (0, mutative_1.create)(ret, draft => {
|
|
956
|
+
var _a, _b;
|
|
957
|
+
if ((grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) === java_1.J.Kind.ClassDeclaration && (parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
|
|
958
|
+
const classDecl = grandparent;
|
|
959
|
+
const block = parent;
|
|
960
|
+
const isFirst = block.statements.length > 0 && block.statements[0].element.id === draft.id;
|
|
961
|
+
if (!isFirst) {
|
|
962
|
+
if (draft.kind === java_1.J.Kind.VariableDeclarations) {
|
|
963
|
+
const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
|
|
964
|
+
? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
|
|
965
|
+
: this.style.minimum.aroundField;
|
|
966
|
+
this.minimumBlankLines(draft, declMax);
|
|
1139
967
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
968
|
+
else if (draft.kind === java_1.J.Kind.MethodDeclaration) {
|
|
969
|
+
const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
|
|
970
|
+
? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
|
|
971
|
+
: this.style.minimum.aroundMethod;
|
|
972
|
+
this.minimumBlankLines(draft, declMax);
|
|
973
|
+
}
|
|
974
|
+
else if (draft.kind === java_1.J.Kind.Block) {
|
|
975
|
+
this.minimumBlankLines(draft, this.style.minimum.aroundFunction);
|
|
1147
976
|
}
|
|
1148
|
-
if (
|
|
977
|
+
else if (draft.kind === java_1.J.Kind.ClassDeclaration) {
|
|
1149
978
|
this.minimumBlankLines(draft, this.style.minimum.aroundClass);
|
|
1150
979
|
}
|
|
1151
980
|
this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
|
|
1152
981
|
}
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
});
|
|
1160
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1161
|
-
var _a, _b, _c;
|
|
1162
|
-
const ret = yield _super.visitStatement.call(this, statement, p);
|
|
1163
|
-
const parent = (_a = this.cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
|
|
1164
|
-
const grandparent = (_c = (_b = this.cursor.parentTree()) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.value;
|
|
1165
|
-
return (0, mutative_1.create)(ret, draft => {
|
|
1166
|
-
var _a, _b;
|
|
1167
|
-
if ((grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) === java_1.J.Kind.ClassDeclaration && (parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block) {
|
|
1168
|
-
const classDecl = grandparent;
|
|
1169
|
-
const block = parent;
|
|
1170
|
-
const isFirst = block.statements.length > 0 && block.statements[0].element.id === draft.id;
|
|
1171
|
-
if (!isFirst) {
|
|
1172
|
-
if (draft.kind === java_1.J.Kind.VariableDeclarations) {
|
|
1173
|
-
const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
|
|
1174
|
-
? (_a = this.style.minimum.aroundFieldInInterface) !== null && _a !== void 0 ? _a : 0
|
|
1175
|
-
: this.style.minimum.aroundField;
|
|
1176
|
-
this.minimumBlankLines(draft, declMax);
|
|
1177
|
-
}
|
|
1178
|
-
else if (draft.kind === java_1.J.Kind.MethodDeclaration) {
|
|
1179
|
-
const declMax = classDecl.classKind.type === java_1.J.ClassDeclaration.Kind.Type.Interface
|
|
1180
|
-
? (_b = this.style.minimum.aroundMethodInInterface) !== null && _b !== void 0 ? _b : 0
|
|
1181
|
-
: this.style.minimum.aroundMethod;
|
|
1182
|
-
this.minimumBlankLines(draft, declMax);
|
|
1183
|
-
}
|
|
1184
|
-
else if (draft.kind === java_1.J.Kind.Block) {
|
|
1185
|
-
this.minimumBlankLines(draft, this.style.minimum.aroundFunction);
|
|
1186
|
-
}
|
|
1187
|
-
else if (draft.kind === java_1.J.Kind.ClassDeclaration) {
|
|
1188
|
-
this.minimumBlankLines(draft, this.style.minimum.aroundClass);
|
|
1189
|
-
}
|
|
1190
|
-
this.keepMaximumBlankLines(draft, this.style.keepMaximum.inCode);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
else if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== java_1.J.Kind.NewClass && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== tree_1.JS.Kind.TypeLiteral ||
|
|
1194
|
-
((parent === null || parent === void 0 ? void 0 : parent.kind) === tree_1.JS.Kind.CompilationUnit && parent.statements[0].element.id != draft.id) ||
|
|
1195
|
-
((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Case && this.isInsideCaseStatements(parent, draft))) {
|
|
1196
|
-
if (draft.kind != java_1.J.Kind.Case) {
|
|
1197
|
-
this.ensurePrefixHasNewLine(draft);
|
|
1198
|
-
}
|
|
982
|
+
}
|
|
983
|
+
else if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Block && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== java_1.J.Kind.NewClass && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.kind) !== tree_1.JS.Kind.TypeLiteral ||
|
|
984
|
+
((parent === null || parent === void 0 ? void 0 : parent.kind) === tree_1.JS.Kind.CompilationUnit && parent.statements[0].element.id != draft.id) ||
|
|
985
|
+
((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.Case && this.isInsideCaseStatements(parent, draft))) {
|
|
986
|
+
if (draft.kind != java_1.J.Kind.Case) {
|
|
987
|
+
this.ensurePrefixHasNewLine(draft);
|
|
1199
988
|
}
|
|
1200
|
-
}
|
|
989
|
+
}
|
|
1201
990
|
});
|
|
1202
991
|
}
|
|
1203
|
-
visitBlock(block, p) {
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
// Skip newline for object literals (NewClass) and type literals (TypeLiteral)
|
|
1213
|
-
if (parentKind != java_1.J.Kind.NewClass && parentKind != tree_1.JS.Kind.TypeLiteral) {
|
|
1214
|
-
draft.end = (0, java_1.replaceLastWhitespace)(draft.end, ws => ws.includes("\n") ? ws : ws.replace(/[ \t]+$/, '') + "\n");
|
|
1215
|
-
}
|
|
1216
|
-
});
|
|
992
|
+
async visitBlock(block, p) {
|
|
993
|
+
const b = await super.visitBlock(block, p);
|
|
994
|
+
return (0, mutative_1.create)(b, draft => {
|
|
995
|
+
var _a;
|
|
996
|
+
const parentKind = (_a = this.cursor.parent) === null || _a === void 0 ? void 0 : _a.value.kind;
|
|
997
|
+
// Skip newline for object literals (NewClass) and type literals (TypeLiteral)
|
|
998
|
+
if (parentKind != java_1.J.Kind.NewClass && parentKind != tree_1.JS.Kind.TypeLiteral) {
|
|
999
|
+
draft.end = (0, java_1.replaceLastWhitespace)(draft.end, ws => ws.includes("\n") ? ws : ws.replace(/[ \t]+$/, '') + "\n");
|
|
1000
|
+
}
|
|
1217
1001
|
});
|
|
1218
1002
|
}
|
|
1219
|
-
visitEnumValue(enumValue, p) {
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1224
|
-
const e = yield _super.visitEnumValue.call(this, enumValue, p);
|
|
1225
|
-
this.keepMaximumBlankLines(e, this.style.keepMaximum.inCode);
|
|
1226
|
-
return e;
|
|
1227
|
-
});
|
|
1003
|
+
async visitEnumValue(enumValue, p) {
|
|
1004
|
+
const e = await super.visitEnumValue(enumValue, p);
|
|
1005
|
+
this.keepMaximumBlankLines(e, this.style.keepMaximum.inCode);
|
|
1006
|
+
return e;
|
|
1228
1007
|
}
|
|
1229
1008
|
/**
|
|
1230
1009
|
* Check if a statement is inside a Case's statements container or body,
|
|
@@ -1281,17 +1060,12 @@ class BlankLinesVisitor extends visitor_1.JavaScriptVisitor {
|
|
|
1281
1060
|
static countNewlines(s) {
|
|
1282
1061
|
return [...s].filter(c => c === "\n").length;
|
|
1283
1062
|
}
|
|
1284
|
-
postVisit(tree, p) {
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
1291
|
-
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
1292
|
-
}
|
|
1293
|
-
return _super.postVisit.call(this, tree, p);
|
|
1294
|
-
});
|
|
1063
|
+
async postVisit(tree, p) {
|
|
1064
|
+
var _a;
|
|
1065
|
+
if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
|
|
1066
|
+
(_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
|
|
1067
|
+
}
|
|
1068
|
+
return super.postVisit(tree, p);
|
|
1295
1069
|
}
|
|
1296
1070
|
}
|
|
1297
1071
|
exports.BlankLinesVisitor = BlankLinesVisitor;
|