Fix move tests for bunch 192
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.refactoring.move
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiReference
|
||||||
|
import com.intellij.refactoring.move.MoveHandlerDelegate
|
||||||
|
|
||||||
|
// BUNCH: 191
|
||||||
|
internal fun MoveHandlerDelegate.canMoveCompat(
|
||||||
|
elements: Array<out PsiElement>,
|
||||||
|
targetContainer: PsiElement?,
|
||||||
|
reference: PsiReference?
|
||||||
|
): Boolean = canMove(elements, targetContainer, reference)
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.refactoring.move
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiReference
|
||||||
|
import com.intellij.refactoring.move.MoveHandlerDelegate
|
||||||
|
|
||||||
|
// BUNCH: 191
|
||||||
|
internal fun MoveHandlerDelegate.canMoveCompat(
|
||||||
|
elements: Array<out PsiElement>,
|
||||||
|
targetContainer: PsiElement?,
|
||||||
|
reference: PsiReference?
|
||||||
|
): Boolean = canMove(elements, targetContainer)
|
||||||
+32
-32
@@ -51,90 +51,90 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
|
|
||||||
fun testObjectLiteral() = doTest { rootDir, handler ->
|
fun testObjectLiteral() = doTest { rootDir, handler ->
|
||||||
val objectDeclaration = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtObjectDeclaration>()!!
|
val objectDeclaration = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtObjectDeclaration>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(objectDeclaration), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(objectDeclaration), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testLocalClass() = doTest { rootDir, handler ->
|
fun testLocalClass() = doTest { rootDir, handler ->
|
||||||
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(klass), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(klass), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testLocalFun() = doTest { rootDir, handler ->
|
fun testLocalFun() = doTest { rootDir, handler ->
|
||||||
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(function), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(function), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testLocalVal() = doTest { rootDir, handler ->
|
fun testLocalVal() = doTest { rootDir, handler ->
|
||||||
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(property), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(property), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMemberFun() = doTest { rootDir, handler ->
|
fun testMemberFun() = doTest { rootDir, handler ->
|
||||||
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(function), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(function), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMemberVal() = doTest { rootDir, handler ->
|
fun testMemberVal() = doTest { rootDir, handler ->
|
||||||
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
||||||
assert(!handler.canMove(arrayOf<PsiElement>(property), null))
|
assert(!handler.canMoveCompat(arrayOf<PsiElement>(property), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testNestedClass() = doTest { rootDir, handler ->
|
fun testNestedClass() = doTest { rootDir, handler ->
|
||||||
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(klass), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(klass), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testInnerClass() = doTest { rootDir, handler ->
|
fun testInnerClass() = doTest { rootDir, handler ->
|
||||||
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(klass), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(klass), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelClass() = doTest { rootDir, handler ->
|
fun testTopLevelClass() = doTest { rootDir, handler ->
|
||||||
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
val klass = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(klass), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(klass), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelFun() = doTest { rootDir, handler ->
|
fun testTopLevelFun() = doTest { rootDir, handler ->
|
||||||
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
val function = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(function), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(function), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelVal() = doTest { rootDir, handler ->
|
fun testTopLevelVal() = doTest { rootDir, handler ->
|
||||||
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
val property = getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtProperty>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(property), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(property), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMultipleNestedClasses() = doTest { rootDir, handler ->
|
fun testMultipleNestedClasses() = doTest { rootDir, handler ->
|
||||||
val classes = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtClass>()!! }
|
val classes = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtClass>()!! }
|
||||||
assert(handler.canMove(classes.toTypedArray(), null))
|
assert(handler.canMoveCompat(classes.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testNestedAndTopLevelClass() = doTest { rootDir, handler ->
|
fun testNestedAndTopLevelClass() = doTest { rootDir, handler ->
|
||||||
val classes = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtClass>()!! }
|
val classes = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtClass>()!! }
|
||||||
assert(!handler.canMove(classes.toTypedArray(), null))
|
assert(!handler.canMoveCompat(classes.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMultipleTopLevelDeclarations() = doTest { rootDir, handler ->
|
fun testMultipleTopLevelDeclarations() = doTest { rootDir, handler ->
|
||||||
val declarations = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
val declarations = getElementsAtCarets(rootDir, "test.kt").map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
||||||
assert(handler.canMove(declarations.toTypedArray(), null))
|
assert(handler.canMoveCompat(declarations.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMultipleTopLevelDeclarationsInDifferentFiles() = doTest { rootDir, handler ->
|
fun testMultipleTopLevelDeclarationsInDifferentFiles() = doTest { rootDir, handler ->
|
||||||
val declarations = listOf("test.kt", "test2.kt").flatMap { getElementsAtCarets(rootDir, it) }
|
val declarations = listOf("test.kt", "test2.kt").flatMap { getElementsAtCarets(rootDir, it) }
|
||||||
.map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
.map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
||||||
assert(handler.canMove(declarations.toTypedArray(), null))
|
assert(handler.canMoveCompat(declarations.toTypedArray(), null, null))
|
||||||
|
|
||||||
val files = listOf("test.kt", "test2.kt").map { getPsiFile(rootDir, it) }
|
val files = listOf("test.kt", "test2.kt").map { getPsiFile(rootDir, it) }
|
||||||
assert(handler.canMove(files.toTypedArray(), null))
|
assert(handler.canMoveCompat(files.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMultipleTopLevelDeclarationsInDifferentDirs() = doTest { rootDir, handler ->
|
fun testMultipleTopLevelDeclarationsInDifferentDirs() = doTest { rootDir, handler ->
|
||||||
val declarations = listOf("test1/test.kt", "test2/test2.kt").flatMap { getElementsAtCarets(rootDir, it) }
|
val declarations = listOf("test1/test.kt", "test2/test2.kt").flatMap { getElementsAtCarets(rootDir, it) }
|
||||||
.map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
.map { it.getNonStrictParentOfType<KtNamedDeclaration>()!! }
|
||||||
assert(!handler.canMove(declarations.toTypedArray(), null))
|
assert(!handler.canMoveCompat(declarations.toTypedArray(), null, null))
|
||||||
|
|
||||||
val files = listOf("test1/test.kt", "test2/test2.kt").map { getPsiFile(rootDir, it) }
|
val files = listOf("test1/test.kt", "test2/test2.kt").map { getPsiFile(rootDir, it) }
|
||||||
assert(!handler.canMove(files.toTypedArray(), null))
|
assert(!handler.canMoveCompat(files.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testFileAndTopLevelDeclarations() = doTest { rootDir, handler ->
|
fun testFileAndTopLevelDeclarations() = doTest { rootDir, handler ->
|
||||||
@@ -142,20 +142,20 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
rootDir,
|
rootDir,
|
||||||
"test2.kt"
|
"test2.kt"
|
||||||
)
|
)
|
||||||
assert(!handler.canMove(elements.toTypedArray(), null))
|
assert(!handler.canMoveCompat(elements.toTypedArray(), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testCommonTargets() = doTest { rootDir, handler ->
|
fun testCommonTargets() = doTest { rootDir, handler ->
|
||||||
val elementsToMove = arrayOf<PsiElement>(getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!)
|
val elementsToMove = arrayOf<PsiElement>(getElementAtCaret(rootDir, "test.kt").getNonStrictParentOfType<KtClass>()!!)
|
||||||
|
|
||||||
val targetPackage = JavaPsiFacade.getInstance(project).findPackage("pack")!!
|
val targetPackage = JavaPsiFacade.getInstance(project).findPackage("pack")!!
|
||||||
assert(handler.canMove(elementsToMove, targetPackage))
|
assert(handler.canMoveCompat(elementsToMove, targetPackage, null))
|
||||||
|
|
||||||
val targetDirectory = getPsiDirectory(rootDir, "pack")
|
val targetDirectory = getPsiDirectory(rootDir, "pack")
|
||||||
assert(handler.canMove(elementsToMove, targetDirectory))
|
assert(handler.canMoveCompat(elementsToMove, targetDirectory, null))
|
||||||
|
|
||||||
val targetFile = getPsiFile(rootDir, "pack/test2.kt")
|
val targetFile = getPsiFile(rootDir, "pack/test2.kt")
|
||||||
assert(handler.canMove(elementsToMove, targetFile))
|
assert(handler.canMoveCompat(elementsToMove, targetFile, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelClassToClass() = doTest { rootDir, handler ->
|
fun testTopLevelClassToClass() = doTest { rootDir, handler ->
|
||||||
@@ -164,14 +164,14 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
|
|
||||||
val topLevelTarget = targetFile.declarations.firstIsInstance<KtClass>()
|
val topLevelTarget = targetFile.declarations.firstIsInstance<KtClass>()
|
||||||
assert(topLevelTarget.name == "B")
|
assert(topLevelTarget.name == "B")
|
||||||
assert(!handler.canMove(elementsToMove, topLevelTarget))
|
assert(!handler.canMoveCompat(elementsToMove, topLevelTarget, null))
|
||||||
|
|
||||||
val annotationTarget = targetFile.declarations.first { it.name == "Ann" } as KtClass
|
val annotationTarget = targetFile.declarations.first { it.name == "Ann" } as KtClass
|
||||||
assert(!handler.canMove(elementsToMove, annotationTarget))
|
assert(!handler.canMoveCompat(elementsToMove, annotationTarget, null))
|
||||||
|
|
||||||
val nestedTarget = topLevelTarget.declarations.firstIsInstance<KtClass>()
|
val nestedTarget = topLevelTarget.declarations.firstIsInstance<KtClass>()
|
||||||
assert(nestedTarget.name == "C")
|
assert(nestedTarget.name == "C")
|
||||||
assert(!handler.canMove(elementsToMove, nestedTarget))
|
assert(!handler.canMoveCompat(elementsToMove, nestedTarget, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testNestedClassToClass() = doTest { rootDir, handler ->
|
fun testNestedClassToClass() = doTest { rootDir, handler ->
|
||||||
@@ -180,33 +180,33 @@ class MoveKotlinDeclarationsHandlerTest : KotlinMultiFileTestCase() {
|
|||||||
|
|
||||||
val topLevelTarget = targetFile.declarations.firstIsInstance<KtClass>()
|
val topLevelTarget = targetFile.declarations.firstIsInstance<KtClass>()
|
||||||
assert(topLevelTarget.name == "B")
|
assert(topLevelTarget.name == "B")
|
||||||
assert(handler.canMove(elementsToMove, topLevelTarget))
|
assert(handler.canMoveCompat(elementsToMove, topLevelTarget, null))
|
||||||
|
|
||||||
val annotationTarget = targetFile.declarations.first { it.name == "Ann" } as KtClass
|
val annotationTarget = targetFile.declarations.first { it.name == "Ann" } as KtClass
|
||||||
assert(!handler.canMove(elementsToMove, annotationTarget))
|
assert(!handler.canMoveCompat(elementsToMove, annotationTarget, null))
|
||||||
|
|
||||||
val nestedTarget = topLevelTarget.declarations.firstIsInstance<KtClass>()
|
val nestedTarget = topLevelTarget.declarations.firstIsInstance<KtClass>()
|
||||||
assert(nestedTarget.name == "C")
|
assert(nestedTarget.name == "C")
|
||||||
assert(handler.canMove(elementsToMove, nestedTarget))
|
assert(handler.canMoveCompat(elementsToMove, nestedTarget, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTypeAlias() = doTest { rootDir, handler ->
|
fun testTypeAlias() = doTest { rootDir, handler ->
|
||||||
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.canMoveCompat(arrayOf<PsiElement>(typeAlias), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelClassInScript() = doTest { rootDir, handler ->
|
fun testTopLevelClassInScript() = doTest { rootDir, handler ->
|
||||||
val klass = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtClass>()!!
|
val klass = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtClass>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(klass), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(klass), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelFunInScript() = doTest { rootDir, handler ->
|
fun testTopLevelFunInScript() = doTest { rootDir, handler ->
|
||||||
val function = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtNamedFunction>()!!
|
val function = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtNamedFunction>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(function), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(function), null, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTopLevelValInScript() = doTest { rootDir, handler ->
|
fun testTopLevelValInScript() = doTest { rootDir, handler ->
|
||||||
val property = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtProperty>()!!
|
val property = getElementAtCaret(rootDir, "test.kts").getNonStrictParentOfType<KtProperty>()!!
|
||||||
assert(handler.canMove(arrayOf<PsiElement>(property), null))
|
assert(handler.canMoveCompat(arrayOf<PsiElement>(property), null, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user