Skip to content

Add @RequiredArgsConstructor and @AllArgsConstructor recipes#996

Merged
jkschneider merged 2 commits intomainfrom
jkschneider/lombok-recipes
Mar 1, 2026
Merged

Add @RequiredArgsConstructor and @AllArgsConstructor recipes#996
jkschneider merged 2 commits intomainfrom
jkschneider/lombok-recipes

Conversation

@jkschneider
Copy link
Member

Summary

  • Add UseRequiredArgsConstructor recipe that replaces explicit constructors assigning only final fields with @RequiredArgsConstructor, handling access levels and onConstructor_ for annotations like @Autowired
  • Add UseAllArgsConstructor recipe that replaces constructors assigning all non-static fields with @AllArgsConstructor
  • Add shared utility methods to LombokUtils for field collection and constructor body validation
  • Register both recipes in LombokBestPractices composite recipe

Test plan

  • 16 tests for UseRequiredArgsConstructor (single/multiple final fields, access levels, static/initialized field exclusion, negative cases)
  • 9 tests for UseAllArgsConstructor (non-static fields, access levels, skip when @RequiredArgsConstructor present, negative cases)
  • All existing Lombok tests pass (18 test suites, 0 failures)

Replace explicit constructors that only assign final fields with
@requiredargsconstructor, and constructors that assign all non-static
fields with @AllArgsConstructor. Both handle access levels and
onConstructor_ for transferred annotations like @Autowired.
@jkschneider jkschneider merged commit c0f7b7d into main Mar 1, 2026
1 check passed
@jkschneider jkschneider deleted the jkschneider/lombok-recipes branch March 1, 2026 10:54
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 1, 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