diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index f1b21e49ab0..12dca0fa4a6 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -278,7 +278,7 @@
-
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt
new file mode 100644
index 00000000000..adef942ad8a
--- /dev/null
+++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.kotlin.idea.refactoring.copy
+
+import com.intellij.psi.PsiDirectory
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiFile
+import com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler
+import com.intellij.refactoring.copy.CopyHandlerDelegateBase
+import org.jetbrains.kotlin.psi.JetClassOrObject
+import org.jetbrains.kotlin.psi.JetFile
+
+public class CopyKotlinFileHandler : CopyHandlerDelegateBase() {
+ private val delegate = CopyFilesOrDirectoriesHandler()
+
+ private fun adjustElements(elements: Array): Array? {
+ val adjustedElements = elements
+ .map {
+ val file = it.getContainingFile()
+ when {
+ it is JetFile -> it
+ it is JetClassOrObject && it.isTopLevel() && (file as JetFile).getDeclarations().size() == 1 -> file
+ else -> return null
+ }
+ }
+ .toTypedArray()
+ return adjustedElements
+ }
+
+ override fun canCopy(elements: Array, fromUpdate: Boolean): Boolean {
+ return delegate.canCopy(adjustElements(elements) ?: return false, fromUpdate)
+ }
+
+ override fun doCopy(elements: Array, defaultTargetDirectory: PsiDirectory?) {
+ return delegate.doCopy(adjustElements(elements) ?: return, defaultTargetDirectory)
+ }
+
+ override fun doClone(element: PsiElement?) = delegate.doClone(element)
+}
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/JetCopyClassHandler.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/JetCopyClassHandler.java
deleted file mode 100644
index 6ad25e3f4b1..00000000000
--- a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/JetCopyClassHandler.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2010-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.kotlin.idea.refactoring.copy;
-
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiElement;
-import com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler;
-import com.intellij.refactoring.copy.CopyHandlerDelegateBase;
-import org.jetbrains.kotlin.idea.refactoring.move.moveFilesOrDirectories.KotlinMoveFilesOrDirectoriesHandler;
-import org.jetbrains.kotlin.psi.JetClassOrObject;
-
-import java.util.ArrayList;
-
-public class JetCopyClassHandler extends CopyHandlerDelegateBase {
- private CopyFilesOrDirectoriesHandler delegate = new CopyFilesOrDirectoriesHandler();
-
- private static PsiElement[] replaceElements(PsiElement[] elements) {
- ArrayList result = new ArrayList();
- for (PsiElement element : elements) {
- result.add(replaceElement(element));
- }
- return result.toArray(new PsiElement[result.size()]);
- }
-
- private static PsiElement replaceElement(PsiElement element) {
- if (element instanceof JetClassOrObject &&
- KotlinMoveFilesOrDirectoriesHandler.Companion.isMovableClass((JetClassOrObject) element)) {
- return element.getContainingFile();
- }
- else {
- return element;
- }
- }
-
-
- @Override
- public boolean canCopy(PsiElement[] elements, boolean fromUpdate) {
- return delegate.canCopy(replaceElements(elements), fromUpdate);
- }
-
- @Override
- public void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) {
- delegate.doCopy(replaceElements(elements), defaultTargetDirectory);
- }
-
- @Override
- public void doClone(PsiElement element) {
- delegate.doClone(replaceElement(element));
- }
-}
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveFilesOrDirectories/KotlinMoveFilesOrDirectoriesHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveFilesOrDirectories/KotlinMoveFilesOrDirectoriesHandler.kt
index ff71c6fd4ea..2910fce4cc1 100644
--- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveFilesOrDirectories/KotlinMoveFilesOrDirectoriesHandler.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveFilesOrDirectories/KotlinMoveFilesOrDirectoriesHandler.kt
@@ -50,10 +50,4 @@ public class KotlinMoveFilesOrDirectoriesHandler : MoveFilesOrDirectoriesHandler
callback?.refactoringCompleted()
}
}
-
- companion object {
- public fun isMovableClass(clazz: JetClassOrObject): Boolean {
- return clazz.isTopLevel() && clazz.getContainingJetFile().getDeclarations().all { it !is JetClassOrObject || it == clazz }
- }
- }
}