Skip to content

Commit 7c49978

Browse files
committed
Fix SQL formatting logic for parameter blocks and update static field access handling
1 parent 62b8ecd commit 7c49978

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ class SqlElParametersBlock(
6363
val childBlock1 = child1 as? SqlBlock
6464
val childBlock2 = child2 as? SqlBlock
6565

66-
if (childBlock1 == null) return SqlCustomSpacingBuilder.nonSpacing
66+
if (childBlock1 == null || childBlock1.node.elementType == SqlTypes.LEFT_PAREN) {
67+
return SqlCustomSpacingBuilder.nonSpacing
68+
}
6769
if (childBlock2 != null) {
6870
if (childBlock2.node.elementType == SqlTypes.RIGHT_PAREN) {
6971
return SqlCustomSpacingBuilder.nonSpacing
7072
}
7173
return when (childBlock1) {
72-
is SqlElSymbolBlock -> SqlCustomSpacingBuilder.nonSpacing
7374
is SqlElCommaBlock -> SqlCustomSpacingBuilder.normalSpacing
75+
is SqlElSymbolBlock -> SqlCustomSpacingBuilder.nonSpacing
7476
else -> SqlCustomSpacingBuilder.nonSpacing
7577
}
7678
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import com.intellij.psi.PsiWhiteSpace
2222
import com.intellij.psi.util.PsiTreeUtil
2323
import org.domaframework.doma.intellij.formatter.block.SqlBlock
2424
import org.domaframework.doma.intellij.formatter.block.SqlUnknownBlock
25-
import org.domaframework.doma.intellij.formatter.block.group.subgroup.SqlParallelListBlock
2625
import org.domaframework.doma.intellij.formatter.builder.SqlCustomSpacingBuilder
2726
import org.domaframework.doma.intellij.formatter.util.SqlBlockFormattingContext
2827
import org.domaframework.doma.intellij.psi.SqlElClass
@@ -56,7 +55,7 @@ class SqlElStaticFieldAccessBlock(
5655
SqlElIdentifierBlock(child, context)
5756

5857
SqlTypes.EL_PARAMETERS ->
59-
SqlParallelListBlock(child, context)
58+
SqlElParametersBlock(child, context)
6059

6160
else -> SqlUnknownBlock(child, context)
6261
}

src/test/testData/sql/formatter/Select.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AS nearest
2626
WHERE p.TYPE = 'Star'
2727
-- Line3
2828
OR ( p.flags & FPHOTOFLAGS('EDGE') = 0 AND (p.psfmag_g - p.extinction_g) BETWEEN 15 AND 20)
29-
/*%if status == 2 */
29+
/*%if status == 2 && employee.employeeParams(1,null, true ,"A") */
3030
-- Line4
3131
and u.propermotion > 2.0
3232
/** And Group */

src/test/testData/sql/formatter/Select_format.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ SELECT COUNT(DISTINCT x) AS count_x
3030
-- Line3
3131
OR (p.flags & FPHOTOFLAGS('EDGE') = 0
3232
AND (p.psfmag_g - p.extinction_g) BETWEEN 15 AND 20)
33-
/*%if status == 2 */
33+
/*%if status == 2 && employee.employeeParams(1, null, true, "A") */
3434
-- Line4
3535
AND u.propermotion > 2.0
3636
/** And Group */

src/test/testData/sql/formatter/StaticFieldAccess.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ SELECT *
22
FROM configurations
33
WHERE
44
config_key = /*@ com.example.Constants @CONFIG_KEY */'system.timeout'
5-
AND value = /*@ com.example.Utils @ util. getDefaultValue (0 , "x") */'30'
5+
AND value = /*@ com.example.Utils @ util. getDefaultValue (0,null,true , "0") */'30'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
SELECT *
22
FROM configurations
33
WHERE config_key = /* @com.example.Constants@CONFIG_KEY */'system.timeout'
4-
AND value = /* @[email protected](0, "x") */'30'
4+
AND value = /* @[email protected](0, null, true, "0") */'30'

0 commit comments

Comments
 (0)