This commit is contained in:
Pavel Talanov
2011-12-14 13:35:59 +04:00
parent 9f66d644df
commit 9c91bf1163
6 changed files with 41 additions and 10 deletions
@@ -40,7 +40,7 @@ public final class K2JSTranslator {
public K2JSTranslator() {
}
public void translate(String inputFile, String outputFile) throws Exception {
public void translateFile(String inputFile, String outputFile) throws Exception {
try {
@@ -73,19 +73,21 @@ public final class StandardClasses {
ClassDescriptor iteratorClass = (ClassDescriptor)
standardLibrary.getLibraryScope().getClassifier("Iterator");
assert iteratorClass != null;
standardClasses.declareStandardTopLevelObject(iteratorClass, "ArrayIterator");
standardClasses.declareTopLevel(iteratorClass, "ArrayIterator");
declareMethods(standardClasses, getFQName(iteratorClass), "next", "hasNext");
}
private static void declareArray(@NotNull StandardClasses standardClasses,
@NotNull JetStandardLibrary standardLibrary) {
ClassDescriptor arrayClass = standardLibrary.getArray();
standardClasses.declareStandardTopLevelObject(arrayClass, "Array");
standardClasses.declareTopLevel(arrayClass, "Array");
FunctionDescriptor nullConstructorFunction = getFunctionByName(standardLibrary.getLibraryScope(), "Array");
standardClasses.declareStandardTopLevelObject(nullConstructorFunction, "array");
standardClasses.declareTopLevel(nullConstructorFunction, "array");
PropertyDescriptor sizeProperty =
getPropertyByName(arrayClass.getDefaultType().getMemberScope(), "size");
standardClasses.declareStandardInnerDeclaration(sizeProperty, "size");
standardClasses.declareInner(sizeProperty, "size");
PropertyDescriptor indices = getPropertyByName(arrayClass.getDefaultType().getMemberScope(), "indices");
standardClasses.declareInner(indices, "indices");
}
@@ -120,8 +122,8 @@ public final class StandardClasses {
this.kotlinScope = kotlinScope;
}
private void declareStandardTopLevelObject(@NotNull DeclarationDescriptor descriptor,
@NotNull String kotlinLibName) {
private void declareTopLevel(@NotNull DeclarationDescriptor descriptor,
@NotNull String kotlinLibName) {
declareStandardTopLevelObject(DescriptorUtils.getFQName(descriptor), kotlinLibName);
}
@@ -130,8 +132,8 @@ public final class StandardClasses {
scopeMap.put(fullQualifiedName, new JsScope(kotlinScope, "standard object " + kotlinLibName));
}
private void declareStandardInnerDeclaration(@NotNull DeclarationDescriptor descriptor,
@NotNull String kotlinLibName) {
private void declareInner(@NotNull DeclarationDescriptor descriptor,
@NotNull String kotlinLibName) {
String containingFQName = DescriptorUtils.getFQName(getContainingDeclaration(descriptor));
declareStandardInnerDeclaration(containingFQName, descriptor.getName(), kotlinLibName);
}
@@ -58,6 +58,23 @@ public final class SystemTest extends JavaClassesTest {
"Out: array has only 3 elements. x = 4\n" +
"Yes: array contains aaa\n" +
"No: array doesn't contains ddd\n", "4");
checkOutput("ranges.kt", " 1 2 3 4 5\n" +
"Out: array has only 3 elements. x = 10\n" +
"Yes: array contains aaa\n" +
"No: array doesn't contains ddd\n", "10");
}
@Test
public void forLoop() throws Exception {
checkOutput("forLoop.kt", "a\n" +
"b\n" +
"c\n" +
"\n" +
"a\n" +
"b\n" +
"c\n", "a", "b", "c");
checkOutput("forLoop.kt", "123\n\n123\n", "123");
}
}
@@ -57,7 +57,7 @@ public abstract class TranslationTest {
}
protected void translateFile(String filename) throws Exception {
(new K2JSTranslator()).translate(getInputFilePath(filename), getOutputFilePath(filename));
(new K2JSTranslator()).translateFile(getInputFilePath(filename), getOutputFilePath(filename));
}
protected List<String> generateFilenameList(String inputFile) {
@@ -0,0 +1,9 @@
fun main(args : Array<String>) {
for (arg in args)
System.out?.println(arg)
// or
System.out?.println()
for (i in args.indices)
System.out?.println(args[i])
}
+3
View File
@@ -493,6 +493,9 @@ Kotlin.Array = Class.create({
},
iterator:function () {
return new Kotlin.ArrayIterator(this);
},
indices:function() {
return new Kotlin.NumberRange(0, this.size(), false);
}
});