Recently we've migrated our project from java 11 to java 21, and we are now able to use java-15 string blocks. But in our project we also use eclipse formatter plugin:
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
</plugin>
and what i found, the plugin formats string blocks with tab identation (the same way as it formats strings before java15, with concatenation). For example:
public class SomeClass {
String hello = """
Whatever
text
that
shouldn't
be idented
from
the
left""";
}
after plugin invocation it looks like:
public class SomeClass {
String hello = """
Whatever
text
that
shouldn't
be idented
from
the
left""";
}
While for concatenation such formatting was absolutely okay, since no additional tab symbols were compiled into class file, while for string-block it differs.
Does anybody knows what config should be configured on formatter-maven-plugin to avoid this behaviour? Is it possible at all?
According to the Java Language specification 3.10.6 Text Blocks both variants result in the same string (i.e. the amount of indentation on the first line is removed from all lines in the text block.)
See the example text blocks shown there:
class Test {
public static void main(String[] args) {
// The six characters w i n t e r
String season = """
winter""";
// The seven characters w i n t e r LF
String period = """
winter
""";
// The ten characters H i , SP " B o b " LF
String greeting = """
Hi, "Bob"
""";
// remaining code left out
}
}