"Convert to secondary constructor": Fix false positive with delegation #KT-27061 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-09-26 12:15:27 +09:00
committed by Mikhail Glukhikh
parent af1fc5b668
commit c1013cc198
3 changed files with 12 additions and 1 deletions
@@ -42,7 +42,8 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
) {
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
val containingClass = element.containingClassOrObject as? KtClass ?: return false
if (containingClass.isAnnotation() || containingClass.isData()) return false;
if (containingClass.isAnnotation() || containingClass.isData()
|| containingClass.superTypeListEntries.any { it is KtDelegatedSuperTypeEntry }) return false
return element.valueParameters.all { !it.hasValOrVar() || it.annotationEntries.isEmpty() }
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
interface Base
class Foo(<caret>s: String, b: Base): Base by b
@@ -5755,6 +5755,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/defaultValueChain.kt");
}
@TestMetadata("delegation.kt")
public void testDelegation() throws Exception {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/delegation.kt");
}
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/enum.kt");