Skip to content

Commit

Permalink
Regenerate Json and Yaml LST models (#212)
Browse files Browse the repository at this point in the history
* Regenerate `Json` and `Yaml` LST models

* Fix `RemotingRecipeRunTest` error
  • Loading branch information
knutwannheden authored Mar 3, 2025
1 parent 7f8b138 commit 00e461c
Show file tree
Hide file tree
Showing 14 changed files with 451 additions and 242 deletions.
2 changes: 1 addition & 1 deletion openrewrite/src/json/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JsonVisitor} from "./visitor";
import {JsonRightPadded, Space} from "./support_types";
import {JsonRightPadded, Space} from "./tree";
import {Tree} from "../core";

export function visitRightPadded<P, T extends Tree>(v: JsonVisitor<P>, right: JsonRightPadded<T> | null, p: P): JsonRightPadded<T> {
Expand Down
1 change: 0 additions & 1 deletion openrewrite/src/json/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './markers';
export * from './support_types';
export * from './tree';
export * from './visitor';
44 changes: 0 additions & 44 deletions openrewrite/src/json/support_types.ts

This file was deleted.

1 change: 1 addition & 0 deletions openrewrite/src/json/tree/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
2 changes: 2 additions & 0 deletions openrewrite/src/json/tree/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './support_types';
export * from './tree';
104 changes: 104 additions & 0 deletions openrewrite/src/json/tree/support_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {LstType, Markers, Tree, TreeVisitor, UUID} from "../../core";
import {JsonVisitor} from "../visitor";

export interface Json extends Tree {
get prefix(): Space;

withPrefix(prefix: Space): Json;

get id(): UUID;

withId(id: UUID): Json;

get markers(): Markers;

withMarkers(markers: Markers): Json;

isAcceptable<P>(v: TreeVisitor<Tree, P>, p: P): boolean;

accept<R extends Tree, P>(v: TreeVisitor<R, P>, p: P): R | null;

acceptJson<P>(v: JsonVisitor<P>, p: P): Json | null;
}

type Constructor<T = {}> = new (...args: any[]) => T;

export function isJson(tree: any): tree is Json {
return !!tree.constructor.isJson || !!tree.isJson;
}

export function JsonMixin<TBase extends Constructor<Object>>(Base: TBase) {
abstract class JsonMixed extends Base implements Json {
static isTree = true;
static isJson = true;

abstract get prefix(): Space;

abstract withPrefix(prefix: Space): Json;

abstract get id(): UUID;

abstract withId(id: UUID): Json;

abstract get markers(): Markers;

abstract withMarkers(markers: Markers): Json;

public isAcceptable<P>(v: TreeVisitor<Tree, P>, p: P): boolean {
return v.isAdaptableTo(JsonVisitor);
}

public accept<R extends Tree, P>(v: TreeVisitor<R, P>, p: P): R | null {
return this.acceptJson(v.adapt(JsonVisitor), p) as unknown as R | null;
}

public acceptJson<P>(v: JsonVisitor<P>, p: P): Json | null {
return v.defaultValue(this, p) as Json | null;
}
}

return JsonMixed;
}

export interface JsonKey extends Tree {
}

export interface JsonValue extends Tree {
}

@LstType("org.openrewrite.json.tree.Space")
export class Space {
}

@LstType("org.openrewrite.json.tree.Comment")
export class Comment {
}

@LstType("org.openrewrite.json.tree.JsonRightPadded")
export class JsonRightPadded<T extends Tree> {
constructor(element: T) {
this._element = element;
}

private readonly _element: T;

get element(): T {
return this._element;
}

static getElements<T extends Tree>(padded: JsonRightPadded<T>[]) {
return [];
}

static withElements<T extends Tree>(padded: JsonRightPadded<T>[], elements: T[]) {
return [];
}

static withElement<T extends Tree>(padded: JsonRightPadded<T>, element: T): JsonRightPadded<T> {
return padded;
}

withElement(element: T) : JsonRightPadded<T> {
return undefined!;
}
}
Loading

0 comments on commit 00e461c

Please # to comment.