Insert imports on copy/paste

Introduce KotlinCopyPasteReferenceProcessor
This commit is contained in:
Pavel V. Talanov
2014-01-22 20:29:46 +04:00
parent 2f55959578
commit 61153c87e0
138 changed files with 2813 additions and 0 deletions
@@ -0,0 +1,21 @@
package to
import a.*
import a.E.ENTRY
import a.Outer.Inner
import a.Outer.Nested
import a.Outer.NestedEnum
import a.Outer.NestedObj
import a.Outer.NestedTrait
import a.Outer.NestedAnnotation
fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}
@@ -0,0 +1,56 @@
package a
import a.E.ENTRY
import a.Outer.*
trait T
class A(i: Int) {}
val c = 0
fun g(a: A) {}
fun A.ext()
object O1 {
fun f() {
}
}
object O2 {
}
enum class E {
ENTRY
}
class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
class ClassObject {
class object {
}
}
<selection>fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}</selection>
@@ -0,0 +1,5 @@
package to
import a.*
<caret>
@@ -0,0 +1,7 @@
package b
import a.A
fun f(a: A) {
A()
}
@@ -0,0 +1,7 @@
package a
class A() {}
<selection>fun f(a: A) {
A()
}</selection>
@@ -0,0 +1,5 @@
package b
import a.A
<caret>
@@ -0,0 +1,3 @@
package to
fun f() = c + d + g + j()
@@ -0,0 +1,14 @@
package a
// ALLOW_UNRESOLVED
class A(val c: Int = 1) {
var d = 2
val g: Int
get() = d
fun j() = c
<selection>fun f() = c + d + g + j()</selection>
}
@@ -0,0 +1,10 @@
package to
import a.T
import a.A
import a.B
fun g(t: T): Int {
g(A)
B.f()
}
@@ -0,0 +1,21 @@
package a
trait T
class A {
class object: T {
}
}
class B {
class object {
fun f(): Int
}
}
<selection>fun g(t: T): Int {
g(A)
B.f()
}</selection>
@@ -0,0 +1,5 @@
package to
fun g() {
f()
}
@@ -0,0 +1,13 @@
package a
// ALLOW_UNRESOLVED
//NOTE: is is an unsupported case
class A {
<selection>fun g() {
f()
}</selection>
class object {
fun f()
}
}
@@ -0,0 +1,11 @@
package to
import a.Outer.Inner
import a.Outer.Nested
import a.Outer.NestedEnum
import a.Outer.NestedObj
import a.Outer.NestedTrait
import a.Outer.NestedAnnotation
fun f(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
}
@@ -0,0 +1,22 @@
package a
import a.Outer.*
class Outer {
class object {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
}
<selection>fun f(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
}</selection>
@@ -0,0 +1,6 @@
package to
fun f(i: a.a) {
a.a
a.a()
}
@@ -0,0 +1,12 @@
package a
//NOTE: this case can be improved by using shorten reference after importing
class a {
class object {
}
}
<selection>fun f(i: a) {
a
a()
}</selection>
@@ -0,0 +1,6 @@
package to
import a.A
fun f(a: A) {
}
@@ -0,0 +1,6 @@
package a
class A() {}
<selection>fun f(a: A) {
}</selection>
@@ -0,0 +1,19 @@
package to
class C {
}
val c = 1
fun g() {
}
fun C.ext() {
}
fun f() {
a.c
a.g()
a.C()
a.C().ext()
}
@@ -0,0 +1,21 @@
package a
// ALLOW_UNRESOLVED
class C {
}
val c = 1
fun g() {
}
fun C.ext() {
}
<selection>fun f() {
c
g()
C()
C().ext()
}</selection>
@@ -0,0 +1,14 @@
package to
class C {
}
val c = 1
fun g() {
}
fun C.ext() {
}
<caret>
@@ -0,0 +1,7 @@
package to
class A<T> {
}
fun f(b: a.A<Int>) {
}
@@ -0,0 +1,7 @@
package a
class A<T> {
}
<selection>fun f(b: A<Int>) {
}</selection>
@@ -0,0 +1,6 @@
package to
class A<T> {
}
<caret>
@@ -0,0 +1,7 @@
package to
class A() {
}
fun f(a: a.A) {
}
@@ -0,0 +1,7 @@
package a
class A() {
}
<selection>fun f(a: A) {
}</selection>
@@ -0,0 +1,6 @@
package to
class A() {
}
<caret>
@@ -0,0 +1,6 @@
package to
fun f() {
}
fun g() = a.f()
@@ -0,0 +1,6 @@
package a
fun f() {
}
<selection>fun g() = f()</selection>
@@ -0,0 +1,6 @@
package to
fun f() {
}
<caret>
@@ -0,0 +1,7 @@
package b
import a.A
fun b() {
A()
}
@@ -0,0 +1,5 @@
package a
class A() {}
val c = <selection>A()</selection>
@@ -0,0 +1,5 @@
package b
fun b() {
<caret>
}
@@ -0,0 +1,21 @@
package to
import a.Outer.Nested.NN
import a.Outer.Nested.NI
import a.Outer.Inner.IN
import a.Outer.Inner.II
import a.Outer.Nested.NN2
import a.with
import a.Outer
import a.Outer.Inner.IN2
fun f(p1: NN, p2: NI, p3: IN, p4: II) {
NN2()
with(Outer.Nested()) {
NI2()
}
IN2()
with(Outer().Inner()) {
II2()
}
}
@@ -0,0 +1,41 @@
package a
import a.Outer.Nested.*
import a.Outer.Inner.*
class Outer {
class Nested {
class NN {
}
class NN2 {
}
inner class NI {
}
inner class NI2 {
}
}
inner class Inner {
class IN {
}
class IN2 {
}
inner class II {
}
inner class II2 {
}
}
}
fun <T> with(v: T, body: T.() -> Unit) = v.body()
<selection>fun f(p1: NN, p2: NI, p3: IN, p4: II) {
NN2()
with(Outer.Nested()) {
NI2()
}
IN2()
with(Outer().Inner()) {
II2()
}
}</selection>
@@ -0,0 +1,3 @@
package to
val c = A()
@@ -0,0 +1,6 @@
// ALLOW_UNRESOLVED
class A {
}
<selection>val c = A()</selection>
@@ -0,0 +1,9 @@
package to
import a.A
import a.get
import a.set
class B {
var a by A()
}
@@ -0,0 +1,16 @@
package a
trait T
fun T.get(thisRef: B, desc: PropertyMetadata): Int {
return 3
}
fun T.set(thisRef: B, desc: PropertyMetadata, value: Int) {
}
class A(): T
<selection>class B {
var a by A()
}</selection>
@@ -0,0 +1,16 @@
package java;
public class JavaClass {
public static int staticMethod() {
return 3;
}
public void method() {
}
public class InnerClass {
}
public class NestedClass {
}
}
@@ -0,0 +1,12 @@
package to
import java.JavaClass
import java.JavaClass.staticMethod
import java.JavaClass.NestedClass
fun f(c: JavaClass) {
staticMethod()
c.method()
c.InnerClass()
NestedClass()
}
@@ -0,0 +1,13 @@
package a
import java.JavaClass
import java.JavaClass.NestedClass
import java.JavaClass.staticMethod
<selection>fun f(c: JavaClass) {
staticMethod()
c.method()
c.InnerClass()
NestedClass()
}</selection>
@@ -0,0 +1,28 @@
package to
import d.A
import d.T
import d.g
import d.c
import d.ext
import d.O1
import d.O2
import d.E.ENTRY
import d.Outer.Inner
import d.Outer.Nested
import d.Outer.NestedEnum
import d.Outer.NestedObj
import d.Outer.NestedTrait
import d.Outer.NestedAnnotation
import d.ClassObject
fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}
@@ -0,0 +1,18 @@
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
package a
import d.*
import d.E.ENTRY
import d.Outer.*
<selection>fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}</selection>
@@ -0,0 +1,5 @@
package to
import kotlin.concurrent.FunctionalList
fun f(l: FunctionalList<Int>) {}
@@ -0,0 +1,7 @@
// RUNTIME
package g
import kotlin.concurrent.FunctionalList
<selection>fun f(l: FunctionalList<Int>) {}</selection>
@@ -0,0 +1,11 @@
package to
import a.A.A
import a.A.B
import a.A.C
fun f() {
A
B
C
}
@@ -0,0 +1,13 @@
package a
enum class A {
A
B
C
<selection>fun f() {
A
B
C
}</selection>
}
@@ -0,0 +1,11 @@
package to
import a.f
import a.p
import a.g
fun foo() {
3.f()
2.p
3.g = 5
}
@@ -0,0 +1,16 @@
package a
fun Int.f() {}
val Int.p: Int
get() = 2
var Int.g: Int
get() = 1
set(i : Int) = Unit
<selection>fun foo() {
3.f()
2.p
3.g = 5
}</selection>
@@ -0,0 +1,10 @@
package to
import a.A
import a.plus
import a.infix
fun f(a: A) {
a + a
a infix 1
}
@@ -0,0 +1,12 @@
package a
class A() {}
fun A.plus(a: A) = this
fun A.infix(i: Int) = i
<selection>fun f(a: A) {
a + a
a infix 1
}</selection>
@@ -0,0 +1,16 @@
package to
import a.A
fun A.ext() {
}
var A.p: Int
get() = 2
set(i: Int) = throw UnsupportedOperationException()
fun A.f() {
ext()
p
p = 3
}
@@ -0,0 +1,17 @@
package a
class A() {
}
fun A.ext() {
}
var A.p: Int
get() = 2
set(i: Int) = throw UnsupportedOperationException()
<selection>fun A.f() {
ext()
p
p = 3
}</selection>
@@ -0,0 +1,12 @@
package to
import a.A
fun A.ext() {
}
var A.p: Int
get() = 2
set(i: Int) = throw UnsupportedOperationException()
<caret>
@@ -0,0 +1,26 @@
package to
import a.A
fun A.ext() {
}
fun A.infix(a: A) {
}
fun A.plus(a: A) {
}
fun A.minus() {
}
val A.p: Int
get() = 2
fun f() {
A().ext()
A() + A()
A() infix A()
-A()
A().p
}
@@ -0,0 +1,27 @@
package a
class A {
}
fun A.ext() {
}
fun A.infix(a: A) {
}
fun A.plus(a: A) {
}
fun A.minus() {
}
val A.p: Int
get() = 2
<selection>fun f() {
A().ext()
A() + A()
A() infix A()
-A()
A().p
}</selection>
@@ -0,0 +1,20 @@
package to
import a.A
fun A.ext() {
}
fun A.infix(a: A) {
}
fun A.plus(a: A) {
}
fun A.minus() {
}
val A.p: Int
get() = 2
<caret>
@@ -0,0 +1,11 @@
package to
import a.A
import a.iterator
import a.next
import a.hasNext
fun f() {
for (i in A()) {
}
}
@@ -0,0 +1,18 @@
package a
class A() {
}
class B() {
}
fun B.next(): Int = 3
fun B.hasNext(): Boolean = false
fun A.iterator() = B()
<selection>fun f() {
for (i in A()) {
}
}</selection>
@@ -0,0 +1,3 @@
package to
fun f(t: a.b.c.A): a.b.c.B = a.b.c.B()
@@ -0,0 +1,7 @@
package a.b.c
class A() {}
class B() {}
<selection>fun f(t: a.b.c.A): a.b.c.B = a.b.c.B()</selection>
@@ -0,0 +1,7 @@
package to
import a.g
fun f() {
g()
}
@@ -0,0 +1,8 @@
package a
fun g() {
}
<selection>fun f() {
g()
}</selection>
@@ -0,0 +1,7 @@
package b
import a.g
fun f() {
g()
}
@@ -0,0 +1,8 @@
package a
fun g() {
}
<selection>fun f() {
g()
}</selection>
@@ -0,0 +1,5 @@
package b
import a.g
<caret>
@@ -0,0 +1,7 @@
package to
fun f() {
val r = arrayListOf<T>()
r.addAll(b)
val x = c
}
@@ -0,0 +1,10 @@
//RUNTIME
// ALLOW_UNRESOLVED
package a
fun <T> f(c: Int, b: List<T>) {
<selection>val r = arrayListOf<T>()
r.addAll(b)
val x = c</selection>
}
@@ -0,0 +1,5 @@
package to
fun f() {
<caret>
}
@@ -0,0 +1,8 @@
package to
import a.A
import a.get
fun f() {
A()[""]
}
@@ -0,0 +1,11 @@
package a
class A {
}
fun A.get(s: String) {
}
<selection>fun f() {
A()[""]
}</selection>
@@ -0,0 +1,42 @@
package d
trait T
class A(i: Int) {}
val c = 0
fun g(a: A) {}
fun A.ext()
object O1 {
fun f() {
}
}
object O2 {
}
enum class E {
ENTRY
}
class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
class ClassObject {
class object {
}
}
@@ -0,0 +1,28 @@
package to
import d.A
import d.T
import d.g
import d.c
import d.ext
import d.O1
import d.O2
import d.E.ENTRY
import d.Outer.Inner
import d.Outer.Nested
import d.Outer.NestedEnum
import d.Outer.NestedObj
import d.Outer.NestedTrait
import d.Outer.NestedAnnotation
import d.ClassObject
fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}
@@ -0,0 +1,16 @@
package a
import d.*
import d.E.ENTRY
import d.Outer.*
<selection>fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}</selection>
@@ -0,0 +1,5 @@
package to
package a
import a.A
@@ -0,0 +1,8 @@
// ALLOW_UNRESOLVED
<selection>package a
import a.A</selection>
class A() {
}
@@ -0,0 +1,3 @@
package to
<caret>
@@ -0,0 +1,14 @@
package to
import a.f
import a.A.Nested
import a.ext
fun g() {
f {
Inner()
Nested()
foo()
ext()
}
}
@@ -0,0 +1,28 @@
package a
import a.A.Inner
import a.A.Nested
class A {
inner class Inner {
}
class Nested {
}
fun foo() {
}
}
fun A.ext() {
}
fun f(body: A.() -> Unit) {
}
<selection>fun g() {
f {
Inner()
Nested()
foo()
ext()
}
}</selection>
@@ -0,0 +1,22 @@
package to
class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
enum class E {
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
}
@@ -0,0 +1,30 @@
package a
// ALLOW_UNRESOLVED
//NOTE: This test shows a corner case which is not covered fully by current implementation
// All we do now is avoid inserting wrong imports (we do not import anything for declaration from copied block)
// To cover this case properly and insert good imports some other approach should be used (some sophisticated heuristic might do the job)
import a.Outer.*
import a.E.ENTRY
<selection>class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
enum class E {
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
}</selection>
@@ -0,0 +1,13 @@
package to
import a.Outer.Inner
import a.Outer.Nested
import a.Outer.NestedEnum
import a.Outer.NestedObj
import a.Outer.NestedTrait
import a.Outer.NestedAnnotation
import a.Outer
fun f(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
Outer().Inner2()
}
+23
View File
@@ -0,0 +1,23 @@
package a
import a.Outer.*
class Outer {
inner class Inner {
}
inner class Inner2 {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
<selection>fun f(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
Outer().Inner2()
}</selection>
@@ -0,0 +1,8 @@
package to
import a.A
import a.invoke
fun f(a: A) {
a()
}
+11
View File
@@ -0,0 +1,11 @@
package a
class A {
}
fun A.invoke() {
}
<selection>fun f(a: A) {
a()
}</selection>
@@ -0,0 +1,10 @@
package a;
class JavaM {
static void staticMethod() {
}
}
class JavaF {
static int staticField = 0;
}
@@ -0,0 +1,9 @@
package to
import a.JavaM
import a.JavaF
fun f() {
JavaM.staticMethod()
JavaF.staticField()
}
@@ -0,0 +1,6 @@
package a
<selection>fun f() {
JavaM.staticMethod()
JavaF.staticField()
}</selection>
@@ -0,0 +1,43 @@
package d
trait T
class A(i: Int) {}
val c: Int = 0
fun g(a: A) {}
fun A.ext() {
}
object O1 {
fun f() {
}
}
object O2 {
}
enum class E {
ENTRY
}
class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
class ClassObject {
class object {
}
}
@@ -0,0 +1,6 @@
package to
fun f() {
val b = A()
val a = g()
}
+14
View File
@@ -0,0 +1,14 @@
package a
// ALLOW_UNRESOLVED
fun f() {
fun g(): Int {
}
class A() {
}
<selection>val b = A()
val a = g()</selection>
}
@@ -0,0 +1,5 @@
package to
fun f() {
<caret>
}
@@ -0,0 +1,13 @@
package to
import a.A
import a.B
import a.next
import a.hasNext
fun A.iterator() = B()
fun f() {
for (i in A()) {
}
}
@@ -0,0 +1,18 @@
package a
class A() {
}
class B() {
}
fun B.next(): Int = 3
fun B.hasNext(): Boolean = false
<selection>fun A.iterator() = B()
fun f() {
for (i in A()) {
}
}</selection>
@@ -0,0 +1,6 @@
package to
import a.d
import a.b
fun f(c: IntRange) = d + b
@@ -0,0 +1,6 @@
package a
private val d = 1
private val b = 2
<selection>fun f(c: IntRange) = d + b</selection>
@@ -0,0 +1,20 @@
package a
import a.E.ENTRY
import a.Outer.Inner
import a.Outer.Nested
import a.Outer.NestedEnum
import a.Outer.NestedObj
import a.Outer.NestedTrait
import a.Outer.NestedAnnotation
fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}
@@ -0,0 +1,56 @@
package a
import a.E.ENTRY
import a.Outer.*
trait T
class A(i: Int) {}
val c = 0
fun g(a: A) {}
fun A.ext() = A()
object O1 {
fun f() {
}
}
object O2 {
}
enum class E {
ENTRY
}
class Outer {
inner class Inner {
}
class Nested {
}
enum class NestedEnum {
}
object NestedObj {
}
trait NestedTrait {
}
annotation class NestedAnnotation
}
class ClassObject {
class object {
}
}
<selection>fun f(a: A, t: T) {
g(A(c).ext())
O1.f()
O2
ENTRY
}
fun f2(i: Inner, n: Nested, e: NestedEnum, o: NestedObj, t: NestedTrait, a: NestedAnnotation) {
ClassObject
}</selection>
@@ -0,0 +1,3 @@
package a
<caret>

Some files were not shown because too many files have changed in this diff Show More