Drop ERROR deprecations in JS library that were introduced in 1.1-rc

This commit is contained in:
Ilya Gorbunov
2017-02-20 22:29:54 +03:00
parent b393c66426
commit 6e8f227121
5 changed files with 0 additions and 284 deletions
-31
View File
@@ -1,31 +0,0 @@
package kotlin.dom.build
import org.w3c.dom.*
import kotlin.dom.*
/**
* Creates a new element which can be configured via a function
*/
@Deprecated("Moved to kotlin.dom package", ReplaceWith("createElement(name, init)", "kotlin.dom.createElement"), level = DeprecationLevel.ERROR)
public fun Document.createElement(name: String, init: Element.() -> Unit): Element = createElement(name).apply(init)
/**
* Creates a new element to an element which has an owner Document which can be configured via a function
*/
@Deprecated("Use Document.createElement instead", level = DeprecationLevel.ERROR)
fun Element.createElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element = ownerDocument!!.createElement(name).apply(init)
/**
* Adds a newly created element which can be configured via a function
*/
@Deprecated("Use Element.appendElement instead.", level = DeprecationLevel.ERROR)
fun Document.addElement(name: String, init: Element.() -> Unit): Element {
val child = createElement(name).apply(init)
this.appendChild(child)
return child
}
@Deprecated("Use Element.appendElement instead", ReplaceWith("appendElement(name, init)", "kotlin.dom.appendElement"), level = DeprecationLevel.ERROR)
fun Element.addElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element = appendElement(name, init)
-122
View File
@@ -13,133 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DEPRECATION_ERROR")
package kotlin.dom
import org.w3c.dom.*
import kotlin.collections.*
// DEPRECATED in 1.1-RC, drop after 1.1
/** Returns the children of the element as a list */
@Deprecated("Use childNodes() function with safe call", ReplaceWith("this?.childNodes()?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
fun Element?.children(): List<Node> {
return this?.childNodes?.asList() ?: emptyList()
}
/** Returns the child elements of this element */
@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR)
fun Element?.childElements(): List<Element> = this?.childNodes?.filterElements() ?: emptyList()
/** Returns the child elements of this element with the given name. */
@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR)
fun Element?.childElements(name: String): List<Element> = this?.childNodes?.filterElements()?.filter { it.nodeName == name } ?: emptyList()
/** Returns all the descendant elements given the local element name. */
@Deprecated("Use getElementsByTagName() instead", ReplaceWith("getElementsByTagName(localName).asList()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
fun Element.elements(localName: String = "*"): List<Element> {
return this.getElementsByTagName(localName).asList()
}
/** Returns all the descendant elements given the local element name */
@JsName("deprecated_document_elements")
@Deprecated("Use getElementsByTagName() function with safe call", ReplaceWith("this?.getElementsByTagName(localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
fun Document?.elements(localName: String = "*"): List<Element> {
return this?.elements(localName).orEmpty()
}
/** Returns all the descendant elements given the namespace URI and local element name. */
@Deprecated("Use getElementsByTagNameNS() function instead", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
public fun Element.elements(namespaceUri: String, localName: String): List<Element> {
return this.getElementsByTagNameNS(namespaceUri, localName).asList()
}
/** Returns all the descendant elements given the namespace URI and local element name */
@Deprecated("Use getElementsByTagNameNS() function with safe call", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
fun Document?.elements(namespaceUri: String, localName: String): List<Element> {
return this?.getElementsByTagNameNS(namespaceUri, localName)?.asList() ?: emptyList()
}
// END OF DEPRECATED
/**
* Returns a view of this [NodeList] as a list of elements assuming that it contains only elements.
*
* An attempt to get an element with [List.get] indexed accessor of the returned list
* will result in [ClassCastException] being thrown if that node is not an element.
*
* If you want to get a snapshot filtered to contain elements only it's better to use [filterElements] function.
*/
@Deprecated("This API is going to be removed, use asList() as a close replacement instead.", ReplaceWith("asList() as List<Element>", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
public fun NodeList.asElementList(): List<Element> = ElementListAsList(this)
/**
* Returns a list containing only [Element] nodes.
*/
@Deprecated("Use filter function instead", ReplaceWith("filter { it.isElement } as List<Element>"), level = DeprecationLevel.ERROR)
public fun List<Node>.filterElements(): List<Element> {
@Suppress("UNCHECKED_CAST")
return filter { it.isElement } as List<Element>
}
/**
* Returns a list containing only [Element] nodes.
*/
@Deprecated("Use filter function instead", ReplaceWith("asList().filter { it.isElement } as List<Element>", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR)
public fun NodeList.filterElements(): List<Element> = asList().filterElements()
private class ElementListAsList(private val nodeList: NodeList) : AbstractList<Element>() {
override fun get(index: Int): Element {
val node = nodeList.item(index)
if (node == null) {
throw IndexOutOfBoundsException("NodeList does not contain a node at index: " + index)
} else if (node.nodeType == Node.ELEMENT_NODE) {
return node as Element
} else {
throw ClassCastException("Node is not an Element as expected but is $node")
}
}
override val size: Int get() = nodeList.length
}
/** Returns an [Iterator] over the next siblings of this node. */
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node.nextSiblings(): Iterable<Node> = NextSiblings(this)
private class NextSiblings(private var node: Node) : Iterable<Node> {
override fun iterator(): Iterator<Node> = object : AbstractIterator<Node>() {
override fun computeNext(): Unit {
val nextValue = node.nextSibling
if (nextValue != null) {
setNext(nextValue)
node = nextValue
} else {
done()
}
}
}
}
/** Returns an [Iterator] over the next siblings of this node. */
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node.previousSiblings(): Iterable<Node> = PreviousSiblings(this)
private class PreviousSiblings(private var node: Node) : Iterable<Node> {
override fun iterator(): Iterator<Node> = object : AbstractIterator<Node>() {
override fun computeNext(): Unit {
val nextValue = node.previousSibling
if (nextValue != null) {
setNext(nextValue)
node = nextValue
} else {
done()
}
}
}
}
/**
* Gets a value indicating whether this node is a TEXT_NODE or a CDATA_SECTION_NODE.
-73
View File
@@ -1,73 +0,0 @@
@file:Suppress("DEPRECATION_ERROR")
package kotlin.dom
import org.w3c.dom.*
import org.w3c.dom.events.*
/**
* Turns an event handler function into an [EventListener]
*/
@Deprecated("Use EventListener SAM-like constructor instead", ReplaceWith("EventListener(handler)", "org.w3c.dom.events.EventListener"), level = DeprecationLevel.ERROR)
public fun eventHandler(handler: (Event) -> Unit): EventListener = EventListener(handler)
@Deprecated("Use EventListener SAM-like constructor instead", ReplaceWith("EventListener(handler)", "org.w3c.dom.events.EventListener"), level = DeprecationLevel.ERROR)
public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener {
return eventHandler { e ->
if (e is MouseEvent) {
handler(e)
}
}
}
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public interface Closeable {
public open fun close(): Unit
}
/**
* Registers a handler on the named event
*/
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node.on(name: String, capture: Boolean, handler: (Event) -> Unit): Closeable? {
return on(name, capture, eventHandler(handler))
}
/**
* Registers an [EventListener] on the named event
*/
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node?.on(name: String, capture: Boolean, listener: EventListener): Closeable? {
// TODO: instanceof EventTarget is a very bad idea!
// TODO: nullable target is a very bad idea!
// TODO: receiver should be EventTarget
val target = this as? EventTarget
return if (target != null) {
target.addEventListener(name, listener, capture)
CloseableEventListener(target, listener, name, capture)
} else {
null
}
}
private class CloseableEventListener(
private val target: EventTarget,
private val listener: EventListener,
private val name: String,
private val capture: Boolean
) : Closeable {
public override fun close() {
target.removeEventListener(name, listener, capture)
}
public override fun toString(): String = "CloseableEventListener($target, $name)"
}
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? {
return on("click", capture, mouseEventHandler(handler))
}
@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR)
public fun Node?.onDoubleClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? {
return on("dblclick", capture, mouseEventHandler(handler))
}
-20
View File
@@ -1,20 +0,0 @@
package kotlin.dom
import org.w3c.dom.*
import org.w3c.dom.DOMTokenList
import org.w3c.dom.HTMLCollection
import org.w3c.dom.HTMLElement
/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */
@Deprecated("Use querySelectorAll instead", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
operator fun Document?.get(selector: String): List<Element> {
return this?.querySelectorAll(selector)?.asList()?.filterElements() ?: emptyList()
}
/** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */
@Deprecated("Use querySelectorAll instead", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
operator fun Element.get(selector: String): List<Element> {
return querySelectorAll(selector).asList().filterElements()
}
-38
View File
@@ -9,36 +9,6 @@ public fun Node.clear() {
}
}
/**
* Removes this node from parent node. Does nothing if no parent node
*/
@Deprecated("Use parentNode?.removeChild(this) instead.", ReplaceWith("this.also { it.parentNode?.removeChild(it) }"), level = DeprecationLevel.ERROR)
public fun Node.removeFromParent() {
parentNode?.removeChild(this)
}
@Deprecated("Use appendChild instead", ReplaceWith("appendChild(node)"), level = DeprecationLevel.ERROR)
operator fun Node.plus(child: Node): Node {
appendChild(child)
return this
}
@Deprecated("Use appendText instead", ReplaceWith("appendText(text)"), level = DeprecationLevel.ERROR)
operator fun Element.plus(text: String): Element = appendText(text)
@Deprecated("Use appendText instead", ReplaceWith("appendText(text)"), level = DeprecationLevel.ERROR)
operator fun Element.plusAssign(text: String): Unit {
appendText(text)
}
/** Returns the owner document of the element or uses the provided document */
@Deprecated("Use ownerDocument property instead", ReplaceWith("this.ownerDocument ?: doc ?: error(\"no ownerDocument\")"), level = DeprecationLevel.ERROR)
fun Node.ownerDocument(doc: Document? = null): Document = when {
nodeType == Node.DOCUMENT_NODE -> this as Document
else -> doc ?: ownerDocument ?: throw IllegalArgumentException("Neither node contains nor parameter doc provides an owner document for $this")
}
/**
* Creates text node and append it to the element.
*
@@ -48,11 +18,3 @@ fun Element.appendText(text: String): Element {
appendChild(ownerDocument!!.createTextNode(text))
return this
}
/**
* Appends the node to the specified parent element
*/
@Deprecated("Use parent.appendChild instead", ReplaceWith("this.let(parent::appendChild)"), level = DeprecationLevel.ERROR)
fun Node.appendTo(parent: Element) {
parent.appendChild(this)
}