rewrite-migrate-java icon indicating copy to clipboard operation
rewrite-migrate-java copied to clipboard

`UseTextBlocks` should not delete comments

Open aholland opened this issue 1 year ago • 2 comments

image

Hi - there are two problems with the way text blocks are being created, illustrated in this image.

  1. The comments in the original have been deleted. There is no good way to insert comments into a text block, but in such cases you could just leave the old syntax in place.
  2. When you're creating text block within an annotation like this, there is no need for the trailing \ . I admit this might be hard to detect and do correctly and reliably. Perhaps there could be an option though.

This bug report is really about 1.

I am using the Gradle plugin, version 6.6.4.

aholland avatar Jan 20 '24 09:01 aholland

Hi @aholland ; thanks for pointing that out! Yes indeed we should not convert to text blocks when there's comments; a case currently missed in UseTextBlocks https://github.com/openrewrite/rewrite-migrate-java/blob/d12d72bed27b6f183fbd7a37e6d6b3cead30411b/src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java#L46

If you'd want to help out retain comments the quickest way is likely to add a draft PR with a new test, based on this existing test, but with a comment thrown in somewhere in the middle. Ideally we convert none of it to text blocks. https://github.com/openrewrite/rewrite-migrate-java/blob/d12d72bed27b6f183fbd7a37e6d6b3cead30411b/src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java#L47-L70

timtebeek avatar Jan 20 '24 10:01 timtebeek

Your second comment of ending up with trailing slashes in SQL queries is maybe best handled with a run of our Format SQL recipe: https://docs.openrewrite.org/recipes/sql/formatsql. I think that ought to already introduce newlines, as seen in the tests.

timtebeek avatar Jan 20 '24 10:01 timtebeek

Hello @timtebeek i think that this issue was already fixed, i maked some test and we are not converting to text blocks when there's comments.

BramliAK avatar Sep 19 '24 09:09 BramliAK

Awesome, thanks a lot for confirming!

timtebeek avatar Sep 19 '24 09:09 timtebeek