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
+1
View File
@@ -208,6 +208,7 @@
- [`KT-11975`](https://youtrack.jetbrains.com/issue/KT-11975) "Invert if-condition" intention does not simplify `is` expression
- [`KT-12437`](https://youtrack.jetbrains.com/issue/KT-12437) "Replace explicit parameter" intention is suggested for parameter of inner lambda in presence of `it` from outer lambda
- [`KT-12376`](https://youtrack.jetbrains.com/issue/KT-12376) Don't show "Package directive doesn't match file location" in injected code
- [`KT-12777`](https://youtrack.jetbrains.com/issue/KT-12777) Fix exception in "Create class" quickfix applied to unresolved references in type arguments
#### Language injection
@@ -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
@@ -0,0 +1,4 @@
// "Create class 'X'" "true"
open class A<T>
class B : A<B.<caret>X>()
@@ -0,0 +1,8 @@
// "Create class 'X'" "true"
open class A<T>
class B : A<B.X>() {
class X {
}
}
@@ -0,0 +1,6 @@
// "Create class 'X'" "true"
open class A<T>
class B : A<B.<caret>X>() {
}
@@ -0,0 +1,9 @@
// "Create class 'X'" "true"
open class A<T>
class B : A<B.X>() {
class X {
}
}
@@ -1788,6 +1788,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("nestedClassByTypeArgumentRefNoBody.kt")
public void testNestedClassByTypeArgumentRefNoBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/nestedClassByTypeArgumentRefNoBody.kt");
doTest(fileName);
}
@TestMetadata("nestedClassByTypeArgumentRefWithBody.kt")
public void testNestedClassByTypeArgumentRefWithBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/nestedClassByTypeArgumentRefWithBody.kt");
doTest(fileName);
}
@TestMetadata("objectNotQualifierNoTypeArgs.kt")
public void testObjectNotQualifierNoTypeArgs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/objectNotQualifierNoTypeArgs.kt");