Move statement: enable single lambda expression function

#KT-10478 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-07-18 12:27:45 +09:00
committed by Natalia Selezneva
parent 51a9df2902
commit f7ff397a31
6 changed files with 61 additions and 1 deletions
@@ -140,7 +140,17 @@ public class KotlinDeclarationMover extends AbstractKotlinUpDownMover {
private static KtDeclaration getMovableDeclaration(@Nullable PsiElement element) {
if (element == null) return null;
KtDeclaration declaration = PsiTreeUtil.getParentOfType(element, KtDeclaration.class, false);
KtDeclaration declaration = null;
if (element.getNode().getElementType() == KtTokens.LBRACE) {
KtLambdaExpression lambda = PsiTreeUtil.getParentOfType(element, KtLambdaExpression.class, true);
KtFunction function = PsiTreeUtil.getParentOfType(lambda, KtFunction.class, true);
if (function != null && function.getBodyExpression() == lambda) {
declaration = function;
}
}
if (declaration == null) {
declaration = PsiTreeUtil.getParentOfType(element, KtDeclaration.class, false);
}
if (declaration instanceof KtParameter) return null;
if (declaration instanceof KtTypeParameter) {
return getMovableDeclaration(declaration.getParent());
@@ -0,0 +1,10 @@
// MOVE: down
fun a() {
}
<caret>fun b() = {
""
}
fun c() {
}
@@ -0,0 +1,10 @@
// MOVE: down
fun a() {
}
fun c() {
}
<caret>fun b() = {
""
}
@@ -0,0 +1,10 @@
// MOVE: up
fun a() {
}
fun c() {
}
<caret>fun b() = {
""
}
@@ -0,0 +1,10 @@
// MOVE: up
fun a() {
}
<caret>fun b() = {
""
}
fun c() {
}
@@ -418,6 +418,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
public void testFunctionAtTheScriptEnd() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtTheScriptEnd.kts");
}
@TestMetadata("singleLambdaExpressionFunction1.kt")
public void testSingleLambdaExpressionFunction1() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt");
}
@TestMetadata("singleLambdaExpressionFunction2.kt")
public void testSingleLambdaExpressionFunction2() throws Exception {
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt");
}
}
@TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors")