Skip to content

Add record component wrapping and method call argument alignment#6601

Merged
jkschneider merged 2 commits intomainfrom
jkschneider/intellij-wrapping-styles
Jan 26, 2026
Merged

Add record component wrapping and method call argument alignment#6601
jkschneider merged 2 commits intomainfrom
jkschneider/intellij-wrapping-styles

Conversation

@jkschneider
Copy link
Copy Markdown
Member

@jkschneider jkschneider commented Jan 26, 2026

Summary

  • Adds wrapping support for Java record components (ChopIfTooLong, WrapAlways, openNewLine, closeNewLine, alignWhenMultiline)
  • Adds alignment support for method call arguments (alignWhenMultiline)
  • Existing support for chained method calls and method declaration parameters was already complete

Problem

  • Scentbird requested support for several IntelliJ code style formatting options (issues #1555-Inconsistent use of Charset when getting bytes from String-like content #1558):
  • Chained method calls: ChopIfLong, align when multiline, builder methods
  • Record components: ChopIfLong, alignWhenMultiline, newLineAfter(, )onNewLine
  • Method declaration parameters: ChopIfLong, alignWhenMultiline, newLineAfter(, )onNewLine
  • Method call arguments: ChopIfLong, alignWhenMultiple, newLineAfter(, )onNewLine

Solution

  1. Record Components (new): Added WrappingAndBracesStyle.RecordComponents class and WrapRecordComponents visitor to handle wrapping for Java record component lists, supporting ChopIfTooLong, WrapAlways, openNewLine, closeNewLine, and alignWhenMultiline options.

  2. Method Call Argument Alignment (fixed): Added handling for METHOD_INVOCATION_ARGUMENT and NEW_CLASS_ARGUMENTS in TabsAndIndentsVisitor.alignWhenMultiple() to enable alignment when multiline for method call arguments.

  3. Chained Method Calls & Method Declaration Parameters: These were already implemented. The style options for ChopIfTooLong, alignWhenMultiline, openNewLine, and closeNewLine already existed in the codebase.

Test plan

  • Existing tests pass

  • New tests added for record component wrapping (WrapRecordComponentsTest)

  • All WrapMethod*Test tests pass with updated constructors

  • Fixes moderneinc/customer-requests#1555

  • Fixes moderneinc/customer-requests#1556

  • Fixes moderneinc/customer-requests#1557

  • Fixes moderneinc/customer-requests#1558

This adds support for IntelliJ-style formatting options requested by Scentbird:

1. Record Components (issue #1556):
   - Added WrappingAndBracesStyle.RecordComponents with wrap, alignWhenMultiline,
     openNewLine, and closeNewLine options
   - Added WrapRecordComponents visitor to apply wrapping rules
   - Integrated into WrappingAndBracesVisitor for class declarations
   - Added comprehensive tests

2. Method Call Arguments Alignment (issue #1558):
   - Added METHOD_INVOCATION_ARGUMENT and NEW_CLASS_ARGUMENTS handling
     in TabsAndIndentsVisitor.alignWhenMultiple()
   - This enables alignWhenMultiline for method call arguments

Note: Issues #1555 (Chained Method Calls) and #1557 (Method Declaration
Parameters) were already implemented - the style options for ChopIfTooLong,
alignWhenMultiline, openNewLine, and closeNewLine already existed.

Fixes moderneinc/customer-requests#1555
Fixes moderneinc/customer-requests#1556
Fixes moderneinc/customer-requests#1557
Fixes moderneinc/customer-requests#1558
Add missing RecordComponents parameter to constructor calls
in rewrite-java-test module.
@jkschneider jkschneider merged commit 082dc82 into main Jan 26, 2026
2 checks passed
@jkschneider jkschneider deleted the jkschneider/intellij-wrapping-styles branch January 26, 2026 19:38
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jan 26, 2026
jkschneider added a commit that referenced this pull request Jan 26, 2026
* Add record component wrapping and method call argument alignment

This adds support for IntelliJ-style formatting options requested:

1. Record Components (issue #1556):
   - Added WrappingAndBracesStyle.RecordComponents with wrap, alignWhenMultiline,
     openNewLine, and closeNewLine options
   - Added WrapRecordComponents visitor to apply wrapping rules
   - Integrated into WrappingAndBracesVisitor for class declarations
   - Added comprehensive tests

2. Method Call Arguments Alignment (issue #1558):
   - Added METHOD_INVOCATION_ARGUMENT and NEW_CLASS_ARGUMENTS handling
     in TabsAndIndentsVisitor.alignWhenMultiple()
   - This enables alignWhenMultiline for method call arguments

Note: Issues #1555 (Chained Method Calls) and #1557 (Method Declaration
Parameters) were already implemented - the style options for ChopIfTooLong,
alignWhenMultiline, openNewLine, and closeNewLine already existed.

Fixes moderneinc/customer-requests#1555
Fixes moderneinc/customer-requests#1556
Fixes moderneinc/customer-requests#1557
Fixes moderneinc/customer-requests#1558

* Fix WrappingAndBracesTest constructor calls

Add missing RecordComponents parameter to constructor calls
in rewrite-java-test module.
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