Do not suggest 'Convert to secondary constructor' for annotation classes
#KT-17408 Fixed
This commit is contained in:
+6
-2
@@ -40,8 +40,11 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
||||
KtPrimaryConstructor::class.java,
|
||||
"Convert to secondary constructor"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int) =
|
||||
element.containingClassOrObject is KtClass && element.valueParameters.all { !it.hasValOrVar() || it.annotationEntries.isEmpty() }
|
||||
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
|
||||
val containingClass = element.containingClassOrObject as? KtClass ?: return false
|
||||
if (containingClass.isAnnotation()) return false;
|
||||
return element.valueParameters.all { !it.hasValOrVar() || it.annotationEntries.isEmpty() }
|
||||
}
|
||||
|
||||
private fun KtReferenceExpression.isIndependent(classDescriptor: ClassDescriptor, context: BindingContext): Boolean {
|
||||
val referencedDescriptor = context[BindingContext.REFERENCE_TARGET, this] ?: return false
|
||||
@@ -61,6 +64,7 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
||||
|
||||
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
|
||||
val klass = element.containingClassOrObject as? KtClass ?: return
|
||||
if (klass.isAnnotation()) return
|
||||
val context = klass.analyze()
|
||||
val factory = KtPsiFactory(klass)
|
||||
val commentSaver = CommentSaver(element)
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
annotation class ValueMatters<caret>(val value: String)
|
||||
@@ -5012,6 +5012,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationClass.kt")
|
||||
public void testAnnotationClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/annotationClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultValueChain.kt")
|
||||
public void testDefaultValueChain() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/defaultValueChain.kt");
|
||||
|
||||
Reference in New Issue
Block a user