Property <-> Function Conversion: Add/remove 'get'/'is' prefixes automatically

#KT-8812 Fixed
This commit is contained in:
Alexey Sedunov
2015-09-24 13:40:37 +03:00
parent 1b9bbf0bb6
commit 9ec87c01ab
32 changed files with 207 additions and 52 deletions
@@ -1,5 +1,5 @@
class G {
void test() {
test.TestPackage.bar();
test.TestPackage.getBar();
}
}
@@ -1,3 +1,3 @@
package test
fun bar(): Int = 1
fun getBar(): Int = 1
@@ -1,9 +1,9 @@
class A(val n: Int) {
fun foo(): Boolean {
fun getFoo(): Boolean {
return n > 1
}
}
fun test() {
val t = A(1).foo()
val t = A(1).getFoo()
}
@@ -1,7 +1,7 @@
class A(val n: Int) {
fun foo(): Boolean = n > 1
fun getFoo(): Boolean = n > 1
}
fun test() {
val t = A(1).foo()
val t = A(1).getFoo()
}
@@ -1,7 +1,7 @@
class A(val n: Int) {
fun foo(): Boolean = n > 1
fun getFoo(): Boolean = n > 1
}
fun test() {
val t = A(1).foo()
val t = A(1).getFoo()
}
@@ -1,9 +1,7 @@
import test.O;
import static test.O.foo;
class J {
void test() {
int n = O.foo;
int m = foo;
}
}
@@ -1,9 +1,7 @@
import test.O;
import static test.O.foo;
class J {
void test() {
int n = O.foo();
int m = foo();
int n = O.getFoo();
}
}
@@ -0,0 +1,7 @@
import static test.O.foo;
class J {
void test() {
int m = foo;
}
}
@@ -0,0 +1,7 @@
import static test.O.foo;
class J {
void test() {
int m = getFoo();
}
}
@@ -1,5 +1,5 @@
package test
object O {
fun foo(): Int = 1
fun getFoo(): Int = 1
}
@@ -1,7 +1,7 @@
import static test.TestPackage.foo;
import static test.TestPackage.getFoo;
class J {
void test() {
boolean b = foo();
boolean b = getFoo();
}
}
@@ -1,3 +1,3 @@
package test
fun foo(): Boolean = true
fun getFoo(): Boolean = true
@@ -1,12 +1,12 @@
// WITH_RUNTIME
package p
import p.foo
import p.getFoo
class A(val n: Int)
fun A.foo(): Boolean = n > 1
fun A.getFoo(): Boolean = n > 1
fun test() {
val t = A::foo
val t = A::getFoo
}
@@ -6,14 +6,14 @@ class JA extends A {
}
@Override
boolean foo() {
boolean getFoo() {
return true;
}
}
class JTest {
void test() {
boolean x = new A(1).foo();
boolean y = new JA().foo();
boolean x = new A(1).getFoo();
boolean y = new JA().getFoo();
}
}
@@ -1,18 +1,18 @@
package test
interface T {
fun foo(): Boolean
fun getFoo(): Boolean
}
open class A(val n: Int): T {
override fun foo(): Boolean = n > 1
override fun getFoo(): Boolean = n > 1
}
class B: A(1) {
override fun foo(): Boolean = true
override fun getFoo(): Boolean = true
}
fun test() {
val a = A(1).foo()
val b = B().foo()
val a = A(1).getFoo()
val b = B().getFoo()
}
@@ -1,2 +1,2 @@
// WITH_RUNTIME
fun String.foo(): String = if (isEmpty()) "" else substring(1).foo()
fun String.getFoo(): String = if (isEmpty()) "" else substring(1).getFoo()
@@ -3,11 +3,11 @@
annotation class X(val s: String)
class A(val n: Int) {
internal X("1") fun <T : Number> T.foo(): Boolean = toInt() - n > 1
internal X("1") fun <T : Number> T.getFoo(): Boolean = toInt() - n > 1
}
fun test() {
val t = with(A(1)) {
2.5.foo()
2.5.getFoo()
}
}