Eliminate deprecated language constructions from the generated code.
This commit is contained in:
@@ -17,13 +17,13 @@ private val COMMON_AUTOGENERATED_WARNING: String = """//
|
||||
* at runtime.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
require(args.size() == 1, "Expecting Kotlin project home path as an argument")
|
||||
require(args.size() == 1) { "Expecting Kotlin project home path as an argument" }
|
||||
|
||||
val outDir = File(File(args[0]), "libraries/stdlib/src/generated")
|
||||
require(outDir.exists(), "${outDir.getPath()} doesn't exist!")
|
||||
require(outDir.exists()) { "$outDir doesn't exist!" }
|
||||
|
||||
val jsCoreDir = File(args[0], "js/js.libraries/src/core")
|
||||
require(jsCoreDir.exists(), "${jsCoreDir.getPath()} doesn't exist!")
|
||||
require(jsCoreDir.exists()) { "$jsCoreDir doesn't exist!" }
|
||||
|
||||
generateCollectionsAPI(outDir)
|
||||
generateCollectionsJsAPI(jsCoreDir)
|
||||
@@ -31,16 +31,16 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
fun List<GenericFunction>.writeTo(file: File, builder: GenericFunction.() -> String) {
|
||||
println("Generating file: ${file.getPath()}")
|
||||
println("Generating file: $file")
|
||||
val its = FileWriter(file)
|
||||
|
||||
its.use {
|
||||
its.append("package kotlin\n\n")
|
||||
its.append("$COMMON_AUTOGENERATED_WARNING\n\n")
|
||||
its.append("import kotlin.platform.*\n")
|
||||
its.append("import kotlin.platform.*\n") // TODO: Remove unneeded import
|
||||
its.append("import java.util.*\n\n")
|
||||
its.append("import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js\n\n")
|
||||
for (t in this.sort()) {
|
||||
for (t in this.sorted()) {
|
||||
its.append(t.builder())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,7 +762,7 @@ fun elements(): List<GenericFunction> {
|
||||
templates addAll (1..5).map { n ->
|
||||
f("component$n()") {
|
||||
inline(true)
|
||||
annotations("""suppress("NOTHING_TO_INLINE")""")
|
||||
annotations("""@Suppress("NOTHING_TO_INLINE")""")
|
||||
fun getOrdinal(n: Int) = n.toString() + when (n) {
|
||||
1 -> "st"
|
||||
2 -> "nd"
|
||||
|
||||
@@ -326,13 +326,13 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
|
||||
deprecate[f]?.let { deprecated ->
|
||||
val replacement = deprecateReplacement[f]?.let { ", ReplaceWith(\"$it\")" } ?: ""
|
||||
builder.append("deprecated(\"$deprecated\"$replacement)\n")
|
||||
builder.append("@Deprecated(\"$deprecated\"$replacement)\n")
|
||||
}
|
||||
|
||||
if (!f.isPrimitiveSpecialization && primitive != null) {
|
||||
platformName[primitive]
|
||||
?.replace("<T>", primitive.name)
|
||||
?.let { platformName -> builder.append("platformName(\"${platformName}\")\n")}
|
||||
?.let { platformName -> builder.append("@kotlin.jvm.JvmName(\"${platformName}\")\n")}
|
||||
}
|
||||
|
||||
annotations[f]?.let { builder.append(it).append('\n') }
|
||||
|
||||
@@ -234,7 +234,7 @@ fun ordering(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?)") {
|
||||
templates add f("sortedBy(crossinline selector: (T) -> R?)") {
|
||||
exclude(Strings)
|
||||
inline(true)
|
||||
returns("List<T>")
|
||||
@@ -256,7 +256,7 @@ fun ordering(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?)") {
|
||||
templates add f("sortedByDescending(crossinline selector: (T) -> R?)") {
|
||||
exclude(Strings)
|
||||
inline(true)
|
||||
returns("List<T>")
|
||||
@@ -350,7 +350,7 @@ fun ordering(): List<GenericFunction> {
|
||||
exclude(Strings)
|
||||
}
|
||||
|
||||
templates add f("sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R)") {
|
||||
templates add f("sortBy(crossinline order: (T) -> R)") {
|
||||
inline(true)
|
||||
|
||||
doc {
|
||||
@@ -402,7 +402,7 @@ fun ordering(): List<GenericFunction> {
|
||||
only(Sequences, ArraysOfObjects, ArraysOfPrimitives, Iterables)
|
||||
}
|
||||
|
||||
templates add f("sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R)") {
|
||||
templates add f("sortDescendingBy(crossinline order: (T) -> R)") {
|
||||
inline(true)
|
||||
|
||||
doc {
|
||||
|
||||
@@ -131,7 +131,7 @@ fun ranges(): List<GenericFunction> {
|
||||
only(RangesOfPrimitives)
|
||||
only(rangeType)
|
||||
returns("Nothing")
|
||||
annotations("""deprecated("The 'contains' operation for a range of $rangeType and $itemType item is not supported and should not be used.")""")
|
||||
annotations("""@Deprecated("The 'contains' operation for a range of $rangeType and $itemType item is not supported and should not be used.")""")
|
||||
body { """throw UnsupportedOperationException()""" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
doc { "Returns new array which is a copy of range of original array." }
|
||||
inline(true)
|
||||
annotations("""suppress("NOTHING_TO_INLINE")""")
|
||||
annotations("""@Suppress("NOTHING_TO_INLINE")""")
|
||||
returns("SELF")
|
||||
returns(ArraysOfObjects) { "Array<T>" }
|
||||
body {
|
||||
@@ -54,7 +54,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
doc { "Returns new array which is a copy of the original array." }
|
||||
inline(true)
|
||||
annotations("""suppress("NOTHING_TO_INLINE")""")
|
||||
annotations("""@Suppress("NOTHING_TO_INLINE")""")
|
||||
returns("SELF")
|
||||
returns(ArraysOfObjects) { "Array<T>" }
|
||||
body {
|
||||
@@ -95,7 +95,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
returns("SELF")
|
||||
returns(ArraysOfObjects) { "Array<T>" }
|
||||
inline(true)
|
||||
annotations("""suppress("NOTHING_TO_INLINE")""")
|
||||
annotations("""@Suppress("NOTHING_TO_INLINE")""")
|
||||
doc { "Returns an array containing all elements of the original array and then the given [element]." }
|
||||
body() {
|
||||
"""
|
||||
@@ -121,7 +121,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
doc { "Returns an array containing all elements of the original array and then all elements of the given [array]." }
|
||||
inline(true)
|
||||
annotations("""suppress("NOTHING_TO_INLINE")""")
|
||||
annotations("""@Suppress("NOTHING_TO_INLINE")""")
|
||||
returns("SELF")
|
||||
returns(ArraysOfObjects) { "Array<T>" }
|
||||
body {
|
||||
@@ -134,7 +134,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
templates add f("sort(comparison: (T, T) -> Int)") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
annotations("native")
|
||||
annotations("@native")
|
||||
returns("Unit")
|
||||
doc { "Sorts the array inplace according to the order specified by the given [comparison] function." }
|
||||
body { "return noImpl" }
|
||||
@@ -154,7 +154,7 @@ fun specialJS(): List<GenericFunction> {
|
||||
exclude(PrimitiveType.Long)
|
||||
returns("Unit")
|
||||
doc { "Sorts the array inplace." }
|
||||
annotations("""library("primitiveArraySort")""")
|
||||
annotations("""@library("primitiveArraySort")""")
|
||||
body { "return noImpl" }
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
returns(ArraysOfObjects) { "Array<out T?>" }
|
||||
returns(InvariantArraysOfObjects) { "Array<T?>" }
|
||||
annotations(InvariantArraysOfObjects) { """platformName("mutableCopyOf")"""}
|
||||
annotations(InvariantArraysOfObjects) { """@JvmName("mutableCopyOf")"""}
|
||||
}
|
||||
|
||||
templates add f("fill(element: T, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
|
||||
Reference in New Issue
Block a user