Move: Update test data for tests with conflicts

Check refactoring result for the case when conflicts are ignored.
Fix move destination when moving to another source root
This commit is contained in:
Alexey Sedunov
2017-03-20 12:22:28 +03:00
parent 38f9e99d91
commit 9a3ace423a
59 changed files with 155 additions and 100 deletions
@@ -1,9 +1,9 @@
public class A {
public static class X {
}
}
public class B {
private static class X {
}
}
@@ -1,3 +1,3 @@
fun bar(s: String) {
val t: A.X = A.X()
val t: B.X = B.X()
}
@@ -1,5 +1,5 @@
import A.*
fun bar(s: String) {
val t: X = X()
val t: B.X = B.X()
}
@@ -1,4 +1,4 @@
import A.X as XX
import B.X as XX
fun bar(s: String) {
val t: XX = XX()
@@ -1,7 +1,7 @@
public class A {
public static String X = "";
}
public class B {
private static String X = "";
}
@@ -1,3 +1,3 @@
fun bar(s: String) {
A.X = s
B.X = s
}
@@ -1,5 +1,5 @@
import A.*
fun bar(s: String) {
X = s
B.X = s
}
@@ -1,4 +1,4 @@
import A.X as XX
import B.X as XX
fun bar(s: String) {
XX = s
@@ -1,9 +1,9 @@
public class A {
public static void foo(String s) {
System.out.println(s)
}
}
public class B {
private static void foo(String s) {
System.out.println(s)
}
}
@@ -1,3 +1,3 @@
fun bar(s: String) {
A.foo(s)
B.foo(s)
}
@@ -1,5 +1,5 @@
import A.*
fun bar(s: String) {
foo(s)
B.foo(s)
}
@@ -1,4 +1,4 @@
import A.foo as foofoo
import B.foo as foofoo
fun bar(s: String) {
foofoo(s)
@@ -0,0 +1,8 @@
package test
class C(private val a: A.B) {
fun test() {
OuterOuterY()
this@A.OuterOuterY()
}
}
@@ -4,11 +4,5 @@ class A {
inner class OuterOuterY
inner class B {
inner class C {
fun test() {
OuterOuterY()
this@A.OuterOuterY()
}
}
}
}
@@ -2,8 +2,9 @@ class A {
private class B {
private class D
private class C {
private val d = D()
}
}
private class C {
private val d = B.D()
}
}
@@ -2,12 +2,13 @@ class A {
open class B {
protected class D
protected class C {
private val d = D()
}
}
protected class C {
private val d = B.D()
}
}
class X : A.B() {
private val c = A.B.C()
private val c = A.C()
}
@@ -0,0 +1,9 @@
package test
class Y(private val a: X) {
fun test() {
1.foo()
with(1) { foo() }
with(A()) { bar() }
}
}
@@ -9,11 +9,4 @@ class A() {
class X {
fun Int.foo() {}
inner class Y {
fun test() {
1.foo()
with(1) { foo() }
with(A()) { bar() }
}
}
}
@@ -0,0 +1,7 @@
package test
class B {
fun test() {
1.extFoo(1.extBar)
}
}
@@ -7,9 +7,4 @@ class A {
val Int.extBar: Int get() = 1
}
class B {
fun test() {
1.extFoo(1.extBar)
}
}
}
@@ -0,0 +1,3 @@
private class B {
private val c = A.C()
}
@@ -1,9 +1,5 @@
class A {
private val a = B()
private class B {
private val c = C()
}
private class C()
}
@@ -0,0 +1,3 @@
class B {
private val c = A.C()
}
@@ -1,10 +1,6 @@
open class A {
private val a = B()
protected class B {
private val c = C()
}
protected class C()
}
@@ -1,5 +1,5 @@
package a2
import a1.internalTargetVal
import b.internalTargetVal
internal val sourceVal = internalTargetVal
internal val sourceVal = b.internalTargetVal
@@ -1,4 +1,3 @@
package a
val val1 = 0
val val2 = val1
val val2 = target.val1
@@ -1,3 +1,3 @@
package a2
import a1.internalTargetVal
import b.internalTargetVal
@@ -1,7 +1,2 @@
package a
private class Test {
fun test {
foo(Foo())
}
}
@@ -1,5 +1,7 @@
package a;
import b.Test;
class J {
void bar() {
Test t = new Test();
@@ -1,5 +1,7 @@
package a
import b.Test
fun bar() {
val t: Test = Test()
}
@@ -0,0 +1,10 @@
package b
import a.Foo
import a.foo
private class Test {
fun test {
foo(Foo())
}
}
@@ -1,5 +1,2 @@
package a
private fun test() {
foo(Foo())
}
@@ -1,7 +1,9 @@
package a;
import b.TestKt;
class J {
void bar() {
MainKt.test();
TestKt.test();
}
}
@@ -1,5 +1,7 @@
package a
import b.test
fun bar() {
test()
}
@@ -0,0 +1,8 @@
package b
import a.Foo
import a.foo
private fun test() {
foo(Foo())
}
@@ -1,7 +1,2 @@
package a
private object Test {
fun test {
foo(Foo())
}
}
@@ -1,5 +1,7 @@
package a;
import b.Test;
class J {
void bar() {
Test t = Test.INSTANCE;
@@ -1,5 +1,7 @@
package a
import b.Test
fun bar() {
val t: Test = Test
}
@@ -0,0 +1,10 @@
package b
import a.Foo
import a.foo
private object Test {
fun test {
foo(Foo())
}
}
@@ -1 +1,3 @@
package test
package test
private class TempY
@@ -1,7 +1,7 @@
package test
private class TempY
var tempY: Int = 0
get() { TempY(); return field }
set(p: Int) { TempY(); field = p }
get() {
TempY(); return field }
set(p: Int) {
TempY(); field = p }
@@ -1,9 +1,5 @@
package a
private fun foo() {
bar()
}
private fun bar() {
foo()
}
@@ -1,3 +1,7 @@
package a
object Utils
object Utils
private fun foo() {
bar()
}
@@ -1,7 +1,4 @@
package a
private val foo: Int
get() = bar
private val bar: Int
get() = foo
@@ -1,3 +1,6 @@
package a
object Utils
object Utils
private val foo: Int
get() = bar
@@ -1,4 +1,3 @@
package a
private val used: Int = 2
val using: Int = used + 1
@@ -1,3 +1,5 @@
package a
object Utils
object Utils
private val used: Int = 2
@@ -1,7 +1,2 @@
package a
private var test: String
get() = ""
set(value: String) {
foo(Foo())
}
@@ -1,8 +1,10 @@
package a;
import b.TestKt;
class J {
void bar() {
MainKt.setTest("");
System.out.println(MainKt.getTest());
TestKt.setTest("");
System.out.println(TestKt.getTest());
}
}
@@ -1,5 +1,7 @@
package a
import b.test
fun bar() {
test = ""
println(test)
@@ -0,0 +1,10 @@
package b
import a.Foo
import a.foo
private var test: String
get() = ""
set(value: String) {
foo(Foo())
}
@@ -26,12 +26,10 @@ import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.*
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
import com.intellij.refactoring.MoveDestination
import com.intellij.refactoring.PackageWrapper
import com.intellij.refactoring.move.MoveHandler
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassToInnerProcessor
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor
import com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor
import com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination
import com.intellij.refactoring.move.moveClassesOrPackages.*
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor
import com.intellij.refactoring.move.moveInner.MoveInnerProcessor
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions
@@ -98,8 +96,15 @@ abstract class AbstractMoveTest : KotlinMultiFileTestCase() {
}
catch(e: ConflictsInTestsException) {
KotlinTestUtils.assertEqualsToFile(conflictFile, e.messages.sorted().joinToString("\n"))
ConflictsInTestsException.setTestIgnore(true)
// Run refactoring again with ConflictsInTestsException suppressed
action.runRefactoring(rootDir, mainPsiFile, elementAtCaret, config)
}
finally {
ConflictsInTestsException.setTestIgnore(false)
PsiDocumentManager.getInstance(project!!).commitAllDocuments()
FileDocumentManager.getInstance().saveAllDocuments()
@@ -270,15 +275,18 @@ enum class MoveAction {
val moveTarget = config.getNullableString("targetPackage")?.let { packageName ->
val targetSourceRootPath = config["targetSourceRoot"]?.asString
val moveDestination = MultipleRootsMoveDestination(PackageWrapper(mainFile.getManager(), packageName))
val packageWrapper = PackageWrapper(mainFile.getManager(), packageName)
val moveDestination: MoveDestination = targetSourceRootPath?.let {
AutocreatingSingleSourceRootMoveDestination(packageWrapper, rootDir.findFileByRelativePath(it)!!)
} ?: MultipleRootsMoveDestination(packageWrapper)
val targetDir = moveDestination.getTargetIfExists(mainFile)
val targetSourceRoot = if (targetSourceRootPath != null) {
val targetVirtualFile = if (targetSourceRootPath != null) {
rootDir.findFileByRelativePath(targetSourceRootPath)!!
} else {
targetDir?.virtualFile
}
KotlinMoveTargetForDeferredFile(FqName(packageName), targetDir, targetSourceRoot) {
KotlinMoveTargetForDeferredFile(FqName(packageName), targetDir, targetVirtualFile) {
createKotlinFile(guessNewFileName(listOf(elementToMove))!!, moveDestination.getTargetDirectory(mainFile))
}
} ?: config.getString("targetFile").let { filePath ->