Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions openrewrite/src/java/remote/remote_extensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Comment, JContainer, JLeftPadded, JRightPadded, Space, TextComment} from "../tree";
import {DetailsReceiver, ReceiverContext, SenderContext, ValueType} from "@openrewrite/rewrite-remote";
import {Tree} from "../../core";
import {Markers, Tree} from "../../core";

export function sendSpace(space: Space, ctx: SenderContext) {
ctx.sendNodes(space, v => v.comments, sendComment, x => x);
Expand Down Expand Up @@ -68,13 +68,37 @@ export function sendRightPadded<T>(type: ValueType): (rightPadded: JRightPadded<
}

export function receiveContainer<T>(container: JContainer<T> | null, type: string | null, ctx: ReceiverContext): JContainer<T> {
// FIXME
throw new Error("Not implemented!");
if (container != null) {
container = container.withBefore(ctx.receiveNode(container.before, receiveSpace)!);
container = container.padding.withElements(
ctx.receiveNodes(container.padding.elements, receiveRightPaddedTree)!
);
container = container!.withMarkers(ctx.receiveNode(container.markers, ctx.receiveMarkers)!);
} else {
container = JContainer.build(
ctx.receiveNode<Space>(null, receiveSpace)!,
ctx.receiveNodes<JRightPadded<T>>(null, receiveRightPaddedTree)!,
ctx.receiveNode<Markers>(null, ctx.receiveMarkers)!
);
}
return container;
}

export function leftPaddedValueReceiver<T>(type: any): DetailsReceiver<JLeftPadded<T>> {
// FIXME
throw new Error("Not implemented!");
export function leftPaddedValueReceiver<T>(valueType: any): DetailsReceiver<JLeftPadded<T>> {
return (leftPadded, type, ctx): JLeftPadded<T> => {
if (leftPadded != null) {
leftPadded = leftPadded.withBefore(ctx.receiveNode(leftPadded.before, receiveSpace)!);
leftPadded = leftPadded.withElement(ctx.receiveValue(leftPadded.element, valueType)!);
leftPadded = leftPadded.withMarkers(ctx.receiveNode(leftPadded.markers, ctx.receiveMarkers)!);
} else {
leftPadded = new JLeftPadded<T>(
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveValue(null, valueType)!,
ctx.receiveNode(null, ctx.receiveMarkers)!
);
}
return leftPadded;
};
}

export function leftPaddedNodeReceiver<T>(type: any): DetailsReceiver<JLeftPadded<T>> {
Expand Down Expand Up @@ -130,7 +154,22 @@ export function rightPaddedValueReceiver<T>(valueType: any): DetailsReceiver<JRi
}

export function rightPaddedNodeReceiver<T>(type: any): DetailsReceiver<JRightPadded<T>> {
// FIXME
if (type === Space || type.name === 'Space') {
return function (rightPadded: JRightPadded<Space>, t: string | null, ctx: ReceiverContext): JRightPadded<Space> {
if (rightPadded !== null) {
rightPadded = rightPadded.withElement(ctx.receiveNode(rightPadded.element, receiveSpace)!);
rightPadded = rightPadded.withAfter(ctx.receiveNode<Space>(rightPadded.after, receiveSpace)!);
rightPadded = rightPadded.withMarkers(ctx.receiveNode(rightPadded.markers, ctx.receiveMarkers)!);
} else {
rightPadded = new JRightPadded<Space>(
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, receiveSpace)!,
ctx.receiveNode(null, ctx.receiveMarkers)
);
}
return rightPadded;
} as unknown as DetailsReceiver<JRightPadded<T>>;
}
throw new Error("Not implemented!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public Stream<SourceFile> parseInputs(Iterable<Input> inputs, @Nullable Path rel
Path path = input.getRelativePath(relativeTo);
parsingListener.startedParsing(input);

assert client != null;
assert remotingContext != null;
try (EncodingDetectingInputStream is = input.getSource(ctx)) {
SourceFile parsed = client.runUsingSocket((socket, messenger) -> requireNonNull(messenger.sendRequest(generator -> {
if (input.isSynthetic() || !Files.isRegularFile(input.getPath())) {
Expand Down Expand Up @@ -121,6 +123,9 @@ public Stream<SourceFile> parseInputs(Iterable<Input> inputs, @Nullable Path rel
} catch (Throwable t) {
ctx.getOnError().accept(t);
return ParseError.build(this, input, relativeTo, ctx, t);
} finally {
// NOTE: this is because we parse one source at the time
client.getContext().reset();
}
});
}
Expand Down