Minor: reformat code in JS stdlib

This commit is contained in:
Ilya Gorbunov
2016-03-10 05:02:11 +03:00
parent d7cda17d2a
commit d6506d9770
17 changed files with 68 additions and 64 deletions
+5 -1
View File
@@ -1,6 +1,6 @@
package kotlin.js package kotlin.js
import java.util.*; import java.util.*
@native @native
public val noImpl: Nothing public val noImpl: Nothing
@@ -16,16 +16,20 @@ public val undefined: Nothing? = noImpl
@library @library
public fun println() {} public fun println() {}
@library @library
public fun println(s: Any?) {} public fun println(s: Any?) {}
@library @library
public fun print(s: Any?) {} public fun print(s: Any?) {}
//TODO: consistent parseInt //TODO: consistent parseInt
@native @native
public fun parseInt(s: String, radix: Int = 10): Int = noImpl public fun parseInt(s: String, radix: Int = 10): Int = noImpl
@library @library
public fun safeParseInt(s: String): Int? = noImpl public fun safeParseInt(s: String): Int? = noImpl
@library @library
public fun safeParseDouble(s: String): Double? = noImpl public fun safeParseDouble(s: String): Double? = noImpl
+1 -1
View File
@@ -5,7 +5,7 @@ public class IOException(message: String = "") : Exception() {}
@library @library
public interface Closeable { public interface Closeable {
public open fun close() : Unit; public open fun close(): Unit
} }
interface Serializable interface Serializable
+1 -1
View File
@@ -32,7 +32,7 @@ public class AssertionError(message: String? = null) : Error(message) {}
@library @library
public interface Runnable { public interface Runnable {
public open fun run() : Unit; public open fun run(): Unit
} }
public fun Runnable(action: () -> Unit): Runnable = object : Runnable { public fun Runnable(action: () -> Unit): Runnable = object : Runnable {
+1 -1
View File
@@ -24,7 +24,7 @@ private val DEFAULT_LOAD_FACTOR = 0.75f
@library @library
public interface Comparator<T> { public interface Comparator<T> {
public fun compare(obj1: T, obj2: T): Int; public fun compare(obj1: T, obj2: T): Int
} }
public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> { public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
+3 -3
View File
@@ -3,8 +3,8 @@ package kotlin.js
//TODO: declare using number //TODO: declare using number
@native @native
public class MathClass() { public class MathClass() {
public val PI : Double = noImpl; public val PI: Double = noImpl
public fun random() : Double = noImpl; public fun random(): Double = noImpl
public fun abs(value: Double): Double = noImpl public fun abs(value: Double): Double = noImpl
public fun acos(value: Double): Double = noImpl public fun acos(value: Double): Double = noImpl
public fun asin(value: Double): Double = noImpl public fun asin(value: Double): Double = noImpl
@@ -27,4 +27,4 @@ public class MathClass() {
} }
@native @native
public val Math: MathClass = MathClass(); public val Math: MathClass = MathClass()
+3 -1
View File
@@ -147,7 +147,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
* @param limit The maximum number of times the split can occur. * @param limit The maximum number of times the split can occur.
*/ */
public fun split(input: CharSequence, limit: Int = 0): List<String> { public fun split(input: CharSequence, limit: Int = 0): List<String> {
require(limit >= 0, { "Limit must be non-negative, but was $limit" } ) require(limit >= 0) { "Limit must be non-negative, but was $limit" }
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) } val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
val result = ArrayList<String>() val result = ArrayList<String>()
var lastStart = 0 var lastStart = 0
@@ -166,8 +166,10 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
companion object { companion object {
/** Returns a literal regex for the specified [literal] string. */ /** Returns a literal regex for the specified [literal] string. */
public fun fromLiteral(literal: String): Regex = Regex(escape(literal)) public fun fromLiteral(literal: String): Regex = Regex(escape(literal))
/** Returns a literal pattern for the specified [literal] string. */ /** Returns a literal pattern for the specified [literal] string. */
public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&") public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&")
/** Returns a literal replacement exression for the specified [literal] string. */ /** Returns a literal replacement exression for the specified [literal] string. */
public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$") public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$")
+1 -2
View File
@@ -15,6 +15,7 @@ internal fun String.nativeLastIndexOf(str : String, fromIndex : Int) : Int = noI
@native("startsWith") @native("startsWith")
internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
@native("endsWith") @native("endsWith")
internal fun String.nativeEndsWith(s: String): Boolean = noImpl internal fun String.nativeEndsWith(s: String): Boolean = noImpl
@@ -40,8 +41,6 @@ public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noI
public val CharSequence.size: Int get() = noImpl public val CharSequence.size: Int get() = noImpl
@native("replace") @native("replace")
internal fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl internal fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl
+1
View File
@@ -86,6 +86,7 @@ fun NodeList.asElementList(): List<Element> = if (length == 0) emptyList() else
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun List<Node>.filterElements(): List<Element> = filter { it.isElement } as List<Element> fun List<Node>.filterElements(): List<Element> = filter { it.isElement } as List<Element>
fun NodeList.filterElements(): List<Element> = asList().filterElements() fun NodeList.filterElements(): List<Element> = asList().filterElements()
private class NodeListAsList(private val delegate: NodeList) : AbstractList<Node>() { private class NodeListAsList(private val delegate: NodeList) : AbstractList<Node>() {
@@ -62,4 +62,5 @@ private object CharCompanionObject {
} }
private object StringCompanionObject {} private object StringCompanionObject {}
private object EnumCompanionObject {} private object EnumCompanionObject {}
+1 -1
View File
@@ -5,5 +5,5 @@ package QUnit
*/ */
@native @native
public fun ok(actual: Boolean, message: String?): Unit = noImpl; public fun ok(actual: Boolean, message: String?): Unit = noImpl
-3
View File
@@ -38,7 +38,6 @@ class RegExpTest {
assertFalse(re2.global) assertFalse(re2.global)
assertFalse(re2.ignoreCase) assertFalse(re2.ignoreCase)
assertFalse(re2.multiline) assertFalse(re2.multiline)
} }
@test fun regExpTest() { @test fun regExpTest() {
@@ -69,6 +68,4 @@ class RegExpTest {
assertEquals(0, re.lastIndex) assertEquals(0, re.lastIndex)
} }
} }