refactored the JS kotlin code so that we've a simple naming convention (*Code.kt") to refer to library code which needs to generate JS code to separate those files from the pure definitions which just refer to existing JS code already - this will help make it easier to keep the maven build and the js test cases in sync

This commit is contained in:
James Strachan
2012-07-05 10:34:00 +01:00
parent 038f79a77a
commit 925e5b2236
12 changed files with 93 additions and 66 deletions
+2
View File
@@ -35,10 +35,12 @@ public trait Runnable {
public open fun run() : Unit;
}
library
public trait Comparable<T> {
public fun compareTo(that: T): Int
}
library
public trait Appendable {
public open fun append(csq: CharSequence?): Appendable?
public open fun append(csq: CharSequence?, start: Int, end: Int): Appendable?
+2 -38
View File
@@ -17,48 +17,12 @@ public trait Iterator<T> {
open public fun remove() : Unit = js.noImpl
}
public object Collections {
library("collectionsMax")
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = js.noImpl
// TODO should be immutable!
public val emptyList: List<Any> = ArrayList<Any>()
public val emptyMap: Map<Any, Any> = HashMap<Any,Any>()
public val <T> EMPTY_LIST: List<T>
get() = emptyList<T>()
public val <K,V> EMPTY_MAP: Map<K,V>
get() = emptyMap<K,V>()
public fun <T> emptyList(): List<T> = emptyList as List<T>
public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V>
public fun <in T> sort(list: List<T>): Unit {
throw UnsupportedOperationException()
}
public fun <in T> sort(list: List<T>, comparator: java.util.Comparator<T>): Unit {
throw UnsupportedOperationException()
}
public fun <T> reverse(list: List<T>): Unit {
val size = list.size()
for (i in 0.upto(size / 2)) {
val i2 = size - i
val tmp = list[i]
list[i] = list[i2]
list[i2] = tmp
}
}
}
library
public trait Collection<E>: Iterable<E> {
open public fun size(): Int
open public fun isEmpty(): Boolean
open public fun contains(o: Any?): Boolean
override public fun iterator(): Iterator<E>
override public fun iterator(): java.util.Iterator<E>
public fun toArray(): Array<E>
// open public fun toArray<T>(a : Array<out T>) : Array<T>
open public fun add(e: E): Boolean
@@ -76,7 +40,7 @@ public abstract class AbstractCollection<E>() : Collection<E> {
override public fun isEmpty(): Boolean = js.noImpl
override public fun contains(o: Any?): Boolean = js.noImpl
override public fun iterator(): Iterator<E> = js.noImpl
override public fun iterator(): java.util.Iterator<E> = js.noImpl
override public fun add(e: E): Boolean = js.noImpl
override public fun remove(o: Any?): Boolean = js.noImpl
+39
View File
@@ -0,0 +1,39 @@
package java.util
import java.lang.*
public object Collections {
library("collectionsMax")
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = js.noImpl
// TODO should be immutable!
public val emptyList: List<Any> = ArrayList<Any>()
public val emptyMap: Map<Any, Any> = HashMap<Any,Any>()
public val <T> EMPTY_LIST: List<T>
get() = emptyList<T>()
public val <K,V> EMPTY_MAP: Map<K,V>
get() = emptyMap<K,V>()
public fun <T> emptyList(): List<T> = emptyList as List<T>
public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V>
public fun <in T> sort(list: List<T>): Unit {
throw UnsupportedOperationException()
}
public fun <in T> sort(list: List<T>, comparator: java.util.Comparator<T>): Unit {
throw UnsupportedOperationException()
}
public fun <T> reverse(list: List<T>): Unit {
val size = list.size()
for (i in 0.upto(size / 2)) {
val i2 = size - i
val tmp = list[i]
list[i] = list[i2]
list[i2] = tmp
}
}
}
@@ -12,7 +12,8 @@ native public fun String.indexOf(str : String, fromIndex : Int) : Int = js.noImp
native public fun String.lastIndexOf(str: String) : Int = js.noImpl
native public fun String.lastIndexOf(str : String, fromIndex : Int) : Int = js.noImpl
native public fun String.split(regex : String) : Array<String> = js.noImpl
// Defined in javalang.kt
//native public fun String.split(regex : String) : Array<String> = js.noImpl
native public fun String.substring(beginIndex : Int) : String = js.noImpl
native public fun String.substring(beginIndex : Int, endIndex : Int) : String = js.noImpl
@@ -56,28 +56,31 @@ public abstract class Config {
@NotNull
public static final List<String> LIB_FILES_WITH_DECLARATIONS = Arrays.asList(
"/core/annotations.kt",
"/jquery/common.kt",
"/jquery/ui.kt",
"/core/javautil.kt",
"/core/javalang.kt",
"/core/javaio.kt",
"/core/kotlin.kt",
"/core/date.kt",
"/core/core.kt",
"/core/math.kt",
"/core/json.kt",
"/stdlib/browser.kt",
"/core/date.kt",
"/core/dom.kt",
"/core/javaio.kt",
"/core/javalang.kt",
"/core/javautil.kt",
"/core/json.kt",
"/core/kotlin.kt",
"/core/math.kt",
"/core/string.kt",
"/dom/domcore.kt",
"/dom/html/htmlcore.kt",
"/dom/html5/canvas.kt",
"/dom/html/window.kt",
"/jquery/common.kt",
"/jquery/ui.kt",
"/junit/core.kt",
"/qunit/core.kt"
"/qunit/core.kt",
"/stdlib/browser.kt"
);
@NotNull
public static final List<String> LIB_FILES_WITH_CODE = Lists.newArrayList();
public static final List<String> LIB_FILES_WITH_CODE = Arrays.asList(
"/core/javautilCode.kt"
);
@NotNull
public static final List<String> LIB_FILE_NAMES = Lists.newArrayList();
@@ -91,12 +94,11 @@ public abstract class Config {
*/
@NotNull
public static final List<String> LIB_FILE_NAMES_DEPENDENT_ON_STDLIB = Arrays.asList(
"/stdlib/dom.kt",
"/stdlib/jutil.kt",
//"/stdlib/JUMaps.kt",
"/stdlib/test.kt",
"/core/stringDefs.kt",
"/core/strings.kt"
"/core/stringsCode.kt",
"/stdlib/domCode.kt",
"/stdlib/jutilCode.kt",
//"/stdlib/JUMapsCode.kt",
"/stdlib/testCode.kt"
);
public static final String LIBRARIES_LOCATION = "js/js.libraries/src";
+18
View File
@@ -161,6 +161,24 @@ var kotlin = {set:function (receiver, key, value) {
}
});
Kotlin.Runnable = Kotlin.$createClass({
initialize: function () {
},
run: throwAbstractFunctionInvocationError
});
Kotlin.Comparable = Kotlin.$createClass({
initialize: function () {
},
compareTo: throwAbstractFunctionInvocationError
});
Kotlin.Appendable = Kotlin.$createClass({
initialize: function () {
},
append: throwAbstractFunctionInvocationError
});
Kotlin.parseInt = function (str) {
return parseInt(str, 10);
};
+10 -9
View File
@@ -31,25 +31,20 @@
<mkdir dir="${basedir}/target/generated-js-definitions"/>
<copy todir="${basedir}/target/generated-js-definitions">
<fileset dir="${kotlin-js-lib-srcdir}">
<exclude name="**/*Code.kt"/>
<exclude name="core/dom/core.kt"/>
<exclude name="core/strings.kt"/>
<exclude name="html5/localstorage.kt"/>
<exclude name="jquery/common.kt"/>
<exclude name="jquery/ui.kt"/>
<exclude name="dom/html/htmlcore.kt"/>
<exclude name="dom/html5/canvas.kt"/>
<exclude name="dom/html/window.kt"/>
<exclude name="stdlib/test.kt"/>
<exclude name="stdlib/dom.kt"/>
<exclude name="stdlib/jutil.kt"/>
</fileset>
</copy>
<copy todir="${basedir}/target/generated-js-library">
<fileset dir="${kotlin-js-lib-srcdir}">
<include name="stdlib/test.kt"/>
<include name="stdlib/jutil.kt"/>
<include name="stdlib/dom.kt"/>
<include name="core/strings.kt"/>
<include name="**/*Code.kt"/>
<exclude name="**/JUtilMapsCode.kt"/>
</fileset>
</copy>
<copy todir="${basedir}/target/generated-js-library/kotlin">
@@ -70,16 +65,22 @@
<include name="Iterators.kt"/>
<include name="JUtil.kt"/>
<include name="JUtilCollections.kt"/>
<!--
<include name="JUtilMaps.kt"/>
-->
<include name="JLangIterables.kt"/>
<include name="JLangIterablesLazy.kt"/>
<include name="JLangIterablesSpecial.kt"/>
<include name="JLangIterablesSpecial.kkt"/>
<!--
<include name="Ordering.kt"/>
-->
<include name="Standard.kt"/>
<include name="Strings.kt"/>
</fileset>
<fileset dir="${basedir}/../../stdlib/src/generated">
<include name="JUtilIteratorsFromJLangIterables.kt"/>
<include name="JUtilIterablesFromJUtilCollections.kt"/>
</fileset>
</copy>
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib.js"
file="${kotlin-js-lib-srcdir}/../../js.translator/testFiles/kotlin_lib.js"/>