Merge pull request #570 from JetBrains/rr/yole/generate-more-stdlib

Replace some manually duplicated stdlib method implementations with generated code
This commit is contained in:
Evgeny Gerashchenko
2015-02-11 17:26:30 +04:00
8 changed files with 448 additions and 197 deletions
+108
View File
@@ -9,6 +9,60 @@ import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns the range of valid indices for the array
*/
public val <T> Array<out T>.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val BooleanArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val ByteArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val CharArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val DoubleArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val FloatArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val IntArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val LongArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns the range of valid indices for the array
*/
public val ShortArray.indices: IntRange
get() = IntRange(0, lastIndex)
/**
* Returns true if the array is empty
*/
@@ -135,3 +189,57 @@ public fun ShortArray.isNotEmpty(): Boolean {
return !isEmpty()
}
/**
* Returns the last valid index for the array
*/
public val <T> Array<out T>.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val BooleanArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val ByteArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val CharArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val DoubleArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val FloatArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val IntArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val LongArray.lastIndex: Int
get() = size - 1
/**
* Returns the last valid index for the array
*/
public val ShortArray.lastIndex: Int
get() = size - 1
+223
View File
@@ -0,0 +1,223 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun ByteProgression.reversed(): ByteProgression {
return ByteProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun CharProgression.reversed(): CharProgression {
return CharProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun DoubleProgression.reversed(): DoubleProgression {
return DoubleProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun FloatProgression.reversed(): FloatProgression {
return FloatProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun IntProgression.reversed(): IntProgression {
return IntProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun LongProgression.reversed(): LongProgression {
return LongProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step
*/
public fun ShortProgression.reversed(): ShortProgression {
return ShortProgression(end, start, -increment)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun ByteRange.reversed(): ByteProgression {
return ByteProgression(end, start, -1)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun CharRange.reversed(): CharProgression {
return CharProgression(end, start, -1)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun DoubleRange.reversed(): DoubleProgression {
return DoubleProgression(end, start, -1.0)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun FloatRange.reversed(): FloatProgression {
return FloatProgression(end, start, -1.0f)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun IntRange.reversed(): IntProgression {
return IntProgression(end, start, -1)
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun LongRange.reversed(): LongProgression {
return LongProgression(end, start, -1.toLong())
}
/**
* Returns a progression that goes over this range in reverse direction
*/
public fun ShortRange.reversed(): ShortProgression {
return ShortProgression(end, start, -1)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun ByteProgression.step(step: Int): ByteProgression {
checkStepIsPositive(step > 0, step)
return ByteProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun CharProgression.step(step: Int): CharProgression {
checkStepIsPositive(step > 0, step)
return CharProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun DoubleProgression.step(step: Double): DoubleProgression {
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun FloatProgression.step(step: Float): FloatProgression {
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun IntProgression.step(step: Int): IntProgression {
checkStepIsPositive(step > 0, step)
return IntProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun LongProgression.step(step: Long): LongProgression {
checkStepIsPositive(step > 0, step)
return LongProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step
*/
public fun ShortProgression.step(step: Int): ShortProgression {
checkStepIsPositive(step > 0, step)
return ShortProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun ByteRange.step(step: Int): ByteProgression {
checkStepIsPositive(step > 0, step)
return ByteProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun CharRange.step(step: Int): CharProgression {
checkStepIsPositive(step > 0, step)
return CharProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun DoubleRange.step(step: Double): DoubleProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN")
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun FloatRange.step(step: Float): FloatProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN")
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun IntRange.step(step: Int): IntProgression {
checkStepIsPositive(step > 0, step)
return IntProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun LongRange.step(step: Long): LongProgression {
checkStepIsPositive(step > 0, step)
return LongProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step
*/
public fun ShortRange.step(step: Int): ShortProgression {
checkStepIsPositive(step > 0, step)
return ShortProgression(start, end, step)
}
@@ -9,58 +9,3 @@ public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
return result as Array<T>
}
public val BooleanArray.lastIndex: Int
get() = size() - 1
public val ByteArray.lastIndex: Int
get() = size() - 1
public val ShortArray.lastIndex: Int
get() = size() - 1
public val IntArray.lastIndex: Int
get() = size() - 1
public val LongArray.lastIndex: Int
get() = size() - 1
public val FloatArray.lastIndex: Int
get() = size() - 1
public val DoubleArray.lastIndex: Int
get() = size() - 1
public val CharArray.lastIndex: Int
get() = size() - 1
public val Array<*>.lastIndex: Int
get() = size() - 1
public val BooleanArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val ByteArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val ShortArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val IntArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val LongArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val FloatArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val DoubleArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val CharArray.indices: IntRange
get() = IntRange(0, lastIndex)
public val Array<*>.indices: IntRange
get() = IntRange(0, lastIndex)
-133
View File
@@ -23,139 +23,6 @@ public fun <T: Comparable<T>> T.rangeTo(that: T): ComparableRange<T> {
}
public fun CharProgression.reversed(): CharProgression {
return CharProgression(end, start, -increment)
}
public fun ByteProgression.reversed(): ByteProgression {
return ByteProgression(end, start, -increment)
}
public fun ShortProgression.reversed(): ShortProgression {
return ShortProgression(end, start, -increment)
}
public fun IntProgression.reversed(): IntProgression {
return IntProgression(end, start, -increment)
}
public fun FloatProgression.reversed(): FloatProgression {
return FloatProgression(end, start, -increment)
}
public fun LongProgression.reversed(): LongProgression {
return LongProgression(end, start, -increment)
}
public fun DoubleProgression.reversed(): DoubleProgression {
return DoubleProgression(end, start, -increment)
}
public fun CharRange.reversed(): CharProgression {
return CharProgression(end, start, -1)
}
public fun ByteRange.reversed(): ByteProgression {
return ByteProgression(end, start, -1)
}
public fun ShortRange.reversed(): ShortProgression {
return ShortProgression(end, start, -1)
}
public fun IntRange.reversed(): IntProgression {
return IntProgression(end, start, -1)
}
public fun FloatRange.reversed(): FloatProgression {
return FloatProgression(end, start, -1.0.toFloat())
}
public fun LongRange.reversed(): LongProgression {
return LongProgression(end, start, -1.toLong())
}
public fun DoubleRange.reversed(): DoubleProgression {
return DoubleProgression(end, start, -1.0)
}
public fun IntProgression.step(step: Int): IntProgression {
checkStepIsPositive(step > 0, step)
return IntProgression(start, end, if (increment > 0) step else -step)
}
public fun CharProgression.step(step: Int): CharProgression {
checkStepIsPositive(step > 0, step)
return CharProgression(start, end, if (increment > 0) step else -step)
}
public fun ByteProgression.step(step: Int): ByteProgression {
checkStepIsPositive(step > 0, step)
return ByteProgression(start, end, if (increment > 0) step else -step)
}
public fun ShortProgression.step(step: Int): ShortProgression {
checkStepIsPositive(step > 0, step)
return ShortProgression(start, end, if (increment > 0) step else -step)
}
public fun LongProgression.step(step: Long): LongProgression {
checkStepIsPositive(step > 0, step)
return LongProgression(start, end, if (increment > 0) step else -step)
}
public fun FloatProgression.step(step: Float): FloatProgression {
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, if (increment > 0) step else -step)
}
public fun DoubleProgression.step(step: Double): DoubleProgression {
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, if (increment > 0) step else -step)
}
public fun IntRange.step(step: Int): IntProgression {
checkStepIsPositive(step > 0, step)
return IntProgression(start, end, step)
}
public fun CharRange.step(step: Int): CharProgression {
checkStepIsPositive(step > 0, step)
return CharProgression(start, end, step)
}
public fun ByteRange.step(step: Int): ByteProgression {
checkStepIsPositive(step > 0, step)
return ByteProgression(start, end, step)
}
public fun ShortRange.step(step: Int): ShortProgression {
checkStepIsPositive(step > 0, step)
return ShortProgression(start, end, step)
}
public fun LongRange.step(step: Long): LongProgression {
checkStepIsPositive(step > 0, step)
return LongProgression(start, end, step)
}
public fun FloatRange.step(step: Float): FloatProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN")
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, step)
}
public fun DoubleRange.step(step: Double): DoubleProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN")
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, step)
}
private fun checkStepIsPositive(isPositive: Boolean, step: Number) {
if (!isPositive) throw IllegalArgumentException("Step must be positive, was: $step")
}