@openrewrite/rewrite 8.66.0 → 8.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/javascript/comparator.d.ts +67 -4
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +523 -2794
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format.d.ts.map +1 -1
- package/dist/javascript/format.js +4 -3
- package/dist/javascript/format.js.map +1 -1
- package/dist/javascript/index.d.ts +1 -1
- package/dist/javascript/index.d.ts.map +1 -1
- package/dist/javascript/index.js +1 -1
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +18 -16
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/templating/capture.d.ts +226 -0
- package/dist/javascript/templating/capture.d.ts.map +1 -0
- package/dist/javascript/templating/capture.js +371 -0
- package/dist/javascript/templating/capture.js.map +1 -0
- package/dist/javascript/templating/comparator.d.ts +61 -0
- package/dist/javascript/templating/comparator.d.ts.map +1 -0
- package/dist/javascript/templating/comparator.js +393 -0
- package/dist/javascript/templating/comparator.js.map +1 -0
- package/dist/javascript/templating/engine.d.ts +75 -0
- package/dist/javascript/templating/engine.d.ts.map +1 -0
- package/dist/javascript/templating/engine.js +228 -0
- package/dist/javascript/templating/engine.js.map +1 -0
- package/dist/javascript/templating/index.d.ts +6 -0
- package/dist/javascript/templating/index.d.ts.map +1 -0
- package/dist/javascript/templating/index.js +42 -0
- package/dist/javascript/templating/index.js.map +1 -0
- package/dist/javascript/templating/pattern.d.ts +171 -0
- package/dist/javascript/templating/pattern.d.ts.map +1 -0
- package/dist/javascript/templating/pattern.js +681 -0
- package/dist/javascript/templating/pattern.js.map +1 -0
- package/dist/javascript/templating/placeholder-replacement.d.ts +58 -0
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
- package/dist/javascript/templating/placeholder-replacement.js +365 -0
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
- package/dist/javascript/templating/rewrite.d.ts +39 -0
- package/dist/javascript/templating/rewrite.d.ts.map +1 -0
- package/dist/javascript/templating/rewrite.js +81 -0
- package/dist/javascript/templating/rewrite.js.map +1 -0
- package/dist/javascript/templating/template.d.ts +204 -0
- package/dist/javascript/templating/template.d.ts.map +1 -0
- package/dist/javascript/templating/template.js +293 -0
- package/dist/javascript/templating/template.js.map +1 -0
- package/dist/javascript/templating/types.d.ts +263 -0
- package/dist/javascript/templating/types.d.ts.map +1 -0
- package/dist/javascript/templating/types.js +3 -0
- package/dist/javascript/templating/types.js.map +1 -0
- package/dist/javascript/templating/utils.d.ts +118 -0
- package/dist/javascript/templating/utils.d.ts.map +1 -0
- package/dist/javascript/templating/utils.js +253 -0
- package/dist/javascript/templating/utils.js.map +1 -0
- package/dist/version.txt +1 -1
- package/package.json +2 -1
- package/src/javascript/comparator.ts +554 -3323
- package/src/javascript/format.ts +3 -2
- package/src/javascript/index.ts +1 -1
- package/src/javascript/parser.ts +19 -17
- package/src/javascript/templating/capture.ts +503 -0
- package/src/javascript/templating/comparator.ts +430 -0
- package/src/javascript/templating/engine.ts +252 -0
- package/src/javascript/templating/index.ts +60 -0
- package/src/javascript/templating/pattern.ts +727 -0
- package/src/javascript/templating/placeholder-replacement.ts +372 -0
- package/src/javascript/templating/rewrite.ts +95 -0
- package/src/javascript/templating/template.ts +326 -0
- package/src/javascript/templating/types.ts +300 -0
- package/src/javascript/templating/utils.ts +284 -0
- package/dist/javascript/templating.d.ts +0 -265
- package/dist/javascript/templating.d.ts.map +0 -1
- package/dist/javascript/templating.js +0 -1027
- package/dist/javascript/templating.js.map +0 -1
- package/src/javascript/templating.ts +0 -1226
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/comparator.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,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AAC,gBAAgB,EAAE,CAAC,CAAC,gBAAgB,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA2D7F,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA2B5D,sBAAsB,CAAC,eAAe,EAAE,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA2B5G;;;OAGG;YACW,cAAc;IAI5B;;;;;;;;;;;OAWG;YACW,aAAa;IAI3B;;;;;;;;;;;OAWG;YACW,sBAAsB;CAiMvC"}
|
|
@@ -0,0 +1,393 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PatternMatchingComparator = void 0;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright 2025 the original author or authors.
|
|
15
|
+
* <p>
|
|
16
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License.
|
|
18
|
+
* You may obtain a copy of the License at
|
|
19
|
+
* <p>
|
|
20
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
21
|
+
* <p>
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
* See the License for the specific language governing permissions and
|
|
26
|
+
* limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
const __1 = require("../..");
|
|
29
|
+
const java_1 = require("../../java");
|
|
30
|
+
const index_1 = require("../index");
|
|
31
|
+
const comparator_1 = require("../comparator");
|
|
32
|
+
const utils_1 = require("./utils");
|
|
33
|
+
/**
|
|
34
|
+
* A comparator for pattern matching that is lenient about optional properties.
|
|
35
|
+
* Allows patterns without type annotations to match actual code with type annotations.
|
|
36
|
+
* Uses semantic comparison to match semantically equivalent code (e.g., isDate() and util.isDate()).
|
|
37
|
+
*/
|
|
38
|
+
class PatternMatchingComparator extends comparator_1.JavaScriptSemanticComparatorVisitor {
|
|
39
|
+
constructor(matcher, lenientTypeMatching = true) {
|
|
40
|
+
// Enable lenient type matching based on pattern configuration (default: true for backward compatibility)
|
|
41
|
+
super(lenientTypeMatching);
|
|
42
|
+
this.matcher = matcher;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the wrapper from the cursor if the parent is a RightPadded.
|
|
46
|
+
*/
|
|
47
|
+
getWrapperFromCursor(cursor) {
|
|
48
|
+
if (!cursor.parent) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const parent = cursor.parent.value;
|
|
52
|
+
// Check if parent is a RightPadded by checking its kind
|
|
53
|
+
if (parent.kind === java_1.J.Kind.RightPadded) {
|
|
54
|
+
return parent;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
visit(j, p, parent) {
|
|
59
|
+
const _super = Object.create(null, {
|
|
60
|
+
visit: { get: () => super.visit }
|
|
61
|
+
});
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
// Check if the pattern node is a capture - this handles captures anywhere in the tree
|
|
64
|
+
if (utils_1.PlaceholderUtils.isCapture(j)) {
|
|
65
|
+
const wrapper = this.getWrapperFromCursor(this.cursor);
|
|
66
|
+
const success = this.matcher.handleCapture(j, p, wrapper);
|
|
67
|
+
if (!success) {
|
|
68
|
+
return this.abort(j);
|
|
69
|
+
}
|
|
70
|
+
return j;
|
|
71
|
+
}
|
|
72
|
+
if (!this.match) {
|
|
73
|
+
return j;
|
|
74
|
+
}
|
|
75
|
+
return _super.visit.call(this, j, p, parent);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
hasSameKind(j, other) {
|
|
79
|
+
return super.hasSameKind(j, other) ||
|
|
80
|
+
(j.kind == java_1.J.Kind.Identifier && utils_1.PlaceholderUtils.isCapture(j));
|
|
81
|
+
}
|
|
82
|
+
visitIdentifier(identifier, other) {
|
|
83
|
+
const _super = Object.create(null, {
|
|
84
|
+
visitIdentifier: { get: () => super.visitIdentifier }
|
|
85
|
+
});
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if (utils_1.PlaceholderUtils.isCapture(identifier)) {
|
|
88
|
+
const wrapper = this.getWrapperFromCursor(this.cursor);
|
|
89
|
+
const success = this.matcher.handleCapture(identifier, other, wrapper);
|
|
90
|
+
return success ? identifier : this.abort(identifier);
|
|
91
|
+
}
|
|
92
|
+
return _super.visitIdentifier.call(this, identifier, other);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
visitMethodInvocation(methodInvocation, other) {
|
|
96
|
+
const _super = Object.create(null, {
|
|
97
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
98
|
+
});
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
// Check if any arguments are variadic captures
|
|
101
|
+
const hasVariadicCapture = methodInvocation.arguments.elements.some(arg => utils_1.PlaceholderUtils.isVariadicCapture(arg.element));
|
|
102
|
+
// If no variadic captures, use parent implementation (which includes semantic/type-aware matching)
|
|
103
|
+
if (!hasVariadicCapture) {
|
|
104
|
+
return _super.visitMethodInvocation.call(this, methodInvocation, other);
|
|
105
|
+
}
|
|
106
|
+
// Otherwise, handle variadic captures ourselves
|
|
107
|
+
if (!this.match || other.kind !== java_1.J.Kind.MethodInvocation) {
|
|
108
|
+
return this.abort(methodInvocation);
|
|
109
|
+
}
|
|
110
|
+
const otherMethodInvocation = other;
|
|
111
|
+
// Compare select
|
|
112
|
+
if ((methodInvocation.select === undefined) !== (otherMethodInvocation.select === undefined)) {
|
|
113
|
+
return this.abort(methodInvocation);
|
|
114
|
+
}
|
|
115
|
+
// Visit select if present
|
|
116
|
+
if (methodInvocation.select && otherMethodInvocation.select) {
|
|
117
|
+
yield this.visit(methodInvocation.select.element, otherMethodInvocation.select.element);
|
|
118
|
+
if (!this.match)
|
|
119
|
+
return methodInvocation;
|
|
120
|
+
}
|
|
121
|
+
// Compare typeParameters
|
|
122
|
+
if ((methodInvocation.typeParameters === undefined) !== (otherMethodInvocation.typeParameters === undefined)) {
|
|
123
|
+
return this.abort(methodInvocation);
|
|
124
|
+
}
|
|
125
|
+
// Visit typeParameters if present
|
|
126
|
+
if (methodInvocation.typeParameters && otherMethodInvocation.typeParameters) {
|
|
127
|
+
if (methodInvocation.typeParameters.elements.length !== otherMethodInvocation.typeParameters.elements.length) {
|
|
128
|
+
return this.abort(methodInvocation);
|
|
129
|
+
}
|
|
130
|
+
// Visit each type parameter in lock step
|
|
131
|
+
for (let i = 0; i < methodInvocation.typeParameters.elements.length; i++) {
|
|
132
|
+
yield this.visit(methodInvocation.typeParameters.elements[i].element, otherMethodInvocation.typeParameters.elements[i].element);
|
|
133
|
+
if (!this.match)
|
|
134
|
+
return methodInvocation;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Visit name
|
|
138
|
+
yield this.visit(methodInvocation.name, otherMethodInvocation.name);
|
|
139
|
+
if (!this.match)
|
|
140
|
+
return methodInvocation;
|
|
141
|
+
// Special handling for variadic captures in arguments
|
|
142
|
+
if (!(yield this.matchArguments(methodInvocation.arguments.elements, otherMethodInvocation.arguments.elements))) {
|
|
143
|
+
return this.abort(methodInvocation);
|
|
144
|
+
}
|
|
145
|
+
return methodInvocation;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
visitBlock(block, other) {
|
|
149
|
+
const _super = Object.create(null, {
|
|
150
|
+
visitBlock: { get: () => super.visitBlock }
|
|
151
|
+
});
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
// Check if any statements have CaptureMarker indicating they're variadic
|
|
154
|
+
const hasVariadicCapture = block.statements.some(stmt => {
|
|
155
|
+
const captureMarker = utils_1.PlaceholderUtils.getCaptureMarker(stmt.element);
|
|
156
|
+
return (captureMarker === null || captureMarker === void 0 ? void 0 : captureMarker.variadicOptions) !== undefined;
|
|
157
|
+
});
|
|
158
|
+
// If no variadic captures, use parent implementation
|
|
159
|
+
if (!hasVariadicCapture) {
|
|
160
|
+
return _super.visitBlock.call(this, block, other);
|
|
161
|
+
}
|
|
162
|
+
// Otherwise, handle variadic captures ourselves
|
|
163
|
+
if (!this.match || other.kind !== java_1.J.Kind.Block) {
|
|
164
|
+
return this.abort(block);
|
|
165
|
+
}
|
|
166
|
+
const otherBlock = other;
|
|
167
|
+
// Special handling for variadic captures in statements
|
|
168
|
+
if (!(yield this.matchSequence(block.statements, otherBlock.statements, false))) {
|
|
169
|
+
return this.abort(block);
|
|
170
|
+
}
|
|
171
|
+
return block;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
visitJsCompilationUnit(compilationUnit, other) {
|
|
175
|
+
const _super = Object.create(null, {
|
|
176
|
+
visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
|
|
177
|
+
});
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
// Check if any statements are variadic captures (unwrap ExpressionStatement wrappers first)
|
|
180
|
+
const hasVariadicCapture = compilationUnit.statements.some(stmt => {
|
|
181
|
+
const unwrapped = utils_1.PlaceholderUtils.unwrapStatementCapture(stmt.element);
|
|
182
|
+
return utils_1.PlaceholderUtils.isVariadicCapture(unwrapped);
|
|
183
|
+
});
|
|
184
|
+
// If no variadic captures, use parent implementation
|
|
185
|
+
if (!hasVariadicCapture) {
|
|
186
|
+
return _super.visitJsCompilationUnit.call(this, compilationUnit, other);
|
|
187
|
+
}
|
|
188
|
+
// Otherwise, handle variadic captures ourselves
|
|
189
|
+
if (!this.match || other.kind !== index_1.JS.Kind.CompilationUnit) {
|
|
190
|
+
return this.abort(compilationUnit);
|
|
191
|
+
}
|
|
192
|
+
const otherCompilationUnit = other;
|
|
193
|
+
// Special handling for variadic captures in top-level statements
|
|
194
|
+
if (!(yield this.matchSequence(compilationUnit.statements, otherCompilationUnit.statements, false))) {
|
|
195
|
+
return this.abort(compilationUnit);
|
|
196
|
+
}
|
|
197
|
+
return compilationUnit;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Matches argument lists, with special handling for variadic captures.
|
|
202
|
+
* A variadic capture can match zero or more consecutive arguments.
|
|
203
|
+
*/
|
|
204
|
+
matchArguments(patternArgs, targetArgs) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
return this.matchSequence(patternArgs, targetArgs, true);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generic sequence matching with variadic capture support.
|
|
211
|
+
* Works for any sequence of JRightPadded elements (arguments, statements, etc.).
|
|
212
|
+
* A variadic capture can match zero or more consecutive elements.
|
|
213
|
+
*
|
|
214
|
+
* Uses pivot detection to optimize matching, with backtracking as fallback.
|
|
215
|
+
*
|
|
216
|
+
* @param patternElements The pattern elements (JRightPadded)
|
|
217
|
+
* @param targetElements The target elements to match against (JRightPadded)
|
|
218
|
+
* @param filterEmpty Whether to filter out J.Empty elements when capturing (true for arguments, false for statements)
|
|
219
|
+
* @returns true if the sequence matches, false otherwise
|
|
220
|
+
*/
|
|
221
|
+
matchSequence(patternElements, targetElements, filterEmpty) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
return yield this.matchSequenceOptimized(patternElements, targetElements, 0, 0, filterEmpty);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Optimized sequence matcher with pivot detection and backtracking.
|
|
228
|
+
* For variadic patterns, tries to detect pivots (where next pattern matches) to avoid
|
|
229
|
+
* unnecessary backtracking. Falls back to full backtracking when pivots are ambiguous.
|
|
230
|
+
*
|
|
231
|
+
* @param patternElements The pattern elements (JRightPadded)
|
|
232
|
+
* @param targetElements The target elements to match against (JRightPadded)
|
|
233
|
+
* @param patternIdx Current position in pattern
|
|
234
|
+
* @param targetIdx Current position in target
|
|
235
|
+
* @param filterEmpty Whether to filter out J.Empty elements when capturing
|
|
236
|
+
* @returns true if the remaining sequence matches, false otherwise
|
|
237
|
+
*/
|
|
238
|
+
matchSequenceOptimized(patternElements, targetElements, patternIdx, targetIdx, filterEmpty) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
var _a, _b;
|
|
241
|
+
// Base case: all patterns matched
|
|
242
|
+
if (patternIdx >= patternElements.length) {
|
|
243
|
+
return targetIdx >= targetElements.length; // Success if all targets consumed
|
|
244
|
+
}
|
|
245
|
+
const patternElement = patternElements[patternIdx].element;
|
|
246
|
+
const captureMarker = utils_1.PlaceholderUtils.getCaptureMarker(patternElement);
|
|
247
|
+
const isVariadic = (captureMarker === null || captureMarker === void 0 ? void 0 : captureMarker.variadicOptions) !== undefined;
|
|
248
|
+
if (isVariadic) {
|
|
249
|
+
// Variadic pattern: try different consumption amounts with backtracking
|
|
250
|
+
const variadicOptions = captureMarker.variadicOptions;
|
|
251
|
+
const min = (_a = variadicOptions === null || variadicOptions === void 0 ? void 0 : variadicOptions.min) !== null && _a !== void 0 ? _a : 0;
|
|
252
|
+
const max = (_b = variadicOptions === null || variadicOptions === void 0 ? void 0 : variadicOptions.max) !== null && _b !== void 0 ? _b : Infinity;
|
|
253
|
+
// Calculate maximum possible consumption
|
|
254
|
+
let nonVariadicRemainingPatterns = 0;
|
|
255
|
+
for (let i = patternIdx + 1; i < patternElements.length; i++) {
|
|
256
|
+
const nextPatternElement = patternElements[i].element;
|
|
257
|
+
const nextCaptureMarker = utils_1.PlaceholderUtils.getCaptureMarker(nextPatternElement);
|
|
258
|
+
const nextIsVariadic = (nextCaptureMarker === null || nextCaptureMarker === void 0 ? void 0 : nextCaptureMarker.variadicOptions) !== undefined;
|
|
259
|
+
if (!nextIsVariadic) {
|
|
260
|
+
nonVariadicRemainingPatterns++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const remainingTargetElements = targetElements.length - targetIdx;
|
|
264
|
+
const maxPossible = Math.min(remainingTargetElements - nonVariadicRemainingPatterns, max);
|
|
265
|
+
// Pivot detection optimization: try to find where next pattern matches
|
|
266
|
+
// This avoids unnecessary backtracking when constraints make the split point obvious
|
|
267
|
+
let pivotDetected = false;
|
|
268
|
+
let pivotAt = -1;
|
|
269
|
+
if (patternIdx + 1 < patternElements.length && min <= maxPossible) {
|
|
270
|
+
const nextPattern = patternElements[patternIdx + 1].element;
|
|
271
|
+
// Scan through possible consumption amounts starting from min
|
|
272
|
+
for (let tryConsume = min; tryConsume <= maxPossible; tryConsume++) {
|
|
273
|
+
// Check if element after our consumption would match next pattern
|
|
274
|
+
if (targetIdx + tryConsume < targetElements.length) {
|
|
275
|
+
const candidateElement = targetElements[targetIdx + tryConsume].element;
|
|
276
|
+
// Skip J.Empty for arguments
|
|
277
|
+
if (filterEmpty && candidateElement.kind === java_1.J.Kind.Empty) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
// Test if next pattern matches this element
|
|
281
|
+
const savedMatch = this.match;
|
|
282
|
+
const savedState = this.matcher.saveState();
|
|
283
|
+
yield this.visit(nextPattern, candidateElement);
|
|
284
|
+
const matchesNext = this.match;
|
|
285
|
+
this.match = savedMatch;
|
|
286
|
+
this.matcher.restoreState(savedState);
|
|
287
|
+
if (matchesNext) {
|
|
288
|
+
// Found pivot! Try this consumption amount first
|
|
289
|
+
pivotDetected = true;
|
|
290
|
+
pivotAt = tryConsume;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Try different consumption amounts
|
|
297
|
+
// If pivot detected, try that first; otherwise use greedy approach (max to min)
|
|
298
|
+
const consumptionOrder = [];
|
|
299
|
+
if (pivotDetected && pivotAt >= 0) {
|
|
300
|
+
// Try pivot first, then others as fallback
|
|
301
|
+
consumptionOrder.push(pivotAt);
|
|
302
|
+
for (let c = maxPossible; c >= min; c--) {
|
|
303
|
+
if (c !== pivotAt) {
|
|
304
|
+
consumptionOrder.push(c);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
// Greedy approach: max to min
|
|
310
|
+
for (let c = maxPossible; c >= min; c--) {
|
|
311
|
+
consumptionOrder.push(c);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const consume of consumptionOrder) {
|
|
315
|
+
// Capture elements for this consumption amount
|
|
316
|
+
const capturedWrappers = [];
|
|
317
|
+
for (let i = 0; i < consume; i++) {
|
|
318
|
+
const wrapped = targetElements[targetIdx + i];
|
|
319
|
+
const element = wrapped.element;
|
|
320
|
+
// For arguments, filter out J.Empty as it represents an empty argument list
|
|
321
|
+
// For statements, include all elements
|
|
322
|
+
if (!filterEmpty || element.kind !== java_1.J.Kind.Empty) {
|
|
323
|
+
capturedWrappers.push(wrapped);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// Extract just the elements for the constraint check
|
|
327
|
+
const capturedElements = capturedWrappers.map(w => w.element);
|
|
328
|
+
// Re-check min/max constraints against actual captured elements (after filtering if applicable)
|
|
329
|
+
if (capturedElements.length < min || capturedElements.length > max) {
|
|
330
|
+
continue; // Try next consumption amount
|
|
331
|
+
}
|
|
332
|
+
// Save current state for backtracking
|
|
333
|
+
const savedState = this.matcher.saveState();
|
|
334
|
+
// Handle the variadic capture
|
|
335
|
+
const success = this.matcher.handleVariadicCapture(patternElement, capturedElements, capturedWrappers);
|
|
336
|
+
if (!success) {
|
|
337
|
+
// Restore state and try next amount
|
|
338
|
+
this.matcher.restoreState(savedState);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
// Try to match the rest of the pattern
|
|
342
|
+
const restMatches = yield this.matchSequenceOptimized(patternElements, targetElements, patternIdx + 1, targetIdx + consume, filterEmpty);
|
|
343
|
+
if (restMatches) {
|
|
344
|
+
return true; // Found a valid matching
|
|
345
|
+
}
|
|
346
|
+
// Backtrack: restore state and try next amount
|
|
347
|
+
this.matcher.restoreState(savedState);
|
|
348
|
+
}
|
|
349
|
+
return false; // No consumption amount worked
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
// Regular non-variadic element - must match exactly one target element
|
|
353
|
+
if (targetIdx >= targetElements.length) {
|
|
354
|
+
return false; // Pattern has more elements than target
|
|
355
|
+
}
|
|
356
|
+
const targetWrapper = targetElements[targetIdx];
|
|
357
|
+
const targetElement = targetWrapper.element;
|
|
358
|
+
// For arguments, J.Empty represents no argument, so regular captures should not match it
|
|
359
|
+
if (filterEmpty && targetElement.kind === java_1.J.Kind.Empty) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
// Save current state for backtracking (both match state and capture bindings)
|
|
363
|
+
const savedMatch = this.match;
|
|
364
|
+
const savedState = this.matcher.saveState();
|
|
365
|
+
// Push wrapper onto cursor so captures can access it
|
|
366
|
+
const savedCursor = this.cursor;
|
|
367
|
+
this.cursor = new __1.Cursor(targetWrapper, this.cursor);
|
|
368
|
+
try {
|
|
369
|
+
yield this.visit(patternElement, targetElement);
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
this.cursor = savedCursor;
|
|
373
|
+
}
|
|
374
|
+
if (!this.match) {
|
|
375
|
+
// Restore state on match failure
|
|
376
|
+
this.match = savedMatch;
|
|
377
|
+
this.matcher.restoreState(savedState);
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
// Continue matching the rest
|
|
381
|
+
const restMatches = yield this.matchSequenceOptimized(patternElements, targetElements, patternIdx + 1, targetIdx + 1, filterEmpty);
|
|
382
|
+
if (!restMatches) {
|
|
383
|
+
// Restore full state on backtracking failure
|
|
384
|
+
this.match = savedMatch;
|
|
385
|
+
this.matcher.restoreState(savedState);
|
|
386
|
+
}
|
|
387
|
+
return restMatches;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
exports.PatternMatchingComparator = PatternMatchingComparator;
|
|
393
|
+
//# sourceMappingURL=comparator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.js","sourceRoot":"","sources":["../../../src/javascript/templating/comparator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6BAAmC;AACnC,qCAA6B;AAC7B,oCAA4B;AAC5B,8CAAkE;AAClE,mCAA8D;AAE9D;;;;GAIG;AACH,MAAa,yBAA0B,SAAQ,gDAAmC;IAC9E,YACqB,OAKhB,EACD,sBAA+B,IAAI;QAEnC,yGAAyG;QACzG,KAAK,CAAC,mBAAmB,CAAC,CAAC;QATV,YAAO,GAAP,OAAO,CAKvB;IAKL,CAAC;IAED;;OAEG;IACK,oBAAoB,CAAC,MAAc;QACvC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,wDAAwD;QACxD,IAAK,MAAc,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC9C,OAAO,MAA0B,CAAC;QACtC,CAAC;QAC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|
|
1
|
+
import { Cursor } from '../..';
|
|
2
|
+
import { J } from '../../java';
|
|
3
|
+
import { JavaCoordinates } from './template';
|
|
4
|
+
/**
|
|
5
|
+
* Parameter specification for template generation.
|
|
6
|
+
* Represents a placeholder in a template that will be replaced with a parameter value.
|
|
7
|
+
*/
|
|
8
|
+
export interface Parameter {
|
|
9
|
+
/**
|
|
10
|
+
* The value to substitute into the template.
|
|
11
|
+
*/
|
|
12
|
+
value: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Internal template engine - handles the core templating logic.
|
|
16
|
+
* Not exported from index, so only visible within the templating module.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TemplateEngine {
|
|
19
|
+
/**
|
|
20
|
+
* Applies a template with optional match results from pattern matching.
|
|
21
|
+
*
|
|
22
|
+
* @param templateParts The string parts of the template
|
|
23
|
+
* @param parameters The parameters between the string parts
|
|
24
|
+
* @param cursor The cursor pointing to the current location in the AST
|
|
25
|
+
* @param coordinates The coordinates specifying where and how to insert the generated AST
|
|
26
|
+
* @param values Map of capture names to values to replace the parameters with
|
|
27
|
+
* @param wrappersMap Map of capture names to J.RightPadded wrappers (for preserving markers)
|
|
28
|
+
* @param contextStatements Context declarations (imports, types, etc.) to prepend for type attribution
|
|
29
|
+
* @param dependencies NPM dependencies for type attribution
|
|
30
|
+
* @returns A Promise resolving to the generated AST node
|
|
31
|
+
*/
|
|
32
|
+
static applyTemplate(templateParts: TemplateStringsArray, parameters: Parameter[], cursor: Cursor, coordinates: JavaCoordinates, values?: Pick<Map<string, J>, 'get'>, wrappersMap?: Pick<Map<string, J.RightPadded<J> | J.RightPadded<J>[]>, 'get'>, contextStatements?: string[], dependencies?: Record<string, string>): Promise<J | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Builds a template string with parameter placeholders.
|
|
35
|
+
*
|
|
36
|
+
* @param templateParts The string parts of the template
|
|
37
|
+
* @param parameters The parameters between the string parts
|
|
38
|
+
* @returns The template string
|
|
39
|
+
*/
|
|
40
|
+
private static buildTemplateString;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper class for applying a template to an AST.
|
|
44
|
+
*/
|
|
45
|
+
export declare class TemplateApplier {
|
|
46
|
+
private readonly cursor;
|
|
47
|
+
private readonly coordinates;
|
|
48
|
+
private readonly ast;
|
|
49
|
+
constructor(cursor: Cursor, coordinates: JavaCoordinates, ast: J);
|
|
50
|
+
/**
|
|
51
|
+
* Applies the template to the current AST.
|
|
52
|
+
*
|
|
53
|
+
* @returns A Promise resolving to the modified AST
|
|
54
|
+
*/
|
|
55
|
+
apply(): Promise<J | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Applies the template to an expression.
|
|
58
|
+
*
|
|
59
|
+
* @returns A Promise resolving to the modified AST
|
|
60
|
+
*/
|
|
61
|
+
private applyToExpression;
|
|
62
|
+
/**
|
|
63
|
+
* Applies the template to a statement.
|
|
64
|
+
*
|
|
65
|
+
* @returns A Promise resolving to the modified AST
|
|
66
|
+
*/
|
|
67
|
+
private applyToStatement;
|
|
68
|
+
/**
|
|
69
|
+
* Applies the template to a block.
|
|
70
|
+
*
|
|
71
|
+
* @returns A Promise resolving to the modified AST
|
|
72
|
+
*/
|
|
73
|
+
private applyToBlock;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/javascript/templating/engine.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAS,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,CAAC,EAAC,MAAM,YAAY,CAAC;AAM7B,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAO3C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;CACd;AAED;;;GAGG;AACH,qBAAa,cAAc;IACvB;;;;;;;;;;;;OAYG;WACU,aA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