Local objects (#215)
* bug fix * bug fix with nested inner classes * - fixed FixMeInner - support of inner classes in local classes - support of object expressions in initializers * comments * merged modification * - review fixes - tests * review fixes * review fixes
This commit is contained in:
@@ -24,13 +24,6 @@ annotation class ExportTypeInfo(val name: String)
|
||||
public annotation class Used
|
||||
|
||||
|
||||
// Following annotations can be used to mark functions that need to be fixed,
|
||||
// once certain language feature is implemented.
|
||||
/**
|
||||
* Need to be fixed because of inner classes.
|
||||
*/
|
||||
public annotation class FixmeInner
|
||||
|
||||
/**
|
||||
* Need to be fixed because of reification support.
|
||||
*/
|
||||
|
||||
@@ -8,20 +8,15 @@ public abstract class AbstractList<out E> protected constructor() : AbstractColl
|
||||
abstract override val size: Int
|
||||
abstract override fun get(index: Int): E
|
||||
|
||||
// TODO: fix once have inner classes.
|
||||
@FixmeInner
|
||||
override fun iterator(): Iterator<E> = TODO() // IteratorImpl()
|
||||
override fun iterator(): Iterator<E> = IteratorImpl()
|
||||
|
||||
override fun indexOf(element: @UnsafeVariance E): Int = indexOfFirst { it == element }
|
||||
|
||||
override fun lastIndexOf(element: @UnsafeVariance E): Int = indexOfLast { it == element }
|
||||
|
||||
// TODO: fix once have inner classes.
|
||||
@FixmeInner
|
||||
override fun listIterator(): ListIterator<E> = TODO() // ListIteratorImpl(0)
|
||||
override fun listIterator(): ListIterator<E> = ListIteratorImpl(0)
|
||||
|
||||
@FixmeInner
|
||||
override fun listIterator(index: Int): ListIterator<E> = TODO() // ListIteratorImpl(index)
|
||||
override fun listIterator(index: Int): ListIterator<E> = ListIteratorImpl(index)
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<E> = SubList(this, fromIndex, toIndex)
|
||||
|
||||
@@ -52,8 +47,7 @@ public abstract class AbstractList<out E> protected constructor() : AbstractColl
|
||||
|
||||
override fun hashCode(): Int = orderedHashCode(this)
|
||||
|
||||
// TODO: enable, once have inner classes.
|
||||
/*
|
||||
|
||||
private open inner class IteratorImpl : Iterator<E> {
|
||||
/** the index of the item that will be returned on the next call to [next]`()` */
|
||||
protected var index = 0
|
||||
@@ -86,7 +80,7 @@ public abstract class AbstractList<out E> protected constructor() : AbstractColl
|
||||
}
|
||||
|
||||
override fun previousIndex(): Int = index - 1
|
||||
} */
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
internal fun checkElementIndex(index: Int, size: Int) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package kotlin.collections
|
||||
/*
|
||||
|
||||
private open class ReversedListReadOnly<out T>(private val delegate: List<T>) : AbstractList<T>() {
|
||||
override val size: Int get() = delegate.size
|
||||
override fun get(index: Int): T = delegate[reverseElementIndex(index)]
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private class ReversedList<T>(private val delegate: MutableList<T>) : AbstractMutableList<T>() {
|
||||
override val size: Int get() = delegate.size
|
||||
override fun get(index: Int): T = delegate[reverseElementIndex(index)]
|
||||
@@ -17,7 +17,7 @@ private class ReversedList<T>(private val delegate: MutableList<T>) : AbstractMu
|
||||
override fun add(index: Int, element: T) {
|
||||
delegate.add(reversePositionIndex(index), element)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
private fun List<*>.reverseElementIndex(index: Int) = // TODO: Use AbstractList.checkElementIndex: run { AbstractList.checkElementIndex(index, size); lastIndex - index }
|
||||
if (index in 0..size - 1) size - index - 1 else throw IndexOutOfBoundsException("Index $index should be in range [${0..size - 1}].")
|
||||
|
||||
@@ -30,7 +30,7 @@ private fun List<*>.reversePositionIndex(index: Int) =
|
||||
* All changes made in the original list will be reflected in the reversed one.
|
||||
*/
|
||||
public fun <T> List<T>.asReversed(): List<T> = ReversedListReadOnly(this)
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a reversed mutable view of the original mutable List.
|
||||
* All changes made in the original list will be reflected in the reversed one and vice versa.
|
||||
|
||||
Reference in New Issue
Block a user