From: Martin Vitez Date: Wed, 18 Dec 2013 11:42:49 +0000 (+0100) Subject: Documentation generator improvements. X-Git-Tag: release/beryllium~671^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0ea8b05b970322b9772eac34acbd95f64789cb6a;p=mdsal.git Documentation generator improvements. Updated generation of augment target path. Updated generation of notificiations. Change-Id: I477cb9a1baa654792bea7ad21a0edc653538e862 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 e7323720b2..b910609042 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 @@ -7,7 +7,6 @@ import org.opendaylight.yangtools.yang.model.api.Module import java.io.IOException import java.util.HashSet import java.io.BufferedWriter -import java.io.OutputStream; import java.io.OutputStreamWriter; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode import org.opendaylight.yangtools.yang.model.api.ListSchemaNode @@ -27,7 +26,6 @@ import org.opendaylight.yangtools.yang.model.api.NotificationDefinition import org.opendaylight.yangtools.yang.model.api.DataNodeContainer import org.slf4j.LoggerFactory import org.slf4j.Logger -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema import java.util.List import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.model.api.RpcDefinition @@ -46,12 +44,10 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates import java.util.LinkedHashMap import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier -import com.google.common.collect.FluentIterable import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode -import java.net.URLEncoder -import javax.swing.text.StyledEditorKit.ForegroundAction - +import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode import java.util.HashMap +import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode + class GeneratorImpl { File path @@ -66,18 +62,18 @@ class GeneratorImpl { path.mkdirs(); val it = new HashSet; for (module : modulesToGen) { - add(module.generateDocumentation()); + add(generateDocumentation(module, context)); } return it; } - def generateDocumentation(Module module) { + def generateDocumentation(Module module, SchemaContext ctx) { val destination = new File(path, '''«module.name».html''') try { val fw = new OutputStreamWriter(CTX.newFileOutputStream(destination)) val bw = new BufferedWriter(fw) currentModule = module; - bw.append(module.generate); + bw.append(generate(module, ctx)); bw.close(); fw.close(); } catch (IOException e) { @@ -86,19 +82,19 @@ class GeneratorImpl { return destination; } - def generate(Module module) ''' + def generate(Module module, SchemaContext ctx) ''' «module.name» - «module.body» + «body(module, ctx)» ''' - def body(Module module) ''' + def body(Module module, SchemaContext ctx) ''' «header(module)» «typeDefinitions(module)» @@ -113,7 +109,7 @@ class GeneratorImpl { «notifications(module)» - «augmentations(module)» + «augmentations(module, ctx)» «rpcs(module)» @@ -136,7 +132,7 @@ class GeneratorImpl {
  • «strong("typedef " + typedef.QName.localName)»
      - «typedef.descAndRef» + «typedef.descAndRefLi» «typedef.restrictions»
  • @@ -156,7 +152,7 @@ class GeneratorImpl {
  • «strong("identity " + identity.QName.localName)»
      - «identity.descAndRef» + «identity.descAndRefLi» «IF identity.baseIdentity != null» «listItem("base", identity.baseIdentity.QName.localName)» «ENDIF» @@ -178,7 +174,7 @@ class GeneratorImpl {
    • «strong("grouping " + grouping.QName.localName)»
        - «grouping.descAndRef» + «grouping.descAndRefLi»
    • «ENDFOR» @@ -196,7 +192,7 @@ class GeneratorImpl { ''' } - def augmentations(Module module) { + def augmentations(Module module, SchemaContext context) { if (module.augmentations.empty) { return ''; } @@ -206,9 +202,15 @@ class GeneratorImpl {
        «FOR augment : module.augmentations»
      • - augment - «augment.augmentationInfo(InstanceIdentifier.builder().toInstance())» - «augment.childNodes.printChildren(2,InstanceIdentifier.builder().toInstance())» +

        Target [«schemaPathAsRestconfPath(module, augment.targetPath, context)»]

        + «augment.description» + «IF augment.reference !== null» + Reference «augment.reference» + «ENDIF» + «IF augment.whenCondition !== null» + When «augment.whenCondition.toString» + «ENDIF» + «augment.childNodes.printChildren(3,InstanceIdentifier.builder().toInstance())»
      • «ENDFOR»
      @@ -220,13 +222,14 @@ class GeneratorImpl { if (notificationdefs.empty) { return ''; } - + return '''

      Notifications

      «FOR notificationdef : notificationdefs» - +

      «notificationdef.nodeName»

      - «notificationdef.notificationInfo(InstanceIdentifier.builder().node(notificationdef.QName).toInstance())» + «notificationdef.descAndRef» + «notificationdef.childNodes.printChildren(3,InstanceIdentifier.builder().toInstance())» «ENDFOR» ''' } @@ -235,7 +238,7 @@ class GeneratorImpl { if (module.rpcs.empty) { return ''; } - + return '''

      RPC Definitions

      «FOR rpc : module.rpcs» @@ -256,6 +259,7 @@ class GeneratorImpl {
    • «ext.nodeName»

    • + «extensionInfo(ext)» «ENDFOR» ''' } @@ -272,7 +276,7 @@ class GeneratorImpl {
    • «strong("feature " + feature.QName.localName)»
        - «feature.descAndRef» + «feature.descAndRefLi»
    • «ENDFOR» @@ -282,7 +286,7 @@ class GeneratorImpl { def header(Module module) '''

      «module.name»

      - +

      Base Information

      Prefix
      @@ -291,15 +295,15 @@ class GeneratorImpl {
      «pre(module.namespace.toString)»
      Revision
      «pre(REVISION_FORMAT.format(module.revision))»
      - + «FOR imp : module.imports BEFORE "
      Imports
      " »
      «code(imp.prefix)» = «code(imp.moduleName)»
      «ENDFOR»
      ''' - + def code(String string) '''«string»''' - + def process(Module module) { throw new UnsupportedOperationException("TODO: auto-generated method stub") } @@ -308,12 +312,12 @@ class GeneratorImpl { «strong("module " + module.name)» «module.childNodes.treeSet(InstanceIdentifier.builder.toInstance())» ''' - + private def dispatch CharSequence tree(ChoiceNode node,InstanceIdentifier path) ''' «node.nodeName» (choice) «casesTree(node.cases,path)» ''' - + def casesTree(Set nodes,InstanceIdentifier path) '''
        «FOR node : nodes» @@ -334,7 +338,7 @@ class GeneratorImpl { «localLink(newPath,node.nodeName)» «node.childNodes.treeSet(newPath)» ''' - + private def dispatch CharSequence tree(ContainerSchemaNode node,InstanceIdentifier path) ''' «val newPath = path.append(node)» «localLink(newPath,node.nodeName)» @@ -346,11 +350,12 @@ class GeneratorImpl { «IF childNodes !== null && !childNodes.empty»

        Child nodes

        - «childNodes.printChildren(2,InstanceIdentifier.builder().toInstance())» + «childNodes.printChildren(3,InstanceIdentifier.builder().toInstance())» «ENDIF» ''' - + def CharSequence printChildren(Set nodes, int level, InstanceIdentifier path) { + val anyxmlNodes = nodes.filter(AnyXmlSchemaNode) val leafNodes = nodes.filter(LeafSchemaNode) val leafListNodes = nodes.filter(LeafListSchemaNode) val choices = nodes.filter(ChoiceNode) @@ -358,8 +363,12 @@ class GeneratorImpl { val containers = nodes.filter(ContainerSchemaNode) val lists = nodes.filter(ListSchemaNode) return ''' + «IF ((anyxmlNodes.size + leafNodes.size + leafListNodes.size + containers.size + lists.size) > 0)»

        Direct children

          + «FOR childNode : anyxmlNodes» + «childNode.printShortInfo(level,path)» + «ENDFOR» «FOR childNode : leafNodes» «childNode.printShortInfo(level,path)» «ENDFOR» @@ -373,7 +382,8 @@ class GeneratorImpl { «childNode.printShortInfo(level,path)» «ENDFOR»
        - + «ENDIF» + «IF !path.path.empty»

        XML example

        «nodes.xmlExample(path.path.last.nodeType,path)» @@ -394,53 +404,68 @@ class GeneratorImpl { ''' } - + def CharSequence xmlExample(Set nodes, QName name,InstanceIdentifier path) '''
                 «xmlExampleTag(name,nodes.xmplExampleTags(path))»
             
        ''' - + def CharSequence xmplExampleTags(Set nodes, InstanceIdentifier identifier) ''' «FOR node : nodes» «node.asXmlExampleTag(identifier)» «ENDFOR» - + ''' - + private def dispatch CharSequence asXmlExampleTag(LeafSchemaNode node, InstanceIdentifier identifier) ''' «node.QName.xmlExampleTag("...")» ''' - + private def dispatch CharSequence asXmlExampleTag(LeafListSchemaNode node, InstanceIdentifier identifier) ''' <!-- This node could appear multiple times --> «node.QName.xmlExampleTag("...")» ''' - + private def dispatch CharSequence asXmlExampleTag(ContainerSchemaNode node, InstanceIdentifier identifier) ''' <!-- See «localLink(identifier.append(node),"definition")» for child nodes. --> «node.QName.xmlExampleTag("...")» ''' - - + + private def dispatch CharSequence asXmlExampleTag(ListSchemaNode node, InstanceIdentifier identifier) ''' <!-- See «localLink(identifier.append(node),"definition")» for child nodes. --> <!-- This node could appear multiple times --> «node.QName.xmlExampleTag("...")» ''' - - + + private def dispatch CharSequence asXmlExampleTag(DataSchemaNode node, InstanceIdentifier identifier) ''' ''' - - + + def xmlExampleTag(QName name, CharSequence data) { return '''<«name.localName» xmlns="«name.namespace»">«data»</«name.localName»>''' } - + + def header(int level,QName name) '''«name.localName»''' + + + def header(int level,InstanceIdentifier name) ''' + + «FOR cmp : name.path SEPARATOR "/"»«cmp.nodeType.localName»«ENDFOR» + + ''' + + + + private def dispatch CharSequence printInfo(DataSchemaNode node, int level, InstanceIdentifier path) ''' + «header(level+1,node.QName)» + ''' + private def dispatch CharSequence printInfo(ContainerSchemaNode node, int level, InstanceIdentifier path) ''' «val newPath = path.append(node)» «header(level,newPath)» @@ -452,17 +477,7 @@ class GeneratorImpl { «node.childNodes.printChildren(level,newPath)» ''' - - def header(int level,QName name) '''«name.localName»''' - - - def header(int level,InstanceIdentifier name) - ''' - - «FOR cmp : name.path SEPARATOR "/"»«cmp.nodeType.localName»«ENDFOR» - ''' - - + private def dispatch CharSequence printInfo(ListSchemaNode node, int level, InstanceIdentifier path) ''' «val newPath = path.append(node)» «header(level,newPath)» @@ -484,26 +499,34 @@ class GeneratorImpl { «node.childNodes.printChildren(level,path)» ''' + + def CharSequence printShortInfo(ContainerSchemaNode node, int level, InstanceIdentifier path) { val newPath = path.append(node); return '''
      • «strong(localLink(newPath,node.QName.localName))» (container)
      • ''' } - + def CharSequence printShortInfo(ListSchemaNode node, int level, InstanceIdentifier path) { val newPath = path.append(node); return '''
      • «strong(localLink(newPath,node.QName.localName))» (list)
      • ''' } - + + def CharSequence printShortInfo(AnyXmlSchemaNode node, int level, InstanceIdentifier path) { + return ''' +
      • «strong((node.QName.localName))» (anyxml)
      • + ''' + } + def CharSequence printShortInfo(LeafSchemaNode node, int level, InstanceIdentifier path) { return '''
      • «strong((node.QName.localName))» (leaf)
      • ''' } - + def CharSequence printShortInfo(LeafListSchemaNode node, int level, InstanceIdentifier path) { return '''
      • «strong((node.QName.localName))» (leaf-list)
      • @@ -513,14 +536,14 @@ class GeneratorImpl { def CharSequence localLink(InstanceIdentifier identifier, CharSequence text) ''' «text» ''' - - + + private def dispatch InstanceIdentifier append(InstanceIdentifier identifier, ContainerSchemaNode node) { val pathArguments = new ArrayList(identifier.path) pathArguments.add(new NodeIdentifier(node.QName)); return new InstanceIdentifier(pathArguments); } - + private def dispatch InstanceIdentifier append(InstanceIdentifier identifier, ListSchemaNode node) { val pathArguments = new ArrayList(identifier.path) val keyValues = new LinkedHashMap(); @@ -532,12 +555,12 @@ class GeneratorImpl { pathArguments.add(new NodeIdentifierWithPredicates(node.QName,keyValues)); return new InstanceIdentifier(pathArguments); } - - + + def asXmlPath(InstanceIdentifier identifier) { return ""; } - + def asRestconfPath(InstanceIdentifier identifier) { val it = new StringBuilder(); append(currentModule.name) @@ -556,17 +579,57 @@ class GeneratorImpl { } } } - + return it.toString; } - - - private def dispatch CharSequence printInfo(DataSchemaNode node, int level, InstanceIdentifier path) ''' - «header(level+1,node.QName)» - ''' - + private def String schemaPathAsRestconfPath(Module module, SchemaPath schemaPath, SchemaContext ctx) { + val Map imports = new HashMap(); + for (mImport : module.imports) { + imports.put(mImport.prefix, mImport.moduleName) + } + val List path = schemaPath.path + val StringBuilder pathString = new StringBuilder() + if (schemaPath.absolute) { + pathString.append("/") + } + + val QName qname = path.get(0) + var Object parent = ctx.findModuleByNamespaceAndRevision(qname.namespace, qname.revision) + + for (name : path) { + if (parent instanceof DataNodeContainer) { + var SchemaNode node = (parent as DataNodeContainer).getDataChildByName(name) + if (node == null && (parent instanceof Module)) { + val notifications = (parent as Module).notifications; + for (notification : notifications) { + if (notification.QName.localName.equals(name.localName)) { + node = notification + } + } + } + + if (!(node instanceof ChoiceNode) && !(node instanceof ChoiceCaseNode)) { + var String prefix = node.QName.prefix + var String moduleName + if (prefix == null || "".equals(prefix) || prefix.equals(module.prefix)) { + moduleName = module.name + } else { + moduleName = imports.get(prefix) + } + pathString.append(moduleName) + pathString.append(":") + pathString.append(node.QName.localName) + pathString.append("/") + } + parent = node + } else if (parent instanceof ChoiceNode) { + parent = (parent as ChoiceNode).getCaseNodeByName(qname.localName) + } + } + return pathString.toString; + } def CharSequence childNodesInfoTree(Map childNodes) ''' @@ -583,7 +646,7 @@ class GeneratorImpl { «code(path)» «IF node !== null»
          - «node.descAndRef» + «node.descAndRefLi»
        «ENDIF» «ENDIF» @@ -605,36 +668,9 @@ class GeneratorImpl { [«FOR key : node.keyDefinition SEPARATOR " "»«key.localName»«ENDFOR»] ''' - private def CharSequence augmentationInfo(AugmentationSchema augment, InstanceIdentifier path) ''' -
          - «listItem(augment.description)» - «listItem("Reference", augment.reference)» - «IF augment.whenCondition !== null» - «listItem("When", augment.whenCondition.toString)» - «ENDIF» -
        • - Path «augment.targetPath.path.pathToTree» -
        • -
        • - Child nodes - «augment.childNodes.treeSet(path)» -
        • -
        - ''' - - private def CharSequence notificationInfo(NotificationDefinition notification,InstanceIdentifier path) ''' -
          - «notification.descAndRef» -
        • - Child nodes - «notification.childNodes.treeSet(path)» -
        • -
        - ''' - private def CharSequence rpcInfo(RpcDefinition rpc,InstanceIdentifier path) '''
          - «rpc.descAndRef» + «rpc.descAndRefLi»
        • «rpc.input.tree(path)»
        • @@ -644,9 +680,9 @@ class GeneratorImpl {
        ''' - private def CharSequence extensionInfo(ExtensionDefinition ext, InstanceIdentifier path) ''' + private def CharSequence extensionInfo(ExtensionDefinition ext) '''
          - «ext.descAndRef» + «ext.descAndRefLi» «listItem("Argument", ext.argument)»
        ''' @@ -737,11 +773,18 @@ class GeneratorImpl { private def italic(CharSequence str) '''«str»''' private def pre(CharSequence str) '''
        «str»
        ''' - def CharSequence descAndRef(SchemaNode node) ''' + def CharSequence descAndRefLi(SchemaNode node) ''' «listItem(node.description)» «listItem("Reference", node.reference)» ''' + def CharSequence descAndRef(SchemaNode node) ''' + «node.description» + «IF node.reference !== null» + Reference «node.reference» + «ENDIF» + ''' + private def listItem(String value) ''' «IF value !== null && !value.empty»
      • @@ -753,12 +796,7 @@ class GeneratorImpl { private def listItem(String name, String value) ''' «IF value !== null && !value.empty»
      • - «name» -
          -
        • - «value» -
        • -
        + «name»: «value»
      • «ENDIF» ''' @@ -808,18 +846,6 @@ class GeneratorImpl { } } - private def CharSequence pathToTree(List path) ''' - «IF path !== null && !path.empty» -
          - «FOR pathElement : path» -
        • - «pathElement.namespace» «pathElement.localName» -
        • - «ENDFOR» -
        - «ENDIF» - ''' - private def dispatch addedByInfo(SchemaNode node) ''' '''