Search in sources :

Example 1 with DocumentedNode

use of org.opendaylight.yangtools.yang.model.api.DocumentedNode in project mdsal by opendaylight.

the class JavaFileTemplate method appendSnippet.

static void appendSnippet(final StringBuilder sb, final GeneratedType type) {
    type.getYangSourceDefinition().ifPresent(def -> {
        sb.append('\n');
        if (def instanceof Single) {
            final DocumentedNode node = ((Single) def).getNode();
            sb.append("<p>\n").append("This class represents the following YANG schema fragment defined in module <b>").append(def.getModule().argument().getLocalName()).append("</b>\n").append("<pre>\n");
            appendYangSnippet(sb, def.getModule(), ((EffectiveStatement<?, ?>) node).getDeclared());
            sb.append("</pre>");
            if (node instanceof SchemaNode) {
                final SchemaNode schema = (SchemaNode) node;
                if (hasBuilderClass(schema)) {
                    final String builderName = type.getName() + BindingMapping.BUILDER_SUFFIX;
                    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) {
                        final var keyDef = ((ListSchemaNode) node).getKeyDefinition();
                        if (!keyDef.isEmpty()) {
                            sb.append("@see ").append(type.getName()).append(BindingMapping.KEY_SUFFIX);
                        }
                        sb.append('\n');
                    }
                }
            }
        } else if (def instanceof Multiple) {
            sb.append("<pre>\n");
            for (SchemaNode node : ((Multiple) def).getNodes()) {
                appendYangSnippet(sb, def.getModule(), ((EffectiveStatement<?, ?>) node).getDeclared());
            }
            sb.append("</pre>\n");
        }
    });
}
Also used : ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) Multiple(org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Multiple) Single(org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Single) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) EffectiveStatement(org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement) DocumentedNode(org.opendaylight.yangtools.yang.model.api.DocumentedNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode)

Aggregations

Multiple (org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Multiple)1 Single (org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Single)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 DocumentedNode (org.opendaylight.yangtools.yang.model.api.DocumentedNode)1 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)1 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)1 EffectiveStatement (org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement)1 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)1