From 8c41e44b3b1782377023f10a196723fbfa00a92c Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Fri, 24 Mar 2017 21:52:53 +0300 Subject: [PATCH] Fix MovePropertyToConstructorIntention and broken tests --- .../idea/intentions/MovePropertyToConstructorIntention.kt | 2 ++ .../createFromUsage/createVariable/localVariable/inClass.kt | 1 + .../increaseVisibility/privateMemberToInternalWithExposed.kt | 1 + .../cantChangeMultipleOverriddenPropertiesTypes.kt | 1 + idea/testData/quickfix/typeAddition/noAddErrorType.kt | 1 + .../typeMismatch/dontChangeOverriddenPropertyTypeToErrorType.kt | 1 + idea/testData/quickfix/typeOfAnnotationMember/star.kt | 1 + idea/testData/quickfix/typeOfAnnotationMember/string.kt | 1 + .../variables/removeValVarFromParameter/constructorParameter.kt | 1 + 9 files changed, 10 insertions(+) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt index 5123b671a5d..181b7967fa6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.AnnotationChecker import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe @@ -55,6 +56,7 @@ class MovePropertyToConstructorIntention : && element.getter == null && element.setter == null && !element.hasModifier(LATEINIT_KEYWORD) + && element.getStrictParentOfType() is KtClass override fun applyTo(element: KtProperty, editor: Editor?) { val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt index a2d71d294a9..401789f7068 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt @@ -3,6 +3,7 @@ // ACTION: Create parameter 'foo' // ACTION: Create property 'foo' // ACTION: Rename reference +// ACTION: Move to constructor // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/increaseVisibility/privateMemberToInternalWithExposed.kt b/idea/testData/quickfix/increaseVisibility/privateMemberToInternalWithExposed.kt index 42f67345325..ae82b9b2b01 100644 --- a/idea/testData/quickfix/increaseVisibility/privateMemberToInternalWithExposed.kt +++ b/idea/testData/quickfix/increaseVisibility/privateMemberToInternalWithExposed.kt @@ -1,6 +1,7 @@ // "Make bar internal" "false" // ACTION: Convert property initializer to getter // ACTION: Add names to call arguments +// ACTION: Move to constructor // ERROR: Cannot access 'bar': it is private in 'First' private data class Data(val x: Int) diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeMultipleOverriddenPropertiesTypes.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeMultipleOverriddenPropertiesTypes.kt index 98163105562..f0045a4bc90 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeMultipleOverriddenPropertiesTypes.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/cantChangeMultipleOverriddenPropertiesTypes.kt @@ -1,5 +1,6 @@ // "Change type of overriden property 'A.x' to '(Int) -> Int'" "false" // ACTION: Change type to '(String) -> Int' +// ACTION: Move to constructor // ERROR: Type of 'x' is not a subtype of the overridden property 'public abstract val x: (String) -> Int defined in A' interface A { val x: (String) -> Int diff --git a/idea/testData/quickfix/typeAddition/noAddErrorType.kt b/idea/testData/quickfix/typeAddition/noAddErrorType.kt index 98980c9ac97..2b41846c45e 100644 --- a/idea/testData/quickfix/typeAddition/noAddErrorType.kt +++ b/idea/testData/quickfix/typeAddition/noAddErrorType.kt @@ -2,6 +2,7 @@ // ACTION: Convert property to function // ACTION: Introduce backing property // ACTION: Move to companion object +// ACTION: Move to constructor // ERROR: Unresolved reference: foo class A() { diff --git a/idea/testData/quickfix/typeMismatch/dontChangeOverriddenPropertyTypeToErrorType.kt b/idea/testData/quickfix/typeMismatch/dontChangeOverriddenPropertyTypeToErrorType.kt index e157c9d7639..88b675e3591 100644 --- a/idea/testData/quickfix/typeMismatch/dontChangeOverriddenPropertyTypeToErrorType.kt +++ b/idea/testData/quickfix/typeMismatch/dontChangeOverriddenPropertyTypeToErrorType.kt @@ -1,5 +1,6 @@ // "Change type to '(String) -> [ERROR : Ay]'" "false" // ACTION: Change type of base property 'A.x' to '(Int) -> Int' +// ACTION: Move to constructor // ERROR: Type of 'x' is not a subtype of the overridden property 'public abstract val x: (String) -> [ERROR : Ay] defined in A' // ERROR: Unresolved reference: Ay interface A { diff --git a/idea/testData/quickfix/typeOfAnnotationMember/star.kt b/idea/testData/quickfix/typeOfAnnotationMember/star.kt index 256be03280d..287e4bd0b22 100644 --- a/idea/testData/quickfix/typeOfAnnotationMember/star.kt +++ b/idea/testData/quickfix/typeOfAnnotationMember/star.kt @@ -1,5 +1,6 @@ // "Replace array of boxed with array of primitive" "false" // ACTION: Convert to secondary constructor +// ACTION: Move to class body // ERROR: Invalid type of annotation member annotation class SuperAnnotation( val foo: Array<*>, diff --git a/idea/testData/quickfix/typeOfAnnotationMember/string.kt b/idea/testData/quickfix/typeOfAnnotationMember/string.kt index c0727380cc0..1daa2b1d3c2 100644 --- a/idea/testData/quickfix/typeOfAnnotationMember/string.kt +++ b/idea/testData/quickfix/typeOfAnnotationMember/string.kt @@ -1,5 +1,6 @@ // "Replace array of boxed with array of primitive" "false" // ACTION: Convert to secondary constructor +// ACTION: Move to class body annotation class SuperAnnotation( val str: Array ) \ No newline at end of file diff --git a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt index 6ec2e29fb32..e91d14b2150 100644 --- a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt +++ b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt @@ -4,5 +4,6 @@ // ACTION: Make protected // ACTION: Create test // ACTION: Convert to secondary constructor +// ACTION: Move to class body class C(val x: String) { } \ No newline at end of file