From 8627547a631666fb2417aabbb5bdf4697a3ed7c0 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 26 Sep 2016 16:28:57 +0300 Subject: [PATCH] Provide java.util.AbstractCollection and AbstractList as deprecated classes with implemented abstract methods rather than as typealiases to smooth migration. This comes at price that `ArrayList is java.util.AbstractColleciton` is false. --- js/js.libraries/src/core/javautil.kt | 19 ++++++++++++++++--- .../java/abstractList/cases/iterator.kt | 2 -- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/js.libraries/src/core/javautil.kt b/js/js.libraries/src/core/javautil.kt index 343bae3be1d..1a35985dfda 100644 --- a/js/js.libraries/src/core/javautil.kt +++ b/js/js.libraries/src/core/javautil.kt @@ -34,10 +34,23 @@ public class Date() { // TODO: Deprecate with replacement public typealias RandomAccess = kotlin.collections.RandomAccess -public typealias AbstractCollection = kotlin.collections.AbstractMutableCollection -public typealias AbstractList = kotlin.collections.AbstractMutableList public typealias ArrayList = kotlin.collections.ArrayList public typealias HashSet = kotlin.collections.HashSet public typealias LinkedHashSet = kotlin.collections.LinkedHashSet public typealias HashMap = kotlin.collections.HashMap -public typealias LinkedHashMap = kotlin.collections.LinkedHashMap \ No newline at end of file +public typealias LinkedHashMap = kotlin.collections.LinkedHashMap + +@Deprecated("Use AbstractCollection or AbstractMutableCollection from kotlin.collections", ReplaceWith("kotlin.collections.AbstractMutableCollection")) +public abstract class AbstractCollection : kotlin.collections.AbstractMutableCollection() { + override fun add(element: E): Boolean = throw UnsupportedOperationException() + override fun equals(other: Any?): Boolean = this === other + private val hashCode_ by lazy { (Math.random() * ((1 shl 31) - 1)).toInt() } + override fun hashCode(): Int = hashCode_ +} + +@Deprecated("Use AbstractList or AbstractMutableList from kotlin.collections", ReplaceWith("kotlin.collections.AbstractMutableList")) +public abstract class AbstractList : kotlin.collections.AbstractMutableList() { + override fun add(index: Int, element: E): Unit = throw UnsupportedOperationException() + override fun removeAt(index: Int): E = throw UnsupportedOperationException() + override fun set(index: Int, element: E): E = throw UnsupportedOperationException() +} diff --git a/js/js.translator/testData/java/abstractList/cases/iterator.kt b/js/js.translator/testData/java/abstractList/cases/iterator.kt index b46299c7e47..d45322831d0 100644 --- a/js/js.translator/testData/java/abstractList/cases/iterator.kt +++ b/js/js.translator/testData/java/abstractList/cases/iterator.kt @@ -1,7 +1,5 @@ package foo -import java.util.AbstractList - class MyList(vararg val data: T) : AbstractList() { override fun get(index: Int) = data[index] override val size: Int get() = data.size