Copy: Disable CopyKotlinDeclarationsHandler on non-source files

This commit is contained in:
Alexey Sedunov
2017-05-19 14:49:37 +03:00
parent 151b512a6c
commit 75b73ecbcb
12 changed files with 54 additions and 3 deletions
@@ -19,14 +19,12 @@ package org.jetbrains.kotlin.idea.refactoring.copy
import com.intellij.ide.util.EditorHelper import com.intellij.ide.util.EditorHelper
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.ui.Messages import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.Key import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.psi.PsiNamedElement
import com.intellij.refactoring.BaseRefactoringProcessor import com.intellij.refactoring.BaseRefactoringProcessor
import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog import com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog
@@ -74,7 +72,13 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
} }
override fun canCopy(elements: Array<out PsiElement>, fromUpdate: Boolean): Boolean { override fun canCopy(elements: Array<out PsiElement>, fromUpdate: Boolean): Boolean {
return elements.flatMap { it.getElementsToCopy().ifEmpty { return false } }.distinctBy { it.containingFile }.size == 1 val containingFile =
elements
.flatMap { it.getElementsToCopy().ifEmpty { return false } }
.distinctBy { it.containingFile }
.singleOrNull()
?.containingFile ?: return false
return containingFile.sourceRoot != null
} }
enum class ExistingFilePolicy { enum class ExistingFilePolicy {
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,5 @@
package foo
fun test() {
}
@@ -0,0 +1,5 @@
package foo
fun test() {
}
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,5 @@
package foo
fun test() {
}
@@ -0,0 +1,4 @@
{
"mainFile": "A/foo/test.kt",
"targetDirectory": "A/bar"
}
@@ -36,6 +36,12 @@ public class MultiModuleCopyTestGenerated extends AbstractMultiModuleCopyTest {
KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/refactoring/copyMultiModule"), Pattern.compile("^(.+)\\.test$"), TargetBackend.ANY); KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/refactoring/copyMultiModule"), Pattern.compile("^(.+)\\.test$"), TargetBackend.ANY);
} }
@TestMetadata("fileNotUnderSourceRoot/fileNotUnderSourceRoot.test")
public void testFileNotUnderSourceRoot_FileNotUnderSourceRoot() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copyMultiModule/fileNotUnderSourceRoot/fileNotUnderSourceRoot.test");
doTest(fileName);
}
@TestMetadata("internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test") @TestMetadata("internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test")
public void testInternalReferencesToAnotherModule2_InternalReferencesToAnotherModule() throws Exception { public void testInternalReferencesToAnotherModule2_InternalReferencesToAnotherModule() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copyMultiModule/internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test"); String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copyMultiModule/internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test");