From ae8757f6b818132f516ae1cae14da05bf57171a5 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 1 Jul 2014 14:10:51 +0400 Subject: [PATCH] Added tests on resolved call for 'this' --- .../jet/lang/resolve/BindingContextUtils.kt | 9 ++++--- .../resolvedCalls/this/labeledThis.kt | 5 ++++ .../resolvedCalls/this/labeledThis.txt | 12 +++++++++ .../testData/resolvedCalls/this/simpleThis.kt | 5 ++++ .../resolvedCalls/this/simpleThis.txt | 12 +++++++++ .../this/thisInExtensionFunction.kt | 5 ++++ .../this/thisInExtensionFunction.txt | 12 +++++++++ .../calls/ResolvedCallsTestGenerated.java | 26 ++++++++++++++++++- 8 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/resolvedCalls/this/labeledThis.kt create mode 100644 compiler/testData/resolvedCalls/this/labeledThis.txt create mode 100644 compiler/testData/resolvedCalls/this/simpleThis.kt create mode 100644 compiler/testData/resolvedCalls/this/simpleThis.txt create mode 100644 compiler/testData/resolvedCalls/this/thisInExtensionFunction.kt create mode 100644 compiler/testData/resolvedCalls/this/thisInExtensionFunction.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt index 3674c3231d8..5e8d710cd46 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt @@ -39,6 +39,7 @@ import org.jetbrains.jet.lang.psi.JetUnaryExpression import org.jetbrains.jet.lang.psi.JetBinaryExpression import org.jetbrains.jet.lang.psi.JetSimpleNameExpression import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.jet.lang.psi.JetThisExpression /** * For expressions like a(), a[i], a.b.c(), +a, a + b, (a()), a(): Int, @label a() @@ -54,9 +55,11 @@ fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? { if (expr is JetQualifiedExpression) { return expr.getSelectorExpression()?.getCorrespondingCall(bindingContext) } - val reference = when (expr) { - is JetCallExpression -> expr.getCalleeExpression() - is JetOperationExpression -> expr.getOperationReference() + val parent = expr.getParent() + val reference = when { + parent is JetThisExpression -> parent : JetThisExpression + expr is JetCallExpression -> expr.getCalleeExpression() + expr is JetOperationExpression -> expr.getOperationReference() else -> expr } return bindingContext[CALL, reference] diff --git a/compiler/testData/resolvedCalls/this/labeledThis.kt b/compiler/testData/resolvedCalls/this/labeledThis.kt new file mode 100644 index 00000000000..2f278920d9e --- /dev/null +++ b/compiler/testData/resolvedCalls/this/labeledThis.kt @@ -0,0 +1,5 @@ +class A { + fun foo() { + this@A.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/this/labeledThis.txt b/compiler/testData/resolvedCalls/this/labeledThis.txt new file mode 100644 index 00000000000..3c20ad1969b --- /dev/null +++ b/compiler/testData/resolvedCalls/this/labeledThis.txt @@ -0,0 +1,12 @@ +class A { + fun foo() { + this@A.foo() + } +} + + +Resolved call: + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +This object = NO_RECEIVER +Receiver argument = NO_RECEIVER \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/this/simpleThis.kt b/compiler/testData/resolvedCalls/this/simpleThis.kt new file mode 100644 index 00000000000..26e6b33b9fe --- /dev/null +++ b/compiler/testData/resolvedCalls/this/simpleThis.kt @@ -0,0 +1,5 @@ +class A { + fun foo() { + this.foo() + } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/this/simpleThis.txt b/compiler/testData/resolvedCalls/this/simpleThis.txt new file mode 100644 index 00000000000..cd252fb10a9 --- /dev/null +++ b/compiler/testData/resolvedCalls/this/simpleThis.txt @@ -0,0 +1,12 @@ +class A { + fun foo() { + this.foo() + } +} + + +Resolved call: + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +This object = NO_RECEIVER +Receiver argument = NO_RECEIVER \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/this/thisInExtensionFunction.kt b/compiler/testData/resolvedCalls/this/thisInExtensionFunction.kt new file mode 100644 index 00000000000..fcb5134ff72 --- /dev/null +++ b/compiler/testData/resolvedCalls/this/thisInExtensionFunction.kt @@ -0,0 +1,5 @@ +class A { + fun foo() {} +} + +fun A.bar() = this.foo() \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/this/thisInExtensionFunction.txt b/compiler/testData/resolvedCalls/this/thisInExtensionFunction.txt new file mode 100644 index 00000000000..e5aba9428b4 --- /dev/null +++ b/compiler/testData/resolvedCalls/this/thisInExtensionFunction.txt @@ -0,0 +1,12 @@ +class A { + fun foo() {} +} + +fun A.bar() = this.foo() + + +Resolved call: + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +This object = NO_RECEIVER +Receiver argument = NO_RECEIVER \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java index 20321fb5d6f..268fd50b2a9 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.resolve.calls.AbstractResolvedCallsTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/resolvedCalls") -@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class}) +@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class, ResolvedCallsTestGenerated.This.class}) public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { public void testAllFilesPresentInResolvedCalls() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls"), Pattern.compile("^(.+)\\.kt$"), true); @@ -319,6 +319,29 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { } + @TestMetadata("compiler/testData/resolvedCalls/this") + public static class This extends AbstractResolvedCallsTest { + public void testAllFilesPresentInThis() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/this"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("labeledThis.kt") + public void testLabeledThis() throws Exception { + doTest("compiler/testData/resolvedCalls/this/labeledThis.kt"); + } + + @TestMetadata("simpleThis.kt") + public void testSimpleThis() throws Exception { + doTest("compiler/testData/resolvedCalls/this/simpleThis.kt"); + } + + @TestMetadata("thisInExtensionFunction.kt") + public void testThisInExtensionFunction() throws Exception { + doTest("compiler/testData/resolvedCalls/this/thisInExtensionFunction.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("ResolvedCallsTestGenerated"); suite.addTestSuite(ResolvedCallsTestGenerated.class); @@ -326,6 +349,7 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { suite.addTestSuite(FunctionTypes.class); suite.addTestSuite(Invoke.class); suite.addTestSuite(RealExamples.class); + suite.addTestSuite(This.class); return suite; } }