From 127b7c80dfe6ebf092b8d20485941531538b14c6 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 16 Mar 2017 16:30:21 +0300 Subject: [PATCH] Some inline tests that do not work --- .../inline/function/LocalCapturing.kt | 12 +++++++ .../inline/function/LocalSimple.kt | 10 ++++++ ...ReturnType2.kt.todo => UnitReturnType2.kt} | 0 .../inline/function/UnitReturnType2.kt.after | 3 +- .../expressionBody/MultipleInExpression.kt | 7 ++++ .../MultipleInExpression.kt.after | 8 +++++ .../function/returnAtEnd/PrivateMember.kt | 12 +++++++ .../function/returnAtEnd/PublicMember.kt | 11 ++++++ .../returnAtEnd/PublicMember.kt.after | 9 +++++ .../inline/InlineTestGenerated.java | 36 +++++++++++++++++++ 10 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 idea/testData/refactoring/inline/function/LocalCapturing.kt create mode 100644 idea/testData/refactoring/inline/function/LocalSimple.kt rename idea/testData/refactoring/inline/function/{UnitReturnType2.kt.todo => UnitReturnType2.kt} (100%) create mode 100644 idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt create mode 100644 idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt.after create mode 100644 idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt create mode 100644 idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt create mode 100644 idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt.after diff --git a/idea/testData/refactoring/inline/function/LocalCapturing.kt b/idea/testData/refactoring/inline/function/LocalCapturing.kt new file mode 100644 index 00000000000..093ad4eb453 --- /dev/null +++ b/idea/testData/refactoring/inline/function/LocalCapturing.kt @@ -0,0 +1,12 @@ +fun bar(s: String) {} + +fun foo() { + val t = "Test" + + fun local() { + bar(t) + } + + // TODO: should be available + local() +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/LocalSimple.kt b/idea/testData/refactoring/inline/function/LocalSimple.kt new file mode 100644 index 00000000000..17f6a37ef03 --- /dev/null +++ b/idea/testData/refactoring/inline/function/LocalSimple.kt @@ -0,0 +1,10 @@ +fun bar(s: String) {} + +fun foo() { + fun local() { + bar("Test") + } + + // TODO: should be available + local() +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/UnitReturnType2.kt.todo b/idea/testData/refactoring/inline/function/UnitReturnType2.kt similarity index 100% rename from idea/testData/refactoring/inline/function/UnitReturnType2.kt.todo rename to idea/testData/refactoring/inline/function/UnitReturnType2.kt diff --git a/idea/testData/refactoring/inline/function/UnitReturnType2.kt.after b/idea/testData/refactoring/inline/function/UnitReturnType2.kt.after index 5fcded0ffa7..841bdb85d56 100644 --- a/idea/testData/refactoring/inline/function/UnitReturnType2.kt.after +++ b/idea/testData/refactoring/inline/function/UnitReturnType2.kt.after @@ -9,7 +9,6 @@ fun g(p: String?) { p?.let { println(3) nonUnit(4) - Unit } } @@ -21,5 +20,5 @@ fun h() { fun x() = doIt { println(7) nonUnit(8) - Unit + // Unit should be here } diff --git a/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt b/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt new file mode 100644 index 00000000000..b71914b78d8 --- /dev/null +++ b/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt @@ -0,0 +1,7 @@ + +fun sqr(x: Double) = x * x + +class Point(val x: Double, val y: Double) { + // After sqr inlining, only first usage of sqr is replaced + fun distance(other: Point) = Math.sqrt(sqr(x - other.x) + sqr(y - other.y)) +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt.after b/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt.after new file mode 100644 index 00000000000..4903702ed2a --- /dev/null +++ b/idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt.after @@ -0,0 +1,8 @@ +class Point(val x: Double, val y: Double) { + // After sqr inlining, only first usage of sqr is replaced + fun distance(other: Point): Double { + val x = x - other.x + // See KT-17022 + return Math.sqrt(x * x + sqr(y - other.y)) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt b/idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt new file mode 100644 index 00000000000..33beab7695d --- /dev/null +++ b/idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt @@ -0,0 +1,12 @@ +class My { + fun run() { + // TODO: should be available + val foo = doThing() + System.out.println(foo) + } + + private fun doThing(): Int { + val foo = 1 + 2 + return foo + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt b/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt new file mode 100644 index 00000000000..eec2a7a7e69 --- /dev/null +++ b/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt @@ -0,0 +1,11 @@ +class My { + fun run() { + val foo = doThing() + System.out.println(foo) + } + + fun doThing(): Int { + val foo = 1 + 2 + return foo + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt.after b/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt.after new file mode 100644 index 00000000000..fda45fc39fa --- /dev/null +++ b/idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt.after @@ -0,0 +1,9 @@ +class My { + fun run() { + // foo1 should be here + val foo = 1 + 2 + val foo = foo + System.out.println(foo) + } + +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java index 041978eddd6..14d90928ba6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java @@ -50,6 +50,18 @@ public class InlineTestGenerated extends AbstractInlineTest { doTest(fileName); } + @TestMetadata("LocalCapturing.kt") + public void testLocalCapturing() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/LocalCapturing.kt"); + doTest(fileName); + } + + @TestMetadata("LocalSimple.kt") + public void testLocalSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/LocalSimple.kt"); + doTest(fileName); + } + @TestMetadata("MultipleReturns.kt") public void testMultipleReturns() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/MultipleReturns.kt"); @@ -68,6 +80,12 @@ public class InlineTestGenerated extends AbstractInlineTest { doTest(fileName); } + @TestMetadata("UnitReturnType2.kt") + public void testUnitReturnType2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/UnitReturnType2.kt"); + doTest(fileName); + } + @TestMetadata("idea/testData/refactoring/inline/function/expressionBody") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -112,6 +130,12 @@ public class InlineTestGenerated extends AbstractInlineTest { doTest(fileName); } + @TestMetadata("MultipleInExpression.kt") + public void testMultipleInExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/expressionBody/MultipleInExpression.kt"); + doTest(fileName); + } + @TestMetadata("SafeCall.kt") public void testSafeCall() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/expressionBody/SafeCall.kt"); @@ -163,6 +187,18 @@ public class InlineTestGenerated extends AbstractInlineTest { doTest(fileName); } + @TestMetadata("PrivateMember.kt") + public void testPrivateMember() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt"); + doTest(fileName); + } + + @TestMetadata("PublicMember.kt") + public void testPublicMember() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/PublicMember.kt"); + doTest(fileName); + } + @TestMetadata("ReturnFromLambda.kt") public void testReturnFromLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/ReturnFromLambda.kt");