Skip to content

Prevent UseTextBlocks from dropping comments in concatenations#985

Merged
timtebeek merged 1 commit intomainfrom
timtebeek/keep-concat-comments
Feb 16, 2026
Merged

Prevent UseTextBlocks from dropping comments in concatenations#985
timtebeek merged 1 commit intomainfrom
timtebeek/keep-concat-comments

Conversation

@timtebeek
Copy link
Member

Summary

Skip text block conversion when comments exist in string concatenations. The recipe was silently dropping line and block comments because text block literals have nowhere to preserve inline comments from the middle of the original binary tree.

Changes

  • Add containsComments(Expression) method to detect comments in binary expressions
  • Add guard in visitBinary to skip transformation when comments are found
  • Add test coverage for line and block comment preservation

Test Plan

  • Run existing tests: all 28 UseTextBlocksTest pass
  • Added 2 new no-change tests verifying concatenations with comments are not transformed

Skip text block conversion if any comments exist in the binary expression tree, since text blocks (single J.Literal nodes) have nowhere to preserve inline comments from the middle of concatenations.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Feb 16, 2026
@timtebeek timtebeek merged commit e91f59e into main Feb 16, 2026
1 check passed
@timtebeek timtebeek deleted the timtebeek/keep-concat-comments branch February 16, 2026 21:48
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Feb 16, 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

Comments