Convert to secondary constructor: do not suggest when property has val/var and no name

#KT-29056 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-10 15:16:08 +09:00
committed by Mikhail Glukhikh
parent dab97ac936
commit d6e21b1c21
3 changed files with 8 additions and 1 deletions
@@ -44,7 +44,7 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
val containingClass = element.containingClassOrObject as? KtClass ?: return false
if (containingClass.isAnnotation() || containingClass.isData()
|| containingClass.superTypeListEntries.any { it is KtDelegatedSuperTypeEntry }) return false
return element.valueParameters.all { !it.hasValOrVar() || it.annotationEntries.isEmpty() }
return element.valueParameters.all { !it.hasValOrVar() || (it.name != null && it.annotationEntries.isEmpty()) }
}
private fun KtReferenceExpression.isIndependent(classDescriptor: ClassDescriptor, context: BindingContext): Boolean {
@@ -0,0 +1,2 @@
// IS_APPLICABLE: false
class Foo<caret>(val: String)
@@ -6229,6 +6229,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/noArgName.kt");
}
@TestMetadata("noArgNameVal.kt")
public void testNoArgNameVal() throws Exception {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/noArgNameVal.kt");
}
@TestMetadata("noArgType.kt")
public void testNoArgType() throws Exception {
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/noArgType.kt");