Transform builtin Map declaration and adjust stdlib

This commit is contained in:
Denis Zharkov
2015-10-12 19:54:12 +03:00
committed by Mikhail Glukhikh
parent f0e3fd617d
commit 6fa8083a70
11 changed files with 146 additions and 53 deletions
+19 -13
View File
@@ -928,16 +928,19 @@ public final class LongRange : kotlin.Range<kotlin.Long>, kotlin.Progression<kot
} }
public interface Map</*0*/ K, /*1*/ out V> { public interface Map</*0*/ K, /*1*/ out V> {
public abstract val entries: kotlin.Set<kotlin.Map.Entry<K, V>>
public abstract fun <get-entries>(): kotlin.Set<kotlin.Map.Entry<K, V>>
public abstract val isEmpty: kotlin.Boolean public abstract val isEmpty: kotlin.Boolean
public abstract fun <get-isEmpty>(): kotlin.Boolean public abstract fun <get-isEmpty>(): kotlin.Boolean
public abstract val keys: kotlin.Set<K>
public abstract fun <get-keys>(): kotlin.Set<K>
public abstract val size: kotlin.Int public abstract val size: kotlin.Int
public abstract fun <get-size>(): kotlin.Int public abstract fun <get-size>(): kotlin.Int
public abstract fun containsKey(/*0*/ key: kotlin.Any?): kotlin.Boolean public abstract val values: kotlin.Collection<V>
public abstract fun containsValue(/*0*/ value: kotlin.Any?): kotlin.Boolean public abstract fun <get-values>(): kotlin.Collection<V>
public abstract fun entrySet(): kotlin.Set<kotlin.Map.Entry<K, V>> public abstract fun containsKey(/*0*/ key: K): kotlin.Boolean
public abstract operator fun get(/*0*/ key: kotlin.Any?): V? public abstract fun containsValue(/*0*/ value: @kotlin.UnsafeVariance() V): kotlin.Boolean
public abstract fun keySet(): kotlin.Set<K> public abstract operator fun get(/*0*/ key: K): V?
public abstract fun values(): kotlin.Collection<V>
public interface Entry</*0*/ out K, /*1*/ out V> { public interface Entry</*0*/ out K, /*1*/ out V> {
public abstract val key: K public abstract val key: K
@@ -1012,20 +1015,23 @@ public interface MutableListIterator</*0*/ T> : kotlin.ListIterator<T>, kotlin.M
} }
public interface MutableMap</*0*/ K, /*1*/ V> : kotlin.Map<K, V> { public interface MutableMap</*0*/ K, /*1*/ V> : kotlin.Map<K, V> {
public abstract override /*1*/ val entries: kotlin.MutableSet<kotlin.MutableMap.MutableEntry<K, V>>
public abstract override /*1*/ fun <get-entries>(): kotlin.MutableSet<kotlin.MutableMap.MutableEntry<K, V>>
public abstract override /*1*/ /*fake_override*/ val isEmpty: kotlin.Boolean public abstract override /*1*/ /*fake_override*/ val isEmpty: kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun <get-isEmpty>(): kotlin.Boolean public abstract override /*1*/ /*fake_override*/ fun <get-isEmpty>(): kotlin.Boolean
public abstract override /*1*/ val keys: kotlin.MutableSet<K>
public abstract override /*1*/ fun <get-keys>(): kotlin.MutableSet<K>
public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun <get-size>(): kotlin.Int public abstract override /*1*/ /*fake_override*/ fun <get-size>(): kotlin.Int
public abstract override /*1*/ val values: kotlin.MutableCollection<V>
public abstract override /*1*/ fun <get-values>(): kotlin.MutableCollection<V>
public abstract fun clear(): kotlin.Unit public abstract fun clear(): kotlin.Unit
public abstract override /*1*/ /*fake_override*/ fun containsKey(/*0*/ key: kotlin.Any?): kotlin.Boolean public abstract override /*1*/ /*fake_override*/ fun containsKey(/*0*/ key: K): kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun containsValue(/*0*/ value: kotlin.Any?): kotlin.Boolean public abstract override /*1*/ /*fake_override*/ fun containsValue(/*0*/ value: V): kotlin.Boolean
public abstract override /*1*/ fun entrySet(): kotlin.MutableSet<kotlin.MutableMap.MutableEntry<K, V>> public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: K): V?
public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ key: kotlin.Any?): V?
public abstract override /*1*/ fun keySet(): kotlin.MutableSet<K>
public abstract fun put(/*0*/ key: K, /*1*/ value: V): V? public abstract fun put(/*0*/ key: K, /*1*/ value: V): V?
public abstract fun putAll(/*0*/ m: kotlin.Map<out K, V>): kotlin.Unit public abstract fun putAll(/*0*/ m: kotlin.Map<out K, V>): kotlin.Unit
public abstract fun remove(/*0*/ key: kotlin.Any?): V? public abstract fun remove(/*0*/ key: K): V?
public abstract override /*1*/ fun values(): kotlin.MutableCollection<V>
public interface MutableEntry</*0*/ K, /*1*/ V> : kotlin.Map.Entry<K, V> { public interface MutableEntry</*0*/ K, /*1*/ V> : kotlin.Map.Entry<K, V> {
public abstract override /*1*/ /*fake_override*/ val key: K public abstract override /*1*/ /*fake_override*/ val key: K
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
// FILE: MyMap.java
abstract public class MyMap extends java.util.AbstractMap<Double, CharSequence> {
String get(Object q) { }
}
// FILE: main.kt
fun foo(m: MyMap) {
var x: String? = m.get(1.0)
x = m[2.0]
}
@@ -0,0 +1,28 @@
package
public fun foo(/*0*/ m: MyMap): kotlin.Unit
public abstract class MyMap : java.util.AbstractMap<kotlin.Double!, kotlin.CharSequence!> {
public constructor MyMap()
public abstract override /*1*/ /*fake_override*/ val entries: kotlin.MutableSet<kotlin.MutableMap.MutableEntry<kotlin.Double!, kotlin.CharSequence!>>
public open override /*1*/ /*fake_override*/ val isEmpty: kotlin.Boolean
invisible_fake final override /*1*/ /*fake_override*/ var keySet: kotlin.(Mutable)Set<kotlin.Double!>!
public open override /*1*/ /*fake_override*/ val keys: kotlin.MutableSet<kotlin.Double!>
public open override /*1*/ /*fake_override*/ val size: kotlin.Int
invisible_fake final override /*1*/ /*fake_override*/ var values: kotlin.(Mutable)Collection<kotlin.CharSequence!>!
public open override /*1*/ /*fake_override*/ val values: kotlin.MutableCollection<kotlin.CharSequence!>
public open override /*1*/ /*fake_override*/ fun clear(): kotlin.Unit
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun clone(): kotlin.Any!
public open override /*1*/ /*fake_override*/ fun containsKey(/*0*/ key: kotlin.Double!): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun containsValue(/*0*/ value: kotlin.CharSequence!): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public/*package*/ open override /*1*/ /*synthesized*/ fun get(/*0*/ q: kotlin.Double!): kotlin.String?
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun put(/*0*/ key: kotlin.Double!, /*1*/ value: kotlin.CharSequence!): kotlin.CharSequence?
public open override /*1*/ /*fake_override*/ fun putAll(/*0*/ m: kotlin.Map<out kotlin.Double!, kotlin.CharSequence!>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun remove(/*0*/ key: kotlin.Double!): kotlin.CharSequence?
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
invisible_fake open override /*1*/ /*fake_override*/ fun eq(/*0*/ p0: kotlin.Any!, /*1*/ p1: kotlin.Any!): kotlin.Boolean
}
@@ -9185,6 +9185,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName); doTest(fileName);
} }
@TestMetadata("mapGetOverride.kt")
public void testMapGetOverride() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/collectionOverrides/mapGetOverride.kt");
doTest(fileName);
}
@TestMetadata("removeAt.kt") @TestMetadata("removeAt.kt")
public void testRemoveAt() throws Exception { public void testRemoveAt() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.kt"); String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/collectionOverrides/removeAt.kt");
+10 -10
View File
@@ -284,33 +284,33 @@ public interface Map<K, out V> {
/** /**
* Returns `true` if the map contains the specified [key]. * Returns `true` if the map contains the specified [key].
*/ */
public fun containsKey(key: Any?): Boolean public fun containsKey(key: K): Boolean
/** /**
* Returns `true` if the map maps one or more keys to the specified [value]. * Returns `true` if the map maps one or more keys to the specified [value].
*/ */
public fun containsValue(value: Any?): Boolean public fun containsValue(value: @UnsafeVariance V): Boolean
/** /**
* Returns the value corresponding to the given [key], or `null` if such a key is not present in the map. * Returns the value corresponding to the given [key], or `null` if such a key is not present in the map.
*/ */
public operator fun get(key: Any?): V? public operator fun get(key: K): V?
// Views // Views
/** /**
* Returns a [Set] of all keys in this map. * Returns a [Set] of all keys in this map.
*/ */
public fun keySet(): Set<K> public val keys: Set<K>
/** /**
* Returns a [Collection] of all values in this map. Note that this collection may contain duplicate values. * Returns a [Collection] of all values in this map. Note that this collection may contain duplicate values.
*/ */
public fun values(): Collection<V> public val values: Collection<V>
/** /**
* Returns a [Set] of all key/value pairs in this map. * Returns a [Set] of all key/value pairs in this map.
*/ */
public fun entrySet(): Set<Map.Entry<K, V>> public val entries: Set<Map.Entry<K, V>>
/** /**
* Represents a key/value pair held by a [Map]. * Represents a key/value pair held by a [Map].
@@ -348,7 +348,7 @@ public interface MutableMap<K, V> : Map<K, V> {
* *
* @return the previous value associated with the key, or `null` if the key was not present in the map. * @return the previous value associated with the key, or `null` if the key was not present in the map.
*/ */
public fun remove(key: Any?): V? public fun remove(key: K): V?
// Bulk Modification Operations // Bulk Modification Operations
/** /**
@@ -362,9 +362,9 @@ public interface MutableMap<K, V> : Map<K, V> {
public fun clear(): Unit public fun clear(): Unit
// Views // Views
override fun keySet(): MutableSet<K> override val keys: MutableSet<K>
override fun values(): MutableCollection<V> override val values: MutableCollection<V>
override fun entrySet(): MutableSet<MutableMap.MutableEntry<K, V>> override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
/** /**
* Represents a key/value pair held by a [MutableMap]. * Represents a key/value pair held by a [MutableMap].
@@ -41,7 +41,8 @@ object EMPTY_MEMBER_INDEX : MemberIndex {
private val ADDITIONAL_MEMBER_NAMES_MAP = mapOf( private val ADDITIONAL_MEMBER_NAMES_MAP = mapOf(
FqName("java.util.List") to listOf(Name.identifier("removeAt")), FqName("java.util.List") to listOf(Name.identifier("removeAt")),
FqName("java.lang.CharSequence") to listOf(Name.identifier("get")) FqName("java.lang.CharSequence") to listOf(Name.identifier("get")),
FqName("java.util.Map") to listOf(Name.identifier("keys"), Name.identifier("entries"))
) )
open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember) -> Boolean) : MemberIndex { open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember) -> Boolean) : MemberIndex {
@@ -35,7 +35,10 @@ object BuiltinSpecialProperties {
private val PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP = mapOf( private val PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP = mapOf(
FqName("kotlin.Collection.size") to Name.identifier("size"), FqName("kotlin.Collection.size") to Name.identifier("size"),
FqName("kotlin.Map.size") to Name.identifier("size"), FqName("kotlin.Map.size") to Name.identifier("size"),
FqName("kotlin.CharSequence.length") to Name.identifier("length") FqName("kotlin.CharSequence.length") to Name.identifier("length"),
FqName("kotlin.Map.keys") to Name.identifier("keySet"),
FqName("kotlin.Map.values") to Name.identifier("values"),
FqName("kotlin.Map.entries") to Name.identifier("entrySet")
) )
private val GETTER_JVM_NAME_TO_PROPERTIES_SHORT_NAME_MAP: Map<Name, List<Name>> = private val GETTER_JVM_NAME_TO_PROPERTIES_SHORT_NAME_MAP: Map<Name, List<Name>> =
@@ -71,7 +74,12 @@ object BuiltinSpecialProperties {
object BuiltinMethodsWithSpecialJvmSignature { object BuiltinMethodsWithSpecialJvmSignature {
private val ERASED_COLLECTION_PARAMETER_FQ_NAMES = setOf(FqName("kotlin.Collection.containsAll")) private val ERASED_COLLECTION_PARAMETER_FQ_NAMES = setOf(FqName("kotlin.Collection.containsAll"))
private val GENERIC_PARAMETERS_FQ_NAMES = setOf( private val GENERIC_PARAMETERS_FQ_NAMES = setOf(
FqName("kotlin.Collection.contains"), FqName("kotlin.MutableCollection.remove") FqName("kotlin.Collection.contains"),
FqName("kotlin.MutableCollection.remove"),
FqName("kotlin.Map.containsKey"),
FqName("kotlin.Map.containsValue"),
FqName("kotlin.Map.get"),
FqName("kotlin.MutableMap.remove")
) )
private val ERASED_VALUE_PARAMETERS_FQ_NAMES = private val ERASED_VALUE_PARAMETERS_FQ_NAMES =
@@ -121,7 +129,7 @@ object BuiltinSpecialMethods {
val REMOVE_AT_FQ_NAME = FqName("kotlin.MutableList.removeAt") val REMOVE_AT_FQ_NAME = FqName("kotlin.MutableList.removeAt")
val FQ_NAMES_TO_JVM_MAP: Map<FqName, Name> = mapOf( val FQ_NAMES_TO_JVM_MAP: Map<FqName, Name> = mapOf(
REMOVE_AT_FQ_NAME to Name.identifier("remove"), REMOVE_AT_FQ_NAME to Name.identifier("remove"),
FqName("kotlin.CharSequence.get") to Name.identifier("charAt") FqName("kotlin.CharSequence.get") to Name.identifier("charAt")
) )
+7 -7
View File
@@ -105,18 +105,18 @@ public open class HashMap<K, V>(initialCapacity: Int = DEFAULT_INITIAL_CAPACITY,
override val size: Int get() = noImpl override val size: Int get() = noImpl
override val isEmpty: Boolean get() = noImpl override val isEmpty: Boolean get() = noImpl
@Suppress("BASE_WITH_NULLABLE_UPPER_BOUND") @Suppress("BASE_WITH_NULLABLE_UPPER_BOUND")
override fun get(key: Any?): V? = noImpl override fun get(key: K): V? = noImpl
override fun containsKey(key: Any?): Boolean = noImpl override fun containsKey(key: K): Boolean = noImpl
@Suppress("BASE_WITH_NULLABLE_UPPER_BOUND") @Suppress("BASE_WITH_NULLABLE_UPPER_BOUND")
override fun put(key: K, value: V): V? = noImpl override fun put(key: K, value: V): V? = noImpl
override fun putAll(m: Map<out K, V>): Unit = noImpl override fun putAll(m: Map<out K, V>): Unit = noImpl
@Suppress("BASE_WITH_NULLABLE_UPPER_BOUND") @Suppress("BASE_WITH_NULLABLE_UPPER_BOUND")
override fun remove(key: Any?): V? = noImpl override fun remove(key: K): V? = noImpl
override fun clear(): Unit = noImpl override fun clear(): Unit = noImpl
override fun containsValue(value: Any?): Boolean = noImpl override fun containsValue(value: V): Boolean = noImpl
override fun keySet(): MutableSet<K> = noImpl override val keys: MutableSet<K> get() = noImpl
override fun values(): MutableCollection<V> = noImpl override val values: MutableCollection<V> get() = noImpl
override fun entrySet(): MutableSet<MutableMap.MutableEntry<K, V>> = noImpl override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() = noImpl
} }
@library @library
@@ -66,12 +66,12 @@ private class MapWithDefaultImpl<K, out V>(public override val map: Map<K,V>, pr
override fun toString(): String = map.toString() override fun toString(): String = map.toString()
override val size: Int get() = map.size() override val size: Int get() = map.size()
override val isEmpty: Boolean get() = map.isEmpty() override val isEmpty: Boolean get() = map.isEmpty()
override fun containsKey(key: Any?): Boolean = map.containsKey(key) override fun containsKey(key: K): Boolean = map.containsKey(key)
override fun containsValue(value: Any?): Boolean = map.containsValue(value) override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value)
override fun get(key: Any?): V? = map.get(key) override fun get(key: K): V? = map.get(key)
override fun keySet(): Set<K> = map.keySet() override val keys: Set<K> get() = map.keys
override fun values(): Collection<V> = map.values() override val values: Collection<V> get() = map.values
override fun entrySet(): Set<Map.Entry<K, V>> = map.entrySet() override val entries: Set<Map.Entry<K, V>> get() = map.entries
override fun getOrImplicitDefault(key: K): V = map.getOrElse(key, { default(key) }) override fun getOrImplicitDefault(key: K): V = map.getOrElse(key, { default(key) })
} }
@@ -82,15 +82,15 @@ private class MutableMapWithDefaultImpl<K, V>(public override val map: MutableMa
override fun toString(): String = map.toString() override fun toString(): String = map.toString()
override val size: Int get() = map.size() override val size: Int get() = map.size()
override val isEmpty: Boolean get() = map.isEmpty() override val isEmpty: Boolean get() = map.isEmpty()
override fun containsKey(key: Any?): Boolean = map.containsKey(key) override fun containsKey(key: K): Boolean = map.containsKey(key)
override fun containsValue(value: Any?): Boolean = map.containsValue(value) override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value)
override fun get(key: Any?): V? = map.get(key) override fun get(key: K): V? = map.get(key)
override fun keySet(): MutableSet<K> = map.keySet() override val keys: MutableSet<K> get() = map.keys
override fun values(): MutableCollection<V> = map.values() override val values: MutableCollection<V> get() = map.values
override fun entrySet(): MutableSet<MutableMap.MutableEntry<K, V>> = map.entrySet() override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() = map.entries
override fun put(key: K, value: V): V? = map.put(key, value) override fun put(key: K, value: V): V? = map.put(key, value)
override fun remove(key: Any?): V? = map.remove(key) override fun remove(key: K): V? = map.remove(key)
override fun putAll(m: Map<out K, V>) = map.putAll(m) override fun putAll(m: Map<out K, V>) = map.putAll(m)
override fun clear() = map.clear() override fun clear() = map.clear()
@@ -14,12 +14,12 @@ private object EmptyMap : Map<Any, Nothing>, Serializable {
override val size: Int get() = 0 override val size: Int get() = 0
override val isEmpty: Boolean get() = true override val isEmpty: Boolean get() = true
override fun containsKey(key: Any?): Boolean = false override fun containsKey(key: Any): Boolean = false
override fun containsValue(value: Any?): Boolean = false override fun containsValue(value: Nothing): Boolean = false
override fun get(key: Any?): Nothing? = null override fun get(key: Any): Nothing? = null
override fun entrySet(): Set<Map.Entry<Any, Nothing>> = EmptySet override val entries: Set<Map.Entry<Any, Nothing>> get() = EmptySet
override fun keySet(): Set<Any> = EmptySet override val keys: Set<Any> get() = EmptySet
override fun values(): Collection<Nothing> = EmptyList override val values: Collection<Nothing> get() = EmptyList
private fun readResolve(): Any = EmptyMap private fun readResolve(): Any = EmptyMap
} }
@@ -34,6 +34,37 @@ public fun <E> MutableCollection<E>.remove(o: Any?): Boolean = remove(o as E)
@Deprecated("Use 'length' property instead", ReplaceWith("this.length")) @Deprecated("Use 'length' property instead", ReplaceWith("this.length"))
public fun CharSequence.length(): Int = length public fun CharSequence.length(): Int = length
@Deprecated("Use explicit cast to Map<Any?, V> instead", ReplaceWith("(this as Map<Any?, V>).get(o)"))
public inline operator fun <K, V> Map<K, V>.get(o: Any?): V? = get(o as K)
@Deprecated("Use explicit cast to Map<Any?, V> instead", ReplaceWith("(this as Map<Any?, V>).containsKey(o)"))
public inline fun <K, V> Map<K, V>.containsKey(o: Any?): Boolean = containsKey(o as K)
@Deprecated("Use explicit cast to Map<K, Any?> instead", ReplaceWith("(this as Map<K, Any?>).containsValue(o)"))
public inline fun <K, V> Map<K, V>.containsValue(o: Any?): Boolean = containsValue(o as V)
@Deprecated("Use 'keys' instead", ReplaceWith("this.keys()"))
public inline fun <K, V> Map<K, V>.keySet(): Set<K> = keys
@kotlin.jvm.JvmName("mutableKeys")
@Deprecated("Use 'keys' instead", ReplaceWith("this.keys"))
public inline fun <K, V> MutableMap<K, V>.keySet(): MutableSet<K> = keys
@Deprecated("Use 'entries' instead", ReplaceWith("this.entries"))
public inline fun <K, V> Map<K, V>.entrySet(): Set<Map.Entry<K, V>> = entries
@kotlin.jvm.JvmName("mutableEntrySet")
@Deprecated("Use 'entries' instead", ReplaceWith("this.entries"))
public inline fun <K, V> MutableMap<K, V>.entrySet(): MutableSet<MutableMap.MutableEntry<K, V>> = entries
@Deprecated("Use 'values' properties instead", ReplaceWith("this.values"))
public inline fun <K, V> Map<K, V>.values(): Collection<V> = values
@kotlin.jvm.JvmName("mutableValues")
@Deprecated("Use 'values' properties instead", ReplaceWith("this.values"))
public inline fun <K, V> MutableMap<K, V>.values(): MutableCollection<V> = values
/** /**
* Adds the specified [element] to this mutable collection. * Adds the specified [element] to this mutable collection.
*/ */