CopyKotlinDeclarationsHandler: fix for package with backticks
#KT-38543 Fixed
This commit is contained in:
+7
-4
@@ -24,11 +24,12 @@ import com.intellij.usageView.UsageInfo
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.performDelayedRefactoringRequests
|
||||
import org.jetbrains.kotlin.idea.core.getFqNameWithImplicitPrefix
|
||||
import org.jetbrains.kotlin.idea.core.packageMatchesDirectoryOrImplicit
|
||||
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.idea.core.util.toPsiDirectory
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.refactoring.checkConflictsInteractively
|
||||
import org.jetbrains.kotlin.idea.refactoring.createKotlinFile
|
||||
import org.jetbrains.kotlin.idea.refactoring.move.*
|
||||
@@ -126,7 +127,8 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
|
||||
targetFileName: String,
|
||||
targetDirectory: PsiDirectory
|
||||
): ExistingFilePolicy {
|
||||
val message = KotlinBundle.message("text.file.0.already.exists.in.1",
|
||||
val message = KotlinBundle.message(
|
||||
"text.file.0.already.exists.in.1",
|
||||
targetFileName,
|
||||
targetDirectory.virtualFile.path
|
||||
)
|
||||
@@ -291,7 +293,7 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
|
||||
if (targetKtFile !== null) {
|
||||
runWriteAction {
|
||||
if (!targetKtFile.packageMatchesDirectoryOrImplicit()) {
|
||||
targetKtFile.containingDirectory?.getFqNameWithImplicitPrefix()?.let { targetDirectoryFqName ->
|
||||
targetKtFile.containingDirectory?.getFqNameWithImplicitPrefix()?.quoteIfNeeded()?.let { targetDirectoryFqName ->
|
||||
targetKtFile.packageFqName = targetDirectoryFqName
|
||||
}
|
||||
}
|
||||
@@ -419,8 +421,9 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
|
||||
val targetDirectoryFqName = targetDirectory.getFqNameWithImplicitPrefix()
|
||||
val copiedFile = targetDirectory.copyFileFrom(targetFileName, fileToCopy)
|
||||
if (copiedFile is KtFile && fileToCopy.packageMatchesDirectoryOrImplicit()) {
|
||||
targetDirectoryFqName?.let { copiedFile.packageFqName = it }
|
||||
targetDirectoryFqName?.quoteIfNeeded()?.let { copiedFile.packageFqName = it }
|
||||
}
|
||||
|
||||
performDelayedRefactoringRequests(sourceData.project)
|
||||
copiedFile
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package root.`20-20`
|
||||
|
||||
class Foo
|
||||
@@ -0,0 +1,3 @@
|
||||
package root.`20-20`
|
||||
|
||||
class Root
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
class Foo
|
||||
@@ -0,0 +1,3 @@
|
||||
package root.`20-20`
|
||||
|
||||
class Root
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
class Foo
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"mainFile": "foo/Foo.kt",
|
||||
"targetPackage": ""
|
||||
}
|
||||
@@ -83,6 +83,11 @@ public class CopyTestGenerated extends AbstractCopyTest {
|
||||
runTest("idea/testData/refactoring/copy/copyFIleToDefaultPackage/copyFIleToDefaultPackage.test");
|
||||
}
|
||||
|
||||
@TestMetadata("copyFileToRoot/copyFileToRoot.test")
|
||||
public void testCopyFileToRoot_CopyFileToRoot() throws Exception {
|
||||
runTest("idea/testData/refactoring/copy/copyFileToRoot/copyFileToRoot.test");
|
||||
}
|
||||
|
||||
@TestMetadata("copyFIleWithPackageAndDirUnmatched/copyFIleWithPackageAndDirUnmatched.test")
|
||||
public void testCopyFIleWithPackageAndDirUnmatched_CopyFIleWithPackageAndDirUnmatched() throws Exception {
|
||||
runTest("idea/testData/refactoring/copy/copyFIleWithPackageAndDirUnmatched/copyFIleWithPackageAndDirUnmatched.test");
|
||||
|
||||
Reference in New Issue
Block a user