Skip to content

Extend UseVarForPrimitive to support String literals#1024

Merged
timtebeek merged 4 commits intomainfrom
tim/var-for-strings
Mar 23, 2026
Merged

Extend UseVarForPrimitive to support String literals#1024
timtebeek merged 4 commits intomainfrom
tim/var-for-strings

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

Extends the UseVarForPrimitive recipe to also replace explicit String type declarations with var when the initializer is a string literal (e.g. String s = "hello"var s = "hello"). String literals are unambiguous, so no type hint is needed. Non-literal String initializers (concatenation, method calls) are intentionally excluded.

Test plan

  • Tests pass: forString, forStringWithFinal (applicable cases)
  • Tests pass: forStringConcatenation, forStringMethodCall (not applicable)
  • All existing primitive tests still pass

@timtebeek
Copy link
Copy Markdown
Member Author

/cc @motlin

@timtebeek timtebeek added enhancement New feature or request recipe Recipe requested labels Mar 23, 2026
@timtebeek timtebeek merged commit 69aeb40 into main Mar 23, 2026
1 check passed
@timtebeek timtebeek deleted the tim/var-for-strings branch March 23, 2026 19:03
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request recipe Recipe requested

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant