- def private static void appendSnippet(StringBuilder sb, GeneratedType type) {
- val optDef = type.yangSourceDefinition
- if (optDef.present) {
- val def = optDef.get
- sb.append(NEW_LINE)
-
- if (def instanceof Single) {
- val node = def.node
- sb.append("<p>\n")
- .append("This class represents the following YANG schema fragment defined in module <b>")
- .append(def.module.argument).append("</b>\n")
- .append("<pre>\n")
- appendYangSnippet(sb, def.module, (node as EffectiveStatement<?, ?>).declared)
- sb.append("</pre>")
-
- if (node instanceof SchemaNode) {
- sb.append("The schema path to identify an instance is\n")
- .append("<i>")
- .append(formatSchemaPath(def.module.argument, node.path.pathFromRoot))
- .append("</i>\n")
-
- if (hasBuilderClass(node)) {
- val builderName = type.name + "Builder";
-
- sb.append("\n<p>To create instances of this class use {@link ").append(builderName)
- .append("}.\n")
- .append("@see ").append(builderName).append('\n')
- if (node instanceof ListSchemaNode) {
- val keyDef = node.keyDefinition
- if (keyDef !== null && !keyDef.empty) {
- sb.append("@see ").append(type.name).append("Key")
- }
- sb.append('\n');
- }
- }
- }
- } else if (def instanceof Multiple) {
- sb.append("<pre>\n")
- for (SchemaNode node : def.nodes) {
- appendYangSnippet(sb, def.module, (node as EffectiveStatement<?, ?>).declared)
- }
- sb.append("</pre>\n")
- }
- }
- }
-
- def private static void appendYangSnippet(StringBuilder sb, ModuleEffectiveStatement module,
- DeclaredStatement<?> stmt) {
- for (String str : YANG_FORMATTER.toYangTextSnippet(module, stmt)) {
- sb.append(encodeAngleBrackets(encodeJavadocSymbols(str)))
- }
- }
-
- def private static boolean hasBuilderClass(SchemaNode schemaNode) {
- return schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode
- || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition;
- }
-
- def private static String formatSchemaPath(String moduleName, Iterable<QName> schemaPath) {
- val sb = new StringBuilder().append(moduleName);
-
- var currentElement = Iterables.getFirst(schemaPath, null);
- for (QName pathElement : schemaPath) {
- sb.append('/')
- if (!currentElement.namespace.equals(pathElement.namespace)) {
- currentElement = pathElement
- sb.append(pathElement)
- } else {
- sb.append(pathElement.getLocalName())
- }
- }
- return sb.toString();
- }
-
- def protected String formatDataForJavaDoc(TypeMember type, String additionalComment) {
- val StringBuilder typeDescriptionBuilder = new StringBuilder();
- if (!type.comment.nullOrEmpty) {
- typeDescriptionBuilder.append(formatToParagraph(type.comment))
- typeDescriptionBuilder.append(NEW_LINE)
- typeDescriptionBuilder.append(NEW_LINE)
- typeDescriptionBuilder.append(NEW_LINE)
- }
- typeDescriptionBuilder.append(additionalComment)
- var typeDescription = wrapToDocumentation(typeDescriptionBuilder.toString)
- return '''
- «typeDescription»
- '''.toString
- }