Create from Usage: Fix exception in "Create class" quickfix applied to unresolved references in type arguments. Create class body when necessary

#KT-12777 Fixed
(cherry picked from commit dc90ec9)
This commit is contained in:
Alexey Sedunov
2016-06-20 15:52:41 +03:00
parent ffe4e760d7
commit 0d80bf030f
7 changed files with 43 additions and 2 deletions
@@ -531,8 +531,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
return Math.max(lineBreaksNeeded - lineBreaksPresent, 0)
}
val actualContainer = (containingElement as? KtClassOrObject)?.getOrCreateBody() ?: containingElement
fun addNextToOriginalElementContainer(addBefore: Boolean): KtNamedDeclaration {
val actualContainer = (containingElement as? KtClassOrObject)?.getBody() ?: containingElement
val sibling = config.originalElement.parentsWithSelf.first { it.parent == actualContainer }
return if (addBefore) {
actualContainer.addBefore(declaration, sibling)
@@ -543,7 +544,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
}
val declarationInPlace = when {
containingElement.isAncestor(config.originalElement, true) -> {
actualContainer.isAncestor(config.originalElement, true) -> {
val insertToBlock = containingElement is KtBlockExpression
if (insertToBlock) {
val parent = containingElement.parent