Skip to content

Commit 8a6291a

Browse files
committed
Add Called SqlFormat Logging
1 parent a99ae2c commit 8a6291a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.intellij.psi.impl.source.codeStyle.PreFormatProcessor
2828
import com.intellij.psi.util.PsiTreeUtil
2929
import com.intellij.psi.util.elementType
3030
import com.intellij.psi.util.prevLeafs
31+
import org.domaframework.doma.intellij.common.PluginLoggerUtil
3132
import org.domaframework.doma.intellij.extension.expr.isConditionOrLoopDirective
3233
import org.domaframework.doma.intellij.psi.SqlBlockComment
3334
import org.domaframework.doma.intellij.psi.SqlCustomElCommentExpr
@@ -49,6 +50,8 @@ class SqlFormatPreProcessor : PreFormatProcessor {
4950
if (!isEnableFormat()) return rangeToReformat
5051
if (source.language != SqlLanguage.INSTANCE) return rangeToReformat
5152

53+
logging()
54+
5255
val visitor = SqlFormatVisitor()
5356
source.accept(visitor)
5457

@@ -92,7 +95,13 @@ class SqlFormatPreProcessor : PreFormatProcessor {
9295
}
9396

9497
SqlTypes.RIGHT_PAREN -> {
95-
newKeyword = getRightPatternNewText(it, newKeyword, replaceKeywordList[keywordIndex - 1], createQueryType)
98+
newKeyword =
99+
getRightPatternNewText(
100+
it,
101+
newKeyword,
102+
replaceKeywordList[keywordIndex - 1],
103+
createQueryType,
104+
)
96105
}
97106

98107
SqlTypes.WORD -> {
@@ -119,7 +128,8 @@ class SqlFormatPreProcessor : PreFormatProcessor {
119128
} else if (isCreateViewAs(replaceKeywordList[keywordIndex], createQueryType)) {
120129
removeSpacesAroundNewline(document, it.textRange)
121130
} else {
122-
val isNewLineGroup = SqlKeywordUtil.getIndentType(nextElement.text ?: "").isNewLineGroup()
131+
val isNewLineGroup =
132+
SqlKeywordUtil.getIndentType(nextElement.text ?: "").isNewLineGroup()
123133
val isSetLineKeyword =
124134
if (keywordIndex > 0) {
125135
SqlKeywordUtil.isSetLineKeyword(
@@ -318,6 +328,15 @@ class SqlFormatPreProcessor : PreFormatProcessor {
318328
private fun isSubGroupFirstElement(element: PsiElement): Boolean =
319329
getElementsBeforeKeyword(element.prevLeafs.toList()) { it.elementType == SqlTypes.LEFT_PAREN }
320330
.findLast { it !is PsiWhiteSpace } == null
331+
332+
private fun logging() {
333+
PluginLoggerUtil.countLogging(
334+
this::class.java.simpleName,
335+
"SqlFormat",
336+
"Format",
337+
System.nanoTime(),
338+
)
339+
}
321340
}
322341

323342
private class SqlFormatVisitor : PsiRecursiveElementVisitor() {
@@ -335,6 +354,7 @@ private class SqlFormatVisitor : PsiRecursiveElementVisitor() {
335354
SqlTypes.KEYWORD, SqlTypes.COMMA, SqlTypes.LEFT_PAREN, SqlTypes.RIGHT_PAREN, SqlTypes.WORD -> {
336355
replaces.add(element)
337356
}
357+
338358
SqlTypes.OTHER -> {
339359
if (element.text == "=") {
340360
val updateSetKeyword =
@@ -345,6 +365,7 @@ private class SqlFormatVisitor : PsiRecursiveElementVisitor() {
345365
}
346366
}
347367
}
368+
348369
SqlTypes.BLOCK_COMMENT ->
349370
if (
350371
element is SqlCustomElCommentExpr &&

0 commit comments

Comments
 (0)