Move statement: do not move into lambda beyond 'if/when/try/for/while'
#KT-9065 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
ee5ecb232a
commit
19824201e2
@@ -282,6 +282,15 @@ class KotlinExpressionMover : AbstractKotlinUpDownMover() {
|
|||||||
element: PsiElement,
|
element: PsiElement,
|
||||||
down: Boolean
|
down: Boolean
|
||||||
): KtBlockExpression? {
|
): KtBlockExpression? {
|
||||||
|
if (element is KtIfExpression ||
|
||||||
|
element is KtWhenExpression ||
|
||||||
|
element is KtWhenEntry ||
|
||||||
|
element is KtTryExpression ||
|
||||||
|
element is KtFinallySection ||
|
||||||
|
element is KtCatchClause ||
|
||||||
|
element is KtLoopExpression
|
||||||
|
) return null
|
||||||
|
|
||||||
val callExpression =
|
val callExpression =
|
||||||
KtPsiUtil.getOutermostDescendantElement(element, down, IS_CALL_EXPRESSION) as KtCallExpression? ?: return null
|
KtPsiUtil.getOutermostDescendantElement(element, down, IS_CALL_EXPRESSION) as KtCallExpression? ?: return null
|
||||||
val functionLiterals = callExpression.lambdaArguments
|
val functionLiterals = callExpression.lambdaArguments
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
<caret>println()
|
||||||
|
do {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
} while (i == 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
do {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
} while (i == 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
do {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
} while (i == 1)
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
do {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
} while (i == 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test() {
|
||||||
|
<caret>println()
|
||||||
|
for (i in 1..10) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test() {
|
||||||
|
for (i in 1..10) {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
for (i in 1..10) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
for (i in 1..10) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
<caret>println()
|
||||||
|
if (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
if (i == 1) {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
if (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
if (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test() {
|
||||||
|
<caret>println()
|
||||||
|
try {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test() {
|
||||||
|
try {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
try {
|
||||||
|
} finally {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
try {
|
||||||
|
} finally {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
try {
|
||||||
|
} catch (e: Exception) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test() {
|
||||||
|
try {
|
||||||
|
} catch (e: Exception) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
<caret>println()
|
||||||
|
when (i) {
|
||||||
|
1 -> {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
when (i) {
|
||||||
|
1 -> {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
when (i) {
|
||||||
|
1 -> {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
when (i) {
|
||||||
|
1 -> {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
<caret>println()
|
||||||
|
while (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(i: Int) {
|
||||||
|
while (i == 1) {
|
||||||
|
<caret>println()
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
while (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(i: Int) {
|
||||||
|
while (i == 1) {
|
||||||
|
run {
|
||||||
|
}
|
||||||
|
<caret>println()
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+65
@@ -1063,6 +1063,71 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambda3.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambda3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInDoWhile.kt")
|
||||||
|
public void testLambdaInDoWhile() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInDoWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInDoWhile2.kt")
|
||||||
|
public void testLambdaInDoWhile2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInDoWhile2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInFor.kt")
|
||||||
|
public void testLambdaInFor() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInFor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInFor2.kt")
|
||||||
|
public void testLambdaInFor2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInFor2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInIf.kt")
|
||||||
|
public void testLambdaInIf() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInIf.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInIf2.kt")
|
||||||
|
public void testLambdaInIf2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInIf2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInTry.kt")
|
||||||
|
public void testLambdaInTry() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInTry.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInTry2.kt")
|
||||||
|
public void testLambdaInTry2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInTry2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInTry3.kt")
|
||||||
|
public void testLambdaInTry3() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInTry3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInWhen.kt")
|
||||||
|
public void testLambdaInWhen() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInWhen.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInWhen2.kt")
|
||||||
|
public void testLambdaInWhen2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInWhen2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInWhile.kt")
|
||||||
|
public void testLambdaInWhile() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lambdaInWhile2.kt")
|
||||||
|
public void testLambdaInWhile2() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInWhile2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multilineComment1.kt")
|
@TestMetadata("multilineComment1.kt")
|
||||||
public void testMultilineComment1() throws Exception {
|
public void testMultilineComment1() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/expressions/multilineComment1.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/multilineComment1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user