import { Position, Source } from "./position"; import "reflect-metadata"; import { PossiblyNamed, ReferenceByName } from "./naming"; export declare const NODE_DEFINITION_SYMBOL: unique symbol; export type PackageDescription = { name: string; nodes: { [name: string]: abstract new (...args: any[]) => Node; }; }; export declare const NODE_TYPES: { [name: string]: PackageDescription; }; export type NodeDefinition = { package?: string; name?: string; features: { [name: string | symbol]: Feature; }; resolved?: boolean; }; export type Feature = { name: string | symbol; child?: boolean; multiple?: boolean; inherited?: boolean; reference?: boolean; type?: any; arrayType?: any; }; /** * @deprecated replaced by Feature */ export type PropertyDefinition = Feature; export declare function getNodeDefinition(node: Node | (abstract new (...args: any[]) => Node)): NodeDefinition; export declare abstract class Origin { abstract get position(): Position | undefined; get sourceText(): string | undefined; /** * Tests whether the given position is contained in the interval represented by this object. * @param position the position */ contains(position?: Position): boolean; /** * Tests whether the given position overlaps the interval represented by this object. * @param position the position */ overlaps(position?: Position): boolean; get source(): Source | undefined; } export declare class SimpleOrigin extends Origin { myPosition?: Position | undefined; mySourceText?: string | undefined; constructor(myPosition?: Position | undefined, mySourceText?: string | undefined); get position(): Position | undefined; get sourceText(): string | undefined; } export interface Destination { } export declare class CompositeDestination implements Destination { readonly elements: Destination[]; constructor(elements: Destination[]); } export declare class TextFileDestination implements Destination { readonly position?: Position | undefined; constructor(position?: Position | undefined); } /** * The Abstract Syntax Tree will be constituted by instances of Node. * * It implements Origin as it could be the source of a AST-to-AST transformation, so the node itself can be * the Origin of another node. */ export declare abstract class Node extends Origin implements Destination { protected positionOverride?: Position | undefined; parent?: Node; origin?: Origin; destination?: Destination; constructor(positionOverride?: Position | undefined); get children(): Node[]; getChildNames(): string[]; get nodeDefinition(): NodeDefinition; get features(): FeatureDescription[]; containment(name: string | symbol): Feature | undefined; setChild(name: string | symbol, child: Node): void; addChild(name: string | symbol, child: Node): void; private notAContainment; getChild(name: string | symbol, index?: number): Node | undefined; protected doGetChildOrChildren(name: string | symbol): Node | Node[] | undefined; getChildren(name?: string | symbol): Node[]; getAllChildren(): Node[]; getChildrenWithRole(name: string | symbol): Node[]; getAttributeValue(name: string | symbol): any; setAttributeValue(name: string | symbol, value: any): void; protected doSetAttributeValue(name: string | symbol, value: any): void; protected doGetAttributeValue(name: string | symbol): any; getReference(name: string | symbol): ReferenceByName | undefined; protected doGetReference(name: string | symbol): any; withParent(parent?: Node): this; /** * Replace the current Node with another Node * * @throws Error - if this.parent === undefined */ replaceWith(other: Node): void; /** * Apply the given `operation` function to * all of the Node's children. * * It's possible to use both pure functions, * to replace the nodes, and functions that mutate * the nodes in-place. */ transformChildren(operation: (node: Node) => Node): void; withOrigin(origin?: Origin): this; get position(): Position | undefined; set position(newPos: Position | undefined); get sourceText(): string | undefined; } export interface FeatureDescription { name: string; value: any; } export declare class NodeVisitor { visit(node: Node): void; protected visitNode(ast: Node): void; protected visitChildren(node: Node): void; } export declare function ensurePackage(packageName: string): PackageDescription; export declare function errorOnRedefinition(name: string, target: abstract new (...args: any[]) => T, existingTarget: abstract new (...args: any[]) => Node): void; export declare function warnOnRedefinition(name: string, target: abstract new (...args: any[]) => T, existingTarget: abstract new (...args: any[]) => Node): void; export declare function setNodeRedefinitionStrategy(strategy: typeof errorOnRedefinition): void; export declare function registerNodeDefinition(target: abstract new (...args: any[]) => T, pkg?: string, name?: string): NodeDefinition; export declare function ensureNodeDefinition(node: Node | { new (...args: any[]): Node; }): NodeDefinition; export declare function registerNodeAttribute(type: { new (...args: any[]): T; }, methodName: string | symbol): Feature; export declare function registerNodeChild(type: new (...args: any[]) => T, methodName: string, multiple?: boolean): Feature; export declare function registerNodeReference(type: new (...args: any[]) => T, methodName: string): Feature; export declare function ASTNode(pkg: string, name: string): (target: abstract new (...args: any[]) => T) => void; /** * Declares the decorated property as the holder of a child node. */ export declare function Child(): (target: any, methodName: string) => void; /** * Declares the decorated property as the holder of a collection of child nodes. */ export declare function Children(): (target: any, methodName: string) => void; /** * Declares the decorated property as an attribute. * @deprecated use Attribute instead. */ export declare function Property(): (target: any, methodName: string) => void; /** * Declares the decorated property as an attribute. */ export declare function Attribute(): (target: any, methodName: string) => void; /** * Declares the decorated property as a reference. */ export declare function Reference(): (target: any, methodName: string) => void;