Skip to content

Commit

Permalink
Regenerate Java model and senders and receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 23, 2025
1 parent 44c8ee1 commit 046e856
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,17 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, ReceiverContext ctx
return instanceOf;
}

@Override
public J.DeconstructionPattern visitDeconstructionPattern(J.DeconstructionPattern deconstructionPattern, ReceiverContext ctx) {
deconstructionPattern = deconstructionPattern.withId(ctx.receiveNonNullValue(deconstructionPattern.getId(), UUID.class));
deconstructionPattern = deconstructionPattern.withPrefix(ctx.receiveNonNullNode(deconstructionPattern.getPrefix(), PythonReceiver::receiveSpace));
deconstructionPattern = deconstructionPattern.withMarkers(ctx.receiveNonNullNode(deconstructionPattern.getMarkers(), ctx::receiveMarkers));
deconstructionPattern = deconstructionPattern.withDeconstructor(ctx.receiveNonNullNode(deconstructionPattern.getDeconstructor(), ctx::receiveTree));
deconstructionPattern = deconstructionPattern.getPadding().withNested(ctx.receiveNonNullNode(deconstructionPattern.getPadding().getNested(), PythonReceiver::receiveContainer));
deconstructionPattern = deconstructionPattern.withType(ctx.receiveValue(deconstructionPattern.getType(), JavaType.class));
return deconstructionPattern;
}

