Do not suggest 'Convert to secondary constructor' for annotation classes

#KT-17408 Fixed
This commit is contained in:
Dmitry Neverov
2017-04-26 06:22:14 +02:00
parent d5867c1ee3
commit f84c5b0339
3 changed files with 15 additions and 2 deletions
@@ -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)
@@ -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");