Drop hidden declarations provided for binary compatibility in beta2

This commit is contained in:
Ilya Gorbunov
2015-11-22 09:20:39 +03:00
parent 542ab6ae34
commit a05d0a3c49
18 changed files with 70 additions and 1967 deletions
@@ -15,8 +15,7 @@ fun aggregates(): List<GenericFunction> {
return true
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("none(predicate: (T) -> Boolean)") {
@@ -30,8 +29,7 @@ fun aggregates(): List<GenericFunction> {
return true
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("none()") {
@@ -43,8 +41,7 @@ fun aggregates(): List<GenericFunction> {
return true
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("any(predicate: (T) -> Boolean)") {
@@ -58,8 +55,7 @@ fun aggregates(): List<GenericFunction> {
return false
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("any()") {
@@ -71,8 +67,7 @@ fun aggregates(): List<GenericFunction> {
return false
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("count(predicate: (T) -> Boolean)") {
@@ -87,8 +82,7 @@ fun aggregates(): List<GenericFunction> {
return count
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("count()") {
@@ -101,9 +95,8 @@ fun aggregates(): List<GenericFunction> {
return count
"""
}
deprecate(Strings) { forBinaryCompatibility }
doc(CharSequences) { "Returns the length of this char sequence."}
body(CharSequences, Strings) {
body(CharSequences) {
"return length"
}
body(Maps, Collections, ArraysOfObjects, ArraysOfPrimitives) {
@@ -113,8 +106,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("sumBy(selector: (T) -> Int)") {
inline(true)
include(CharSequences, Strings)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences)
doc { f -> "Returns the sum of all values produced by [selector] function applied to each ${f.element} in the ${f.collection}." }
returns("Int")
body {
@@ -130,8 +122,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("sumByDouble(selector: (T) -> Double)") {
inline(true)
include(CharSequences, Strings)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences)
doc { f -> "Returns the sum of all values produced by [selector] function applied to each ${f.element} in the ${f.collection}." }
returns("Double")
body {
@@ -163,8 +154,7 @@ fun aggregates(): List<GenericFunction> {
return min
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty()) return null
var min = this[0]
@@ -202,8 +192,7 @@ fun aggregates(): List<GenericFunction> {
return minElem
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty()) return null
@@ -268,8 +257,7 @@ fun aggregates(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty()) return null
@@ -308,8 +296,7 @@ fun aggregates(): List<GenericFunction> {
return maxElem
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty()) return null
@@ -358,8 +345,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("fold(initial: R, operation: (R, T) -> R)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each ${f.element}." }
typeParam("R")
returns("R")
@@ -375,8 +361,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("foldRight(initial: R, operation: (T, R) -> R)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from right to left to each ${f.element} and current accumulator value." }
typeParam("R")
returns("R")
@@ -395,8 +380,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("reduce(operation: (T, T) -> T)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
exclude(ArraysOfObjects, Iterables, Sequences)
doc { f -> "Accumulates value starting with the first ${f.element} and applying [operation] from left to right to current accumulator value and each ${f.element}." }
@@ -440,8 +424,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("reduceRight(operation: (T, T) -> T)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, ArraysOfPrimitives)
only(CharSequences, ArraysOfPrimitives)
doc { f -> "Accumulates value starting with last ${f.element} and applying [operation] from right to left to each ${f.element} and current accumulator value." }
returns("T")
body {
@@ -492,14 +475,12 @@ fun aggregates(): List<GenericFunction> {
for (element in this) action(element)
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("forEachIndexed(action: (Int, T) -> Unit)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Performs the given [action] on each ${f.element}, providing sequential index with the ${f.element}." }
returns("Unit")
body {
@@ -69,27 +69,6 @@ fun comparables(): List<GenericFunction> {
}
}
templates add f("coerceIn(range: Range<T>)") {
sourceFile(SourceFile.Ranges)
only(Primitives)
only(numericPrimitives.filterNot { it.isIntegral() })
returns("SELF")
deprecate { forBinaryCompatibility } // force use generic overload instead
doc {
"""
Ensures that this value lies in the specified [range].
@return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
"""
}
body {
"""
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
"""
}
}
templates add f("coerceIn(range: ClosedRange<T>)") {
sourceFile(SourceFile.Ranges)
only(Primitives, Generic)
@@ -226,8 +226,7 @@ fun elements(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(Lists, CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects) {
body(Lists, CharSequences, ArraysOfPrimitives, ArraysOfObjects) {
"""
for (index in indices) {
if (predicate(this[index])) {
@@ -257,8 +256,7 @@ fun elements(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(Lists, CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects) {
body(Lists, CharSequences, ArraysOfPrimitives, ArraysOfObjects) {
"""
for (index in indices.reversed()) {
if (predicate(this[index])) {
@@ -287,8 +285,7 @@ fun elements(): List<GenericFunction> {
return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") }
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
return get(index)
"""
@@ -328,9 +325,8 @@ fun elements(): List<GenericFunction> {
return defaultValue(index)
"""
}
deprecate(Strings) { forBinaryCompatibility }
inline(true, CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
inline(true, CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
"""
@@ -341,8 +337,7 @@ fun elements(): List<GenericFunction> {
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
returns("T")
inline(true)
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
body {
"""
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
@@ -384,8 +379,7 @@ fun elements(): List<GenericFunction> {
return null
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
return if (index >= 0 && index <= lastIndex) get(index) else null
"""
@@ -395,8 +389,7 @@ fun elements(): List<GenericFunction> {
templates add f("getOrNull(index: Int)") {
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
returns("T?")
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
only(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives)
body {
"""
return if (index >= 0 && index <= lastIndex) get(index) else null
@@ -428,8 +421,7 @@ fun elements(): List<GenericFunction> {
}
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
@@ -466,8 +458,7 @@ fun elements(): List<GenericFunction> {
}
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
return if (isEmpty()) null else this[0]
"""
@@ -485,8 +476,7 @@ fun elements(): List<GenericFunction> {
templates add f("first(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> """Returns the first ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
returns("T")
@@ -501,8 +491,7 @@ fun elements(): List<GenericFunction> {
templates add f("firstOrNull(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if ${f.element} was not found." }
returns("T?")
body {
@@ -515,8 +504,7 @@ fun elements(): List<GenericFunction> {
templates add f("find(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { "return firstOrNull(predicate)"}
@@ -558,8 +546,7 @@ fun elements(): List<GenericFunction> {
return last
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) {
"""
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
@@ -598,8 +585,7 @@ fun elements(): List<GenericFunction> {
return last
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
return if (isEmpty()) null else this[length - 1]
"""
@@ -614,8 +600,7 @@ fun elements(): List<GenericFunction> {
templates add f("last(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> """Returns the last ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
returns("T")
@@ -640,7 +625,7 @@ fun elements(): List<GenericFunction> {
"""
}
body(CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects, Lists) {
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects, Lists) {
"""
for (index in this.indices.reversed()) {
val element = this[index]
@@ -653,8 +638,7 @@ fun elements(): List<GenericFunction> {
templates add f("lastOrNull(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { f ->
@@ -675,7 +659,7 @@ fun elements(): List<GenericFunction> {
"""
}
body(CharSequences, Strings, ArraysOfPrimitives, ArraysOfObjects, Lists) {
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects, Lists) {
"""
for (index in this.indices.reversed()) {
val element = this[index]
@@ -688,8 +672,7 @@ fun elements(): List<GenericFunction> {
templates add f("findLast(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(Lists, CharSequences, Strings)
include(Lists, CharSequences)
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { "return lastOrNull(predicate)"}
@@ -729,8 +712,7 @@ fun elements(): List<GenericFunction> {
return single
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
return when (length) {
0 -> throw NoSuchElementException("Collection is empty.")
@@ -780,8 +762,7 @@ fun elements(): List<GenericFunction> {
return single
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
return if (length == 1) this[0] else null
"""
@@ -795,8 +776,7 @@ fun elements(): List<GenericFunction> {
templates add f("single(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns the single ${f.element} matching the given [predicate], or throws exception if there is no or more than one matching ${f.element}." }
returns("T")
body {
@@ -818,8 +798,7 @@ fun elements(): List<GenericFunction> {
templates add f("singleOrNull(predicate: (T) -> Boolean)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns the single ${f.element} matching the given [predicate], or `null` if ${f.element} was not found or more than one ${f.element} was found." }
returns("T?")
body {
@@ -384,8 +384,7 @@ fun filtering(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
for (index in 0..length - 1) {
val element = get(index)
@@ -480,9 +479,8 @@ fun filtering(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
doc(CharSequences) { "Appends all characters not matching the given [predicate] to the given [destination]." }
body(CharSequences, Strings) {
body(CharSequences) {
"""
for (element in this) if (!predicate(element)) destination.append(element)
return destination
@@ -556,8 +556,7 @@ fun generators(): List<GenericFunction> {
}
templates add f("zip(other: String, transform: (Char, Char) -> V)") {
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings)
only(CharSequences)
doc {
"""
Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence.
@@ -599,8 +598,7 @@ fun generators(): List<GenericFunction> {
templates add f("zip(other: String)") {
infix(true)
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings)
only(CharSequences)
doc {
"""
Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
@@ -6,8 +6,7 @@ fun mapping(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("withIndex()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns a ${if (f == Sequences) f.mapResult else "lazy [Iterable]"} of [IndexedValue] for each ${f.element} of the original ${f.collection}." }
returns("Iterable<IndexedValue<T>>")
body {
@@ -41,8 +40,7 @@ fun mapping(): List<GenericFunction> {
body(ArraysOfObjects, ArraysOfPrimitives) {
"return mapIndexedTo(ArrayList<R>(size), transform)"
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"return mapIndexedTo(ArrayList<R>(length), transform)"
}
inline(false, Sequences)
@@ -69,8 +67,7 @@ fun mapping(): List<GenericFunction> {
body(ArraysOfObjects, ArraysOfPrimitives, Maps) {
"return mapTo(ArrayList<R>(size), transform)"
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"return mapTo(ArrayList<R>(length), transform)"
}
@@ -149,8 +146,7 @@ fun mapping(): List<GenericFunction> {
return destination
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("mapIndexedTo(destination: C, transform: (Int, T) -> R)") {
@@ -174,9 +170,8 @@ fun mapping(): List<GenericFunction> {
return destination
"""
}
deprecate(Strings) { forBinaryCompatibility }
deprecate(Maps) { Deprecation("Use entries.mapIndexedTo instead.", replaceWith = "this.entries.mapIndexedTo(destination, transform)") }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("mapNotNullTo(destination: C, transform: (T) -> R?)") {
@@ -231,8 +226,7 @@ fun mapping(): List<GenericFunction> {
body {
"return flatMapTo(ArrayList<R>(), transform)"
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("flatMap(transform: (T) -> Sequence<R>)") {
@@ -261,8 +255,7 @@ fun mapping(): List<GenericFunction> {
return destination
"""
}
deprecate(Strings) { forBinaryCompatibility }
include(Maps, CharSequences, Strings)
include(Maps, CharSequences)
}
templates add f("flatMapTo(destination: C, transform: (T) -> Sequence<R>)") {
@@ -287,8 +280,7 @@ fun mapping(): List<GenericFunction> {
templates add f("groupBy(selector: (T) -> K)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns a map of the ${f.element}s in original ${f.collection} grouped by the key returned by the given [selector] function." }
typeParam("K")
returns("Map<K, List<T>>")
@@ -298,8 +290,7 @@ fun mapping(): List<GenericFunction> {
templates add f("groupByTo(map: MutableMap<K, MutableList<T>>, selector: (T) -> K)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
typeParam("K")
doc { f -> "Appends ${f.element}s from original ${f.collection} grouped by the key returned by the given [selector] function to the given [map]." }
returns("Map<K, MutableList<T>>")
@@ -14,32 +14,22 @@ fun ranges(): List<GenericFunction> {
fun <T> Collection<T>.permutations(): List<Pair<T, T>> = flatMap { a -> map { b -> a to b } }
templates add f("reversed()") {
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(ProgressionsOfPrimitives)
only(rangePrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
returns("TProgression")
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
body(RangesOfPrimitives) {
"return TProgression.fromClosedRange(last, first, -ONE)"
}
body(ProgressionsOfPrimitives) {
"return TProgression.fromClosedRange(last, first, -increment)"
}
}
templates add f("reversed()") {
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(ProgressionsOfPrimitives)
only(defaultPrimitives - PrimitiveType.Boolean - rangePrimitives - floatingPointPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
returns("TProgression")
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
annotations("""@Suppress("DEPRECATION_ERROR")""")
body(RangesOfPrimitives) {
"return TProgression.fromClosedRange(last, first, -ONE)"
}
body(ProgressionsOfPrimitives) {
"return TProgression.fromClosedRange(last, first, -increment)"
}
@@ -48,18 +38,10 @@ fun ranges(): List<GenericFunction> {
templates add f("step(step: SUM)") {
infix(true)
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(ProgressionsOfPrimitives)
only(rangePrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
returns("TProgression")
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
body(RangesOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
return TProgression.fromClosedRange(first, last, step)
"""
}
body(ProgressionsOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
@@ -71,27 +53,12 @@ fun ranges(): List<GenericFunction> {
templates add f("step(step: SUM)") {
infix(true)
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(ProgressionsOfPrimitives)
only(defaultPrimitives - PrimitiveType.Boolean - rangePrimitives - floatingPointPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
returns("TProgression")
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
deprecate(RangesOfPrimitives) { forBinaryCompatibility }
annotations("""@Suppress("DEPRECATION_ERROR")""")
body(RangesOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
return TProgression.fromClosedRange(first, last, step)
"""
}
bodyForTypes(RangesOfPrimitives, PrimitiveType.Float, PrimitiveType.Double) {
"""
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
checkStepIsPositive(step > 0, step)
return TProgression.fromClosedRange(start, end, step)
"""
}
body(ProgressionsOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
@@ -135,34 +102,12 @@ fun ranges(): List<GenericFunction> {
body { "return $progressionType.fromClosedRange($fromExpr, $toExpr, $incrementExpr)" }
}
fun downToDeprecated(fromType: PrimitiveType, toType: PrimitiveType) = f("`-downTo`(to: $toType)") {
deprecate { forBinaryCompatibility }
sourceFile(SourceFile.Ranges)
only(Primitives)
only(fromType)
val elementType = maxByCapacity(fromType, toType)
val progressionType = elementType.name + "Progression"
returns(progressionType)
annotations("""@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]""")
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
val toExpr = if (elementType == toType) "to" else "to.to$elementType()"
val incrementExpr = when (elementType) {
PrimitiveType.Long -> "-1L"
PrimitiveType.Float -> "-1.0F"
PrimitiveType.Double -> "-1.0"
else -> "-1"
}
body { "return $progressionType.fromClosedRange($fromExpr, $toExpr, $incrementExpr)" }
}
val numericPrimitives = PrimitiveType.numericPrimitives
val numericPermutations = numericPrimitives.permutations()
val primitivePermutations = numericPermutations + (PrimitiveType.Char to PrimitiveType.Char)
val integralPermutations = primitivePermutations.filter { it.first.isIntegral() && it.second.isIntegral() }
templates addAll integralPermutations.map { downTo(it.first, it.second) }
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { downToDeprecated(it.first, it.second) }
fun until(fromType: PrimitiveType, toType: PrimitiveType) = f("until(to: $toType)") {
infix(true)
@@ -207,36 +152,7 @@ fun ranges(): List<GenericFunction> {
}
}
fun untilDeprecated(fromType: PrimitiveType, toType: PrimitiveType) = f("`-until`(to: $toType)") {
deprecate { forBinaryCompatibility }
sourceFile(SourceFile.Ranges)
only(Primitives)
only(fromType)
val elementType = maxByCapacity(fromType, toType)
val progressionType = elementType.name + "Range"
returns(progressionType)
annotations("""@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]""")
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
if (elementType == toType) {
// hack to work around incorrect char overflow behavior in JVM and int overflow behavior in JS
val toExpr = "to"
body {
"""
val to_ = ($toExpr - 1).to$elementType()
if (to_ > to) throw IllegalArgumentException("The to argument value '${'$'}to' was too small.")
return $progressionType($fromExpr, to_)
"""
}
} else {
body { "return $progressionType($fromExpr, (to.to$elementType() - 1).to$elementType())" }
}
}
templates addAll integralPermutations.map { until(it.first, it.second) }
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { untilDeprecated(it.first, it.second) }
fun containsDeprecated(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(item: $itemType)") {
operator(true)
@@ -30,8 +30,7 @@ fun sequences(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
if (this is String && isEmpty()) return emptySequence()
return object : Sequence<T> {
@@ -6,8 +6,7 @@ fun snapshots(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("toCollection(destination: C)") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Appends all ${f.element}s to the given [destination] collection." }
returns("C")
typeParam("C : MutableCollection<in T>")
@@ -26,8 +25,7 @@ fun snapshots(): List<GenericFunction> {
returns("Set<T>")
body { "return toCollection(LinkedHashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
body(Sequences) { "return toCollection(LinkedHashSet<T>())" }
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) { "return toCollection(LinkedHashSet<T>(mapCapacity(length)))" }
body(CharSequences) { "return toCollection(LinkedHashSet<T>(mapCapacity(length)))" }
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(LinkedHashSet<T>(mapCapacity(size)))" }
}
@@ -36,14 +34,12 @@ fun snapshots(): List<GenericFunction> {
returns("HashSet<T>")
body { "return toCollection(HashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
body(Sequences) { "return toCollection(HashSet<T>())" }
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) { "return toCollection(HashSet<T>(mapCapacity(length)))" }
body(CharSequences) { "return toCollection(HashSet<T>(mapCapacity(length)))" }
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(HashSet<T>(mapCapacity(size)))" }
}
templates add f("toSortedSet()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
typeParam("T: Comparable<T>")
doc { f -> "Returns a [SortedSet] of all ${f.element}s." }
returns("SortedSet<T>")
@@ -76,8 +72,7 @@ fun snapshots(): List<GenericFunction> {
"""
}
body(Collections) { "return ArrayList(this)" }
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) { "return toCollection(ArrayList<T>(length))" }
body(CharSequences) { "return toCollection(ArrayList<T>(length))" }
body(ArraysOfObjects) { "return ArrayList(this.asCollection())" }
body(ArraysOfPrimitives) {
"""
@@ -103,8 +98,7 @@ fun snapshots(): List<GenericFunction> {
}
templates add f("toList()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
include(CharSequences)
doc { f -> "Returns a [List] containing all ${f.element}s." }
returns("List<T>")
body { "return this.toArrayList()" }
@@ -119,9 +113,7 @@ fun snapshots(): List<GenericFunction> {
templates add f("toMap(selector: (T) -> K)") {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
body(Strings) { "return toMapBy(selector)" }
include(CharSequences, Strings)
include(CharSequences)
typeParam("K")
returns("Map<K, T>")
deprecate(Deprecation("Use toMapBy instead.", replaceWith = "toMapBy(selector)"))
@@ -163,8 +155,7 @@ fun snapshots(): List<GenericFunction> {
return result
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
val capacity = (length/.75f) + 1
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
@@ -222,8 +213,7 @@ fun snapshots(): List<GenericFunction> {
return result
"""
}
deprecate(Strings) { forBinaryCompatibility }
body(CharSequences, Strings) {
body(CharSequences) {
"""
val capacity = (length/.75f) + 1
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
@@ -55,17 +55,6 @@ fun strings(): List<GenericFunction> {
}
}
templates add f("joinTo(buffer: A, separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\", transform: ((T) -> String)? = null)") {
deprecate { forBinaryCompatibility }
typeParam("A : Appendable")
returns { "A" }
body {
"""
return joinTo(buffer, separator, prefix, postfix, limit, truncated, transform)
"""
}
}
templates add f("joinToString(separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
doc {
"""
@@ -85,15 +74,5 @@ fun strings(): List<GenericFunction> {
}
}
templates add f("joinToString(separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\", transform: ((T) -> String)? = null)") {
deprecate { forBinaryCompatibility }
returns("String")
body {
"""
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
"""
}
}
return templates
}