KJS: fix refering to native nested class

This commit is contained in:
Zalim Bashorov
2016-11-14 22:08:06 +03:00
parent bd90b4e051
commit a03e22e774
4 changed files with 49 additions and 5 deletions
@@ -3419,6 +3419,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("formNestedNativeClass.kt")
public void testFormNestedNativeClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inheritance/formNestedNativeClass.kt");
doTest(fileName);
}
@TestMetadata("fromFakeClasses.kt")
public void testFromFakeClasses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inheritance/fromFakeClasses.kt");
@@ -436,10 +436,6 @@ public final class StaticContext {
if (descriptor instanceof LocalVariableDescriptor || descriptor instanceof ParameterDescriptor) {
return getNameForDescriptor(descriptor);
}
if (isNativeObject(descriptor)) {
String name = getNameForAnnotatedObject(descriptor);
if (name != null) return rootFunction.getScope().declareName(name);
}
if (descriptor instanceof ConstructorDescriptor) {
if (((ConstructorDescriptor) descriptor).isPrimary()) {
return getInnerNameForDescriptor(((ConstructorDescriptor) descriptor).getConstructedClass());
@@ -694,7 +690,15 @@ public final class StaticContext {
List<JsStatement> statements = rootFunction.getBody().getStatements();
JsExpression superPrototype = JsAstUtils.prototypeOf(new JsNameRef(getInnerNameForDescriptor(superclass)));
JsNameRef superclassRef;
if (isNativeObject(superclass) || isLibraryObject(superclass)) {
superclassRef = getQualifiedReference(superclass);
}
else {
superclassRef = getInnerNameForDescriptor(superclass).makeRef();
}
JsExpression superPrototype = JsAstUtils.prototypeOf(superclassRef);
JsExpression superPrototypeInstance = new JsInvocation(new JsNameRef("create", "Object"), superPrototype);
JsExpression classRef = new JsNameRef(getInnerNameForDescriptor(cls));
JsExpression prototype = JsAstUtils.prototypeOf(classRef);
@@ -38,6 +38,8 @@ import java.util.*;
import static org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt.isCoroutineLambda;
import static org.jetbrains.kotlin.js.translate.context.UsageTrackerKt.getNameForCapturedDescriptor;
import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isLibraryObject;
import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject;
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getDescriptorForElement;
/**
@@ -232,6 +234,10 @@ public class TranslationContext {
@NotNull
public JsNameRef getInnerReference(@NotNull DeclarationDescriptor descriptor) {
if (isNativeObject(descriptor) || isLibraryObject(descriptor)) {
return getQualifiedReference(descriptor);
}
return JsAstUtils.pureFqn(getInnerNameForDescriptor(descriptor), null);
}
@@ -0,0 +1,28 @@
// FILE: foo.kt
package foo
@native
class A {
open class B {
fun foo(): String
}
}
class C : A.B()
fun box(): String {
return C().foo()
}
// FILE: bar.js
function A() {
}
A.B = function() {
};
A.B.prototype.foo = function() {
return "OK"
};