Skip to content

Commit c0c9c7a

Browse files
author
yevhenii-nadtochii
committed
Document formatting peculiarities in declareValidateMethod()
1 parent a20722f commit c0c9c7a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

java/src/main/kotlin/io/spine/validation/java/MessageValidationCode.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,20 @@ internal class MessageValidationCode(
143143
implement(reference)
144144
}
145145

146+
/**
147+
* Declares `validate()` method in this [MessagePsiClass].
148+
*
149+
* This method does the following to address the formatting issues:
150+
*
151+
* 1. [constraints] are joined to [String] using [joinToString] instead of `joinByLine()`
152+
* because the contained code blocks already have new lines when converted to string.
153+
* 2. For the same reason, we trim the result because a trailing empty line is not needed.
154+
* 3. When creating PSI method from the text, we have to use [trimMargin] and '|' symbols
155+
* (the default separator) to specify minimal common intend explicitly. The code blocks
156+
* from the constraints add some whitespace characters. They break [trimIndent] and corrupt
157+
* the resulting formatting, often leading to non-compilable Java code.
158+
*/
146159
private fun MessagePsiClass.declareValidateMethod() {
147-
// `CodeBlock` is printed with a new line in the end, so no need to call `joinByLine()`.
148-
// And we have to trim because we don't need a trailing empty line.
149160
val formattedConstraints = constraints.joinToString(separator = "").trim()
150161
val psiMethod = elementFactory.createMethodFromText(
151162
"""

0 commit comments

Comments
 (0)