Move: Do not use existing file name when moving its top-level declaration(s)
#KT-7697 Fixed
This commit is contained in:
+1
-2
@@ -51,8 +51,7 @@ public class MoveKotlinTopLevelDeclarationsHandler : MoveHandlerDelegate() {
|
||||
for (element in elements) {
|
||||
if (element !is JetNamedDeclaration) continue
|
||||
|
||||
val fileName = element.getFileNameAfterMove()
|
||||
if (fileName != null && !fileNames.add(fileName)) {
|
||||
if (!fileNames.add(element.getFileNameAfterMove())) {
|
||||
val message = RefactoringBundle.getCannotRefactorMessage(
|
||||
RefactoringBundle.message("there.are.going.to.be.multiple.destination.files.with.the.same.name")
|
||||
)
|
||||
|
||||
+2
-2
@@ -241,8 +241,8 @@ public class MoveKotlinTopLevelDeclarationsProcessor(
|
||||
val targetPsi = moveTarget.getOrCreateTargetPsi(declaration)
|
||||
val targetFile =
|
||||
if (targetPsi is PsiDirectory) {
|
||||
val existingFile = if (targetPsi != file!!.getContainingDirectory()) targetPsi.findFile(file.getName()) else null
|
||||
existingFile ?: declaration.getFileNameAfterMove()?.let {createKotlinFile(it, targetPsi)}
|
||||
val targetFileName = declaration.getFileNameAfterMove()
|
||||
targetPsi.findFile(targetFileName) ?: createKotlinFile(targetFileName, targetPsi)
|
||||
}
|
||||
else targetPsi
|
||||
|
||||
|
||||
@@ -156,11 +156,7 @@ fun createMoveUsageInfoIfPossible(
|
||||
return MoveRenameUsageInfo(element, reference, startOffset, endOffset, referencedElement, false)
|
||||
}
|
||||
|
||||
public fun JetNamedDeclaration.getFileNameAfterMove(): String? {
|
||||
return (getContainingFile() as? JetFile)?.let { file ->
|
||||
if (file.getDeclarations().size() > 1) "${getName()}.${JetFileType.EXTENSION}" else file.getName()
|
||||
}
|
||||
}
|
||||
public fun JetNamedDeclaration.getFileNameAfterMove(): String = "${getName()}.${JetFileType.EXTENSION}"
|
||||
|
||||
// returns true if successful
|
||||
private fun updateJavaReference(reference: PsiReferenceExpression, oldElement: PsiElement, newElement: PsiElement): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user