@openrewrite/rewrite 8.81.10 → 8.81.12

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.
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Check = void 0;
3
+ exports.Check = exports.CompositePrecondition = exports.RecipeRef = void 0;
4
4
  exports.check = check;
5
+ exports.or = or;
6
+ exports.and = and;
7
+ exports.not = not;
5
8
  /*
6
9
  * Copyright 2025 the original author or authors.
7
10
  * <p>
@@ -20,6 +23,60 @@ exports.check = check;
20
23
  const visitor_1 = require("./visitor");
21
24
  const tree_1 = require("./tree");
22
25
  const recipe_1 = require("./recipe");
26
+ /**
27
+ * Recipe-identity placeholder for use as a precondition.
28
+ *
29
+ * Captures a Java recipe class name + options without instantiating the
30
+ * recipe or firing an RPC. The framework introspects a
31
+ * ``check(RecipeRef, editor)`` wrapper at PrepareRecipe time and emits
32
+ * the recipe identity directly in
33
+ * ``PrepareRecipeResponse.editPreconditions``. The Java host's
34
+ * ``PreparedRecipeCache.instantiateVisitor`` constructs the recipe via
35
+ * Jackson and uses its visitor.
36
+ *
37
+ * This avoids requiring the recipe author to do an RPC at ``editor()``
38
+ * construction time, which would otherwise block in-process unit tests
39
+ * that don't have an active RPC connection.
40
+ *
41
+ * If ``localVisitor`` is provided, in-process callers (without an active
42
+ * RPC connection) evaluate the gate against that visitor instead of
43
+ * short-circuiting to "always matches". This preserves real filtering
44
+ * behavior in unit tests while still letting the host evaluate the gate
45
+ * over the wire when an RPC connection is present.
46
+ *
47
+ * Helpers in ``@openrewrite/rewrite/javascript/preconditions``
48
+ * (``usesMethod``, ``usesType``, ``hasSourcePath``, ``findMethods``,
49
+ * ``findTypes``) return ``RecipeRef`` instances populated with the
50
+ * matching native TS visitor where one exists.
51
+ */
52
+ class RecipeRef {
53
+ constructor(recipeName, options = {}, localVisitor) {
54
+ this.recipeName = recipeName;
55
+ this.options = options;
56
+ this.localVisitor = localVisitor;
57
+ }
58
+ }
59
+ exports.RecipeRef = RecipeRef;
60
+ /**
61
+ * Composite of nested precondition operands joined by an operator.
62
+ *
63
+ * Mirrors Java's ``Preconditions.or``/``and``/``not``: a gate that
64
+ * short-circuits over its operands. ``op`` is one of ``"or"`` / ``"and"`` /
65
+ * ``"not"``. Operands may be ``TreeVisitor``, ``Recipe``, ``RecipeRef``,
66
+ * or another ``CompositePrecondition``.
67
+ *
68
+ * The framework promotes the composite to a structured wire entry at
69
+ * PrepareRecipe time; the Java host's ``RewriteRpc.matchAll`` rebuilds
70
+ * the visitor via the matching ``Preconditions`` factory so the gate runs
71
+ * locally and the visit RPC is skipped for files the gate rejects.
72
+ */
73
+ class CompositePrecondition {
74
+ constructor(op, operands) {
75
+ this.op = op;
76
+ this.operands = operands;
77
+ }
78
+ }
79
+ exports.CompositePrecondition = CompositePrecondition;
23
80
  async function check(checkCondition, v) {
24
81
  const resolvedCheck = await checkCondition;
25
82
  const resolvedV = await v;
@@ -28,6 +85,36 @@ async function check(checkCondition, v) {
28
85
  }
29
86
  return new Check(resolvedCheck, resolvedV);
30
87
  }
