Skip to content

Commit

Permalink
Regenerate Yaml and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Sep 20, 2024
1 parent 7f0de27 commit a260115
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 211 deletions.
2 changes: 1 addition & 1 deletion openrewrite/src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class FileAttributes {
const SourceFileSymbol = Symbol('SourceFile');

// This allows using `SourceFile` like a class in certain situations (e.g. `Cursor.firstEnclosing()`)
export const SourceFile = SourceFileSymbol;
const SourceFile = SourceFileSymbol;

export function isSourceFile(tree: any & Tree): tree is SourceFile {
// return 'sourcePath' in tree && 'printer' in tree;
Expand Down
7 changes: 4 additions & 3 deletions openrewrite/src/java/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {JavaVisitor} from "./visitor";
import {
isJava,
J,
JavaType,
JContainer,
JLeftPadded,
JRightPadded,
Space,
} from "./support_types";
import {J} from "./tree";
import {Cursor, ListUtils} from "../core";

export function getJavaType<T extends J>(expr: T): JavaType | null {
Expand Down Expand Up @@ -67,7 +68,7 @@ export function visitLeftPadded<P, T>(v: JavaVisitor<P>, left: JLeftPadded<T> |

let before = v.visitSpace(left.before, JLeftPadded.Location.beforeLocation(loc), p)!;
let t = left.element;
if (left.element instanceof J)
if (isJava(left.element))
t = v.visit(t as J, p) as T;
v.cursor = v.cursor.parent!;

Expand All @@ -84,7 +85,7 @@ export function visitRightPadded<P, T>(v: JavaVisitor<P>, right: JRightPadded<T>
return null;

let t = right.element;
if (t instanceof J) {
if (isJava(t)) {
v.cursor = new Cursor(v.cursor, right);
t = v.visit(t as J, p) as T;
v.cursor = v.cursor.parent!;
Expand Down
3 changes: 2 additions & 1 deletion openrewrite/src/java/support_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {JavaType} from "./types";
import {JavaVisitor} from "./visitor";

export {JavaType} from "./types";
export * as J from './tree'

export interface J extends Tree {
get prefix(): Space;
Expand Down Expand Up @@ -65,6 +64,8 @@ export function JMixin<TBase extends Constructor<Object>>(Base: TBase) {
return JMixed;
}

export * as J from './tree';

export interface JavaSourceFile extends SourceFile {
}

Expand Down
4 changes: 2 additions & 2 deletions openrewrite/src/javascript/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {J, JavaType, JavaVisitor, JContainer, JLeftPadded, JRightPadded, Space} from "../java";
import {J, JavaType, JContainer, JLeftPadded, JRightPadded, Space} from "../java";
import * as java_extensions from "../java/extensions";
import {JavaScriptVisitor} from "./visitor";
import {JsContainer, JsLeftPadded, JsRightPadded, JsSpace} from "./support_types";
import {JS} from "./tree";
import {JS} from "./support_types";

export function getJavaType<T extends J>(expr: T): JavaType | null {
if (expr instanceof JS.Alias) {
Expand Down
1 change: 0 additions & 1 deletion openrewrite/src/javascript/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';
3 changes: 1 addition & 2 deletions openrewrite/src/javascript/support_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {J, JavaVisitor, Space} from "../java";
import {Markers, Tree, TreeVisitor, UUID} from "../core";
import {JavaScriptVisitor} from "./visitor";

export * as JS from './tree'

export interface JS extends J {
get id(): UUID;

Expand Down Expand Up @@ -64,6 +62,7 @@ export function JSMixin<TBase extends Constructor<Object>>(Base: TBase) {
return JSMixed;
}

export * as JS from './tree';

export namespace JsSpace {
export enum Location {
Expand Down
4 changes: 2 additions & 2 deletions openrewrite/src/javascript/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class CompilationUnit extends SourceFileMixin(JSMixin(Object)) implements
}

public acceptJavaScript<P>(v: JavaScriptVisitor<P>, p: P): J | null {
return v.visitCompilationUnit(this, p);
return v.visitJsCompilationUnit(this, p);
}

get padding() {
Expand Down Expand Up @@ -2026,7 +2026,7 @@ export class Unary extends JSMixin(Object) implements Statement, Expression, Typ
}

public acceptJavaScript<P>(v: JavaScriptVisitor<P>, p: P): J | null {
return v.visitUnary(this, p);
return v.visitJsUnary(this, p);
}

get padding() {
Expand Down
4 changes: 2 additions & 2 deletions openrewrite/src/javascript/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class JavaScriptVisitor<P> extends JavaVisitor<P> {
return isJavaScript(sourceFile);
}

public visitCompilationUnit(compilationUnit: JS.CompilationUnit, p: P): J | null {
public visitJsCompilationUnit(compilationUnit: JS.CompilationUnit, p: P): J | null {
compilationUnit = compilationUnit.withPrefix(this.visitSpace(compilationUnit.prefix, Space.Location.COMPILATION_UNIT_PREFIX, p)!);
compilationUnit = compilationUnit.withMarkers(this.visitMarkers(compilationUnit.markers, p));
compilationUnit = compilationUnit.padding.withImports(ListUtils.map(compilationUnit.padding.imports, el => this.visitRightPadded(el, JRightPadded.Location.IMPORT, p)));
Expand Down Expand Up @@ -282,7 +282,7 @@ export class JavaScriptVisitor<P> extends JavaVisitor<P> {
return typeOperator;
}

public visitUnary(unary: JS.Unary, p: P): J | null {
public visitJsUnary(unary: JS.Unary, p: P): J | null {
unary = unary.withPrefix(this.visitSpace(unary.prefix, JsSpace.Location.UNARY_PREFIX, p)!);
let tempStatement = this.visitStatement(unary, p) as Statement & J;
if (!(tempStatement instanceof JS.Unary))
Expand Down
1 change: 0 additions & 1 deletion openrewrite/src/yaml/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';
59 changes: 57 additions & 2 deletions openrewrite/src/yaml/support_types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
import {Tree} from "../core";
import {Markers, Tree, TreeVisitor, UUID} from "../core";
import {YamlVisitor} from "./visitor";

export interface Yaml extends Tree {
get id(): UUID;

withId(id: UUID): Yaml;

get markers(): Markers;

withMarkers(markers: Markers): Yaml;

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

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

acceptYaml<P>(v: YamlVisitor<P>, p: P): Yaml | null;
}

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

const YamlSymbol = Symbol('Yaml');

export function isYaml(tree: any & Tree): tree is Yaml {
return tree && tree[YamlSymbol] === true;
}

export function YamlMixin<TBase extends Constructor<Object>>(Base: TBase) {
abstract class YamlMixed extends Base implements Yaml {
[YamlSymbol]: true = true;

abstract get id(): UUID;

abstract withId(id: UUID): Yaml;

abstract get markers(): Markers;

abstract withMarkers(markers: Markers): Yaml;

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

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

public acceptYaml<P>(v: YamlVisitor<P>, p: P): Yaml | null {
return v.defaultValue(this, p) as Yaml | null;
}
}

return YamlMixed;
}

export * as Yaml from './tree';

export interface YamlKey extends Tree {
// get value(): string;

withPrefix(prefix: string): YamlKey;
}
}
Loading

0 comments on commit a260115

Please sign in to comment.