KT-12877: fix how native calls and property references are translated to be make them work with JsModule annotation

This commit is contained in:
Alexey Andreev
2016-06-29 15:33:02 +03:00
committed by Alexey Andreev
parent ac703dfda6
commit b1d8f91212
9 changed files with 67 additions and 22 deletions
@@ -82,8 +82,7 @@ object CallTranslator {
return DefaultFunctionCallCase.buildDefaultCallWithDispatchReceiver(argumentsInfo, dispatchReceiver, functionName, isNative,
hasSpreadOperator)
} else {
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative,
hasSpreadOperator)
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative, hasSpreadOperator)
}
}
}
@@ -59,7 +59,7 @@ object NativeVariableAccessCase : VariableAccessCase() {
JsInvocation(methodRef, *additionalArguments.toTypedArray())
}
else {
constructAccessExpression(variableName.makeRef())
constructAccessExpression(context.getQualifiedReference(callableDescriptor))
}
}
}
@@ -235,19 +235,7 @@ public final class StaticContext {
@NotNull
private JsExpression buildQualifiedExpression(@NotNull DeclarationDescriptor descriptor) {
String moduleName = AnnotationsUtils.getModuleName(descriptor);
if (moduleName != null) {
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
}
if (isNativeObject(descriptor)) {
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), descriptor);
if (fileModuleName != null) {
return pureFqn(getNameForDescriptor(descriptor), pureFqn(getModuleInternalName(fileModuleName), null));
}
}
if (descriptor instanceof ClassDescriptor) {
if (descriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
if (KotlinBuiltIns.isAny(classDescriptor)) {
return pureFqn("Object", null);
@@ -261,6 +249,18 @@ public final class StaticContext {
return result != null ? result : pureFqn(Namer.getRootPackageName(), null);
}
String moduleName = AnnotationsUtils.getModuleName(suggested.getDescriptor());
if (moduleName != null) {
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
}
if (isNativeObject(suggested.getDescriptor())) {
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), suggested.getDescriptor());
if (fileModuleName != null) {
return pureFqn(getNameForDescriptor(suggested.getDescriptor()), pureFqn(getModuleInternalName(fileModuleName), null));
}
}
JsExpression expression;
List<JsName> partNames = getActualNameFromSuggested(suggested);
if (isLibraryObject(suggested.getDescriptor())) {
+1 -1
View File
@@ -24,7 +24,7 @@ fun box(): String {
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(23))
assertEquals(365, foo(42))
assertEquals(423, bar)
return "OK"
@@ -35,7 +35,7 @@ fun box(): String {
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(23))
assertEquals(365, foo(42))
assertEquals(423, bar)
assertEquals(12345, C.f())
@@ -32,7 +32,7 @@ fun box(): String {
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(23))
assertEquals(365, foo(42))
assertEquals(423, bar)
return "OK"
@@ -0,0 +1,30 @@
@file:JsModule("lib")
package foo
@native class A(@native val x: Int = noImpl) {
@native fun foo(y: Int): Int = noImpl
}
@native object B {
@native val x: Int = noImpl
@native fun foo(y: Int): Int = noImpl
}
@native fun foo(y: Int): Int = noImpl
@native val bar: Int = noImpl
fun box(): String {
val a = A(23)
assertEquals(23, a.x)
assertEquals(65, a.foo(42))
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(42))
assertEquals(423, bar)
return "OK"
}
@@ -0,0 +1,17 @@
package foo
fun box(): String {
val a = A(23)
assertEquals(23, a.x)
assertEquals(65, a.foo(42))
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(42))
assertEquals(423, bar)
assertEquals(12345, C.f())
return "OK"
}
@@ -8,9 +8,8 @@ fun box(): String {
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
/* TODO: get rid of usages of getQualifier, then uncomment it (it's already fixed by js-name branch)
assertEquals(365, foo(23))
assertEquals(423, bar)*/
assertEquals(365, foo(42))
assertEquals(423, bar)
return "OK"
}