Create from Usage: Implement 'Create property as constructor parameter' quick-fix

#KT-8426 Fixed
This commit is contained in:
Alexey Sedunov
2015-10-19 11:32:33 +03:00
parent bdd495460b
commit 929d06c86f
45 changed files with 422 additions and 30 deletions
@@ -0,0 +1,11 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Convert to expression body
// ACTION: Create parameter 'foo'
// ACTION: Create local variable 'foo'
// ERROR: Unresolved reference: foo
fun test() {
fun nestedTest(): Int {
return <caret>foo
}
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A {
class B {
fun test(): Int {
return <caret>foo
}
}
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A {
class B(val foo: Int) {
fun test(): Int {
return foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' as constructor parameter" "true"
class A {
class B {
fun test(): Int {
<caret>foo = 1
return foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' as constructor parameter" "true"
class A {
class B(var foo: Int) {
fun test(): Int {
<caret>foo = 1
return foo
}
}
}
@@ -0,0 +1,14 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create parameter 'foo'
// ACTION: Create property 'foo'
// ERROR: Unresolved reference: foo
class A {
object B {
fun test(): Int {
return <caret>foo
}
}
}
@@ -0,0 +1,8 @@
// "Create member property 'foo' as constructor parameter" "false"
// ACTION: Create member property 'foo'
// ERROR: Unresolved reference: foo
fun test() {
val a: Int = J.<caret>foo
}
@@ -0,0 +1,7 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T) {
fun test(): A<Int> {
return this.<caret>foo
}
}
@@ -0,0 +1,7 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T, val foo: A<Int>) {
fun test(): A<Int> {
return this.foo
}
}
@@ -0,0 +1,7 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T)
fun <U> A<U>.test(): A<Int> {
return this.<caret>foo
}
@@ -0,0 +1,7 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T, val foo: A<Int>)
fun <U> A<U>.test(): A<Int> {
return this.<caret>foo
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U) {
fun test(): A<Int> {
return this.<caret>foo
}
}
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U, val foo: A<Int>) {
fun test(): A<Int> {
return this.foo
}
}
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U) {
fun test(): A<Int> {
return this@A.<caret>foo
}
}
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "true"
class A<T>(val n: T, val foo: A<Int>) {
inner class B<U>(val m: U) {
fun test(): A<Int> {
return this@A.foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Create property 'foo'
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create parameter 'foo'
// ERROR: Unresolved reference: foo
fun test(): Int {
return <caret>foo
}
@@ -0,0 +1,14 @@
// "Create member property 'foo' as constructor parameter" "false"
// ACTION: Create member property 'foo'
// ACTION: Create extension property 'foo'
// ERROR: Unresolved reference: foo
class A<T>(val n: T) {
companion object {
}
}
fun test() {
val a: Int = A.<caret>foo
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Create member property 'foo'
// ACTION: Convert to expression body
// ACTION: Create extension property 'foo'
// ERROR: Unresolved reference: foo
fun test(): String? {
return A().<caret>foo
}
@@ -0,0 +1,9 @@
// "Create property 'foo' as constructor parameter" "false"
// ACTION: Create extension property 'foo'
// ERROR: Unresolved reference: foo
class A<T>(val n: T)
fun test() {
val a: A<Int> = 2.<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' as constructor parameter" "true"
// ERROR: No value passed for parameter foo
class A<T>(val n: T)
fun test() {
val a: A<Int> = A(1).<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' as constructor parameter" "true"
// ERROR: No value passed for parameter foo
class A<T>(val n: T, val foo: A<Int>)
fun test() {
val a: A<Int> = A(1, ).foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' as constructor parameter" "true"
// ERROR: No value passed for parameter foo
class A<T>(val n: T)
fun test() {
A(1).<caret>foo = "1"
}
@@ -0,0 +1,8 @@
// "Create property 'foo' as constructor parameter" "true"
// ERROR: No value passed for parameter foo
class A<T>(val n: T, var foo: String)
fun test() {
A(1, ).foo = "1"
}