Create From Usage: Quick-fix for properties

This commit is contained in:
Alexey Sedunov
2014-09-30 21:10:11 +04:00
parent 8386bcd4e0
commit 58126b28ca
59 changed files with 514 additions and 36 deletions
@@ -1,5 +1,6 @@
// "Create local variable 'foo'" "false"
// ACTION: Create parameter 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A {
@@ -1,4 +1,5 @@
// "Create local variable 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
val t: Int = <caret>foo
@@ -1,4 +1,5 @@
// "Create local variable 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ACTION: Split property declaration
// ERROR: Unresolved reference: foo
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A {
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
object A {
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
trait A {
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
val test: Int get() {
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A {
@@ -1,6 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Create local variable 'foo'
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A<T> {
@@ -1,5 +1,6 @@
// "Create parameter 'foo'" "false"
// ERROR: Unresolved reference: foo
// ACTION: Create property 'foo' from usage
class A {
val <T> test: T = <caret>foo
@@ -1,4 +1,5 @@
// "Create parameter 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A<T> {
@@ -1,4 +1,5 @@
// "Create parameter 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A {
@@ -1,4 +1,5 @@
// "Create parameter 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
object A {
@@ -1,4 +1,5 @@
// "Create parameter 'foo'" "false"
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
val test: Int = <caret>foo
@@ -1,5 +1,6 @@
// "Create parameter 'foo'" "false"
// ACTION: Split property declaration
// ACTION: Create property 'foo' from usage
// ERROR: Unresolved reference: foo
class A
@@ -0,0 +1,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>A&lt;kotlin.Int&gt;</td></tr></table></html>
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
val foo: Any
}
fun test(): Int {
return A(1).foo as A<Int>
}
@@ -0,0 +1,9 @@
// "Create property 'foo' from usage" "true"
fun test() {
val foo: Int
fun nestedTest(): Int {
return foo
}
}
@@ -0,0 +1,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A {
class B {
val foo: Int
fun test(): Int {
return foo
}
}
}
@@ -0,0 +1,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A {
object B {
val foo: Int
fun test(): Int {
return foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
val foo: A<Int>
fun test(): A<Int> {
return this.foo
}
}
@@ -0,0 +1,11 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
val foo: A<Int>
}
fun <U> A<U>.test(): A<Int> {
return this.foo
}
@@ -0,0 +1,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
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,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
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,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
fun test(): Int {
return foo
}
val foo: Int
@@ -0,0 +1,14 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
class object {
val foo: Int
}
}
fun test() {
val a: Int = A.foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
fun test() {
val a: Int = Unit.foo
}
val Unit.foo: Int
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
class A<T>(val n: T)
fun test() {
val a: A<Int> = 2.foo
}
val Int.foo: A<Int>
@@ -0,0 +1,11 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
object A {
val foo: Int
}
fun test() {
val a: Int = A.foo
}
@@ -0,0 +1,11 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
val foo: A<T>
}
fun test() {
val a: A<Int> = A(1).foo
}
@@ -0,0 +1,11 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
val foo: A<T>
}
fun test<U>(u: U) {
val a: A<U> = A(u).foo
}
@@ -0,0 +1,13 @@
// "Create property 'foo' from usage" "false"
// ACTION: Create function 'bar' from usage
// ACTION: Replace with infix function call
// ERROR: Unresolved reference: bar
// ERROR: Unresolved reference: foo
class A<T>(val n: T) {
val foo: Int = 1
}
fun test() {
A(1).<caret>bar(foo)
}
@@ -0,0 +1,9 @@
// "Create property 'foo' from usage" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>A&lt;kotlin.Int&gt;</td></tr></table></html>
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T)
fun test(): Int {
return A(1).<caret>foo as A<Int>
}
@@ -0,0 +1,13 @@
// "Create property 'foo' from usage" "false"
// ACTION: Convert to expression body
// ACTION: Disable 'Convert to Expression Body'
// ACTION: Edit intention settings
// ACTION: Create parameter 'foo'
// ACTION: Create local variable 'foo'
// ERROR: Unresolved reference: foo
fun test() {
fun nestedTest(): Int {
return <caret>foo
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A {
class B {
fun test(): Int {
return <caret>foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A {
object B {
fun test(): Int {
return <caret>foo
}
}
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
fun test(): A<Int> {
return this.<caret>foo
}
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T)
fun <U> A<U>.test(): A<Int> {
return this.<caret>foo
}
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
inner class B<U>(val m: U) {
fun test(): A<Int> {
return this.<caret>foo
}
}
}
@@ -0,0 +1,10 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
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,6 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
fun test(): Int {
return <caret>foo
}
@@ -0,0 +1,12 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T) {
class object {
}
}
fun test() {
val a: Int = A.<caret>foo
}
@@ -0,0 +1,6 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
fun test() {
val a: Int = Unit.<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized
class A<T>(val n: T)
fun test() {
val a: A<Int> = 2.<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
object A
fun test() {
val a: Int = A.<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T)
fun test() {
val a: A<Int> = A(1).<caret>foo
}
@@ -0,0 +1,8 @@
// "Create property 'foo' from usage" "true"
// ERROR: Property must be initialized or be abstract
class A<T>(val n: T)
fun test<U>(u: U) {
val a: A<U> = A(u).<caret>foo
}