Move statement: don't move declarations above package and import directives

This commit is contained in:
Toshiaki Kameyama
2019-07-18 13:15:10 +09:00
committed by Natalia Selezneva
parent 742c3a228a
commit bfa6c7d399
6 changed files with 41 additions and 2 deletions
@@ -292,8 +292,7 @@ public class KotlinDeclarationMover extends AbstractKotlinUpDownMover {
PsiElement sibling = getLastNonWhiteSiblingInLine(firstNonWhiteSibling(sourceRange, down), editor, down);
// Either reached last sibling, or jumped over multi-line whitespace
if (sibling == null) {
if (sibling == null || sibling instanceof KtPackageDirective || sibling instanceof KtImportList) {
info.toMove2 = null;
return true;
}
@@ -0,0 +1,5 @@
// MOVE: up
// IS_APPLICABLE: false
import foo.Bar
<caret>class A
@@ -0,0 +1,5 @@
// MOVE: up
// IS_APPLICABLE: false
import foo.Bar
<caret>class A
@@ -0,0 +1,5 @@
// MOVE: up
// IS_APPLICABLE: false
package foo.bar
<caret>class A
@@ -0,0 +1,5 @@
// MOVE: up
// IS_APPLICABLE: false
package foo.bar
<caret>class A
@@ -145,6 +145,26 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtFunction2.kt");
}
@TestMetadata("classAtImport.kt")
public void testClassAtImport() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtImport.kt");
}
@TestMetadata("classAtImportInScript.kts")
public void testClassAtImportInScript() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtImportInScript.kts");
}
@TestMetadata("classAtPackage.kt")
public void testClassAtPackage() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtPackage.kt");
}
@TestMetadata("classAtPackageInScript.kts")
public void testClassAtPackageInScript() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtPackageInScript.kts");
}
@TestMetadata("classAtProperty1.kt")
public void testClassAtProperty1() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtProperty1.kt");