Support static method references

#KT-5123 Fixed
This commit is contained in:
Alexander Udalov
2014-09-26 17:05:43 +04:00
parent 19497262b3
commit cd0551078c
10 changed files with 96 additions and 4 deletions
@@ -591,14 +591,24 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return null;
}
JetScope staticScope = getStaticNestedClassesScope((ClassDescriptor) classifier);
JetScope staticScope = ((ClassDescriptor) classifier).getStaticScope();
TemporaryTraceAndCache temporaryForStatic = TemporaryTraceAndCache.create(
context, "trace to resolve callable reference in static scope", reference);
CallableDescriptor possibleStaticNestedClassConstructor = resolveCallableNotCheckingArguments(reference, NO_RECEIVER,
context.replaceTraceAndCache(temporaryForStatic).replaceScope(staticScope), result);
CallableDescriptor possibleStatic = resolveCallableNotCheckingArguments(
reference, NO_RECEIVER, context.replaceTraceAndCache(temporaryForStatic).replaceScope(staticScope), result);
if (result[0]) {
temporaryForStatic.commit();
return possibleStaticNestedClassConstructor;
return possibleStatic;
}
JetScope staticNestedClasses = getStaticNestedClassesScope((ClassDescriptor) classifier);
TemporaryTraceAndCache temporaryForNested = TemporaryTraceAndCache.create(
context, "trace to resolve callable reference in static nested classes scope", reference);
CallableDescriptor possibleNestedClassConstructor = resolveCallableNotCheckingArguments(reference, NO_RECEIVER,
context.replaceTraceAndCache(temporaryForNested).replaceScope(staticNestedClasses), result);
if (result[0]) {
temporaryForNested.commit();
return possibleNestedClassConstructor;
}
ReceiverValue receiver = new TransientReceiver(lhsType);
@@ -0,0 +1,5 @@
class A {
public static void main(String[] args) {
args[0] = "OK";
}
}
@@ -0,0 +1,5 @@
fun box(): String {
val args = array("Fail")
(A::main)(args)
return args[0]
}
@@ -0,0 +1,9 @@
enum class E {
ENTRY
}
fun box(): String {
val f = E::valueOf
val result = f("ENTRY")
return if (result == E.ENTRY) "OK" else "Fail $result"
}
@@ -0,0 +1,13 @@
// KT-5123
import java.util.Collections
import java.util.ArrayList
fun box(): String {
val numbers = ArrayList<Int>()
numbers.add(1)
numbers.add(2)
numbers.add(3)
(Collections::rotate)(numbers, 1)
return if ("$numbers" == "[3, 1, 2]") "OK" else "Fail $numbers"
}
@@ -0,0 +1,23 @@
// FILE: test/A.java
package test
import java.util.Arrays;
public class A {
public static void main(String[] args) {
System.out.println(Arrays.asList(args));
}
}
// FILE: 1.kt
import kotlin.reflect.*
import test.A
fun foo(args: Array<String>) {
val main2 = A::main
main2 : KFunction1<Array<String>, Unit>
main2(args)
(A::main)(args)
}
@@ -0,0 +1,3 @@
package
internal fun foo(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
@@ -289,6 +289,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
doTest(fileName);
}
@TestMetadata("javaStaticMethod.kt")
public void testJavaStaticMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/callableReference/function/javaStaticMethod.kt");
doTest(fileName);
}
@TestMetadata("lhsNotAClass.kt")
public void testLhsNotAClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/callableReference/function/lhsNotAClass.kt");
@@ -111,6 +111,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod
doTestAgainstJava(fileName);
}
@TestMetadata("staticMethod.kt")
public void testStaticMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/callableReference/staticMethod.kt");
doTestAgainstJava(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxAgainstJava/constructor")
@@ -297,6 +297,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("enumValueOfMethod.kt")
public void testEnumValueOfMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/enumValueOfMethod.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("equalsIntrinsic.kt")
public void testEqualsIntrinsic() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/equalsIntrinsic.kt");
@@ -369,6 +375,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("javaCollectionsStaticMethod.kt")
public void testJavaCollectionsStaticMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/javaCollectionsStaticMethod.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("nestedConstructorFromClass.kt")
public void testNestedConstructorFromClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/nestedConstructorFromClass.kt");