diff --git a/core/builtins/src/kotlin/Progression.kt b/core/builtins/src/kotlin/Progression.kt index d64858c7dde..b64eee0213d 100644 --- a/core/builtins/src/kotlin/Progression.kt +++ b/core/builtins/src/kotlin/Progression.kt @@ -22,7 +22,7 @@ package kotlin * bytecode generation for it. Progressions with a step of -1 can be created through the * `downTo` method on classes representing primitive types. */ -@Deprecated("This progression has unclear inclusiveness of end value. Use InclusiveRangeProgression instead.", ReplaceWith("InclusiveRangeProgression")) +@Deprecated("This generic progression interface is not of much use and will be removed soon. Use concrete progression implementation instead: IntProgression, LongProgression or CharProgression.") public interface Progression : Iterable { /** * The start value of the progression. @@ -39,34 +39,3 @@ public interface Progression : Iterable { */ public val increment: Number } - - -/** - * Represents an arithmetical progression of numbers or characters with a given start value, end value and step. - * This class is intended to be used in 'for' loops, and the JVM backend suggests efficient - * bytecode generation for it. Progressions with a step of -1 can be created through the - * `downTo` method on classes representing primitive types. - */ -public interface InclusiveRangeProgression : Progression { - /** - * The start value of the progression. - */ - public override val start: N - - /** - * The end value of the progression (inclusive). - */ - @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) - public override val end: N get() = endInclusive - - /** - * The end value of the progression (inclusive). - */ - public val endInclusive: N - - /** - * The step of the progression. - */ - public override val increment: Number -} - diff --git a/core/builtins/src/kotlin/Progressions.kt b/core/builtins/src/kotlin/Progressions.kt index 9a8e4a63780..22ca46fa891 100644 --- a/core/builtins/src/kotlin/Progressions.kt +++ b/core/builtins/src/kotlin/Progressions.kt @@ -18,22 +18,29 @@ package kotlin +@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING) /** * A progression of values of type `Byte`. */ -public class ByteProgression( +public open class ByteProgression( override val start: Byte, - override val endInclusive: Byte, + val endInclusive: Byte, override val increment: Int -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Byte get() = endInclusive + override fun iterator(): ByteIterator = ByteProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is ByteProgression && (isEmpty() && other.isEmpty() || @@ -48,19 +55,25 @@ public class ByteProgression( /** * A progression of values of type `Char`. */ -public class CharProgression( +public open class CharProgression( override val start: Char, - override val endInclusive: Char, + val endInclusive: Char, override val increment: Int -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Char get() = endInclusive + override fun iterator(): CharIterator = CharProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is CharProgression && (isEmpty() && other.isEmpty() || @@ -72,22 +85,29 @@ public class CharProgression( override fun toString(): String = if (increment > 0) "$start..$endInclusive step $increment" else "$start downTo $endInclusive step ${-increment}" } +@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING) /** * A progression of values of type `Short`. */ -public class ShortProgression( +public open class ShortProgression( override val start: Short, - override val endInclusive: Short, + val endInclusive: Short, override val increment: Int -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Short get() = endInclusive + override fun iterator(): ShortIterator = ShortProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is ShortProgression && (isEmpty() && other.isEmpty() || @@ -102,19 +122,25 @@ public class ShortProgression( /** * A progression of values of type `Int`. */ -public class IntProgression( +public open class IntProgression( override val start: Int, - override val endInclusive: Int, + val endInclusive: Int, override val increment: Int -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Int get() = endInclusive + override fun iterator(): IntIterator = IntProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is IntProgression && (isEmpty() && other.isEmpty() || @@ -129,19 +155,25 @@ public class IntProgression( /** * A progression of values of type `Long`. */ -public class LongProgression( +public open class LongProgression( override val start: Long, - override val endInclusive: Long, + val endInclusive: Long, override val increment: Long -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (increment == 0L) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Long get() = endInclusive + override fun iterator(): LongIterator = LongProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is LongProgression && (isEmpty() && other.isEmpty() || @@ -153,25 +185,31 @@ public class LongProgression( override fun toString(): String = if (increment > 0) "$start..$endInclusive step $increment" else "$start downTo $endInclusive step ${-increment}" } -@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING) +@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING) @Suppress("DEPRECATION_ERROR") /** * A progression of values of type `Float`. */ -public class FloatProgression( +public open class FloatProgression( override val start: Float, - override val endInclusive: Float, + val endInclusive: Float, override val increment: Float -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (java.lang.Float.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN") if (increment == 0.0f) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Float get() = endInclusive + override fun iterator(): FloatIterator = FloatProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is FloatProgression && (isEmpty() && other.isEmpty() || @@ -183,25 +221,31 @@ public class FloatProgression( override fun toString(): String = if (increment > 0) "$start..$endInclusive step $increment" else "$start downTo $endInclusive step ${-increment}" } -@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING) +@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING) @Suppress("DEPRECATION_ERROR") /** * A progression of values of type `Double`. */ -public class DoubleProgression( +public open class DoubleProgression( override val start: Double, - override val endInclusive: Double, + val endInclusive: Double, override val increment: Double -) : InclusiveRangeProgression { +) : Progression, Iterable { init { if (java.lang.Double.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN") if (increment == 0.0) throw IllegalArgumentException("Increment must be non-zero") } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: Double get() = endInclusive + override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is DoubleProgression && (isEmpty() && other.isEmpty() || diff --git a/core/builtins/src/kotlin/Ranges.kt b/core/builtins/src/kotlin/Ranges.kt index af194e42dbc..9b9f7196066 100644 --- a/core/builtins/src/kotlin/Ranges.kt +++ b/core/builtins/src/kotlin/Ranges.kt @@ -18,20 +18,16 @@ package kotlin +@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING) /** * A range of values of type `Byte`. */ -public class ByteRange(override val start: Byte, override val endInclusive: Byte) : InclusiveRange, InclusiveRangeProgression { +public class ByteRange(start: Byte, endInclusive: Byte) : ByteProgression(start, endInclusive, 1), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Byte get() = endInclusive - override val increment: Int - get() = 1 - override fun contains(item: Byte): Boolean = start <= item && item <= endInclusive - override fun iterator(): ByteIterator = ByteProgressionIterator(start, endInclusive, 1) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -52,17 +48,12 @@ public class ByteRange(override val start: Byte, override val endInclusive: Byte /** * A range of values of type `Char`. */ -public class CharRange(override val start: Char, override val endInclusive: Char) : InclusiveRange, InclusiveRangeProgression { +public class CharRange(start: Char, endInclusive: Char) : CharProgression(start, endInclusive, 1), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Char get() = endInclusive - override val increment: Int - get() = 1 - override fun contains(item: Char): Boolean = start <= item && item <= endInclusive - override fun iterator(): CharIterator = CharProgressionIterator(start, endInclusive, 1) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -80,20 +71,16 @@ public class CharRange(override val start: Char, override val endInclusive: Char } } +@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING) /** * A range of values of type `Short`. */ -public class ShortRange(override val start: Short, override val endInclusive: Short) : InclusiveRange, InclusiveRangeProgression { +public class ShortRange(start: Short, endInclusive: Short) : ShortProgression(start, endInclusive, 1), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Short get() = endInclusive - override val increment: Int - get() = 1 - override fun contains(item: Short): Boolean = start <= item && item <= endInclusive - override fun iterator(): ShortIterator = ShortProgressionIterator(start, endInclusive, 1) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -114,17 +101,12 @@ public class ShortRange(override val start: Short, override val endInclusive: Sh /** * A range of values of type `Int`. */ -public class IntRange(override val start: Int, override val endInclusive: Int) : InclusiveRange, InclusiveRangeProgression { +public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, endInclusive, 1), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Int get() = endInclusive - override val increment: Int - get() = 1 - override fun contains(item: Int): Boolean = start <= item && item <= endInclusive - override fun iterator(): IntIterator = IntProgressionIterator(start, endInclusive, 1) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -145,17 +127,12 @@ public class IntRange(override val start: Int, override val endInclusive: Int) : /** * A range of values of type `Long`. */ -public class LongRange(override val start: Long, override val endInclusive: Long) : InclusiveRange, InclusiveRangeProgression { +public class LongRange(start: Long, endInclusive: Long) : LongProgression(start, endInclusive, 1), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Long get() = endInclusive - override val increment: Long - get() = 1 - override fun contains(item: Long): Boolean = start <= item && item <= endInclusive - override fun iterator(): LongIterator = LongProgressionIterator(start, endInclusive, 1) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -178,17 +155,12 @@ public class LongRange(override val start: Long, override val endInclusive: Long /** * A range of values of type `Float`. */ -public class FloatRange(override val start: Float, override val endInclusive: Float) : InclusiveRange, InclusiveRangeProgression { +public class FloatRange(start: Float, endInclusive: Float) : FloatProgression(start, endInclusive, 1.0f), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Float get() = endInclusive - override val increment: Float - get() = 1.0f - override fun contains(item: Float): Boolean = start <= item && item <= endInclusive - override fun iterator(): FloatIterator = FloatProgressionIterator(start, endInclusive, 1.0f) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = @@ -211,17 +183,12 @@ public class FloatRange(override val start: Float, override val endInclusive: Fl /** * A range of values of type `Double`. */ -public class DoubleRange(override val start: Double, override val endInclusive: Double) : InclusiveRange, InclusiveRangeProgression { +public class DoubleRange(start: Double, endInclusive: Double) : DoubleProgression(start, endInclusive, 1.0), InclusiveRange { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: Double get() = endInclusive - override val increment: Double - get() = 1.0 - override fun contains(item: Double): Boolean = start <= item && item <= endInclusive - override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, endInclusive, 1.0) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean = diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/progressions.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/progressions.kt index de8fe9a061f..bb30341e606 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/progressions.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/progressions.kt @@ -65,27 +65,37 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) { } if (kind == FLOAT || kind == DOUBLE) { - out.println("""@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)""") + out.println("""@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)""") out.println("""@Suppress("DEPRECATION_ERROR")""") } + if (kind == SHORT || kind == BYTE) { + out.println("""@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING)""") + } + out.println( """/** * A progression of values of type `$t`. */ -public class $progression( +public open class $progression( override val start: $t, - override val endInclusive: $t, + val endInclusive: $t, override val increment: $incrementType -) : InclusiveRangeProgression<$t> { +) : Progression<$t>, Iterable<$t> { init { $constructor } + /** + * The end value of the progression (inclusive). + */ + @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) + public override val end: $t get() = endInclusive + override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(start, endInclusive, increment) /** Checks if the progression is empty. */ - public fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive + public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive override fun equals(other: Any?): Boolean = other is $progression && (isEmpty() && other.isEmpty() || diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/ranges.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/ranges.kt index fdd51142152..e42120634db 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/ranges.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/ranges.kt @@ -68,22 +68,20 @@ class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) { out.println("""@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)""") out.println("""@Suppress("DEPRECATION_ERROR")""") } + if (kind == SHORT || kind == BYTE) { + out.println("""@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING)""") + } out.println( """/** * A range of values of type `$t`. */ -public class $range(override val start: $t, override val endInclusive: $t) : InclusiveRange<$t>, InclusiveRangeProgression<$t> { +public class $range(start: $t, endInclusive: $t) : ${t}Progression(start, endInclusive, $increment), InclusiveRange<$t> { @Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive")) override val end: $t get() = endInclusive - override val increment: $incrementType - get() = $increment - override fun contains(item: $t): Boolean = start <= item && item <= endInclusive - override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(start, endInclusive, $increment) - override fun isEmpty(): Boolean = start > endInclusive override fun equals(other: Any?): Boolean =