88
+ /**
89
+ * OR-compose precondition checks. Mirrors Java's
90
+ * ``Preconditions.or(visitor...)``: the gate matches if any operand
91
+ * matches. Requires at least two operands; a single-operand OR has no
92
+ * value over a bare ``check``.
93
+ */
94
+ function or(...operands) {
95
+ if (operands.length < 2) {
96
+ throw new Error("Preconditions.or requires at least two operands");
97
+ }
98
+ return new CompositePrecondition("or", operands);
99
+ }
100
+ /**
101
+ * AND-compose precondition checks. The outer ``editPreconditions`` list
102
+ * is already AND-composed by the host, so this is mainly useful as an
103
+ * operand of ``or``/``not``.
104
+ */
105
+ function and(...operands) {
106
+ if (operands.length < 2) {
107
+ throw new Error("Preconditions.and requires at least two operands");
108
+ }
109
+ return new CompositePrecondition("and", operands);
110
+ }
111
+ /**
112
+ * Negate a precondition check. Mirrors Java's ``Preconditions.not(visitor)``:
113
+ * the gate matches iff the operand does not.
114
+ */
115
+ function not(operand) {
116
+ return new CompositePrecondition("not", [operand]);
117
+ }
31
118
  class Check extends visitor_1.TreeVisitor {
32
119
  constructor(check, v) {
33
120
  super();
@@ -35,6 +122,10 @@ class Check extends visitor_1.TreeVisitor {
35
122
  this.v = v;
36
123
  }
37
124
  async isAcceptable(sourceFile, ctx) {
125
+ if (this.check instanceof RecipeRef || this.check instanceof CompositePrecondition) {
126
+ // RecipeRef / Composite have no in-process is_acceptable — defer to the wrapped editor.
127
+ return this.v.isAcceptable(sourceFile, ctx);
128
+ }
38
129
  return await (await this.checkVisitor()).isAcceptable(sourceFile, ctx) &&
39
130
  await this.v.isAcceptable(sourceFile, ctx);
40
131
  }
@@ -46,20 +137,95 @@ class Check extends visitor_1.TreeVisitor {
46
137
  ? this.v.visit(tree, ctx, parent)
47
138
  : this.v.visit(tree, ctx);
48
139
  }
49
- const checkResult = parent !== undefined
50
- ? await (await this.checkVisitor()).visit(tree, ctx, parent)
51
- : await (await this.checkVisitor()).visit(tree, ctx);
52
- // If check visitor modified the tree (returned something different), run the main visitor
53
- if (checkResult !== tree) {
140
+ // In-process fallback for a RecipeRef: if a localVisitor was
141
+ // provided, evaluate the gate against it (preserves real filtering
142
+ // for unit tests); otherwise treat as "always matches" so the
143
+ // wrapped editor still runs. Wire-side optimization (skip the
144
+ // visit RPC when the precondition rejects the file) lives in
145
+ // optimizePreconditions and is independent of localVisitor.
146
+ if (this.check instanceof RecipeRef) {
147
+ if (this.check.localVisitor !== undefined) {
148
+ const localResult = parent !== undefined
149
+ ? await this.check.localVisitor.visit(tree, ctx, parent)
150
+ : await this.check.localVisitor.visit(tree, ctx);
151
+ if (localResult === tree) {
152
+ return tree;
153
+ }
154
+ }
155
+ return parent !== undefined
156
+ ? this.v.visit(tree, ctx, parent)
157
+ : this.v.visit(tree, ctx);
158
+ }
159
+ const matched = this.check instanceof CompositePrecondition
160
+ ? await evaluateComposite(this.check, tree, ctx, parent)
161
+ : await this.runLeafCheck(tree, ctx, parent);
162
+ if (matched) {
54
163
  return parent !== undefined
55
164
  ? this.v.visit(tree, ctx, parent)
56
165
  : this.v.visit(tree, ctx);
57
166
  }
58
167
  return tree;
59
168
  }
169
+ async runLeafCheck(tree, ctx, parent) {
170
+ const checkResult = parent !== undefined
171
+ ? await (await this.checkVisitor()).visit(tree, ctx, parent)
172
+ : await (await this.checkVisitor()).visit(tree, ctx);
173
+ return checkResult !== tree;
174
+ }
60
175
  async checkVisitor() {
61
176
  return this.check instanceof recipe_1.Recipe ? this.check.editor() : this.check;
62
177
  }
63
178
  }
64
179
  exports.Check = Check;
180
+ /**
181
+ * Evaluate a {@link CompositePrecondition} in-process for unit tests and
182
+ * direct callers that don't have a live RPC. Mirrors Java's
183
+ * ``Preconditions.or``/``and``/``not`` semantics. Returns ``true`` iff the
184
+ * gate would let the wrapped visitor run.
185
+ */
186
+ async function evaluateComposite(composite, tree, ctx, parent) {
187
+ const operands = composite.operands;
188
+ switch (composite.op) {
189
+ case "or":
190
+ for (const operand of operands) {
191
+ if (await operandMatches(operand, tree, ctx, parent))
192
+ return true;
193
+ }
194
+ return false;
195
+ case "and":
196
+ for (const operand of operands) {
197
+ if (!(await operandMatches(operand, tree, ctx, parent)))
198
+ return false;
199
+ }
200
+ return true;
201
+ case "not":
202
+ if (operands.length !== 1) {
203
+ throw new Error("CompositePrecondition op=not requires exactly one operand");
204
+ }
205
+ return !(await operandMatches(operands[0], tree, ctx, parent));
206
+ }
207
+ }
208
+ async function operandMatches(operand, tree, ctx, parent) {
209
+ if (operand instanceof RecipeRef) {
210
+ // If a localVisitor was provided, evaluate against it for real;
211
+ // otherwise short-circuit to "always matches" so the wrapped
212
+ // editor still runs in unit tests. The host evaluates the gate
213
+ // for real once the response goes over the wire.
214
+ if (operand.localVisitor === undefined) {
215
+ return true;
216
+ }
217
+ const result = parent !== undefined
218
+ ? await operand.localVisitor.visit(tree, ctx, parent)
219
+ : await operand.localVisitor.visit(tree, ctx);
220
+ return result !== tree;
221
+ }
222
+ if (operand instanceof CompositePrecondition) {
223
+ return evaluateComposite(operand, tree, ctx, parent);
224
+ }
225
+ const visitor = operand instanceof recipe_1.Recipe ? await operand.editor() : operand;
226
+ const result = parent !== undefined
227
+ ? await visitor.visit(tree, ctx, parent)
228
+ : await visitor.visit(tree, ctx);
229
+ return result !== tree;
230
+ }
65
231
  //# sourceMappingURL=preconditions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preconditions.js","sourceRoot":"","sources":["../src/preconditions.ts"],"names":[],"mappings":";;;AAoBA,sBAWC;AA/BD;;;;;;;;;;;;;;GAcG;AACH,uCAAmD;AACnD,iCAA8D;AAC9D,qCAAgC;AAGzB,KAAK,UAAU,KAAK,CACvB,cAAiI,EACjI,CAA+E;IAE/E,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC;IAE1B,IAAI,OAAO,aAAa,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,qBAAW,GAAuB,CAAC;IAC1E,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED,MAAa,KAAsB,SAAQ,qBAAgC;IACvE,YACa,KAAgD,EAChD,CAAmC;QAE5C,KAAK,EAAE,CAAC;QAHC,UAAK,GAAL,KAAK,CAA2C;QAChD,MAAC,GAAD,CAAC,CAAkC;IAGhD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,UAAsB,EAAE,GAAqB;QAC5D,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC;YAClE,MAAM,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,KAAK,CAAc,IAAU,EAAE,GAAqB,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AAC;QACxC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrC,OAAO,MAAM,KAAK,IAAI,CAAC;AAC3B,CAAC"}
@@ -1 +1 @@
1
- 8.81.10
1
+ 8.81.12
@@ -13,6 +13,17 @@ export declare class PrepareRecipe {
13
13
  * precondition passes.
14
14
  */
15
15
  private static optimizePreconditions;
16
+ /**
17
+ * Translate a precondition condition (operand) to a wire entry.
18
+ *
19
+ * Mirrors the Java {@code PrepareRecipeResponse.Precondition} schema:
20
+ * leaves carry {@code visitorName} (+ optional options); composites
21
+ * carry {@code op} ({@code "or"}/{@code "and"}/{@code "not"}) and a
22
+ * nested {@code operands} list. Returns {@code undefined} when the
23
+ * condition can't be serialized — the caller leaves the wrapper
24
+ * intact so the gate runs in-process as a fallback.
25
+ */
26
+ private static conditionWireEntry;
16
27
  private static visitorTypePrecondition;
17
28
  }
18
29
  export interface DelegatesTo {
@@ -28,8 +39,21 @@ export interface PrepareRecipeResponse {
28
39
  scanPreconditions: Precondition[];
29
40
  delegatesTo?: DelegatesTo;
30
41
  }
42
+ /**
43
+ * Either a leaf (a single visitor identified by {@code visitorName} +
44
+ * optional {@code visitorOptions}) or a composite of nested preconditions
45
+ * joined by {@code op} ({@code "or"} / {@code "and"} / {@code "not"}).
46
+ *
47
+ * When {@code op} is undefined the entry is a leaf and {@code visitorName}
48
+ * is required; when {@code op} is set, {@code operands} carries the
49
+ * children and the visitor fields are ignored. The composite form mirrors
50
+ * Java's {@code Preconditions.or}/{@code and}/{@code not} so remote
51
+ * languages can express the same gate shapes the Java side does.
52
+ */
31
53
  export interface Precondition {
32
- visitorName: string;
54
+ visitorName?: string;
33
55
  visitorOptions?: {};
56
+ op?: "or" | "and" | "not";
57
+ operands?: Precondition[];
34
58
  }
35
59
  //# sourceMappingURL=prepare-recipe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepare-recipe.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/prepare-recipe.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAOtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,aAAa;IACV,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAU,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAArC,EAAE,EAAE,MAAM,EAAmB,OAAO,CAAC,EAAE,GAAG,YAAA;IAGvE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,EAC7B,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,UAAU,CAAC,EAAE,MAAM;mBAmDZ,iBAAiB;IAStC;;;;OAIG;mBACkB,qBAAqB;mBAuCrB,uBAAuB;CA+B/C;AAED,MAAM,WAAW,WAAW;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAqB;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,gBAAgB,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,YAAY,EAAE,CAAA;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,YAAY,EAAE,CAAA;IACjC,WAAW,CAAC,EAAE,WAAW,CAAA;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,EAAE,CAAA;CACtB"}
1
+ {"version":3,"file":"prepare-recipe.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/prepare-recipe.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,iBAAiB,EAAC,MAAM,q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9 @@ class PrepareRecipe {
124
124
  }
125
125
  }
126
126
  if (visitor instanceof preconditions_1.Check) {
127
- if (visitor.check instanceof recipe_2.RpcRecipe) {
128
- preconditions.push({ visitorName: phase === "edit" ? visitor.check.editVisitor : visitor.check.scanVisitor });
127
+ const wireEntry = this.conditionWireEntry(visitor.check, phase);
128
+ if (wireEntry) {
129
+ preconditions.push(wireEntry);
129
130
  recipe = Object.assign(Object.create(Object.getPrototypeOf(recipe)), recipe, phase === "edit" ?
130
131
  {
131
132
  async editor() {
@@ -146,6 +147,41 @@ class PrepareRecipe {
146
147
  }
147
148
  return recipe;
148
149
  }
150
+ /**
151
+ * Translate a precondition condition (operand) to a wire entry.
152
+ *
153
+ * Mirrors the Java {@code PrepareRecipeResponse.Precondition} schema:
154
+ * leaves carry {@code visitorName} (+ optional options); composites
155
+ * carry {@code op} ({@code "or"}/{@code "and"}/{@code "not"}) and a
156
+ * nested {@code operands} list. Returns {@code undefined} when the
157
+ * condition can't be serialized — the caller leaves the wrapper
158
+ * intact so the gate runs in-process as a fallback.
159
+ */
160
+ static conditionWireEntry(condition, phase) {
161
+ if (condition instanceof preconditions_1.CompositePrecondition) {
162
+ const operands = [];
163
+ for (const operand of condition.operands) {
164
+ const entry = this.conditionWireEntry(operand, phase);
165
+ if (entry === undefined) {
166
+ return undefined;
167
+ }
168
+ operands.push(entry);
169
+ }
170
+ return { op: condition.op, operands };
171
+ }
172
+ // Common case: helpers like usesMethod / usesType return a lightweight
173
+ // RecipeRef so the recipe author can declare a precondition without
174
+ // firing an RPC at editor() time. The Java host's
175
+ // PreparedRecipeCache.instantiateVisitor constructs the named recipe
176
+ // via Jackson and uses its visitor.
177
+ if (condition instanceof preconditions_1.RecipeRef) {
178
+ return { visitorName: condition.recipeName, visitorOptions: Object.assign({}, condition.options) };
179
+ }
180
+ if (condition instanceof recipe_2.RpcRecipe) {
181
+ return { visitorName: phase === "edit" ? condition.editVisitor : condition.scanVisitor };
182
+ }
183
+ return undefined;
184
+ }
149
185
  static async visitorTypePrecondition(preconditions, v) {
150
186
  let treeType;
151
187
  // Use dynamic import to defer loading and avoid circular dependencies
@@ -1 +1 @@
1
- {"version":3,"file":"prepare-recipe.js","sourceRoot":"","sources":["../../../src/rpc/request/prepare-recipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,yDAA2C;AAE3C,yCAAsE;AACtE,gEAA0D;AAC1D,uDAA0C;AAC1C,sCAAoC;AAGpC,uCAAsC;AAGtC,MAAa,aAAa;IACtB,YAA6B,EAAU,EAAmB,OAAa;QAA1C,OAAE,GAAF,EAAE,CAAQ;QAAmB,YAAO,GAAP,OAAO,CAAM;IACvE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,UAA6B,EAC7B,WAA8B,EAC9B,eAAoC,EACpC,UAAmB;QAC7B,MAAM,SAAS,GAAG,IAAA,0BAAW,GAAE,CAAC;QAChC,UAAU,CAAC,SAAS,CAChB,IAAI,GAAG,CAAC,WAAW,CAA8C,eAAe,CAAC,EACjF,IAAA,qBAAW,EACP,eAAe,EACf,UAAU,EACV,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;;YAC3B,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;YAC5B,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YAChC,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YACnE,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,UAAU,OAAO,CAAC,EAAE,sCAAsC,CAAC,CAAC;YAChF,CAAC;YAC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gC,CAAC;QAChD,CAAC;aAAM,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC;YAClC,QAAQ,GAAG,gCAAgC,CAAC;QAChD,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACX,aAAa,CAAC,IAAI,CAAC;gBACf,WAAW,EAAE,8CAA8C;gBAC3D,cAAc,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;aACnC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAnLD,sCAmLC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.81.10",
3
+ "version": "8.81.12",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "repository": {
@@ -13,29 +13,101 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import {RewriteRpc} from "../rpc/rewrite-rpc";
17
- import {UsesMethod, UsesType} from "./search";
18
- import {ExecutionContext} from "../execution";
19
- import {TreeVisitor} from "../visitor";
16
+ import {RecipeRef} from "../preconditions";
20
17
  import {IsSourceFile} from "../search";
21
- import {RpcRecipe} from "../rpc/recipe";
18
+ import {UsesMethod, UsesType} from "./search";
22
19
 
23
- export function hasSourcePath(filePattern: string): Promise<RpcRecipe> | TreeVisitor<any, ExecutionContext> {
24
- return RewriteRpc.get() ? RewriteRpc.get()!.prepareRecipe("org.openrewrite.FindSourceFiles", {
25
- filePattern
26
- }) : new IsSourceFile(filePattern);
20
+ /**
21
+ * Match source files by path glob.
22
+ *
23
+ * Returns a {@link RecipeRef} placeholder bundled with a native
24
+ * {@link IsSourceFile} visitor for in-process evaluation. The framework
25
+ * introspects a ``check(hasSourcePath(...), editor)`` wrapper at
26
+ * PrepareRecipe time and emits the recipe identity directly in
27
+ * ``editPreconditions``; the Java host's ``PreparedRecipeCache.instantiateVisitor``
28
+ * constructs the recipe and uses its visitor — no extra RPC round-trip
29
+ * needed at editor() construction time. Unit tests without an active
30
+ * RPC connection fall back to the bundled native visitor for real
31
+ * filtering.
32
+ *
33
+ * Delegates to {@code org.openrewrite.FindSourceFiles}.
34
+ */
35
+ export function hasSourcePath(filePattern: string): RecipeRef {
36
+ return new RecipeRef(
37
+ "org.openrewrite.FindSourceFiles",
38
+ {filePattern},
39
+ new IsSourceFile(filePattern),
40
+ );
27
41
  }
28
42
 
29
- export function usesMethod(methodPattern: string, matchOverrides: boolean = false): Promise<RpcRecipe> | TreeVisitor<any, ExecutionContext> {
30
- return RewriteRpc.get() ? RewriteRpc.get()!.prepareRecipe("org.openrewrite.java.search.HasMethod", {
31
- methodPattern,
32
- matchOverrides
33
- }) : new UsesMethod(methodPattern);
43
+ /**
44
+ * Match files using a specific method.
45
+ *
46
+ * Returns a {@link RecipeRef} placeholder bundled with a native
47
+ * {@link UsesMethod} visitor for in-process evaluation; see
48
+ * {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
49
+ *
50
+ * ``methodPattern`` follows the OpenRewrite method-pattern syntax:
51
+ * ``<receiver-type> <method-name>(<args>)`` — e.g.
52
+ * ``"*..* tostring(..)"`` or ``"java.util.Collections emptyList()"``.
53
+ *
54
+ * Delegates to {@code org.openrewrite.java.search.HasMethod}.
55
+ */
56
+ export function usesMethod(methodPattern: string, matchOverrides: boolean = false): RecipeRef {
57
+ return new RecipeRef(
58
+ "org.openrewrite.java.search.HasMethod",
59
+ {methodPattern, matchOverrides},
60
+ new UsesMethod(methodPattern),
61
+ );
34
62
  }
35
63
 
36
- export function usesType(fullyQualifiedType: string): Promise<RpcRecipe> | TreeVisitor<any, ExecutionContext> {
37
- return RewriteRpc.get() ? RewriteRpc.get()!.prepareRecipe("org.openrewrite.java.search.HasType", {
38
- fullyQualifiedType,
39
- checkAssignability: false
40
- }) : new UsesType(fullyQualifiedType);
64
+ /**
65
+ * Match files using a specific type.
66
+ *
67
+ * Returns a {@link RecipeRef} placeholder bundled with a native
68
+ * {@link UsesType} visitor for in-process evaluation; see
69
+ * {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
70
+ *
71
+ * Delegates to {@code org.openrewrite.java.search.HasType}.
72
+ */
73
+ export function usesType(fullyQualifiedTypeName: string, checkAssignability: boolean = false): RecipeRef {
74
+ return new RecipeRef(
75
+ "org.openrewrite.java.search.HasType",
76
+ {fullyQualifiedTypeName, checkAssignability},
77
+ new UsesType(fullyQualifiedTypeName),
78
+ );
79
+ }
80
+
81
+ /**
82
+ * Find and mark methods matching a pattern.
83
+ *
84
+ * Returns a {@link RecipeRef} placeholder bundled with a native
85
+ * {@link UsesMethod} visitor for in-process evaluation; see
86
+ * {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
87
+ *
88
+ * Delegates to {@code org.openrewrite.java.search.FindMethods}.
89
+ */
90
+ export function findMethods(methodPattern: string, matchOverrides: boolean = false): RecipeRef {
91
+ return new RecipeRef(
92
+ "org.openrewrite.java.search.FindMethods",
93
+ {methodPattern, matchOverrides},
94
+ new UsesMethod(methodPattern),
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Find and mark usages of a type.
100
+ *
101
+ * Returns a {@link RecipeRef} placeholder bundled with a native
102
+ * {@link UsesType} visitor for in-process evaluation; see
103
+ * {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
104
+ *
105
+ * Delegates to {@code org.openrewrite.java.search.FindTypes}.
106
+ */
107
+ export function findTypes(fullyQualifiedTypeName: string): RecipeRef {
108
+ return new RecipeRef(
109
+ "org.openrewrite.java.search.FindTypes",
110
+ {fullyQualifiedTypeName},
111
+ new UsesType(fullyQualifiedTypeName),
112
+ );
41
113
  }
@@ -1815,7 +1815,16 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
1815
1815
  }
1816
1816
  }
1817
1817
 
1818
- override async visitSpace(space: J.Space, p: PrintOutputCapture): Promise<J.Space> {
1818
+ override async visitSpace(space: J.Space | undefined, p: PrintOutputCapture): Promise<J.Space> {
1819
+ // Recipes can mutate trees in ways that drop required Space fields (e.g. a
1820
+ // RightPadded with `after` left undefined). The hot path is BatchVisit →
1821
+ // print, so throwing here aborts the formatter for the whole file and the
1822
+ // caller falls back to "essential formatting", losing Prettier output.
1823
+ // Treat a missing Space as empty: produces correct text and keeps the
1824
+ // recipe on the fast path.
1825
+ if (!space) {
1826
+ return emptySpace;
1827
+ }
1819
1828
  p.append(space.whitespace!);
1820
1829
 
1821
1830
  const comments = space.comments;