File tree Expand file tree Collapse file tree 2 files changed +40
-12
lines changed
src/main/kotlin/org/domaframework/doma/intellij/formatter/block Expand file tree Collapse file tree 2 files changed +40
-12
lines changed Original file line number Diff line number Diff line change @@ -371,24 +371,51 @@ open class SqlBlock(
371371 0
372372 }
373373
374+ var prevBlock: SqlBlock ? = null
374375 return children
375376 .filter { it !is SqlDefaultCommentBlock && it !is SqlElConditionLoopCommentBlock }
376377 .sumOf { prev ->
377- prev
378- .getChildrenTextLen()
379- .plus(
380- if (prev.node.elementType == SqlTypes .DOT ||
381- prev.node.elementType == SqlTypes .RIGHT_PAREN
382- ) {
383- 0
384- } else {
385- prev.getNodeText().length.plus(1 )
386- },
387- )
378+ val sum =
379+ prev
380+ .getChildrenTextLen()
381+ .plus(
382+ if (prev.node.elementType == SqlTypes .DOT ||
383+ prev.node.elementType == SqlTypes .RIGHT_PAREN
384+ ) {
385+ 0
386+ } else if (prev.isOperationSymbol() && prevBlock?.isOperationSymbol() == true ) {
387+ // When operators appear consecutively, the first symbol includes the text length for the last space.
388+ // Subsequent symbols add only their own symbol length.
389+ prev.getNodeText().length
390+ } else {
391+ prev.getNodeText().length.plus(1 )
392+ },
393+ )
394+ prevBlock = prev
395+ return @sumOf sum
388396 }.plus(parent.indent.groupIndentLen)
389397 .plus(directiveParentIndent)
390398 }
391399
400+ fun isOperationSymbol (): Boolean =
401+ node.elementType in
402+ listOf (
403+ SqlTypes .PLUS ,
404+ SqlTypes .MINUS ,
405+ SqlTypes .ASTERISK ,
406+ SqlTypes .AT_SIGN ,
407+ SqlTypes .SLASH ,
408+ SqlTypes .HASH ,
409+ SqlTypes .LE ,
410+ SqlTypes .LT ,
411+ SqlTypes .EL_EQ ,
412+ SqlTypes .EL_NE ,
413+ SqlTypes .GE ,
414+ SqlTypes .GT ,
415+ SqlTypes .TILDE ,
416+ SqlTypes .OTHER ,
417+ )
418+
392419 /* *
393420 * Returns the child indentation for the block.
394421 *
Original file line number Diff line number Diff line change @@ -648,7 +648,8 @@ open class SqlFileBlock(
648648 childBlock1 is SqlOtherBlock && childBlock2 is SqlElSymbolBlock ||
649649 childBlock1 is SqlElSymbolBlock && childBlock2 is SqlElAtSignBlock ||
650650 childBlock1 is SqlOtherBlock && childBlock2 is SqlOtherBlock ||
651- childBlock1 is SqlElSymbolBlock && childBlock2 is SqlOtherBlock
651+ childBlock1 is SqlElSymbolBlock && childBlock2 is SqlOtherBlock ||
652+ childBlock1?.isOperationSymbol() == true && childBlock2.isOperationSymbol()
652653
653654 override fun isLeaf (): Boolean = false
654655
You can’t perform that action at this time.
0 commit comments