Bump yangtools to 5.0.0-SNAPSHOT
[mdsal.git] / binding / maven-sal-api-gen-plugin / src / main / java / org / opendaylight / mdsal / binding / yang / unified / doc / generator / GeneratorImpl.xtend
index 6a3bbf8517ba35fe31fa87456f32f956a80714fc..e8fc818c11bc9ecc08eec7516ac1ff0311ea10dc 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.mdsal.binding.yang.unified.doc.generator
 
-import com.google.common.collect.Iterables
-import com.google.common.collect.Lists
 import java.io.BufferedWriter
 import java.io.File
 import java.io.IOException
@@ -34,6 +32,7 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext
 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraintAware
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition
@@ -42,11 +41,12 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
 import org.opendaylight.yangtools.yang.model.api.Module
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
-import org.opendaylight.yangtools.yang.model.api.SchemaContext
 import org.opendaylight.yangtools.yang.model.api.SchemaNode
 import org.opendaylight.yangtools.yang.model.api.SchemaPath
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition
 import org.opendaylight.yangtools.yang.model.api.UsesNode
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition
@@ -71,14 +71,14 @@ class GeneratorImpl {
 
     val Map<String, String> imports = new HashMap();
     var Module currentModule;
-    var SchemaContext ctx;
+    var EffectiveModelContext ctx;
     var File path
 
     StringBuilder augmentChildNodesAsString
 
     DataSchemaNode lastNodeInTargetPath = null
 
-    def generate(BuildContext buildContext, SchemaContext context, File targetPath, Set<Module> modulesToGen)
+    def generate(BuildContext buildContext, EffectiveModelContext context, File targetPath, Set<Module> modulesToGen)
             throws IOException {
         path = targetPath;
         path.mkdirs();
@@ -89,7 +89,7 @@ class GeneratorImpl {
         return it;
     }
 
-    def generateDocumentation(BuildContext buildContext, Module module, SchemaContext ctx) {
+    def generateDocumentation(BuildContext buildContext, Module module, EffectiveModelContext ctx) {
         val destination = new File(path, '''«module.name».html''')
         this.ctx = ctx;
         module.imports.forEach[importModule | this.imports.put(importModule.prefix, importModule.moduleName)]
@@ -106,7 +106,7 @@ class GeneratorImpl {
         return destination;
     }
 
-    def generate(Module module, SchemaContext ctx) '''
+    def generate(Module module, EffectiveModelContext ctx) '''
         <!DOCTYPE html>
         <html lang="en">
           <head>
@@ -118,7 +118,7 @@ class GeneratorImpl {
         </html>
     '''
 
-    def body(Module module, SchemaContext ctx) '''
+    def body(Module module, EffectiveModelContext ctx) '''
         «header(module)»
 
         «typeDefinitionsSummary(module)»
@@ -155,7 +155,7 @@ class GeneratorImpl {
 
 
     private def typeDefinitionsSummary(Module module) {
-        val Set<TypeDefinition<?>> typedefs = module.typeDefinitions
+        val Collection<? extends TypeDefinition<?>> typedefs = module.typeDefinitions
         if (typedefs.empty) {
             return '';
         }
@@ -183,7 +183,7 @@ class GeneratorImpl {
     }
 
     def typeDefinitions(Module module) {
-        val Set<TypeDefinition<?>> typedefs = module.typeDefinitions
+        val Collection<? extends TypeDefinition<?>> typedefs = module.typeDefinitions
         if (typedefs.empty) {
             return '';
         }
@@ -307,7 +307,7 @@ class GeneratorImpl {
         '''
     }
 
-    def augmentations(Module module, SchemaContext context) {
+    def augmentations(Module module, EffectiveModelContext context) {
         if (module.augmentations.empty) {
             return '';
         }
@@ -318,7 +318,7 @@ class GeneratorImpl {
             «FOR augment : module.augmentations»
                 <li>
                     <h3 id="«schemaPathToString(module, augment.targetPath, context, augment)»">
-                    Target [«typeAnchorLink(augment.targetPath,schemaPathToString(module, augment.targetPath, context, augment))»]</h3>
+                    Target [«typeAnchorLink(augment.targetPath.asSchemaPath, schemaPathToString(module, augment.targetPath, context, augment))»]</h3>
                     «augment.description»
                         Status: «strong(String.valueOf(augment.status))»
                     «IF augment.reference !== null»
@@ -346,9 +346,9 @@ class GeneratorImpl {
         return ''
     }
 
-    private def parseTargetPath(SchemaPath path) {
-        val List<DataSchemaNode> nodes = new ArrayList<DataSchemaNode>();
-        for (QName pathElement : path.pathFromRoot) {
+    private def parseTargetPath(SchemaNodeIdentifier path) {
+        val nodes = new ArrayList<DataSchemaNode>();
+        for (QName pathElement : path.nodeIdentifiers) {
             val module = ctx.findModule(pathElement.module)
             if (module.isPresent) {
                 var foundNode = module.get.getDataChildByName(pathElement)
@@ -368,14 +368,14 @@ class GeneratorImpl {
             lastNodeInTargetPath = nodes.get(nodes.size() - 1)
         }
 
-        val List<DataSchemaNode> targetPathNodes = new ArrayList<DataSchemaNode>();
+        val targetPathNodes = new ArrayList<DataSchemaNode>();
         targetPathNodes.add(lastNodeInTargetPath)
 
         return targetPathNodes
     }
 
-    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
-        for(child : childNodes) {
+    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<? extends DataSchemaNode> childNodes) {
+        for (child : childNodes) {
             if (child.QName.equals(findingNode))
                 return child;
         }
@@ -435,10 +435,10 @@ class GeneratorImpl {
     }
 
     private def printChoiceNode(ChoiceSchemaNode child) {
-        val List<CaseSchemaNode> cases = new ArrayList(child.cases.values);
-        if(!cases.empty) {
+        val cases = new ArrayList(child.cases)
+        if (!cases.empty) {
             val CaseSchemaNode aCase = cases.get(0)
-            for(caseChildNode : aCase.childNodes)
+            for (caseChildNode : aCase.childNodes)
                 printAugmentedNode(caseChildNode)
         }
     }
@@ -488,7 +488,7 @@ class GeneratorImpl {
         '''
     }
 
-    private def augmentationsSummary(Module module, SchemaContext context) {
+    private def augmentationsSummary(Module module, EffectiveModelContext context) {
         if (module.augmentations.empty) {
             return '';
         }
@@ -515,7 +515,7 @@ class GeneratorImpl {
     }
 
     def notifications(Module module) {
-        val Set<NotificationDefinition> notificationdefs = module.notifications
+        val Collection<? extends NotificationDefinition> notificationdefs = module.notifications
         if (notificationdefs.empty) {
             return '';
         }
@@ -767,10 +767,10 @@ class GeneratorImpl {
 
     private def dispatch CharSequence tree(ChoiceSchemaNode node,YangInstanceIdentifier path) '''
         «node.nodeName» (choice)
-        «casesTree(node.cases.values, path)»
+        «casesTree(node.cases, path)»
     '''
 
-    def casesTree(Collection<CaseSchemaNode> nodes, YangInstanceIdentifier path) '''
+    def casesTree(Collection<? extends CaseSchemaNode> nodes, YangInstanceIdentifier path) '''
         <ul>
         «FOR node : nodes»
             <li>
@@ -818,8 +818,7 @@ class GeneratorImpl {
                 «ENDFOR»
                 </ul>
                 <ul>
-                «val Set<TypeDefinition<?>> typeDefinitions = dataNode.typeDefinitions»
-                «FOR typeDef : typeDefinitions»
+                «FOR typeDef : dataNode.typeDefinitions»
                     «typeDef.restrictions»
                 «ENDFOR»
                 </ul>
@@ -840,7 +839,7 @@ class GeneratorImpl {
 
     def String typeAnchorLink(SchemaPath path, CharSequence text) {
         if(path !== null) {
-            val lastElement = Iterables.getLast(path.pathFromRoot)
+            val lastElement = path.lastComponent
             val ns = lastElement.namespace
             if (ns == this.currentModule.namespace) {
                 return '''<a href="#«path.schemaPathToId»">«text»</a>'''
@@ -879,7 +878,7 @@ class GeneratorImpl {
             return '''
                 «printInfo(node, "choice")»
                 «listItem("default case", node.defaultCase.map([ CaseSchemaNode n | n.getQName.localName]).orElse(null))»
-                «FOR caseNode : node.cases.values»
+                «FOR caseNode : node.cases»
                     «caseNode.printSchemaNodeInfo»
                 «ENDFOR»
                 </ul>
@@ -935,7 +934,7 @@ class GeneratorImpl {
 
     def CharSequence printUses(UsesNode usesNode) {
         return '''
-            «strong(listItem("uses", typeAnchorLink(usesNode.groupingPath, usesNode.groupingPath.pathTowardsRoot.iterator.next.localName)))»
+            «strong(listItem("uses", typeAnchorLink(usesNode.sourceGrouping.path, usesNode.sourceGrouping.path.pathTowardsRoot.iterator.next.localName)))»
             <ul>
             <li>refines:
                 <ul>
@@ -945,7 +944,7 @@ class GeneratorImpl {
                 </ul>
             </li>
             «FOR augment : usesNode.augmentations»
-                «typeAnchorLink(augment.targetPath,schemaPathToString(currentModule, augment.targetPath, ctx, augment))»
+                «typeAnchorLink(augment.targetPath.asSchemaPath, schemaPathToString(currentModule, augment.targetPath, ctx, augment))»
             «ENDFOR»
             </ul>
         '''
@@ -957,7 +956,7 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, YangInstanceIdentifier path) {
+    def CharSequence printChildren(Iterable<? extends DataSchemaNode> nodes, int level, YangInstanceIdentifier path) {
         val anyxmlNodes = nodes.filter(AnyxmlSchemaNode)
         val leafNodes = nodes.filter(LeafSchemaNode)
         val leafListNodes = nodes.filter(LeafListSchemaNode)
@@ -1007,13 +1006,13 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence xmlExample(Iterable<DataSchemaNode> nodes, QName name,YangInstanceIdentifier path) '''
+    def CharSequence xmlExample(Iterable<? extends DataSchemaNode> nodes, QName name, YangInstanceIdentifier path) '''
     <pre>
         «xmlExampleTag(name,nodes.xmplExampleTags(path))»
     </pre>
     '''
 
-    def CharSequence xmplExampleTags(Iterable<DataSchemaNode> nodes, YangInstanceIdentifier identifier) '''
+    def CharSequence xmplExampleTags(Iterable<? extends DataSchemaNode> nodes, YangInstanceIdentifier identifier) '''
         <!-- Child nodes -->
         «FOR node : nodes»
         <!-- «node.QName.localName» -->
@@ -1093,7 +1092,7 @@ class GeneratorImpl {
     '''
 
     private def dispatch CharSequence printInfo(ChoiceSchemaNode node, int level, YangInstanceIdentifier path) '''
-        «val Set<DataSchemaNode> choiceCases = new HashSet(node.cases.values
+        «val Set<DataSchemaNode> choiceCases = new HashSet(node.cases)»
         «choiceCases.printChildren(level, path)»
     '''
 
@@ -1209,10 +1208,11 @@ class GeneratorImpl {
         return it.toString;
     }
 
-    private def String schemaPathToString(Module module, SchemaPath schemaPath, SchemaContext ctx, DataNodeContainer dataNode) {
-            val List<QName> path = Lists.newArrayList(schemaPath.pathFromRoot);
+    private def String schemaPathToString(Module module, SchemaNodeIdentifier schemaPath, EffectiveModelContext ctx,
+            DataNodeContainer dataNode) {
+        val path = schemaPath.nodeIdentifiers
         val StringBuilder pathString = new StringBuilder()
-        if (schemaPath.absolute) {
+        if (schemaPath instanceof Absolute) {
             pathString.append('/')
         }
 
@@ -1279,7 +1279,7 @@ class GeneratorImpl {
         «ENDIF»
     '''
 
-    private def CharSequence treeSet(Collection<DataSchemaNode> childNodes, YangInstanceIdentifier path) '''
+    private def CharSequence treeSet(Collection<? extends DataSchemaNode> childNodes, YangInstanceIdentifier path) '''
         «IF childNodes !== null && !childNodes.empty»
             <ul>
             «FOR child : childNodes»
@@ -1450,7 +1450,7 @@ class GeneratorImpl {
             result.append('/')
         }
         if (path !== null && !path.empty) {
-            val List<QName> actual = new ArrayList()
+            val actual = new ArrayList()
             var i = 0;
             for (pathElement : path) {
                 actual.add(pathElement)
@@ -1475,15 +1475,11 @@ class GeneratorImpl {
     '''
 
     private def dispatch isAddedBy(SchemaNode node) {
-        return false;
+        return false
     }
 
     private def dispatch isAddedBy(DataSchemaNode node) {
-        if (node.augmenting || node.addedByUses) {
-            return true
-        } else {
-            return false;
-        }
+        return node.augmenting || node.addedByUses
     }
 
     private def dispatch nodeName(SchemaNode node) '''