Skip to content

Commit f6604a5

Browse files
committed
Removed indent adjustment process for multi-line comment blocks
1 parent 0d3cc58 commit f6604a5

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/visitor/DaoInjectionSqlVisitor.kt

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.intellij.psi.PsiLiteralExpression
2626
import com.intellij.psi.codeStyle.CodeStyleManager
2727
import org.domaframework.doma.intellij.common.util.InjectionSqlUtil
2828
import org.domaframework.doma.intellij.common.util.StringUtil
29-
import org.domaframework.doma.intellij.common.util.StringUtil.SINGLE_SPACE
3029
import kotlin.text.isBlank
3130

3231
/**
@@ -49,7 +48,6 @@ class DaoInjectionSqlVisitor(
4948
private const val WRITE_COMMAND_NAME = "Format Injected SQL"
5049
private const val BASE_INDENT = "\t\t\t"
5150
private val COMMENT_START_REGEX = Regex("^[ \t]*/[*][ \t]*\\*")
52-
private val COMMENT_END_REGEX = Regex("\\*/.*$")
5351
}
5452

5553
private val formattingTasks = mutableListOf<FormattingTask>()
@@ -71,23 +69,16 @@ class DaoInjectionSqlVisitor(
7169
var blockComment = false
7270
val removeIndentLines =
7371
lines.map { line ->
74-
if (blockComment) {
75-
if (COMMENT_END_REGEX.containsMatchIn(line)) {
76-
blockComment = false
72+
val baseLine =
73+
if (COMMENT_START_REGEX.containsMatchIn(line)) {
74+
blockComment = true
75+
// Exclude spaces between `/*` and the comment content element,
76+
// as IntelliJ IDEA's Java formatter may insert a space there during formatting.
77+
line.replace(COMMENT_START_REGEX, "/**")
78+
} else {
79+
line
7780
}
78-
"$SINGLE_SPACE${line.dropWhile { it.isWhitespace() }}"
79-
} else {
80-
val baseLine =
81-
if (COMMENT_START_REGEX.containsMatchIn(line)) {
82-
blockComment = true
83-
// Exclude spaces between `/*` and the comment content element,
84-
// as IntelliJ IDEA's Java formatter may insert a space there during formatting.
85-
line.replace(COMMENT_START_REGEX, "/**")
86-
} else {
87-
line
88-
}
89-
baseLine.dropWhile { it.isWhitespace() }
90-
}
81+
baseLine.dropWhile { it.isWhitespace() }
9182
}
9283

9384
return removeIndentLines.joinToString(StringUtil.LINE_SEPARATE)

0 commit comments

Comments
 (0)