JS: rewrite stdlib to compile with new flat structure
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.js
|
||||
|
||||
import kotlin.annotation.AnnotationTarget.*
|
||||
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER)
|
||||
@native annotation class JsName(val name: String)
|
||||
|
||||
@native annotation class native
|
||||
|
||||
@native fun js(code: String): dynamic
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin
|
||||
|
||||
class Enum<T : Enum<T>> : Comparable<Enum<T>> {
|
||||
@JsName("name$") private var _name: String = ""
|
||||
@JsName("ordinal$") private var _ordinal: Int = 0
|
||||
|
||||
val name: String
|
||||
get() = _name
|
||||
|
||||
val ordinal: Int
|
||||
get() = _ordinal
|
||||
|
||||
override fun compareTo(other: Enum<T>) = ordinal.compareTo(other.ordinal)
|
||||
|
||||
override fun toString() = name
|
||||
}
|
||||
|
||||
interface Annotation
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package kotlin.js.internal
|
||||
|
||||
private object DoubleCompanionObject {
|
||||
@JsName("DoubleCompanionObject") private object DoubleCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Double = js("Number.MIN_VALUE")
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Double = js("Number.MAX_VALUE")
|
||||
@JsName("POSITIVE_INFINITY") val POSITIVE_INFINITY: Double = js("Number.POSITIVE_INFINITY")
|
||||
@@ -24,7 +24,7 @@ private object DoubleCompanionObject {
|
||||
@JsName("NaN") val NaN: Double = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object FloatCompanionObject {
|
||||
@JsName("FloatCompanionObject") private object FloatCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Float = js("Number.MIN_VALUE")
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Float = js("Number.MAX_VALUE")
|
||||
@JsName("POSITIVE_INFINITY") val POSITIVE_INFINITY: Float = js("Number.POSITIVE_INFINITY")
|
||||
@@ -32,27 +32,27 @@ private object FloatCompanionObject {
|
||||
@JsName("NaN") val NaN: Float = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object IntCompanionObject {
|
||||
@JsName("IntCompanionObject") private object IntCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Int = -2147483647 - 1
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Int = 2147483647
|
||||
}
|
||||
|
||||
private object LongCompanionObject {
|
||||
@JsName("LongCompanionObject") private object LongCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Long = js("Kotlin.Long.MIN_VALUE")
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Long = js("Kotlin.Long.MAX_VALUE")
|
||||
}
|
||||
|
||||
private object ShortCompanionObject {
|
||||
@JsName("ShortCompanionObject") private object ShortCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Short = -32768
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Short = 32767
|
||||
}
|
||||
|
||||
private object ByteCompanionObject {
|
||||
@JsName("ByteCompanionObject") private object ByteCompanionObject {
|
||||
@JsName("MIN_VALUE") val MIN_VALUE: Byte = -128
|
||||
@JsName("MAX_VALUE") val MAX_VALUE: Byte = 127
|
||||
}
|
||||
|
||||
private object CharCompanionObject {
|
||||
@JsName("CharCompanionObject") private object CharCompanionObject {
|
||||
@JsName("MIN_HIGH_SURROGATE") public const val MIN_HIGH_SURROGATE: Char = '\uD800'
|
||||
@JsName("MAX_HIGH_SURROGATE") public const val MAX_HIGH_SURROGATE: Char = '\uDBFF'
|
||||
@JsName("MIN_LOW_SURROGATE") public const val MIN_LOW_SURROGATE: Char = '\uDC00'
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@JsName("arrayIterator")
|
||||
internal fun arrayIterator(array: dynamic): MutableIterator<dynamic> {
|
||||
return object : MutableIterator<dynamic> {
|
||||
var index = 0;
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
val length: Int = array.length
|
||||
return index < length
|
||||
}
|
||||
|
||||
override fun next() = array[index++]
|
||||
|
||||
override fun remove() {
|
||||
array.splice(--index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,41 +16,28 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
@library
|
||||
public open class Error(message: String? = null) : Throwable(message) {}
|
||||
open class Error(message: String? = null) : Throwable(message, null) {}
|
||||
|
||||
@library
|
||||
public open class Exception(message: String? = null) : Throwable(message) {}
|
||||
open class Exception(message: String? = null) : Throwable(message, null) {}
|
||||
|
||||
@library
|
||||
public open class RuntimeException(message: String? = null) : Exception(message) {}
|
||||
open class RuntimeException(message: String? = null) : Exception(message) {}
|
||||
|
||||
@library
|
||||
public open class IllegalArgumentException(message: String? = null) : RuntimeException(message) {}
|
||||
open class IllegalArgumentException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class IllegalStateException(message: String? = null) : RuntimeException(message) {}
|
||||
open class IllegalStateException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class IndexOutOfBoundsException(message: String? = null) : RuntimeException(message) {}
|
||||
open class IndexOutOfBoundsException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class ConcurrentModificationException(message: String? = null) : RuntimeException(message) {}
|
||||
open class ConcurrentModificationException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class UnsupportedOperationException(message: String? = null) : RuntimeException(message) {}
|
||||
open class UnsupportedOperationException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class NumberFormatException(message: String? = null) : RuntimeException(message) {}
|
||||
open class NumberFormatException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class NullPointerException(message: String? = null) : RuntimeException(message) {}
|
||||
open class NullPointerException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class ClassCastException(message: String? = null) : RuntimeException(message) {}
|
||||
open class ClassCastException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
public open class AssertionError(message: String? = null) : Error(message) {}
|
||||
open class AssertionError(message: String? = null) : Error(message) {}
|
||||
|
||||
@library
|
||||
public open class NoSuchElementException(message: String? = null) : Exception() {}
|
||||
open class NoSuchElementException(message: String? = null) : Exception() {}
|
||||
|
||||
@@ -17,25 +17,50 @@
|
||||
package java.lang
|
||||
|
||||
|
||||
@library
|
||||
public interface Appendable {
|
||||
public fun append(csq: CharSequence?): Appendable
|
||||
public fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
||||
public fun append(c: Char): Appendable
|
||||
interface Appendable {
|
||||
fun append(csq: CharSequence?): Appendable
|
||||
fun append(csq: CharSequence?, start: Int, end: Int): Appendable
|
||||
fun append(c: Char): Appendable
|
||||
}
|
||||
|
||||
@library
|
||||
public class StringBuilder(content: String = "") : Appendable, CharSequence {
|
||||
override val length: Int = noImpl
|
||||
override fun get(index: Int): Char = noImpl
|
||||
override fun subSequence(start: Int, end: Int): CharSequence = noImpl
|
||||
override fun append(c: Char): StringBuilder = noImpl
|
||||
override fun append(csq: CharSequence?): StringBuilder = noImpl
|
||||
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder = noImpl
|
||||
public fun append(obj: Any?): StringBuilder = noImpl
|
||||
public fun reverse(): StringBuilder = noImpl
|
||||
override fun toString(): String = noImpl
|
||||
}
|
||||
class StringBuilder(content: String = "") : Appendable, CharSequence {
|
||||
constructor(capacity: Int) : this() {}
|
||||
|
||||
public inline fun StringBuilder(capacity: Int): StringBuilder = StringBuilder()
|
||||
public inline fun StringBuilder(content: CharSequence): StringBuilder = StringBuilder(content.toString())
|
||||
constructor(content: CharSequence) : this(content.toString()) {}
|
||||
|
||||
private var string: String = content
|
||||
|
||||
override val length: Int = string.length
|
||||
|
||||
override fun get(index: Int): Char = string[index]
|
||||
|
||||
override fun subSequence(start: Int, end: Int): CharSequence = string.substring(start, end)
|
||||
|
||||
override fun append(c: Char): StringBuilder {
|
||||
string += c
|
||||
return this
|
||||
}
|
||||
|
||||
override fun append(csq: CharSequence?): StringBuilder {
|
||||
string += csq.toString()
|
||||
return this
|
||||
}
|
||||
|
||||
override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder {
|
||||
string += csq.toString().substring(start, end)
|
||||
return this
|
||||
}
|
||||
|
||||
fun append(obj: Any?): StringBuilder {
|
||||
string += obj.toString()
|
||||
return this
|
||||
}
|
||||
|
||||
fun reverse(): StringBuilder {
|
||||
val nativeString: dynamic = string
|
||||
string = nativeString.split("").reverse().join("")
|
||||
return this
|
||||
}
|
||||
|
||||
override fun toString(): String = string
|
||||
}
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package java.util
|
||||
|
||||
@library
|
||||
public interface Comparator<T> {
|
||||
public fun compare(a: T, b: T): Int
|
||||
interface Comparator<T> {
|
||||
@JsName("compare") fun compare(a: T, b: T): Int
|
||||
}
|
||||
|
||||
public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||
inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||
override fun compare(a: T, b: T): Int = comparison(a, b)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user