Move to top level: update import directives on the usage site when the declaration to be moved is not private
#KT-37213 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
b06a3ea5ac
commit
77f85d8b7c
@@ -25,8 +25,10 @@ import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isPrivate
|
||||
|
||||
abstract class MoveMemberOutOfObjectIntention(text: String) :
|
||||
SelfTargetingRangeIntention<KtNamedDeclaration>(KtNamedDeclaration::class.java, text) {
|
||||
@@ -48,22 +50,29 @@ abstract class MoveMemberOutOfObjectIntention(text: String) :
|
||||
}
|
||||
}
|
||||
|
||||
if (element is KtClassOrObject) {
|
||||
if (element is KtClassOrObject || !element.isPrivate() && destination is KtFile) {
|
||||
val moveDescriptor = MoveDeclarationsDescriptor(
|
||||
project,
|
||||
MoveSource(element),
|
||||
KotlinMoveTargetForExistingElement(destination),
|
||||
MoveDeclarationsDelegate.NestedClass()
|
||||
)
|
||||
object : CompositeRefactoringRunner(project, MoveKotlinDeclarationsProcessor.REFACTORING_ID) {
|
||||
val compositeRefactoringRunner = object : CompositeRefactoringRunner(project, MoveKotlinDeclarationsProcessor.REFACTORING_ID) {
|
||||
override fun runRefactoring() = MoveKotlinDeclarationsProcessor(moveDescriptor).run()
|
||||
override fun onRefactoringDone() = runWriteAction { deleteClassOrObjectIfEmpty() }
|
||||
}.run()
|
||||
override fun onExit() = runWriteAction { deleteClassOrObjectIfEmpty() }
|
||||
}
|
||||
if (element is KtClassOrObject) {
|
||||
compositeRefactoringRunner.run()
|
||||
} else {
|
||||
val conflicts = MultiMap<PsiElement, String>().apply { addConflicts(element, this) }
|
||||
project.checkConflictsInteractively(conflicts) {
|
||||
compositeRefactoringRunner.run()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val conflicts = MultiMap<PsiElement, String>().apply { addConflicts(element, this) }
|
||||
|
||||
project.checkConflictsInteractively(conflicts) {
|
||||
runWriteAction {
|
||||
Mover.Default(element, destination)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package a
|
||||
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,7 @@
|
||||
package b
|
||||
|
||||
import a.foo
|
||||
|
||||
fun main() {
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package a
|
||||
|
||||
object A {
|
||||
fun <caret>foo() {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package b
|
||||
|
||||
import a.A
|
||||
|
||||
fun main() {
|
||||
A.foo()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"mainFile": "a/A.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.intentions.MoveMemberToTopLevelIntention",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+5
@@ -108,6 +108,11 @@ public class MultiFileIntentionTestGenerated extends AbstractMultiFileIntentionT
|
||||
runTest("idea/testData/multiFileIntentions/moveDeclarationToSeparateFile/optimizeImports/optimizeImports.test");
|
||||
}
|
||||
|
||||
@TestMetadata("moveMemberToTopLevel/function/function.test")
|
||||
public void testMoveMemberToTopLevel_function_Function() throws Exception {
|
||||
runTest("idea/testData/multiFileIntentions/moveMemberToTopLevel/function/function.test");
|
||||
}
|
||||
|
||||
@TestMetadata("moveOutOfCompanion/moveClass/moveClass.test")
|
||||
public void testMoveOutOfCompanion_moveClass_MoveClass() throws Exception {
|
||||
runTest("idea/testData/multiFileIntentions/moveOutOfCompanion/moveClass/moveClass.test");
|
||||
|
||||
Reference in New Issue
Block a user