Merge remote-tracking branch 'origin/master'

Conflicts:
	js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java
	js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestToJSTest.java
This commit is contained in:
Pavel V. Talanov
2012-07-04 18:32:24 +04:00
158 changed files with 4376 additions and 1097 deletions
@@ -184,27 +184,21 @@ public inline fun <T> Array<T>.reduceRight(operation: (T, T) -> T): T = reverse(
*/
public inline fun <T, K> Array<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Array<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun <T> Array<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Bool
*/
public inline fun <K> BooleanArray.groupBy(toKey: (Boolean) -> K) : Map<K, List<Boolean>> = groupByTo<K>(HashMap<K, List<Boolean>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> BooleanArray.groupByTo(result: Map<K, List<Boolean>>, toKey: (Boolean) -> K) : Map<K, List<Boolean>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Boolean>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun BooleanArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte): Byte =
*/
public inline fun <K> ByteArray.groupBy(toKey: (Byte) -> K) : Map<K, List<Byte>> = groupByTo<K>(HashMap<K, List<Byte>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> ByteArray.groupByTo(result: Map<K, List<Byte>>, toKey: (Byte) -> K) : Map<K, List<Byte>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Byte>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun ByteArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun CharArray.reduceRight(operation: (Char, Char) -> Char): Char =
*/
public inline fun <K> CharArray.groupBy(toKey: (Char) -> K) : Map<K, List<Char>> = groupByTo<K>(HashMap<K, List<Char>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> CharArray.groupByTo(result: Map<K, List<Char>>, toKey: (Char) -> K) : Map<K, List<Char>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Char>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun CharArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double)
*/
public inline fun <K> DoubleArray.groupBy(toKey: (Double) -> K) : Map<K, List<Double>> = groupByTo<K>(HashMap<K, List<Double>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> DoubleArray.groupByTo(result: Map<K, List<Double>>, toKey: (Double) -> K) : Map<K, List<Double>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Double>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun DoubleArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float): Fl
*/
public inline fun <K> FloatArray.groupBy(toKey: (Float) -> K) : Map<K, List<Float>> = groupByTo<K>(HashMap<K, List<Float>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> FloatArray.groupByTo(result: Map<K, List<Float>>, toKey: (Float) -> K) : Map<K, List<Float>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Float>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun FloatArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int): Int = reve
*/
public inline fun <K> IntArray.groupBy(toKey: (Int) -> K) : Map<K, List<Int>> = groupByTo<K>(HashMap<K, List<Int>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> IntArray.groupByTo(result: Map<K, List<Int>>, toKey: (Int) -> K) : Map<K, List<Int>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Int>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun IntArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -26,29 +26,3 @@ public inline fun <T, R, C: Collection<in R>> java.lang.Iterable<T>.mapTo(result
result.add(transform(item))
return result
}
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JUtilCollectionsJVM.kt
//
import java.util.*
//
// This file contains methods which are optimised for working on Collection / Array collections where the size
// could be used to implement a more optimal solution
//
// See [[GenerateStandardLib.kt]] for more details
//
/**
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
*
* @includeFunctionBody ../../test/CollectionTest.kt map
*/
public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(), transform)
}
@@ -0,0 +1,27 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JUtilCollectionsJVM.kt
//
import java.util.*
//
// This file contains methods which are optimised for working on Collection / Array collections where the size
// could be used to implement a more optimal solution
//
// See [[GenerateStandardLib.kt]] for more details
//
/**
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
*
* @includeFunctionBody ../../test/CollectionTest.kt map
*/
public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(), transform)
}
@@ -182,27 +182,21 @@ public inline fun <T> java.util.Iterator<T>.reduceRight(operation: (T, T) -> T):
*/
public inline fun <T, K> java.util.Iterator<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> java.util.Iterator<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun <T> java.util.Iterator<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -267,17 +261,3 @@ public inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) :
return answer
}
*/
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JLangIterablesJVM.kt
//
import java.util.*
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -0,0 +1,15 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JLangIterablesJVM.kt
//
import java.util.*
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -184,27 +184,21 @@ public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long): Long =
*/
public inline fun <K> LongArray.groupBy(toKey: (Long) -> K) : Map<K, List<Long>> = groupByTo<K>(HashMap<K, List<Long>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> LongArray.groupByTo(result: Map<K, List<Long>>, toKey: (Long) -> K) : Map<K, List<Long>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Long>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun LongArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short): Sh
*/
public inline fun <K> ShortArray.groupBy(toKey: (Short) -> K) : Map<K, List<Short>> = groupByTo<K>(HashMap<K, List<Short>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <K> ShortArray.groupByTo(result: Map<K, List<Short>>, toKey: (Short) -> K) : Map<K, List<Short>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<Short>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun ShortArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -184,27 +184,21 @@ public inline fun <T> Iterable<T>.reduceRight(operation: (T, T) -> T): T = rever
*/
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Iterable<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
list.add(element)
val some = key
val more = some
val onceMore = more
val again = println(more)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
@@ -1,7 +1,7 @@
package kotlin.browser
import org.w3c.dom.Document
import js.native
import org.w3c.dom.Document
private var _document: Document? = null
@@ -9,7 +9,13 @@ private var _document: Document? = null
* Provides access to the current active browsers DOM for the currently visible page.
*/
native public var document: Document
get() = _document!!
set(value) {
_document = value
}
get() {
// Note this code is only executed on the JVM
val answer = _document
return if (answer == null) {
kotlin.dom.createDocument()
} else answer
}
set(value) {
_document = value
}
+20 -1
View File
@@ -311,6 +311,25 @@ val NodeList?.last : Node?
get() = this.tail
/** Converts the node list to an XML String */
fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
return if (this == null)
"" else {
nodesToXmlString(this.toList(), xmlDeclaration)
}
}
/** Converts the collection of nodes to an XML String */
public fun nodesToXmlString(nodes: java.lang.Iterable<Node>, xmlDeclaration: Boolean = false): String {
// TODO this should work...
// return this.map<Node,String>{it.toXmlString()}.makeString("")
val builder = StringBuilder()
for (n in nodes) {
builder.append(n.toXmlString(xmlDeclaration))
}
return builder.toString().sure()
}
// Syntax sugar
inline fun Node.plus(child: Node?): Node {
@@ -381,7 +400,7 @@ Adds a newly created text node to an element which either already has an owner D
*/
fun Element.addText(text: String?, doc: Document? = null): Element {
if (text != null) {
val child = ownerDocument(doc).createTextNode(text)
val child = this.ownerDocument(doc).createTextNode(text)
this.appendChild(child)
}
return this
+4 -19
View File
@@ -153,13 +153,6 @@ fun Element.removeClass(cssClass: String): Boolean {
}
/** Converts the node list to an XML String */
fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
return if (this == null)
"" else {
nodesToXmlString(this.toList(), xmlDeclaration)
}
}
/** Creates a new document with the given document builder*/
public fun createDocument(builder: DocumentBuilder): Document {
@@ -225,7 +218,10 @@ public fun createTransformer(source: Source? = null, factory: TransformerFactory
}
/** Converts the node to an XML String */
public fun Node.toXmlString(xmlDeclaration: Boolean = false): String {
public fun Node.toXmlString(): String = toXmlString(false)
/** Converts the node to an XML String */
public fun Node.toXmlString(xmlDeclaration: Boolean): String {
val writer = StringWriter()
writeXmlString(writer, xmlDeclaration)
return writer.toString().sure()
@@ -237,14 +233,3 @@ public fun Node.writeXmlString(writer: Writer, xmlDeclaration: Boolean): Unit {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, if (xmlDeclaration) "no" else "yes")
transformer.transform(DOMSource(this), StreamResult(writer))
}
/** Converts the collection of nodes to an XML String */
public fun nodesToXmlString(nodes: java.lang.Iterable<Node>, xmlDeclaration: Boolean = false): String {
// TODO this should work...
// return this.map<Node,String>{it.toXmlString()}.makeString("")
val builder = StringBuilder()
for (n in nodes) {
builder.append(n.toXmlString(xmlDeclaration))
}
return builder.toString().sure()
}
@@ -21,10 +21,17 @@ class ClasspathBuilder(val parent: ModuleBuilder) {
}
}
class AnnotationsPathBuilder(val parent: ModuleBuilder) {
public fun plusAssign(name: String) {
parent.addAnnotationsPathEntry(name)
}
}
open class ModuleBuilder(val name: String): Module {
// http://youtrack.jetbrains.net/issue/KT-904
private val sourceFiles0: ArrayList<String?> = ArrayList<String?>()
private val classpathRoots0: ArrayList<String?> = ArrayList<String?>()
private val annotationsRoots0: ArrayList<String?> = ArrayList<String?>()
val sources: SourcesBuilder
get() = SourcesBuilder(this)
@@ -32,6 +39,9 @@ open class ModuleBuilder(val name: String): Module {
val classpath: ClasspathBuilder
get() = ClasspathBuilder(this)
val annotationsPath: AnnotationsPathBuilder
get() = AnnotationsPathBuilder(this)
public fun addSourceFiles(pattern: String) {
sourceFiles0.add(pattern)
}
@@ -40,8 +50,13 @@ open class ModuleBuilder(val name: String): Module {
classpathRoots0.add(name)
}
public fun addAnnotationsPathEntry(name: String) {
annotationsRoots0.add(name)
}
public override fun getSourceFiles(): List<String?>? = sourceFiles0
public override fun getClasspathRoots(): List<String?>? = classpathRoots0
public override fun getAnnotationsRoots(): List<String?>? = annotationsRoots0
public override fun getModuleName(): String? = name
}
@@ -5,7 +5,7 @@ import java.util.NoSuchElementException
// TODO should not need this - its here for the JS stuff
import java.lang.UnsupportedOperationException
enum class State {
public enum class State {
Ready
NotReady
Done