diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 9fe69ed6b9c..6bd87f1c224 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -410,10 +410,6 @@
id="kotlinClass"
implementation="org.jetbrains.kotlin.idea.refactoring.copy.CopyKotlinDeclarationsHandler"
order="first" />
-
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinDeclarationsHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinDeclarationsHandler.kt
index 3f3860af8f7..b815ca953b7 100644
--- a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinDeclarationsHandler.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinDeclarationsHandler.kt
@@ -25,11 +25,13 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiFileSystemItem
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.refactoring.BaseRefactoringProcessor
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog
+import com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler
import com.intellij.refactoring.copy.CopyHandlerDelegateBase
import com.intellij.refactoring.util.MoveRenameUsageInfo
import com.intellij.usageView.UsageInfo
@@ -71,7 +73,20 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
}
}
- override fun canCopy(elements: Array, fromUpdate: Boolean): Boolean {
+ private val copyFilesHandler by lazy { CopyFilesOrDirectoriesHandler() }
+
+ private fun getSourceFiles(elements: Array): Array? {
+ return elements
+ .map { it.containingFile ?: it as? PsiFileSystemItem ?: return null }
+ .toTypedArray()
+ }
+
+ private fun canCopyFiles(elements: Array, fromUpdate: Boolean): Boolean {
+ val sourceFiles = getSourceFiles(elements) ?: return false
+ return copyFilesHandler.canCopy(sourceFiles, fromUpdate)
+ }
+
+ private fun canCopyDeclarations(elements: Array): Boolean {
val containingFile =
elements
.flatMap { it.getElementsToCopy().ifEmpty { return false } }
@@ -81,6 +96,10 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
return containingFile.sourceRoot != null
}
+ override fun canCopy(elements: Array, fromUpdate: Boolean): Boolean {
+ return canCopyDeclarations(elements) || canCopyFiles(elements, fromUpdate)
+ }
+
enum class ExistingFilePolicy {
APPEND, OVERWRITE, SKIP
}
@@ -149,6 +168,11 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
}
override fun doCopy(elements: Array, defaultTargetDirectory: PsiDirectory?) {
+ if (!canCopyDeclarations(elements)) {
+ val sourceFiles = getSourceFiles(elements) ?: return
+ return copyFilesHandler.doCopy(sourceFiles, defaultTargetDirectory)
+ }
+
val elementsToCopy = elements.flatMap { it.getElementsToCopy() }
if (elementsToCopy.isEmpty()) return
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt
deleted file mode 100644
index 6031f8a9c54..00000000000
--- a/idea/src/org/jetbrains/kotlin/idea/refactoring/copy/CopyKotlinFileHandler.kt
+++ /dev/null
@@ -1,44 +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.psi.KtFile
-
-class CopyKotlinFileHandler : CopyHandlerDelegateBase() {
- private val delegate = CopyFilesOrDirectoriesHandler()
-
- private fun adjustElements(elements: Array): Array? {
- return elements
- .map { (if (it.isValid) it.containingFile as? KtFile else null) ?: return null }
- .toTypedArray()
- }
-
- 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)
-}
-