From c0ee50a693885111e4e3a80a1866a608af3042ad Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Sun, 11 Jun 2017 12:09:16 +0300 Subject: [PATCH] do not show "Move to constructor" intention for properties declared in interfaces --- .../MovePropertyToConstructorIntention.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt index 8387208156f..def81e70cd4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.core.ShortenReferences +import org.jetbrains.kotlin.idea.refactoring.isInterfaceClass import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers @@ -53,14 +54,20 @@ class MovePropertyToConstructorIntention : applyTo(property, null) } - override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = - !element.isLocal - && !element.hasDelegate() - && element.getter == null - && element.setter == null - && !element.hasModifier(LATEINIT_KEYWORD) - && element.getStrictParentOfType() is KtClass - && (element.initializer?.isValidInConstructor() ?: true) + override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { + fun KtProperty.isDeclaredInClass() : Boolean { + val parent = element.getStrictParentOfType() + return parent != null && !parent.isInterfaceClass() + } + + return !element.isLocal + && !element.hasDelegate() + && element.getter == null + && element.setter == null + && !element.hasModifier(LATEINIT_KEYWORD) + && (element.isDeclaredInClass()) + && (element.initializer?.isValidInConstructor() ?: true) + } override fun applyTo(element: KtProperty, editor: Editor?) { val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return