Skip to content

Commit

Permalink
rework jsimport to reflect AST structure and fix remaining gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Jan 14, 2025
1 parent f127983 commit 9981432
Show file tree
Hide file tree
Showing 21 changed files with 1,300 additions and 393 deletions.
19 changes: 1 addition & 18 deletions openrewrite/src/java/remote/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions";
import {Checksum, Cursor, FileAttributes, ListUtils, Tree} from '../../core';
import {DetailsReceiver, Receiver, ReceiverContext, ReceiverFactory, ValueType} from '@openrewrite/rewrite-remote';
import {JavaVisitor} from '..';
import {J, Comment, Expression, JavaSourceFile, JavaType, JContainer, JLeftPadded, JRightPadded, Loop, MethodCall, NameTree, Space, Statement, TextComment, TypedTree, TypeTree, AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown, Erroneous} from '../tree';
import {J, Comment, Expression, JavaSourceFile, JavaType, JContainer, JLeftPadded, JRightPadded, Loop, MethodCall, NameTree, Space, Statement, TextComment, TypedTree, TypeTree, AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown} from '../tree';
import * as Java from "../../java/tree";

export class JavaReceiver implements Receiver<J> {
Expand Down Expand Up @@ -708,14 +708,6 @@ class Visitor extends JavaVisitor<ReceiverContext> {
return source;
}

public visitErroneous(erroneous: Erroneous, ctx: ReceiverContext): J {
erroneous = erroneous.withId(ctx.receiveValue(erroneous.id, ValueType.UUID)!);
erroneous = erroneous.withPrefix(ctx.receiveNode(erroneous.prefix, receiveSpace)!);
erroneous = erroneous.withMarkers(ctx.receiveNode(erroneous.markers, ctx.receiveMarkers)!);
erroneous = erroneous.withText(ctx.receiveValue(erroneous.text, ValueType.Primitive)!);
return erroneous;
}

}

class Factory implements ReceiverFactory {
Expand Down Expand Up @@ -1471,15 +1463,6 @@ class Factory implements ReceiverFactory {
);
}

if (type === "org.openrewrite.java.tree.J$Erroneous") {
return new Erroneous(
ctx.receiveValue(null, ValueType.UUID)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)!,
ctx.receiveValue(null, ValueType.Primitive)!
);
}

throw new Error("No factory method for type: " + type);
}
}
Expand Down
10 changes: 1 addition & 9 deletions openrewrite/src/java/remote/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions";
import {Cursor, ListUtils, Tree} from '../../core';
import {Sender, SenderContext, ValueType} from '@openrewrite/rewrite-remote';
import {JavaVisitor} from '..';
import {J, Comment, Expression, JavaSourceFile, JavaType, JContainer, JLeftPadded, JRightPadded, Loop, MethodCall, NameTree, Space, Statement, TextComment, TypedTree, TypeTree, AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown, Erroneous} from '../tree';
import {J, Comment, Expression, JavaSourceFile, JavaType, JContainer, JLeftPadded, JRightPadded, Loop, MethodCall, NameTree, Space, Statement, TextComment, TypedTree, TypeTree, AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown} from '../tree';
import * as Java from "../../java/tree";

export class JavaSender implements Sender<J> {
Expand Down Expand Up @@ -708,14 +708,6 @@ class Visitor extends JavaVisitor<SenderContext> {
return source;
}

public visitErroneous(erroneous: Erroneous, ctx: SenderContext): J {
ctx.sendValue(erroneous, v => v.id, ValueType.UUID);
ctx.sendNode(erroneous, v => v.prefix, Visitor.sendSpace);
ctx.sendNode(erroneous, v => v.markers, ctx.sendMarkers);
ctx.sendValue(erroneous, v => v.text, ValueType.Primitive);
return erroneous;
}

private static sendContainer<T>(type: ValueType): (container: JContainer<T>, ctx: SenderContext) => void {
return extensions.sendContainer(type);
}
Expand Down
64 changes: 0 additions & 64 deletions openrewrite/src/java/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6320,67 +6320,3 @@ export namespace Unknown {
}

}

@LstType("org.openrewrite.java.tree.J$Erroneous")
export class Erroneous extends JMixin(Object) implements Statement, Expression {
public constructor(id: UUID, prefix: Space, markers: Markers, text: string) {
super();
this._id = id;
this._prefix = prefix;
this._markers = markers;
this._text = text;
}

private readonly _id: UUID;

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

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

private readonly _prefix: Space;

public get prefix(): Space {
return this._prefix;
}

public withPrefix(prefix: Space): Erroneous {
return prefix === this._prefix ? this : new Erroneous(this._id, prefix, this._markers, this._text);
}

private readonly _markers: Markers;

public get markers(): Markers {
return this._markers;
}

public withMarkers(markers: Markers): Erroneous {
return markers === this._markers ? this : new Erroneous(this._id, this._prefix, markers, this._text);
}

private readonly _text: string;

public get text(): string {
return this._text;
}

public withText(text: string): Erroneous {
return text === this._text ? this : new Erroneous(this._id, this._prefix, this._markers, text);
}

public acceptJava<P>(v: JavaVisitor<P>, p: P): J | null {
return v.visitErroneous(this, p);
}

public get type(): JavaType | null {
return extensions.getJavaType(this);
}

public withType(type: JavaType): Erroneous {
return extensions.withJavaType(this, type);
}

}
20 changes: 1 addition & 19 deletions openrewrite/src/java/visitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as extensions from "./extensions";
import {ListUtils, SourceFile, Tree, TreeVisitor} from "../core";
import {J, isJava, Comment, Expression, JavaSourceFile, JavaType, JContainer, JLeftPadded, JRightPadded, Loop, MethodCall, NameTree, Space, Statement, TextComment, TypedTree, TypeTree} from "./tree";
import {AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown, Erroneous} from "./tree";
import {AnnotatedType, Annotation, ArrayAccess, ArrayType, Assert, Assignment, AssignmentOperation, Binary, Block, Break, Case, ClassDeclaration, CompilationUnit, Continue, DoWhileLoop, Empty, EnumValue, EnumValueSet, FieldAccess, ForEachLoop, ForLoop, ParenthesizedTypeTree, Identifier, If, Import, InstanceOf, IntersectionType, Label, Lambda, Literal, MemberReference, MethodDeclaration, MethodInvocation, Modifier, MultiCatch, NewArray, ArrayDimension, NewClass, NullableType, Package, ParameterizedType, Parentheses, ControlParentheses, Primitive, Return, Switch, SwitchExpression, Synchronized, Ternary, Throw, Try, TypeCast, TypeParameter, TypeParameters, Unary, VariableDeclarations, WhileLoop, Wildcard, Yield, Unknown} from "./tree";

export class JavaVisitor<P> extends TreeVisitor<J, P> {
isAcceptable(sourceFile: SourceFile, p: P): boolean {
Expand Down Expand Up @@ -965,24 +965,6 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
return source;
}

public visitErroneous(erroneous: Erroneous, p: P): J | null {
erroneous = erroneous.withPrefix(this.visitSpace(erroneous.prefix, Space.Location.ERRONEOUS_PREFIX, p)!);
let tempStatement = this.visitStatement(erroneous, p) as Statement;
if (!(tempStatement instanceof Erroneous))
{
return tempStatement;
}
erroneous = tempStatement as Erroneous;
let tempExpression = this.visitExpression(erroneous, p) as Expression;
if (!(tempExpression instanceof Erroneous))
{
return tempExpression;
}
erroneous = tempExpression as Erroneous;
erroneous = erroneous.withMarkers(this.visitMarkers(erroneous.markers, p));
return erroneous;
}

public visitContainer<T>(container: JContainer<T> | null, loc: JContainer.Location, p: P): JContainer<T> | null {
return extensions.visitContainer(this, container, loc, p);
}
Expand Down
Loading

0 comments on commit 9981432

Please sign in to comment.