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.psi.psiUtil.startOffset
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.util.kind
|
||||||
|
|
||||||
class ConvertSecondaryConstructorToPrimaryInspection : IntentionBasedInspection<KtSecondaryConstructor>(
|
class ConvertSecondaryConstructorToPrimaryInspection : IntentionBasedInspection<KtSecondaryConstructor>(
|
||||||
ConvertSecondaryConstructorToPrimaryIntention::class,
|
ConvertSecondaryConstructorToPrimaryIntention::class,
|
||||||
@@ -162,17 +163,16 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
|
|||||||
|
|
||||||
element.moveParametersToPrimaryConstructorAndInitializers(constructor, parameterToPropertyMap, context, factory)
|
element.moveParametersToPrimaryConstructorAndInitializers(constructor, parameterToPropertyMap, context, factory)
|
||||||
|
|
||||||
val delegationCall = element.getDelegationCall()
|
val argumentList = element.getDelegationCall().valueArgumentList
|
||||||
val argumentList = delegationCall.valueArgumentList
|
for (superTypeListEntry in klass.superTypeListEntries) {
|
||||||
if (!delegationCall.isImplicit && argumentList != null) {
|
val typeReference = superTypeListEntry.typeReference ?: continue
|
||||||
for (superTypeListEntry in klass.superTypeListEntries) {
|
val type = context[BindingContext.TYPE, typeReference]
|
||||||
val typeReference = superTypeListEntry.typeReference ?: continue
|
if ((type?.constructor?.declarationDescriptor as? ClassifierDescriptorWithTypeParameters)?.kind == ClassKind.CLASS) {
|
||||||
val type = context[BindingContext.TYPE, typeReference]
|
val superTypeCallEntry = factory.createSuperTypeCallEntry(
|
||||||
if ((type?.constructor?.declarationDescriptor as? ClassDescriptor)?.kind == ClassKind.CLASS) {
|
"${typeReference.text}${argumentList?.text ?: "()"}"
|
||||||
val superTypeCallEntry = factory.createSuperTypeCallEntry("${typeReference.text}${argumentList.text}")
|
)
|
||||||
superTypeListEntry.replace(superTypeCallEntry)
|
superTypeListEntry.replace(superTypeCallEntry)
|
||||||
break
|
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);
|
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")
|
@TestMetadata("withBaseClass.kt")
|
||||||
public void testWithBaseClass() throws Exception {
|
public void testWithBaseClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClass.kt");
|
||||||
doTest(fileName);
|
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")
|
@TestMetadata("withBaseClassNoArgs.kt")
|
||||||
public void testWithBaseClassNoArgs() throws Exception {
|
public void testWithBaseClassNoArgs() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClassNoArgs.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withBaseClassNoArgs.kt");
|
||||||
@@ -5672,6 +5684,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("withModifiers.kt")
|
||||||
public void testWithModifiers() throws Exception {
|
public void testWithModifiers() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withModifiers.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/withModifiers.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user