Skip to content

Inline JavaParser and JavaTemplate fields in recipes#951

Merged
timtebeek merged 2 commits intomainfrom
tim/inline-parser-fields
Mar 31, 2026
Merged

Inline JavaParser and JavaTemplate fields in recipes#951
timtebeek merged 2 commits intomainfrom
tim/inline-parser-fields

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • Removes the legacy pattern of storing JavaParser.Builder and JavaTemplate instances as cached fields on visitors, inlining them at each usage site instead.
  • 8 cleanup assert recipes had identical lazy-init JavaParser.Builder fields that are now inlined.
  • 3 JUnit 5 migration recipes (RunnerToExtension, JUnitParamsRunnerToParameterized, ParameterizedRunnerToParameterized) had cached JavaTemplate fields built in constructors or lazy-init methods, now replaced with inline construction.
  • Net removal of ~104 lines of boilerplate. No behavioral changes — all existing tests pass.

Remove the legacy pattern of storing JavaParser.Builder and JavaTemplate
instances as cached fields on visitors, inlining them at each usage site
instead.
Comment on lines 214 to 216
private static JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
return JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5", "hamcrest-3", "junit-jupiter-params-5");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also inline this method.

Comment on lines 186 to 188
private static JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
return JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5", "junit-jupiter-params-5");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also inline this method.

Address PR feedback to fully inline the javaParser(ctx) helper methods
in JUnitParamsRunnerToParameterized and ParameterizedRunnerToParameterized.
@timtebeek timtebeek merged commit df743de into main Mar 31, 2026
1 check passed
@timtebeek timtebeek deleted the tim/inline-parser-fields branch March 31, 2026 16:09
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant