Skip to content

Commit

Permalink
adopt new rewrite changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Jan 23, 2025
1 parent cd45431 commit a6b05f1
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 3 deletions.
23 changes: 22 additions & 1 deletion 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, DeconstructionPattern, 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 * as Java from "../../java/tree";

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

public visitDeconstructionPattern(deconstructionPattern: DeconstructionPattern, ctx: ReceiverContext): J {
deconstructionPattern = deconstructionPattern.withId(ctx.receiveValue(deconstructionPattern.id, ValueType.UUID)!);
deconstructionPattern = deconstructionPattern.withPrefix(ctx.receiveNode(deconstructionPattern.prefix, receiveSpace)!);
deconstructionPattern = deconstructionPattern.withMarkers(ctx.receiveNode(deconstructionPattern.markers, ctx.receiveMarkers)!);
deconstructionPattern = deconstructionPattern.withDeconstructor(ctx.receiveNode(deconstructionPattern.deconstructor, ctx.receiveTree)!);
deconstructionPattern = deconstructionPattern.padding.withNested(ctx.receiveNode(deconstructionPattern.padding.nested, receiveContainer)!);
deconstructionPattern = deconstructionPattern.withType(ctx.receiveValue(deconstructionPattern.type, ValueType.Object)!);
return deconstructionPattern;
}

public visitIntersectionType(intersectionType: IntersectionType, ctx: ReceiverContext): J {
intersectionType = intersectionType.withId(ctx.receiveValue(intersectionType.id, ValueType.UUID)!);
intersectionType = intersectionType.withPrefix(ctx.receiveNode(intersectionType.prefix, receiveSpace)!);
Expand Down Expand Up @@ -1054,6 +1064,17 @@ class Factory implements ReceiverFactory {
);
}

if (type === "org.openrewrite.java.tree.J$DeconstructionPattern") {
return new DeconstructionPattern(
ctx.receiveValue(null, ValueType.UUID)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)!,
ctx.receiveNode<Expression>(null, ctx.receiveTree)!,
ctx.receiveNode<JContainer<J>>(null, receiveContainer)!,
ctx.receiveValue(null, ValueType.Object)!
);
}

