Skip to content

Fix annotation and record declaration header not applying continuation indent to wrapped annotations#22

Merged
electrum merged 3 commits into
airlift:mainfrom
ksobolew:kudi/annotations-on-types
Jun 10, 2026
Merged

Fix annotation and record declaration header not applying continuation indent to wrapped annotations#22
electrum merged 3 commits into
airlift:mainfrom
ksobolew:kudi/annotations-on-types

Conversation

@ksobolew

@ksobolew ksobolew commented May 29, 2026

Copy link
Copy Markdown
Contributor

For annotation declarations, this brings it in line with other declarations. For record declarations this is slightly different, as all other declarations call buildTypeHeader, but records have their own buildRecordHeader. Both of these methods needs to do the same thing relative to annotations on the type.

The third commit fixes a related issue, but not exactly the same. It's included in the same PR as the others mostly because the test cases would otherwise get into conflict with test cases from other commits.

Adds more test coverage: classes, enums.

ksobolew added 2 commits May 29, 2026 10:12
This brings it in line with other declarations.

Adds more test coverage: classes, enums.
This is not as simple as with annotation declarations. All other
declarations call `buildTypeHeader`, but records have their own
`buildRecordHeader`. Both of these methods needs to do the same thing
relative to annotations on the type.
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf90e8ac-44e7-46d2-af7d-8388aa08a16d

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5259c and 544db17.

📒 Files selected for processing (2)
  • airstyle-core/src/main/java/io/airlift/airstyle/engine/java/JavaDeclarationBuilder.java
  • airstyle-core/src/test/java/io/airlift/airstyle/TestAnnotationUseStyleFormatting.java

📝 Walkthrough

Walkthrough

JavaDeclarationBuilder refactors header formatting across annotation types and record declarations to align with shared type-header decomposition logic. AnnotationTypeDeclaration headers now use buildTypeHeader() instead of flat token ranges. RecordDeclaration header prefixes conditionally decompose wrapped annotations via emitPrefixWithAnnotations() when present, otherwise use flat token ranges. Record component tails are built with an explicit buildTokensRange(..., false) parameter. Five new tests verify annotation continuation indentation is preserved when wrapped @McpTool and @McpApp annotations precede different declaration types.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…params

The tail composite (type + name after an annotation) shared its
`WhiteSpace` object with the first leaf. Then `applySpacing` zeroed
`indentSpaces` on that shared object, and passing true as
`usesFirstChildIndentAsBlockIndent` caused the walk to short-circuit
there, reading the zeroed value (column 0) instead of the correct column
from RecordComponent (column 8). Passing false as
`canUseFirstChildIndent` forces the walk to continue up to
RecordComponent which still holds the correct `indentSpaces`.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns Java declaration header formatting so wrapped annotation argument lists keep continuation indent consistently for annotation type declarations and record declarations (which use a separate buildRecordHeader path), matching behavior already used for other declarations.

Changes:

  • Route AnnotationTypeDeclaration header building through buildTypeHeader(...) so wrapped annotations are decomposed and their wrapped values retain continuation indent.
  • Update buildRecordHeader(...) to decompose wrapped annotations in the prefix (up to () via emitPrefixWithAnnotations(...), ensuring wrapped annotation values keep continuation indent.
  • Add regression tests covering class, annotation, record, record component, and enum declarations with wrapped annotations / wrapped params.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
airstyle-core/src/main/java/io/airlift/airstyle/engine/java/JavaDeclarationBuilder.java Fixes header construction for annotation type + record declarations to decompose wrapped annotations and preserve continuation indent behavior.
airstyle-core/src/test/java/io/airlift/airstyle/TestAnnotationUseStyleFormatting.java Adds regression tests for wrapped-annotation continuation indent across more declaration kinds (class/enum/record/etc.).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@electrum electrum merged commit 903af3a into airlift:main Jun 10, 2026
1 check passed
@ksobolew ksobolew deleted the kudi/annotations-on-types branch June 15, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants