From 20a67c41ee68e84f09b26bd064d20d3241e40009 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Tue, 16 Jun 2015 19:57:38 +0300 Subject: [PATCH] IDL2K introduce commented declarations list --- .../tools/idl2k/src/main/kotlin/config.kt | 17 +++++++++ .../tools/idl2k/src/main/kotlin/render.kt | 37 +++++++++++-------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/libraries/tools/idl2k/src/main/kotlin/config.kt b/libraries/tools/idl2k/src/main/kotlin/config.kt index 63b9cb34de5..f32dc1cacd9 100644 --- a/libraries/tools/idl2k/src/main/kotlin/config.kt +++ b/libraries/tools/idl2k/src/main/kotlin/config.kt @@ -51,3 +51,20 @@ val relocations = mapOf( "EventTarget" to "org.w3c.dom.events", "EventListener" to "org.w3c.dom.events" ) + +val commentOutDeclarations = listOf( + "MouseEvent.screenX: Double", "MouseEvent.screenY: Double", + "MouseEvent.clientX: Double", "MouseEvent.clientY: Double", + "MouseEvent.x: Double", "MouseEvent.y: Double", + + "HTMLAllCollection.namedItem", + "HTMLAllCollection.get", + + "HTMLFormControlsCollection.namedItem", + "HTMLFormControlsCollection.get", + + "HTMLPropertiesCollection.namedItem", + "HTMLPropertiesCollection.get", + + "SVGElement.id" +).toSet() diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index 9ddf27179bc..1535c439a6f 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -2,14 +2,17 @@ package org.jetbrains.idl2k import java.math.BigInteger -private fun O.indent(level: Int) { +private fun O.indent(commented: Boolean, level: Int) { + if (commented) { + append("//") + } for (i in 1..level) { append(" ") } } -private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, override: Boolean, open: Boolean, level: Int = 1) { - indent(level) +private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, override: Boolean, open: Boolean, commented: Boolean, level: Int = 1) { + indent(commented, level) when { override -> append("override ") @@ -28,11 +31,11 @@ private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, overri appendln() if (arg.getterNoImpl) { - indent(level + 1) + indent(commented, level + 1) appendln("get() = noImpl") } if (arg.setterNoImpl) { - indent(level + 1) + indent(commented, level + 1) appendln("set(value) = noImpl") } } @@ -65,8 +68,8 @@ private fun Appendable.renderArgumentsDeclaration(args: List, private fun renderCall(call: GenerateFunctionCall) = "${call.name.replaceKeywords()}(${call.arguments.map { it.replaceKeywords() }.join(", ")})" -private fun Appendable.renderFunctionDeclaration(f: GenerateFunction, override: Boolean, level: Int = 1) { - indent(level) +private fun Appendable.renderFunctionDeclaration(f: GenerateFunction, override: Boolean, commented: Boolean, level: Int = 1) { + indent(commented, level) when (f.nativeGetterOrSetter) { NativeGetterOrSetter.GETTER -> append("nativeGetter ") @@ -92,6 +95,10 @@ private val GenerateAttribute.isVal: Boolean private val GenerateAttribute.isVar: Boolean get() = !readOnly +private fun GenerateAttribute.isCommented(parent: String) = "$parent.$name" in commentOutDeclarations || "$parent.$name: ${type.render()}" in commentOutDeclarations +private fun GenerateFunction.isCommented(parent: String) = + "$parent.$name" in commentOutDeclarations || "$parent.$name(${arguments.size()})" in commentOutDeclarations + fun Appendable.render(allTypes: Map, typeNamesToUnions: Map>, iface: GenerateTraitOrClass, markerAnnotation: Boolean = false) { append("native public ") if (markerAnnotation) { @@ -124,7 +131,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn appendln (" {") iface.secondaryConstructors.forEach { secondary -> - indent(1) + indent(false, 1) append("constructor") renderArgumentsDeclaration(secondary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) @@ -145,10 +152,10 @@ fun Appendable.render(allTypes: Map, typeNamesToUn .filter { it !in superAttributes && !it.static && (it.isVar || (it.isVal && superAttributesByName[it.name]?.hasNoVars() ?: true)) } .map { it.dynamicIfUnknownType(allTypes.keySet()) } .groupBy { it.signature }.reduceValues().values().forEach { arg -> - renderAttributeDeclaration(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.readOnly) + renderAttributeDeclaration(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.readOnly, commented = arg.isCommented(iface.name)) } iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keySet()) }.groupBy { it.signature }.reduceValues(::betterFunction).values().forEach { - renderFunctionDeclaration(it, it.signature in superSignatures) + renderFunctionDeclaration(it, it.signature in superSignatures, commented = it.isCommented(iface.name)) } val staticAttributes = iface.memberAttributes.filter { it.static } @@ -156,18 +163,18 @@ fun Appendable.render(allTypes: Map, typeNamesToUn if (iface.constants.isNotEmpty() || staticAttributes.isNotEmpty() || staticFunctions.isNotEmpty()) { appendln() - indent(1) + indent(false, 1) appendln("companion object {") iface.constants.forEach { - renderAttributeDeclaration(it, override = false, open = false, level = 2) + renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name)) } staticAttributes.forEach { - renderAttributeDeclaration(it, override = false, open = false, level = 2) + renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name)) } staticFunctions.forEach { - renderFunctionDeclaration(it, override = false, level = 2) + renderFunctionDeclaration(it, override = false, level = 2, commented = it.isCommented(iface.name)) } - indent(1) + indent(false, 1) appendln("}") }