File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
java/src/main/kotlin/io/spine/validation/java Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -143,9 +143,20 @@ internal class MessageValidationCode(
143
143
implement(reference)
144
144
}
145
145
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
+ */
146
159
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.
149
160
val formattedConstraints = constraints.joinToString(separator = " " ).trim()
150
161
val psiMethod = elementFactory.createMethodFromText(
151
162
"""
You can’t perform that action at this time.
0 commit comments