Fix MovePropertyToConstructorIntention and broken tests

This commit is contained in:
Vyacheslav Gerasimov
2017-03-24 21:52:53 +03:00
parent efa03e7ad8
commit 8c41e44b3b
9 changed files with 10 additions and 0 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.AnnotationChecker import org.jetbrains.kotlin.resolve.AnnotationChecker
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -55,6 +56,7 @@ class MovePropertyToConstructorIntention :
&& element.getter == null && element.getter == null
&& element.setter == null && element.setter == null
&& !element.hasModifier(LATEINIT_KEYWORD) && !element.hasModifier(LATEINIT_KEYWORD)
&& element.getStrictParentOfType<KtClassOrObject>() is KtClass
override fun applyTo(element: KtProperty, editor: Editor?) { override fun applyTo(element: KtProperty, editor: Editor?) {
val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return
@@ -3,6 +3,7 @@
// ACTION: Create parameter 'foo' // ACTION: Create parameter 'foo'
// ACTION: Create property 'foo' // ACTION: Create property 'foo'
// ACTION: Rename reference // ACTION: Rename reference
// ACTION: Move to constructor
// ERROR: Unresolved reference: foo // ERROR: Unresolved reference: foo
class A { class A {
@@ -1,6 +1,7 @@
// "Make bar internal" "false" // "Make bar internal" "false"
// ACTION: Convert property initializer to getter // ACTION: Convert property initializer to getter
// ACTION: Add names to call arguments // ACTION: Add names to call arguments
// ACTION: Move to constructor
// ERROR: Cannot access 'bar': it is private in 'First' // ERROR: Cannot access 'bar': it is private in 'First'
private data class Data(val x: Int) private data class Data(val x: Int)
@@ -1,5 +1,6 @@
// "Change type of overriden property 'A.x' to '(Int) -> Int'" "false" // "Change type of overriden property 'A.x' to '(Int) -> Int'" "false"
// ACTION: Change type to '(String) -> Int' // 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' // ERROR: Type of 'x' is not a subtype of the overridden property 'public abstract val x: (String) -> Int defined in A'
interface A { interface A {
val x: (String) -> Int val x: (String) -> Int
+1
View File
@@ -2,6 +2,7 @@
// ACTION: Convert property to function // ACTION: Convert property to function
// ACTION: Introduce backing property // ACTION: Introduce backing property
// ACTION: Move to companion object // ACTION: Move to companion object
// ACTION: Move to constructor
// ERROR: Unresolved reference: foo // ERROR: Unresolved reference: foo
class A() { class A() {
@@ -1,5 +1,6 @@
// "Change type to '(String) -> [ERROR : Ay]'" "false" // "Change type to '(String) -> [ERROR : Ay]'" "false"
// ACTION: Change type of base property 'A.x' to '(Int) -> Int' // 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: 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 // ERROR: Unresolved reference: Ay
interface A { interface A {
+1
View File
@@ -1,5 +1,6 @@
// "Replace array of boxed with array of primitive" "false" // "Replace array of boxed with array of primitive" "false"
// ACTION: Convert to secondary constructor // ACTION: Convert to secondary constructor
// ACTION: Move to class body
// ERROR: Invalid type of annotation member // ERROR: Invalid type of annotation member
annotation class SuperAnnotation( annotation class SuperAnnotation(
val foo: <caret>Array<*>, val foo: <caret>Array<*>,
@@ -1,5 +1,6 @@
// "Replace array of boxed with array of primitive" "false" // "Replace array of boxed with array of primitive" "false"
// ACTION: Convert to secondary constructor // ACTION: Convert to secondary constructor
// ACTION: Move to class body
annotation class SuperAnnotation( annotation class SuperAnnotation(
val str: <caret>Array<String> val str: <caret>Array<String>
) )
@@ -4,5 +4,6 @@
// ACTION: Make protected // ACTION: Make protected
// ACTION: Create test // ACTION: Create test
// ACTION: Convert to secondary constructor // ACTION: Convert to secondary constructor
// ACTION: Move to class body
class C(<caret>val x: String) { class C(<caret>val x: String) {
} }