From: Martin Vitez Date: Fri, 22 Nov 2013 08:53:07 +0000 (+0100) Subject: Added path to child nodes in documentation generator. X-Git-Tag: release/beryllium~711^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=9c1a554a9b7d0a2f83133027b6114494e2722c75;p=mdsal.git Added path to child nodes in documentation generator. Signed-off-by: Martin Vitez --- diff --git a/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend b/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend index 78eeaf3383..206a0b9613 100644 --- a/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend +++ b/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend @@ -31,6 +31,12 @@ import java.util.List import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.model.api.RpcDefinition import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition +import java.util.ArrayList +import java.util.Map +import org.opendaylight.yangtools.yang.model.api.SchemaPath +import java.util.LinkedHashMap +import org.opendaylight.yangtools.yang.model.api.ChoiceNode +import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode class GeneratorImpl { @@ -86,6 +92,8 @@ class GeneratorImpl { «groupings(module)» + «childNodes(module)» + «dataStore(module)» «notifications(module)» @@ -312,6 +320,38 @@ class GeneratorImpl { «node.childNodes.tree» ''' + def CharSequence childNodes(Module module) ''' + «val Map childNodes = new LinkedHashMap()» + «collectChildNodes(module.childNodes, childNodes)» + «IF childNodes !== null && !childNodes.empty» +

Child nodes

+ + «childNodes.childNodesInfoTree» + «ENDIF» + ''' + + def CharSequence childNodesInfoTree(Map childNodes) ''' + «IF childNodes !== null && !childNodes.empty» +
    + «FOR child : childNodes.values» + «childInfo(child, childNodes)» + «ENDFOR» +
+ «ENDIF» + ''' + + def CharSequence childInfo(DataSchemaNode node, Map childNodes) ''' + «val String path = nodeSchemaPathToPath(node, childNodes)» + «IF path != null» + «listItem(strong(path))» + «IF node !== null» +
    + «node.descAndRef» +
+ «ENDIF» + «ENDIF» + ''' + def dispatch CharSequence tree(Collection childNodes) ''' «IF childNodes !== null && !childNodes.empty»
    @@ -453,7 +493,7 @@ class GeneratorImpl { /* #################### UTILITY #################### */ - private def strong(String str) '''«str»''' + private def String strong(String str) '''«str»''' private def italic(String str) '''«str»''' private def pre(String str) '''
    «str»
    ''' @@ -483,6 +523,51 @@ class GeneratorImpl { «ENDIF» ''' + private def String nodeSchemaPathToPath(DataSchemaNode node, Map childNodes) { + if (node instanceof ChoiceNode || node instanceof ChoiceCaseNode) { + return null + } + + val path = node.path.path + val absolute = node.path.absolute; + var StringBuilder result = new StringBuilder + if (absolute) { + result.append("/") + } + if (path !== null && !path.empty) { + val List actual = new ArrayList() + var i = 0; + for (pathElement : path) { + actual.add(pathElement) + val DataSchemaNode nodeByPath = childNodes.get(new SchemaPath(actual, absolute)) + if (!(nodeByPath instanceof ChoiceNode) && !(nodeByPath instanceof ChoiceCaseNode)) { + result.append(pathElement.localName) + if (i != path.size - 1) { + result.append("/") + } + } + i = i + 1 + } + } + return result.toString + } + + private def void collectChildNodes(Collection source, Map destination) { + for (node : source) { + destination.put(node.path, node) + if (node instanceof DataNodeContainer) { + collectChildNodes((node as DataNodeContainer).childNodes, destination) + } + if (node instanceof ChoiceNode) { + val List choiceCases = new ArrayList() + for (caseNode : (node as ChoiceNode).cases) { + choiceCases.add(caseNode) + } + collectChildNodes(choiceCases, destination) + } + } + } + private def CharSequence pathToTree(List path) ''' «IF path !== null && !path.empty»
      diff --git a/code-generator/maven-sal-api-gen-plugin/src/test/resources/doc-gen/network-topology@2013-07-12.yang b/code-generator/maven-sal-api-gen-plugin/src/test/resources/doc-gen/network-topology@2013-07-12.yang index fb18be46bc..c22258baa2 100644 --- a/code-generator/maven-sal-api-gen-plugin/src/test/resources/doc-gen/network-topology@2013-07-12.yang +++ b/code-generator/maven-sal-api-gen-plugin/src/test/resources/doc-gen/network-topology@2013-07-12.yang @@ -277,6 +277,29 @@ module network-topology { that serve a purpose other than identifying a particular topology type. "; + choice node-type { + case type1 { + container c1 { + leaf id { + type int8; + } + } + } + case type2 { + container c2 { + container cc2 {} + } + } + case type3 { + list c3 { + container cc3 { + leaf id { + type string; + } + } + } + } + } } list underlay-topology { key "topology-ref";