Move: Fix "scanEntireFile" values after the refactoring

#KT-17032 Fixed
This commit is contained in:
Alexey Sedunov
2017-03-23 18:19:09 +03:00
parent b818ef0a51
commit d71cefee8a
11 changed files with 76 additions and 56 deletions
@@ -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
)
@@ -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<KtNamedDeclaration, KotlinMemberInfo> {
}
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<KtClassOrObject> 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<KtNamedDeclaration, KotlinMemberInfo> {
}
}
@@ -411,7 +411,7 @@ public class MoveKotlinNestedClassesToUpperLevelDialog extends MoveDialogBase {
delegate,
isSearchInComments(),
isSearchInNonJavaFiles(),
true,
false,
false,
null,
isOpenInEditor()
@@ -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<KtNamedDeclaration, KotlinMemberInfo> {
}
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<KtNamedDeclaration> elementsToMove,
@@ -193,6 +186,40 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
return true;
}
@NotNull
private static List<PsiFile> getFilesExistingInTargetDir(
@NotNull List<KtFile> sourceFiles,
@Nullable String targetFileName,
@Nullable final PsiDirectory targetDirectory
) {
if (targetDirectory == null) return Collections.emptyList();
List<String> fileNames =
targetFileName != null
? Collections.singletonList(targetFileName)
: CollectionsKt.map(
sourceFiles,
new Function1<KtFile, String>() {
@Override
public String invoke(KtFile jetFile) {
return jetFile.getName();
}
}
);
return CollectionsKt.filterNotNull(
CollectionsKt.map(
fileNames,
new Function1<String, PsiFile>() {
@Override
public PsiFile invoke(String s) {
return targetDirectory.findFile(s);
}
}
)
);
}
private void initMemberInfo(
@NotNull final Set<KtNamedDeclaration> elementsToMove,
@NotNull List<KtFile> sourceFiles
@@ -474,40 +501,6 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
return false;
}
@NotNull
private static List<PsiFile> getFilesExistingInTargetDir(
@NotNull List<KtFile> sourceFiles,
@Nullable String targetFileName,
@Nullable final PsiDirectory targetDirectory
) {
if (targetDirectory == null) return Collections.emptyList();
List<String> fileNames =
targetFileName != null
? Collections.singletonList(targetFileName)
: CollectionsKt.map(
sourceFiles,
new Function1<KtFile, String>() {
@Override
public String invoke(KtFile jetFile) {
return jetFile.getName();
}
}
);
return CollectionsKt.filterNotNull(
CollectionsKt.map(
fileNames,
new Function1<String, PsiFile>() {
@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<KtNamedDeclaration, KotlinMemberInfo> {
}
}
@@ -0,0 +1,3 @@
package cr.app
class Mobile
@@ -0,0 +1,5 @@
package cr
class Immobile
val immobileUsage = Immobile()
@@ -0,0 +1,7 @@
package cr
class Immobile
class <caret>Mobile
val immobileUsage = Immobile()
@@ -0,0 +1,5 @@
{
"mainFile": "cr/test.kt",
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
"targetPackage": "cr.app"
}
@@ -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");