@Override
public J.IntersectionType visitIntersectionType(J.IntersectionType intersectionType, ReceiverContext ctx) {
intersectionType = intersectionType.withId(ctx.receiveNonNullValue(intersectionType.getId(), UUID.class));
Expand Down Expand Up @@ -1240,6 +1251,7 @@ protected Function<ReceiverContext, Object> computeValue(Class type) {
if (type == J.If.Else.class) return Factory::createJIfElse;
if (type == J.Import.class) return Factory::createJImport;
if (type == J.InstanceOf.class) return Factory::createJInstanceOf;
if (type == J.DeconstructionPattern.class) return Factory::createJDeconstructionPattern;
if (type == J.IntersectionType.class) return Factory::createJIntersectionType;
if (type == J.Label.class) return Factory::createJLabel;
if (type == J.Lambda.class) return Factory::createJLambda;
Expand Down Expand Up @@ -1984,6 +1996,17 @@ private static J.InstanceOf createJInstanceOf(ReceiverContext ctx) {
);
}

private static J.DeconstructionPattern createJDeconstructionPattern(ReceiverContext ctx) {
return new J.DeconstructionPattern(
ctx.receiveNonNullValue(null, UUID.class),
ctx.receiveNonNullNode(null, PythonReceiver::receiveSpace),
ctx.receiveNonNullNode(null, ctx::receiveMarkers),
ctx.receiveNonNullNode(null, ctx::receiveTree),
ctx.receiveNonNullNode(null, PythonReceiver::receiveContainer),
ctx.receiveValue(null, JavaType.class)
);
}

private static J.IntersectionType createJIntersectionType(ReceiverContext ctx) {
return new J.IntersectionType(
ctx.receiveNonNullValue(null, UUID.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,17 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, SenderContext ctx)
return instanceOf;
}

@Override
public J.DeconstructionPattern visitDeconstructionPattern(J.DeconstructionPattern deconstructionPattern, SenderContext ctx) {
ctx.sendValue(deconstructionPattern, J.DeconstructionPattern::getId);
ctx.sendNode(deconstructionPattern, J.DeconstructionPattern::getPrefix, PythonSender::sendSpace);
ctx.sendNode(deconstructionPattern, J.DeconstructionPattern::getMarkers, ctx::sendMarkers);
ctx.sendNode(deconstructionPattern, J.DeconstructionPattern::getDeconstructor, ctx::sendTree);
ctx.sendNode(deconstructionPattern, e -> e.getPadding().getNested(), PythonSender::sendContainer);
ctx.sendTypedValue(deconstructionPattern, J.DeconstructionPattern::getType);
return deconstructionPattern;
}

@Override
public J.IntersectionType visitIntersectionType(J.IntersectionType intersectionType, SenderContext ctx) {
ctx.sendValue(intersectionType, J.IntersectionType::getId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, P p) {
return instanceOf;
}

@Override
public J.DeconstructionPattern visitDeconstructionPattern(J.DeconstructionPattern deconstructionPattern, P p) {
visitAndValidateNonNull(deconstructionPattern.getDeconstructor(), Expression.class, p);
visitAndValidate(deconstructionPattern.getNested(), J.class, p);
return deconstructionPattern;
}

@Override
public J.IntersectionType visitIntersectionType(J.IntersectionType intersectionType, P p) {
visitAndValidate(intersectionType.getBounds(), TypeTree.class, p);
Expand Down
19 changes: 19 additions & 0 deletions rewrite/rewrite/java/remote/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ def visit_instance_of(self, instance_of: InstanceOf, ctx: ReceiverContext) -> J:
instance_of = instance_of.with_type(ctx.receive_value(instance_of.type, JavaType))
return instance_of

def visit_deconstruction_pattern(self, deconstruction_pattern: DeconstructionPattern, ctx: ReceiverContext) -> J:
deconstruction_pattern = deconstruction_pattern.with_id(ctx.receive_value(deconstruction_pattern.id, UUID))
deconstruction_pattern = deconstruction_pattern.with_prefix(ctx.receive_node(deconstruction_pattern.prefix, JavaReceiver.receive_space))
deconstruction_pattern = deconstruction_pattern.with_markers(ctx.receive_node(deconstruction_pattern.markers, ctx.receive_markers))
deconstruction_pattern = deconstruction_pattern.with_deconstructor(ctx.receive_node(deconstruction_pattern.deconstructor, ctx.receive_tree))
deconstruction_pattern = deconstruction_pattern.padding.with_nested(ctx.receive_node(deconstruction_pattern.padding.nested, JavaReceiver.receive_container))
deconstruction_pattern = deconstruction_pattern.with_type(ctx.receive_value(deconstruction_pattern.type, JavaType))
return deconstruction_pattern

def visit_intersection_type(self, intersection_type: IntersectionType, ctx: ReceiverContext) -> J:
intersection_type = intersection_type.with_id(ctx.receive_value(intersection_type.id, UUID))
intersection_type = intersection_type.with_prefix(ctx.receive_node(intersection_type.prefix, JavaReceiver.receive_space))
Expand Down Expand Up @@ -958,6 +967,16 @@ def create(self, type: str, ctx: ReceiverContext) -> Tree:
ctx.receive_value(None, JavaType)
)

if type in ["rewrite.java.tree.DeconstructionPattern", "org.openrewrite.java.tree.J$DeconstructionPattern"]:
return DeconstructionPattern(
ctx.receive_value(None, UUID),
ctx.receive_node(None, JavaReceiver.receive_space),
ctx.receive_node(None, ctx.receive_markers),
ctx.receive_node(None, ctx.receive_tree),
ctx.receive_node(None, JavaReceiver.receive_container),
ctx.receive_value(None, JavaType)
)

if type in ["rewrite.java.tree.IntersectionType", "org.openrewrite.java.tree.J$IntersectionType"]:
return IntersectionType(
ctx.receive_value(None, UUID),
Expand Down
9 changes: 9 additions & 0 deletions rewrite/rewrite/java/remote/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ def visit_instance_of(self, instance_of: InstanceOf, ctx: SenderContext) -> J:
ctx.send_typed_value(instance_of, attrgetter('_type'))
return instance_of

def visit_deconstruction_pattern(self, deconstruction_pattern: DeconstructionPattern, ctx: SenderContext) -> J:
ctx.send_value(deconstruction_pattern, attrgetter('_id'))
ctx.send_node(deconstruction_pattern, attrgetter('_prefix'), JavaSender.send_space)
ctx.send_node(deconstruction_pattern, attrgetter('_markers'), ctx.send_markers)
ctx.send_node(deconstruction_pattern, attrgetter('_deconstructor'), ctx.send_tree)
ctx.send_node(deconstruction_pattern, attrgetter('_nested'), JavaSender.send_container)
ctx.send_typed_value(deconstruction_pattern, attrgetter('_type'))
return deconstruction_pattern

def visit_intersection_type(self, intersection_type: IntersectionType, ctx: SenderContext) -> J:
ctx.send_value(intersection_type, attrgetter('_id'))
ctx.send_node(intersection_type, attrgetter('_prefix'), JavaSender.send_space)
Expand Down
90 changes: 89 additions & 1 deletion rewrite/rewrite/java/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,8 @@ def padding(self) -> PaddingHelper:
return p

def printer(self, cursor: Cursor) -> TreeVisitor[Tree, PrintOutputCapture[P]]:
return PrinterFactory.current().create_printer(cursor)
factory = PrinterFactory.current()
return factory.create_printer(cursor) if factory else JavaPrinter[PrintOutputCapture[P]]()

def accept_java(self, v: JavaVisitor[P], p: P) -> J:
return v.visit_compilation_unit(self, p)
Expand Down Expand Up @@ -2487,6 +2488,93 @@ def padding(self) -> PaddingHelper:
def accept_java(self, v: JavaVisitor[P], p: P) -> J:
return v.visit_instance_of(self, p)

# noinspection PyShadowingBuiltins,PyShadowingNames,DuplicatedCode
@dataclass(frozen=True, eq=False)
class DeconstructionPattern(TypedTree):
_id: UUID

@property
def id(self) -> UUID:
return self._id

def with_id(self, id: UUID) -> DeconstructionPattern:
return self if id is self._id else replace(self, _id=id)

_prefix: Space

@property
def prefix(self) -> Space:
return self._prefix

def with_prefix(self, prefix: Space) -> DeconstructionPattern:
return self if prefix is self._prefix else replace(self, _prefix=prefix)

_markers: Markers

@property
def markers(self) -> Markers:
return self._markers

def with_markers(self, markers: Markers) -> DeconstructionPattern:
return self if markers is self._markers else replace(self, _markers=markers)

_deconstructor: Expression

@property
def deconstructor(self) -> Expression:
return self._deconstructor

def with_deconstructor(self, deconstructor: Expression) -> DeconstructionPattern:
return self if deconstructor is self._deconstructor else replace(self, _deconstructor=deconstructor)

_nested: JContainer[J]

@property
def nested(self) -> List[J]:
return self._nested.elements

def with_nested(self, nested: List[J]) -> DeconstructionPattern:
return self.padding.with_nested(JContainer.with_elements(self._nested, nested))

_type: JavaType

@property
def type(self) -> JavaType:
return self._type

def with_type(self, type: JavaType) -> DeconstructionPattern:
return self if type is self._type else replace(self, _type=type)

@dataclass
class PaddingHelper:
_t: DeconstructionPattern

@property
def nested(self) -> JContainer[J]:
return self._t._nested

def with_nested(self, nested: JContainer[J]) -> DeconstructionPattern:
return self._t if self._t._nested is nested else replace(self._t, _nested=nested)

_padding: weakref.ReferenceType[PaddingHelper] = None

@property
def padding(self) -> PaddingHelper:
p: DeconstructionPattern.PaddingHelper
if self._padding is None:
p = DeconstructionPattern.PaddingHelper(self)
object.__setattr__(self, '_padding', weakref.ref(p))
else:
p = self._padding()
# noinspection PyProtectedMember
if p is None or p._t != self:
p = DeconstructionPattern.PaddingHelper(self)
object.__setattr__(self, '_padding', weakref.ref(p))
return p

def accept_java(self, v: JavaVisitor[P], p: P) -> J:
return v.visit_deconstruction_pattern(self, p)

# noinspection PyShadowingBuiltins,PyShadowingNames,DuplicatedCode
@dataclass(frozen=True, eq=False)
class IntersectionType(TypeTree, Expression):
Expand Down
7 changes: 7 additions & 0 deletions rewrite/rewrite/java/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ def visit_instance_of(self, instance_of: InstanceOf, p: P) -> J:
instance_of = instance_of.with_pattern(self.visit_and_cast(instance_of.pattern, J, p))
return instance_of

def visit_deconstruction_pattern(self, deconstruction_pattern: DeconstructionPattern, p: P) -> J:
deconstruction_pattern = deconstruction_pattern.with_prefix(self.visit_space(deconstruction_pattern.prefix, Space.Location.DECONSTRUCTION_PATTERN_PREFIX, p))
deconstruction_pattern = deconstruction_pattern.with_markers(self.visit_markers(deconstruction_pattern.markers, p))
deconstruction_pattern = deconstruction_pattern.with_deconstructor(self.visit_and_cast(deconstruction_pattern.deconstructor, Expression, p))
deconstruction_pattern = deconstruction_pattern.padding.with_nested(self.visit_container(deconstruction_pattern.padding.nested, JContainer.Location.DECONSTRUCTION_PATTERN_NESTED, p))
return deconstruction_pattern

def visit_intersection_type(self, intersection_type: IntersectionType, p: P) -> J:
intersection_type = intersection_type.with_prefix(self.visit_space(intersection_type.prefix, Space.Location.INTERSECTION_TYPE_PREFIX, p))
temp_expression = cast(Expression, self.visit_expression(intersection_type, p))
Expand Down
19 changes: 19 additions & 0 deletions rewrite/rewrite/python/remote/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ def visit_instance_of(self, instance_of: InstanceOf, ctx: ReceiverContext) -> J:
instance_of = instance_of.with_type(ctx.receive_value(instance_of.type, JavaType))
return instance_of

def visit_deconstruction_pattern(self, deconstruction_pattern: DeconstructionPattern, ctx: ReceiverContext) -> J:
deconstruction_pattern = deconstruction_pattern.with_id(ctx.receive_value(deconstruction_pattern.id, UUID))
deconstruction_pattern = deconstruction_pattern.with_prefix(ctx.receive_node(deconstruction_pattern.prefix, PythonReceiver.receive_space))
deconstruction_pattern = deconstruction_pattern.with_markers(ctx.receive_node(deconstruction_pattern.markers, ctx.receive_markers))
deconstruction_pattern = deconstruction_pattern.with_deconstructor(ctx.receive_node(deconstruction_pattern.deconstructor, ctx.receive_tree))
deconstruction_pattern = deconstruction_pattern.padding.with_nested(ctx.receive_node(deconstruction_pattern.padding.nested, PythonReceiver.receive_container))
deconstruction_pattern = deconstruction_pattern.with_type(ctx.receive_value(deconstruction_pattern.type, JavaType))
return deconstruction_pattern

def visit_intersection_type(self, intersection_type: IntersectionType, ctx: ReceiverContext) -> J:
intersection_type = intersection_type.with_id(ctx.receive_value(intersection_type.id, UUID))
intersection_type = intersection_type.with_prefix(ctx.receive_node(intersection_type.prefix, PythonReceiver.receive_space))
Expand Down Expand Up @@ -1578,6 +1587,16 @@ def create(self, type: str, ctx: ReceiverContext) -> Tree:
ctx.receive_value(None, JavaType)
)

if type in ["rewrite.python.tree.DeconstructionPattern", "org.openrewrite.java.tree.J$DeconstructionPattern"]:
return DeconstructionPattern(
ctx.receive_value(None, UUID),
ctx.receive_node(None, PythonReceiver.receive_space),
ctx.receive_node(None, ctx.receive_markers),
ctx.receive_node(None, ctx.receive_tree),
ctx.receive_node(None, PythonReceiver.receive_container),
ctx.receive_value(None, JavaType)
)

if type in ["rewrite.python.tree.IntersectionType", "org.openrewrite.java.tree.J$IntersectionType"]:
return IntersectionType(
ctx.receive_value(None, UUID),
Expand Down
9 changes: 9 additions & 0 deletions rewrite/rewrite/python/remote/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ def visit_instance_of(self, instance_of: InstanceOf, ctx: SenderContext) -> J:
ctx.send_typed_value(instance_of, attrgetter('_type'))
return instance_of

def visit_deconstruction_pattern(self, deconstruction_pattern: DeconstructionPattern, ctx: SenderContext) -> J:
ctx.send_value(deconstruction_pattern, attrgetter('_id'))
ctx.send_node(deconstruction_pattern, attrgetter('_prefix'), PythonSender.send_space)
ctx.send_node(deconstruction_pattern, attrgetter('_markers'), ctx.send_markers)
ctx.send_node(deconstruction_pattern, attrgetter('_deconstructor'), ctx.send_tree)
ctx.send_node(deconstruction_pattern, attrgetter('_nested'), PythonSender.send_container)
ctx.send_typed_value(deconstruction_pattern, attrgetter('_type'))
return deconstruction_pattern

def visit_intersection_type(self, intersection_type: IntersectionType, ctx: SenderContext) -> J:
ctx.send_value(intersection_type, attrgetter('_id'))
ctx.send_node(intersection_type, attrgetter('_prefix'), PythonSender.send_space)
Expand Down

0 comments on commit 046e856

Please sign in to comment.