Skip to content

Add explicit casts for visitor visit() return type#1049

Merged
timtebeek merged 4 commits intomainfrom
fix/visitor-return-type-cast
Apr 6, 2026
Merged

Add explicit casts for visitor visit() return type#1049
timtebeek merged 4 commits intomainfrom
fix/visitor-return-type-cast

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • The visit() method on OpenRewrite visitors now returns J rather than the specific subtype
  • Add explicit casts at 4 affected call sites (J.Switch, J.ClassDeclaration)
  • Fix missing @Nullable import in MoveAnnotationToArrayType (add org.jspecify.annotations.Nullable, adjust type-use annotation placement)
  • Fixes scheduled CI compilation failure (6 errors)

Changed files

  • RefineSwitchCases.java — cast to J.Switch
  • IfElseIfConstructToSwitch.java — cast to J.Switch
  • LombokValueToRecord.java — cast to J.ClassDeclaration
  • RemoveEmbeddableId.java — cast to J.ClassDeclaration
  • MoveAnnotationToArrayType.java — add @Nullable import, fix annotation placement

Test plan

  • ./gradlew compileJava passes
  • ./gradlew test (running)

The `visit()` method on OpenRewrite visitors now returns `J` rather
than the specific subtype. Add explicit casts at affected call sites:
- `RefineSwitchCases` — cast to `J.Switch`
- `IfElseIfConstructToSwitch` — cast to `J.Switch`
- `LombokValueToRecord` — cast to `J.ClassDeclaration`
- `RemoveEmbeddableId` — cast to `J.ClassDeclaration`

Also fix `MoveAnnotationToArrayType` missing `@Nullable` import by
adding `org.jspecify.annotations.Nullable` and adjusting type-use
annotation placement.
…uctors test

The core ChangeMethodTargetToStatic recipe now matches constructor calls
with the wildcard pattern, incorrectly converting `new Modifier()` to
`Modifier.Modifier()`. Pass instances as parameters instead to avoid
triggering the constructor matching.
@timtebeek timtebeek merged commit 9e118a4 into main Apr 6, 2026
1 check passed
@timtebeek timtebeek deleted the fix/visitor-return-type-cast branch April 6, 2026 21:11
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant