Skip to content

Commit

Permalink
bugfix/compact-incorrect-tree(#599)
Browse files Browse the repository at this point in the history
### What's done:
  * Fixed bugs
  • Loading branch information
aktsay6 committed Dec 7, 2020
1 parent 42a6817 commit 31288f0
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ class CompactInitialization(private val configRules: List<RulesConfig>) : Rule("
bodyExpression.addChild(it.clone() as ASTNode, null)
it.treeParent.removeChild(it)
}
// strip receiver name and move assignment itself into `apply`
// Code above breaks a tree a little bit, so need this hack to recover it
// Code above adds whiteSpace node to block, but it should be in functional literal after LBRACE
if (bodyExpression.treeParent.elementType == FUNCTION_LITERAL
&& bodyExpression.firstChildNode.elementType == WHITE_SPACE) {
bodyExpression.treeParent.addChild(bodyExpression.firstChildNode.copyElement(),
bodyExpression.treeParent.firstChildNode.treeNext)
bodyExpression.removeChild(bodyExpression.firstChildNode)
}
// strip receiver name and move assignment itself into `apply`
bodyExpression.addChild(kotlinParser.createNode(assignment.text.substringAfter('.')), null)
assignment.node.run { treeParent.removeChild(this) }
}
Expand Down

0 comments on commit 31288f0

Please sign in to comment.