KT-53778 Remove experimental annotations from open ranges

This commit is contained in:
Ilya Gorbunov
2023-04-11 18:42:07 +02:00
committed by Space Team
parent 9953991c4c
commit b35b727d73
42 changed files with 516 additions and 540 deletions
@@ -10,14 +10,13 @@ package kotlin.ranges
/**
* A range of values of type `Char`.
*/
@OptIn(ExperimentalStdlibApi::class)
public class CharRange(start: Char, endInclusive: Char) : CharProgression(start, endInclusive, 1), ClosedRange<Char>, OpenEndRange<Char> {
override val start: Char get() = first
override val endInclusive: Char get() = last
@Deprecated("Can throw an exception when it's impossible to represent the value with Char type, for example, when the range includes MAX_VALUE. It's recommended to use 'endInclusive' property that doesn't throw.")
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
override val endExclusive: Char get() {
if (last == Char.MAX_VALUE) error("Cannot return the exclusive upper bound of a range that includes MAX_VALUE.")
return last + 1
@@ -50,14 +49,13 @@ public class CharRange(start: Char, endInclusive: Char) : CharProgression(start,
/**
* A range of values of type `Int`.
*/
@OptIn(ExperimentalStdlibApi::class)
public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, endInclusive, 1), ClosedRange<Int>, OpenEndRange<Int> {
override val start: Int get() = first
override val endInclusive: Int get() = last
@Deprecated("Can throw an exception when it's impossible to represent the value with Int type, for example, when the range includes MAX_VALUE. It's recommended to use 'endInclusive' property that doesn't throw.")
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
override val endExclusive: Int get() {
if (last == Int.MAX_VALUE) error("Cannot return the exclusive upper bound of a range that includes MAX_VALUE.")
return last + 1
@@ -90,14 +88,13 @@ public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, end
/**
* A range of values of type `Long`.
*/
@OptIn(ExperimentalStdlibApi::class)
public class LongRange(start: Long, endInclusive: Long) : LongProgression(start, endInclusive, 1), ClosedRange<Long>, OpenEndRange<Long> {
override val start: Long get() = first
override val endInclusive: Long get() = last
@Deprecated("Can throw an exception when it's impossible to represent the value with Long type, for example, when the range includes MAX_VALUE. It's recommended to use 'endInclusive' property that doesn't throw.")
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
override val endExclusive: Long get() {
if (last == Long.MAX_VALUE) error("Cannot return the exclusive upper bound of a range that includes MAX_VALUE.")
return last + 1
+2 -2
View File
@@ -39,8 +39,8 @@ public interface ClosedRange<T : Comparable<T>> {
* Represents a range of values (for example, numbers or characters) where the upper bound is not included in the range.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/ranges.html) for more information.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
public interface OpenEndRange<T : Comparable<T>> {
/**
* The minimum value in the range.
+8 -11
View File
@@ -39,7 +39,6 @@ public operator fun <T : Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = Com
/**
* Represents a range of [Comparable] values.
*/
@OptIn(ExperimentalStdlibApi::class)
private open class ComparableOpenEndRange<T : Comparable<T>>(
override val start: T,
override val endExclusive: T
@@ -63,8 +62,8 @@ private open class ComparableOpenEndRange<T : Comparable<T>>(
* This value needs to be smaller than [that] value, otherwise the returned range will be empty.
* @sample samples.ranges.Ranges.rangeFromComparable
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
public operator fun <T : Comparable<T>> T.rangeUntil(that: T): OpenEndRange<T> = ComparableOpenEndRange(this, that)
@@ -132,7 +131,6 @@ public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange<Doubl
*
* Numbers are compared with the ends of this range according to IEEE-754.
*/
@OptIn(ExperimentalStdlibApi::class)
private class OpenEndDoubleRange(
start: Double,
endExclusive: Double
@@ -164,8 +162,8 @@ private class OpenEndDoubleRange(
*
* Numbers are compared with the ends of this range according to IEEE-754.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
public operator fun Double.rangeUntil(that: Double): OpenEndRange<Double> = OpenEndDoubleRange(this, that)
@@ -215,7 +213,6 @@ public operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange<Float>
*
* Numbers are compared with the ends of this range according to IEEE-754.
*/
@OptIn(ExperimentalStdlibApi::class)
private class OpenEndFloatRange(
start: Float,
endExclusive: Float
@@ -247,8 +244,8 @@ private class OpenEndFloatRange(
*
* Numbers are compared with the ends of this range according to IEEE-754.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
public operator fun Float.rangeUntil(that: Float): OpenEndRange<Float> = OpenEndFloatRange(this, that)
@@ -267,8 +264,8 @@ public inline operator fun <T, R> R.contains(element: T?): Boolean where T : Any
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline operator fun <T, R> R.contains(element: T?): Boolean where T : Any, R : OpenEndRange<T>, R : Iterable<T> =
element != null && contains(element)