diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinDeclarationMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinDeclarationMover.java index b7e563ba0c9..d9f17f6d070 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinDeclarationMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinDeclarationMover.java @@ -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()); diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt new file mode 100644 index 00000000000..54c75633ca8 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt @@ -0,0 +1,10 @@ +// MOVE: down +fun a() { +} + +fun b() = { + "" +} + +fun c() { +} diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt.after new file mode 100644 index 00000000000..bf2233b90e9 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction1.kt.after @@ -0,0 +1,10 @@ +// MOVE: down +fun a() { +} + +fun c() { +} + +fun b() = { + "" +} diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt new file mode 100644 index 00000000000..19bb1736912 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt @@ -0,0 +1,10 @@ +// MOVE: up +fun a() { +} + +fun c() { +} + +fun b() = { + "" +} diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt.after new file mode 100644 index 00000000000..9ffccac9c65 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/function/singleLambdaExpressionFunction2.kt.after @@ -0,0 +1,10 @@ +// MOVE: up +fun a() { +} + +fun b() = { + "" +} + +fun c() { +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java index 39a57f887b6..185acc908aa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java @@ -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")