fixed bug in property generation on the JS DOM API
This commit is contained in:
@@ -16,8 +16,7 @@ native public trait Attr: Node {
|
|||||||
public val ownerElement: Element
|
public val ownerElement: Element
|
||||||
public val schemaTypeInfo: TypeInfo
|
public val schemaTypeInfo: TypeInfo
|
||||||
public val specified: Boolean
|
public val specified: Boolean
|
||||||
public val value: String
|
public var value: String
|
||||||
public fun setValue(arg1: String): Unit = js.noImpl
|
|
||||||
public fun isId(): Boolean = js.noImpl
|
public fun isId(): Boolean = js.noImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,10 +24,9 @@ native public trait CDATASection: Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
native public trait CharacterData: Node {
|
native public trait CharacterData: Node {
|
||||||
public val data: String
|
public var data: String
|
||||||
public val length: Int
|
public val length: Int
|
||||||
public fun replaceData(arg1: Int, arg2: Int, arg3: String): Unit = js.noImpl
|
public fun replaceData(arg1: Int, arg2: Int, arg3: String): Unit = js.noImpl
|
||||||
public fun setData(arg1: String): Unit = js.noImpl
|
|
||||||
public fun substringData(arg1: Int, arg2: Int): String = js.noImpl
|
public fun substringData(arg1: Int, arg2: Int): String = js.noImpl
|
||||||
public fun appendData(arg1: String): Unit = js.noImpl
|
public fun appendData(arg1: String): Unit = js.noImpl
|
||||||
public fun insertData(arg1: Int, arg2: String): Unit = js.noImpl
|
public fun insertData(arg1: Int, arg2: String): Unit = js.noImpl
|
||||||
@@ -41,14 +39,14 @@ native public trait Comment: CharacterData {
|
|||||||
native public trait Document: Node {
|
native public trait Document: Node {
|
||||||
public val doctype: DocumentType
|
public val doctype: DocumentType
|
||||||
public val documentElement: Element
|
public val documentElement: Element
|
||||||
public val documentURI: String
|
public var documentURI: String
|
||||||
public val domConfig: DOMConfiguration
|
public val domConfig: DOMConfiguration
|
||||||
public val implementation: DOMImplementation
|
public val implementation: DOMImplementation
|
||||||
public val inputEncoding: String
|
public val inputEncoding: String
|
||||||
public val strictErrorChecking: Boolean
|
public var strictErrorChecking: Boolean
|
||||||
public val xmlEncoding: String
|
public val xmlEncoding: String
|
||||||
public val xmlStandalone: Boolean
|
public var xmlStandalone: Boolean
|
||||||
public val xmlVersion: String
|
public var xmlVersion: String
|
||||||
public fun createElement(arg1: String): Element = js.noImpl
|
public fun createElement(arg1: String): Element = js.noImpl
|
||||||
public fun createComment(arg1: String): Comment = js.noImpl
|
public fun createComment(arg1: String): Comment = js.noImpl
|
||||||
public fun getElementsByTagName(arg1: String): NodeList = js.noImpl
|
public fun getElementsByTagName(arg1: String): NodeList = js.noImpl
|
||||||
@@ -63,10 +61,6 @@ native public trait Document: Node {
|
|||||||
public fun createElementNS(arg1: String, arg2: String): Element = js.noImpl
|
public fun createElementNS(arg1: String, arg2: String): Element = js.noImpl
|
||||||
public fun createAttributeNS(arg1: String, arg2: String): Attr = js.noImpl
|
public fun createAttributeNS(arg1: String, arg2: String): Attr = js.noImpl
|
||||||
public fun getElementById(arg1: String): Element = js.noImpl
|
public fun getElementById(arg1: String): Element = js.noImpl
|
||||||
public fun setXmlStandalone(arg1: Boolean): Unit = js.noImpl
|
|
||||||
public fun setXmlVersion(arg1: String): Unit = js.noImpl
|
|
||||||
public fun setStrictErrorChecking(arg1: Boolean): Unit = js.noImpl
|
|
||||||
public fun setDocumentURI(arg1: String): Unit = js.noImpl
|
|
||||||
public fun adoptNode(arg1: Node): Node = js.noImpl
|
public fun adoptNode(arg1: Node): Node = js.noImpl
|
||||||
public fun normalizeDocument(): Unit = js.noImpl
|
public fun normalizeDocument(): Unit = js.noImpl
|
||||||
public fun renameNode(arg1: Node, arg2: String, arg3: String): Node = js.noImpl
|
public fun renameNode(arg1: Node, arg2: String, arg3: String): Node = js.noImpl
|
||||||
@@ -144,20 +138,20 @@ native public trait Element: Node {
|
|||||||
public fun setAttribute(arg1: String, arg2: String): Unit = js.noImpl
|
public fun setAttribute(arg1: String, arg2: String): Unit = js.noImpl
|
||||||
public fun removeAttribute(arg1: String): Unit = js.noImpl
|
public fun removeAttribute(arg1: String): Unit = js.noImpl
|
||||||
public fun getAttributeNode(arg1: String): Attr = js.noImpl
|
public fun getAttributeNode(arg1: String): Attr = js.noImpl
|
||||||
public fun setAttributeNode(arg1: Attr): Attr = js.noImpl
|
|
||||||
public fun removeAttributeNode(arg1: Attr): Attr = js.noImpl
|
public fun removeAttributeNode(arg1: Attr): Attr = js.noImpl
|
||||||
public fun getElementsByTagName(arg1: String): NodeList = js.noImpl
|
public fun getElementsByTagName(arg1: String): NodeList = js.noImpl
|
||||||
public fun getAttributeNS(arg1: String, arg2: String): String = js.noImpl
|
public fun getAttributeNS(arg1: String, arg2: String): String = js.noImpl
|
||||||
public fun setAttributeNS(arg1: String, arg2: String, arg3: String): Unit = js.noImpl
|
public fun setAttributeNS(arg1: String, arg2: String, arg3: String): Unit = js.noImpl
|
||||||
public fun removeAttributeNS(arg1: String, arg2: String): Unit = js.noImpl
|
public fun removeAttributeNS(arg1: String, arg2: String): Unit = js.noImpl
|
||||||
public fun getAttributeNodeNS(arg1: String, arg2: String): Attr = js.noImpl
|
public fun getAttributeNodeNS(arg1: String, arg2: String): Attr = js.noImpl
|
||||||
public fun setAttributeNodeNS(arg1: Attr): Attr = js.noImpl
|
|
||||||
public fun getElementsByTagNameNS(arg1: String, arg2: String): NodeList = js.noImpl
|
public fun getElementsByTagNameNS(arg1: String, arg2: String): NodeList = js.noImpl
|
||||||
public fun hasAttribute(arg1: String): Boolean = js.noImpl
|
public fun hasAttribute(arg1: String): Boolean = js.noImpl
|
||||||
public fun hasAttributeNS(arg1: String, arg2: String): Boolean = js.noImpl
|
public fun hasAttributeNS(arg1: String, arg2: String): Boolean = js.noImpl
|
||||||
public fun setIdAttribute(arg1: String, arg2: Boolean): Unit = js.noImpl
|
public fun setIdAttribute(arg1: String, arg2: Boolean): Unit = js.noImpl
|
||||||
public fun setIdAttributeNS(arg1: String, arg2: String, arg3: Boolean): Unit = js.noImpl
|
public fun setIdAttributeNS(arg1: String, arg2: String, arg3: Boolean): Unit = js.noImpl
|
||||||
public fun setIdAttributeNode(arg1: Attr, arg2: Boolean): Unit = js.noImpl
|
public fun setIdAttributeNode(arg1: Attr, arg2: Boolean): Unit = js.noImpl
|
||||||
|
public fun setAttributeNode(arg1: Attr): Attr = js.noImpl
|
||||||
|
public fun setAttributeNodeNS(arg1: Attr): Attr = js.noImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
native public trait Entity: Node {
|
native public trait Entity: Node {
|
||||||
@@ -184,11 +178,11 @@ native public trait NamedNodeMap {
|
|||||||
public val length: Int
|
public val length: Int
|
||||||
public fun item(arg1: Int): Node = js.noImpl
|
public fun item(arg1: Int): Node = js.noImpl
|
||||||
public fun getNamedItem(arg1: String): Node = js.noImpl
|
public fun getNamedItem(arg1: String): Node = js.noImpl
|
||||||
public fun setNamedItem(arg1: Node): Node = js.noImpl
|
|
||||||
public fun removeNamedItem(arg1: String): Node = js.noImpl
|
public fun removeNamedItem(arg1: String): Node = js.noImpl
|
||||||
public fun getNamedItemNS(arg1: String, arg2: String): Node = js.noImpl
|
public fun getNamedItemNS(arg1: String, arg2: String): Node = js.noImpl
|
||||||
public fun setNamedItemNS(arg1: Node): Node = js.noImpl
|
|
||||||
public fun removeNamedItemNS(arg1: String, arg2: String): Node = js.noImpl
|
public fun removeNamedItemNS(arg1: String, arg2: String): Node = js.noImpl
|
||||||
|
public fun setNamedItem(arg1: Node): Node = js.noImpl
|
||||||
|
public fun setNamedItemNS(arg1: Node): Node = js.noImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
native public trait Node {
|
native public trait Node {
|
||||||
@@ -202,28 +196,25 @@ native public trait Node {
|
|||||||
public val nextSibling: Node
|
public val nextSibling: Node
|
||||||
public val nodeName: String
|
public val nodeName: String
|
||||||
public val nodeType: Short
|
public val nodeType: Short
|
||||||
public val nodeValue: String
|
public var nodeValue: String
|
||||||
public val ownerDocument: Document
|
public val ownerDocument: Document
|
||||||
public val parentNode: Node
|
public val parentNode: Node
|
||||||
public val prefix: String
|
public var prefix: String
|
||||||
public val previousSibling: Node
|
public val previousSibling: Node
|
||||||
public val textContent: String
|
public var textContent: String
|
||||||
public fun normalize(): Unit = js.noImpl
|
public fun normalize(): Unit = js.noImpl
|
||||||
public fun isSupported(arg1: String, arg2: String): Boolean = js.noImpl
|
public fun isSupported(arg1: String, arg2: String): Boolean = js.noImpl
|
||||||
public fun getUserData(arg1: String): Any = js.noImpl
|
public fun getUserData(arg1: String): Any = js.noImpl
|
||||||
public fun setUserData(arg1: String, arg2: Any, arg3: UserDataHandler): Any = js.noImpl
|
public fun setUserData(arg1: String, arg2: Any, arg3: UserDataHandler): Any = js.noImpl
|
||||||
public fun getFeature(arg1: String, arg2: String): Any = js.noImpl
|
public fun getFeature(arg1: String, arg2: String): Any = js.noImpl
|
||||||
public fun hasAttributes(): Boolean = js.noImpl
|
public fun hasAttributes(): Boolean = js.noImpl
|
||||||
public fun setPrefix(arg1: String): Unit = js.noImpl
|
|
||||||
public fun removeChild(arg1: Node): Node = js.noImpl
|
public fun removeChild(arg1: Node): Node = js.noImpl
|
||||||
public fun replaceChild(arg1: Node, arg2: Node): Node = js.noImpl
|
public fun replaceChild(arg1: Node, arg2: Node): Node = js.noImpl
|
||||||
public fun insertBefore(arg1: Node, arg2: Node): Node = js.noImpl
|
public fun insertBefore(arg1: Node, arg2: Node): Node = js.noImpl
|
||||||
public fun setNodeValue(arg1: String): Unit = js.noImpl
|
|
||||||
public fun appendChild(arg1: Node): Node = js.noImpl
|
public fun appendChild(arg1: Node): Node = js.noImpl
|
||||||
public fun hasChildNodes(): Boolean = js.noImpl
|
public fun hasChildNodes(): Boolean = js.noImpl
|
||||||
public fun cloneNode(arg1: Boolean): Node = js.noImpl
|
public fun cloneNode(arg1: Boolean): Node = js.noImpl
|
||||||
public fun compareDocumentPosition(arg1: Node): Short = js.noImpl
|
public fun compareDocumentPosition(arg1: Node): Short = js.noImpl
|
||||||
public fun setTextContent(arg1: String): Unit = js.noImpl
|
|
||||||
public fun isSameNode(arg1: Node): Boolean = js.noImpl
|
public fun isSameNode(arg1: Node): Boolean = js.noImpl
|
||||||
public fun lookupPrefix(arg1: String): String = js.noImpl
|
public fun lookupPrefix(arg1: String): String = js.noImpl
|
||||||
public fun isDefaultNamespace(arg1: String): Boolean = js.noImpl
|
public fun isDefaultNamespace(arg1: String): Boolean = js.noImpl
|
||||||
@@ -263,9 +254,8 @@ native public trait Notation: Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
native public trait ProcessingInstruction: Node {
|
native public trait ProcessingInstruction: Node {
|
||||||
public val data: String
|
public var data: String
|
||||||
public val target: String
|
public val target: String
|
||||||
public fun setData(arg1: String): Unit = js.noImpl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
native public trait Text: CharacterData {
|
native public trait Text: CharacterData {
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import java.lang.IndexOutOfBoundsException
|
|||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
|
|
||||||
var Node.text : String
|
var Node.text : String
|
||||||
get() {
|
get() {
|
||||||
|
return textContent
|
||||||
|
/*
|
||||||
if (this.nodeType == Node.ELEMENT_NODE) {
|
if (this.nodeType == Node.ELEMENT_NODE) {
|
||||||
val buffer = StringBuilder()
|
val buffer = StringBuilder()
|
||||||
val nodeList = this.childNodes
|
val nodeList = this.childNodes
|
||||||
@@ -34,9 +35,12 @@ get() {
|
|||||||
} else {
|
} else {
|
||||||
return this.nodeValue
|
return this.nodeValue
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
if (this.nodeType == Node.ELEMENT_NODE) {
|
textContent = value
|
||||||
|
/*
|
||||||
|
if (nodeType == Node.ELEMENT_NODE) {
|
||||||
val element = this as Element
|
val element = this as Element
|
||||||
// lets remove all the previous text nodes first
|
// lets remove all the previous text nodes first
|
||||||
for (node in element.children()) {
|
for (node in element.children()) {
|
||||||
@@ -46,8 +50,9 @@ set(value) {
|
|||||||
}
|
}
|
||||||
element.addText(value)
|
element.addText(value)
|
||||||
} else {
|
} else {
|
||||||
this.setNodeValue(value)
|
nodeValue = value
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
var Element.id : String
|
var Element.id : String
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import js.noImpl
|
|||||||
if (methods != null) {
|
if (methods != null) {
|
||||||
// lets figure out the properties versus methods
|
// lets figure out the properties versus methods
|
||||||
val validMethods = ArrayList<Method>()
|
val validMethods = ArrayList<Method>()
|
||||||
val properties = TreeMap<String, String>()
|
val properties = TreeMap<String, PropertyKind>()
|
||||||
for (method in methods) {
|
for (method in methods) {
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
val name = method.getName() ?: ""
|
val name = method.getName() ?: ""
|
||||||
@@ -71,18 +71,18 @@ import js.noImpl
|
|||||||
} else answer
|
} else answer
|
||||||
}
|
}
|
||||||
fun propertyType() = simpleTypeName(method.getReturnType())
|
fun propertyType() = simpleTypeName(method.getReturnType())
|
||||||
|
fun propertyKind(method: Method): PropertyKind {
|
||||||
|
val propName = propertyName()
|
||||||
|
return properties.getOrPut(propName) { PropertyKind(propName, "val", method) }
|
||||||
|
}
|
||||||
|
|
||||||
val params = method.getParameterTypes()
|
val params = method.getParameterTypes()!!
|
||||||
val paramSize = params?.size ?: 0
|
val paramSize = params.size
|
||||||
if (name.size > 3) {
|
if (name.size > 3) {
|
||||||
if (name.startsWith("get") && paramSize == 0) {
|
if (name.startsWith("get") && paramSize == 0) {
|
||||||
val propName = propertyName()
|
propertyKind(method).typeName = propertyType()
|
||||||
if (!properties.containsKey(propName)) {
|
} else if (name.startsWith("set") && paramSize == 1) {
|
||||||
properties.put(propName, "public val $propName: ${propertyType()}")
|
propertyKind(method).kind = "var"
|
||||||
}
|
|
||||||
} else if (name.startsWith("set") && paramSize == 0) {
|
|
||||||
val propName = propertyName()
|
|
||||||
properties.put(propName, "public var $propName: ${propertyType()}")
|
|
||||||
} else {
|
} else {
|
||||||
validMethods.add(method)
|
validMethods.add(method)
|
||||||
}
|
}
|
||||||
@@ -91,8 +91,17 @@ import js.noImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (statement in properties.values()) {
|
|
||||||
println(" $statement")
|
for (pk in properties.values()) {
|
||||||
|
// some properties might not have a getter defined
|
||||||
|
// so lets ignore those
|
||||||
|
|
||||||
|
val typeName = pk.typeName
|
||||||
|
if (typeName == null) {
|
||||||
|
validMethods.add(pk.method)
|
||||||
|
} else {
|
||||||
|
println(" public ${pk.kind} ${pk.name}: ${typeName}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (method in validMethods) {
|
for (method in validMethods) {
|
||||||
val parameterTypes = method.getParameterTypes()!!
|
val parameterTypes = method.getParameterTypes()!!
|
||||||
@@ -136,6 +145,8 @@ import js.noImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PropertyKind(val name: String, var kind: String, val method: Method, var typeName: String? = null)
|
||||||
|
|
||||||
fun write(file: File, block: PrintWriter.() -> Unit): Unit {
|
fun write(file: File, block: PrintWriter.() -> Unit): Unit {
|
||||||
println("Generating file: ${file.getCanonicalPath()}")
|
println("Generating file: ${file.getCanonicalPath()}")
|
||||||
val writer = PrintWriter(FileWriter(file))
|
val writer = PrintWriter(FileWriter(file))
|
||||||
|
|||||||
Reference in New Issue
Block a user