Allow moving out to arbitrary blocks and moving any declaration into class body

This commit is contained in:
Alexey Sedunov
2013-05-30 17:29:53 +04:00
parent b00ec82884
commit 57edbdfbc4
15 changed files with 55 additions and 16 deletions
@@ -809,6 +809,12 @@ public class JetPsiUtil {
return first ? results.get(0) : results.get(results.size() - 1); 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 @Nullable
public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) { public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) {
if (expression instanceof JetCallElement) { if (expression instanceof JetCallElement) {
@@ -190,9 +190,6 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
nextParent = jetClassOrObject.getParent(); nextParent = jetClassOrObject.getParent();
// elements may be placed only to class body or file
if (!(nextParent instanceof JetFile || nextParent instanceof JetClassBody)) return null;
if (!down) { if (!down) {
start = jetClassOrObject; start = jetClassOrObject;
} }
@@ -203,7 +203,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
else { else {
// moving into code block // moving into code block
//noinspection unchecked //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 && if (blockLikeElement != null &&
!(PsiTreeUtil.instanceOf(blockLikeElement, FUNCTIONLIKE_ELEMENT_CLASSES))) { !(PsiTreeUtil.instanceOf(blockLikeElement, FUNCTIONLIKE_ELEMENT_CLASSES))) {
if (blockLikeElement instanceof JetWhenExpression) { if (blockLikeElement instanceof JetWhenExpression) {
@@ -212,13 +212,11 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
} }
if (blockLikeElement != null) { if (blockLikeElement != null) {
JetBlockExpression block = (JetBlockExpression) blockLikeElement;
if (down) { if (down) {
end = block.getLBrace(); end = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.LBRACE);
} }
else { else {
start = block.getRBrace(); start = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.RBRACE);
} }
} }
} }
@@ -1,7 +1,6 @@
// MOVE: down // MOVE: down
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class A {
<caret>class B { <caret>class B {
} }
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
class A {
}
<caret>class B {
}
}
@@ -1,7 +1,6 @@
// MOVE: up // MOVE: up
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class A {
<caret>class B { <caret>class B {
} }
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
<caret>class B {
}
class A {
}
}
@@ -1,5 +1,4 @@
// MOVE: down // MOVE: down
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class B {
<caret>fun foo() { <caret>fun foo() {
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
class B {
}
<caret>fun foo() {
}
}
@@ -1,5 +1,4 @@
// MOVE: up // MOVE: up
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class B {
<caret>fun foo() { <caret>fun foo() {
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
<caret>fun foo() {
}
class B {
}
}
@@ -1,5 +1,4 @@
// MOVE: down // MOVE: down
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class B {
<caret>val y = "" <caret>val y = ""
@@ -0,0 +1,6 @@
// MOVE: down
fun foo() {
class B {
}
<caret>val y = ""
}
@@ -1,5 +1,4 @@
// MOVE: up // MOVE: up
// IS_APPLICABLE: false
fun foo() { fun foo() {
class B { class B {
<caret>val y = "" <caret>val y = ""
@@ -0,0 +1,6 @@
// MOVE: up
fun foo() {
<caret>val y = ""
class B {
}
}