== Why is this an issue?
In Java 15 Text Blocks are official and can be used just like an ordinary String. However, when they are used to represent a big chunk of text, they should not be used directly in complex expressions, as it decreases the readability. In this case, it is better to extract the text block into a variable or a field.
This rule reports an issue when a text block longer than a number of lines given as a parameter is directly used within a lambda expression.
=== Noncompliant code example
[source,java]
----
listOfString.stream()
.map(str -> !"""
4.0.0
com.mycompany.app
my-app
1
com.mycompany.app
my-module
1
""".equals(str));
----
=== Compliant solution
[source,java]
----
String myTextBlock = """
4.0.0
com.mycompany.app
my-app
1
com.mycompany.app
my-module
1
""";
listOfString.stream()
.map(str -> !myTextBlock.equals(str));
----
== Resources
* https://openjdk.java.net/jeps/378[JEP 378: Text Blocks]
* https://openjdk.org/projects/amber/guides/text-blocks-guide[Programmer's Guide To Text Blocks], by Jim Laskey and Stuart Marks
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this text block out of the lambda body and refactor it to a local variable or a static final field.
=== Parameters
.MaximumNumberOfLines
****
----
5
----
The maximum number of lines in a text block that can be nested into a complex expression.
****
=== Highlighting
Text block
endif::env-github,rspecator-view[]