diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index d95e66fcf47..7f1f7e3093e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -809,6 +809,12 @@ public class JetPsiUtil { return first ? results.get(0) : results.get(results.size() - 1); } + @Nullable + public static PsiElement findChildByType(@NotNull PsiElement element, @NotNull IElementType type) { + ASTNode node = element.getNode().findChildByType(type); + return node == null ? null : node.getPsi(); + } + @Nullable public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) { if (expression instanceof JetCallElement) { diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java index f720fd312b2..d1ecaedb468 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java @@ -190,9 +190,6 @@ public class JetDeclarationMover extends AbstractJetUpDownMover { nextParent = jetClassOrObject.getParent(); - // elements may be placed only to class body or file - if (!(nextParent instanceof JetFile || nextParent instanceof JetClassBody)) return null; - if (!down) { start = jetClassOrObject; } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java index 419cab627e4..828335213ad 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java @@ -203,7 +203,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover { else { // moving into code block //noinspection unchecked - JetElement blockLikeElement = JetPsiUtil.getOutermostJetElement(sibling, down, JetBlockExpression.class, JetWhenExpression.class); + JetElement blockLikeElement = JetPsiUtil.getOutermostJetElement(sibling, down, JetBlockExpression.class, JetWhenExpression.class, JetClassBody.class); if (blockLikeElement != null && !(PsiTreeUtil.instanceOf(blockLikeElement, FUNCTIONLIKE_ELEMENT_CLASSES))) { if (blockLikeElement instanceof JetWhenExpression) { @@ -212,13 +212,11 @@ public class JetExpressionMover extends AbstractJetUpDownMover { } if (blockLikeElement != null) { - JetBlockExpression block = (JetBlockExpression) blockLikeElement; - if (down) { - end = block.getLBrace(); + end = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.LBRACE); } else { - start = block.getRBrace(); + start = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.RBRACE); } } } diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt index 5511821cbc4..b2b6b8f865a 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt @@ -1,7 +1,6 @@ // MOVE: down -// IS_APPLICABLE: false fun foo() { - class B { + class A { class B { } diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt.after new file mode 100644 index 00000000000..c52276366e7 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace5.kt.after @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + class A { + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt index 711e905df5e..aa4e230f674 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt @@ -1,7 +1,6 @@ // MOVE: up -// IS_APPLICABLE: false fun foo() { - class B { + class A { class B { } diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt.after new file mode 100644 index 00000000000..831f7025b08 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtBrace6.kt.after @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + class B { + + } + class A { + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt index 977102561eb..fcd181dca97 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt @@ -1,5 +1,4 @@ // MOVE: down -// IS_APPLICABLE: false fun foo() { class B { fun foo() { diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt.after new file mode 100644 index 00000000000..794f2076261 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace5.kt.after @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + class B { + } + fun foo() { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt index d3a54cf6fc1..42314a50cc1 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt @@ -1,5 +1,4 @@ // MOVE: up -// IS_APPLICABLE: false fun foo() { class B { fun foo() { diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt.after new file mode 100644 index 00000000000..1a3e7adb4c5 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtBrace6.kt.after @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + fun foo() { + + } + class B { + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt index 97ca96de10c..e2dfb807f51 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt @@ -1,5 +1,4 @@ // MOVE: down -// IS_APPLICABLE: false fun foo() { class B { val y = "" diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt.after new file mode 100644 index 00000000000..8df651be8f5 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace5.kt.after @@ -0,0 +1,6 @@ +// MOVE: down +fun foo() { + class B { + } + val y = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt index bfe83368b6b..ab18d34ca64 100644 --- a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt @@ -1,5 +1,4 @@ // MOVE: up -// IS_APPLICABLE: false fun foo() { class B { val y = "" diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt.after new file mode 100644 index 00000000000..12853c9e00e --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property/propertyAtBrace6.kt.after @@ -0,0 +1,6 @@ +// MOVE: up +fun foo() { + val y = "" + class B { + } +} \ No newline at end of file