Rename copyToArray() to toTypedArray().

This commit is contained in:
Ilya Gorbunov
2015-04-20 20:17:49 +03:00
parent 5eb3c0bb5e
commit be11394adf
9 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -32,4 +32,4 @@ library
public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl
library("copyToArray") library("copyToArray")
public fun <reified T> Collection<T>.copyToArray(): Array<T> = noImpl public fun <reified T> Collection<T>.toTypedArray(): Array<T> = noImpl
@@ -77,9 +77,12 @@ public fun ByteArray.toString(charset: String): String = String(this, charset)
public fun ByteArray.toString(charset: Charset): String = String(this, charset) public fun ByteArray.toString(charset: Charset): String = String(this, charset)
/** /**
* Returns an array containing the elements of this collection. * Returns a *typed* array containing all of the elements of this collection.
*
* Allocates an array of runtime type `T` having its size equal to the size of this collection
* and populates the array with the elements of this collection.
*/ */
[Intrinsic("kotlin.collections.copyToArray")] public fun <reified T> Collection<T>.copyToArray(): Array<T> = [Intrinsic("kotlin.collections.copyToArray")] public fun <reified T> Collection<T>.toTypedArray(): Array<T> =
throw UnsupportedOperationException() throw UnsupportedOperationException()
/** Returns the array if it's not null, or an empty array otherwise. */ /** Returns the array if it's not null, or an empty array otherwise. */
@@ -36,3 +36,6 @@ inline public fun byteArray(vararg content : Byte) : ByteArray = byteAr
suppress("NOTHING_TO_INLINE") suppress("NOTHING_TO_INLINE")
deprecated("Use booleanArrayOf() instead.") deprecated("Use booleanArrayOf() instead.")
inline public fun booleanArray(vararg content : Boolean) : BooleanArray = booleanArrayOf(*content) inline public fun booleanArray(vararg content : Boolean) : BooleanArray = booleanArrayOf(*content)
deprecated("Use toTypedArray() instead.")
inline public fun <reified T> Collection<T>.copyToArray(): Array<T> = toTypedArray()
@@ -94,7 +94,7 @@ public fun String.split(regex: Pattern, limit: Int = 0): List<String> = regex.sp
* Splits this string around matches of the given regular expression. * Splits this string around matches of the given regular expression.
*/ */
deprecated("Convert an argument to regex with toRegex or use splitBy instead.") deprecated("Convert an argument to regex with toRegex or use splitBy instead.")
public fun String.split(regex: String): Array<String> = split(regex.toRegex()).copyToArray() public fun String.split(regex: String): Array<String> = split(regex.toRegex()).toTypedArray()
/** /**
@@ -91,7 +91,7 @@ class CollectionJVMTest {
test fun toArray() { test fun toArray() {
val data = listOf("foo", "bar") val data = listOf("foo", "bar")
val arr = data.copyToArray() val arr = data.toTypedArray()
println("Got array ${arr}") println("Got array ${arr}")
assertEquals(2, arr.size()) assertEquals(2, arr.size())
todo { todo {
@@ -286,7 +286,7 @@ class CollectionTest {
test fun copyToArray() { test fun copyToArray() {
val data = listOf("foo", "bar") val data = listOf("foo", "bar")
val arr = data.copyToArray() val arr = data.toTypedArray()
println("Got array ${arr}") println("Got array ${arr}")
assertEquals(2, arr.size()) assertEquals(2, arr.size())
todo { todo {
@@ -31,7 +31,7 @@ class JavautilCollectionsTest {
} }
test fun collectionToArray() { test fun collectionToArray() {
val array = TEST_LIST.copyToArray() val array = TEST_LIST.toTypedArray()
assertEquals(array.toList(), TEST_LIST) assertEquals(array.toList(), TEST_LIST)
} }
} }
@@ -196,7 +196,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
} }
public fun addLibraryFiles(vararg fs: File) { public fun addLibraryFiles(vararg fs: File) {
val strs = fs.map { it.getPath() }.copyToArray() val strs = fs.map { it.getPath() }.toTypedArray()
addLibraryFiles(*strs) addLibraryFiles(*strs)
} }
@@ -477,8 +477,8 @@ private class SubpluginEnvironment(
} }
val extraProperties = compileTask.getExtensions().getExtraProperties() val extraProperties = compileTask.getExtensions().getExtraProperties()
extraProperties.set("compilerPluginClasspaths", realPluginClasspaths.copyToArray()) extraProperties.set("compilerPluginClasspaths", realPluginClasspaths.toTypedArray())
extraProperties.set("compilerPluginArguments", pluginArguments.copyToArray()) extraProperties.set("compilerPluginArguments", pluginArguments.toTypedArray())
} }
} }
@@ -488,7 +488,7 @@ open class GradleUtils(val scriptHandler: ScriptHandler, val project: ProjectInt
val configurationsContainer: ConfigurationContainer = scriptHandler.getConfigurations() val configurationsContainer: ConfigurationContainer = scriptHandler.getConfigurations()
val deps = coordinates map { dependencyHandler.create(it) } val deps = coordinates map { dependencyHandler.create(it) }
val configuration = configurationsContainer.detachedConfiguration(*deps.copyToArray()) val configuration = configurationsContainer.detachedConfiguration(*deps.toTypedArray())
return configuration.getResolvedConfiguration().getFiles { true } return configuration.getResolvedConfiguration().getFiles { true }
} }