*/
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 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
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
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();
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)]
return destination;
}
- def generate(Module module, SchemaContext ctx) '''
+ def generate(Module module, EffectiveModelContext ctx) '''
<!DOCTYPE html>
<html lang="en">
<head>
</html>
'''
- def body(Module module, SchemaContext ctx) '''
+ def body(Module module, EffectiveModelContext ctx) '''
«header(module)»
«typeDefinitionsSummary(module)»
private def typeDefinitionsSummary(Module module) {
- val Set<TypeDefinition<?>> typedefs = module.typeDefinitions
+ val Collection<? extends TypeDefinition<?>> typedefs = module.typeDefinitions
if (typedefs.empty) {
return '';
}
}
def typeDefinitions(Module module) {
- val Set<TypeDefinition<?>> typedefs = module.typeDefinitions
+ val Collection<? extends TypeDefinition<?>> typedefs = module.typeDefinitions
if (typedefs.empty) {
return '';
}
'''
}
- def augmentations(Module module, SchemaContext context) {
+ def augmentations(Module module, EffectiveModelContext context) {
if (module.augmentations.empty) {
return '';
}
«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»
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)
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;
}
}
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)
}
}
'''
}
- private def augmentationsSummary(Module module, SchemaContext context) {
+ private def augmentationsSummary(Module module, EffectiveModelContext context) {
if (module.augmentations.empty) {
return '';
}
}
def notifications(Module module) {
- val Set<NotificationDefinition> notificationdefs = module.notifications
+ val Collection<? extends NotificationDefinition> notificationdefs = module.notifications
if (notificationdefs.empty) {
return '';
}
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>
«ENDFOR»
</ul>
<ul>
- «val Set<TypeDefinition<?>> typeDefinitions = dataNode.typeDefinitions»
- «FOR typeDef : typeDefinitions»
+ «FOR typeDef : dataNode.typeDefinitions»
«typeDef.restrictions»
«ENDFOR»
</ul>
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>'''
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>
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>
</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>
'''
'''
}
- 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)
'''
}
- 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» -->
'''
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)»
'''
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('/')
}
«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»
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)
'''
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) '''