Move: Do not process imported references when moving entire file

#KT-17538 Fixed
This commit is contained in:
Alexey Sedunov
2017-04-21 21:18:35 +03:00
parent eab6c024c2
commit c690761715
10 changed files with 34 additions and 2 deletions
@@ -163,7 +163,10 @@ fun KtElement.processInternalReferencesToUpdateOnPackageNameChange(
} }
.firstOrNull() .firstOrNull()
if (isExtension || containerFqName != null || isImported(descriptor)) return { val isImported = isImported(descriptor)
if (isImported && this is KtFile) return null
if (isExtension || containerFqName != null || isImported) return {
createMoveUsageInfoIfPossible(it.mainReference, declaration, false, true) createMoveUsageInfoIfPossible(it.mainReference, declaration, false, true)
} }
@@ -16,6 +16,6 @@ public fun test(a: A) {
a.bar() a.bar()
a.foo() a.foo()
B().foo().bar() B().foo().bar()
B().foo().bar() library.B().foo().bar()
B().bar().foo() B().bar().foo()
} }
@@ -0,0 +1,3 @@
package one
class ImportedWithAlias
@@ -0,0 +1,6 @@
package three
import one.ImportedWithAlias as WithAlias
val v1 = WithAlias()
val v2 = 2
@@ -0,0 +1,3 @@
package one
class ImportedWithAlias
@@ -0,0 +1,6 @@
package two
import one.ImportedWithAlias as WithAlias
val v1 = WithAlias()
val v2 = 2
@@ -0,0 +1,5 @@
{
"mainFile": "two/Source.kt",
"type": "MOVE_FILES",
"targetPackage": "three"
}
@@ -258,6 +258,12 @@ public class MoveTestGenerated extends AbstractMoveTest {
doTest(fileName); doTest(fileName);
} }
@TestMetadata("kotlin/moveFile/keepImportAliasRefs/keepImportAliasRefs.test")
public void testKotlin_moveFile_keepImportAliasRefs_KeepImportAliasRefs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/keepImportAliasRefs/keepImportAliasRefs.test");
doTest(fileName);
}
@TestMetadata("kotlin/moveFile/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test") @TestMetadata("kotlin/moveFile/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test")
public void testKotlin_moveFile_moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir_MoveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir() throws Exception { public void testKotlin_moveFile_moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir_MoveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test"); String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test");