Skip to content

Commit 7822680

Browse files
committed
Refactor SQL formatting to use SINGLE_SPACE constant for consistency
1 parent 262ef2f commit 7822680

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiPatternUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.intellij.psi.util.elementType
2727
import com.intellij.psi.util.prevLeafs
2828
import com.intellij.util.ProcessingContext
2929
import org.domaframework.doma.intellij.common.sql.directive.DirectiveCompletion
30+
import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
3031
import org.domaframework.doma.intellij.psi.SqlCustomElCommentExpr
3132
import org.domaframework.doma.intellij.psi.SqlElClass
3233
import org.domaframework.doma.intellij.psi.SqlElIdExpr
@@ -135,7 +136,7 @@ object PsiPatternUtil {
135136
element: PsiElement,
136137
symbol: String,
137138
): String {
138-
val text = originalFile.containingFile?.text ?: " "
139+
val text = originalFile.containingFile?.text ?: SINGLE_SPACE
139140
val offset = element.textOffset
140141
val builder = StringBuilder()
141142
for (i in offset - 1 downTo 0) {

src/main/kotlin/org/domaframework/doma/intellij/common/sql/CleanElementText.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.domaframework.doma.intellij.common.sql
1717

1818
import org.domaframework.doma.intellij.common.util.StringUtil
19+
import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
1920

2021
/**
2122
* Exclude extra strings and block symbols added by IntelliJ operations a
@@ -29,5 +30,5 @@ fun cleanString(str: String): String {
2930
// TODO: Temporary support when using operators.
3031
// Remove the "== a" element because it is attached to the end.
3132
// Make it possible to obtain the equilateral elements of the left side individually.
32-
.substringBefore(" ")
33+
.substringBefore(SINGLE_SPACE)
3334
}

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/StaticDirectiveHandler.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.domaframework.doma.intellij.common.psi.PsiPatternUtil
2525
import org.domaframework.doma.intellij.common.sql.directive.collector.FunctionCallCollector
2626
import org.domaframework.doma.intellij.common.sql.directive.collector.StaticClassPackageCollector
2727
import org.domaframework.doma.intellij.common.sql.directive.collector.StaticPropertyCollector
28+
import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
2829
import org.domaframework.doma.intellij.psi.SqlElClass
2930
import org.domaframework.doma.intellij.psi.SqlElStaticFieldAccessExpr
3031
import org.domaframework.doma.intellij.psi.SqlTypes
@@ -117,7 +118,7 @@ class StaticDirectiveHandler(
117118
val prev = PsiTreeUtil.prevLeaf(element, true)
118119
val staticFieldAccess =
119120
PsiTreeUtil.getParentOfType(prev, SqlElStaticFieldAccessExpr::class.java)
120-
val sqlElClassWords = PsiPatternUtil.getBindSearchWord(element.containingFile, element, " ")
121+
val sqlElClassWords = PsiPatternUtil.getBindSearchWord(element.containingFile, element, SINGLE_SPACE)
121122
return (
122123
staticFieldAccess != null && staticFieldAccess.elIdExprList.isEmpty()
123124
) ||
@@ -141,7 +142,7 @@ class StaticDirectiveHandler(
141142
.getChildOfType(prev, SqlElClass::class.java)
142143
?: PsiTreeUtil.getChildOfType(PsiTreeUtil.prevLeaf(element)?.parent, SqlElClass::class.java)
143144

144-
val sqlElClassWords = PsiPatternUtil.getBindSearchWord(element.containingFile, element, " ")
145+
val sqlElClassWords = PsiPatternUtil.getBindSearchWord(element.containingFile, element, SINGLE_SPACE)
145146
val sqlElClassName = PsiTreeUtil.getChildrenOfTypeAsList(clazzRef, PsiElement::class.java).joinToString("") { it.text }
146147
val fqdn = if (sqlElClassName.isNotEmpty()) sqlElClassName else sqlElClassWords.replace("@", "")
147148

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.common.util
1717

1818
object StringUtil {
1919
const val LINE_SEPARATE: String = "\n"
20+
const val SINGLE_SPACE: String = " "
2021

2122
fun getSqlElClassText(text: String): String =
2223
text

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project
2020
import com.intellij.psi.PsiClassType
2121
import com.intellij.psi.PsiType
2222
import org.domaframework.doma.intellij.common.psi.PsiTypeChecker
23+
import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
2324
import org.domaframework.doma.intellij.extension.getJavaClazz
2425
import org.domaframework.doma.intellij.extension.psi.getClassAnnotation
2526
import org.domaframework.doma.intellij.extension.psi.isDomain
@@ -79,13 +80,13 @@ object TypeUtil {
7980
* Checks if the given type is a valid Map<String, Object>.
8081
*/
8182
fun isValidMapType(type: PsiType?): Boolean {
82-
val canonical = type?.canonicalText?.replace(" ", "") ?: return false
83+
val canonical = type?.canonicalText?.replace(SINGLE_SPACE, "") ?: return false
8384
val expected =
8485
DomaClassName.MAP
8586
.getGenericParamCanonicalText(
8687
DomaClassName.STRING.className,
8788
DomaClassName.OBJECT.className,
88-
).replace(" ", "")
89+
).replace(SINGLE_SPACE, "")
8990
return canonical == expected
9091
}
9192

0 commit comments

Comments
 (0)