Remove unnecessary constraint from filterIsInstance(Class<R>) signature #KT-6516 Fixed

This commit is contained in:
Ilya Ryzhenkov
2014-12-22 22:18:41 +03:00
parent 93326d8643
commit 071eb87f27
3 changed files with 12 additions and 10 deletions
@@ -348,21 +348,21 @@ public inline fun <reified R> Stream<*>.filterIsInstance(): Stream<R> {
/** /**
* Returns a list containing all elements that are instances of specified class * Returns a list containing all elements that are instances of specified class
*/ */
public fun <T, R : T> Array<out T>.filterIsInstance(klass: Class<R>): List<R> { public fun <R> Array<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass) return filterIsInstanceTo(ArrayList<R>(), klass)
} }
/** /**
* Returns a list containing all elements that are instances of specified class * Returns a list containing all elements that are instances of specified class
*/ */
public fun <T, R : T> Iterable<T>.filterIsInstance(klass: Class<R>): List<R> { public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass) return filterIsInstanceTo(ArrayList<R>(), klass)
} }
/** /**
* Returns a stream containing all elements that are instances of specified class * Returns a stream containing all elements that are instances of specified class
*/ */
public fun <T, R : T> Stream<T>.filterIsInstance(klass: Class<R>): Stream<R> { public fun <R> Stream<*>.filterIsInstance(klass: Class<R>): Stream<R> {
return FilteringStream(this, true, { klass.isInstance(it) }) as Stream<R> return FilteringStream(this, true, { klass.isInstance(it) }) as Stream<R>
} }
@@ -393,7 +393,7 @@ public inline fun <reified R, C : MutableCollection<in R>> Stream<*>.filterIsIns
/** /**
* Appends all elements that are instances of specified class to the given *destination* * Appends all elements that are instances of specified class to the given *destination*
*/ */
public fun <T, C : MutableCollection<in R>, R : T> Array<out T>.filterIsInstanceTo(destination: C, klass: Class<R>): C { public fun <C : MutableCollection<in R>, R> Array<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
for (element in this) if (klass.isInstance(element)) destination.add(element as R) for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination return destination
} }
@@ -401,7 +401,7 @@ public fun <T, C : MutableCollection<in R>, R : T> Array<out T>.filterIsInstance
/** /**
* Appends all elements that are instances of specified class to the given *destination* * Appends all elements that are instances of specified class to the given *destination*
*/ */
public fun <T, C : MutableCollection<in R>, R : T> Iterable<T>.filterIsInstanceTo(destination: C, klass: Class<R>): C { public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
for (element in this) if (klass.isInstance(element)) destination.add(element as R) for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination return destination
} }
@@ -409,7 +409,7 @@ public fun <T, C : MutableCollection<in R>, R : T> Iterable<T>.filterIsInstanceT
/** /**
* Appends all elements that are instances of specified class to the given *destination* * Appends all elements that are instances of specified class to the given *destination*
*/ */
public fun <T, C : MutableCollection<in R>, R : T> Stream<T>.filterIsInstanceTo(destination: C, klass: Class<R>): C { public fun <C : MutableCollection<in R>, R> Stream<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
for (element in this) if (klass.isInstance(element)) destination.add(element as R) for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination return destination
} }
+2 -2
View File
@@ -112,10 +112,10 @@ public val NodeList.outerHTML: String
get() = toList().map { it.innerHTML }.join("") get() = toList().map { it.innerHTML }.join("")
/** Returns an [[Iterator]] of all the next [[Element]] siblings */ /** Returns an [[Iterator]] of all the next [[Element]] siblings */
public fun Node.nextElements(): List<Element> = nextSiblings().filterIsInstance<Node, Element>(javaClass<Element>()) public fun Node.nextElements(): List<Element> = nextSiblings().filterIsInstance(javaClass<Element>())
/** Returns an [[Iterator]] of all the previous [[Element]] siblings */ /** Returns an [[Iterator]] of all the previous [[Element]] siblings */
public fun Node.previousElements(): List<Element> = previousSiblings().filterIsInstance<Node, Element>(javaClass<Element>()) public fun Node.previousElements(): List<Element> = previousSiblings().filterIsInstance(javaClass<Element>())
public var Element.classSet: MutableSet<String> public var Element.classSet: MutableSet<String>
@@ -75,8 +75,9 @@ fun specialJVM(): List<GenericFunction> {
templates add f("filterIsInstanceTo(destination: C, klass: Class<R>)") { templates add f("filterIsInstanceTo(destination: C, klass: Class<R>)") {
doc { "Appends all elements that are instances of specified class to the given *destination*" } doc { "Appends all elements that are instances of specified class to the given *destination*" }
receiverAsterisk(true)
typeParam("C : MutableCollection<in R>") typeParam("C : MutableCollection<in R>")
typeParam("R : T") typeParam("R")
returns("C") returns("C")
exclude(ArraysOfPrimitives, Strings) exclude(ArraysOfPrimitives, Strings)
body { body {
@@ -89,7 +90,8 @@ fun specialJVM(): List<GenericFunction> {
templates add f("filterIsInstance(klass: Class<R>)") { templates add f("filterIsInstance(klass: Class<R>)") {
doc { "Returns a list containing all elements that are instances of specified class" } doc { "Returns a list containing all elements that are instances of specified class" }
typeParam("R : T") receiverAsterisk(true)
typeParam("R")
returns("List<R>") returns("List<R>")
body { body {
""" """