Skip to content
Merged
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
29 changes: 10 additions & 19 deletions rewrite-core/src/main/java/org/openrewrite/rpc/RpcRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import lombok.RequiredArgsConstructor;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.config.OptionDescriptor;
import org.openrewrite.config.RecipeDescriptor;
import org.openrewrite.config.RecipeExample;
import org.openrewrite.rpc.request.PrepareRecipeResponse;
Expand All @@ -30,8 +29,8 @@
import java.util.Set;

import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;


@RequiredArgsConstructor
Expand Down Expand Up @@ -65,8 +64,8 @@ public class RpcRecipe extends ScanningRecipe<Integer> {

/**
* The prepared child recipe responses returned by the server as part of the whole-tree
* prepare response. When non-null and non-empty, {@link #getRecipeList()} builds children
* locally from these nodes instead of making individual PrepareRecipe RPC calls.
* prepare response. {@link #getRecipeList()} builds the children locally from these. Every
* RPC server populates this (an empty list for a leaf), so it is effectively required.
*/
private final @Nullable List<PrepareRecipeResponse> childResponses;

Expand Down Expand Up @@ -134,21 +133,13 @@ public TreeVisitor<?, ExecutionContext> getVisitor(Integer acc) {
@Override
public synchronized List<Recipe> getRecipeList() {
if (recipeList == null) {
if (childResponses != null) {
// Whole-tree: children were prepared in the parent's response; build locally, no RPC.
recipeList = childResponses.stream()
.map(rpc::recipeFromPrepareResponse)
.collect(toList());
} else {
// Fallback by-name path: peers whose servers don't yet return a prepared child tree
// (Python/JS/Go until updated). The C# server always takes the branch above.
// TODO(remove-fallback): delete this branch once every RPC server populates `recipeList`.
recipeList = descriptor.getRecipeList().stream()
.map(r -> rpc.prepareRecipe(r.getName(), r.getOptions().stream()
.filter(opt -> opt.getValue() != null)
.collect(toMap(OptionDescriptor::getName, OptionDescriptor::getValue))))
.collect(toList());
}
// Every RPC server returns the whole prepared tree, so build the children locally from
// the child responses — no individual PrepareRecipe RPC per child.
recipeList = requireNonNull(childResponses,
"RPC server returned a recipe without a prepared child tree (recipeList)")
.stream()
.map(rpc::recipeFromPrepareResponse)
.collect(toList());
}
return recipeList;
}
Expand Down
Loading