mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 00:21:26 +00:00
Use wrappers around java.util.* to emulate kotlin.collection.* behaviour
Backend: If kotlin class extends kotlin.collection.List
write it as it's super interface (light class mode only)
IDE: Provide wrapper classes to java resolve
that try to emulate backend behaviour
For example if kotlin class implements kotlin.collections.Map,
we provide a superinterface that has abstract 'getEntries' method
and 'entrySet' method that is considered default.
In reality all those methods are generated in the class itself.
In IDE supporting this case without hacks is not feasible performance-wise
since kotlin.collection.* may not be an immediate supertype and we need
to compute all supertypes just to calculate own methods of the class
This commit is contained in:
35
compiler/testData/asJava/lightClasses/ideRegression/ImplementingMutableSet.kt
vendored
Normal file
35
compiler/testData/asJava/lightClasses/ideRegression/ImplementingMutableSet.kt
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// SmartSet
|
||||
|
||||
class SmartSet<T> private constructor() : AbstractSet<T>(), MutableSet<T> {
|
||||
companion object {
|
||||
private val ARRAY_THRESHOLD = 5
|
||||
|
||||
@JvmStatic
|
||||
fun <T> create() = SmartSet<T>()
|
||||
|
||||
@JvmStatic
|
||||
fun <T> create(set: Collection<T>): SmartSet<T> = TODO()
|
||||
}
|
||||
|
||||
private var data: Any? = null
|
||||
|
||||
override var size: Int = 0
|
||||
|
||||
|
||||
|
||||
override fun iterator(): MutableIterator<T> = TODO()
|
||||
|
||||
override fun add(element: T): Boolean = TODO()
|
||||
|
||||
override fun clear() {
|
||||
data = null
|
||||
size = 0
|
||||
}
|
||||
|
||||
override fun contains(element: T): Boolean = when {
|
||||
size == 0 -> false
|
||||
size == 1 -> data == element
|
||||
size < ARRAY_THRESHOLD -> element in data as Array<T>
|
||||
else -> element in data as Set<T>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user