Cleanup: suppress warnings where appropriate.

This commit is contained in:
Ilya Gorbunov
2016-02-12 23:29:37 +03:00
parent f025a3b8c4
commit 00e30e417f
14 changed files with 57 additions and 19 deletions
+10
View File
@@ -10823,6 +10823,7 @@ public fun <T : Any> Array<T?>.requireNoNulls(): Array<T> {
throw IllegalArgumentException("null element found in $this.")
}
}
@Suppress("CAST_NEVER_SUCCEEDS")
return this as Array<T>
}
@@ -12531,6 +12532,7 @@ public inline fun <reified R, C : MutableCollection<in R>> Array<*>.filterIsInst
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Array<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
@@ -13002,6 +13004,7 @@ public fun ByteArray.toTypedArray(): Array<Byte> {
val result = arrayOfNulls<Byte>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Byte>
}
@@ -13013,6 +13016,7 @@ public fun ShortArray.toTypedArray(): Array<Short> {
val result = arrayOfNulls<Short>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Short>
}
@@ -13024,6 +13028,7 @@ public fun IntArray.toTypedArray(): Array<Int> {
val result = arrayOfNulls<Int>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Int>
}
@@ -13035,6 +13040,7 @@ public fun LongArray.toTypedArray(): Array<Long> {
val result = arrayOfNulls<Long>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Long>
}
@@ -13046,6 +13052,7 @@ public fun FloatArray.toTypedArray(): Array<Float> {
val result = arrayOfNulls<Float>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Float>
}
@@ -13057,6 +13064,7 @@ public fun DoubleArray.toTypedArray(): Array<Double> {
val result = arrayOfNulls<Double>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Double>
}
@@ -13068,6 +13076,7 @@ public fun BooleanArray.toTypedArray(): Array<Boolean> {
val result = arrayOfNulls<Boolean>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Boolean>
}
@@ -13079,6 +13088,7 @@ public fun CharArray.toTypedArray(): Array<Char> {
val result = arrayOfNulls<Char>(size)
for (index in indices)
result[index] = this[index]
@Suppress("CAST_NEVER_SUCCEEDS")
return result as Array<Char>
}
@@ -799,6 +799,7 @@ public fun <T : Comparable<T>> MutableList<T>.sortDescending(): Unit {
public fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> {
if (this is Collection) {
if (size <= 1) return this.toMutableList()
@Suppress("CAST_NEVER_SUCCEEDS")
return (toTypedArray<Comparable<T>>() as Array<T>).apply { sort() }.asList()
}
return toMutableList().apply { sort() }
@@ -831,6 +832,7 @@ public fun <T : Comparable<T>> Iterable<T>.sortedDescending(): List<T> {
public fun <T> Iterable<T>.sortedWith(comparator: Comparator<in T>): List<T> {
if (this is Collection) {
if (size <= 1) return this.toMutableList()
@Suppress("CAST_NEVER_SUCCEEDS")
return (toTypedArray<Any?>() as Array<T>).apply { sortWith(comparator) }.asList()
}
return toMutableList().apply { sortWith(comparator) }
@@ -1593,6 +1595,7 @@ public fun <T : Any> Iterable<T?>.requireNoNulls(): Iterable<T> {
throw IllegalArgumentException("null element found in $this.")
}
}
@Suppress("UNCHECKED_CAST")
return this as Iterable<T>
}
@@ -1605,6 +1608,7 @@ public fun <T : Any> List<T?>.requireNoNulls(): List<T> {
throw IllegalArgumentException("null element found in $this.")
}
}
@Suppress("UNCHECKED_CAST")
return this as List<T>
}
@@ -1896,6 +1900,7 @@ public inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterIsI
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
@@ -343,6 +343,7 @@ public fun <T> Sequence<T>.filterNot(predicate: (T) -> Boolean): Sequence<T> {
* Returns a sequence containing all elements that are not `null`.
*/
public fun <T : Any> Sequence<T?>.filterNotNull(): Sequence<T> {
@Suppress("UNCHECKED_CAST")
return filterNot { it == null } as Sequence<T>
}
@@ -1179,6 +1180,7 @@ public inline fun <T> Sequence<T>.asSequence(): Sequence<T> {
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.internal.NoInfer R> {
@Suppress("UNCHECKED_CAST")
return filter { it is R } as Sequence<R>
}
@@ -1187,6 +1189,7 @@ public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.i
*/
@kotlin.jvm.JvmVersion
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
@Suppress("UNCHECKED_CAST")
return filter { klass.isInstance(it) } as Sequence<R>
}
@@ -1204,6 +1207,7 @@ public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsI
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
@@ -18,7 +18,9 @@ public inline fun ByteArray.toString(charset: Charset): String = String(this, ch
* Allocates an array of runtime type `T` having its size equal to the size of this collection
* and populates the array with the elements of this collection.
*/
@Suppress("UNCHECKED_CAST")
public inline fun <reified T> Collection<T>.toTypedArray(): Array<T> {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
val thisCollection = this as java.util.Collection<T>
return thisCollection.toArray(arrayOfNulls<T>(thisCollection.size())) as Array<T>
}
@@ -28,5 +30,6 @@ public inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: ar
/** Internal unsafe construction of array based on reference array type */
internal fun <T> arrayOfNulls(reference: Array<T>, size: Int): Array<T> {
@Suppress("UNCHECKED_CAST")
return java.lang.reflect.Array.newInstance(reference.javaClass.componentType, size) as Array<T>
}
@@ -13,9 +13,8 @@ import kotlin.internal.Exact
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
*/
@kotlin.internal.InlineOnly
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
public inline operator fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef: Any?, property: KProperty<*>): V1
= getOrImplicitDefault(property.name) as V1
= @Suppress("UNCHECKED_CAST", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") (getOrImplicitDefault(property.name) as V1)
/**
* Returns the value of the property for the given object from this mutable map.
@@ -27,9 +26,8 @@ public inline operator fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef:
*/
@kotlin.jvm.JvmName("getVar")
@kotlin.internal.InlineOnly
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
public inline operator fun <V> MutableMap<in String, in V>.getValue(thisRef: Any?, property: KProperty<*>): V
= getOrImplicitDefault(property.name) as V
= @Suppress("UNCHECKED_CAST", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") (getOrImplicitDefault(property.name) as V)
/**
* Stores the value of the property for the given object in this mutable map.
@@ -25,7 +25,7 @@ private object EmptyMap : Map<Any?, Nothing>, Serializable {
}
/** Returns an empty read-only map of specified type. The returned map is serializable (JVM). */
public fun <K, V> emptyMap(): Map<K, V> = EmptyMap as Map<K, V>
public fun <K, V> emptyMap(): Map<K, V> = @Suppress("CAST_NEVER_SUCCEEDS") (EmptyMap as Map<K, V>)
/**
* Returns a new read-only map with the specified contents, given as a list of pairs
@@ -115,7 +115,8 @@ public inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.
* Returns the value corresponding to the given [key], or `null` if such a key is not present in the map.
*/
@kotlin.internal.InlineOnly
public inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get(key: K): V? = (this as Map<K, V>).get(key)
public inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get(key: K): V?
= @Suppress("UNCHECKED_CAST") (this as Map<K, V>).get(key)
/**
* Returns `true` if the map contains the specified [key].
@@ -123,7 +124,8 @@ public inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.
* Allows to overcome type-safety restriction of `containsKey` that requires to pass a key of type `K`.
*/
@kotlin.internal.InlineOnly
public inline fun <@kotlin.internal.OnlyInputTypes K> Map<out K, *>.containsKey(key: K): Boolean = (this as Map<K, *>).containsKey(key)
public inline fun <@kotlin.internal.OnlyInputTypes K> Map<out K, *>.containsKey(key: K): Boolean
= @Suppress("UNCHECKED_CAST") (this as Map<K, *>).containsKey(key)
/**
* Returns `true` if the map maps one or more keys to the specified [value].
@@ -142,7 +144,8 @@ public inline fun <K, @kotlin.internal.OnlyInputTypes V> Map<K, V>.containsValue
* Allows to overcome type-safety restriction of `remove` that requires to pass a key of type `K`.
*/
@kotlin.internal.InlineOnly
public inline fun <@kotlin.internal.OnlyInputTypes K, V> MutableMap<out K, V>.remove(key: K): V? = (this as MutableMap<K, V>).remove(key)
public inline fun <@kotlin.internal.OnlyInputTypes K, V> MutableMap<out K, V>.remove(key: K): V?
= @Suppress("UNCHECKED_CAST") (this as MutableMap<K, V>).remove(key)
/**
* Returns the key component of the map entry.
@@ -14,7 +14,8 @@ import java.util.*
* @return `true` if the element has been successfully removed; `false` if it was not present in the collection.
*/
@kotlin.internal.InlineOnly
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.remove(element: T): Boolean = (this as MutableCollection<T>).remove(element)
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.remove(element: T): Boolean
= @Suppress("UNCHECKED_CAST") (this as MutableCollection<T>).remove(element)
/**
* Removes all of this collection's elements that are also contained in the specified collection.
@@ -24,7 +25,8 @@ public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.r
* @return `true` if any of the specified elements was removed from the collection, `false` if the collection was not modified.
*/
@kotlin.internal.InlineOnly
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.removeAll(elements: Collection<T>): Boolean = (this as MutableCollection<T>).removeAll(elements)
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.removeAll(elements: Collection<T>): Boolean
= @Suppress("UNCHECKED_CAST") (this as MutableCollection<T>).removeAll(elements)
/**
* Retains only the elements in this collection that are contained in the specified collection.
@@ -34,7 +36,8 @@ public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.r
* @return `true` if any element was removed from the collection, `false` if the collection was not modified.
*/
@kotlin.internal.InlineOnly
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.retainAll(elements: Collection<T>): Boolean = (this as MutableCollection<T>).retainAll(elements)
public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection<out T>.retainAll(elements: Collection<T>): Boolean
= @Suppress("UNCHECKED_CAST") (this as MutableCollection<T>).retainAll(elements)
/**
* Adds the specified [element] to this mutable collection.
@@ -74,6 +74,7 @@ public fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int {
if (a == null) return -1
if (b == null) return 1
@Suppress("UNCHECKED_CAST")
return (a as Comparable<Any>).compareTo(b)
}
@@ -279,18 +280,18 @@ public inline fun <T: Comparable<T>> nullsLast(): Comparator<T?> = nullsLast(nat
/**
* Returns a comparator that compares [Comparable] objects in natural order.
*/
public fun <T: Comparable<T>> naturalOrder(): Comparator<T> = NaturalOrderComparator as Comparator<T>
public fun <T: Comparable<T>> naturalOrder(): Comparator<T> = @Suppress("CAST_NEVER_SUCCEEDS") (NaturalOrderComparator as Comparator<T>)
/**
* Returns a comparator that compares [Comparable] objects in reversed natural order.
*/
public fun <T: Comparable<T>> reverseOrder(): Comparator<T> = ReverseOrderComparator as Comparator<T>
public fun <T: Comparable<T>> reverseOrder(): Comparator<T> = @Suppress("CAST_NEVER_SUCCEEDS") (ReverseOrderComparator as Comparator<T>)
/** Returns a comparator that imposes the reverse ordering of this comparator. */
public fun <T> Comparator<T>.reversed(): Comparator<T> = when (this) {
is ReversedComparator -> this.comparator
NaturalOrderComparator -> ReverseOrderComparator as Comparator<T>
ReverseOrderComparator -> NaturalOrderComparator as Comparator<T>
NaturalOrderComparator -> @Suppress("CAST_NEVER_SUCCEEDS") (ReverseOrderComparator as Comparator<T>)
ReverseOrderComparator -> @Suppress("CAST_NEVER_SUCCEEDS") (NaturalOrderComparator as Comparator<T>)
else -> ReversedComparator(this)
}
@@ -17,7 +17,7 @@
package kotlin.jvm.internal.unsafe
@kotlin.internal.InlineExposed
internal fun monitorEnter(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
internal fun monitorEnter(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
@kotlin.internal.InlineExposed
internal fun monitorExit(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
internal fun monitorExit(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
+4 -1
View File
@@ -118,13 +118,14 @@ private class SynchronizedLazyImpl<out T>(initializer: () -> T, lock: Any? = nul
get() {
val _v1 = _value
if (_v1 !== UNINITIALIZED_VALUE) {
@Suppress("UNCHECKED_CAST")
return _v1 as T
}
return synchronized(lock) {
val _v2 = _value
if (_v2 !== UNINITIALIZED_VALUE) {
_v2 as T
@Suppress("UNCHECKED_CAST") (_v2 as T)
}
else {
val typedValue = initializer!!()
@@ -153,6 +154,7 @@ internal class UnsafeLazyImpl<out T>(initializer: () -> T) : Lazy<T>, Serializab
_value = initializer!!()
initializer = null
}
@Suppress("UNCHECKED_CAST")
return _value as T
}
@@ -190,6 +192,7 @@ private class SafePublicationLazyImpl<out T>(initializer: () -> T) : Lazy<T>, Se
}
}
}
@Suppress("UNCHECKED_CAST")
return _value as T
}