diff --git a/libraries/stdlib/src/kotlin/collections/ImmutableArrayList.kt b/libraries/stdlib/src/kotlin/collections/ImmutableArrayList.kt deleted file mode 100644 index fe7f89f38a8..00000000000 --- a/libraries/stdlib/src/kotlin/collections/ImmutableArrayList.kt +++ /dev/null @@ -1,97 +0,0 @@ -package kotlin - -import java.util.AbstractList - -private class ImmutableArrayList( - private val array: Array, - private val offset: Int, - private val length: Int -) : AbstractList() { - { - // impossible - if (offset < 0) { - throw IllegalArgumentException("Negative offset ($offset)") - } - // impossible - if (length < 0) { - throw IllegalArgumentException("Negative length ($length)") - } - // possible when builder is used from different threads - if (offset + length > array.size()) { - throw IllegalArgumentException("offset ($offset) + length ($length) > array.length (${array.size()})") - } - } - - protected fun indexInArray(index: Int): Int { - if (index < 0) { - throw IndexOutOfBoundsException("Negative index ($index)") - } - if (index >= length) { - throw IndexOutOfBoundsException("index ($index) >= length ($length)") - } - return index + offset - } - - public override fun get(index: Int): T = array[indexInArray(index)] - - public override fun size() : Int = length - - public override fun subList(fromIndex: Int, toIndex: Int) : MutableList { - if (fromIndex < 0) { - throw IndexOutOfBoundsException("Negative from index ($fromIndex)") - } - if (toIndex < fromIndex) { - throw IndexOutOfBoundsException("toIndex ($toIndex) < fromIndex ($fromIndex)") - } - if (toIndex > length) { - throw IndexOutOfBoundsException("fromIndex ($fromIndex) + toIndex ($toIndex) > length ($length)") - } - if (fromIndex == toIndex) { - return emptyImmutableArrayList as MutableList - } - if (fromIndex == 0 && toIndex == length) { - return this - } - return ImmutableArrayList(array, offset + fromIndex, toIndex - fromIndex) - } - - // TODO: efficiently implement iterator and other stuff -} - -private val emptyArray = arrayOfNulls(0) -private val emptyImmutableArrayList = ImmutableArrayList(emptyArray, 0, 0) - -public class ImmutableArrayListBuilder() { - - private var array = emptyArray - private var length = 0 - - public fun build(): List { - if (length == 0) { - return emptyImmutableArrayList as List - } - else { - val r = ImmutableArrayList(array as Array, 0, length) - array = emptyArray - length = 0 - return r - } - } - - public fun ensureCapacity(capacity: Int) { - if (array.size() < capacity) { - val newSize = Math.max(capacity, Math.max(array.size() * 2, 11)) - array = array.copyOf(newSize) - } - } - - public fun add(item: T) { - ensureCapacity(length + 1) - array[length] = item - ++length - } - -} - -// default list builder -public fun listBuilder(): ImmutableArrayListBuilder = ImmutableArrayListBuilder() diff --git a/libraries/stdlib/src/kotlin/Deprecated.kt b/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt similarity index 84% rename from libraries/stdlib/src/kotlin/Deprecated.kt rename to libraries/stdlib/src/kotlin/deprecated/Deprecated.kt index e823aa72140..122189baf32 100644 --- a/libraries/stdlib/src/kotlin/Deprecated.kt +++ b/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt @@ -23,6 +23,32 @@ public fun linkedList(vararg values: T): LinkedList = linkedListOf(*values deprecated("Use linkedMapOf(...) instead") public fun linkedMap(vararg values: Pair): LinkedHashMap = linkedMapOf(*values) +/** Copies all characters into a [[Collection] */ +deprecated("Use toList() instead.") +public fun String.toCollection(): Collection = toCollection(ArrayList(this.length())) + +/** + * Returns the first character which matches the given *predicate* or *null* if none matched + * + * @includeFunctionBody ../../test/text/StringTest.kt find + */ +deprecated("Use firstOrNull instead") +public inline fun String.find(predicate: (Char) -> Boolean): Char? { + for (c in this) if (predicate(c)) return c + return null +} + +/** + * Returns the first character which does not match the given *predicate* or *null* if none matched + * + * @includeFunctionBody ../../test/text/StringTest.kt findNot + */ +deprecated("Use firstOrNull instead") +public inline fun String.findNot(predicate: (Char) -> Boolean): Char? { + for (c in this) if (!predicate(c)) return c + return null +} + /** * A helper method for creating a [[Runnable]] from a function */ diff --git a/libraries/stdlib/src/kotlin/DeprecatedJVM.kt b/libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt similarity index 100% rename from libraries/stdlib/src/kotlin/DeprecatedJVM.kt rename to libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt diff --git a/libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt b/libraries/stdlib/src/kotlin/deprecated/Iterators.kt similarity index 100% rename from libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt rename to libraries/stdlib/src/kotlin/deprecated/Iterators.kt diff --git a/libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt b/libraries/stdlib/src/kotlin/deprecated/IteratorsJVM.kt similarity index 100% rename from libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt rename to libraries/stdlib/src/kotlin/deprecated/IteratorsJVM.kt diff --git a/libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt b/libraries/stdlib/src/kotlin/deprecated/_Iterators.kt similarity index 100% rename from libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt rename to libraries/stdlib/src/kotlin/deprecated/_Iterators.kt diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index f087cecf7bf..2ffb88e327e 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -198,29 +198,6 @@ public fun String.repeat(n: Int): String { return sb.toString() } - -/** - * Returns the first character which matches the given *predicate* or *null* if none matched - * - * @includeFunctionBody ../../test/text/StringTest.kt find - */ -deprecated("Use firstOrNull instead") -public inline fun String.find(predicate: (Char) -> Boolean): Char? { - for (c in this) if (predicate(c)) return c - return null -} - -/** - * Returns the first character which does not match the given *predicate* or *null* if none matched - * - * @includeFunctionBody ../../test/text/StringTest.kt findNot - */ -deprecated("Use firstOrNull instead") -public inline fun String.findNot(predicate: (Char) -> Boolean): Char? { - for (c in this) if (!predicate(c)) return c - return null -} - /** * Returns an Appendable containing the everything but the first characters that satisfy the given *predicate* * @@ -249,10 +226,6 @@ public inline fun String.takeWhileTo(result: T, predicate: (Cha return result } -/** Copies all characters into a [[Collection] */ -deprecated("Use toList() instead.") -public fun String.toCollection(): Collection = toCollection(ArrayList(this.length())) - /** * Replaces every *regexp* occurence in the text with the value retruned by the given function *body* that can handle * particular occurance using [[MatchResult]] provided. diff --git a/libraries/stdlib/test/collections/ImmutableArrayListTest.kt b/libraries/stdlib/test/collections/ImmutableArrayListTest.kt deleted file mode 100644 index a97d897ae98..00000000000 --- a/libraries/stdlib/test/collections/ImmutableArrayListTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package test.collections - -import kotlin.test.* - -import junit.framework.TestCase -import java.util.Random - -class ImmutableArrayListTest() : TestCase() { - - fun testSimple() { - val builder = ImmutableArrayListBuilder() - builder.add(17) - val list = builder.build() - assertEquals(1, list.size()) - assertEquals(17, list[0]) - } - - - fun testGet() { - for (length in 0 .. 55) { - val list = buildIntArray(length, 19) - assertEquals(length, list.size()) - checkList(list, length, 19) - } - } - - private fun buildIntArray(length: Int, firstValue: Int): List { - val builder = ImmutableArrayListBuilder() - for (j in 0 .. length - 1) { - builder.add(firstValue + j) - } - return builder.build() - } - - - private fun checkList(list: List, expectedLength: Int, expectedFirstValue: Int) { - assertEquals(expectedLength, list.size()) - for (i in 0 .. expectedLength - 1) { - assertEquals(expectedFirstValue + i, list[i]) - } - try { - list[expectedLength] - fail() - } catch (e: IndexOutOfBoundsException) { - // expected - } - } - - - fun testSublist() { - val r = Random(1) - for (i in 0 .. 200) { - val length = r.nextInt(55) - val list = buildIntArray(length, 23) - val fromIndex = r.nextInt(length + 1) - val toIndex = fromIndex + r.nextInt(length - fromIndex + 1) - val sublist = list.subList(fromIndex, toIndex) - checkList(sublist, toIndex - fromIndex, 23 + fromIndex) - } - } - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt index c3c4d2f43d2..3c383357d45 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt @@ -6,16 +6,16 @@ private fun PsiElement.getTextChildRelativeOffset() = getTextRange()!!.getStartOffset() - getParent()!!.getTextRange()!!.getStartOffset() private fun PsiElement.getAllChildren(): List { - val r = listBuilder() + val r = arrayListOf() var child = getFirstChild() while (child != null) { r.add(child!!) child = child!!.getNextSibling() } - return r.build() + return r } -private fun splitPsiImpl(psi: PsiElement, listBuilder: ImmutableArrayListBuilder>) { +private fun splitPsiImpl(psi: PsiElement, listBuilder: MutableList>) { var lastPos = 0 for (child in psi.getAllChildren()) { if (child.getTextChildRelativeOffset() > lastPos) { @@ -32,9 +32,9 @@ private fun splitPsiImpl(psi: PsiElement, listBuilder: ImmutableArrayListBuilder } fun splitPsi(psi: PsiElement): List> { - val listBuilder = listBuilder>() + val listBuilder = arrayListOf>() splitPsiImpl(psi, listBuilder) - return listBuilder.build() + return listBuilder } diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt index a08426e9705..d2b8ace67c2 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt @@ -8,17 +8,13 @@ abstract class HtmlTemplate() : TextTemplate() { className: String? = null, attributes: List> = listOf(), content: () -> Unit) { - val allAttributesBuilder = listBuilder>() + val allAttributes = arrayListOf>() if (style != null) - allAttributesBuilder.add(Pair("style", style)) + allAttributes.add(Pair("style", style)) if (className != null) - allAttributesBuilder.add(Pair("class", className)) + allAttributes.add(Pair("class", className)) - // TODO: add addAll to ListBuilder - for (attribute in attributes) - allAttributesBuilder.add(attribute) - - val allAttributes = allAttributesBuilder.build() + allAttributes.addAll(attributes) print( if (allAttributes.isEmpty()) { @@ -77,12 +73,12 @@ abstract class HtmlTemplate() : TextTemplate() { tag(tagName = "span", style = style, className = className, content = content) fun a(href: String? = null, name: String? = null, content: () -> Unit) { - val attributes = listBuilder>() + val attributes = arrayListOf>() if (href != null) - attributes.add(Pair("href", href)) + attributes.add(Pair("href", href)) if (name != null) - attributes.add(Pair("name", name)) - tag(tagName = "a", attributes = attributes.build(), content = content) + attributes.add(Pair("name", name)) + tag(tagName = "a", attributes = attributes, content = content) } }