Sort out warnings related to inline and library functions in stdlib-js

This commit is contained in:
Ilya Gorbunov
2017-04-13 22:08:33 +03:00
parent 6ae19e03d5
commit 37c3d8f204
11 changed files with 54 additions and 9 deletions
+2
View File
@@ -155,6 +155,7 @@ internal class BoxedChar(val c: Char) : Comparable<Char> {
}
}
@kotlin.internal.InlineOnly
internal inline fun <T> concat(args: Array<T>): T {
val typed = js("Array")(args.size)
for (i in 0..args.size - 1) {
@@ -221,6 +222,7 @@ internal fun charArrayOf() = withType("CharArray", js("new Uint16Array([].slice.
internal fun longArrayOf() = withType("LongArray", js("[].slice.call(arguments)"))
@JsName("withType")
@kotlin.internal.InlineOnly
internal inline fun withType(type: String, array: dynamic): dynamic {
array.`$type$` = type
return array
+3 -1
View File
@@ -19,12 +19,14 @@ package kotlin.collections
import kotlin.comparisons.naturalOrder
/** Returns the array if it's not `null`, or an empty array otherwise. */
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>?.orEmpty(): Array<out T> = this ?: emptyArray<T>()
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
@kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
@JsName("copyToArray")
@PublishedApi
internal fun <T> copyToArray(collection: Collection<T>): Array<T> {
return if (collection.asDynamic().toArray !== undefined)
collection.asDynamic().toArray().unsafeCast<Array<T>>()
@@ -5168,6 +5168,7 @@ public fun CharArray.sortedWith(comparator: Comparator<in Char>): List<Char> {
*/
@SinceKotlin("1.1")
@library("arrayDeepEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
definedExternally
}
@@ -5203,6 +5204,7 @@ public fun <T> Array<out T>.contentDeepToString(): String {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
definedExternally
}
@@ -5213,6 +5215,7 @@ public infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
definedExternally
}
@@ -5223,6 +5226,7 @@ public infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
definedExternally
}
@@ -5233,6 +5237,7 @@ public infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun IntArray.contentEquals(other: IntArray): Boolean {
definedExternally
}
@@ -5243,6 +5248,7 @@ public infix fun IntArray.contentEquals(other: IntArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun LongArray.contentEquals(other: LongArray): Boolean {
definedExternally
}
@@ -5253,6 +5259,7 @@ public infix fun LongArray.contentEquals(other: LongArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
definedExternally
}
@@ -5263,6 +5270,7 @@ public infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
definedExternally
}
@@ -5273,6 +5281,7 @@ public infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
definedExternally
}
@@ -5283,6 +5292,7 @@ public infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
*/
@SinceKotlin("1.1")
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
public infix fun CharArray.contentEquals(other: CharArray): Boolean {
definedExternally
}
@@ -12926,6 +12936,7 @@ public fun <T> Array<out T>.asList(): List<T> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.asList(): List<Byte> {
return this.unsafeCast<Array<Byte>>().asList()
}
@@ -12933,6 +12944,7 @@ public inline fun ByteArray.asList(): List<Byte> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.asList(): List<Short> {
return this.unsafeCast<Array<Short>>().asList()
}
@@ -12940,6 +12952,7 @@ public inline fun ShortArray.asList(): List<Short> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.asList(): List<Int> {
return this.unsafeCast<Array<Int>>().asList()
}
@@ -12947,6 +12960,7 @@ public inline fun IntArray.asList(): List<Int> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.asList(): List<Long> {
return this.unsafeCast<Array<Long>>().asList()
}
@@ -12954,6 +12968,7 @@ public inline fun LongArray.asList(): List<Long> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.asList(): List<Float> {
return this.unsafeCast<Array<Float>>().asList()
}
@@ -12961,6 +12976,7 @@ public inline fun FloatArray.asList(): List<Float> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.asList(): List<Double> {
return this.unsafeCast<Array<Double>>().asList()
}
@@ -12968,6 +12984,7 @@ public inline fun DoubleArray.asList(): List<Double> {
/**
* Returns a [List] that wraps the original array.
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.asList(): List<Boolean> {
return this.unsafeCast<Array<Boolean>>().asList()
}
@@ -13533,6 +13550,7 @@ public fun CharArray.toTypedArray(): Array<Char> {
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.sort(noinline comparison: (a: T, b: T) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13540,6 +13558,7 @@ public inline fun <T> Array<out T>.sort(noinline comparison: (a: T, b: T) -> Int
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13547,6 +13566,7 @@ public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int)
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13554,6 +13574,7 @@ public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> I
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13561,6 +13582,7 @@ public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): U
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13568,6 +13590,7 @@ public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int)
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13575,6 +13598,7 @@ public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> I
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -13582,6 +13606,7 @@ public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) -
/**
* Sorts the array in-place according to the order specified by the given [comparison] function.
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.sort(noinline comparison: (a: Char, b: Char) -> Int): Unit {
asDynamic().sort(comparison)
}
@@ -80,6 +80,7 @@ public fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast<Double>(
* Parses the string as a [Float] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@kotlin.internal.InlineOnly
public inline fun String.toFloat(): Float = toDouble().unsafeCast<Float>()
/**
@@ -94,6 +95,7 @@ public fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast<D
* Parses the string as a [Float] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
@kotlin.internal.InlineOnly
public inline fun String.toFloatOrNull(): Float? = toDoubleOrNull().unsafeCast<Float?>()
+1
View File
@@ -17,5 +17,6 @@
package kotlin.ranges
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange<Float> =
this.toDouble().rangeTo(that.toDouble()).unsafeCast<ClosedFloatingPointRange<Float>>()
+5
View File
@@ -8,12 +8,16 @@ public inline fun String.toUpperCase(): String = asDynamic().toUpperCase()
@kotlin.internal.InlineOnly
public inline fun String.toLowerCase(): String = asDynamic().toLowerCase()
@kotlin.internal.InlineOnly
internal inline fun String.nativeIndexOf(str: String, fromIndex: Int): Int = asDynamic().indexOf(str, fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = asDynamic().lastIndexOf(str, fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeStartsWith(s: String, position: Int): Boolean = asDynamic().startsWith(s, position)
@kotlin.internal.InlineOnly
internal inline fun String.nativeEndsWith(s: String): Boolean = asDynamic().endsWith(s)
@kotlin.internal.InlineOnly
@@ -34,4 +38,5 @@ public inline fun String.match(regex: String): Array<String>? = asDynamic().matc
@kotlin.internal.InlineOnly
public inline val CharSequence.size: Int get() = asDynamic().length
@kotlin.internal.InlineOnly
internal inline fun String.nativeReplace(pattern: RegExp, replacement: String): String = asDynamic().replace(pattern, replacement)
+5 -3
View File
@@ -2,7 +2,9 @@ package kotlin.text
import kotlin.js.RegExp
@kotlin.internal.InlineOnly
internal inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = nativeIndexOf(ch.toString(), fromIndex)
@kotlin.internal.InlineOnly
internal inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = nativeLastIndexOf(ch.toString(), fromIndex)
/**
@@ -37,7 +39,7 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean
public inline fun String.matches(regex: String): Boolean {
public fun String.matches(regex: String): Boolean {
val result = this.match(regex)
return result != null && result.size != 0
}
@@ -62,7 +64,7 @@ public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, othe
*
* @includeFunctionBody ../../test/StringTest.kt capitalize
*/
public inline fun String.capitalize(): String {
public fun String.capitalize(): String {
return if (isNotEmpty()) substring(0, 1).toUpperCase() + substring(1) else this
}
@@ -71,7 +73,7 @@ public inline fun String.capitalize(): String {
*
* @includeFunctionBody ../../test/StringTest.kt decapitalize
*/
public inline fun String.decapitalize(): String {
public fun String.decapitalize(): String {
return if (isNotEmpty()) substring(0, 1).toLowerCase() + substring(1) else this
}
@@ -58,7 +58,10 @@ fun arrays(): List<GenericFunction> {
returns("Boolean")
body(Platform.JVM) { "return java.util.Arrays.equals(this, other)" }
annotations(Platform.JS, """@library("arrayEquals")""")
annotations(Platform.JS, """
@library("arrayEquals")
@Suppress("UNUSED_PARAMETER")
""")
body(Platform.JS) { "definedExternally" }
}
@@ -79,7 +82,10 @@ fun arrays(): List<GenericFunction> {
}
returns("Boolean")
body(Platform.JVM) { "return java.util.Arrays.deepEquals(this, other)" }
annotations(Platform.JS, """@library("arrayDeepEquals")""")
annotations(Platform.JS, """
@library("arrayDeepEquals")
@Suppress("UNUSED_PARAMETER")
""")
body(Platform.JS) { "definedExternally" }
}
@@ -24,7 +24,7 @@ fun specialJS(): List<GenericFunction> {
templates add f("sort(noinline comparison: (a: T, b: T) -> Int)") {
only(ArraysOfObjects, ArraysOfPrimitives)
exclude(PrimitiveType.Boolean)
inline(true)
inline(Inline.Only)
returns("Unit")
doc { "Sorts the array in-place according to the order specified by the given [comparison] function." }
body { "asDynamic().sort(comparison)" }
@@ -497,7 +497,7 @@ object CommonArrays {
body(Platform.JS) { objectLiteralImpl }
}
else {
inline(Platform.JS, Inline.Yes, ArraysOfPrimitives)
inline(Platform.JS, Inline.Only, ArraysOfPrimitives)
body(Platform.JS) { "return this.unsafeCast<Array<T>>().asList()" }
}
}
@@ -483,7 +483,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
builder.append("@SinceKotlin(\"$since\")\n")
}
annotations[platform, f]?.let { builder.append(it).append('\n') }
annotations[platform, f]?.let { builder.append(it.trimIndent()).append('\n') }
if (inline[platform, f] == Inline.Only) {
builder.append("@kotlin.internal.InlineOnly").append('\n')