Skip to content

Correct string block indent#6694

Merged
timtebeek merged 10 commits intoopenrewrite:mainfrom
BoykoAlex:string-block-indent
Feb 9, 2026
Merged

Correct string block indent#6694
timtebeek merged 10 commits intoopenrewrite:mainfrom
BoykoAlex:string-block-indent

Conversation

@BoykoAlex
Copy link
Copy Markdown
Contributor

String blocks autoformat is based on spaces rather than whatever is in the style.

@BoykoAlex BoykoAlex marked this pull request as ready for review February 9, 2026 19:11
@BoykoAlex
Copy link
Copy Markdown
Contributor Author

@timtebeek this is to support autoformat for text blocks where idents are not spaces. Looks like the code currently is biased towards spaces based indents. The indent for multiline string is parent AST node indent + 2 indents - this seesm to be the same to JDT and IntelliJ.

@timtebeek timtebeek self-requested a review February 9, 2026 19:54
Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the immediate suggested fix! @Jenson3210 is our expert here, but this looks alright to me already. I'll merge before tomorrow's release if I don't hear from him before then. If he sees this and agrees he can immediately merge.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 9, 2026
@timtebeek timtebeek self-requested a review February 9, 2026 19:56
@BoykoAlex
Copy link
Copy Markdown
Contributor Author

@timtebeek i see there is a test failure for aligned text blocks. Trying to figure it out... I don't know why we're making a check !literal.getPrefix().getLastWhitespace().contains("\n") - I'd align the string even if """ on the new line... Something blows up with the cursor is the source position service if I remove this check. If you @Jenson3210 and @timtebeek have ideas/opinions/directions for me, please don't be shy :-)

@BoykoAlex
Copy link
Copy Markdown
Contributor Author

Okay, I think i came up with a good fix for the alignment things. Should be good to go now

@Jenson3210
Copy link
Copy Markdown
Contributor

@BoykoAlex, thanks for identifying this gap!

I made some suggestions which I think will make the code behave even more accurate. Let me know if you have thoughts here.

BoykoAlex and others added 5 commits February 9, 2026 13:52
…IndentsVisitor.java

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
…IndentsVisitor.java

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
…IndentsVisitor.java

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
…bsAndIndentsTest.java

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
…bsAndIndentsTest.java

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
@BoykoAlex
Copy link
Copy Markdown
Contributor Author

@Jenson3210 thank you for the review :-)

Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 left a comment

Choose a reason for hiding this comment

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

Great! Thanks a lot for the issue/troubleshooting/fix here!

@timtebeek timtebeek merged commit 9bf6d01 into openrewrite:main Feb 9, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 9, 2026
@timtebeek
Copy link
Copy Markdown
Member

Quick note that we're seeing two failures downstream that I think are related: https://ge.openrewrite.org/s/gtr3ruly7ncng

SourceSpecTextBlockNewLineTest > newlineBetweenMultipleTextBlocks() FAILED
    org.opentest4j.AssertionFailedError: [Unexpected result in "MyRecipeTest.java":
    diff --git a/MyRecipeTest.java b/MyRecipeTest.java
    index 54a59ee..bdfba39 100644
    --- a/MyRecipeTest.java
    +++ b/MyRecipeTest.java
    @@ -15,14 +15,14 @@ 
                  }
                  """,
                   """
    -                class Test {
    -                
    -                    
    -                    void test() {
    -                        System.out.println("Hello, world!");
    -                    }
    -                }
    -                """
    +                      class Test {
    +                      
    +                          
    +                          void test() {
    +                              System.out.println("Hello, world!");
    +                          }
    +                      }
    +                      """
              )
           );
         }
    ] 

Could either of you have a look? I want to prevent us having to field related questions after today's release.

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.

3 participants