Skip to content

Conversation

@Laurens-W
Copy link
Contributor

@Laurens-W Laurens-W commented Nov 25, 2025

What's changed?

Introduce a recipe that can be used as precondition to prevent a recipe from running multiple times

What's your motivation?

Nested recipe cycles may make recipes significantly slower than they have to be

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@Laurens-W Laurens-W self-assigned this Nov 25, 2025
@Laurens-W Laurens-W added the enhancement New feature or request label Nov 25, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Nov 25, 2025

@Override
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
for (Recipe recipe : ctx.getCycleDetails().getMadeChangesInThisCycle()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way if the recipe doesn't make any changes it will still be re attempted.
The recipe stack is not public API of the RecipeRunCycle, if it were we could modify the stack to only contain a single instance of the recipe so it's ran exactly once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the more typical desired state with this recipe is run once regardless of whether it made changes.

It is the case of something like removing unnecessary parentheses which might make changes as the result of other recipes that makes this behavior not desirable in every case. But opting in to the singleton-like recipe is an explicit indication of intent.

@Laurens-W Laurens-W changed the title Precondition to prevent rerunning recipes Precondition recipe to make a recipe run only once Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants