#KT-19924: Fix usability issue with extract declaration from file intention
Fix ExtractDeclaration intention name in tests Fix ExtractDeclaration intention folder and description to avoid "not found Dir URL" exception
This commit is contained in:
@@ -1217,7 +1217,7 @@
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention</className>
|
||||
<className>org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention extracts a top-level class or object from current file and places it in a separate one in the same package and directory.
|
||||
</body>
|
||||
</html>
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention moves a top-level class or object to a separate file in the same package and directory.
|
||||
</body>
|
||||
</html>
|
||||
+25
-25
@@ -39,9 +39,9 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
|
||||
class MoveDeclarationToSeparateFileIntention :
|
||||
SelfTargetingRangeIntention<KtClassOrObject>(KtClassOrObject::class.java, "Move declaration to separate file"),
|
||||
LowPriorityAction {
|
||||
class ExtractDeclarationFromCurrentFileIntention :
|
||||
SelfTargetingRangeIntention<KtClassOrObject>(KtClassOrObject::class.java, "Extract declaration from current file"),
|
||||
LowPriorityAction {
|
||||
override fun applicabilityRange(element: KtClassOrObject): TextRange? {
|
||||
if (element.name == null) return null
|
||||
if (element.parent !is KtFile) return null
|
||||
@@ -60,7 +60,7 @@ class MoveDeclarationToSeparateFileIntention :
|
||||
val startOffset = keyword?.startOffset ?: return null
|
||||
val endOffset = element.nameIdentifier?.endOffset ?: return null
|
||||
|
||||
text = "Move '${element.name}' to separate file"
|
||||
text = "Extract '${element.name}' from current file"
|
||||
|
||||
return TextRange(startOffset, endOffset)
|
||||
}
|
||||
@@ -84,15 +84,15 @@ class MoveDeclarationToSeparateFileIntention :
|
||||
// If automatic move is not possible, fall back to full-fledged Move Declarations refactoring
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
MoveKotlinTopLevelDeclarationsDialog(
|
||||
project,
|
||||
setOf(element),
|
||||
packageName.asString(),
|
||||
directory,
|
||||
targetFile as? KtFile,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
null
|
||||
project,
|
||||
setOf(element),
|
||||
packageName.asString(),
|
||||
directory,
|
||||
targetFile as? KtFile,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
null
|
||||
).show()
|
||||
}
|
||||
return
|
||||
@@ -101,18 +101,18 @@ class MoveDeclarationToSeparateFileIntention :
|
||||
createKotlinFile(targetFileName, directory, packageName.asString())
|
||||
}
|
||||
val descriptor = MoveDeclarationsDescriptor(
|
||||
project = project,
|
||||
moveSource = MoveSource(element),
|
||||
moveTarget = moveTarget,
|
||||
delegate = MoveDeclarationsDelegate.TopLevel,
|
||||
searchInCommentsAndStrings = false,
|
||||
searchInNonCode = false,
|
||||
moveCallback = MoveCallback {
|
||||
val newFile = directory.findFile(targetFileName) as KtFile
|
||||
val newDeclaration = newFile.declarations.first()
|
||||
NavigationUtil.activateFileWithPsiElement(newFile)
|
||||
FileEditorManager.getInstance(project).selectedTextEditor?.moveCaret(newDeclaration.startOffset + originalOffset)
|
||||
}
|
||||
project = project,
|
||||
moveSource = MoveSource(element),
|
||||
moveTarget = moveTarget,
|
||||
delegate = MoveDeclarationsDelegate.TopLevel,
|
||||
searchInCommentsAndStrings = false,
|
||||
searchInNonCode = false,
|
||||
moveCallback = MoveCallback {
|
||||
val newFile = directory.findFile(targetFileName) as KtFile
|
||||
val newDeclaration = newFile.declarations.first()
|
||||
NavigationUtil.activateFileWithPsiElement(newFile)
|
||||
FileEditorManager.getInstance(project).selectedTextEditor?.moveCaret(newDeclaration.startOffset + originalOffset)
|
||||
}
|
||||
)
|
||||
|
||||
MoveKotlinDeclarationsProcessor(descriptor).run()
|
||||
@@ -1 +1 @@
|
||||
org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention
|
||||
org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"mainFile": "source/test.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention"
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention"
|
||||
}
|
||||
idea/testData/multiFileIntentions/moveDeclarationToSeparateFile/moveClassToFile/moveClassToFile.test
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"mainFile": "source/test.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention"
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention"
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"mainFile": "test.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention"
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"mainFile": "source/test.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention",
|
||||
"isApplicable": "false"
|
||||
}
|
||||
idea/testData/multiFileIntentions/moveDeclarationToSeparateFile/optimizeImports/optimizeImports.test
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"mainFile": "test.kt",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.MoveDeclarationToSeparateFileIntention",
|
||||
"intentionClass": "org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ExtractDeclarationFromCurrentFileIntention",
|
||||
"isApplicable": "true"
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
// ERROR: Primary constructor is required for inline class
|
||||
// ACTION: Create test
|
||||
// ACTION: Implement members
|
||||
// ACTION: Move 'A' to separate file
|
||||
// ACTION: Extract 'A' from current file
|
||||
// ACTION: Rename file to A.kt
|
||||
interface I {
|
||||
fun foo(): String
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
// ACTION: Create test
|
||||
// ACTION: Make internal
|
||||
// ACTION: Make private
|
||||
// ACTION: Move 'X' to separate file
|
||||
// ACTION: Extract 'X' from current file
|
||||
|
||||
interface D {
|
||||
fun foo()
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
// "Make 'Some' abstract" "false"
|
||||
// ACTION: Create test
|
||||
// ACTION: Implement members
|
||||
// ACTION: Move 'Some' to separate file
|
||||
// ACTION: Extract 'Some' from current file
|
||||
// ACTION: Rename file to Some.kt
|
||||
// ERROR: Object 'Some' is not abstract and does not implement abstract member public abstract fun foo(): Unit defined in T
|
||||
interface T {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
object <caret>Some : T
|
||||
object <caret>Some : T
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Implement members" "false"
|
||||
// ACTION: Create test
|
||||
// ACTION: Make internal
|
||||
// ACTION: Move 'A' to separate file
|
||||
// ACTION: Extract 'A' from current file
|
||||
|
||||
interface I {
|
||||
fun foo()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// ACTION: Make 'A' abstract
|
||||
// ACTION: Make internal
|
||||
// ACTION: Make private
|
||||
// ACTION: Move 'A' to separate file
|
||||
// ACTION: Extract 'A' from current file
|
||||
// ERROR: Class 'A' is not abstract and does not implement abstract member public abstract fun foo(): Int defined in I
|
||||
interface I {
|
||||
fun foo(): Int
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// ACTION: Implement members
|
||||
// ACTION: Make internal
|
||||
// ACTION: Make private
|
||||
// ACTION: Move 'A' to separate file
|
||||
// ACTION: Extract 'A' from current file
|
||||
// ERROR: Object 'A' is not abstract and does not implement abstract member public abstract val foo: Int defined in I
|
||||
interface I {
|
||||
val foo: Int
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Safe delete 'Imported'" "false"
|
||||
// ACTION: Create test
|
||||
// ACTION: Move 'ImportedClass' to separate file
|
||||
// ACTION: Extract 'ImportedClass' from current file
|
||||
// ACTION: Rename file to ImportedClass.kt
|
||||
import ImportedClass as ClassAlias
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// "Safe delete 'Imported'" "false"
|
||||
// ACTION: Create test
|
||||
// ACTION: Move 'Imported' to separate file
|
||||
// ACTION: Extract 'Imported' from current file
|
||||
// ACTION: Rename file to Imported.kt
|
||||
import Imported as Alias
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// ACTION: Create test
|
||||
// ACTION: Make primary constructor internal
|
||||
// ACTION: Make primary constructor private
|
||||
// ACTION: Move 'C' to separate file
|
||||
// ACTION: Extract 'C' from current file
|
||||
// ACTION: Rename file to C.kt
|
||||
|
||||
interface A {
|
||||
|
||||
Reference in New Issue
Block a user