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,
|
KtPrimaryConstructor::class.java,
|
||||||
"Convert to secondary constructor"
|
"Convert to secondary constructor"
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int) =
|
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
|
||||||
element.containingClassOrObject is KtClass && element.valueParameters.all { !it.hasValOrVar() || it.annotationEntries.isEmpty() }
|
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 {
|
private fun KtReferenceExpression.isIndependent(classDescriptor: ClassDescriptor, context: BindingContext): Boolean {
|
||||||
val referencedDescriptor = context[BindingContext.REFERENCE_TARGET, this] ?: return false
|
val referencedDescriptor = context[BindingContext.REFERENCE_TARGET, this] ?: return false
|
||||||
@@ -61,6 +64,7 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
|
|
||||||
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
|
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
|
||||||
val klass = element.containingClassOrObject as? KtClass ?: return
|
val klass = element.containingClassOrObject as? KtClass ?: return
|
||||||
|
if (klass.isAnnotation()) return
|
||||||
val context = klass.analyze()
|
val context = klass.analyze()
|
||||||
val factory = KtPsiFactory(klass)
|
val factory = KtPsiFactory(klass)
|
||||||
val commentSaver = CommentSaver(element)
|
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);
|
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")
|
@TestMetadata("defaultValueChain.kt")
|
||||||
public void testDefaultValueChain() throws Exception {
|
public void testDefaultValueChain() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/defaultValueChain.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/defaultValueChain.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user