From 1dba69186c0be98c4eb5fda02f10a2fc65644639 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 11 Nov 2013 15:52:14 +0400 Subject: [PATCH] Stdlib compilation error fixes with new diagnostics --- libraries/stdlib/src/kotlin/ArraysJVM.kt | 18 ++++++------ libraries/stdlib/src/kotlin/AssertionsJVM.kt | 6 ++-- .../stdlib/src/kotlin/IterablesSpecial.kt | 2 +- libraries/stdlib/src/kotlin/Iterators.kt | 8 +++--- libraries/stdlib/src/kotlin/IteratorsJVM.kt | 2 +- libraries/stdlib/src/kotlin/JUtil.kt | 8 +++--- libraries/stdlib/src/kotlin/Maps.kt | 8 +++--- libraries/stdlib/src/kotlin/MapsJVM.kt | 2 +- libraries/stdlib/src/kotlin/OrderingJVM.kt | 4 +-- libraries/stdlib/src/kotlin/Preconditions.kt | 10 +++---- libraries/stdlib/src/kotlin/StandardJVM.kt | 4 +-- libraries/stdlib/src/kotlin/Strings.kt | 2 +- libraries/stdlib/src/kotlin/StringsJVM.kt | 8 +++--- .../stdlib/src/kotlin/beans/Listeners.kt | 2 +- .../stdlib/src/kotlin/concurrent/Thread.kt | 8 +++--- libraries/stdlib/src/kotlin/io/JIO.kt | 20 ++++++------- libraries/stdlib/src/kotlin/test/Test.kt | 28 +++++++++++-------- libraries/stdlib/src/kotlin/test/TestJVM.kt | 2 +- 18 files changed, 75 insertions(+), 67 deletions(-) diff --git a/libraries/stdlib/src/kotlin/ArraysJVM.kt b/libraries/stdlib/src/kotlin/ArraysJVM.kt index 7f007fba326..caf5c9898bc 100644 --- a/libraries/stdlib/src/kotlin/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/ArraysJVM.kt @@ -75,17 +75,17 @@ public inline fun FloatArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays public inline fun DoubleArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays.sort(this, fromIndex, toIndex) public inline fun CharArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays.sort(this, fromIndex, toIndex) -public inline fun BooleanArray.copyOf(newLength: Int = this.size) : BooleanArray = Arrays.copyOf(this, newLength) -public inline fun ByteArray.copyOf(newLength: Int = this.size) : ByteArray = Arrays.copyOf(this, newLength) -public inline fun ShortArray.copyOf(newLength: Int = this.size) : ShortArray = Arrays.copyOf(this, newLength) -public inline fun IntArray.copyOf(newLength: Int = this.size) : IntArray = Arrays.copyOf(this, newLength) -public inline fun LongArray.copyOf(newLength: Int = this.size) : LongArray = Arrays.copyOf(this, newLength) -public inline fun FloatArray.copyOf(newLength: Int = this.size) : FloatArray = Arrays.copyOf(this, newLength) -public inline fun DoubleArray.copyOf(newLength: Int = this.size) : DoubleArray = Arrays.copyOf(this, newLength) -public inline fun CharArray.copyOf(newLength: Int = this.size) : CharArray = Arrays.copyOf(this, newLength) +public fun BooleanArray.copyOf(newLength: Int = this.size) : BooleanArray = Arrays.copyOf(this, newLength) +public fun ByteArray.copyOf(newLength: Int = this.size) : ByteArray = Arrays.copyOf(this, newLength) +public fun ShortArray.copyOf(newLength: Int = this.size) : ShortArray = Arrays.copyOf(this, newLength) +public fun IntArray.copyOf(newLength: Int = this.size) : IntArray = Arrays.copyOf(this, newLength) +public fun LongArray.copyOf(newLength: Int = this.size) : LongArray = Arrays.copyOf(this, newLength) +public fun FloatArray.copyOf(newLength: Int = this.size) : FloatArray = Arrays.copyOf(this, newLength) +public fun DoubleArray.copyOf(newLength: Int = this.size) : DoubleArray = Arrays.copyOf(this, newLength) +public fun CharArray.copyOf(newLength: Int = this.size) : CharArray = Arrays.copyOf(this, newLength) // TODO: resuling array may contain nulls even if T is non-nullable -public inline fun Array.copyOf(newLength: Int = this.size) : Array = Arrays.copyOf(this, newLength) as Array +public fun Array.copyOf(newLength: Int = this.size) : Array = Arrays.copyOf(this, newLength) as Array public inline fun BooleanArray.copyOfRange(from: Int, to: Int) : BooleanArray = Arrays.copyOfRange(this, from, to) public inline fun ByteArray.copyOfRange(from: Int, to: Int) : ByteArray = Arrays.copyOfRange(this, from, to) diff --git a/libraries/stdlib/src/kotlin/AssertionsJVM.kt b/libraries/stdlib/src/kotlin/AssertionsJVM.kt index 1e8d3ea9cff..6654b50d82f 100644 --- a/libraries/stdlib/src/kotlin/AssertionsJVM.kt +++ b/libraries/stdlib/src/kotlin/AssertionsJVM.kt @@ -2,13 +2,15 @@ package kotlin private object _Assertions -private val ASSERTIONS_ENABLED = _Assertions.javaClass.desiredAssertionStatus() + +deprecated("Must be puplic to make assert() inlinable") +public val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus() /** * Throws an [[AssertionError]] with an optional *message* if the *value* is false * and runtime assertions have been enabled on the JVM using the *-ea* JVM option. */ -public inline fun assert(value: Boolean, message: Any = "Assertion failed") { +public fun assert(value: Boolean, message: Any = "Assertion failed") { if (ASSERTIONS_ENABLED) { if (!value) { throw AssertionError(message) diff --git a/libraries/stdlib/src/kotlin/IterablesSpecial.kt b/libraries/stdlib/src/kotlin/IterablesSpecial.kt index 17004f9ee68..347e1ecc7bd 100644 --- a/libraries/stdlib/src/kotlin/IterablesSpecial.kt +++ b/libraries/stdlib/src/kotlin/IterablesSpecial.kt @@ -23,7 +23,7 @@ public fun Iterable.count() : Int { return number } -private fun countTo(n: Int): (T) -> Boolean { +public fun countTo(n: Int): (T) -> Boolean { var count = 0 return { ++count; count <= n } } diff --git a/libraries/stdlib/src/kotlin/Iterators.kt b/libraries/stdlib/src/kotlin/Iterators.kt index ce64ba62e39..d44266ca9bb 100644 --- a/libraries/stdlib/src/kotlin/Iterators.kt +++ b/libraries/stdlib/src/kotlin/Iterators.kt @@ -7,7 +7,7 @@ import kotlin.test.assertTrue /** * Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null* */ -public inline fun iterate(nextFunction: () -> T?) : Iterator { +public fun iterate(nextFunction: () -> T?) : Iterator { return FunctionIterator(nextFunction) } @@ -15,7 +15,7 @@ public inline fun iterate(nextFunction: () -> T?) : Iterator { * Returns an iterator which invokes the function to calculate the next value based on the previous one on each iteration * until the function returns *null* */ -public inline fun iterate(initialValue: T, nextFunction: (T) -> T?): Iterator = +public /*inline*/ fun iterate(initialValue: T, nextFunction: (T) -> T?): Iterator = iterate(nextFunction.toGenerator(initialValue)) /** @@ -26,7 +26,7 @@ public inline fun Iterator.zip(iterator: Iterator): Iterator Iterator.skip(n: Int): Iterator = SkippingIterator(this, n) +public fun Iterator.skip(n: Int): Iterator = SkippingIterator(this, n) class FilterIterator(val iterator : Iterator, val predicate: (T)-> Boolean) : AbstractIterator() { override protected fun computeNext(): Unit { @@ -203,7 +203,7 @@ class SkippingIterator(val iterator: Iterator, val n: Int): Iterator { } } -fun Function1.toGenerator(initialValue: T): Function0 { +public fun Function1.toGenerator(initialValue: T): Function0 { var nextValue: T? = initialValue return { nextValue?.let { result -> diff --git a/libraries/stdlib/src/kotlin/IteratorsJVM.kt b/libraries/stdlib/src/kotlin/IteratorsJVM.kt index 75033c0029d..14d5e671e2d 100644 --- a/libraries/stdlib/src/kotlin/IteratorsJVM.kt +++ b/libraries/stdlib/src/kotlin/IteratorsJVM.kt @@ -3,7 +3,7 @@ package kotlin import kotlin.support.* /** Returns an iterator over elements that are instances of a given type *R* which is a subclass of *T* */ -public inline fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass) +public fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass) private class FilterIsIterator(val iterator : Iterator, val klass: Class) : AbstractIterator() { override protected fun computeNext(): Unit { diff --git a/libraries/stdlib/src/kotlin/JUtil.kt b/libraries/stdlib/src/kotlin/JUtil.kt index 5074760f009..e68d39890c7 100644 --- a/libraries/stdlib/src/kotlin/JUtil.kt +++ b/libraries/stdlib/src/kotlin/JUtil.kt @@ -3,17 +3,17 @@ package kotlin import java.util.* /** Returns the size of the collection */ -val Collection<*>.size : Int +public val Collection<*>.size : Int get() = size() /** Returns true if this collection is empty */ -val Collection<*>.empty : Boolean +public val Collection<*>.empty : Boolean get() = isEmpty() -val Collection<*>.indices : IntRange +public val Collection<*>.indices : IntRange get() = 0..size-1 -val Int.indices: IntRange +public val Int.indices: IntRange get() = 0..this-1 /** Returns true if the collection is not empty */ diff --git a/libraries/stdlib/src/kotlin/Maps.kt b/libraries/stdlib/src/kotlin/Maps.kt index bda2cca48df..72642535184 100644 --- a/libraries/stdlib/src/kotlin/Maps.kt +++ b/libraries/stdlib/src/kotlin/Maps.kt @@ -6,11 +6,11 @@ import java.util.HashMap // Map APIs /** Returns the size of the map */ -val Map<*,*>.size : Int +public val Map<*,*>.size : Int get() = size() /** Returns true if this map is empty */ -val Map<*,*>.empty : Boolean +public val Map<*,*>.empty : Boolean get() = isEmpty() /** Provides [] access to maps */ @@ -22,11 +22,11 @@ public inline fun Map?.orEmpty() : Map /** Returns the key of the entry */ -val Map.Entry.key : K +public val Map.Entry.key : K get() = getKey() /** Returns the value of the entry */ -val Map.Entry.value : V +public val Map.Entry.value : V get() = getValue() /** Returns the key of the entry */ diff --git a/libraries/stdlib/src/kotlin/MapsJVM.kt b/libraries/stdlib/src/kotlin/MapsJVM.kt index 6c71c9f3277..86b4a201efa 100644 --- a/libraries/stdlib/src/kotlin/MapsJVM.kt +++ b/libraries/stdlib/src/kotlin/MapsJVM.kt @@ -34,7 +34,7 @@ public inline fun Map.toSortedMap(comparator: Comparator): SortedM * * @includeFunctionBody ../../test/MapTest.kt toProperties */ -public inline fun Map.toProperties(): Properties { +public fun Map.toProperties(): Properties { val answer = Properties() for (e in this) { answer.put(e.key, e.value) diff --git a/libraries/stdlib/src/kotlin/OrderingJVM.kt b/libraries/stdlib/src/kotlin/OrderingJVM.kt index 7533bd79d58..47e54c154b1 100644 --- a/libraries/stdlib/src/kotlin/OrderingJVM.kt +++ b/libraries/stdlib/src/kotlin/OrderingJVM.kt @@ -36,7 +36,7 @@ public inline fun > compareValues(a: T?, b: T?): Int { /** * Creates a comparator using the sequence of functions used to calculate a value to compare on */ -public inline fun comparator(vararg functions: T.() -> Comparable<*>?): Comparator { +public fun comparator(vararg functions: T.() -> Comparable<*>?): Comparator { return FunctionComparator(*functions) } @@ -59,7 +59,7 @@ private class FunctionComparator(vararg val functions: T.() -> Comparable<*>? /** * Creates a comparator using the sequence of functions used to calculate a value to compare on */ -public inline fun comparator(fn: (T,T) -> Int): Comparator { +public fun comparator(fn: (T,T) -> Int): Comparator { return Function2Comparator(fn) } private class Function2Comparator(val compareFn: (T,T) -> Int): Comparator { diff --git a/libraries/stdlib/src/kotlin/Preconditions.kt b/libraries/stdlib/src/kotlin/Preconditions.kt index 6b6b340a654..c08bf38b8c2 100644 --- a/libraries/stdlib/src/kotlin/Preconditions.kt +++ b/libraries/stdlib/src/kotlin/Preconditions.kt @@ -9,7 +9,7 @@ import java.lang.IllegalStateException * * @includeFunctionBody ../../test/PreconditionsTest.kt failingRequireWithMessage */ -public inline fun require(value: Boolean, message: Any = "Failed requirement"): Unit { +public fun require(value: Boolean, message: Any = "Failed requirement"): Unit { if (!value) { throw IllegalArgumentException(message.toString()) } @@ -33,7 +33,7 @@ public inline fun require(value: Boolean, lazyMessage: () -> String): Unit { * * @includeFunctionBody ../../test/PreconditionsTest.kt requireNotNull */ -public inline fun requireNotNull(value: T?, message: Any = "Required value was null"): T { +public fun requireNotNull(value: T?, message: Any = "Required value was null"): T { if (value == null) { throw IllegalArgumentException(message.toString()) } else { @@ -46,7 +46,7 @@ public inline fun requireNotNull(value: T?, message: Any = "Required val * * @includeFunctionBody ../../test/PreconditionsTest.kt failingCheckWithMessage */ -public inline fun check(value: Boolean, message: Any = "Check failed"): Unit { +public fun check(value: Boolean, message: Any = "Check failed"): Unit { if (!value) { throw IllegalStateException(message.toString()) } @@ -70,7 +70,7 @@ public inline fun check(value: Boolean, lazyMessage: () -> String): Unit { * * @includeFunctionBody ../../test/PreconditionsTest.kt checkNotNull */ -public inline fun checkNotNull(value: T?, message: String = "Required value was null"): T { +public fun checkNotNull(value: T?, message: String = "Required value was null"): T { if (value == null) { throw IllegalStateException(message) } else { @@ -78,4 +78,4 @@ public inline fun checkNotNull(value: T?, message: String = "Required va } } -public inline fun error(message: String): Nothing = throw RuntimeException(message) +public fun error(message: String): Nothing = throw RuntimeException(message) diff --git a/libraries/stdlib/src/kotlin/StandardJVM.kt b/libraries/stdlib/src/kotlin/StandardJVM.kt index 7e995f870b5..d781ae64b99 100644 --- a/libraries/stdlib/src/kotlin/StandardJVM.kt +++ b/libraries/stdlib/src/kotlin/StandardJVM.kt @@ -42,7 +42,7 @@ public inline fun Throwable.printStackTrace(stream: PrintStream): Unit { /** * A helper method for creating a [[Callable]] from a function */ -public inline fun callable(action: ()-> T): Callable { +public /*inline*/ fun callable(action: ()-> T): Callable { return object: Callable { public override fun call() = action() } @@ -51,7 +51,7 @@ public inline fun callable(action: ()-> T): Callable { /** * A helper method for creating a [[Runnable]] from a function */ -public inline fun runnable(action: ()-> Unit): Runnable { +public /*inline*/ fun runnable(action: ()-> Unit): Runnable { return object: Runnable { public override fun run() { action() diff --git a/libraries/stdlib/src/kotlin/Strings.kt b/libraries/stdlib/src/kotlin/Strings.kt index b2926a53549..726c4e54b90 100644 --- a/libraries/stdlib/src/kotlin/Strings.kt +++ b/libraries/stdlib/src/kotlin/Strings.kt @@ -35,7 +35,7 @@ public inline fun String?.isNotEmpty() : Boolean = this != null && this.length() /** Iterator for characters of given CharSequence */ -public inline fun CharSequence.iterator() : CharIterator = object: jet.CharIterator() { +public fun CharSequence.iterator() : CharIterator = object: jet.CharIterator() { private var index = 0 public override fun nextChar(): Char = get(index++) diff --git a/libraries/stdlib/src/kotlin/StringsJVM.kt b/libraries/stdlib/src/kotlin/StringsJVM.kt index 7ccd4eea976..1af3682d5f7 100644 --- a/libraries/stdlib/src/kotlin/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/StringsJVM.kt @@ -147,7 +147,7 @@ public inline fun CharSequence.toString() : String? = (this as java.lang.CharSeq public inline fun CharSequence.length() : Int = (this as java.lang.CharSequence).length() -public inline fun String.toByteArray(encoding: String = Charset.defaultCharset().name()): ByteArray = (this as java.lang.String).getBytes(encoding) +public fun String.toByteArray(encoding: String = Charset.defaultCharset().name()): ByteArray = (this as java.lang.String).getBytes(encoding) public inline fun String.toByteArray(encoding: Charset): ByteArray = (this as java.lang.String).getBytes(encoding) public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this) @@ -162,7 +162,7 @@ public inline fun String.toDouble() : Double = java.lang.Double.parseDouble(this * with the specified flags from [[Pattern]] or'd together * so that strings can be split or matched on. */ -public inline fun String.toRegex(flags: Int=0): java.util.regex.Pattern { +public fun String.toRegex(flags: Int=0): java.util.regex.Pattern { return java.util.regex.Pattern.compile(this, flags) } @@ -283,7 +283,7 @@ public inline fun String.any(predicate: (Char) -> Boolean): Boolean { * * @includeFunctionBody ../../test/StringTest.kt appendString */ -public inline fun String.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { +public fun String.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit { buffer.append(prefix) var count = 0 for (c in this) { @@ -441,7 +441,7 @@ public inline fun String.groupByTo(result: MutableMap, toKey: (Ch * * @includeFunctionBody ../../test/StringTest.kt makeString */ -public inline fun String.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { +public fun String.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) return buffer.toString() diff --git a/libraries/stdlib/src/kotlin/beans/Listeners.kt b/libraries/stdlib/src/kotlin/beans/Listeners.kt index db2d3a7424a..bc948a78c89 100644 --- a/libraries/stdlib/src/kotlin/beans/Listeners.kt +++ b/libraries/stdlib/src/kotlin/beans/Listeners.kt @@ -8,7 +8,7 @@ import java.beans.* /** * Creates a [[PropertyChangeListener]] for the given function for processing each [[PropertyChangeEvent]] */ -inline fun propertyChangeListener(fn: (PropertyChangeEvent) -> Unit): PropertyChangeListener = FunctionPropertyChangeListener(fn) +fun propertyChangeListener(fn: (PropertyChangeEvent) -> Unit): PropertyChangeListener = FunctionPropertyChangeListener(fn) private class FunctionPropertyChangeListener(val fn: (PropertyChangeEvent) -> Unit) : PropertyChangeListener { public override fun propertyChange(e: PropertyChangeEvent) { diff --git a/libraries/stdlib/src/kotlin/concurrent/Thread.kt b/libraries/stdlib/src/kotlin/concurrent/Thread.kt index 5441bf74759..120e6b7afb1 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Thread.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Thread.kt @@ -49,7 +49,7 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo /** * Executes the given block on the [[Executor]] */ -public inline fun Executor.execute(action: ()->Unit) { +public /*inline*/ fun Executor.execute(action: ()->Unit) { execute(runnable(action)) } @@ -57,14 +57,14 @@ public inline fun Executor.execute(action: ()->Unit) { * Allows you to use the executor as a function to * execute the given block on the [[Executor]]. */ -public inline fun Executor.invoke(action: ()->Unit) { +public /*inline*/ fun Executor.invoke(action: ()->Unit) { execute(runnable(action)) } /** * Executes the given block on the [[Executor]] */ -public inline fun ExecutorService.submit(action: ()->T):Future { +public /*inline*/ fun ExecutorService.submit(action: ()->T):Future { val c:Callable = callable(action) return submit(c); } @@ -73,6 +73,6 @@ public inline fun ExecutorService.submit(action: ()->T):Future { * Allows you to use the executor as a function to * execute the given block on the [[Executor]]. */ -public inline fun ExecutorService.invoke(action: ()->T):Future { +public /*inline*/ fun ExecutorService.invoke(action: ()->T):Future { return submit(action) } \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/io/JIO.kt b/libraries/stdlib/src/kotlin/io/JIO.kt index d9b87799761..6167d2cd3fe 100644 --- a/libraries/stdlib/src/kotlin/io/JIO.kt +++ b/libraries/stdlib/src/kotlin/io/JIO.kt @@ -141,7 +141,7 @@ private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : I })) /** Reads a line of input from [[System.in]] */ -public inline fun readLine() : String? = stdin.readLine() +public fun readLine() : String? = stdin.readLine() /** Uses the given resource then closes it down correctly whether an exception is thrown or not */ public inline fun T.use(block: (T)-> R) : R { @@ -178,33 +178,33 @@ object: ByteIterator() { } /** Creates a buffered input stream */ -public inline fun InputStream.buffered(bufferSize: Int = defaultBufferSize) : InputStream +public fun InputStream.buffered(bufferSize: Int = defaultBufferSize) : InputStream = if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize) -public inline fun InputStream.reader(encoding: Charset = defaultCharset) : InputStreamReader = InputStreamReader(this, encoding) +public fun InputStream.reader(encoding: Charset = defaultCharset) : InputStreamReader = InputStreamReader(this, encoding) public inline fun InputStream.reader(encoding: String) : InputStreamReader = InputStreamReader(this, encoding) public inline fun InputStream.reader(encoding: CharsetDecoder) : InputStreamReader = InputStreamReader(this, encoding) -public inline fun OutputStream.buffered(bufferSize: Int = defaultBufferSize) : BufferedOutputStream +public fun OutputStream.buffered(bufferSize: Int = defaultBufferSize) : BufferedOutputStream = if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize) -public inline fun OutputStream.writer(encoding: Charset = defaultCharset) : OutputStreamWriter = OutputStreamWriter(this, encoding) +public fun OutputStream.writer(encoding: Charset = defaultCharset) : OutputStreamWriter = OutputStreamWriter(this, encoding) -public inline fun OutputStream.writer(encoding: String) : OutputStreamWriter = OutputStreamWriter(this, encoding) +public fun OutputStream.writer(encoding: String) : OutputStreamWriter = OutputStreamWriter(this, encoding) -public inline fun OutputStream.writer(encoding: CharsetEncoder) : OutputStreamWriter = OutputStreamWriter(this, encoding) +public fun OutputStream.writer(encoding: CharsetEncoder) : OutputStreamWriter = OutputStreamWriter(this, encoding) -public inline fun Reader.buffered(bufferSize: Int = defaultBufferSize): BufferedReader +public fun Reader.buffered(bufferSize: Int = defaultBufferSize): BufferedReader = if(this is BufferedReader) this else BufferedReader(this, bufferSize) -public inline fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter +public fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter = if(this is BufferedWriter) this else BufferedWriter(this, bufferSize) @@ -231,7 +231,7 @@ public inline fun Reader.useLines(block: (Iterator) -> T): T = this. *
* We suggest you try the method useLines() instead which closes the stream when the processing is complete. */ -public inline fun BufferedReader.lineIterator() : Iterator = LineIterator(this) +public fun BufferedReader.lineIterator() : Iterator = LineIterator(this) class LineIterator(val reader: BufferedReader) : Iterator { private var nextValue: String? = null diff --git a/libraries/stdlib/src/kotlin/test/Test.kt b/libraries/stdlib/src/kotlin/test/Test.kt index 8aef9079691..b63a762e10c 100644 --- a/libraries/stdlib/src/kotlin/test/Test.kt +++ b/libraries/stdlib/src/kotlin/test/Test.kt @@ -13,7 +13,7 @@ public inline fun assertTrue(message: String, block: ()-> Boolean) { } /** Asserts that the given block returns true */ -public inline fun assertTrue(block: ()-> Boolean) : Unit = assertTrue(block.toString(), block) +public inline fun assertTrue(block: ()-> Boolean) : Unit = assertTrue("exprected true", block) /** Asserts that the given block returns false */ public inline fun assertNot(message: String, block: ()-> Boolean) { @@ -21,31 +21,37 @@ public inline fun assertNot(message: String, block: ()-> Boolean) { } /** Asserts that the given block returns false */ -public inline fun assertNot(block: ()-> Boolean) : Unit = assertNot(block.toString(), block) +public fun assertNot(block: ()-> Boolean) : Unit = assertNot("expected false", block) /** Asserts that the expression is true with an optional message */ -public inline fun assertTrue(actual: Boolean, message: String = "") { +public fun assertTrue(actual: Boolean, message: String = "") { return assertEquals(true, actual, message) } /** Asserts that the expression is false with an optional message */ -public inline fun assertFalse(actual: Boolean, message: String = "") { +public fun assertFalse(actual: Boolean, message: String = "") { return assertEquals(false, actual, message) } /** Asserts that the expected value is equal to the actual value, with an optional message */ -public inline fun assertEquals(expected: Any?, actual: Any?, message: String = "") { +public fun assertEquals(expected: Any?, actual: Any?, message: String = "") { asserter.assertEquals(message, expected, actual) } /** Asserts that the expression is not null, with an optional message */ -public inline fun assertNotNull(actual: T?, message: String = ""): T { +public fun assertNotNull(actual: T?, message: String = ""): T { asserter.assertNotNull(message, actual) return actual!! } +//TODO merge with next via default /** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */ -public inline fun assertNotNull(actual: T?, message: String = "", block: (T) -> R) { +public inline fun assertNotNull(actual: T?, block: (T) -> R) { + assertNotNull(actual, "", block) +} + +/** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */ +public inline fun assertNotNull(actual: T?, message: String, block: (T) -> R) { asserter.assertNotNull(message, actual) if (actual != null) { block(actual) @@ -53,18 +59,18 @@ public inline fun assertNotNull(actual: T?, message: String = "", block: } /** Asserts that the expression is null, with an optional message */ -public inline fun assertNull(actual: Any?, message: String = "") { +public fun assertNull(actual: Any?, message: String = "") { asserter.assertNull(message, actual) } /** Marks a test as having failed if this point in the execution path is reached, with an optional message */ -public inline fun fail(message: String = "") { +public fun fail(message: String = "") { asserter.fail(message) } /** Asserts that given function block returns the given expected value */ public inline fun expect(expected: T, block: ()-> T) { - expect(expected, block.toString(), block) + expect(expected, "expected " + expected, block) } /** Asserts that given function block returns the given expected value and use the given message if it fails */ @@ -88,7 +94,7 @@ public fun fails(block: ()-> Unit): Throwable? { /** * A plugin for performing assertions which can reuse JUnit or TestNG */ -trait Asserter { +public trait Asserter { public fun assertTrue(message: String, actual: Boolean): Unit public fun assertEquals(message: String, expected: Any?, actual: Any?): Unit diff --git a/libraries/stdlib/src/kotlin/test/TestJVM.kt b/libraries/stdlib/src/kotlin/test/TestJVM.kt index 44c230dd119..ccf28e2d9f9 100644 --- a/libraries/stdlib/src/kotlin/test/TestJVM.kt +++ b/libraries/stdlib/src/kotlin/test/TestJVM.kt @@ -21,7 +21,7 @@ public fun failsWith(exceptionClass: Class, block: ()-> Any): * to implement in your unit test output */ public inline fun todo(block: ()-> Any) { - println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block) + println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1)) } private var _asserter: Asserter? = null