Skip to content

Commit 3247255

Browse files
committed
Implemented an override method to set child block properties into the parent block accordingly.
1 parent ae7dce7 commit 3247255

13 files changed

+66
-55
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlInlineSe
4343
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
4444
import org.domaframework.doma.intellij.formatter.block.group.keyword.create.SqlCreateTableColumnDefinitionGroupBlock
4545
import org.domaframework.doma.intellij.formatter.block.group.keyword.insert.SqlInsertColumnGroupBlock
46+
import org.domaframework.doma.intellij.formatter.block.group.keyword.update.SqlUpdateColumnAssignmentSymbolBlock
4647
import org.domaframework.doma.intellij.formatter.block.group.keyword.update.SqlUpdateSetGroupBlock
4748
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlColumnRawGroupBlock
4849
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlDataTypeParamBlock
4950
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlFunctionParamBlock
5051
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlParallelListBlock
5152
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlRightPatternBlock
5253
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlSubQueryGroupBlock
53-
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlUpdateColumnAssignmentSymbolBlock
5454
import org.domaframework.doma.intellij.formatter.builder.SqlBlockBuilder
5555
import org.domaframework.doma.intellij.formatter.builder.SqlCustomSpacingBuilder
5656
import org.domaframework.doma.intellij.formatter.processor.SqlSetParentGroupProcessor
@@ -109,8 +109,11 @@ open class SqlBlock(
109109
open fun setParentGroupBlock(lastGroup: SqlBlock?) {
110110
parentBlock = lastGroup
111111
parentBlock?.addChildBlock(this)
112+
setParentPropertyBlock(lastGroup)
112113
}
113114

115+
open fun setParentPropertyBlock(lastGroup: SqlBlock?) {}
116+
114117
open val isNeedWhiteSpace: Boolean = true
115118

116119
open fun addChildBlock(childBlock: SqlBlock) {
@@ -414,7 +417,9 @@ open class SqlBlock(
414417
return blockUtil.getSubGroupBlock(lastGroup, child)
415418
}
416419

417-
SqlTypes.OTHER -> return if (lastGroup is SqlUpdateSetGroupBlock) {
420+
SqlTypes.OTHER -> return if (lastGroup is SqlUpdateSetGroupBlock &&
421+
lastGroup.columnDefinitionGroupBlock != null
422+
) {
418423
SqlUpdateColumnAssignmentSymbolBlock(child, defaultFormatCtx)
419424
} else {
420425
SqlOtherBlock(

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlColumnBlock.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class SqlColumnBlock(
4545
indent.groupIndentLen = 0
4646
}
4747

48-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
49-
// (lastGroup as? SqlColumnDefinitionRawGroupBlock)?.columnBlock = this
50-
// }
48+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
49+
(lastGroup as? SqlColumnDefinitionRawGroupBlock)?.columnBlock = this
50+
}
5151

5252
override fun buildChildren(): MutableList<AbstractBlock> = mutableListOf()
5353

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlTableBlock.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package org.domaframework.doma.intellij.formatter.block
1717

1818
import com.intellij.lang.ASTNode
1919
import com.intellij.psi.formatter.common.AbstractBlock
20+
import org.domaframework.doma.intellij.formatter.block.group.keyword.create.SqlCreateKeywordGroupBlock
21+
import org.domaframework.doma.intellij.formatter.util.CreateQueryType
2022
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2123

2224
class SqlTableBlock(
@@ -32,11 +34,11 @@ class SqlTableBlock(
3234
super.setParentGroupBlock(lastGroup)
3335
}
3436

35-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
36-
// if (lastGroup is SqlCreateKeywordGroupBlock && lastGroup.createType == CreateQueryType.TABLE) {
37-
// lastGroup.tableBlock = this
38-
// }
39-
// }
37+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
38+
if (lastGroup is SqlCreateKeywordGroupBlock && lastGroup.createType == CreateQueryType.TABLE) {
39+
lastGroup.tableBlock = this
40+
}
41+
}
4042

4143
override fun buildChildren(): MutableList<AbstractBlock> = mutableListOf()
4244
}

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/SqlKeywordGroupBlock.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.intellij.psi.formatter.common.AbstractBlock
2121
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2222
import org.domaframework.doma.intellij.formatter.block.group.SqlNewGroupBlock
2323
import org.domaframework.doma.intellij.formatter.block.group.keyword.create.SqlCreateViewGroupBlock
24+
import org.domaframework.doma.intellij.formatter.block.group.keyword.insert.SqlInsertQueryGroupBlock
2425
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlSubGroupBlock
2526
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlSubQueryGroupBlock
2627
import org.domaframework.doma.intellij.formatter.util.IndentType
@@ -50,17 +51,17 @@ open class SqlKeywordGroupBlock(
5051
createGroupIndentLen()
5152
}
5253

53-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
54-
// if (lastGroup is SqlSelectKeywordGroupBlock &&
55-
// SqlKeywordUtil.isSelectSecondOptionKeyword(getNodeText())
56-
// ) {
57-
// lastGroup.secondGroupBlocks.add(this)
58-
// }
59-
//
60-
// if (getNodeText() == "values" && lastGroup is SqlInsertQueryGroupBlock) {
61-
// lastGroup.valueKeywordBlock = this
62-
// }
63-
// }
54+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
55+
if (lastGroup is SqlSelectKeywordGroupBlock &&
56+
SqlKeywordUtil.isSelectSecondOptionKeyword(getNodeText())
57+
) {
58+
lastGroup.secondGroupBlocks.add(this)
59+
}
60+
61+
if (getNodeText() == "values" && lastGroup is SqlInsertQueryGroupBlock) {
62+
lastGroup.valueKeywordBlock = this
63+
}
64+
}
6465

6566
open fun getBaseIndentLen(
6667
preChildBlock: SqlBlock?,

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/SqlSelectKeywordGroupBlock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SqlSelectKeywordGroupBlock(
2525
node: ASTNode,
2626
context: SqlBlockFormattingContext,
2727
) : SqlKeywordGroupBlock(node, IndentType.TOP, context) {
28-
// val secondGroupBlocks: MutableList<SqlKeywordGroupBlock> = mutableListOf()
28+
val secondGroupBlocks: MutableList<SqlKeywordGroupBlock> = mutableListOf()
2929
val selectionColumns: MutableList<SqlBlock> = mutableListOf()
3030

3131
override fun setParentGroupBlock(lastGroup: SqlBlock?) {

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/create/SqlCreateTableColumnDefinitionRawGroupBlock.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class SqlCreateTableColumnDefinitionRawGroupBlock(
5555
indent.groupIndentLen = indent.indentLen
5656
}
5757

58-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
59-
// (lastGroup as? SqlCreateTableColumnDefinitionGroupBlock)
60-
// ?.columnRawGroupBlocks
61-
// ?.add(
62-
// this,
63-
// )
64-
// }
58+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
59+
(lastGroup as? SqlCreateTableColumnDefinitionGroupBlock)
60+
?.columnRawGroupBlocks
61+
?.add(
62+
this,
63+
)
64+
}
6565

6666
override fun createBlockIndentLen(): Int =
6767
(parentBlock as? SqlCreateTableColumnDefinitionGroupBlock)

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/insert/SqlInsertColumnGroupBlock.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class SqlInsertColumnGroupBlock(
5757
updateParentGroupIndentLen()
5858
}
5959

60-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
61-
// (lastGroup as? SqlInsertQueryGroupBlock)?.columnDefinitionGroupBlock = this
62-
// }
60+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
61+
(lastGroup as? SqlInsertQueryGroupBlock)?.columnDefinitionGroupBlock = this
62+
}
6363

6464
override fun buildChildren(): MutableList<AbstractBlock> = mutableListOf()
6565

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.domaframework.doma.intellij.formatter.block.group.subgroup
16+
package org.domaframework.doma.intellij.formatter.block.group.keyword.update
1717

1818
import com.intellij.lang.ASTNode
1919
import org.domaframework.doma.intellij.formatter.block.SqlBlock
@@ -35,9 +35,11 @@ class SqlUpdateColumnAssignmentSymbolBlock(
3535
indent.groupIndentLen = indent.groupIndentLen.plus(1)
3636
}
3737

38-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
39-
// (lastGroup as? SqlUpdateSetGroupBlock)?.assignmentSymbol = this
40-
// }
38+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
39+
if (lastGroup is SqlUpdateSetGroupBlock && lastGroup.columnDefinitionGroupBlock != null) {
40+
lastGroup.assignmentSymbol = this
41+
}
42+
}
4143

4244
private fun createIndentLen(): Int {
4345
parentBlock?.let { parent -> return parent.indent.groupIndentLen.plus(1) }

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/update/SqlUpdateColumnGroupBlock.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class SqlUpdateColumnGroupBlock(
4343
updateParentGroupIndentLen()
4444
}
4545

46-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
47-
// (lastGroup as? SqlUpdateSetGroupBlock)?.columnDefinitionGroupBlock = this
48-
// }
46+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
47+
(lastGroup as? SqlUpdateSetGroupBlock)?.columnDefinitionGroupBlock = this
48+
}
4949

5050
override fun createBlockIndentLen(): Int {
5151
parentBlock?.let { parent ->

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/group/keyword/update/SqlUpdateSetGroupBlock.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.intellij.lang.ASTNode
2020
import com.intellij.psi.formatter.common.AbstractBlock
2121
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2222
import org.domaframework.doma.intellij.formatter.block.group.keyword.SqlKeywordGroupBlock
23-
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlUpdateColumnAssignmentSymbolBlock
2423
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlUpdateValueGroupBlock
2524
import org.domaframework.doma.intellij.formatter.util.IndentType
2625
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
@@ -48,9 +47,9 @@ open class SqlUpdateSetGroupBlock(
4847
indent.groupIndentLen = indent.indentLen.plus(getNodeText().length)
4948
}
5049

51-
// override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
52-
// (lastGroup as? SqlUpdateQueryGroupBlock)?.setQueryGroupBlock = this
53-
// }
50+
override fun setParentPropertyBlock(lastGroup: SqlBlock?) {
51+
(lastGroup as? SqlUpdateQueryGroupBlock)?.setQueryGroupBlock = this
52+
}
5453

5554
override fun buildChildren(): MutableList<AbstractBlock> = mutableListOf()
5655

0 commit comments

Comments
 (0)