File tree Expand file tree Collapse file tree 8 files changed +13
-12
lines changed
main/kotlin/org/domaframework/doma/intellij/formatter
test/kotlin/org/domaframework/doma/intellij/formatter Expand file tree Collapse file tree 8 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ open class SqlBlock(
8989 open var parentBlock: SqlBlock ? = null
9090 open val childBlocks = mutableListOf<SqlBlock >()
9191
92+ fun getChildBlocksDropLast (dropIndex : Int = 1): List <SqlBlock > = childBlocks.dropLast(dropIndex)
93+
9294 open val indent: ElementIndent =
9395 ElementIndent (
9496 IndentType .FILE ,
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ open class SqlLineCommentBlock(
4141 override fun createBlockIndentLen (): Int {
4242 parentBlock?.let { parent ->
4343 if (parent is SqlSubQueryGroupBlock ) {
44- if (parent.childBlocks.dropLast( 1 ).isEmpty()) {
44+ if (parent.getChildBlocksDropLast( ).isEmpty()) {
4545 return 0
4646 }
4747 if (parent.isFirstLineComment) {
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ open class SqlElBlockCommentBlock(
130130 override fun createBlockIndentLen (): Int {
131131 parentBlock?.let {
132132 if (it is SqlSubQueryGroupBlock ) {
133- if (it.childBlocks.dropLast( 1 ).isEmpty()) {
133+ if (it.getChildBlocksDropLast( ).isEmpty()) {
134134 return 0
135135 }
136136 if (it.isFirstLineComment) {
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ class SqlSelectQueryGroupBlock(
6565 override fun isSaveSpace (lastGroup : SqlBlock ? ): Boolean {
6666 lastGroup?.let { lastBlock ->
6767 if (lastGroup is SqlWithQuerySubGroupBlock ) return true
68- if (lastBlock is SqlSubGroupBlock ) return lastBlock.childBlocks.dropLast( 1 ).isNotEmpty()
68+ if (lastBlock is SqlSubGroupBlock ) return lastBlock.getChildBlocksDropLast( ).isNotEmpty()
6969 }
7070 return true
7171 }
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ class SqlWithCommonTableGroupBlock(
5656 private fun findWithQueryChildBlocks (): SqlBlock ? {
5757 parentBlock?.let { parent ->
5858 if (parent is SqlWithQueryGroupBlock ) {
59- return parent.childBlocks.dropLast( 1 ).find { it is SqlWithCommonTableGroupBlock }
59+ return parent.getChildBlocksDropLast( ).find { it is SqlWithCommonTableGroupBlock }
6060 }
6161 }
6262 return null
@@ -75,7 +75,7 @@ class SqlWithCommonTableGroupBlock(
7575
7676 override fun createGroupIndentLen (): Int {
7777 parentBlock?.let { parent ->
78- childBlocks.dropLast( 1 ).sumOf { it.getNodeText().length.plus(1 ) }
78+ getChildBlocksDropLast( ).sumOf { it.getNodeText().length.plus(1 ) }
7979 }
8080 return offset
8181 }
Original file line number Diff line number Diff line change 1616package org.domaframework.doma.intellij.formatter.block.group.subgroup
1717
1818import com.intellij.lang.ASTNode
19+ import org.domaframework.doma.intellij.formatter.block.comment.SqlBlockCommentBlock
20+ import org.domaframework.doma.intellij.formatter.block.comment.SqlLineCommentBlock
1921import org.domaframework.doma.intellij.formatter.util.IndentType
2022import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2123
@@ -41,8 +43,9 @@ class SqlParallelListBlock(
4143
4244 override fun createBlockIndentLen (): Int {
4345 parentBlock?.let { parent ->
44- return parent.childBlocks
45- .dropLast(1 )
46+ return parent
47+ .getChildBlocksDropLast()
48+ .filter { it !is SqlLineCommentBlock && it !is SqlBlockCommentBlock }
4649 .sumOf { it.getNodeText().length.plus(1 ) }
4750 .plus(parent.indent.indentLen)
4851 .plus(parent.getNodeText().length)
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ class SqlCustomSpacingBuilder {
132132 }
133133
134134 paramBlock is SqlParallelListBlock -> {
135- val lastKeywordGroup = paramBlock.childBlocks.dropLast( 1 ).lastOrNull()
135+ val lastKeywordGroup = paramBlock.getChildBlocksDropLast( ).lastOrNull()
136136 return if (lastKeywordGroup is SqlKeywordGroupBlock ) {
137137 normalSpacing
138138 } else {
Original file line number Diff line number Diff line change @@ -90,10 +90,6 @@ class SqlFormatterTest : BasePlatformTestCase() {
9090 formatSqlFile(" UpdateTupleAssignment.sql" , " UpdateTupleAssignment$formatDataPrefix .sql" )
9191 }
9292
93- fun testUpdateTupleAssignmentSubQueryFormatter () {
94- formatSqlFile(" UpdateTupleAssignmentSubQuery.sql" , " UpdateTupleAssignmentSubQuery$formatDataPrefix .sql" )
95- }
96-
9793 fun testUpdateTupleSubUseQueryRowFormatter () {
9894 formatSqlFile(" UpdateTupleSubUseQueryRow.sql" , " UpdateTupleSubUseQueryRow$formatDataPrefix .sql" )
9995 }
You can’t perform that action at this time.
0 commit comments