Partial body resolve tests: more informative test output
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.openapi.util.Key
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.psi.PsiComment
|
||||
|
||||
public fun JetPsiFactory(project: Project?): JetPsiFactory = JetPsiFactory(project!!)
|
||||
public fun JetPsiFactory(contextElement: JetElement): JetPsiFactory = JetPsiFactory(contextElement.getProject())
|
||||
@@ -632,6 +633,14 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return createClass("class foo { class object { } }").getClassObject()!!
|
||||
}
|
||||
|
||||
public fun createComment(text: String): PsiComment {
|
||||
val file = createFile(text)
|
||||
val comments = file.getChildren().filterIsInstance<PsiComment>()
|
||||
val comment = comments.single()
|
||||
assert(comment.getText() == text)
|
||||
return comment
|
||||
}
|
||||
|
||||
public fun wrapInABlock(expression: JetExpression): JetBlockExpression {
|
||||
if (expression is JetBlockExpression) {
|
||||
return expression as JetBlockExpression
|
||||
|
||||
@@ -1,2 +1,24 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
y(p as? Int)
|
||||
z(f() as String)
|
||||
p1 as String
|
||||
z(p1 as 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,5 +1,20 @@
|
||||
Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
y(f()!!)
|
||||
p1!!
|
||||
z(p1!!)
|
||||
----------------------------------------------
|
||||
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,3 +1,9 @@
|
||||
Resolve target: value-parameter val p: kotlin.Boolean? smart-cast to kotlin.Boolean
|
||||
Skipped statements:
|
||||
print(p1!!.hashCode())
|
||||
----------------------------------------------
|
||||
fun foo(p: Boolean?, p1: Any?) {
|
||||
if (p!!) {
|
||||
// STATEMENT DELETED: print(p1!!.hashCode())
|
||||
}
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
Resolve target: val v2: kotlin.Int
|
||||
Skipped statements:
|
||||
x()
|
||||
run { val v2 = 1 println(v2) }
|
||||
run { val v2 = 2 println(v2) }
|
||||
z()
|
||||
----------------------------------------------
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -1,2 +1,9 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?) {
|
||||
do {
|
||||
print(p!!)
|
||||
} while (x())
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
print(p1!!)
|
||||
----------------------------------------------
|
||||
fun x(s: String): Collection<String>{}
|
||||
|
||||
fun foo(p: Any?, p1: Any?) {
|
||||
for (e in x(p as String)) {
|
||||
// STATEMENT DELETED: print(p1!!)
|
||||
}
|
||||
|
||||
<caret>p.size
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
Resolve target: null
|
||||
Skipped statements:
|
||||
if (x()) { y(p!!) } else { z(p1!!) }
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?, p1, Any?) {
|
||||
// STATEMENT DELETED: if (x()) { y(p!!) } else { z(p1!!) }
|
||||
|
||||
<caret>xxx
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
Resolve target: value-parameter val p1: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
print(p!!)
|
||||
print(p2!!)
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?, p1: Any?, p2: Any?) {
|
||||
if (x()) {
|
||||
// STATEMENT DELETED: print(p!!)
|
||||
print(p1!!)
|
||||
}
|
||||
else {
|
||||
print(p1 as String)
|
||||
// STATEMENT DELETED: print(p2!!)
|
||||
}
|
||||
|
||||
<caret>p1.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
Resolve target: value-parameter val o: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(o: Any?, p: Int) {
|
||||
if (p > 0) {
|
||||
if (o == null) return
|
||||
}
|
||||
else {
|
||||
if (o !is String) return
|
||||
}
|
||||
<caret>o.javaClass
|
||||
}
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
Resolve target: value-parameter val o: kotlin.String? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(o: String?, o1: String) {
|
||||
if (o != o1) return
|
||||
<caret>o.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: Any) {
|
||||
if (p !is String) {
|
||||
error("Not String")
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: Any) {
|
||||
if (p !is String) {
|
||||
kotlin.error("Not String")
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any
|
||||
Skipped statements:
|
||||
if (p !is String) { print(error) }
|
||||
----------------------------------------------
|
||||
val error = "error"
|
||||
fun foo(p: Any) {
|
||||
// STATEMENT DELETED: if (p !is String) { print(error) }
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,10 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun myError(): Nothing = throw Exception()
|
||||
|
||||
fun foo(p: Any) {
|
||||
if (p !is String) {
|
||||
myError()
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
val prop: Nothing
|
||||
get() = throw Exception()
|
||||
|
||||
fun foo(p: Any) {
|
||||
if (p !is String) {
|
||||
prop
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
print("null")
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?) {
|
||||
if (p !is String) {
|
||||
if (p == null) {
|
||||
// STATEMENT DELETED: print("null")
|
||||
return
|
||||
}
|
||||
else {
|
||||
return
|
||||
}
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
Resolve target: val v: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
class C(public val v: Any)
|
||||
|
||||
fun foo(c: C) {
|
||||
if (c.v !is String) return
|
||||
println(c.<caret>v.size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: Any) {
|
||||
if (p !is String) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
println(<caret>p.size)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
print("not null")
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?) {
|
||||
if (p != null) {
|
||||
// STATEMENT DELETED: print("not null")
|
||||
}
|
||||
else {
|
||||
return
|
||||
}
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (p != null) return
|
||||
@@ -1,2 +1,11 @@
|
||||
Resolve target: val x: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
if (x == null) break
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { print(1) if (f()) return }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { print(1) if (f()) return }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { print(1) if (f()) { return } else { print(2) } }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { print(1) if (f()) { return } else { print(2) } }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
Resolve target: val x: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
if (x == null) continue
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { do { if (g()) break } while (f()) }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { do { if (g()) break } while (f()) }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
fun g(): Boolean{}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { print(1) val v = f() ?: return }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { print(1) val v = f() ?: return }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): String? = null
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { for (s in c) { print(s) return } }
|
||||
----------------------------------------------
|
||||
fun foo(c: Collection<String>) {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { for (s in c) { print(s) return } }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (p == null) { print("null") }
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?) {
|
||||
// STATEMENT DELETED: if (p == null) { print("null") }
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
print("null")
|
||||
----------------------------------------------
|
||||
fun foo(p: Any?) {
|
||||
if (p == null) {
|
||||
// STATEMENT DELETED: print("null")
|
||||
return
|
||||
}
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { while (true) { if (g()) break } }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { while (true) { if (g()) break } }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
fun g(): Boolean{}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { while (f()) { print(1) return } }
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { while (f()) { print(1) return } }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
Resolve target: val kotlin.String.size: kotlin.Int
|
||||
Skipped statements:
|
||||
if (x()) return
|
||||
----------------------------------------------
|
||||
fun foo(p: String) {
|
||||
// STATEMENT DELETED: if (x()) return
|
||||
println(p.<caret>size)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
Resolve target: null
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(s: String){}
|
||||
fun foo(c: Char){}
|
||||
|
||||
fun bar(b: Boolean, s: String, c: Char){
|
||||
foo(if (b) "abc" else <caret>xxx)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
Resolve target: fun f(): kotlin.Unit
|
||||
Skipped statements:
|
||||
x()
|
||||
----------------------------------------------
|
||||
class C {
|
||||
fun f(){}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
val lambda = {() -> // STATEMENT DELETED: x(); C() }
|
||||
lambda().<caret>f()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
Resolve target: value-parameter val c: kotlin.Collection<kotlin.String>
|
||||
Skipped statements:
|
||||
println()
|
||||
----------------------------------------------
|
||||
fun foo(c: Collection<String>): Collection<String> {
|
||||
return <caret>c.filter {
|
||||
val v = it.length
|
||||
val v1 = v * v
|
||||
if (v1 > 10) {
|
||||
true
|
||||
}
|
||||
else {
|
||||
// STATEMENT DELETED: println()
|
||||
it[0] == 'a'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,13 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: String?) {
|
||||
class LocalClass {
|
||||
fun f(): String? {
|
||||
if (p == null) return null
|
||||
print(p.size)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
<caret>p?.size
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
if (p == null) return null
|
||||
print(p.size)
|
||||
return ""
|
||||
----------------------------------------------
|
||||
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,2 +1,12 @@
|
||||
Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
fun foo(p: String?, p1: Any?) {
|
||||
if (p1 == null) return
|
||||
|
||||
fun localError(): Nothing = throw Exception()
|
||||
|
||||
if (p == null) {
|
||||
localError()
|
||||
}
|
||||
<caret>p.size
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
println()
|
||||
----------------------------------------------
|
||||
fun foo(p: String?): () -> String {
|
||||
if (p == null) {
|
||||
return {
|
||||
// STATEMENT DELETED: println()
|
||||
"a"
|
||||
}
|
||||
}
|
||||
<caret>p.size
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
Resolve target: value-parameter val p: kotlin.Int
|
||||
Skipped statements:
|
||||
x()
|
||||
z()
|
||||
----------------------------------------------
|
||||
fun foo(p: Int) {
|
||||
// STATEMENT DELETED: x()
|
||||
if (y()) {
|
||||
print(<caret>p)
|
||||
}
|
||||
// STATEMENT DELETED: z()
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
Resolve target: value-parameter val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
@@ -1,2 +0,0 @@
|
||||
Resolve target: value-parameter val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
@@ -1,2 +1,14 @@
|
||||
Resolve target: val s: kotlin.String? smart-cast to kotlin.String
|
||||
Skipped statements:
|
||||
----------------------------------------------
|
||||
class C(val s: String?) {
|
||||
fun foo(p: Boolean) {
|
||||
if (p) {
|
||||
print(s!!)
|
||||
}
|
||||
else {
|
||||
print(this.s!!)
|
||||
}
|
||||
|
||||
<caret>s.size
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any
|
||||
Skipped statements:
|
||||
print(p1!!)
|
||||
----------------------------------------------
|
||||
fun x(s: Any): Boolean{}
|
||||
|
||||
fun foo(p: Any?, p1: Any?) {
|
||||
while(x(p!!)) {
|
||||
// STATEMENT DELETED: print(p1!!)
|
||||
}
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x()) break
|
||||
----------------------------------------------
|
||||
fun x(): Boolean{}
|
||||
|
||||
fun foo(p: Any?) {
|
||||
while(true) {
|
||||
print(p!!)
|
||||
// STATEMENT DELETED: if (x()) break
|
||||
}
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
while(2 * 2 == 4) { print(p!!) if (x()) break }
|
||||
----------------------------------------------
|
||||
// this test will fail if control flow analysis will start to produce smart-casts after "while(2 * 2 == 4)"
|
||||
|
||||
fun x(): Boolean{}
|
||||
|
||||
fun foo(p: Any?) {
|
||||
// STATEMENT DELETED: while(2 * 2 == 4) { print(p!!) if (x()) break }
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.parents
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
|
||||
public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtureTestCase() {
|
||||
override fun getTestDataPath() = JetTestCaseBuilder.getHomeDirectory()
|
||||
@@ -45,7 +48,8 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur
|
||||
myFixture.configureByFile(testPath)
|
||||
|
||||
val file = myFixture.getFile() as JetFile
|
||||
val offset = myFixture.getEditor().getCaretModel().getOffset()
|
||||
val editor = myFixture.getEditor()
|
||||
val offset = editor.getCaretModel().getOffset()
|
||||
val element = file.findElementAt(offset)
|
||||
val refExpression = element.getParentByType(javaClass<JetSimpleNameExpression>()) ?: error("No JetSimpleNameExpression at caret")
|
||||
|
||||
@@ -63,16 +67,31 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("Resolve target: ${target2.presentation(type2)}\n")
|
||||
builder.append("Skipped statements:\n")
|
||||
set.sortBy { it.getTextOffset() }.forEach {
|
||||
if (!it.parents(withItself = false).any { it in set }) { // do not dump skipped statements which are inside other skipped statement
|
||||
builder append it.presentation() append "\n"
|
||||
}
|
||||
}
|
||||
builder.append("----------------------------------------------\n")
|
||||
|
||||
val skippedStatements = set
|
||||
.filter { !it.parents(withItself = false).any { it in set } } // do not include skipped statements which are inside other skipped statement
|
||||
.sortBy { it.getTextOffset() }
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
{
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
for (statement in skippedStatements) {
|
||||
statement.replace(JetPsiFactory(getProject()).createComment("// STATEMENT DELETED: ${statement.compactPresentation()}"))
|
||||
}
|
||||
}
|
||||
},
|
||||
"",
|
||||
null
|
||||
)
|
||||
val fileText = file.getText()
|
||||
val newCaretOffset = editor.getCaretModel().getOffset()
|
||||
builder.append(fileText.substring(0, newCaretOffset))
|
||||
builder.append("<caret>")
|
||||
builder.append(fileText.substring(newCaretOffset))
|
||||
|
||||
JetTestUtils.assertEqualsToFile(File(testPath.substringBeforeLast('.') + ".dump"), builder.toString())
|
||||
|
||||
//TODO: discuss that descriptors are different
|
||||
Assert.assertEquals(target2.presentation(type2), target1.presentation(type1))
|
||||
}
|
||||
|
||||
@@ -112,7 +131,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur
|
||||
return s + " smart-cast to " + if (type != null) DescriptorRenderer.COMPACT.renderType(type) else "unknown type"
|
||||
}
|
||||
|
||||
private fun JetExpression.presentation(): String {
|
||||
private fun JetExpression.compactPresentation(): String {
|
||||
val text = getText()
|
||||
val builder = StringBuilder()
|
||||
var dropSpace = false
|
||||
|
||||
Reference in New Issue
Block a user