Drop deprecated primitive ranges and progressions: for Byte and Short
This commit is contained in:
@@ -13,60 +13,6 @@ import java.util.*
|
||||
|
||||
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-downTo`(to: Byte): ByteProgression {
|
||||
return ByteProgression.fromClosedRange(this, to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-downTo`(to: Byte): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this, to.toShort(), -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-downTo`(to: Short): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this.toShort(), to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("downTo") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-downTo`(to: Short): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(this, to, -1)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-until`(to: Byte): ByteRange {
|
||||
val to_ = (to - 1).toByte()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ByteRange(this, to_)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-until`(to: Byte): ShortRange {
|
||||
return ShortRange(this, (to.toShort() - 1).toShort())
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Byte.`-until`(to: Short): ShortRange {
|
||||
val to_ = (to - 1).toShort()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ShortRange(this.toShort(), to_)
|
||||
}
|
||||
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@[kotlin.jvm.JvmName("until") kotlin.jvm.JvmVersion]
|
||||
public fun Short.`-until`(to: Short): ShortRange {
|
||||
val to_ = (to - 1).toShort()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.")
|
||||
return ShortRange(this, to_)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified [value] belongs to this range.
|
||||
*/
|
||||
@@ -488,42 +434,6 @@ public fun LongRange.reversed(): LongProgression {
|
||||
return LongProgression.fromClosedRange(last, first, -1L)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range in the opposite direction with the same step.
|
||||
*/
|
||||
@Deprecated("This range implementation has unclear semantics and will be removed soon.")
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ByteProgression.reversed(): ByteProgression {
|
||||
return ByteProgression.fromClosedRange(last, first, -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range in the opposite direction with the same step.
|
||||
*/
|
||||
@Deprecated("This range implementation has unclear semantics and will be removed soon.")
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ShortProgression.reversed(): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(last, first, -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ByteRange.reversed(): ByteProgression {
|
||||
return ByteProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range in reverse direction.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public fun ShortRange.reversed(): ShortProgression {
|
||||
return ShortProgression.fromClosedRange(last, first, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*/
|
||||
@@ -575,46 +485,6 @@ public infix fun LongRange.step(step: Long): LongProgression {
|
||||
return LongProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*/
|
||||
@Deprecated("This range implementation has unclear semantics and will be removed soon.")
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ByteProgression.step(step: Int): ByteProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ByteProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*/
|
||||
@Deprecated("This range implementation has unclear semantics and will be removed soon.")
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ShortProgression.step(step: Int): ShortProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ShortProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ByteRange.step(step: Int): ByteProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ByteProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over this range with given step.
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public infix fun ShortRange.step(step: Int): ShortProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ShortProgression.fromClosedRange(first, last, step)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
|
||||
@@ -57,8 +57,6 @@ public class RangeIterationTest : RangeIterationTestBase() {
|
||||
|
||||
@test fun emptyConstant() {
|
||||
doTest(IntRange.EMPTY, 1, 0, 1, listOf())
|
||||
doTest(ByteRange.EMPTY, 1.toByte(), 0.toByte(), 1, listOf())
|
||||
doTest(ShortRange.EMPTY, 1.toShort(), 0.toShort(), 1, listOf())
|
||||
doTest(LongRange.EMPTY, 1.toLong(), 0.toLong(), 1.toLong(), listOf())
|
||||
|
||||
doTest(CharRange.EMPTY, 1.toChar(), 0.toChar(), 1, listOf())
|
||||
|
||||
@@ -7,7 +7,6 @@ fun ranges(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
val rangePrimitives = listOf(PrimitiveType.Int, PrimitiveType.Long, PrimitiveType.Char)
|
||||
val floatingPointPrimitives = listOf(PrimitiveType.Double, PrimitiveType.Float)
|
||||
fun rangeElementType(fromType: PrimitiveType, toType: PrimitiveType)
|
||||
= maxByCapacity(fromType, toType).let { if (it == PrimitiveType.Char) it else maxByCapacity(it, PrimitiveType.Int) }
|
||||
|
||||
@@ -28,23 +27,6 @@ fun ranges(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("reversed()") {
|
||||
only(RangesOfPrimitives, 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, -step)"
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("step(step: SUM)") {
|
||||
infix(true)
|
||||
|
||||
@@ -68,39 +50,6 @@ fun ranges(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("step(step: SUM)") {
|
||||
infix(true)
|
||||
|
||||
only(RangesOfPrimitives, 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)
|
||||
return TProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun downTo(fromType: PrimitiveType, toType: PrimitiveType) = f("downTo(to: $toType)") {
|
||||
infix(true)
|
||||
|
||||
@@ -118,32 +67,6 @@ fun ranges(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
if (!fromType.isIntegral() || !toType.isIntegral()) {
|
||||
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
|
||||
annotations("""@Suppress("DEPRECATION_ERROR")""")
|
||||
}
|
||||
|
||||
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)" }
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -162,7 +85,6 @@ fun ranges(): List<GenericFunction> {
|
||||
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)
|
||||
@@ -181,11 +103,6 @@ fun ranges(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
if (!fromType.isIntegral() || !toType.isIntegral()) {
|
||||
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING))
|
||||
annotations("""@Suppress("DEPRECATION_ERROR")""")
|
||||
}
|
||||
|
||||
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
|
||||
|
||||
if (elementType == toType) {
|
||||
@@ -207,36 +124,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 contains(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(value: $itemType)") {
|
||||
operator(true)
|
||||
|
||||
Reference in New Issue
Block a user