Convert to secondary constructor: do not suggest when property has val/var and no name
#KT-29056 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
dab97ac936
commit
d6e21b1c21
+1
-1
@@ -44,7 +44,7 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
val containingClass = element.containingClassOrObject as? KtClass ?: return false
|
val containingClass = element.containingClassOrObject as? KtClass ?: return false
|
||||||
if (containingClass.isAnnotation() || containingClass.isData()
|
if (containingClass.isAnnotation() || containingClass.isData()
|
||||||
|| containingClass.superTypeListEntries.any { it is KtDelegatedSuperTypeEntry }) return false
|
|| 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 {
|
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");
|
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")
|
@TestMetadata("noArgType.kt")
|
||||||
public void testNoArgType() throws Exception {
|
public void testNoArgType() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/noArgType.kt");
|
runTest("idea/testData/intentions/convertPrimaryConstructorToSecondary/noArgType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user