Intentions: function <-> property conversion
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ConvertFunctionToPropertyIntention
|
||||
@@ -0,0 +1,15 @@
|
||||
trait T {
|
||||
fun bar()
|
||||
}
|
||||
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo() = object : T {
|
||||
override fun bar() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
trait T {
|
||||
fun bar()
|
||||
}
|
||||
|
||||
class A(val n: Int) {
|
||||
val foo: T
|
||||
get() = object : T {
|
||||
override fun bar() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun test() {
|
||||
class X
|
||||
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo() = X()
|
||||
}
|
||||
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun test() {
|
||||
class X
|
||||
|
||||
class A(val n: Int) {
|
||||
val foo: X
|
||||
get() = X()
|
||||
}
|
||||
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo() = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A(val n: Int) {
|
||||
val foo: Boolean
|
||||
get() = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo(): Boolean {
|
||||
return n > 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class A(val n: Int) {
|
||||
val foo: Boolean
|
||||
get() {
|
||||
return n > 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// SHOULD_FAIL_WITH: Property foo already exists
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
val A.foo: Int
|
||||
get() = 1
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import test.A;
|
||||
|
||||
class J extends A {
|
||||
boolean getFoo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
int foo() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// SHOULD_FAIL_WITH: Method J.getFoo() already exists
|
||||
package test
|
||||
|
||||
open class A {
|
||||
open fun <caret>foo(): Int = 1
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A(val n: Int) {
|
||||
val foo: Boolean
|
||||
get() = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// ERROR: Too many arguments for internal final fun foo(): kotlin.Boolean defined in A
|
||||
// SHOULD_FAIL_WITH: Call with arguments will be skipped: foo(2)
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo(2)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo(k: Int): Boolean = n - k > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo(2)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>invoke(): Int = 1
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
val n = a()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>iterator(): Iterator<Int> = throw Exception("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
for (a in A(10)) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import static test.TestPackage.foo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
boolean b = foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import static test.TestPackage.getFoo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
boolean b = getFoo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
fun <caret>foo(): Boolean = true
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
val foo: Boolean
|
||||
get() = true
|
||||
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test(n: Int) {
|
||||
fun <caret>foo(): Boolean = n > 1
|
||||
|
||||
val t = foo()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo() = throw Exception("foo")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
package p
|
||||
|
||||
import p.foo
|
||||
|
||||
class A(val n: Int)
|
||||
|
||||
fun A.<caret>foo(): Boolean = n > 1
|
||||
|
||||
fun test() {
|
||||
val t = A::foo
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
package p
|
||||
|
||||
import p.foo
|
||||
|
||||
class A(val n: Int)
|
||||
|
||||
val A.foo: Boolean
|
||||
get() = n > 1
|
||||
|
||||
fun test() {
|
||||
val t = A::foo
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import test.*;
|
||||
|
||||
class JA extends A {
|
||||
public JA() {
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean foo() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class JTest {
|
||||
void test() {
|
||||
boolean x = new A(1).foo();
|
||||
boolean y = new JA().foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import test.*;
|
||||
|
||||
class JA extends A {
|
||||
public JA() {
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean getFoo() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class JTest {
|
||||
void test() {
|
||||
boolean x = new A(1).getFoo();
|
||||
boolean y = new JA().getFoo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package test
|
||||
|
||||
trait T {
|
||||
fun foo(): Boolean
|
||||
}
|
||||
|
||||
open class A(val n: Int): T {
|
||||
override fun foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
class B: A(1) {
|
||||
override fun <caret>foo(): Boolean = true
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A(1).foo()
|
||||
val b = B().foo()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package test
|
||||
|
||||
trait T {
|
||||
val foo: Boolean
|
||||
}
|
||||
|
||||
open class A(val n: Int): T {
|
||||
override val foo: Boolean
|
||||
get() = n > 1
|
||||
}
|
||||
|
||||
class B: A(1) {
|
||||
override val foo: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A(1).foo
|
||||
val b = B().foo
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// SHOULD_FAIL_WITH: Type arguments will be lost after conversion: foo<Double>()
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo<T>(): Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo<Double>()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>minus(): A = A(-n)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = -A(1)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class X(val s: String)
|
||||
|
||||
class A(val n: Int) {
|
||||
val t = 1
|
||||
internal X("1") fun <T : Number> T.<caret>foo(): Boolean = toInt() - n > 1
|
||||
val u = 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = with(A(1)) {
|
||||
2.5.foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class X(val s: String)
|
||||
|
||||
class A(val n: Int) {
|
||||
val t = 1
|
||||
internal X("1") val <T : Number> T.foo: Boolean
|
||||
get() = toInt() - n > 1
|
||||
val u = 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = with(A(1)) {
|
||||
2.5.foo
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>foo() {
|
||||
println(n)
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
A(1).foo()
|
||||
}
|
||||
Reference in New Issue
Block a user