Skip to content

Skip main migration when referenced as static API#1084

Merged
timtebeek merged 1 commit intomainfrom
tim/issue-1083
May 5, 2026
Merged

Skip main migration when referenced as static API#1084
timtebeek merged 1 commit intomainfrom
tim/issue-1083

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 5, 2026

Summary

  • Convert MigrateMainMethodToInstanceMain to a ScanningRecipe so it scans every compilation unit for references to a class's main(String[]) method, not only the file in which it's declared.

  • Detect Main.main(...) method invocations in addition to Main::main member references, and skip migrating classes whose static main is referenced anywhere.

  • Add tests for static main invocations from another file and from the same file.

  • Fixes MigrateMainMethodToInstanceMain changes main method referenced as static API #1083

Test plan

  • ./gradlew :test --tests "org.openrewrite.java.migrate.lang.MigrateMainMethodToInstanceMainTest"

Convert `MigrateMainMethodToInstanceMain` to a `ScanningRecipe` so it
detects `Main.main(...)` invocations and `Main::main` references across
all compilation units, not just the same file. Migrating the declaring
class to `void main()` would otherwise leave call sites broken.

Fixes #1083
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 5, 2026
@timtebeek timtebeek merged commit dcaa8ca into main May 5, 2026
1 check passed
@timtebeek timtebeek deleted the tim/issue-1083 branch May 5, 2026 09:42
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 5, 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.

MigrateMainMethodToInstanceMain changes main method referenced as static API

1 participant