fixed bug in property generation on the JS DOM API

This commit is contained in:
James Strachan
2012-06-01 11:40:30 +01:00
parent 32b70db6b2
commit 23db5d7fc8
3 changed files with 45 additions and 39 deletions
+14 -24
View File
@@ -16,8 +16,7 @@ native public trait Attr: Node {
public val ownerElement: Element
public val schemaTypeInfo: TypeInfo
public val specified: Boolean
public val value: String
public fun setValue(arg1: String): Unit = js.noImpl
public var value: String
public fun isId(): Boolean = js.noImpl
}
@@ -25,10 +24,9 @@ native public trait CDATASection: Text {
}
native public trait CharacterData: Node {
public val data: String
public var data: String
public val length: Int
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 appendData(arg1: 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 {
public val doctype: DocumentType
public val documentElement: Element
public val documentURI: String
public var documentURI: String
public val domConfig: DOMConfiguration
public val implementation: DOMImplementation
public val inputEncoding: String
public val strictErrorChecking: Boolean
public var strictErrorChecking: Boolean
public val xmlEncoding: String
public val xmlStandalone: Boolean
public val xmlVersion: String
public var xmlStandalone: Boolean
public var xmlVersion: String
public fun createElement(arg1: String): Element = js.noImpl
public fun createComment(arg1: String): Comment = 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 createAttributeNS(arg1: String, arg2: String): Attr = 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 normalizeDocument(): Unit = 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 removeAttribute(arg1: String): Unit = 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 getElementsByTagName(arg1: String): NodeList = 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 removeAttributeNS(arg1: String, arg2: String): Unit = 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 hasAttribute(arg1: 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 setIdAttributeNS(arg1: String, arg2: String, arg3: 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 {
@@ -184,11 +178,11 @@ native public trait NamedNodeMap {
public val length: Int
public fun item(arg1: Int): 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 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 setNamedItem(arg1: Node): Node = js.noImpl
public fun setNamedItemNS(arg1: Node): Node = js.noImpl
}
native public trait Node {
@@ -202,28 +196,25 @@ native public trait Node {
public val nextSibling: Node
public val nodeName: String
public val nodeType: Short
public val nodeValue: String
public var nodeValue: String
public val ownerDocument: Document
public val parentNode: Node
public val prefix: String
public var prefix: String
public val previousSibling: Node
public val textContent: String
public var textContent: String
public fun normalize(): Unit = js.noImpl
public fun isSupported(arg1: String, arg2: String): Boolean = js.noImpl
public fun getUserData(arg1: String): 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 hasAttributes(): Boolean = js.noImpl
public fun setPrefix(arg1: String): Unit = js.noImpl
public fun removeChild(arg1: 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 setNodeValue(arg1: String): Unit = js.noImpl
public fun appendChild(arg1: Node): Node = js.noImpl
public fun hasChildNodes(): Boolean = js.noImpl
public fun cloneNode(arg1: Boolean): Node = 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 lookupPrefix(arg1: String): String = js.noImpl
public fun isDefaultNamespace(arg1: String): Boolean = js.noImpl
@@ -263,9 +254,8 @@ native public trait Notation: Node {
}
native public trait ProcessingInstruction: Node {
public val data: String
public var data: String
public val target: String
public fun setData(arg1: String): Unit = js.noImpl
}
native public trait Text: CharacterData {
+8 -3
View File
@@ -11,9 +11,10 @@ import java.lang.IndexOutOfBoundsException
// Properties
var Node.text : String
get() {
return textContent
/*
if (this.nodeType == Node.ELEMENT_NODE) {
val buffer = StringBuilder()
val nodeList = this.childNodes
@@ -34,9 +35,12 @@ get() {
} else {
return this.nodeValue
}
*/
}
set(value) {
if (this.nodeType == Node.ELEMENT_NODE) {
textContent = value
/*
if (nodeType == Node.ELEMENT_NODE) {
val element = this as Element
// lets remove all the previous text nodes first
for (node in element.children()) {
@@ -46,8 +50,9 @@ set(value) {
}
element.addText(value)
} else {
this.setNodeValue(value)
nodeValue = value
}
*/
}
var Element.id : String
@@ -60,7 +60,7 @@ import js.noImpl
if (methods != null) {
// lets figure out the properties versus methods
val validMethods = ArrayList<Method>()
val properties = TreeMap<String, String>()
val properties = TreeMap<String, PropertyKind>()
for (method in methods) {
if (method != null) {
val name = method.getName() ?: ""
@@ -71,18 +71,18 @@ import js.noImpl
} else answer
}
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 paramSize = params?.size ?: 0
val params = method.getParameterTypes()!!
val paramSize = params.size
if (name.size > 3) {
if (name.startsWith("get") && paramSize == 0) {
val propName = propertyName()
if (!properties.containsKey(propName)) {
properties.put(propName, "public val $propName: ${propertyType()}")
}
} else if (name.startsWith("set") && paramSize == 0) {
val propName = propertyName()
properties.put(propName, "public var $propName: ${propertyType()}")
propertyKind(method).typeName = propertyType()
} else if (name.startsWith("set") && paramSize == 1) {
propertyKind(method).kind = "var"
} else {
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) {
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 {
println("Generating file: ${file.getCanonicalPath()}")
val writer = PrintWriter(FileWriter(file))