Skip to content

Commit dac1f8f

Browse files
committed
Move the line break character handling to a utility class.
1 parent a461bcf commit dac1f8f

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/util/StringUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package org.domaframework.doma.intellij.common.util
1717

1818
object StringUtil {
19+
const val LINE_SEPARATE: String = "\n"
20+
1921
fun getSqlElClassText(text: String): String =
2022
text
2123
.substringAfter("@")

src/main/kotlin/org/domaframework/doma/intellij/document/ForItemElementDocumentationProvider.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.domaframework.doma.intellij.document
1818
import com.intellij.lang.documentation.AbstractDocumentationProvider
1919
import com.intellij.psi.PsiElement
2020
import com.intellij.psi.util.PsiTreeUtil
21+
import org.domaframework.doma.intellij.common.util.StringUtil
2122
import org.domaframework.doma.intellij.document.generator.DocumentDaoParameterGenerator
2223
import org.domaframework.doma.intellij.document.generator.DocumentStaticFieldGenerator
2324
import org.domaframework.doma.intellij.psi.SqlElIdExpr
@@ -62,7 +63,7 @@ class ForItemElementDocumentationProvider : AbstractDocumentationProvider() {
6263

6364
generator.generateDocument()
6465

65-
return result.joinToString("\n")
66+
return result.joinToString(StringUtil.LINE_SEPARATE)
6667
}
6768

6869
override fun generateHoverDoc(
@@ -77,6 +78,6 @@ class ForItemElementDocumentationProvider : AbstractDocumentationProvider() {
7778
val result: MutableList<String?> = LinkedList<String?>()
7879
val typeDocument = generateDoc(element, originalElement)
7980
result.add(typeDocument)
80-
return result.joinToString("\n")
81+
return result.joinToString(StringUtil.LINE_SEPARATE)
8182
}
8283
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/comment/SqlBlockCommentBlock.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.formatter.block.comment
1717

1818
import com.intellij.lang.ASTNode
1919
import com.intellij.psi.util.PsiTreeUtil
20+
import org.domaframework.doma.intellij.common.util.StringUtil
2021
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2122
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2223

@@ -27,5 +28,6 @@ open class SqlBlockCommentBlock(
2728
node,
2829
context,
2930
) {
30-
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean = PsiTreeUtil.prevLeaf(node.psi)?.text?.contains("\n") == true
31+
override fun isSaveSpace(lastGroup: SqlBlock?): Boolean =
32+
PsiTreeUtil.prevLeaf(node.psi)?.text?.contains(StringUtil.LINE_SEPARATE) == true
3133
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/comment/SqlDefaultCommentBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.domaframework.doma.intellij.formatter.block.comment
1818
import com.intellij.lang.ASTNode
1919
import com.intellij.psi.formatter.common.AbstractBlock
2020
import com.intellij.psi.util.PsiTreeUtil
21+
import org.domaframework.doma.intellij.common.util.StringUtil
2122
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2223
import org.domaframework.doma.intellij.formatter.util.IndentType
2324
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
@@ -60,5 +61,5 @@ abstract class SqlDefaultCommentBlock(
6061
}
6162
}
6263

63-
override fun isSaveSpace(lastGroup: SqlBlock?) = PsiTreeUtil.prevLeaf(node.psi)?.text?.contains("\n") == true
64+
override fun isSaveSpace(lastGroup: SqlBlock?) = PsiTreeUtil.prevLeaf(node.psi)?.text?.contains(StringUtil.LINE_SEPARATE) == true
6465
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/comment/SqlElConditionLoopCommentBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiWhiteSpace
2222
import com.intellij.psi.formatter.common.AbstractBlock
2323
import com.intellij.psi.util.PsiTreeUtil
2424
import com.intellij.psi.util.elementType
25+
import org.domaframework.doma.intellij.common.util.StringUtil
2526
import org.domaframework.doma.intellij.common.util.TypeUtil
2627
import org.domaframework.doma.intellij.extension.expr.isConditionOrLoopDirective
2728
import org.domaframework.doma.intellij.formatter.block.SqlBlock
@@ -108,7 +109,7 @@ class SqlElConditionLoopCommentBlock(
108109
// If the child is a condition loop directive, align its indentation with the parent directive
109110
child.indent.indentLen = indent.indentLen.plus(2)
110111
} else if (child is SqlLineCommentBlock) {
111-
if (PsiTreeUtil.prevLeaf(child.node.psi, false)?.text?.contains("\n") == true) {
112+
if (PsiTreeUtil.prevLeaf(child.node.psi, false)?.text?.contains(StringUtil.LINE_SEPARATE) == true) {
112113
child.indent.indentLen = indent.groupIndentLen
113114
} else {
114115
child.indent.indentLen = 1

src/main/kotlin/org/domaframework/doma/intellij/formatter/builder/SqlCustomSpacingBuilder.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.formatting.ASTBlock
1919
import com.intellij.formatting.Block
2020
import com.intellij.formatting.Spacing
2121
import com.intellij.psi.tree.IElementType
22+
import org.domaframework.doma.intellij.common.util.StringUtil
2223
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2324
import org.domaframework.doma.intellij.formatter.block.SqlRightPatternBlock
2425
import org.domaframework.doma.intellij.formatter.block.SqlWhitespaceBlock
@@ -79,8 +80,8 @@ class SqlCustomSpacingBuilder {
7980
null -> return nonSpacing
8081
is SqlWhitespaceBlock -> {
8182
val indentLen: Int = child2.indent.indentLen
82-
val afterNewLine = child1.getNodeText().substringAfterLast("\n", "")
83-
if (child1.getNodeText().contains("\n")) {
83+
val afterNewLine = child1.getNodeText().substringAfterLast(StringUtil.LINE_SEPARATE, "")
84+
if (child1.getNodeText().contains(StringUtil.LINE_SEPARATE)) {
8485
val currentIndent = afterNewLine.length
8586
val newIndent =
8687
if (currentIndent != indentLen) {

0 commit comments

Comments
 (0)