KT-44043 [Sealed interfaces]: quickfix for nested -> to upper level
This commit is contained in:
+6
-5
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui
|
package org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui
|
||||||
|
|
||||||
import com.intellij.BundleBase
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.ui.DialogWrapper
|
import com.intellij.openapi.ui.DialogWrapper
|
||||||
|
import com.intellij.psi.PsiDirectory
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.refactoring.RefactoringBundle
|
import com.intellij.refactoring.RefactoringBundle
|
||||||
import com.intellij.refactoring.util.RadioUpDownListener
|
import com.intellij.refactoring.util.RadioUpDownListener
|
||||||
@@ -99,10 +99,7 @@ internal class KotlinSelectNestedClassRefactoringDialog private constructor(
|
|||||||
fun chooseNestedClassRefactoring(nestedClass: KtClassOrObject, targetContainer: PsiElement?) {
|
fun chooseNestedClassRefactoring(nestedClass: KtClassOrObject, targetContainer: PsiElement?) {
|
||||||
val project = nestedClass.project
|
val project = nestedClass.project
|
||||||
val dialog = when {
|
val dialog = when {
|
||||||
targetContainer != null && targetContainer !is KtClassOrObject ||
|
targetContainer.isUpperLevelFor(nestedClass) -> MoveKotlinNestedClassesToUpperLevelDialog(nestedClass, targetContainer)
|
||||||
nestedClass is KtClass && nestedClass.isInner() -> {
|
|
||||||
MoveKotlinNestedClassesToUpperLevelDialog(nestedClass, targetContainer)
|
|
||||||
}
|
|
||||||
nestedClass is KtEnumEntry -> return
|
nestedClass is KtEnumEntry -> return
|
||||||
else -> {
|
else -> {
|
||||||
val selectionDialog =
|
val selectionDialog =
|
||||||
@@ -118,5 +115,9 @@ internal class KotlinSelectNestedClassRefactoringDialog private constructor(
|
|||||||
}
|
}
|
||||||
dialog?.show()
|
dialog?.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun PsiElement?.isUpperLevelFor(nestedClass: KtClassOrObject) =
|
||||||
|
this != null && this !is KtClassOrObject && this !is PsiDirectory ||
|
||||||
|
nestedClass is KtClass && nestedClass.isInner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
|||||||
import org.jetbrains.kotlin.idea.roots.getSuitableDestinationSourceRoots
|
import org.jetbrains.kotlin.idea.roots.getSuitableDestinationSourceRoots
|
||||||
import org.jetbrains.kotlin.idea.statistics.MoveRefactoringFUSCollector.MovedEntity
|
import org.jetbrains.kotlin.idea.statistics.MoveRefactoringFUSCollector.MovedEntity
|
||||||
import org.jetbrains.kotlin.idea.statistics.MoveRefactoringFUSCollector.MoveRefactoringDestination
|
import org.jetbrains.kotlin.idea.statistics.MoveRefactoringFUSCollector.MoveRefactoringDestination
|
||||||
|
import org.jetbrains.kotlin.idea.util.projectStructure.module
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
@@ -66,8 +67,8 @@ internal abstract class MoveKotlinNestedClassesToUpperLevelModel(
|
|||||||
val targetName = packageName
|
val targetName = packageName
|
||||||
if (oldPackageFqName?.asString() != targetName) {
|
if (oldPackageFqName?.asString() != targetName) {
|
||||||
val projectRootManager = ProjectRootManager.getInstance(project)
|
val projectRootManager = ProjectRootManager.getInstance(project)
|
||||||
|
val contentSourceRoots = target.module?.let { getSuitableDestinationSourceRoots(it) }
|
||||||
val contentSourceRoots = getSuitableDestinationSourceRoots(project)
|
?: getSuitableDestinationSourceRoots(project)
|
||||||
val newPackage = PackageWrapper(PsiManager.getInstance(project), targetName)
|
val newPackage = PackageWrapper(PsiManager.getInstance(project), targetName)
|
||||||
|
|
||||||
val targetSourceRoot: VirtualFile
|
val targetSourceRoot: VirtualFile
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ fun getSuitableDestinationSourceRoots(project: Project): List<VirtualFile> {
|
|||||||
return roots
|
return roots
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSuitableDestinationSourceRoots(module: Module): MutableList<VirtualFile> {
|
||||||
|
val roots = ArrayList<VirtualFile>()
|
||||||
|
collectSuitableDestinationSourceRoots(module, roots)
|
||||||
|
return roots
|
||||||
|
}
|
||||||
|
|
||||||
fun collectSuitableDestinationSourceRoots(module: Module, result: MutableList<VirtualFile>) {
|
fun collectSuitableDestinationSourceRoots(module: Module, result: MutableList<VirtualFile>) {
|
||||||
for (entry in ModuleRootManager.getInstance(module).contentEntries) {
|
for (entry in ModuleRootManager.getInstance(module).contentEntries) {
|
||||||
for (sourceFolder in entry.getSourceFolders(KOTLIN_AWARE_SOURCE_ROOT_TYPES)) {
|
for (sourceFolder in entry.getSourceFolders(KOTLIN_AWARE_SOURCE_ROOT_TYPES)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user