Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Sep 9, 2024
1 parent 4366076 commit d25a5bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 15 additions & 4 deletions openrewrite/src/core/markers.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import {random_id, UUID} from "./tree";

export interface Marker {
id(): UUID;

withId(id: UUID): Marker;
}

export class Markers {
public static readonly EMPTY: Markers = new Markers(random_id(), []);

private readonly _id: string;
private readonly _id: UUID;
private readonly _markers: Marker[] = [];

constructor(id: UUID, markers: Marker[]) {
this._id = id;
this._markers = markers;
}

public id(): string {
public id(): UUID {
return this._id;
}

public withId(id: UUID): Markers {
return this._id === id ? this : new Markers(id, this._markers);
}

public markers(): Marker[] {
return this._markers;
}

public findFirst<T extends Marker>(markerType: new () => T): T | null {
return this._markers.find((marker) => marker instanceof markerType) as T || null;
public withMarkers(markers: Marker[]): Markers {
return this._markers === markers ? this : new Markers(this._id, markers);
}

public findFirst<T extends Marker>(markerType: new () => T): T | undefined {
return this._markers.find((marker) => marker instanceof markerType) as T || undefined;
}
}
8 changes: 7 additions & 1 deletion openrewrite/src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export class Cursor {
public fork(): Cursor {
return new Cursor(this._parent === null ? null : this._parent.fork(), this.value);
}
}
}

export interface Tree {
id(): UUID;

withId(id: UUID): Tree;
}

0 comments on commit d25a5bc

Please sign in to comment.