Degrade DataNodeContainer.getChildNodes() from Set to Collection
[yangtools.git] / code-generator / maven-sal-api-gen-plugin / src / main / java / org / opendaylight / yangtools / yang / unified / doc / generator / GeneratorImpl.xtend
index 01f94dff04685700333ab605828ba2f746977c22..bc4e267b0c6c429f1a52b8cf43dcf4cce1704d6b 100644 (file)
@@ -64,6 +64,10 @@ class GeneratorImpl {
     var Module currentModule;
     val Map<String, String> imports = new HashMap();
     var SchemaContext ctx;
+    
+    StringBuilder augmentChildNodesAsString
+    
+    DataSchemaNode lastNodeInTargetPath = null
 
     def generate(SchemaContext context, File targetPath, Set<Module> modulesToGen) throws IOException {
         path = targetPath;
@@ -299,13 +303,14 @@ class GeneratorImpl {
         }
         return '''
             <h2>Augmentations</h2>
-
+            
             <ul>
             «FOR augment : module.augmentations»
                 <li>
                     <h3 id="«schemaPathToString(module, augment.targetPath, context, augment)»">
                     Target [«typeAnchorLink(augment.targetPath,schemaPathToString(module, augment.targetPath, context, augment))»]</h3>
                     «augment.description»
+                        Status: «strong(String.valueOf(augment.status))»
                     «IF augment.reference !== null»
                         Reference «augment.reference»
                     «ENDIF»
@@ -315,11 +320,169 @@ class GeneratorImpl {
                     «FOR childNode : augment.childNodes»
                         «childNode.printSchemaNodeInfo»
                     «ENDFOR»
+                    
+                    <h3>Example</h3>
+                    «createAugmentChildNodesAsString(new ArrayList(augment.childNodes))»
+                    «printNodeChildren(parseTargetPath(augment.targetPath))»
                 </li>
             «ENDFOR»
             </ul>
         '''
     }
+    
+    private def createAugmentChildNodesAsString(List<DataSchemaNode> childNodes) {
+        augmentChildNodesAsString = new StringBuilder();
+        augmentChildNodesAsString.append(printNodeChildren(childNodes))
+        return ''
+    }
+    
+    private def parseTargetPath(SchemaPath path) {
+        val List<DataSchemaNode> nodes = new ArrayList<DataSchemaNode>();
+        for (QName pathElement : path.pathFromRoot) {
+            val prefix = pathElement.prefix
+            val moduleName = imports.get(prefix)
+            if(moduleName != null) {
+                val revision = pathElement.revision
+                val module = ctx.findModuleByName(moduleName, revision)
+                var foundNode = module.getDataChildByName(pathElement)
+                if(foundNode == null) {
+                    val child = nodes.last
+                    if (child instanceof DataNodeContainer) {
+                        val dataContNode = child as DataNodeContainer
+                        foundNode = findNodeInChildNodes(pathElement, dataContNode.childNodes)
+                    }
+                }
+                if(foundNode != null) {
+                    nodes.add(foundNode);
+                }
+            }
+        }
+        if(! nodes.empty) {
+            lastNodeInTargetPath = nodes.get(nodes.size() - 1)
+        }
+        
+        val List<DataSchemaNode> targetPathNodes = new ArrayList<DataSchemaNode>();
+        targetPathNodes.add(lastNodeInTargetPath)
+        
+        return targetPathNodes
+    }
+    
+    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
+        for(child : childNodes) {
+            if (child.QName.equals(findingNode))
+                return child;
+        }
+        // find recursively
+        for(child : childNodes) {
+            if(child instanceof ContainerSchemaNode) {
+                val contChild = child as ContainerSchemaNode
+                val foundChild = findNodeInChildNodes(findingNode, contChild.childNodes)
+                if (foundChild != null)
+                    return foundChild;
+            }
+            else if(child instanceof ListSchemaNode) {
+                val listChild = child as ListSchemaNode
+                val foundChild = findNodeInChildNodes(findingNode, listChild.childNodes)
+                if (foundChild != null)
+                    return foundChild;
+            }
+        }
+    }
+    
+    private def printNodeChildren(List<DataSchemaNode> childNodes) {
+        if (childNodes.empty) {
+            return ''
+        }
+        
+        return 
+        '''
+        <pre>
+        «printAugmentedNode(childNodes.get(0))»
+        </pre>
+        '''
+    }
+    
+    private def printAugmentedNode(DataSchemaNode child) {
+        
+        if(child instanceof ChoiceCaseNode)
+            return ''
+            
+        return
+        '''
+        «IF child instanceof ContainerSchemaNode»
+            «printContainerNode(child as ContainerSchemaNode)»
+        «ENDIF»
+        «IF child instanceof AnyXmlSchemaNode»
+            «printAnyXmlNode(child as AnyXmlSchemaNode)»
+        «ENDIF»
+        «IF child instanceof LeafSchemaNode»
+            «printLeafNode(child as LeafSchemaNode)»
+        «ENDIF»
+        «IF child instanceof LeafListSchemaNode»
+            «printLeafListNode(child as LeafListSchemaNode)»
+        «ENDIF»
+        «IF child instanceof ListSchemaNode»
+            «printListNode(child as ListSchemaNode)»
+        «ENDIF»
+        «IF child instanceof ChoiceNode»
+            «printChoiceNode(child as ChoiceNode)»
+        «ENDIF»
+        '''
+    }
+    
+    private def printChoiceNode(ChoiceNode child) {
+        val List<ChoiceCaseNode> cases = new ArrayList(child.cases);
+        if(!cases.empty) {
+            val ChoiceCaseNode aCase = cases.get(0)
+            for(caseChildNode : aCase.childNodes)
+                printAugmentedNode(caseChildNode)
+        }
+    }
+    
+    private def printListNode(ListSchemaNode listNode) {
+        return
+        '''
+            &lt;«listNode.QName.localName»«IF !listNode.QName.namespace.equals(currentModule.namespace)» xmlns="«listNode.QName.namespace»"«ENDIF»&gt;
+                «FOR child : listNode.childNodes»
+                    «printAugmentedNode(child)»
+                «ENDFOR»
+            &lt;/«listNode.QName.localName»&gt;
+        '''
+    }
+    
+    private def printContainerNode(ContainerSchemaNode containerNode) {
+        return
+        '''
+            &lt;«containerNode.QName.localName»«IF !containerNode.QName.namespace.equals(currentModule.namespace)» xmlns="«containerNode.QName.namespace»"«ENDIF»&gt;
+                «FOR child : containerNode.childNodes»
+                    «printAugmentedNode(child)»
+                «ENDFOR»
+            &lt;/«containerNode.QName.localName»&gt;
+        '''
+    }
+    
+    private def printLeafListNode(LeafListSchemaNode leafListNode) {
+        return
+        '''
+            &lt;«leafListNode.QName.localName»&gt;. . .&lt;/«leafListNode.QName.localName»&gt;
+            &lt;«leafListNode.QName.localName»&gt;. . .&lt;/«leafListNode.QName.localName»&gt;
+            &lt;«leafListNode.QName.localName»&gt;. . .&lt;/«leafListNode.QName.localName»&gt;
+        '''
+    }
+    
+    private def printAnyXmlNode(AnyXmlSchemaNode anyXmlNode) {
+        return 
+        '''
+            &lt;«anyXmlNode.QName.localName»&gt;. . .&lt;/«anyXmlNode.QName.localName»&gt;
+        '''
+    }
+    
+    private def printLeafNode(LeafSchemaNode leafNode) {
+        return 
+        '''
+            &lt;«leafNode.QName.localName»&gt;. . .&lt;/«leafNode.QName.localName»&gt;
+        '''
+    }
 
     private def augmentationsSummary(Module module, SchemaContext context) {
         if (module.augmentations.empty) {
@@ -649,8 +812,7 @@ class GeneratorImpl {
                 «ENDFOR»
                 </ul>
                 <ul>
-                «val Set<TypeDefinition<?>> typedefs = dataNode.typeDefinitions»
-                «FOR typeDef : typedefs»
+                «FOR typeDef : dataNode.typeDefinitions»
                     «typeDef.restrictions»
                 «ENDFOR»
                 </ul>
@@ -788,7 +950,7 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printChildren(Set<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
+    def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
         val anyxmlNodes = nodes.filter(AnyXmlSchemaNode)
         val leafNodes = nodes.filter(LeafSchemaNode)
         val leafListNodes = nodes.filter(LeafListSchemaNode)
@@ -838,13 +1000,13 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence xmlExample(Set<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
+    def CharSequence xmlExample(Iterable<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
     <pre>
         «xmlExampleTag(name,nodes.xmplExampleTags(path))»
     </pre>
     '''
 
-    def CharSequence xmplExampleTags(Set<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
+    def CharSequence xmplExampleTags(Iterable<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
         <!-- Child nodes -->
         «FOR node : nodes»
         <!-- «node.QName.localName» -->
@@ -937,32 +1099,54 @@ class GeneratorImpl {
     def CharSequence printShortInfo(ContainerSchemaNode node, int level, InstanceIdentifier path) {
         val newPath = path.append(node);
         return '''
-            <li>«strong(localLink(newPath,node.QName.localName))» (container)</li>
+            <li>«strong(localLink(newPath,node.QName.localName))» (container)
+            <ul>
+                <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+            </ul>
+            </li>
         '''
     }
 
     def CharSequence printShortInfo(ListSchemaNode node, int level, InstanceIdentifier path) {
         val newPath = path.append(node);
         return '''
-            <li>«strong(localLink(newPath,node.QName.localName))» (list)</li>
+            <li>«strong(localLink(newPath,node.QName.localName))» (list)
+            <ul>
+                <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+            </ul>
+            </li>
         '''
     }
 
     def CharSequence printShortInfo(AnyXmlSchemaNode node, int level, InstanceIdentifier path) {
         return '''
-            <li>«strong((node.QName.localName))» (anyxml)</li>
+            <li>«strong((node.QName.localName))» (anyxml)
+            <ul>
+                <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+                <li>mandatory: «strong(String.valueOf(node.constraints.mandatory))»</li>
+            </ul>
+            </li>
         '''
     }
 
     def CharSequence printShortInfo(LeafSchemaNode node, int level, InstanceIdentifier path) {
         return '''
-            <li>«strong((node.QName.localName))» (leaf)</li>
+            <li>«strong((node.QName.localName))» (leaf)
+            <ul>
+                <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+                <li>mandatory: «strong(String.valueOf(node.constraints.mandatory))»</li>
+            </ul>
+            </li>
         '''
     }
 
     def CharSequence printShortInfo(LeafListSchemaNode node, int level, InstanceIdentifier path) {
         return '''
-            <li>«strong((node.QName.localName))» (leaf-list)</li>
+            <li>«strong((node.QName.localName))» (leaf-list)
+            <ul>
+                <li>configuration data: «strong(String.valueOf(node.configuration))»</li>
+            </ul>
+            </li>
         '''
     }
 
@@ -1023,7 +1207,7 @@ class GeneratorImpl {
             val List<QName> path = schemaPath.path
         val StringBuilder pathString = new StringBuilder()
         if (schemaPath.absolute) {
-            pathString.append("/")
+            pathString.append('/')
         }
 
         val QName qname = path.get(0)
@@ -1051,15 +1235,15 @@ class GeneratorImpl {
 
                 var String prefix = name.prefix
                 var String moduleName
-                if (prefix == null || "".equals(prefix) || prefix.equals(module.prefix)) {
+                if (prefix == null || prefix.empty || prefix.equals(module.prefix)) {
                     moduleName = module.name
                 } else {
                     moduleName = imports.get(prefix)
                 }
                 pathString.append(moduleName)
-                pathString.append(":")
+                pathString.append(':')
                 pathString.append(name.localName)
-                pathString.append("/")
+                pathString.append('/')
                 if(node instanceof ChoiceNode && dataNode !== null) {
                     val DataSchemaNode caseNode = dataNode.childNodes.findFirst[DataSchemaNode e | e instanceof ChoiceCaseNode];
                     if(caseNode !== null) {