Move: Forbind moving to non-Kotlin file
#KT-8500 Fixed
This commit is contained in:
+11
-2
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.JavaProjectRootsUtil;
|
||||
@@ -30,6 +31,7 @@ import com.intellij.openapi.ui.TextComponentAccessor;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.*;
|
||||
import com.intellij.refactoring.classMembers.DependencyMemberInfoModel;
|
||||
@@ -55,6 +57,7 @@ import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.idea.core.CorePackage;
|
||||
import org.jetbrains.kotlin.idea.core.refactoring.RefactoringPackage;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
||||
@@ -72,8 +75,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -355,6 +356,12 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
||||
return ((DestinationFolderComboBox) destinationFolderCB).selectDirectory(targetPackage, false);
|
||||
}
|
||||
|
||||
private boolean checkTargetFileName(String fileName) {
|
||||
if (FileTypeManager.getInstance().getFileTypeByFileName(fileName) == JetFileType.INSTANCE) return true;
|
||||
setErrorText("Can't move to non-Kotlin file");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private KotlinMoveTarget selectMoveTarget() {
|
||||
String message = verifyBeforeRun();
|
||||
@@ -370,6 +377,7 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
||||
if (moveDestination == null) return null;
|
||||
|
||||
final String targetFileName = tfFileNameInPackage.getText();
|
||||
if (!checkTargetFileName(targetFileName)) return null;
|
||||
|
||||
PsiDirectory directory = moveDestination.getTargetIfExists(sourceFile);
|
||||
PsiFile targetFile = directory != null ? directory.findFile(targetFileName) : null;
|
||||
@@ -403,6 +411,7 @@ public class MoveKotlinTopLevelDeclarationsDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
final File targetFile = new File(getTargetFilePath());
|
||||
if (!checkTargetFileName(targetFile.getName())) return null;
|
||||
JetFile jetFile = (JetFile) RefactoringPackage.toPsiFile(targetFile, myProject);
|
||||
if (jetFile != null) {
|
||||
if (jetFile == sourceFile) {
|
||||
|
||||
Reference in New Issue
Block a user