Fix "secondary constructor -> primary" in case of implicit super call
So #KT-16903 Fixed
This commit is contained in:
+11
-11
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.util.kind
|
||||
|
||||
class ConvertSecondaryConstructorToPrimaryInspection : IntentionBasedInspection<KtSecondaryConstructor>(
|
||||
ConvertSecondaryConstructorToPrimaryIntention::class,
|
||||
@@ -162,17 +163,16 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
|
||||
|
||||
element.moveParametersToPrimaryConstructorAndInitializers(constructor, parameterToPropertyMap, context, factory)
|
||||
|
||||
val delegationCall = element.getDelegationCall()
|
||||
val argumentList = delegationCall.valueArgumentList
|
||||
if (!delegationCall.isImplicit && argumentList != null) {
|
||||
for (superTypeListEntry in klass.superTypeListEntries) {
|
||||
val typeReference = superTypeListEntry.typeReference ?: continue
|
||||
val type = context[BindingContext.TYPE, typeReference]
|
||||
if ((type?.constructor?.declarationDescriptor as? ClassDescriptor)?.kind == ClassKind.CLASS) {
|
||||
val superTypeCallEntry = factory.createSuperTypeCallEntry("${typeReference.text}${argumentList.text}")
|
||||
superTypeListEntry.replace(superTypeCallEntry)
|
||||
break
|
||||
}
|
||||
val argumentList = element.getDelegationCall().valueArgumentList
|
||||
for (superTypeListEntry in klass.superTypeListEntries) {
|
||||
val typeReference = superTypeListEntry.typeReference ?: continue
|
||||
val type = context[BindingContext.TYPE, typeReference]
|
||||
if ((type?.constructor?.declarationDescriptor as? ClassifierDescriptorWithTypeParameters)?.kind == ClassKind.CLASS) {
|
||||
val superTypeCallEntry = factory.createSuperTypeCallEntry(
|
||||
"${typeReference.text}${argumentList?.text ?: "()"}"
|
||||
)
|
||||
superTypeListEntry.replace(superTypeCallEntry)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
abstract class A<T>
|
||||
|
||||
typealias AS = A<String>
|
||||
|
||||
class C : AS {
|
||||
<caret>constructor()
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
abstract class A<T>
|
||||
|
||||
typealias AS = A<String>
|
||||
|
||||
class C() : AS() {
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
abstract class A
|
||||
|
||||
class C : A {
|
||||
<caret>constructor()
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
abstract class A
|
||||
|
||||
class C() : A() {
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
interface A<T>
|
||||
|
||||
typealias AS = A<String>
|
||||
|
||||
class C : AS {
|
||||
<caret>constructor()
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
interface A<T>
|
||||
|
||||
typealias AS = A<String>
|
||||
|
||||
class C() : AS {
|
||||
}
|
||||
@@ -5636,12 +5636,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withBaseAliasImplicit.kt")
|
||||
public void testWithBaseAliasImplicit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseAliasImplicit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withBaseClass.kt")
|
||||
public void testWithBaseClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withBaseClassImplicit.kt")
|
||||
public void testWithBaseClassImplicit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClassImplicit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withBaseClassNoArgs.kt")
|
||||
public void testWithBaseClassNoArgs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClassNoArgs.kt");
|
||||
@@ -5672,6 +5684,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withInterfaceAlias.kt")
|
||||
public void testWithInterfaceAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withInterfaceAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withModifiers.kt")
|
||||
public void testWithModifiers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withModifiers.kt");
|
||||
|
||||
Reference in New Issue
Block a user