From 8f32a6c1f905457eda81d33689211a6756ad7b89 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Sun, 7 Dec 2014 06:25:24 -0700 Subject: [PATCH] Partial body resolve test to test 2 resolve modes --- .../AnonymousObjects.completion | 24 +++++++++++++++++ .../partialBodyResolve/AnonymousObjects.dump | 7 +---- .../resolve/partialBodyResolve/As.completion | 21 +++++++++++++++ .../resolve/partialBodyResolve/As.dump | 2 +- .../partialBodyResolve/BangBang.completion | 20 ++++++++++++++ .../resolve/partialBodyResolve/BangBang.dump | 2 +- .../DeclarationsBefore.completion | 20 ++++++++++++++ .../DeclarationsBefore.dump | 2 +- .../partialBodyResolve/LocalClass.completion | 13 ++++++++++ .../partialBodyResolve/LocalClass.dump | 8 +----- .../partialBodyResolve/LocalFun.completion | 11 ++++++++ .../resolve/partialBodyResolve/LocalFun.dump | 6 +---- .../LocalNothingFun.completion | 12 +++++++++ .../partialBodyResolve/LocalNothingFun.dump | 2 +- .../resolve/AbstractPartialBodyResolveTest.kt | 26 ++++++++++++++++--- 15 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 idea/testData/resolve/partialBodyResolve/AnonymousObjects.completion create mode 100644 idea/testData/resolve/partialBodyResolve/As.completion create mode 100644 idea/testData/resolve/partialBodyResolve/BangBang.completion create mode 100644 idea/testData/resolve/partialBodyResolve/DeclarationsBefore.completion create mode 100644 idea/testData/resolve/partialBodyResolve/LocalClass.completion create mode 100644 idea/testData/resolve/partialBodyResolve/LocalFun.completion create mode 100644 idea/testData/resolve/partialBodyResolve/LocalNothingFun.completion diff --git a/idea/testData/resolve/partialBodyResolve/AnonymousObjects.completion b/idea/testData/resolve/partialBodyResolve/AnonymousObjects.completion new file mode 100644 index 00000000000..3a760160652 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/AnonymousObjects.completion @@ -0,0 +1,24 @@ +Resolve target: value-parameter val p: kotlin.String? +---------------------------------------------- +open class C(p: Int) { + open fun f(){} +} + +fun foo(p: String?) { + val o = object : Runnable { + override fun run() { + if (p == null) return + print(p.size) + } + } + + val c = object : C(p!!.size) { + override fun f() { + super.f() + if (p == null) return + print(p.size) + } + } + + p?.size +} diff --git a/idea/testData/resolve/partialBodyResolve/AnonymousObjects.dump b/idea/testData/resolve/partialBodyResolve/AnonymousObjects.dump index 3a760160652..a9bcfa7543a 100644 --- a/idea/testData/resolve/partialBodyResolve/AnonymousObjects.dump +++ b/idea/testData/resolve/partialBodyResolve/AnonymousObjects.dump @@ -5,12 +5,7 @@ open class C(p: Int) { } fun foo(p: String?) { - val o = object : Runnable { - override fun run() { - if (p == null) return - print(p.size) - } - } + /* STATEMENT DELETED: val o = object : Runnable { override fun run() { if (p == null) return print(p.size) } } */ val c = object : C(p!!.size) { override fun f() { diff --git a/idea/testData/resolve/partialBodyResolve/As.completion b/idea/testData/resolve/partialBodyResolve/As.completion new file mode 100644 index 00000000000..42ef4d5d47b --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/As.completion @@ -0,0 +1,21 @@ +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String +---------------------------------------------- +fun foo(p: Any, p1: Any?) { + x(e.f as String) + /* STATEMENT DELETED: y(p as? Int) */ + /* STATEMENT DELETED: z(f() as String) */ + + if (a) { + print((p as String).size) + } + else { + print((p as String).length) + } + + if (y()) { + print(p.size) + /* STATEMENT DELETED: p1 as String */ + } + + /* STATEMENT DELETED: z(p1 as String) */ +} diff --git a/idea/testData/resolve/partialBodyResolve/As.dump b/idea/testData/resolve/partialBodyResolve/As.dump index 42ef4d5d47b..024f59c27de 100644 --- a/idea/testData/resolve/partialBodyResolve/As.dump +++ b/idea/testData/resolve/partialBodyResolve/As.dump @@ -1,7 +1,7 @@ Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String ---------------------------------------------- fun foo(p: Any, p1: Any?) { - x(e.f as String) + /* STATEMENT DELETED: x(e.f as String) */ /* STATEMENT DELETED: y(p as? Int) */ /* STATEMENT DELETED: z(f() as String) */ diff --git a/idea/testData/resolve/partialBodyResolve/BangBang.completion b/idea/testData/resolve/partialBodyResolve/BangBang.completion new file mode 100644 index 00000000000..0cb2ad517aa --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/BangBang.completion @@ -0,0 +1,20 @@ +Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String +---------------------------------------------- +fun foo(p: String?, p1: Any?) { + x(e.f!!) + /* STATEMENT DELETED: y(f()!!) */ + + if (a) { + print(p!!.size) + } + else { + print(p!!.length) + } + + if (y()) { + print(p.size) + /* STATEMENT DELETED: p1!! */ + } + + /* STATEMENT DELETED: z(p1!!) */ +} diff --git a/idea/testData/resolve/partialBodyResolve/BangBang.dump b/idea/testData/resolve/partialBodyResolve/BangBang.dump index 0cb2ad517aa..f2f5d0e4b53 100644 --- a/idea/testData/resolve/partialBodyResolve/BangBang.dump +++ b/idea/testData/resolve/partialBodyResolve/BangBang.dump @@ -1,7 +1,7 @@ Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String ---------------------------------------------- fun foo(p: String?, p1: Any?) { - x(e.f!!) + /* STATEMENT DELETED: x(e.f!!) */ /* STATEMENT DELETED: y(f()!!) */ if (a) { diff --git a/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.completion b/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.completion new file mode 100644 index 00000000000..12b0bad85aa --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.completion @@ -0,0 +1,20 @@ +Resolve target: val v2: kotlin.Int +---------------------------------------------- +fun foo(p: Int) { + /* STATEMENT DELETED: x() */ + + val v1 = p * p + + if (y()) { + val v2 = v1 * v1 + val v3 = v1 * v2 + + /* STATEMENT DELETED: run { val v2 = 1 println(v2) } */ + + print(v2) + + /* STATEMENT DELETED: run { val v2 = 2 println(v2) } */ + } + + /* STATEMENT DELETED: z() */ +} diff --git a/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.dump b/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.dump index 12b0bad85aa..54003178edb 100644 --- a/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.dump +++ b/idea/testData/resolve/partialBodyResolve/DeclarationsBefore.dump @@ -7,7 +7,7 @@ fun foo(p: Int) { if (y()) { val v2 = v1 * v1 - val v3 = v1 * v2 + /* STATEMENT DELETED: val v3 = v1 * v2 */ /* STATEMENT DELETED: run { val v2 = 1 println(v2) } */ diff --git a/idea/testData/resolve/partialBodyResolve/LocalClass.completion b/idea/testData/resolve/partialBodyResolve/LocalClass.completion new file mode 100644 index 00000000000..6e965e2a888 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/LocalClass.completion @@ -0,0 +1,13 @@ +Resolve target: value-parameter val p: kotlin.String? +---------------------------------------------- +fun foo(p: String?) { + class LocalClass { + fun f(): String? { + if (p == null) return null + print(p.size) + return "" + } + } + + p?.size +} diff --git a/idea/testData/resolve/partialBodyResolve/LocalClass.dump b/idea/testData/resolve/partialBodyResolve/LocalClass.dump index 6e965e2a888..95ddf3faffc 100644 --- a/idea/testData/resolve/partialBodyResolve/LocalClass.dump +++ b/idea/testData/resolve/partialBodyResolve/LocalClass.dump @@ -1,13 +1,7 @@ Resolve target: value-parameter val p: kotlin.String? ---------------------------------------------- fun foo(p: String?) { - class LocalClass { - fun f(): String? { - if (p == null) return null - print(p.size) - return "" - } - } + /* STATEMENT DELETED: class LocalClass { fun f(): String? { if (p == null) return null print(p.size) return "" } } */ p?.size } diff --git a/idea/testData/resolve/partialBodyResolve/LocalFun.completion b/idea/testData/resolve/partialBodyResolve/LocalFun.completion new file mode 100644 index 00000000000..7c3dc20d527 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/LocalFun.completion @@ -0,0 +1,11 @@ +Resolve target: value-parameter val p: kotlin.String? +---------------------------------------------- +fun foo(p: String?) { + fun local(): String? { + /* STATEMENT DELETED: if (p == null) return null */ + /* STATEMENT DELETED: print(p.size) */ + /* STATEMENT DELETED: return "" */ + } + + p?.size +} diff --git a/idea/testData/resolve/partialBodyResolve/LocalFun.dump b/idea/testData/resolve/partialBodyResolve/LocalFun.dump index 7c3dc20d527..73f8cfd4990 100644 --- a/idea/testData/resolve/partialBodyResolve/LocalFun.dump +++ b/idea/testData/resolve/partialBodyResolve/LocalFun.dump @@ -1,11 +1,7 @@ Resolve target: value-parameter val p: kotlin.String? ---------------------------------------------- fun foo(p: String?) { - fun local(): String? { - /* STATEMENT DELETED: if (p == null) return null */ - /* STATEMENT DELETED: print(p.size) */ - /* STATEMENT DELETED: return "" */ - } + /* STATEMENT DELETED: fun local(): String? { if (p == null) return null print(p.size) return "" } */ p?.size } diff --git a/idea/testData/resolve/partialBodyResolve/LocalNothingFun.completion b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.completion new file mode 100644 index 00000000000..6742455fe37 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.completion @@ -0,0 +1,12 @@ +Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String +---------------------------------------------- +fun foo(p: String?, p1: Any?) { + if (p1 == null) return + + fun localError(): Nothing = throw Exception() + + if (p == null) { + localError() + } + p.size +} diff --git a/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump index 6742455fe37..3674a079033 100644 --- a/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump +++ b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump @@ -1,7 +1,7 @@ Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String ---------------------------------------------- fun foo(p: String?, p1: Any?) { - if (p1 == null) return + /* STATEMENT DELETED: if (p1 == null) return */ fun localError(): Nothing = throw Exception() diff --git a/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt b/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt index f6ccd8cd60d..05e4747caed 100644 --- a/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt +++ b/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt @@ -42,13 +42,31 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.jet.lang.psi.JetReferenceExpression import org.jetbrains.jet.lang.psi.psiUtil.getReceiverExpression import org.jetbrains.jet.lang.resolve.lazy.BodyResolveMode +import org.jetbrains.jet.plugin.JetFileType +import com.intellij.openapi.util.io.FileUtil public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtureTestCase() { override fun getTestDataPath() = JetTestCaseBuilder.getHomeDirectory() override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE public fun doTest(testPath: String) { - myFixture.configureByFile(testPath) + val dumpNormal = dump(testPath, BodyResolveMode.PARTIAL) + + val testPathNoExt = FileUtil.getNameWithoutExtension(testPath) + JetTestUtils.assertEqualsToFile(File(testPathNoExt + ".dump"), dumpNormal) + + val dumpForCompletion = dump(testPath, BodyResolveMode.PARTIAL_FOR_COMPLETION) + val completionDump = File(testPathNoExt + ".completion") + if (dumpForCompletion != dumpNormal) { + JetTestUtils.assertEqualsToFile(completionDump, dumpForCompletion) + } + else { + Assert.assertFalse(completionDump.exists()) + } + } + + private fun dump(testPath: String, resolveMode: BodyResolveMode): String { + myFixture.configureByText(JetFileType.INSTANCE, File(testPath).readText()) val file = myFixture.getFile() as JetFile val editor = myFixture.getEditor() @@ -66,7 +84,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur val resolutionFacade = file.getResolutionFacade() // optimized resolve - val (target1, type1, processedStatements1) = doResolve(expression, resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL_FOR_COMPLETION)) + val (target1, type1, processedStatements1) = doResolve(expression, resolutionFacade.analyze(expression, resolveMode)) // full body resolve val (target2, type2, processedStatements2) = doResolve(expression, resolutionFacade.analyze(expression)) @@ -117,10 +135,10 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur builder.append(fileText.substring(newCaretOffset)) } - JetTestUtils.assertEqualsToFile(File(testPath.substringBeforeLast('.') + ".dump"), builder.toString()) - Assert.assertEquals(target2.presentation(null), target1.presentation(null)) Assert.assertEquals(type2.presentation(), type1.presentation()) + + return builder.toString() } private data class ResolveData(