Move: Fix top-level declaration detection for scripts
#KT-25858 Fixed
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ class MoveKotlinDeclarationsHandler : MoveHandlerDelegate() {
|
|||||||
return elements.mapNotNullTo(LinkedHashSet(), getContainer).singleOrNull()
|
return elements.mapNotNullTo(LinkedHashSet(), getContainer).singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtNamedDeclaration.canMove() = if (this is KtClassOrObject) !isLocal else parent is KtFile
|
private fun KtNamedDeclaration.canMove() = if (this is KtClassOrObject) !isLocal else isTopLevelInFileOrScript(this)
|
||||||
|
|
||||||
private fun doMoveWithCheck(
|
private fun doMoveWithCheck(
|
||||||
project: Project, elements: Array<out PsiElement>, targetContainer: PsiElement?, callback: MoveCallback?, editor: Editor?
|
project: Project, elements: Array<out PsiElement>, targetContainer: PsiElement?, callback: MoveCallback?, editor: Editor?
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class <caret>Foo
|
||||||
|
fun bar() = 1
|
||||||
|
val baz = 0
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo
|
||||||
|
fun <caret>bar() = 1
|
||||||
|
val baz = 0
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo
|
||||||
|
fun bar() = 1
|
||||||
|
val <caret>baz = 0
|
||||||
+15
@@ -202,4 +202,19 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
val typeAlias = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtTypeAlias>()!!
|
val typeAlias = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtTypeAlias>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(typeAlias), null))
|
assert(handler.canMove(arrayOf<PsiElement>(typeAlias), null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testTopLevelClassInScript() = doTest { rootDir, handler ->
|
||||||
|
val klass = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtClass>()!!
|
||||||
|
assert(handler.canMove(arrayOf<PsiElement>(klass), null))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testTopLevelFunInScript() = doTest { rootDir, handler ->
|
||||||
|
val function = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
|
assert(handler.canMove(arrayOf<PsiElement>(function), null))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testTopLevelValInScript() = doTest { rootDir, handler ->
|
||||||
|
val property = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtProperty>()!!
|
||||||
|
assert(handler.canMove(arrayOf<PsiElement>(property), null))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+10
@@ -203,4 +203,14 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
val typeAlias = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtTypeAlias>()!!
|
val typeAlias = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtTypeAlias>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(typeAlias), null))
|
assert(handler.canMove(arrayOf<PsiElement>(typeAlias), null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testTopLevelFunInScript() = doTest { rootDir, handler ->
|
||||||
|
val function = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
|
assert(handler.canMove(arrayOf<PsiElement>(function), null))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testTopLevelValInScript() = doTest { rootDir, handler ->
|
||||||
|
val property = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtProperty>()!!
|
||||||
|
assert(handler.canMove(arrayOf<PsiElement>(property), null))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user