Skip to content

Commit c16a416

Browse files
committed
Formatter processor support for platform version 233
1 parent 74feb93 commit c16a416

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlBlockBuilder.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.domaframework.doma.intellij.formatter
217

318
import org.domaframework.doma.intellij.formatter.block.SqlBlock

src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatPreProcessor.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ import com.intellij.psi.PsiWhiteSpace
2525
import com.intellij.psi.TokenType
2626
import com.intellij.psi.impl.source.codeStyle.PreFormatProcessor
2727
import com.intellij.psi.util.PsiTreeUtil
28+
import com.intellij.psi.util.elementType
2829
import com.intellij.psi.util.prevLeafs
2930
import org.domaframework.doma.intellij.psi.SqlBlockComment
3031
import org.domaframework.doma.intellij.psi.SqlTypes
3132
import 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

3635
class 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

Comments
 (0)