JS backend: native trait exists only at compile time.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
@@ -36,8 +37,13 @@ public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
@Override
|
||||
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion));
|
||||
result.add(pathToTestFiles() + NATIVE + "/" + getTestName(true) + ".js");
|
||||
//result.addAll(JsTestUtils.getAllFilesInDir(pathToTestFiles() + NATIVE));
|
||||
|
||||
String jsFilePath = pathToTestFiles() + NATIVE + "/" + getTestName(true) + ".js";
|
||||
File jsFile = new File(jsFilePath);
|
||||
if (jsFile.exists() && jsFile.isFile()) {
|
||||
result.add(jsFilePath);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,6 +55,10 @@ public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testInheritanceFromNativeTrait() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClass() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.isNativeObject;
|
||||
|
||||
public final class JsDescriptorUtils {
|
||||
// TODO: maybe we should use external annotations or something else.
|
||||
@@ -82,7 +83,9 @@ public final class JsDescriptorUtils {
|
||||
@Override
|
||||
public boolean value(JetType type) {
|
||||
ClassDescriptor classDescriptor = getClassDescriptorForType(type);
|
||||
return !FAKE_CLASSES.contains(getFqNameSafe(classDescriptor).asString());
|
||||
|
||||
return !FAKE_CLASSES.contains(getFqNameSafe(classDescriptor).asString()) &&
|
||||
!(classDescriptor.getKind() == ClassKind.TRAIT && isNativeObject(classDescriptor));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
trait NativeTrait {
|
||||
val foo: String
|
||||
fun bar(a: Int): Any
|
||||
|
||||
native("boo")
|
||||
fun baz(): String
|
||||
}
|
||||
|
||||
trait Trait : NativeTrait
|
||||
|
||||
class Class : NativeTrait {
|
||||
override val foo: String = "Class().foo"
|
||||
override fun bar(a: Int): Any = "Class().bar($a)"
|
||||
override fun baz(): String = "Class().boo()"
|
||||
}
|
||||
|
||||
class AnotherClass : Trait {
|
||||
override val foo: String = "AnotherClass().foo"
|
||||
override fun bar(a: Int): Any = "AnotherClass().bar($a)"
|
||||
override fun baz(): String = "AnotherClass().boo()"
|
||||
}
|
||||
|
||||
fun test<T : NativeTrait>(c: T, className: String) {
|
||||
assertEquals("$className().foo", c.foo)
|
||||
assertEquals("$className().bar(3)", c.bar(3))
|
||||
assertEquals("$className().boo()", c.baz())
|
||||
|
||||
val t: NativeTrait = c
|
||||
assertEquals("$className().foo", t.foo)
|
||||
assertEquals("$className().bar(3)", t.bar(3))
|
||||
assertEquals("$className().boo()", t.baz())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(Class(), "Class")
|
||||
test(AnotherClass(), "AnotherClass")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user