diff --git a/rewrite-core/src/main/java/org/openrewrite/rpc/RpcRecipe.java b/rewrite-core/src/main/java/org/openrewrite/rpc/RpcRecipe.java index df0cd7b172..760cf5af02 100644 --- a/rewrite-core/src/main/java/org/openrewrite/rpc/RpcRecipe.java +++ b/rewrite-core/src/main/java/org/openrewrite/rpc/RpcRecipe.java @@ -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; @@ -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 @@ -65,8 +64,8 @@ public class RpcRecipe extends ScanningRecipe { /** * 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 childResponses; @@ -134,21 +133,13 @@ public TreeVisitor getVisitor(Integer acc) { @Override public synchronized List 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; }