Partial body resolve test to test 2 resolve modes

This commit is contained in:
Valentin Kipyatkov
2014-12-07 06:25:24 -07:00
parent 2a41856af6
commit 8f32a6c1f9
15 changed files with 150 additions and 26 deletions
@@ -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)
}
}
<caret>p?.size
}
@@ -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() {
@@ -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(<caret>p.size)
/* STATEMENT DELETED: p1 as String */
}
/* STATEMENT DELETED: z(p1 as String) */
}
@@ -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) */
@@ -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(<caret>p.size)
/* STATEMENT DELETED: p1!! */
}
/* STATEMENT DELETED: z(p1!!) */
}
@@ -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) {
@@ -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(<caret>v2)
/* STATEMENT DELETED: run { val v2 = 2 println(v2) } */
}
/* STATEMENT DELETED: z() */
}
@@ -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) } */
@@ -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 ""
}
}
<caret>p?.size
}
@@ -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 "" } } */
<caret>p?.size
}
@@ -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 "" */
}
<caret>p?.size
}
@@ -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 "" } */
<caret>p?.size
}
@@ -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()
}
<caret>p.size
}
@@ -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()
@@ -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(