Copy: Improve file copying

- Do not copy individual declarations if entire file is selected
  (keeping original content with comments, formatting, etc.)
- Update package directive when original file packages matches
  its directory

 #KT-20092 Fixed
 #KT-18196 Fixed
This commit is contained in:
Alexey Sedunov
2017-09-19 15:21:31 +03:00
parent fbf6bd534c
commit 0beadddb7f
22 changed files with 159 additions and 13 deletions
@@ -0,0 +1,8 @@
package bar
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,6 @@
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,6 @@
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,4 @@
{
"mainFile": "test.kt",
"targetPackage": "bar"
}
@@ -0,0 +1,8 @@
package bar
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,8 @@
package foo
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,8 @@
package foo
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,4 @@
{
"mainFile": "foo/test.kt",
"targetPackage": "bar"
}
@@ -0,0 +1,8 @@
package foo
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,6 @@
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,8 @@
package foo
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,4 @@
{
"mainFile": "foo/test.kt",
"targetPackage": ""
}
@@ -0,0 +1,8 @@
package baz
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,8 @@
package baz
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,8 @@
package baz
val a = 42
// comment
// some other comment
val s = ""
@@ -0,0 +1,4 @@
{
"mainFile": "foo/test.kt",
"targetPackage": "bar"
}
@@ -8,4 +8,4 @@ class A {
class B {
val a: A = A()
val b: B = B()
}
}
@@ -1,15 +1,14 @@
package refactor.copy2
import refactor.ParentJava
import refactor.copy.Company
import kotlin.properties.Delegates
enum class Possible {
NO, YES
}
data class Potable(val p1: String)
class Insider(val peace: String)
class Init {
fun referred() = 0
fun moved() = referred()
@@ -28,6 +27,7 @@ class Simple {
}
annotation class MemAnn
class Variety<C> {
// object
object ExtractedObject {}
@@ -42,8 +42,7 @@ class Variety<C> {
private fun privateFun() = 0
fun <T> genFunB(p: T): T = p
fun <T> genFunC(p: T): C where T : C = p
@MemAnn
fun annotatedFun() = 0
@MemAnn fun annotatedFun() = 0
final fun finalFun() = 0
// property
var publicProp = 0
@@ -56,8 +55,7 @@ class Variety<C> {
var <T> List<T>.genVarL: T where T : C
get() = last()
set(p) {}
@MemAnn
val annotatedVal = 0
@MemAnn val annotatedVal = 0
var byVar by Delegates.notNull<Int>()
lateinit var lateVal: String
final val finalVal = 0
@@ -146,9 +144,9 @@ class CtorParameterChild(val pvc: String, var prc: String) : CtorParameter(pvc,
class CtorParameterChild2: CtorParameter {
constructor() : super("", "", "")
}
class CtorParameterChild3(override val pv: String, override var pr: String) : CtorParameter(pv, pv, pr)
data class CtorData(val pv: String, var pr: String) {}
class Company {
companion object {
val companyVal = 0