Use binary expression as parent for better spacing (KT-27717)

When BINARY_EXPRESSION is used as parent, spacing rules for it are applied.
There're no rules for OPERATION_REFERENCE on the other side.

 #KT-27717 Fixed
This commit is contained in:
Nikolay Krasko
2018-10-30 18:15:18 +03:00
parent 2684974a33
commit 6f719a9460
5 changed files with 26 additions and 3 deletions
@@ -163,7 +163,15 @@ abstract class KotlinCommonBlock(
operationBlock.requireNode(),
subList(index, size),
null, indent, wrap, spacingBuilder
) { createSyntheticSpacingNodeBlock(it) }
) {
val parent = it.treeParent ?: node
val skipOperationNodeParent = if (parent.elementType === KtNodeTypes.OPERATION_REFERENCE) {
parent.treeParent ?: parent
} else {
parent
}
createSyntheticSpacingNodeBlock(skipOperationNodeParent)
}
return subList(0, index) + operationSyntheticBlock
}
@@ -27,7 +27,7 @@ class SyntheticKotlinBlock(
private val indent: Indent?,
private val wrap: Wrap?,
private val spacingBuilder: KotlinSpacingBuilder,
private val createSyntheticSpacingNodeBlock: (ASTNode) -> ASTBlock
private val createParentSyntheticSpacingBlock: (ASTNode) -> ASTBlock
) : ASTBlock {
private val textRange = TextRange(
@@ -44,7 +44,7 @@ class SyntheticKotlinBlock(
override fun isLeaf() = false
override fun getNode() = node
override fun getSpacing(child1: Block?, child2: Block): Spacing? {
return spacingBuilder.getSpacing(createSyntheticSpacingNodeBlock(node.treeParent!!), child1, child2)
return spacingBuilder.getSpacing(createParentSyntheticSpacingBlock(node), child1, child2)
}
@@ -27,6 +27,11 @@ class Some {
12%3*12/3
1..2
null ?: 3+1
val a=1
null ?: a+a
}
}
@@ -27,6 +27,11 @@ class Some {
12 % 3 * 12 / 3
1 .. 2
null ?: 3 + 1
val a = 1
null ?: a + a
}
}
+5
View File
@@ -27,6 +27,11 @@ class Some {
12%3*12/3
1..2
null ?: 3 + 1
val a = 1
null ?: a + a
}
}