Create from Usage: Implement "Create function" on callable references

#KT-10283 Fixed
This commit is contained in:
Alexey Sedunov
2015-12-07 20:21:15 +03:00
parent 87aebd2cdf
commit f50059a11a
15 changed files with 186 additions and 0 deletions
@@ -0,0 +1,8 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
fun test() {
consume(1.map(::<caret>foo))
}
@@ -0,0 +1,11 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
fun test() {
fun foo(i: Int): String {
<selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
}
consume(1.map(::foo))
}
@@ -0,0 +1,8 @@
// "Create extension function 'foo'" "true"
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
fun test() {
consume(1.map(Int::<caret>foo))
}
@@ -0,0 +1,12 @@
// "Create extension function 'foo'" "true"
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
fun test() {
consume(1.map(Int::foo))
}
fun Int.foo(): String {
<selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
}
@@ -0,0 +1,6 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: (T) -> U) = f(this)
fun test() {
1.map(::<caret>foo)
}
@@ -0,0 +1,9 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: (T) -> U) = f(this)
fun test() {
fun foo(i: Int): Any {
<selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
}
1.map(::foo)
}
@@ -0,0 +1,11 @@
// "Create function 'foo'" "false"
// ACTION: Convert to expression body
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
fun bar(n: Int) = "$n"
fun consume(s: String) {}
fun test() {
consume(bar(::<caret>foo))
}
@@ -0,0 +1,8 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: (T) -> U) = f(this)
fun consume(s: String) {}
fun test() {
consume(1.map(::<caret>foo))
}
@@ -0,0 +1,11 @@
// "Create function 'foo'" "true"
fun <T, U> T.map(f: (T) -> U) = f(this)
fun consume(s: String) {}
fun test() {
fun foo(i: Int): String {
<selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
}
consume(1.map(::foo))
}