Try-with-resources does not indent wrapped method calls properly for the first resource.

Answered

Code autoformat has issues indenting the first resources in a try-with-resources block when the creating of that resources is long enough to cause line wrapping to occur. The 2nd resource and onward indent the wrapped code properly.

Expected:  

try(AutoCloseable someAutoCloseable = AutoClosableFactory.factory()
.generateAutoCloseable("AReallyLongNameThatCausesALineWrap");
AutoCloseable someOtherAutoCloseable = AutoClosableFactory.factory()
.generateAutoCloseable("AnotherLongNameThatCausesALineWrap"))
{
System.out.println("AutoCloseables created.");
}

Formatted:

try(AutoCloseable someAutoCloseable = AutoClosableFactory.factory()
.generateAutoCloseable("AReallyLongNameThatCausesALineWrap");
AutoCloseable someOtherAutoCloseable = AutoClosableFactory.factory()
.generateAutoCloseable("AnotherLongNameThatCausesALineWrap"))
{
System.out.println("AutoCloseables created.");
}

This appears even stranger if there are spaces used around the "try ( " as the wrapped line starts before the definition of the resource.

1
1 comment

Created bug request for that: 

https://youtrack.jetbrains.com/issue/IDEA-264140

Feel free to watch it in order to be notified once it has updates. See this article if you are not familiar with YouTrack.

0

Please sign in to leave a comment.