added test for object
This commit is contained in:
@@ -16,6 +16,7 @@ public final class Namer {
|
|||||||
private static final String CLASS_OBJECT_NAME = "Class";
|
private static final String CLASS_OBJECT_NAME = "Class";
|
||||||
private static final String TRAIT_OBJECT_NAME = "Trait";
|
private static final String TRAIT_OBJECT_NAME = "Trait";
|
||||||
private static final String NAMESPACE_OBJECT_NAME = "Namespace";
|
private static final String NAMESPACE_OBJECT_NAME = "Namespace";
|
||||||
|
private static final String OBJECT_OBJECT_NAME = "object";
|
||||||
private static final String SETTER_PREFIX = "set_";
|
private static final String SETTER_PREFIX = "set_";
|
||||||
private static final String GETTER_PREFIX = "get_";
|
private static final String GETTER_PREFIX = "get_";
|
||||||
private static final String BACKING_FIELD_PREFIX = "$";
|
private static final String BACKING_FIELD_PREFIX = "$";
|
||||||
@@ -76,6 +77,8 @@ public final class Namer {
|
|||||||
private final JsName traitName;
|
private final JsName traitName;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final JsName namespaceName;
|
private final JsName namespaceName;
|
||||||
|
@NotNull
|
||||||
|
private final JsName objectName;
|
||||||
|
|
||||||
private Namer(@NotNull JsScope rootScope) {
|
private Namer(@NotNull JsScope rootScope) {
|
||||||
kotlinName = rootScope.declareName(KOTLIN_OBJECT_NAME);
|
kotlinName = rootScope.declareName(KOTLIN_OBJECT_NAME);
|
||||||
@@ -83,6 +86,7 @@ public final class Namer {
|
|||||||
traitName = kotlinScope.declareName(TRAIT_OBJECT_NAME);
|
traitName = kotlinScope.declareName(TRAIT_OBJECT_NAME);
|
||||||
namespaceName = kotlinScope.declareName(NAMESPACE_OBJECT_NAME);
|
namespaceName = kotlinScope.declareName(NAMESPACE_OBJECT_NAME);
|
||||||
className = kotlinScope.declareName(CLASS_OBJECT_NAME);
|
className = kotlinScope.declareName(CLASS_OBJECT_NAME);
|
||||||
|
objectName = kotlinScope.declareName(OBJECT_OBJECT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -100,6 +104,11 @@ public final class Namer {
|
|||||||
return kotlin(createMethodReference(namespaceName));
|
return kotlin(createMethodReference(namespaceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JsNameRef objectCreationMethodReference() {
|
||||||
|
return kotlin(createMethodReference(objectName));
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsNameRef createMethodReference(@NotNull JsName name) {
|
private JsNameRef createMethodReference(@NotNull JsName name) {
|
||||||
JsNameRef qualifier = name.makeRef();
|
JsNameRef qualifier = name.makeRef();
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.jetbrains.k2js.test;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public class ObjectTest extends TranslationTest {
|
||||||
|
|
||||||
|
private static final String MAIN = "object/";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String mainDirectory() {
|
||||||
|
return MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void objectWithMethods() throws Exception {
|
||||||
|
testFooBoxIsTrue("objectWithMethods.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
val a = object {
|
||||||
|
fun c() = 3
|
||||||
|
fun b() = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : Boolean {
|
||||||
|
|
||||||
|
|
||||||
|
if (a.c() != 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (a.b() != 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user