<commit_before>package com.sixrq.kaxb

import org.w3c.dom.Element
import org.w3c.dom.Node

class ComplexType(val packageName: String, val xmlns: String, val xsdns: String, val item: Element) {
    val className: String by lazy { extractClassName(item.attributes.item(0).nodeValue) }

    val comment: String by lazy {
        val comments = StringBuilder()
        comments.append("/**\n")
        val elementsByTagName = item.getElementsByTagName("xsd:annotation")
        comments.append(when(elementsByTagName.length) {
            1 -> { processAnnotation(elementsByTagName.item(0)) }
            else -> ""
        })
        comments.append("\n *\n$schemaDefinition\n *\n**/\n\n")
        comments.toString().replace("\n\n", "\n")
    }

    val definition: String by lazy {
        val classDefinition = StringBuilder()
        classDefinition.append("data class ${className} {\n")
        classDefinition.append(processClassContent())
        classDefinition.append("}\n")
        classDefinition.toString()
    }

    private fun processClassContent(): String {
        val content = StringBuilder()
        val elementsByTagName = item.getElementsByTagName("xsd:sequence")
        if (elementsByTagName.item(0) != null) {
            for (index in 0..(elementsByTagName.item(0).childNodes.length - 1)) {
                val item = elementsByTagName.item(0).childNodes.item(index)
                when (item.nodeName) {
                    "xsd:element" -> {
                        val varName = item.attributes.getNamedItem("name").nodeValue.decapitalize()
                        val varType =
                            if (item.attributes.getNamedItem("maxOccurs") != null) {
                                "List<${extractClassName(item.attributes.getNamedItem("type").nodeValue.replace("xsd:", "").replace("token", "String"))}>"
                            } else {
                                "${extractClassName(item.attributes.getNamedItem("type").nodeValue.replace("xsd:", "").replace("token", "String"))}"
                            }
                        content.append("   @XmlElement(name = \"${item.attributes.getNamedItem("name").nodeValue}\", namespace = \"${xmlns}\"")
                        if (item.attributes.getNamedItem("maxOccurs") != null && item.attributes.getNamedItem("maxOccurs").nodeValue == "unbounded") {
                            content.append(", required = true)\n")
                        } else {
                            content.append(")\n")
                        }
                        content.append("   val ${varName}: ${varType}\n")
                    }
                }
            }
        }
        return content.toString()
    }

    val schemaDefinition: String by lazy {
        val definition = StringBuilder()
        definition.append(" * <p>Kotlin class for ${item.attributes.item(0).nodeValue} complex type\n *\n")
        definition.append(" * <p>The following schema fragment specifies the expected content contained within this class.\n *\n")
        definition.append(" * <pre>\n")
        definition.append(" * &lt;complexType name=\"${item.attributes.item(0).nodeValue}\">\n")
        definition.append(" *   &lt;complexContent>\n")
        definition.append(" *     &lt;restriction base=\"{${xsdns}}anyType\">\n")
        // TODO Add Schema comments for sequence etc.
        definition.append(" *     &lt;/restriction>\n")
        definition.append(" *   &lt;/complexContent>\n")
        definition.append(" * &lt;/complexType>\n")
        definition.append(" * </pre>\n *\n")
        definition.toString()
    }

