@@ -28,7 +28,8 @@ import com.intellij.psi.util.PsiTreeUtil
2828import com.intellij.psi.util.elementType
2929import org.domaframework.doma.intellij.common.util.InjectionSqlUtil.isInjectedSqlFile
3030import org.domaframework.doma.intellij.common.util.PluginLoggerUtil
31- import org.domaframework.doma.intellij.common.util.StringUtil
31+ import org.domaframework.doma.intellij.common.util.StringUtil.LINE_SEPARATE
32+ import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
3233import org.domaframework.doma.intellij.formatter.util.CreateQueryType
3334import org.domaframework.doma.intellij.formatter.util.SqlKeywordUtil
3435import org.domaframework.doma.intellij.formatter.visitor.SqlFormatVisitor
@@ -139,38 +140,37 @@ class SqlFormatPreProcessor : PreFormatProcessor {
139140 document : Document ,
140141 element : PsiWhiteSpace ,
141142 ) {
142- val singleSpace = " "
143143 val range = element.textRange
144144 val originalText = document.getText(range)
145145 val nextElement = element.nextSibling
146146 val nextElementText = nextElement?.let { document.getText(it.textRange) } ? : " "
147147
148148 var newText = " "
149149 if (! targetElementTypes.contains(nextElement?.elementType)) {
150- newText = originalText.replace(originalText, singleSpace )
150+ newText = originalText.replace(originalText, SINGLE_SPACE )
151151 } else {
152152 newText =
153153 if (element.prevSibling == null ) {
154154 " "
155155 } else {
156156 when (nextElement.elementType) {
157157 SqlTypes .LINE_COMMENT -> {
158- if (nextElementText.startsWith(StringUtil . LINE_SEPARATE )) {
159- originalText.replace(originalText, singleSpace )
160- } else if (originalText.contains(StringUtil . LINE_SEPARATE )) {
161- originalText.replace(Regex (" \\ s*\\ n\\ s*" ), StringUtil . LINE_SEPARATE )
158+ if (nextElementText.startsWith(LINE_SEPARATE )) {
159+ originalText.replace(originalText, SINGLE_SPACE )
160+ } else if (originalText.contains(LINE_SEPARATE )) {
161+ originalText.replace(Regex (" \\ s*\\ n\\ s*" ), LINE_SEPARATE )
162162 } else {
163- originalText.replace(originalText, singleSpace )
163+ originalText.replace(originalText, SINGLE_SPACE )
164164 }
165165 }
166166
167167 else -> {
168- if (nextElementText.contains(StringUtil . LINE_SEPARATE ) == true ) {
169- originalText.replace(originalText, singleSpace )
170- } else if (originalText.contains(StringUtil . LINE_SEPARATE )) {
171- originalText.replace(Regex (" \\ s*\\ n\\ s*" ), StringUtil . LINE_SEPARATE )
168+ if (nextElementText.contains(LINE_SEPARATE ) == true ) {
169+ originalText.replace(originalText, SINGLE_SPACE )
170+ } else if (originalText.contains(LINE_SEPARATE )) {
171+ originalText.replace(Regex (" \\ s*\\ n\\ s*" ), LINE_SEPARATE )
172172 } else {
173- originalText.replace(originalText, StringUtil . LINE_SEPARATE )
173+ originalText.replace(originalText, LINE_SEPARATE )
174174 }
175175 }
176176 }
@@ -256,10 +256,10 @@ class SqlFormatPreProcessor : PreFormatProcessor {
256256 prevElement : PsiElement ? ,
257257 text : String ,
258258 ): String =
259- if (prevElement?.text?.contains(StringUtil . LINE_SEPARATE ) == false &&
259+ if (prevElement?.text?.contains(LINE_SEPARATE ) == false &&
260260 PsiTreeUtil .prevLeaf(prevElement) != null
261261 ) {
262- " ${ StringUtil . LINE_SEPARATE } $text "
262+ " $LINE_SEPARATE$text "
263263 } else {
264264 text
265265 }
0 commit comments