diff --git a/idea/testData/debugger/tinyApp/outs/evDelegatedProperty.out b/idea/testData/debugger/tinyApp/outs/evDelegatedProperty.out index 6d6cbd4a2f7..e4aba2782c4 100644 --- a/idea/testData/debugger/tinyApp/outs/evDelegatedProperty.out +++ b/idea/testData/debugger/tinyApp/outs/evDelegatedProperty.out @@ -22,7 +22,7 @@ fun main(args: Array) { local = args: java.lang.String[] = {java.lang.String[0]@uniqueID} (sp = evDelegatedProperty.kt, 9) local = a: evDelegatedProperty.A = {evDelegatedProperty.A@uniqueID} (sp = evDelegatedProperty.kt, 10) field = prop$delegate: kotlin.properties.ReadWriteProperty = {kotlin.properties.NotNullVar@uniqueID} (sp = evDelegatedProperty.kt, 6) - field = value: java.lang.Object = {java.lang.Integer@uniqueID}1 (sp = Delegation.!EXT!) + field = value: java.lang.Object = {java.lang.Integer@uniqueID}1 (sp = Delegates.!EXT!) field = value: int = 1 (sp = Integer.!EXT!) field = prop: int = 1 (sp = evDelegatedProperty.kt, 6) Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' diff --git a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt index 510b7e5aa2f..a48d06be03b 100644 --- a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt @@ -3,7 +3,6 @@ package kotlin.collections -import java.io.ByteArrayInputStream import java.nio.charset.Charset /** diff --git a/libraries/stdlib/src/kotlin/collections/JUtil.kt b/libraries/stdlib/src/kotlin/collections/Collections.kt similarity index 81% rename from libraries/stdlib/src/kotlin/collections/JUtil.kt rename to libraries/stdlib/src/kotlin/collections/Collections.kt index a62ccd1ea1a..fa69a5ad20e 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtil.kt +++ b/libraries/stdlib/src/kotlin/collections/Collections.kt @@ -133,39 +133,13 @@ public inline fun List?.orEmpty(): List = this ?: emptyList() public inline fun Enumeration.toList(): List = Collections.list(this) /** - * Returns the size of this iterable if it is known, or `null` otherwise. + * Checks if all elements in the specified collection are contained in this collection. + * + * Allows to overcome type-safety restriction of `containsAll` that requires to pass a collection of type `Collection`. */ -@kotlin.internal.InlineExposed -internal fun Iterable.collectionSizeOrNull(): Int? = if (this is Collection<*>) this.size else null +@kotlin.internal.InlineOnly +public inline fun <@kotlin.internal.OnlyInputTypes T> Collection.containsAll(elements: Collection): Boolean = this.containsAll(elements) -/** - * Returns the size of this iterable if it is known, or the specified [default] value otherwise. - */ -@kotlin.internal.InlineExposed -internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default - -/** Returns true when it's safe to convert this collection to a set without changing contains method behavior. */ -private fun Collection.safeToConvertToSet() = size > 2 && this is ArrayList - -/** Converts this collection to a set, when it's worth so and it doesn't change contains method behavior. */ -internal fun Iterable.convertToSetForSetOperationWith(source: Iterable): Collection = - when(this) { - is Set -> this - is Collection -> - when { - source is Collection && source.size < 2 -> this - else -> if (this.safeToConvertToSet()) toHashSet() else this - } - else -> toHashSet() - } - -/** Converts this collection to a set, when it's worth so and it doesn't change contains method behavior. */ -internal fun Iterable.convertToSetForSetOperation(): Collection = - when(this) { - is Set -> this - is Collection -> if (this.safeToConvertToSet()) toHashSet() else this - else -> toHashSet() - } // copies typed varargs array to array of objects @JvmVersion @@ -278,30 +252,4 @@ private fun rangeCheck(size: Int, fromIndex: Int, toIndex: Int) { } } -/** - * Returns a single list of all elements from all collections in the given collection. - */ -public fun Iterable>.flatten(): List { - val result = ArrayList() - for (element in this) { - result.addAll(element) - } - return result -} - -/** - * Returns a pair of lists, where - * *first* list is built from the first values of each pair from this collection, - * *second* list is built from the second values of each pair from this collection. - */ -public fun Iterable>.unzip(): Pair, List> { - val expectedSize = collectionSizeOrDefault(10) - val listT = ArrayList(expectedSize) - val listR = ArrayList(expectedSize) - for (pair in this) { - listT.add(pair.first) - listR.add(pair.second) - } - return listT to listR -} diff --git a/libraries/stdlib/src/kotlin/collections/IndexedValue.kt b/libraries/stdlib/src/kotlin/collections/IndexedValue.kt new file mode 100644 index 00000000000..7259c82a2b4 --- /dev/null +++ b/libraries/stdlib/src/kotlin/collections/IndexedValue.kt @@ -0,0 +1,9 @@ +package kotlin.collections + +/** + * Data class representing a value from a collection or sequence, along with its index in that collection or sequence. + * + * @property value the underlying value. + * @property index the index of the value in the collection or sequence. + */ +public data class IndexedValue(public val index: Int, public val value: T) diff --git a/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt b/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt deleted file mode 100644 index 1f357fc49ee..00000000000 --- a/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt +++ /dev/null @@ -1,26 +0,0 @@ -package kotlin.collections - -/** - * Data class representing a value from a collection or sequence, along with its index in that collection or sequence. - * - * @property value the underlying value. - * @property index the index of the value in the collection or sequence. - */ -public data class IndexedValue(public val index: Int, public val value: T) - -/** - * A wrapper over another [Iterable] (or any other object that can produce an [Iterator]) that returns - * an indexing iterator. - */ -internal class IndexingIterable(private val iteratorFactory: () -> Iterator) : Iterable> { - override fun iterator(): Iterator> = IndexingIterator(iteratorFactory()) -} - -/** - * Iterator transforming original `iterator` into iterator of [IndexedValue], counting index from zero. - */ -internal class IndexingIterator(private val iterator: Iterator) : Iterator> { - private var index = 0 - final override fun hasNext(): Boolean = iterator.hasNext() - final override fun next(): IndexedValue = IndexedValue(index++, iterator.next()) -} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/collections/Iterables.kt b/libraries/stdlib/src/kotlin/collections/Iterables.kt new file mode 100644 index 00000000000..bd0ae08551b --- /dev/null +++ b/libraries/stdlib/src/kotlin/collections/Iterables.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("CollectionsKt") +package kotlin.collections + +import java.util.* + +/** + * A wrapper over another [Iterable] (or any other object that can produce an [Iterator]) that returns + * an indexing iterator. + */ +internal class IndexingIterable(private val iteratorFactory: () -> Iterator) : Iterable> { + override fun iterator(): Iterator> = IndexingIterator(iteratorFactory()) +} + + +/** + * Returns the size of this iterable if it is known, or `null` otherwise. + */ +@kotlin.internal.InlineExposed +internal fun Iterable.collectionSizeOrNull(): Int? = if (this is Collection<*>) this.size else null + +/** + * Returns the size of this iterable if it is known, or the specified [default] value otherwise. + */ +@kotlin.internal.InlineExposed +internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default + +/** Returns true when it's safe to convert this collection to a set without changing contains method behavior. */ +private fun Collection.safeToConvertToSet() = size > 2 && this is ArrayList + +/** Converts this collection to a set, when it's worth so and it doesn't change contains method behavior. */ +internal fun Iterable.convertToSetForSetOperationWith(source: Iterable): Collection = + when(this) { + is Set -> this + is Collection -> + when { + source is Collection && source.size < 2 -> this + else -> if (this.safeToConvertToSet()) toHashSet() else this + } + else -> toHashSet() + } + +/** Converts this collection to a set, when it's worth so and it doesn't change contains method behavior. */ +internal fun Iterable.convertToSetForSetOperation(): Collection = + when(this) { + is Set -> this + is Collection -> if (this.safeToConvertToSet()) toHashSet() else this + else -> toHashSet() + } + + +/** + * Returns a single list of all elements from all collections in the given collection. + */ +public fun Iterable>.flatten(): List { + val result = ArrayList() + for (element in this) { + result.addAll(element) + } + return result +} + +/** + * Returns a pair of lists, where + * *first* list is built from the first values of each pair from this collection, + * *second* list is built from the second values of each pair from this collection. + */ +public fun Iterable>.unzip(): Pair, List> { + val expectedSize = collectionSizeOrDefault(10) + val listT = ArrayList(expectedSize) + val listR = ArrayList(expectedSize) + for (pair in this) { + listT.add(pair.first) + listR.add(pair.second) + } + return listT to listR +} diff --git a/libraries/stdlib/src/kotlin/collections/Iterators.kt b/libraries/stdlib/src/kotlin/collections/Iterators.kt index 5f1bb2b0cbe..f8131247eb6 100644 --- a/libraries/stdlib/src/kotlin/collections/Iterators.kt +++ b/libraries/stdlib/src/kotlin/collections/Iterators.kt @@ -33,3 +33,11 @@ public inline fun Iterator.forEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) } +/** + * Iterator transforming original `iterator` into iterator of [IndexedValue], counting index from zero. + */ +internal class IndexingIterator(private val iterator: Iterator) : Iterator> { + private var index = 0 + final override fun hasNext(): Boolean = iterator.hasNext() + final override fun next(): IndexedValue = IndexedValue(index++, iterator.next()) +} diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index c602a66373d..3ce4f56f3ca 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -5,14 +5,6 @@ package kotlin.collections import java.util.* -/** - * Checks if all elements in the specified collection are contained in this collection. - * - * Allows to overcome type-safety restriction of `containsAll` that requires to pass a collection of type `Collection`. - */ -@kotlin.internal.InlineOnly -public inline fun <@kotlin.internal.OnlyInputTypes T> Collection.containsAll(elements: Collection): Boolean = this.containsAll(elements) - /** * Removes a single instance of the specified element from this * collection, if it is present. diff --git a/libraries/stdlib/src/kotlin/util/Ordering.kt b/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt similarity index 100% rename from libraries/stdlib/src/kotlin/util/Ordering.kt rename to libraries/stdlib/src/kotlin/comparisons/Comparisons.kt diff --git a/libraries/stdlib/src/kotlin/properties/Delegation.kt b/libraries/stdlib/src/kotlin/properties/Delegates.kt similarity index 63% rename from libraries/stdlib/src/kotlin/properties/Delegation.kt rename to libraries/stdlib/src/kotlin/properties/Delegates.kt index feff34bccc1..694b7540627 100644 --- a/libraries/stdlib/src/kotlin/properties/Delegation.kt +++ b/libraries/stdlib/src/kotlin/properties/Delegates.kt @@ -1,6 +1,5 @@ package kotlin.properties -import java.util.NoSuchElementException import kotlin.reflect.KProperty /** @@ -54,37 +53,3 @@ private class NotNullVar() : ReadWriteProperty { } } -/** - * Implements the core logic of a property delegate for a read/write property that calls callback functions when changed. - * @param initialValue the initial value of the property. - */ -public abstract class ObservableProperty(initialValue: T) : ReadWriteProperty { - private var value = initialValue - - /** - * The callback which is called before a change to the property value is attempted. - * The value of the property hasn't been changed yet, when this callback is invoked. - * If the callback returns `true` the value of the property is being set to the new value, - * and if the callback returns `false` the new value is discarded and the property remains its old value. - */ - protected open fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean = true - - /** - * The callback which is called after the change of the property is made. The value of the property - * has already been changed when this callback is invoked. - */ - protected open fun afterChange (property: KProperty<*>, oldValue: T, newValue: T): Unit {} - - public override fun getValue(thisRef: Any?, property: KProperty<*>): T { - return value - } - - public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { - val oldValue = this.value - if (!beforeChange(property, oldValue, value)) { - return - } - this.value = value - afterChange(property, oldValue, value) - } -} diff --git a/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt b/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt new file mode 100644 index 00000000000..cb3eb98026b --- /dev/null +++ b/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt @@ -0,0 +1,38 @@ +package kotlin.properties + +import kotlin.reflect.KProperty + +/** + * Implements the core logic of a property delegate for a read/write property that calls callback functions when changed. + * @param initialValue the initial value of the property. + */ +public abstract class ObservableProperty(initialValue: T) : ReadWriteProperty { + private var value = initialValue + + /** + * The callback which is called before a change to the property value is attempted. + * The value of the property hasn't been changed yet, when this callback is invoked. + * If the callback returns `true` the value of the property is being set to the new value, + * and if the callback returns `false` the new value is discarded and the property remains its old value. + */ + protected open fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean = true + + /** + * The callback which is called after the change of the property is made. The value of the property + * has already been changed when this callback is invoked. + */ + protected open fun afterChange (property: KProperty<*>, oldValue: T, newValue: T): Unit {} + + public override fun getValue(thisRef: Any?, property: KProperty<*>): T { + return value + } + + public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { + val oldValue = this.value + if (!beforeChange(property, oldValue, value)) { + return + } + this.value = value + afterChange(property, oldValue, value) + } +} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/Ranges.kt b/libraries/stdlib/src/kotlin/ranges/Ranges.kt similarity index 100% rename from libraries/stdlib/src/kotlin/util/Ranges.kt rename to libraries/stdlib/src/kotlin/ranges/Ranges.kt diff --git a/libraries/stdlib/src/kotlin/text/CharCategoryJVM.kt b/libraries/stdlib/src/kotlin/text/CharCategory.kt similarity index 99% rename from libraries/stdlib/src/kotlin/text/CharCategoryJVM.kt rename to libraries/stdlib/src/kotlin/text/CharCategory.kt index 969112004a9..3ec5575aa0a 100644 --- a/libraries/stdlib/src/kotlin/text/CharCategoryJVM.kt +++ b/libraries/stdlib/src/kotlin/text/CharCategory.kt @@ -1,3 +1,4 @@ +@file:JvmVersion package kotlin.text /** diff --git a/libraries/stdlib/src/kotlin/text/CharDirectionalityJVM.kt b/libraries/stdlib/src/kotlin/text/CharDirectionality.kt similarity index 99% rename from libraries/stdlib/src/kotlin/text/CharDirectionalityJVM.kt rename to libraries/stdlib/src/kotlin/text/CharDirectionality.kt index e824b3baca9..71972e2db33 100644 --- a/libraries/stdlib/src/kotlin/text/CharDirectionalityJVM.kt +++ b/libraries/stdlib/src/kotlin/text/CharDirectionality.kt @@ -1,3 +1,4 @@ +@file:JvmVersion package kotlin.text /** diff --git a/libraries/stdlib/src/kotlin/text/CharsetsJVM.kt b/libraries/stdlib/src/kotlin/text/Charsets.kt similarity index 99% rename from libraries/stdlib/src/kotlin/text/CharsetsJVM.kt rename to libraries/stdlib/src/kotlin/text/Charsets.kt index 063e97eeb7c..8b85adccbd0 100644 --- a/libraries/stdlib/src/kotlin/text/CharsetsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/Charsets.kt @@ -1,4 +1,5 @@ @file:JvmName("CharsetsKt") +@file:JvmVersion package kotlin.text import java.nio.charset.* diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index e83302bfe88..346465b55b9 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -1,5 +1,6 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("StringsKt") +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") package kotlin.text diff --git a/libraries/stdlib/src/kotlin/text/regex/Regex.kt b/libraries/stdlib/src/kotlin/text/regex/MatchResult.kt similarity index 100% rename from libraries/stdlib/src/kotlin/text/regex/Regex.kt rename to libraries/stdlib/src/kotlin/text/regex/MatchResult.kt diff --git a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt index b8337bd66b4..318b10fa01f 100644 --- a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt +++ b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@file:JvmVersion package kotlin.text import java.util.* diff --git a/libraries/stdlib/src/kotlin/util/StandardJVM.kt b/libraries/stdlib/src/kotlin/util/Exceptions.kt similarity index 97% rename from libraries/stdlib/src/kotlin/util/StandardJVM.kt rename to libraries/stdlib/src/kotlin/util/Exceptions.kt index 777ef31d29e..221c234ba18 100644 --- a/libraries/stdlib/src/kotlin/util/StandardJVM.kt +++ b/libraries/stdlib/src/kotlin/util/Exceptions.kt @@ -1,5 +1,6 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("ExceptionsKt") +@file:kotlin.jvm.JvmVersion @file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") package kotlin diff --git a/libraries/stdlib/src/kotlin/util/Integers.kt b/libraries/stdlib/src/kotlin/util/Integers.kt deleted file mode 100644 index 20ca1e414ad..00000000000 --- a/libraries/stdlib/src/kotlin/util/Integers.kt +++ /dev/null @@ -1,15 +0,0 @@ -@file:kotlin.jvm.JvmMultifileClass -@file:kotlin.jvm.JvmName("StandardKt") -package kotlin - -/** - * Executes the given function [action] specified number of [times]. - * - * A zero-based index of current iteration is passed as a parameter to [action]. - */ -@kotlin.internal.InlineOnly -public inline fun repeat(times: Int, action: (Int) -> Unit) { - for (index in 0..times - 1) { - action(index) - } -} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index e34edd70489..64a04a5085b 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -53,3 +53,16 @@ public inline fun T.apply(block: T.() -> Unit): T { block(); return this } */ @kotlin.internal.InlineOnly public inline fun T.let(block: (T) -> R): R = block(this) + + +/** + * Executes the given function [action] specified number of [times]. + * + * A zero-based index of current iteration is passed as a parameter to [action]. + */ +@kotlin.internal.InlineOnly +public inline fun repeat(times: Int, action: (Int) -> Unit) { + for (index in 0..times - 1) { + action(index) + } +} \ No newline at end of file