Move statement: enable single lambda expression function
#KT-10478 Fixed
This commit is contained in:
committed by
Natalia Selezneva
parent
51a9df2902
commit
f7ff397a31
+11
-1
@@ -140,7 +140,17 @@ public class KotlinDeclarationMover extends AbstractKotlinUpDownMover {
|
|||||||
private static KtDeclaration getMovableDeclaration(@Nullable PsiElement element) {
|
private static KtDeclaration getMovableDeclaration(@Nullable PsiElement element) {
|
||||||
if (element == null) return null;
|
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 KtParameter) return null;
|
||||||
if (declaration instanceof KtTypeParameter) {
|
if (declaration instanceof KtTypeParameter) {
|
||||||
return getMovableDeclaration(declaration.getParent());
|
return getMovableDeclaration(declaration.getParent());
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun a() {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>fun b() = {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun c() {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun a() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun c() {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>fun b() = {
|
||||||
|
""
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun a() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun c() {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>fun b() = {
|
||||||
|
""
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun a() {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>fun b() = {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun c() {
|
||||||
|
}
|
||||||
Generated
+10
@@ -418,6 +418,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
public void testFunctionAtTheScriptEnd() throws Exception {
|
public void testFunctionAtTheScriptEnd() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/functionAtTheScriptEnd.kts");
|
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")
|
@TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors")
|
||||||
|
|||||||
Reference in New Issue
Block a user