diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/KotlinChangePackageRefactoring.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/KotlinChangePackageRefactoring.kt index 7eee99f5f03..9746f07152d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/KotlinChangePackageRefactoring.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/KotlinChangePackageRefactoring.kt @@ -57,7 +57,7 @@ class KotlinChangePackageRefactoring(val file: KtFile) { override fun verify(file: PsiFile) = null }, delegate = MoveDeclarationsDelegate.TopLevel, - scanEntireFile = false + scanEntireFile = true ), Mover.Idle // we don't need to move any declarations physically ) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java index 68fb3f470b3..591a4e80922 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java @@ -57,11 +57,8 @@ import java.util.List; public class MoveKotlinNestedClassesDialog extends RefactoringDialog { private static final String RECENTS_KEY = MoveKotlinNestedClassesDialog.class.getName() + ".RECENTS_KEY"; - - private static class MemberInfoModelImpl extends AbstractMemberInfoModel { - - } - + private final KtClassOrObject originalClass; + private final MoveCallback moveCallback; private JPanel mainPanel; private JTextField originalClassField; private JPanel membersInfoPanel; @@ -69,11 +66,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { private JCheckBox openInEditorCheckBox; private JPanel targetClassChooserPanel; private KotlinMemberSelectionTable memberTable; - - private final KtClassOrObject originalClass; private KtClassOrObject targetClass; - private final MoveCallback moveCallback; - public MoveKotlinNestedClassesDialog( @NotNull Project project, @NotNull List elementsToMove, @@ -242,7 +235,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { KotlinMoveTarget target = new KotlinMoveTargetForExistingElement(targetClass); MoveDeclarationsDelegate.NestedClass delegate = new MoveDeclarationsDelegate.NestedClass(); MoveDeclarationsDescriptor descriptor = new MoveDeclarationsDescriptor( - elementsToMove, target, delegate, false, false, true, false, moveCallback, openInEditorCheckBox.isSelected() + elementsToMove, target, delegate, false, false, false, false, moveCallback, openInEditorCheckBox.isSelected() ); invokeRefactoring(new MoveKotlinDeclarationsProcessor(myProject, descriptor, Mover.Default.INSTANCE)); } @@ -251,4 +244,8 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { public JComponent getPreferredFocusedComponent() { return targetClassChooser.getChildComponent(); } + + private static class MemberInfoModelImpl extends AbstractMemberInfoModel { + + } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesToUpperLevelDialog.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesToUpperLevelDialog.java index 1ef86527491..e5a9922a5ae 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesToUpperLevelDialog.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesToUpperLevelDialog.java @@ -411,7 +411,7 @@ public class MoveKotlinNestedClassesToUpperLevelDialog extends MoveDialogBase { delegate, isSearchInComments(), isSearchInNonJavaFiles(), - true, + false, false, null, isOpenInEditor() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinTopLevelDeclarationsDialog.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinTopLevelDeclarationsDialog.java index e47b75a4d5b..5bab1cef190 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinTopLevelDeclarationsDialog.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinTopLevelDeclarationsDialog.java @@ -82,11 +82,8 @@ import java.util.List; public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { private static final String RECENTS_KEY = "MoveKotlinTopLevelDeclarationsDialog.RECENTS_KEY"; - - private static class MemberInfoModelImpl extends AbstractMemberInfoModel { - - } - + private final MoveCallback moveCallback; + private final PsiDirectory initialTargetDirectory; private JCheckBox cbSearchInComments; private JCheckBox cbSearchTextOccurrences; private JPanel mainPanel; @@ -101,10 +98,6 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { private JCheckBox cbSpecifyFileNameInPackage; private JCheckBox cbUpdatePackageDirective; private KotlinMemberSelectionTable memberTable; - - private final MoveCallback moveCallback; - private final PsiDirectory initialTargetDirectory; - public MoveKotlinTopLevelDeclarationsDialog( @NotNull Project project, @NotNull Set elementsToMove, @@ -193,6 +186,40 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { return true; } + @NotNull + private static List getFilesExistingInTargetDir( + @NotNull List sourceFiles, + @Nullable String targetFileName, + @Nullable final PsiDirectory targetDirectory + ) { + if (targetDirectory == null) return Collections.emptyList(); + + List fileNames = + targetFileName != null + ? Collections.singletonList(targetFileName) + : CollectionsKt.map( + sourceFiles, + new Function1() { + @Override + public String invoke(KtFile jetFile) { + return jetFile.getName(); + } + } + ); + + return CollectionsKt.filterNotNull( + CollectionsKt.map( + fileNames, + new Function1() { + @Override + public PsiFile invoke(String s) { + return targetDirectory.findFile(s); + } + } + ) + ); + } + private void initMemberInfo( @NotNull final Set elementsToMove, @NotNull List sourceFiles @@ -474,40 +501,6 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { return false; } - @NotNull - private static List getFilesExistingInTargetDir( - @NotNull List sourceFiles, - @Nullable String targetFileName, - @Nullable final PsiDirectory targetDirectory - ) { - if (targetDirectory == null) return Collections.emptyList(); - - List fileNames = - targetFileName != null - ? Collections.singletonList(targetFileName) - : CollectionsKt.map( - sourceFiles, - new Function1() { - @Override - public String invoke(KtFile jetFile) { - return jetFile.getName(); - } - } - ); - - return CollectionsKt.filterNotNull( - CollectionsKt.map( - fileNames, - new Function1() { - @Override - public PsiFile invoke(String s) { - return targetDirectory.findFile(s); - } - } - ) - ); - } - @Nullable private KotlinMoveTarget selectMoveTarget() { String message = verifyBeforeRun(); @@ -775,7 +768,7 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { MoveDeclarationsDelegate.TopLevel.INSTANCE, isSearchInComments(), isSearchInNonJavaFiles(), - true, + false, deleteSourceFile, moveCallback, false @@ -803,4 +796,8 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog { public JComponent getPreferredFocusedComponent() { return classPackageChooser.getChildComponent(); } + + private static class MemberInfoModelImpl extends AbstractMemberInfoModel { + + } } diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/app/Mobile.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/app/Mobile.kt new file mode 100644 index 00000000000..eebb42d5957 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/app/Mobile.kt @@ -0,0 +1,3 @@ +package cr.app + +class Mobile \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/app/dummy.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/app/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/test.kt new file mode 100644 index 00000000000..8505fdbec3c --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/after/cr/test.kt @@ -0,0 +1,5 @@ +package cr + +class Immobile + +val immobileUsage = Immobile() \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/before/cr/app/dummy.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/before/cr/app/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/before/cr/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/before/cr/test.kt new file mode 100644 index 00000000000..79d0c46ad4f --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/before/cr/test.kt @@ -0,0 +1,7 @@ +package cr + +class Immobile + +class Mobile + +val immobileUsage = Immobile() \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/kt17032.test b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/kt17032.test new file mode 100644 index 00000000000..bdb83a8bae2 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/kt17032.test @@ -0,0 +1,5 @@ +{ + "mainFile": "cr/test.kt", + "type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS", + "targetPackage": "cr.app" +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java index 030dee7474e..235d12b68ac 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java @@ -462,6 +462,12 @@ public class MoveTestGenerated extends AbstractMoveTest { doTest(fileName); } + @TestMetadata("kotlin/moveTopLevelDeclarations/misc/kt17032/kt17032.test") + public void testKotlin_moveTopLevelDeclarations_misc_kt17032_Kt17032() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/kt17032/kt17032.test"); + doTest(fileName); + } + @TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveClassFromDefaultPackage/moveClassFromDefaultPackage.test") public void testKotlin_moveTopLevelDeclarations_misc_moveClassFromDefaultPackage_MoveClassFromDefaultPackage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveClassFromDefaultPackage/moveClassFromDefaultPackage.test");