From db38f420f31e198e2af6e92ddf874545ca062991 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 15 Apr 2014 14:06:06 +0400 Subject: [PATCH] Move Refactoring: Do not replace references to local declaration with qualified names. Update and fix test data #KT-4851 Fixed --- .../jet/plugin/refactoring/move/moveUtils.kt | 3 ++- .../moveClassToFile/after/b/dependency.kt | 10 ++++++++++ .../moveClassToFile/before/a/main.kt | 10 ++++++++++ .../moveClassToPackage/after/b/Test.kt | 10 ++++++++++ .../moveClassToPackage/before/a/main.kt | 10 ++++++++++ .../moveFunctionToFile/after/b/dependency.kt | 14 +++++++++++++- .../moveFunctionToFile/before/a/main.kt | 14 +++++++++++++- .../moveFunctionToPackage/after/b/test.kt | 14 +++++++++++++- .../moveFunctionToPackage/before/a/main.kt | 14 +++++++++++++- .../after/a/main.kt | 2 +- .../before/a/main.kt | 2 +- .../moveObjectToFile/after/b/dependency.kt | 10 ++++++++++ .../moveObjectToFile/before/a/main.kt | 10 ++++++++++ .../moveObjectToPackage/after/b/Test.kt | 10 ++++++++++ .../moveObjectToPackage/before/a/main.kt | 10 ++++++++++ .../movePropertyToFile/after/b/dependency.kt | 12 ++++++++++++ .../movePropertyToFile/before/a/main.kt | 12 ++++++++++++ .../movePropertyToPackage/after/b/test.kt | 12 ++++++++++++ .../movePropertyToPackage/before/a/main.kt | 12 ++++++++++++ 19 files changed, 184 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/move/moveUtils.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/move/moveUtils.kt index 4ef32078001..11322e269bb 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/move/moveUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/move/moveUtils.kt @@ -32,6 +32,7 @@ import org.jetbrains.jet.asJava.KotlinLightClass import org.jetbrains.jet.plugin.JetFileType import org.jetbrains.jet.lang.psi.JetClassOrObject import org.jetbrains.jet.lang.psi.JetNamedDeclaration +import org.jetbrains.jet.plugin.imports.canBeReferencedViaImport public class PackageNameInfo(val oldPackageName: FqName, val newPackageName: FqName) @@ -49,7 +50,7 @@ public fun JetElement.updateInternalReferencesOnPackageNameChange( val descriptor = bindingContext[BindingContext.REFERENCE_TARGET, refExpr]?.let { descriptor -> if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration() else descriptor } - if (descriptor == null) continue + if (descriptor == null || !descriptor.canBeReferencedViaImport()) continue val packageName = DescriptorUtils.getParentOfType( descriptor, javaClass(), false diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/after/b/dependency.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/after/b/dependency.kt index fa509866370..ea9660bcae4 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/after/b/dependency.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/after/b/dependency.kt @@ -7,6 +7,16 @@ open class Foo { } class Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/before/a/main.kt index d406a46a313..feab8838528 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/before/a/main.kt @@ -1,6 +1,16 @@ package a class Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/after/b/Test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/after/b/Test.kt index b3cd9c2badc..7fd98cba435 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/after/b/Test.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/after/b/Test.kt @@ -1,6 +1,16 @@ package b class Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/before/a/main.kt index d406a46a313..feab8838528 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackage/before/a/main.kt @@ -1,6 +1,16 @@ package a class Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/after/b/dependency.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/after/b/dependency.kt index 499f51466ec..44395ab96eb 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/after/b/dependency.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/after/b/dependency.kt @@ -6,11 +6,23 @@ open class Foo { } } -fun test { +fun test() { val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() val aBar: a.Foo.Bar = a.Foo.Bar() val bBar: Foo.Bar = Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/before/a/main.kt index 867d2f3d996..3d0688f9341 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/before/a/main.kt @@ -1,12 +1,24 @@ package a -fun test { +fun test() { val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() val aBar: Foo.Bar = Foo.Bar() val bBar: b.Foo.Bar = b.Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } class Test { diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/after/b/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/after/b/test.kt index 673a8fc2f38..fc26e3c9a95 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/after/b/test.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/after/b/test.kt @@ -1,10 +1,22 @@ package b -fun test { +fun test() { val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() val aBar: a.Foo.Bar = a.Foo.Bar() val bBar: Foo.Bar = Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/before/a/main.kt index 867d2f3d996..3d0688f9341 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackage/before/a/main.kt @@ -1,12 +1,24 @@ package a -fun test { +fun test() { val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() val aBar: Foo.Bar = Foo.Bar() val bBar: b.Foo.Bar = b.Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } class Test { diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/after/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/after/a/main.kt index b7df9ace7e1..8564564226f 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/after/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/after/a/main.kt @@ -1,5 +1,5 @@ package a -private fun test { +private fun test() { foo(Foo()) } diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/before/a/main.kt index ba30a0c8f50..fc38ceff013 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/before/a/main.kt @@ -1,5 +1,5 @@ package a -private fun test { +private fun test() { foo(Foo()) } diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/after/b/dependency.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/after/b/dependency.kt index 96ce8b09a23..7865947a8c6 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/after/b/dependency.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/after/b/dependency.kt @@ -7,6 +7,16 @@ open class Foo { } object Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/before/a/main.kt index aba81f03b4f..b727429e5b3 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToFile/before/a/main.kt @@ -1,6 +1,16 @@ package a object Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/after/b/Test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/after/b/Test.kt index 439f5e5e9c2..193b14f17a9 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/after/b/Test.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/after/b/Test.kt @@ -1,6 +1,16 @@ package b object Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: a.Foo = a.Foo() val bFoo: Foo = Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/before/a/main.kt index aba81f03b4f..b727429e5b3 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackage/before/a/main.kt @@ -1,6 +1,16 @@ package a object Test { + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + val aFoo: Foo = Foo() val bFoo: b.Foo = b.Foo() val cFoo: c.Foo = c.Foo() diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/after/b/dependency.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/after/b/dependency.kt index 30d8040a4ac..7a7164717f8 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/after/b/dependency.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/after/b/dependency.kt @@ -15,4 +15,16 @@ var test: String val aBar: a.Foo.Bar = a.Foo.Bar() val bBar: Foo.Bar = Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/before/a/main.kt index ab655b8d5a5..3b47d299009 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToFile/before/a/main.kt @@ -9,6 +9,18 @@ var test: String val aBar: Foo.Bar = Foo.Bar() val bBar: b.Foo.Bar = b.Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } class Test { diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/after/b/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/after/b/test.kt index ba3d09436a6..fcefd817737 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/after/b/test.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/after/b/test.kt @@ -9,4 +9,16 @@ var test: String val aBar: a.Foo.Bar = a.Foo.Bar() val bBar: Foo.Bar = Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/before/a/main.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/before/a/main.kt index ab655b8d5a5..3b47d299009 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/before/a/main.kt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackage/before/a/main.kt @@ -9,6 +9,18 @@ var test: String val aBar: Foo.Bar = Foo.Bar() val bBar: b.Foo.Bar = b.Foo.Bar() val cBar: c.Foo.Bar = c.Foo.Bar() + + fun foo(u: Int) { + class T(val t: Int) + object O { + val t: Int = 1 + } + + val v = T(u).t + O.t + println(v) + } + + foo(1) } class Test {