import { J, Type } from '../../java'; import { Any, Capture, CaptureOptions, ConstraintFunction, TemplateParam, VariadicOptions } from './types'; /** * Combines multiple constraints with AND logic. * All constraints must return true for the combined constraint to pass. * * @example * const largeEvenNumber = capture('n', { * constraint: and( * (node) => typeof node.value === 'number', * (node) => node.value > 100, * (node) => node.value % 2 === 0 * ) * }); */ export declare function and(...constraints: ConstraintFunction[]): ConstraintFunction; /** * Combines multiple constraints with OR logic. * At least one constraint must return true for the combined constraint to pass. * * @example * const stringOrNumber = capture('value', { * constraint: or( * (node) => node.kind === J.Kind.Literal && typeof node.value === 'string', * (node) => node.kind === J.Kind.Literal && typeof node.value === 'number' * ) * }); */ export declare function or(...constraints: ConstraintFunction[]): ConstraintFunction; /** * Negates a constraint. * Returns true when the constraint returns false, and vice versa. * * @example * const notString = capture('value', { * constraint: not((node) => typeof node.value === 'string') * }); */ export declare function not(constraint: ConstraintFunction): ConstraintFunction; export declare const CAPTURE_NAME_SYMBOL: unique symbol; export declare const CAPTURE_VARIADIC_SYMBOL: unique symbol; export declare const CAPTURE_CONSTRAINT_SYMBOL: unique symbol; export declare const CAPTURE_CAPTURING_SYMBOL: unique symbol; export declare const CAPTURE_TYPE_SYMBOL: unique symbol; export declare const RAW_CODE_SYMBOL: unique symbol; export declare class CaptureImpl implements Capture { readonly name: string; [CAPTURE_NAME_SYMBOL]: string; [CAPTURE_VARIADIC_SYMBOL]: VariadicOptions | undefined; [CAPTURE_CONSTRAINT_SYMBOL]: ConstraintFunction | undefined; [CAPTURE_CAPTURING_SYMBOL]: boolean; [CAPTURE_TYPE_SYMBOL]: string | Type | undefined; constructor(name: string, options?: CaptureOptions, capturing?: boolean); getName(): string; isVariadic(): boolean; getVariadicOptions(): VariadicOptions | undefined; getConstraint(): ConstraintFunction | undefined; isCapturing(): boolean; getType(): string | Type | undefined; } export declare class TemplateParamImpl implements TemplateParam { readonly name: string; constructor(name: string); getName(): string; } /** * Represents a property access on a captured value. * When you access a property on a Capture (e.g., method.name), you get a CaptureValue * that knows how to resolve that property from the matched values. */ export declare class CaptureValue { readonly rootCapture: Capture; readonly propertyPath: string[]; readonly arrayOperation?: { type: "index" | "slice" | "length"; args?: number[]; } | undefined; constructor(rootCapture: Capture, propertyPath: string[], arrayOperation?: { type: "index" | "slice" | "length"; args?: number[]; } | undefined); /** * Resolves this capture value by looking up the root capture in the values map * and navigating through the property path. */ resolve(values: Pick, 'get'>): any; /** * Checks if this CaptureValue will resolve to an array that should be expanded. */ isArrayExpansion(): boolean; } export declare function capture(options: CaptureOptions & { variadic?: never; }): Capture & T; export declare function capture(options: { name?: string; variadic: true | VariadicOptions; constraint?: ConstraintFunction; min?: number; max?: number; }): Capture & T[]; export declare function capture(name?: string): Capture & T; export declare namespace capture { var nextUnnamedId: number; } /** * Creates a non-capturing pattern match for use in patterns. * * Use `any()` when you need to match AST structure without binding the matched value to a name. * This is useful for validation patterns where you care about structure but not the specific values. * * **Key Differences from `capture()`:** * - `any()` returns `Any` type (not `Capture`) * - Cannot be used in templates (TypeScript compiler prevents this) * - Does not bind matched values (more memory efficient for patterns) * - Supports same features: constraints, variadic matching * * @template T The expected type of the matched AST node (for TypeScript autocomplete and constraints) * @param options Optional configuration (variadic, constraint) * @returns An Any object that matches patterns without capturing * * @example * // Match any single argument without capturing * const pat = pattern`foo(${any()})`; * * @example * // Match with constraint validation * const numericArg = any({ * constraint: (node) => typeof node.value === 'number' * }); * const pat = pattern`process(${numericArg})`; * * @example * // Variadic any - match zero or more without capturing * const rest = any({ variadic: true }); * const first = capture('first'); * const pat = pattern`foo(${first}, ${rest})`; * * @example * // Mixed with captures - capture some, ignore others * const important = capture('important'); * const pat = pattern` * if (${any()}) { * ${important} * } * `; * * @example * // Variadic with constraints * const numericArgs = any({ * variadic: true, * constraint: (nodes) => nodes.every(n => typeof n.value === 'number') * }); * const pat = pattern`sum(${numericArgs})`; */ export declare function any(options: { constraint: ConstraintFunction; } & { variadic?: never; }): Any & T; export declare function any(options: { variadic: true | VariadicOptions; constraint?: ConstraintFunction; min?: number; max?: number; }): Any & T[]; export declare function any(options?: CaptureOptions): Any & T; export declare namespace any { var nextAnonId: number; } /** * Creates a parameter specification for use in standalone templates (not used with patterns). * * Use `param()` when creating templates that are not used with pattern matching. * Use `capture()` when the template works with a pattern. * * @template T The expected type of the parameter value (for TypeScript autocomplete only) * @param name Optional name for the parameter. If not provided, an auto-generated name is used. * @returns A TemplateParam object (simpler than Capture, no property access support) * * @remarks * **When to use `param()` vs `capture()`:** * * - Use `param()` in **standalone templates** (no pattern matching involved) * - Use `capture()` in **patterns** and templates used with patterns * * **Key Differences:** * - `TemplateParam` is simpler - no property access proxy overhead * - `Capture` supports property access (e.g., `capture('x').name.simpleName`) * - Both work in templates, but `param()` makes intent clearer for standalone use * * @example * // ✅ GOOD: Use param() for standalone templates * const value = param('value'); * const tmpl = template`return ${value} * 2;`; * await tmpl.apply(cursor, node, new Map([['value', someLiteral]])); * * @example * // ✅ GOOD: Use capture() with patterns * const value = capture('value'); * const pat = pattern`foo(${value})`; * const tmpl = template`bar(${value})`; // capture() makes sense here * * @example * // ⚠️ CONFUSING: Using capture() in standalone template * const value = capture('value'); * template`return ${value} * 2;`; // "Capturing" what? There's no pattern! * * @example * // ❌ WRONG: param() doesn't support property access * const node = param('invocation'); * template`console.log(${node.name})` // Error! Use capture() for property access */ export declare function param(name?: string): TemplateParam; /** * Represents raw code that should be inserted verbatim into templates at construction time. * This is useful for dynamic code generation where the code structure is determined at runtime. */ export declare class RawCode { readonly code: string; [RAW_CODE_SYMBOL]: boolean; constructor(code: string); } /** * Creates a raw code specification for inserting literal code strings into templates. * * Use `raw()` when you need to insert code that is generated dynamically (e.g., from recipe options, * computed field names, or programmatic string manipulation) directly into a template at construction time. * * The string is spliced into the template before parsing, so it becomes part of the template's AST. * This is different from `param()` or `capture()` which are placeholders replaced during application. * * @param code The code string to insert verbatim into the template * @returns A RawCode object that will be spliced into the template * * @remarks * **When to use `raw()` vs `param()` vs `capture()`:** * * - Use `raw()` when you have a **code string** to insert at **template construction time** * - Use `param()` when you have an **AST node** to substitute at **template application time** * - Use `capture()` when working with **pattern matching** and need to reference matched values * * **Safety Considerations:** * - No validation is performed on the code string * - The code must be syntactically valid at the position where it's inserted * - Recipe authors are trusted to provide valid code * * @example * // Recipe option determines the log level * class MyRecipe extends Recipe { * @Option * logLevel: string = "info"; * * getVisitor() { * // Template constructed with dynamic method name * const replacement = template`logger.${raw(this.logLevel)}(${_('msg')})`; * // Produces: logger.info(...) or logger.warn(...) etc. * } * } * * @example * // Build object literal from collected field names * const fields = ["userId", "timestamp", "status"]; * template`{ ${raw(fields.join(', '))} }` * // Produces: { userId, timestamp, status } * * @example * // Dynamic import path * const modulePath = "./utils"; * template`import { helper } from ${raw(`'${modulePath}'`)}` * // Produces: import { helper } from './utils' * * @example * // Configurable operator * const operator = ">="; * template`${_('value')} ${raw(operator)} threshold` * // Produces: value >= threshold */ export declare function raw(code: string): RawCode; /** * Concise alias for `capture`. Works well for inline captures in patterns and templates. * * @param name Optional name for the capture. If not provided, an auto-generated name is used. * @returns A Capture object * * @example * // Inline captures with _ alias * pattern`isDate(${_('dateArg')})` * template`${_('dateArg')} instanceof Date` */ export declare const _: typeof capture; //# sourceMappingURL=capture.d.ts.map