if (type === "org.openrewrite.java.tree.J$IntersectionType") {
return new IntersectionType(
ctx.receiveValue(null, ValueType.UUID)!,
Expand Down
12 changes: 11 additions & 1 deletion 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, DeconstructionPattern, 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 * as Java from "../../java/tree";

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

public visitDeconstructionPattern(deconstructionPattern: DeconstructionPattern, ctx: SenderContext): J {
ctx.sendValue(deconstructionPattern, v => v.id, ValueType.UUID);
ctx.sendNode(deconstructionPattern, v => v.prefix, Visitor.sendSpace);
ctx.sendNode(deconstructionPattern, v => v.markers, ctx.sendMarkers);
ctx.sendNode(deconstructionPattern, v => v.deconstructor, ctx.sendTree);
ctx.sendNode(deconstructionPattern, v => v.padding.nested, Visitor.sendContainer(ValueType.Tree));
ctx.sendTypedValue(deconstructionPattern, v => v.type, ValueType.Object);
return deconstructionPattern;
}

public visitIntersectionType(intersectionType: IntersectionType, ctx: SenderContext): J {
ctx.sendValue(intersectionType, v => v.id, ValueType.UUID);
ctx.sendNode(intersectionType, v => v.prefix, Visitor.sendSpace);
Expand Down
2 changes: 2 additions & 0 deletions openrewrite/src/java/tree/support_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ export namespace Space {
WILDCARD_PREFIX,
YIELD_PREFIX,
ERRONEOUS_PREFIX,
DECONSTRUCTION_PATTERN_PREFIX,
}
}

Expand Down Expand Up @@ -798,6 +799,7 @@ export namespace JContainer {
TRY_RESOURCES,
TYPE_BOUNDS,
TYPE_PARAMETERS,
DECONSTRUCTION_PATTERN_NESTED,
}

export namespace Location {
Expand Down
90 changes: 90 additions & 0 deletions openrewrite/src/java/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,96 @@ export class InstanceOf extends JMixin(Object) implements Expression, TypedTree

}

@LstType("org.openrewrite.java.tree.J$DeconstructionPattern")
export class DeconstructionPattern extends JMixin(Object) implements TypedTree {
public constructor(id: UUID, prefix: Space, markers: Markers, deconstructor: Expression, nested: JContainer<J>, _type: JavaType) {
super();
this._id = id;
this._prefix = prefix;
this._markers = markers;
this._deconstructor = deconstructor;
this._nested = nested;
this._type = _type;
}

private readonly _id: UUID;

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

public withId(id: UUID): DeconstructionPattern {
return id === this._id ? this : new DeconstructionPattern(id, this._prefix, this._markers, this._deconstructor, this._nested, this._type);
}

private readonly _prefix: Space;

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

public withPrefix(prefix: Space): DeconstructionPattern {
return prefix === this._prefix ? this : new DeconstructionPattern(this._id, prefix, this._markers, this._deconstructor, this._nested, this._type);
}

private readonly _markers: Markers;

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

public withMarkers(markers: Markers): DeconstructionPattern {
return markers === this._markers ? this : new DeconstructionPattern(this._id, this._prefix, markers, this._deconstructor, this._nested, this._type);
}

private readonly _deconstructor: Expression;

public get deconstructor(): Expression {
return this._deconstructor;
}

public withDeconstructor(deconstructor: Expression): DeconstructionPattern {
return deconstructor === this._deconstructor ? this : new DeconstructionPattern(this._id, this._prefix, this._markers, deconstructor, this._nested, this._type);
}

private readonly _nested: JContainer<J>;

public get nested(): J[] {
return this._nested.elements;
}

public withNested(nested: J[]): DeconstructionPattern {
return this.padding.withNested(JContainer.withElements(this._nested, nested));
}

private readonly _type: JavaType;

public get type(): JavaType {
return this._type;
}

public withType(_type: JavaType): DeconstructionPattern {
return _type === this._type ? this : new DeconstructionPattern(this._id, this._prefix, this._markers, this._deconstructor, this._nested, _type);
}

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

get padding() {
const t = this;
return new class {
public get nested(): JContainer<J> {
return t._nested;
}
public withNested(nested: JContainer<J>): DeconstructionPattern {
return t._nested === nested ? t : new DeconstructionPattern(t._id, t._prefix, t._markers, t._deconstructor, nested, t._type);
}
}
}

}

@LstType("org.openrewrite.java.tree.J$IntersectionType")
export class IntersectionType extends JMixin(Object) implements TypeTree, Expression {
public constructor(id: UUID, prefix: Space, markers: Markers, bounds: JContainer<TypeTree>) {
Expand Down
10 changes: 9 additions & 1 deletion 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, DeconstructionPattern, 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";

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

public visitDeconstructionPattern(deconstructionPattern: DeconstructionPattern, p: P): J | null {
deconstructionPattern = deconstructionPattern.withPrefix(this.visitSpace(deconstructionPattern.prefix, Space.Location.DECONSTRUCTION_PATTERN_PREFIX, p)!);
deconstructionPattern = deconstructionPattern.withMarkers(this.visitMarkers(deconstructionPattern.markers, p));
deconstructionPattern = deconstructionPattern.withDeconstructor(this.visitAndCast(deconstructionPattern.deconstructor, p)!);
deconstructionPattern = deconstructionPattern.padding.withNested(this.visitContainer(deconstructionPattern.padding.nested, JContainer.Location.DECONSTRUCTION_PATTERN_NESTED, p)!);
return deconstructionPattern;
}

public visitIntersectionType(intersectionType: IntersectionType, p: P): J | null {
intersectionType = intersectionType.withPrefix(this.visitSpace(intersectionType.prefix, Space.Location.INTERSECTION_TYPE_PREFIX, p)!);
let tempExpression = this.visitExpression(intersectionType, p) as Expression;
Expand Down
21 changes: 21 additions & 0 deletions openrewrite/src/javascript/remote/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,16 @@ class Visitor extends JavaScriptVisitor<ReceiverContext> {
return instanceOf;
}

public visitDeconstructionPattern(deconstructionPattern: Java.DeconstructionPattern, ctx: ReceiverContext): J {
deconstructionPattern = deconstructionPattern.withId(ctx.receiveValue(deconstructionPattern.id, ValueType.UUID)!);
deconstructionPattern = deconstructionPattern.withPrefix(ctx.receiveNode(deconstructionPattern.prefix, receiveSpace)!);
deconstructionPattern = deconstructionPattern.withMarkers(ctx.receiveNode(deconstructionPattern.markers, ctx.receiveMarkers)!);
deconstructionPattern = deconstructionPattern.withDeconstructor(ctx.receiveNode(deconstructionPattern.deconstructor, ctx.receiveTree)!);
deconstructionPattern = deconstructionPattern.padding.withNested(ctx.receiveNode(deconstructionPattern.padding.nested, receiveContainer)!);
deconstructionPattern = deconstructionPattern.withType(ctx.receiveValue(deconstructionPattern.type, ValueType.Object)!);
return deconstructionPattern;
}

public visitIntersectionType(intersectionType: Java.IntersectionType, ctx: ReceiverContext): J {
intersectionType = intersectionType.withId(ctx.receiveValue(intersectionType.id, ValueType.UUID)!);
intersectionType = intersectionType.withPrefix(ctx.receiveNode(intersectionType.prefix, receiveSpace)!);
Expand Down Expand Up @@ -2493,6 +2503,17 @@ class Factory implements ReceiverFactory {
);
}

if (type === "org.openrewrite.java.tree.J$DeconstructionPattern") {
return new Java.DeconstructionPattern(
ctx.receiveValue(null, ValueType.UUID)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)!,
ctx.receiveNode<Expression>(null, ctx.receiveTree)!,
ctx.receiveNode<JContainer<J>>(null, receiveContainer)!,
ctx.receiveValue(null, ValueType.Object)!
);
}

if (type === "org.openrewrite.java.tree.J$IntersectionType") {
return new Java.IntersectionType(
ctx.receiveValue(null, ValueType.UUID)!,
Expand Down
10 changes: 10 additions & 0 deletions openrewrite/src/javascript/remote/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,16 @@ class Visitor extends JavaScriptVisitor<SenderContext> {
return instanceOf;
}

public visitDeconstructionPattern(deconstructionPattern: Java.DeconstructionPattern, ctx: SenderContext): J {
ctx.sendValue(deconstructionPattern, v => v.id, ValueType.UUID);
ctx.sendNode(deconstructionPattern, v => v.prefix, Visitor.sendSpace);
ctx.sendNode(deconstructionPattern, v => v.markers, ctx.sendMarkers);
ctx.sendNode(deconstructionPattern, v => v.deconstructor, ctx.sendTree);
ctx.sendNode(deconstructionPattern, v => v.padding.nested, Visitor.sendContainer(ValueType.Tree));
ctx.sendTypedValue(deconstructionPattern, v => v.type, ValueType.Object);
return deconstructionPattern;
}

public visitIntersectionType(intersectionType: Java.IntersectionType, ctx: SenderContext): J {
ctx.sendValue(intersectionType, v => v.id, ValueType.UUID);
ctx.sendNode(intersectionType, v => v.prefix, Visitor.sendSpace);
Expand Down
Loading

0 comments on commit a6b05f1

Please # to comment.