Refactoring: AbstractResolvedCallsTest

Render resolved call to a separate file
This commit is contained in:
Svetlana Isakova
2014-05-30 09:59:44 +04:00
parent b2c2e1811c
commit 29ab166e1b
77 changed files with 770 additions and 208 deletions
@@ -1,8 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentMatch(t : Int, SUCCESS)
// !ARG_2: ArgumentMatch(f : (Int) -> String, SUCCESS)
// !ARG_3: ArgumentMatch(g : (String) -> Int, SUCCESS)
fun <T, S, R> foo(t: T, f: (T) -> S, g: (S) -> R) {}
@@ -0,0 +1,21 @@
// !CALL: foo
fun <T, S, R> foo(t: T, f: (T) -> S, g: (S) -> R) {}
fun test() {
foo(1, { x -> "$x"}, { y -> y.length })
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS t : Int = 1
SUCCESS f : (Int) -> String = { x -> "$x"}
SUCCESS g : (String) -> Int = { y -> y.length }
@@ -1,10 +1,7 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentMatch(f : () -> ???, UNINFERRED_TYPE_IN_PARAMETER)
fun <T> foo(f: () -> T) {}
fun test() {
foo { b }
}
@@ -0,0 +1,18 @@
// !CALL: foo
fun <T> foo(f: () -> T) {}
fun test() {
foo { b }
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES f : () -> ??? = { b }
@@ -1,10 +1,7 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentMatch(f : (???) -> String, UNINFERRED_TYPE_IN_PARAMETER)
fun <T> foo(f: (T) -> String) {}
fun test() {
foo { x -> "$x"}
}
@@ -0,0 +1,18 @@
// !CALL: foo
fun <T> foo(f: (T) -> String) {}
fun test() {
foo { x -> "$x"}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES f : (???) -> String = { x -> "$x"}
@@ -1,10 +1,7 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentMatch(f : (Int) -> String, SUCCESS)
fun <T> foo(f: (T) -> String) {}
fun test() {
foo { (x: Int) -> "$x"}
}
@@ -0,0 +1,18 @@
// !CALL: foo
fun <T> foo(f: (T) -> String) {}
fun test() {
foo { (x: Int) -> "$x"}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS f : (Int) -> String = { (x: Int) -> "$x"}
@@ -1,10 +1,7 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentMatch(f : (Int) -> String, SUCCESS)
fun foo(f: (Int) -> String) {}
fun test() {
foo { x -> "$x"}
}
@@ -0,0 +1,18 @@
// !CALL: foo
fun foo(f: (Int) -> String) {}
fun test() {
foo { x -> "$x"}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS f : (Int) -> String = { x -> "$x"}
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: ArgumentUnmapped
fun foo() {}
@@ -0,0 +1,18 @@
// !CALL: foo
fun foo() {}
fun test() {
foo { x -> "$x"}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
ARGUMENT UNMAPPED: { x -> "$x"}
@@ -1,7 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: 11 = ArgumentMatch(t : Comparable<out Any?>, SUCCESS)
// !ARG_2: ls = ArgumentMatch(l : List<Comparable<out Any?>>, SUCCESS)
fun <T> foo(t: T, l: List<T>) {}
@@ -0,0 +1,21 @@
// !CALL: foo
fun <T> foo(t: T, l: List<T>) {}
fun use(vararg a: Any?) = a
fun test(a: Any, ls: List<String>) {
use(foo(11, ls))
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS t : Comparable<out Any?> = 11
SUCCESS l : List<Comparable<out Any?>> = ls
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: A() = ArgumentMatch(t : A, SUCCESS)
class A {}
@@ -0,0 +1,20 @@
// !CALL: foo
class A {}
fun <T> foo(t: T) {}
fun bar() {
foo(A())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS t : A = A()
@@ -1,7 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: 11 = ArgumentMatch(t : ???, UNINFERRED_TYPE_IN_PARAMETER)
// !ARG_2: ls = ArgumentMatch(l : MutableList<???>, UNINFERRED_TYPE_IN_PARAMETER)
fun <T> foo(t: T, l: MutableList<T>) {}
@@ -0,0 +1,21 @@
// !CALL: foo
fun <T> foo(t: T, l: MutableList<T>) {}
fun use(vararg a: Any?) = a
fun test(ls: MutableList<String>) {
use(foo(11, ls))
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES t : ??? = 11
MATCH_MODULO_UNINFERRED_TYPES l : MutableList<???> = ls
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: 11 = ArgumentMatch(l : List<???>, TYPE_MISMATCH)
fun <T> foo(l: List<T>) {}
@@ -0,0 +1,18 @@
// !CALL: foo
fun <T> foo(l: List<T>) {}
fun test() {
foo(11)
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
TYPE_MISMATCH l : List<???> = 11
@@ -1,7 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: B() = ArgumentMatch(b : B, SUCCESS)
// !ARG_2: A() = ArgumentUnmapped
class A {}
class B {}
@@ -0,0 +1,22 @@
// !CALL: foo
class A {}
class B {}
fun foo(a: A, b: B) {}
fun bar() {
foo(b = B(), A())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS b : B = B()
ARGUMENT UNMAPPED: A()
@@ -1,7 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: B() = ArgumentMatch(b : B, SUCCESS)
// !ARG_2: A() = ArgumentMatch(a : A, SUCCESS)
class A {}
class B {}
@@ -0,0 +1,22 @@
// !CALL: foo
class A {}
class B {}
fun foo(a: A, b: B) {}
fun bar() {
foo(b = B(), a = A())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS b : B = B()
SUCCESS a : A = A()
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: b = ArgumentMatch(a : A, ARGUMENT_HAS_NO_TYPE)
class A {}
@@ -0,0 +1,20 @@
// !CALL: foo
class A {}
fun foo(a: A) {}
fun bar() {
foo(b)
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
ARGUMENT_HAS_NO_TYPE a : A = b
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: A() = ArgumentMatch(a : A, SUCCESS)
class A {}
@@ -0,0 +1,20 @@
// !CALL: foo
class A {}
fun foo(a: A) {}
fun bar() {
foo(A())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS a : A = A()
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: "" = ArgumentMatch(a : A, TYPE_MISMATCH)
class A {}
@@ -0,0 +1,20 @@
// !CALL: foo
class A {}
fun foo(a: A) {}
fun bar() {
foo("")
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
TYPE_MISMATCH a : A = ""
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: "" = ArgumentUnmapped
fun foo() {}
@@ -0,0 +1,18 @@
// !CALL: foo
fun foo() {}
fun bar() {
foo("")
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
ARGUMENT UNMAPPED: ""
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: emptyList() = ArgumentMatch(t : List<???>, UNINFERRED_TYPE_IN_PARAMETER)
class A {}
@@ -0,0 +1,22 @@
// !CALL: foo
class A {}
fun <T> foo(t: T) {}
fun <T> emptyList(): List<T> = throw Exception()
fun bar() {
foo(emptyList())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES t : List<???> = emptyList()
@@ -1,6 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: emptyList() = ArgumentMatch(t : MutableList<???>, UNINFERRED_TYPE_IN_PARAMETER)
class A {}
@@ -0,0 +1,22 @@
// !CALL: foo
class A {}
fun <T> foo(t: T) {}
fun <T> emptyList(): MutableList<T> = throw Exception()
fun bar() {
foo(emptyList())
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES t : MutableList<???> = emptyList()
@@ -1,7 +1,4 @@
// !ONLY_ARGUMENTS
// !CALL: foo
// !ARG_1: A() = ArgumentMatch(a : A, SUCCESS)
// !ARG_2: "" = ArgumentMatch(s : String, SUCCESS)
class A {}
@@ -0,0 +1,23 @@
// !CALL: foo
class A {}
fun foo(a: A) {}
fun foo(a: A, s: String) {}
fun foo(a: A, any: Any) {}
fun bar() {
foo(A(), "")
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS a : A = A()
SUCCESS s : String = ""
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: RECEIVER_ARGUMENT
// !THIS_OBJECT: NO_RECEIVER
// !RECEIVER_ARGUMENT: a
class A {}
@@ -0,0 +1,16 @@
// !CALL: foo
class A {}
fun A.foo() {}
fun bar(a: A) {
a.foo()
}
Resolved call:
Explicit receiver kind = RECEIVER_ARGUMENT
This object = NO_RECEIVER
Receiver argument = a
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: a
// !RECEIVER_ARGUMENT: NO_RECEIVER
class A {
fun foo() {}
@@ -0,0 +1,16 @@
// !CALL: foo
class A {
fun foo() {}
}
fun bar(a: A) {
a.foo()
}
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = a
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: BOTH_RECEIVERS
// !THIS_OBJECT: f
// !RECEIVER_ARGUMENT: 1
fun bar(f: Int.()->Unit) {
1.f()
@@ -0,0 +1,12 @@
// !CALL: invoke
fun bar(f: Int.()->Unit) {
1.f()
}
Resolved call:
Explicit receiver kind = BOTH_RECEIVERS
This object = f
Receiver argument = 1
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: f
// !RECEIVER_ARGUMENT: NO_RECEIVER
fun bar(f: ()->Unit) {
f()
@@ -0,0 +1,12 @@
// !CALL: invoke
fun bar(f: ()->Unit) {
f()
}
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = f
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: Class{A}
// !RECEIVER_ARGUMENT: NO_RECEIVER
trait A {
val foo: Int.()->Unit
@@ -0,0 +1,16 @@
// !CALL: foo
trait A {
val foo: Int.()->Unit
fun test() {
1.foo()
}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = Class{A}
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: BOTH_RECEIVERS
// !THIS_OBJECT: foo
// !RECEIVER_ARGUMENT: 1
trait A {
val foo: Int.()->Unit
@@ -0,0 +1,16 @@
// !CALL: invoke
trait A {
val foo: Int.()->Unit
fun test() {
1.foo()
}
}
Resolved call:
Explicit receiver kind = BOTH_RECEIVERS
This object = foo
Receiver argument = 1
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: a
// !RECEIVER_ARGUMENT: NO_RECEIVER
trait A {
val foo: (Int)->Int
@@ -0,0 +1,16 @@
// !CALL: foo
trait A {
val foo: (Int)->Int
}
fun test(a: A) {
a.foo(1)
}
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = a
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: foo
// !RECEIVER_ARGUMENT: NO_RECEIVER
trait A {
val foo: (Int)->Int
@@ -0,0 +1,20 @@
// !CALL: invoke
trait A {
val foo: (Int)->Int
}
fun test(a: A) {
a.foo(1)
}
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = foo
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS p1 : Int = 1
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: RECEIVER_ARGUMENT
// !THIS_OBJECT: A
// !RECEIVER_ARGUMENT: b
class A {
fun B.foo() {}
@@ -0,0 +1,22 @@
// !CALL: foo
class A {
fun B.foo() {}
}
trait B
fun bar(a: A, b: B) {
with (a) {
b.foo()
}
}
fun <T, R> with(receiver: T, f: T.() -> R) : R = receiver.f()
Resolved call:
Explicit receiver kind = RECEIVER_ARGUMENT
This object = A
Receiver argument = b
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: A
// !RECEIVER_ARGUMENT: B
class A {
fun B.foo() {}
@@ -0,0 +1,24 @@
// !CALL: foo
class A {
fun B.foo() {}
}
trait B
fun bar(a: A, b: B) {
with (a) {
with (b) {
foo()
}
}
}
fun <T, R> with(receiver: T, f: T.() -> R) : R = receiver.f()
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = A
Receiver argument = B
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: NO_RECEIVER
// !RECEIVER_ARGUMENT: A
class A {}
@@ -0,0 +1,16 @@
// !CALL: foo
class A {}
fun A.foo() {}
fun A.bar() {
foo()
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = A
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: A
// !RECEIVER_ARGUMENT: NO_RECEIVER
class A {
fun foo() {}
@@ -0,0 +1,16 @@
// !CALL: foo
class A {
fun foo() {}
}
fun A.bar() {
foo()
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = A
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: Class{A}
// !RECEIVER_ARGUMENT: NO_RECEIVER
class A {
fun foo() {}
@@ -0,0 +1,15 @@
// !CALL: foo
class A {
fun foo() {}
fun bar() {
foo()
}
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = Class{A}
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: BOTH_RECEIVERS
// !THIS_OBJECT: f
// !RECEIVER_ARGUMENT: 1
class Foo() {
fun Int.invoke() {}
@@ -0,0 +1,16 @@
// !CALL: invoke
class Foo() {
fun Int.invoke() {}
}
fun bar(f: Foo) {
1.f()
}
Resolved call:
Explicit receiver kind = BOTH_RECEIVERS
This object = f
Receiver argument = 1
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: f
// !RECEIVER_ARGUMENT: Int
class Foo() {
fun Int.invoke() {}
@@ -0,0 +1,20 @@
// !CALL: invoke
class Foo() {
fun Int.invoke() {}
}
fun bar(f: Foo, i: Int) {
with (i) {
f()
}
}
fun <T, R> with(receiver: T, f: T.() -> R) : R = throw Exception()
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = f
Receiver argument = Int
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: RECEIVER_ARGUMENT
// !THIS_OBJECT: NO_RECEIVER
// !RECEIVER_ARGUMENT: f
class Foo
fun Foo.invoke() {}
@@ -0,0 +1,15 @@
// !CALL: invoke
class Foo
fun Foo.invoke() {}
fun bar(f: Foo) {
f()
}
Resolved call:
Explicit receiver kind = RECEIVER_ARGUMENT
This object = NO_RECEIVER
Receiver argument = f
@@ -1,7 +1,4 @@
// !CALL: invoke
// !EXPLICIT_RECEIVER_KIND: THIS_OBJECT
// !THIS_OBJECT: f
// !RECEIVER_ARGUMENT: NO_RECEIVER
class Foo {
fun invoke() {}
@@ -0,0 +1,16 @@
// !CALL: invoke
class Foo {
fun invoke() {}
}
fun bar(f: Foo) {
f()
}
Resolved call:
Explicit receiver kind = THIS_OBJECT
This object = f
Receiver argument = NO_RECEIVER
@@ -1,7 +1,4 @@
// !CALL: +
// !EXPLICIT_RECEIVER_KIND: RECEIVER_ARGUMENT
// !THIS_OBJECT: Title
// !RECEIVER_ARGUMENT: "Foo"
trait Element {
fun render(builder: StringBuilder, indent: String)
@@ -0,0 +1,48 @@
// !CALL: +
trait Element {
fun render(builder: StringBuilder, indent: String)
}
class TextElement(val text: String): Element {
override fun render(builder: StringBuilder, indent: String): Unit = fail
}
abstract class Tag(val name: String): Element {
protected fun initTag<T: Element>(tag: T, init: T.() -> Unit): T = fail
override fun render(builder: StringBuilder, indent: String): Unit = fail
}
abstract class TagWithText(name: String): Tag(name) {
fun String.plus() {}
}
class HTML(): TagWithText("html") {
fun head(init: Head.() -> Unit): Head = fail
}
class Head(): TagWithText("head") {
fun title(init: Title.() -> Unit): Title = fail
}
class Title(): TagWithText("title")
fun html(init: HTML.() -> Unit): HTML = fail
fun result() =
html {
head {
title {+"Foo"}
}
}
val fail: Nothing get() = throw Exception()
Resolved call:
Explicit receiver kind = RECEIVER_ARGUMENT
This object = Title
Receiver argument = "Foo"
@@ -1,7 +1,4 @@
// !CALL: foo
// !EXPLICIT_RECEIVER_KIND: NO_EXPLICIT_RECEIVER
// !THIS_OBJECT: NO_RECEIVER
// !RECEIVER_ARGUMENT: NO_RECEIVER
fun foo() {}
@@ -0,0 +1,14 @@
// !CALL: foo
fun foo() {}
fun bar() {
foo()
}
Resolved call:
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
@@ -20,26 +20,23 @@ import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.JetLiteFixture
import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
import java.io.File
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil
import java.util.ArrayList
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers
import org.jetbrains.jet.lang.resolve.calls.util.getAllValueArguments
import org.jetbrains.jet.renderer.DescriptorRenderer
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jet.lang.psi.ValueArgument
public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
@@ -49,11 +46,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
val text = JetTestUtils.doLoadFile(file)
val directives = JetTestUtils.parseDirectives(text)
val onlyArguments = directives.onlyArguments()
val (callName, thisObject, receiverArgument) = with (directives) {
Triple(get("CALL"), get("THIS_OBJECT"), get("RECEIVER_ARGUMENT"))
}
val explicitReceiverKind = directives.getExplicitReceiverKind()
val callName = directives["CALL"]
fun analyzeFileAndGetResolvedCallEntries(): Map<JetElement, ResolvedCall<*>> {
val psiFile = JetTestUtils.loadJetFile(getProject(), file)!!
@@ -62,114 +55,63 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
return bindingContext.getSliceContents(BindingContext.RESOLVED_CALL)
}
fun checkResolvedCall(resolvedCall: ResolvedCall<*>, element: JetElement) {
if (onlyArguments) return
val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.getContainingFile(), element.getTextRange())
val (actualThisObject, actualReceiverArgument, actualExplicitReceiverKind) = with(resolvedCall) {
Triple(getThisObject().getText(), getReceiverArgument().getText(), getExplicitReceiverKind())
}
val actualDataMessage = "Actual data:\nThis object: $actualThisObject. Receiver argument: $actualReceiverArgument. " +
"Explicit receiver kind: $actualExplicitReceiverKind.\n"
assertEquals(thisObject, actualThisObject, "${actualDataMessage}This object mismatch: ")
assertEquals(receiverArgument, actualReceiverArgument, "${actualDataMessage}Receiver argument mismatch: ")
assertEquals(explicitReceiverKind, actualExplicitReceiverKind,
"$actualDataMessage" +
"Explicit receiver kind for resolved call for '${element.getText()}'$lineAndColumn in not as expected")
}
val argumentsExpectedData = directives.getArgumentsExpectedData()
fun checkArguments(resolvedCall: ResolvedCall<*>) {
if (argumentsExpectedData.isEmpty()) return
for ((index, valueArgument) in resolvedCall.getCall().getAllValueArguments().withIndices()) {
val (argText, argumentMapping) = argumentsExpectedData[index]
if (argText != null) {
assertEquals(argText, valueArgument.getArgumentExpression()!!.getText(),
"An argument expression is incorrect")
}
assertEquals(argumentMapping, resolvedCall.getArgumentMapping(valueArgument).print(),
"Argument mapping is incorrect")
}
}
var callFound = false
fun tryCall(resolvedCall: ResolvedCall<*>, actualName: String?) {
if (callName == null || callName != actualName) return
callFound = true
val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt"
JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall.renderToText()}")
}
for ((element, resolvedCall) in analyzeFileAndGetResolvedCallEntries()) {
fun tryCall(resolvedCall: ResolvedCall<*>, actualName: String? = element.getText()) {
if (callName == null || callName != actualName) return
callFound = true
checkResolvedCall(resolvedCall, element)
checkArguments(resolvedCall)
}
if (resolvedCall is VariableAsFunctionResolvedCall) {
tryCall(resolvedCall.functionCall, "invoke")
tryCall(resolvedCall.variableCall)
tryCall(resolvedCall.variableCall, element.getText())
}
else {
tryCall(resolvedCall)
tryCall(resolvedCall, element.getText())
}
}
assertTrue(callFound, "Resolved call for $callName was not found")
}
}
private fun ReceiverValue.getText() =
if (this is ExpressionReceiver) {
this.getExpression().getText()
}
else if (this is AbstractReceiverValue) {
this.getType().toString()
}
else toString()
private val EXPLICIT_RECEIVER_KIND_DIRECTIVE: String = "EXPLICIT_RECEIVER_KIND"
private fun Map<String, String>.getExplicitReceiverKind(): ExplicitReceiverKind? {
if (onlyArguments()) return null
val explicitReceiverKind = get(EXPLICIT_RECEIVER_KIND_DIRECTIVE)
assert(explicitReceiverKind != null) { "$EXPLICIT_RECEIVER_KIND_DIRECTIVE should be present." }
try {
return ExplicitReceiverKind.valueOf(explicitReceiverKind!!)
}
catch (e: IllegalArgumentException) {
val message = StringBuilder()
message.append("$EXPLICIT_RECEIVER_KIND_DIRECTIVE must be one of the following: ")
for (kind in ExplicitReceiverKind.values()) {
message.append("$kind, ")
}
message.append("\nnot $explicitReceiverKind.")
throw AssertionError(message)
}
private fun ReceiverValue.getText() = when (this) {
is ExpressionReceiver -> getExpression().getText()
is AbstractReceiverValue -> getType().toString()
else -> toString()
}
private fun Map<String, String>.getArgumentsExpectedData(): List<Pair<String?, String>> {
val result = ArrayList<Pair<String?, String>>()
for (i in 1..7) {
val argData = get("ARG_$i")
if (argData == null) continue
private fun ValueArgument.getText() = this.getArgumentExpression()?.getText()?.replace("\n", " ") ?: ""
if (argData.contains("=")) {
val strings = argData.split("=")
assert(strings.size == 2, "Incorrect input data for an argument ARG_$i : $argData")
result.add(Pair(strings[0].trim(), strings[1].trim()))
}
else {
result.add(Pair(null, argData))
}
}
return result
}
private fun Map<String, String>.onlyArguments() = containsKey("ONLY_ARGUMENTS")
fun ArgumentMapping.print() = when (this) {
private fun ArgumentMapping.getText() = when (this) {
is ArgumentMatch -> {
val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.getType())
"ArgumentMatch(${valueParameter.getName()} : ${parameterType}, ${status.name()})"
"${status.name()} ${valueParameter.getName()} : ${parameterType} ="
}
else -> "ArgumentUnmapped"
else -> "ARGUMENT UNMAPPED: "
}
private fun ResolvedCall<*>.renderToText(): String {
val result = StringBuilder()
fun addLine(line: String) = result.append(line).append("\n")
addLine("Resolved call:\n")
addLine("Explicit receiver kind = ${getExplicitReceiverKind()}")
addLine("This object = ${getThisObject().getText()}")
addLine("Receiver argument = ${getReceiverArgument().getText()}")
val valueArguments = getCall().getAllValueArguments()
if (valueArguments.isEmpty()) return result.toString()
addLine("\nValue arguments mapping:\n")
for (valueArgument in valueArguments) {
val argumentText = valueArgument.getText()
val argumentMappingText = getArgumentMapping(valueArgument).getText()
addLine("$argumentMappingText $argumentText")
}
return result.toString()
}