From eab6c024c2b753541fb68fba977bdde5ff2a35c0 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 20 Apr 2017 18:18:27 +0300 Subject: [PATCH] Move: Warn about moving to non-Kotlin class #KT-17472 Fixed --- .../ui/MoveKotlinNestedClassesDialog.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 00c36e4c8ec..3f46a8e748a 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 @@ -70,7 +70,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { private JCheckBox openInEditorCheckBox; private JPanel targetClassChooserPanel; private KotlinMemberSelectionTable memberTable; - private KtClassOrObject targetClass; + private PsiElement targetClass; public MoveKotlinNestedClassesDialog( @NotNull Project project, @NotNull List elementsToMove, @@ -149,6 +149,9 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { targetClass = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin(); targetClassChooser.setText(aClass.getQualifiedName()); } + else { + targetClass = aClass; + } } }, initialTargetClass.getFqName().asString(), @@ -179,7 +182,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { .findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject)); targetClass = aClass instanceof KtLightClassForSourceDeclaration ? ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin() - : null; + : aClass; validateButtons(); } } @@ -240,6 +243,8 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { protected void canRun() throws ConfigurationException { if (targetClass == null) throw new ConfigurationException("No destination class specified"); + if (!(targetClass instanceof KtClassOrObject)) throw new ConfigurationException("Destination class must be a Kotlin class"); + if (originalClass == targetClass) { throw new ConfigurationException(RefactoringBundle.message("source.and.destination.classes.should.be.different")); } @@ -254,7 +259,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog { @Override protected void doAction() { List elementsToMove = getSelectedElementsToMove(); - KotlinMoveTarget target = new KotlinMoveTargetForExistingElement(targetClass); + KotlinMoveTarget target = new KotlinMoveTargetForExistingElement((KtClassOrObject) targetClass); MoveDeclarationsDelegate.NestedClass delegate = new MoveDeclarationsDelegate.NestedClass(); MoveDeclarationsDescriptor descriptor = new MoveDeclarationsDescriptor( myProject, elementsToMove, target, delegate, false, false, false, false, moveCallback, openInEditorCheckBox.isSelected()