    private fun extractClassName(name: String): String {
        val className = StringBuilder()
        name.split('_').forEach {
            className.append(it.capitalize())
        }
        return className.toString()<commit_msg>KAXB-1 : Add sequence information to javadoc<commit_after>package com.sixrq.kaxb

import org.w3c.dom.Element
import org.w3c.dom.Node

class ComplexType(val packageName: String, val xmlns: String, val xsdns: String, val item: Element) {
    val className: String by lazy { extractClassName(item.attributes.item(0).nodeValue) }

    val comment: String by lazy {
        val comments = StringBuilder()
        comments.append("/**\n")
        val elementsByTagName = item.getElementsByTagName("xsd:annotation")
        comments.append(when(elementsByTagName.length) {
            1 -> { processAnnotation(elementsByTagName.item(0)) }
            else -> ""
        })
        comments.append("\n *\n$schemaDefinition\n *\n**/\n\n")
        comments.toString().replace("\n\n", "\n")
    }

    val definition: String by lazy {
        val classDefinition = StringBuilder()
        classDefinition.append("data class ${className} {\n")
        classDefinition.append(processClassContent())
        classDefinition.append("}\n")
        classDefinition.toString()
    }

    private fun processClassContent(): String {
        val content = StringBuilder()
        val elementsByTagName = item.getElementsByTagName("xsd:sequence")
        if (elementsByTagName.item(0) != null) {
            for (index in 0..(elementsByTagName.item(0).childNodes.length - 1)) {
                val item = elementsByTagName.item(0).childNodes.item(index)
                when (item.nodeName) {
                    "xsd:element" -> {
                        val varName = item.attributes.getNamedItem("name").nodeValue.decapitalize()
                        val varType =
                            if (item.attributes.getNamedItem("maxOccurs") != null) {
                                "List<${extractClassName(item.attributes.getNamedItem("type").nodeValue.replace("xsd:", "").replace("token", "String"))}>"
                            } else {
                                "${extractClassName(item.attributes.getNamedItem("type").nodeValue.replace("xsd:", "").replace("token", "String"))}"
                            }
                        content.append("   @XmlElement(name = \"${item.attributes.getNamedItem("name").nodeValue}\", namespace = \"${xmlns}\"")
                        if (item.attributes.getNamedItem("maxOccurs") != null && item.attributes.getNamedItem("maxOccurs").nodeValue == "unbounded") {
                            content.append(", required = true)\n")
                        } else {
                            content.append(")\n")
                        }
                        content.append("   val ${varName}: ${varType}\n")
                    }
                }
            }
        }
        return content.toString()
    }

    val schemaDefinition: String by lazy {
        val definition = StringBuilder()
        definition.append(" * <p>Kotlin class for ${item.attributes.item(0).nodeValue} complex type\n *\n")
        definition.append(" * <p>The following schema fragment specifies the expected content contained within this class.\n *\n")
        definition.append(" * <pre>\n")
        definition.append(" * &lt;complexType name=\"${item.attributes.item(0).nodeValue}\">\n")
        definition.append(" *   &lt;complexContent>\n")
        definition.append(" *     &lt;restriction base=\"{${xsdns}}anyType\">\n")
        for (nodeIndex in 0..(item.childNodes.length-1)) {
            val node = item.childNodes.item(nodeIndex)
            when (node.nodeName) {
                "xsd:sequence" -> {
                    definition.append(" *       &lt;${node.nodeName.replace("xsd:", "")}>\n")
                    for(childIndex in 0..(node.childNodes.length-1)) {
                        val childNode = node.childNodes.item(childIndex)
                        when (childNode) {
                            is Element -> {
                                definition.append(" *         &lt;${childNode.nodeName.replace("xsd:", "")}")
                                definition.append(" name=\"${childNode.getAttribute("name")}\"")
                                definition.append(" type=\"{${xmlns}}${childNode.getAttribute("type")}\"")
                                if (childNode.getAttribute("maxOccurs") != null)
                                    definition.append(" maxOccurs=\"${childNode.getAttribute("maxOccurs")}\"")
                                if (childNode.getAttribute("maxOccurs") != null)
                                    definition.append(" minOccurs=\"${childNode.getAttribute("minOccurs")}\"")
                                definition.append("/>\n")
                            }
                        }
                    }
                    definition.append(" *       &lt;/${node.nodeName.replace("xsd:", "")}>\n")
                }
            }
        }
        definition.append(" *     &lt;/restriction>\n")
        definition.append(" *   &lt;/complexContent>\n")
        definition.append(" * &lt;/complexType>\n")
        definition.append(" * </pre>\n *\n")
        definition.toString()
    }

    private fun extractClassName(name: String): String {
        val className = StringBuilder()
        name.split('_').forEach {
            className.append(it.capitalize())
        }
        return className.toString()
{'fraction_non_alphanumeric': 0.14429383471797114, 'fraction_numerical': 0.003170091823349366, 'mean_word_length': 1.8824826717076244, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2599', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2320, 'n_words': 420}