Intentions: function <-> property conversion
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ConvertPropertyToFunctionIntention
|
||||
@@ -0,0 +1,5 @@
|
||||
class G {
|
||||
void test() {
|
||||
test.TestPackage.getBar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class G {
|
||||
void test() {
|
||||
test.TestPackage.bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
val <caret>bar: Int
|
||||
get() = 1
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
fun bar(): Int = 1
|
||||
@@ -0,0 +1,10 @@
|
||||
class A(val n: Int) {
|
||||
val <caret>foo: Boolean
|
||||
get() {
|
||||
return n > 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(): Boolean {
|
||||
return n > 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class A(val n: Int) {
|
||||
val <caret>foo: Boolean by Delegates.lazy { n > 1 }
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// SHOULD_FAIL_WITH: Function foo already exists
|
||||
class A(val n: Int) {
|
||||
val <caret>foo: Boolean = n > 1
|
||||
}
|
||||
|
||||
fun A.foo() = 1
|
||||
@@ -0,0 +1,12 @@
|
||||
import test.A;
|
||||
|
||||
class J extends A {
|
||||
boolean foo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getFoo() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// SHOULD_FAIL_WITH: Method J.foo() already exists
|
||||
package test
|
||||
|
||||
open class A {
|
||||
open val <caret>foo: Int = 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A(val n: Int) {
|
||||
val <caret>foo: Boolean
|
||||
get() = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(val n: Int) {
|
||||
val <caret>foo: Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(): Boolean = n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import test.O;
|
||||
import static test.O.foo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
int n = O.foo;
|
||||
int m = foo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import test.O;
|
||||
import static test.O.foo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
int n = O.foo();
|
||||
int m = foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
object O {
|
||||
val <caret>foo: Int = 1
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
object O {
|
||||
fun foo(): Int = 1
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import static test.TestPackage.getFoo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
boolean b = getFoo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import static test.TestPackage.foo;
|
||||
|
||||
class J {
|
||||
void test() {
|
||||
boolean b = foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
val <caret>foo: Boolean
|
||||
get() = true
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
fun foo(): Boolean = true
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
package p
|
||||
|
||||
import p.foo
|
||||
|
||||
class A(val n: Int)
|
||||
|
||||
val A.<caret>foo: Boolean
|
||||
get() = n > 1
|
||||
|
||||
fun test() {
|
||||
val t = A::foo
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
package p
|
||||
|
||||
import p.foo
|
||||
|
||||
class A(val n: Int)
|
||||
|
||||
fun A.foo(): Boolean = n > 1
|
||||
|
||||
fun test() {
|
||||
val t = A::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,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,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 <caret>foo: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A(1).foo
|
||||
val b = B().foo
|
||||
}
|
||||
@@ -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 foo(): Boolean = true
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A(1).foo()
|
||||
val b = B().foo()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class G {
|
||||
void test() {
|
||||
test.TestPackage.bar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// SHOULD_FAIL_WITH: Can't replace foreign reference with call expression: test.TestPackage.bar
|
||||
package test
|
||||
|
||||
val <caret>bar: Int
|
||||
get() = 1
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class X(val s: String)
|
||||
|
||||
class A(val n: Int) {
|
||||
internal X("1") val <T : Number> T.<caret>foo: Boolean
|
||||
get() = toInt() - n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = with(A(1)) {
|
||||
2.5.foo
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class X(val s: String)
|
||||
|
||||
class A(val n: Int) {
|
||||
internal X("1") fun <T : Number> T.foo(): Boolean = toInt() - n > 1
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = with(A(1)) {
|
||||
2.5.foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: false
|
||||
class A(var n: Int) {
|
||||
var <caret>foo: Int
|
||||
get() = n + 1
|
||||
set(value: Int) { n = value - 1 }
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val t = A(1).foo
|
||||
}
|
||||
Reference in New Issue
Block a user