Intentions: Move class member to companion object

#KT-9697 In Progress
This commit is contained in:
Alexey Sedunov
2016-01-29 15:02:19 +03:00
parent fe8a0ec2bc
commit d13ac6b5a4
70 changed files with 1417 additions and 45 deletions
@@ -0,0 +1,62 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
fun test(a: A, n: Int) {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
a.OuterY()
a.outerFoo(a.outerBar)
a.OuterY()
a.outerFoo(a.outerBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
void foo() {
A.Companion.test(new A(), 1);
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo() {
A.test(A(), 1)
}
@@ -0,0 +1,62 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
fun <caret>test(n: Int) {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
OuterY()
outerFoo(outerBar)
this.OuterY()
this.outerFoo(this@A.outerBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
void foo() {
new A().test(1);
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo() {
A().test(1)
}
@@ -0,0 +1,4 @@
{
"mainFile": "test.kt",
"intentionClass": "org.jetbrains.kotlin.idea.intentions.MoveMemberToCompanionObjectIntention"
}
@@ -0,0 +1,65 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
class B(private val a: A) {
fun test() {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
a.OuterY()
a.outerFoo(a.outerBar)
a.OuterY()
a.outerFoo(a.outerBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
A.Companion.B foo() {
return new A.Companion.B(new A());
}
}
@@ -0,0 +1,10 @@
package test2;
import test.A;
import test.A.Companion.B;
class Test {
B foo() {
return new B(new A());
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo(): A.Companion.B {
return A.Companion.B(A())
}
@@ -0,0 +1,8 @@
package test2
import test.A
import test.A.Companion.B
fun foo2(): B {
return B(A())
}
@@ -0,0 +1,64 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
inner class <caret>B {
fun test() {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
OuterY()
outerFoo(outerBar)
this@A.OuterY()
this@A.outerFoo(this@A.outerBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
A.B foo() {
return new A().new B();
}
}
@@ -0,0 +1,10 @@
package test2;
import test.A;
import test.A.B;
class Test {
B foo() {
return new A().new B();
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo(): A.B {
return A().B()
}
@@ -0,0 +1,8 @@
package test2
import test.A
import test.A.B
fun foo2(): B {
return A().B()
}
@@ -0,0 +1,4 @@
{
"mainFile": "test.kt",
"intentionClass": "org.jetbrains.kotlin.idea.intentions.MoveMemberToCompanionObjectIntention"
}
@@ -0,0 +1,53 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
class B {
fun test() {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
A.Companion.B foo() {
return new A.Companion.B();
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A.Companion.B;
class Test {
B foo() {
return new B();
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo(): A.Companion.B {
return A.Companion.B()
}
@@ -0,0 +1,7 @@
package test2
import test.A.Companion.B
fun foo(): B {
return B()
}
@@ -0,0 +1,52 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
class <caret>B {
fun test() {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A;
class Test {
A.B foo() {
return new A.B();
}
}
@@ -0,0 +1,9 @@
package test2;
import test.A.B;
class Test {
B foo() {
return new B();
}
}
@@ -0,0 +1,7 @@
package test2
import test.A
fun foo(): A.B {
return A.B()
}
@@ -0,0 +1,7 @@
package test2
import test.A.B
fun foo(): B {
return B()
}
@@ -0,0 +1,4 @@
{
"mainFile": "test.kt",
"intentionClass": "org.jetbrains.kotlin.idea.intentions.MoveMemberToCompanionObjectIntention"
}
@@ -0,0 +1,58 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
var test: Int
get() = 1
set(value: Int) {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
}
@@ -0,0 +1,10 @@
package test2;
import test.A;
class Test {
void foo() {
int x = A.Companion.getTest();
A.Companion.setTest(1);
}
}
@@ -0,0 +1,8 @@
package test2
import test.A
fun foo() {
val x = A.test
A.test = 1
}
@@ -0,0 +1,58 @@
package test
inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
class A {
class X {
}
inner class OuterY
fun outerFoo(n: Int) {}
val outerBar = 1
companion object {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
object O {
class Y
fun foo(n: Int) {}
val bar = 1
fun Int.extFoo(n: Int) {}
val Int.extBar: Int get() = 1
}
var <caret>test: Int
get() = 1
set(value: Int) {
X()
Y()
foo(bar)
1.extFoo(1.extBar)
O.Y()
O.foo(O.bar)
with (O) {
Y()
foo(bar)
1.extFoo(1.extBar)
}
}
}
@@ -0,0 +1,10 @@
package test2;
import test.A;
class Test {
void foo() {
int x = new A().getTest();
new A().setTest(1);
}
}
@@ -0,0 +1,8 @@
package test2
import test.A
fun foo() {
val x = A().test
A().test = 1
}
@@ -0,0 +1,4 @@
{
"mainFile": "test.kt",
"intentionClass": "org.jetbrains.kotlin.idea.intentions.MoveMemberToCompanionObjectIntention"
}