@@ -25,13 +25,12 @@ import com.intellij.psi.PsiWhiteSpace
2525import com.intellij.psi.TokenType
2626import com.intellij.psi.impl.source.codeStyle.PreFormatProcessor
2727import com.intellij.psi.util.PsiTreeUtil
28+ import com.intellij.psi.util.elementType
2829import com.intellij.psi.util.prevLeafs
2930import org.domaframework.doma.intellij.psi.SqlBlockComment
3031import org.domaframework.doma.intellij.psi.SqlTypes
3132import org.domaframework.doma.intellij.setting.SqlLanguage
32- import org.jetbrains.kotlin.idea.base.codeInsight.handlers.fixers.end
33- import org.jetbrains.kotlin.idea.base.codeInsight.handlers.fixers.start
34- import org.toml.lang.psi.ext.elementType
33+ import org.jetbrains.kotlin.psi.psiUtil.startOffset
3534
3635class SqlFormatPreProcessor : PreFormatProcessor {
3736 enum class CreateQueryType {
@@ -74,6 +73,8 @@ class SqlFormatPreProcessor : PreFormatProcessor {
7473
7574 visitor.replaces.asReversed().forEach {
7675 val isCreateTableGroup = isCreateTableGroup(keywordList, index)
76+ val textRangeStart = it.startOffset
77+ val textRangeEnd = textRangeStart + it.text.length
7778 if (it.elementType != TokenType .WHITE_SPACE ) {
7879 index--
7980 var newKeyword = getUpperText(it)
@@ -150,8 +151,8 @@ class SqlFormatPreProcessor : PreFormatProcessor {
150151 newKeyword = getNewLineString(it)
151152 }
152153 }
153- document.deleteString(it.textRange.start, it.textRange.end )
154- document.insertString(it.textRange.start , newKeyword)
154+ document.deleteString(textRangeStart, textRangeEnd )
155+ document.insertString(textRangeStart , newKeyword)
155156 } else {
156157 if (keywordIndex < replaceKeywordList.size) {
157158 val nextElement = replaceKeywordList[keywordIndex]
@@ -166,18 +167,17 @@ class SqlFormatPreProcessor : PreFormatProcessor {
166167 isNewLineOnlyCreateTable(nextElement) && isCreateTableGroup
167168 )
168169 ) {
169- val start = it.textRange.start
170- document.deleteString(start, it.textRange.end)
171- document.insertString(start, " " )
170+ document.deleteString(textRangeStart, textRangeEnd)
171+ document.insertString(textRangeStart, " " )
172172 } else {
173173 val currentIndent = it.text.substringAfter(" \n " , " " ).length
174- val start = it.textRange.end - currentIndent
175- document.deleteString(start, it.textRange.end )
174+ val start = textRangeEnd - currentIndent
175+ document.deleteString(start, textRangeEnd )
176176 }
177177 } else {
178178 val currentIndent = it.text.substringAfter(" \n " , " " ).length
179- val start = it.textRange.end - currentIndent
180- document.deleteString(start, it.textRange.end )
179+ val start = textRangeEnd - currentIndent
180+ document.deleteString(start, textRangeEnd )
181181 }
182182 }
183183 }
0 commit comments