Migrate getDataChildByName() users
[mdsal.git] / binding / maven-sal-api-gen-plugin / src / main / java / org / opendaylight / mdsal / binding / yang / unified / doc / generator / GeneratorImpl.xtend
index 45fb65da6dc74c046263cd95ca2dee5ac04f6acf..ec0b087204421e1875be7db0ac0159eec48eff2a 100644 (file)
@@ -7,13 +7,12 @@
  */
 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
 import java.io.OutputStreamWriter
 import java.nio.charset.StandardCharsets
+import java.nio.file.Files
 import java.util.ArrayList
 import java.util.Collection
 import java.util.HashMap
@@ -23,16 +22,18 @@ import java.util.List
 import java.util.Map
 import java.util.Optional
 import java.util.Set
+import org.gaul.modernizer_maven_annotations.SuppressModernizer
 import org.opendaylight.yangtools.yang.common.QName
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode
 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
@@ -41,70 +42,70 @@ 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.type.BinaryTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition
+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.LengthConstraint
+import org.opendaylight.yangtools.yang.model.api.type.LengthRestrictedTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint
-import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition
+import org.opendaylight.yangtools.yang.model.api.type.RangeRestrictedTypeDefinition
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.sonatype.plexus.build.incremental.BuildContext
-import org.sonatype.plexus.build.incremental.DefaultBuildContext
 
+@SuppressModernizer
 class GeneratorImpl {
 
-    File path
     static val Logger LOG = LoggerFactory.getLogger(GeneratorImpl)
-    static val BuildContext CTX = new DefaultBuildContext();
-    var Module currentModule;
+
     val Map<String, String> imports = new HashMap();
-    var SchemaContext ctx;
+    var Module currentModule;
+    var EffectiveModelContext ctx;
+    var File path
 
     StringBuilder augmentChildNodesAsString
 
     DataSchemaNode lastNodeInTargetPath = null
 
-    def generate(SchemaContext context, File targetPath, Set<Module> modulesToGen) throws IOException {
+    def generate(BuildContext buildContext, EffectiveModelContext context, File targetPath, Set<Module> modulesToGen)
+            throws IOException {
         path = targetPath;
-        path.mkdirs();
+        Files.createDirectories(path.getParentFile().toPath())
         val it = new HashSet;
         for (module : modulesToGen) {
-            add(generateDocumentation(module, context));
+            add(generateDocumentation(buildContext, module, context));
         }
         return it;
     }
 
-    def generateDocumentation(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)]
+        var OutputStreamWriter fw
+        var BufferedWriter bw
         try {
-            val fw = new OutputStreamWriter(CTX.newFileOutputStream(destination), StandardCharsets.UTF_8)
-            val bw = new BufferedWriter(fw)
+            fw = new OutputStreamWriter(buildContext.newFileOutputStream(destination), StandardCharsets.UTF_8)
+            bw = new BufferedWriter(fw)
             currentModule = module;
             bw.append(generate(module, ctx));
-            bw.close();
-            fw.close();
         } catch (IOException e) {
-            LOG.error(e.getMessage());
+            LOG.error("Failed to emit file {}", destination, e);
+        } finally {
+            if (bw !== null) {
+                bw.close();
+            }
+            if (fw !== null) {
+                fw.close();
+            }
         }
         return destination;
     }
 
-    def generate(Module module, SchemaContext ctx) '''
+    def generate(Module module, EffectiveModelContext ctx) '''
         <!DOCTYPE html>
         <html lang="en">
           <head>
@@ -116,7 +117,7 @@ class GeneratorImpl {
         </html>
     '''
 
-    def body(Module module, SchemaContext ctx) '''
+    def body(Module module, EffectiveModelContext ctx) '''
         «header(module)»
 
         «typeDefinitionsSummary(module)»
@@ -153,7 +154,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 '';
         }
@@ -181,7 +182,7 @@ class GeneratorImpl {
     }
 
     def typeDefinitions(Module module) {
-        val Set<TypeDefinition<?>> typedefs = module.typeDefinitions
+        val Collection<? extends TypeDefinition<?>> typedefs = module.typeDefinitions
         if (typedefs.empty) {
             return '';
         }
@@ -305,7 +306,7 @@ class GeneratorImpl {
         '''
     }
 
-    def augmentations(Module module, SchemaContext context) {
+    def augmentations(Module module, EffectiveModelContext context) {
         if (module.augmentations.empty) {
             return '';
         }
@@ -316,7 +317,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»
@@ -344,12 +345,12 @@ 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)
+                var foundNode = module.get.dataChildByName(pathElement)
                 if (foundNode === null) {
                     val child = nodes.last
                     if (child instanceof DataNodeContainer) {
@@ -362,18 +363,18 @@ class GeneratorImpl {
                 }
             }
         }
-        if(! nodes.empty) {
+        if (!nodes.empty) {
             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;
         }
@@ -414,7 +415,7 @@ class GeneratorImpl {
         «IF child instanceof ContainerSchemaNode»
             «printContainerNode(child)»
         «ENDIF»
-        «IF child instanceof AnyXmlSchemaNode»
+        «IF child instanceof AnyxmlSchemaNode»
             «printAnyXmlNode(child)»
         «ENDIF»
         «IF child instanceof LeafSchemaNode»
@@ -433,10 +434,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)
         }
     }
@@ -472,7 +473,7 @@ class GeneratorImpl {
         '''
     }
 
-    private def printAnyXmlNode(AnyXmlSchemaNode anyXmlNode) {
+    private def printAnyXmlNode(AnyxmlSchemaNode anyXmlNode) {
         return
         '''
             &lt;«anyXmlNode.QName.localName»&gt;. . .&lt;/«anyXmlNode.QName.localName»&gt;
@@ -486,7 +487,7 @@ class GeneratorImpl {
         '''
     }
 
-    private def augmentationsSummary(Module module, SchemaContext context) {
+    private def augmentationsSummary(Module module, EffectiveModelContext context) {
         if (module.augmentations.empty) {
             return '';
         }
@@ -513,7 +514,7 @@ class GeneratorImpl {
     }
 
     def notifications(Module module) {
-        val Set<NotificationDefinition> notificationdefs = module.notifications
+        val Collection<? extends NotificationDefinition> notificationdefs = module.notifications
         if (notificationdefs.empty) {
             return '';
         }
@@ -763,12 +764,12 @@ class GeneratorImpl {
         «module.childNodes.treeSet(YangInstanceIdentifier.builder.build())»
     '''
 
-    private def dispatch CharSequence tree(ChoiceSchemaNode node,YangInstanceIdentifier path) '''
+    private def 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>
@@ -779,17 +780,24 @@ class GeneratorImpl {
         </ul>
     '''
 
-    private def dispatch CharSequence tree(DataSchemaNode node,YangInstanceIdentifier path) '''
-        «node.nodeName»
-    '''
+    private def CharSequence tree(DataSchemaNode node, YangInstanceIdentifier path) {
+        if (node instanceof ChoiceSchemaNode) {
+            return tree(node, path)
+        } else if (node instanceof ListSchemaNode) {
+            return tree(node, path)
+        } else if (node instanceof ContainerSchemaNode) {
+            return tree(node, path)
+        }
+        return node.nodeName
+    }
 
-    private def dispatch CharSequence tree(ListSchemaNode node,YangInstanceIdentifier path) '''
+    private def CharSequence tree(ListSchemaNode node, YangInstanceIdentifier path) '''
         «val newPath = path.append(node)»
         «localLink(newPath,node.nodeName)»
         «node.childNodes.treeSet(newPath)»
     '''
 
-    private def dispatch CharSequence tree(ContainerSchemaNode node,YangInstanceIdentifier path) '''
+    private def CharSequence tree(ContainerSchemaNode node,YangInstanceIdentifier path) '''
         «val newPath = path.append(node)»
         «localLink(newPath,node.nodeName)»
         «node.childNodes.treeSet(newPath)»
@@ -816,8 +824,7 @@ class GeneratorImpl {
                 «ENDFOR»
                 </ul>
                 <ul>
-                «val Set<TypeDefinition<?>> typeDefinitions = dataNode.typeDefinitions»
-                «FOR typeDef : typeDefinitions»
+                «FOR typeDef : dataNode.typeDefinitions»
                     «typeDef.restrictions»
                 «ENDFOR»
                 </ul>
@@ -838,7 +845,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>'''
@@ -862,7 +869,9 @@ class GeneratorImpl {
         } else if(node instanceof LeafListSchemaNode) {
             return '''
                 «printInfo(node, "leaf-list")»
-                «listItem("type", node.type?.QName.localName)»
+                «IF node.type !== null»
+                    «listItem("type", node.type.QName.localName)»
+                «ENDIF»
                 </ul>
             '''
         } else if(node instanceof ListSchemaNode) {
@@ -877,7 +886,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>
@@ -892,7 +901,7 @@ class GeneratorImpl {
                 «printInfo(node, "container")»
                 </ul>
             '''
-        } else if(node instanceof AnyXmlSchemaNode) {
+        } else if(node instanceof AnyxmlSchemaNode) {
             return '''
                 «printInfo(node, "anyxml")»
                 </ul>
@@ -933,7 +942,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>
@@ -943,7 +952,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>
         '''
@@ -955,8 +964,8 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, YangInstanceIdentifier path) {
-        val anyxmlNodes = nodes.filter(AnyXmlSchemaNode)
+    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)
         val choices = nodes.filter(ChoiceSchemaNode)
@@ -1005,13 +1014,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» -->
@@ -1020,32 +1029,31 @@ class GeneratorImpl {
 
     '''
 
-    private def dispatch CharSequence asXmlExampleTag(LeafSchemaNode node, YangInstanceIdentifier identifier) '''
-        «node.QName.xmlExampleTag("...")»
-    '''
-
-    private def dispatch CharSequence asXmlExampleTag(LeafListSchemaNode node, YangInstanceIdentifier identifier) '''
-        &lt!-- This node could appear multiple times --&gt
-        «node.QName.xmlExampleTag("...")»
-    '''
-
-    private def dispatch CharSequence asXmlExampleTag(ContainerSchemaNode node, YangInstanceIdentifier identifier) '''
-        &lt!-- See «localLink(identifier.append(node),"definition")» for child nodes.  --&gt
-        «node.QName.xmlExampleTag("...")»
-    '''
-
-
-    private def dispatch CharSequence asXmlExampleTag(ListSchemaNode node, YangInstanceIdentifier identifier) '''
-        &lt!-- See «localLink(identifier.append(node),"definition")» for child nodes.  --&gt
-        &lt!-- This node could appear multiple times --&gt
-        «node.QName.xmlExampleTag("...")»
-    '''
-
-
-    private def dispatch CharSequence asXmlExampleTag(DataSchemaNode node, YangInstanceIdentifier identifier) '''
-        <!-- noop -->
-    '''
-
+    private def CharSequence asXmlExampleTag(DataSchemaNode node, YangInstanceIdentifier identifier) {
+        if (node instanceof LeafSchemaNode) {
+            return '''«node.QName.xmlExampleTag("...")»'''
+        }
+        if (node instanceof LeafListSchemaNode) {
+            return '''
+            &lt!-- This node could appear multiple times --&gt
+            «node.QName.xmlExampleTag("...")»
+            '''
+        }
+        if (node instanceof ContainerSchemaNode) {
+            return '''
+            &lt!-- See «localLink(identifier.append(node),"definition")» for child nodes.  --&gt
+            «node.QName.xmlExampleTag("...")»
+            '''
+        }
+        if (node instanceof ListSchemaNode) {
+            return '''
+            &lt!-- See «localLink(identifier.append(node),"definition")» for child nodes.  --&gt
+            &lt!-- This node could appear multiple times --&gt
+            «node.QName.xmlExampleTag("...")»
+            '''
+        }
+        return "<!-- noop -->"
+    }
 
     def xmlExampleTag(QName name, CharSequence data) {
         return '''&lt;«name.localName» xmlns="«name.namespace»"&gt;«data»&lt;/«name.localName»&gt;'''
@@ -1060,13 +1068,7 @@ class GeneratorImpl {
         </h«level»>
     '''
 
-
-
-    private def dispatch CharSequence printInfo(DataSchemaNode node, int level, YangInstanceIdentifier path) '''
-        «header(level+1,node.QName)»
-    '''
-
-    private def dispatch CharSequence printInfo(ContainerSchemaNode node, int level, YangInstanceIdentifier path) '''
+    private def CharSequence printInfo(ContainerSchemaNode node, int level, YangInstanceIdentifier path) '''
         «val newPath = path.append(node)»
         «header(level,newPath)»
         <dl>
@@ -1078,7 +1080,7 @@ class GeneratorImpl {
         «node.childNodes.printChildren(level,newPath)»
     '''
 
-    private def dispatch CharSequence printInfo(ListSchemaNode node, int level, YangInstanceIdentifier path) '''
+    private def CharSequence printInfo(ListSchemaNode node, int level, YangInstanceIdentifier path) '''
         «val newPath = path.append(node)»
         «header(level,newPath)»
         <dl>
@@ -1090,12 +1092,12 @@ class GeneratorImpl {
         «node.childNodes.printChildren(level,newPath)»
     '''
 
-    private def dispatch CharSequence printInfo(ChoiceSchemaNode node, int level, YangInstanceIdentifier path) '''
-        «val Set<DataSchemaNode> choiceCases = new HashSet(node.cases.values
+    private def CharSequence printInfo(ChoiceSchemaNode node, int level, YangInstanceIdentifier path) '''
+        «val Set<DataSchemaNode> choiceCases = new HashSet(node.cases)»
         «choiceCases.printChildren(level, path)»
     '''
 
-    private def dispatch CharSequence printInfo(CaseSchemaNode node, int level, YangInstanceIdentifier path) '''
+    private def CharSequence printInfo(CaseSchemaNode node, int level, YangInstanceIdentifier path) '''
         «node.childNodes.printChildren(level, path)»
     '''
 
@@ -1123,7 +1125,7 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printShortInfo(AnyXmlSchemaNode node, int level, YangInstanceIdentifier path) {
+    def CharSequence printShortInfo(AnyxmlSchemaNode node, int level, YangInstanceIdentifier path) {
         return '''
             <li>«strong((node.QName.localName))» (anyxml)
             <ul>
@@ -1178,7 +1180,7 @@ class GeneratorImpl {
             }
         }
 
-        return identifier.node(new NodeIdentifierWithPredicates(node.QName, keyValues));
+        return identifier.node(NodeIdentifierWithPredicates.of(node.QName, keyValues));
     }
 
 
@@ -1196,7 +1198,7 @@ class GeneratorImpl {
             append(arg.nodeType.localName);
             previous = true;
             if(arg instanceof NodeIdentifierWithPredicates) {
-                for(qname : arg.getKeyValues.keySet) {
+                for(qname : arg.keySet) {
                     append("/{");
                     append(qname.localName)
                     append('}')
@@ -1207,10 +1209,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('/')
         }
 
@@ -1219,7 +1222,7 @@ class GeneratorImpl {
 
         for (name : path) {
             if (parent instanceof DataNodeContainer) {
-                var SchemaNode node = parent.getDataChildByName(name)
+                var SchemaNode node = parent.dataChildByName(name)
                 if (node === null && (parent instanceof Module)) {
                     val notifications = (parent as Module).notifications;
                     for (notification : notifications) {
@@ -1277,7 +1280,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»
@@ -1300,10 +1303,6 @@ class GeneratorImpl {
         </ul>
     '''
 
-    private def dispatch CharSequence tree(Void obj, YangInstanceIdentifier path) '''
-    '''
-
-
 
     /* #################### RESTRICTIONS #################### */
     private def restrictions(TypeDefinition<?> type) '''
@@ -1312,54 +1311,16 @@ class GeneratorImpl {
         «type.toRange»
     '''
 
-    private def dispatch toLength(TypeDefinition<?> type) {
-    }
-
-    private def dispatch toLength(BinaryTypeDefinition type) '''
-        «type.lengthConstraint.toLengthStmt»
-    '''
-
-    private def dispatch toLength(StringTypeDefinition type) '''
-        «type.lengthConstraint.toLengthStmt»
-    '''
-
-    private def dispatch toRange(TypeDefinition<?> type) {
-    }
-
-    private def dispatch toRange(DecimalTypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Int8TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Int16TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Int32TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Int64TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Uint8TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Uint16TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
-    '''
-
-    private def dispatch toRange(Uint32TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
+    private def toLength(TypeDefinition<?> type) '''
+        «IF type instanceof LengthRestrictedTypeDefinition»
+            «type.lengthConstraint.toLengthStmt»
+        «ENDIF»
     '''
 
-    private def dispatch toRange(Uint64TypeDefinition type) '''
-        «type.rangeConstraint.toRangeStmt»
+    private def toRange(TypeDefinition<?> type) '''
+        «IF type instanceof RangeRestrictedTypeDefinition»
+            «type.rangeConstraint.toRangeStmt»
+        «ENDIF»
     '''
 
     def toLengthStmt(Optional<LengthConstraint> lengths) '''
@@ -1448,7 +1409,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)
@@ -1465,34 +1426,38 @@ class GeneratorImpl {
         return result.toString
     }
 
-    private def dispatch addedByInfo(SchemaNode node) '''
-    '''
+    private def addedByInfo(SchemaNode node) {
+        if (node instanceof DataSchemaNode) {
+            return addedByInfo(node)
+        }
+        return ""
+    }
 
-    private def dispatch addedByInfo(DataSchemaNode node) '''
+    private def addedByInfo(DataSchemaNode node) '''
         «IF node.augmenting»(A)«ENDIF»«IF node.addedByUses»(U)«ENDIF»
     '''
 
-    private def dispatch isAddedBy(SchemaNode node) {
-        return false;
+    private def isAddedBy(SchemaNode node) {
+        if (node instanceof DataSchemaNode) {
+            return node.augmenting || node.addedByUses
+        }
+        return false
     }
 
-    private def dispatch isAddedBy(DataSchemaNode node) {
-        if (node.augmenting || node.addedByUses) {
-            return true
-        } else {
-            return false;
+    private def nodeName(SchemaNode node) {
+        if (node instanceof ContainerSchemaNode) {
+            return nodeName(node);
+        } else if (node instanceof ListSchemaNode) {
+            return nodeName(node);
         }
+        val addedByInfo = node.addedByInfo
+        if (node.isAddedBy) {
+            return '''«italic(node.QName.localName)»«addedByInfo»'''
+        }
+        return '''«node.QName.localName»«addedByInfo»'''
     }
 
-    private def dispatch nodeName(SchemaNode node) '''
-        «IF node.isAddedBy»
-            «italic(node.QName.localName)»«node.addedByInfo»
-        «ELSE»
-            «node.QName.localName»«node.addedByInfo»
-        «ENDIF»
-    '''
-
-    private def dispatch nodeName(ContainerSchemaNode node) '''
+    private def nodeName(ContainerSchemaNode node) '''
         «IF node.isAddedBy»
             «strong(italic(node.QName.localName))»«node.addedByInfo»
         «ELSE»
@@ -1500,7 +1465,7 @@ class GeneratorImpl {
         «ENDIF»
     '''
 
-    private def dispatch nodeName(ListSchemaNode node) '''
+    private def nodeName(ListSchemaNode node) '''
         «IF node.isAddedBy»
             «strong(italic(node.QName.localName))» «IF node.keyDefinition !== null && !node.keyDefinition.empty»«node.listKeys»«ENDIF»«node.addedByInfo»
         «ELSE»