/*
- * Copyright (c) 2018 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
/**
* DTO capturing the YANG source definition which lead to a {@link GeneratedType} being emitted.
public static final class Multiple extends YangSourceDefinition {
private final List<? extends SchemaNode> nodes;
- Multiple(final Module module, final Collection<? extends SchemaNode> nodes) {
+ Multiple(final ModuleEffectiveStatement module, final Collection<? extends SchemaNode> nodes) {
super(module);
this.nodes = ImmutableList.copyOf(nodes);
}
/**
- * Return the defining SchemaNodes.
+ * Return the defining SchemaNodes. Each node is guaranteed to implement {@link EffectiveStatement} and have
+ * a corresponding declared statement.
*
* @return defining SchemaNodes, guaranteed to be non-empty
*/
public List<? extends SchemaNode> getNodes() {
- return nodes;
+ return nodes.stream().filter(node -> {
+ return node instanceof EffectiveStatement && ((EffectiveStatement<?, ?>) node).getDeclared() != null;
+ }).collect(Collectors.toList());
}
}
public static final class Single extends YangSourceDefinition {
private final DocumentedNode node;
- Single(final Module module, final DocumentedNode node) {
+ Single(final ModuleEffectiveStatement module, final DocumentedNode node) {
super(module);
this.node = requireNonNull(node);
}
+ /**
+ * Return the defining DocumentedNode. The node is guaranteed to implement {@link EffectiveStatement} and have
+ * a corresponding declared statement.
+ *
+ * @return defining SchemaNodes, guaranteed to be non-empty
+ */
public DocumentedNode getNode() {
return node;
}
}
- private final Module module;
+ private final ModuleEffectiveStatement module;
- private YangSourceDefinition(final Module module) {
+ private YangSourceDefinition(final ModuleEffectiveStatement module) {
this.module = requireNonNull(module);
}
- public static YangSourceDefinition of(final Module module) {
- return new Single(module, module);
+ public static Optional<YangSourceDefinition> of(final Module module) {
+ if (module instanceof ModuleEffectiveStatement) {
+ final ModuleEffectiveStatement effective = (ModuleEffectiveStatement) module;
+ final ModuleStatement declared = effective.getDeclared();
+ if (declared != null) {
+ return Optional.of(new Single(effective, module));
+ }
+ }
+ return Optional.empty();
}
- public static YangSourceDefinition of(final Module module, final SchemaNode node) {
- return new Single(module, node);
+ public static Optional<YangSourceDefinition> of(final Module module, final SchemaNode node) {
+ if (module instanceof ModuleEffectiveStatement) {
+ final ModuleEffectiveStatement effective = (ModuleEffectiveStatement) module;
+ if (node instanceof EffectiveStatement) {
+ final DeclaredStatement<?> declared = ((EffectiveStatement<?, ?>) node).getDeclared();
+ if (declared != null) {
+ return Optional.of(new Single(effective, node));
+ }
+ }
+ }
+ return Optional.empty();
}
- public static YangSourceDefinition of(final Module module, final Collection<? extends SchemaNode> nodes) {
+ public static Optional<YangSourceDefinition> of(final Module module, final Collection<? extends SchemaNode> nodes) {
checkArgument(!nodes.isEmpty());
- return new Multiple(module, nodes);
+
+ if (module instanceof ModuleEffectiveStatement) {
+ final ModuleEffectiveStatement effective = (ModuleEffectiveStatement) module;
+ final boolean anyDeclared = nodes.stream().anyMatch(node -> {
+ return node instanceof EffectiveStatement && ((EffectiveStatement<?, ?>) node).getDeclared() != null;
+ });
+ if (anyDeclared) {
+ return Optional.of(new Multiple(effective, nodes));
+ }
+ }
+ return Optional.empty();
}
/**
*
* @return Defining YANG module.
*/
- public final Module getModule() {
+ public final ModuleEffectiveStatement getModule() {
return module;
}
}
final GeneratedTOBuilderImpl returnType = (GeneratedTOBuilderImpl) genTOBuilder;
if (verboseClassComments) {
- returnType.setYangSourceDefinition(YangSourceDefinition.of(parentModule, typeDef));
+ YangSourceDefinition.of(parentModule, typeDef).ifPresent(returnType::setYangSourceDefinition);
TypeComments.description(typeDef).ifPresent(returnType::addComment);
typeDef.getDescription().ifPresent(returnType::setDescription);
typeDef.getReference().ifPresent(returnType::setReference);
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.NOTIFICATION;
import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.parameterizedTypeFor;
import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.wildcardTypeFor;
-import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.opendaylight.mdsal.binding.javav2.generator.util.TypeComments;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl;
-import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
import org.opendaylight.mdsal.binding.javav2.generator.yang.types.GroupingDefinitionDependencySort;
import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
moduleDataTypeBuilder.addImplementsType(BindingTypes.TREE_ROOT);
if (verboseClassComments) {
- moduleDataTypeBuilder.setYangSourceDefinition(YangSourceDefinition.of(module));
+ YangSourceDefinition.of(module).ifPresent(moduleDataTypeBuilder::setYangSourceDefinition);
TypeComments.description(module).ifPresent(moduleDataTypeBuilder::addComment);
module.getDescription().ifPresent(moduleDataTypeBuilder::setDescription);
module.getReference().ifPresent(moduleDataTypeBuilder::setReference);
final GeneratedTypeBuilderImpl moduleBuilder = new GeneratedTypeBuilderImpl(packageName, moduleName, context);
if (verboseClassComments) {
- moduleBuilder.setYangSourceDefinition(YangSourceDefinition.of(module));
+ YangSourceDefinition.of(module).ifPresent(moduleBuilder::setYangSourceDefinition);
TypeComments.description(module).ifPresent(moduleBuilder::addComment);
module.getDescription().ifPresent(moduleBuilder::setDescription);
module.getReference().ifPresent(moduleBuilder::setReference);
final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
qNameConstant(newType, BindingMapping.QNAME_STATIC_FIELD_NAME, schemaNode.getQName());
if (verboseClassComments) {
- newType.setYangSourceDefinition(YangSourceDefinition.of(module, schemaNode));
+ YangSourceDefinition.of(module, schemaNode).ifPresent(newType::setYangSourceDefinition);
TypeComments.description(schemaNode).ifPresent(newType::addComment);
schemaNode.getDescription().ifPresent(newType::setDescription);
schemaNode.getReference().ifPresent(newType::setReference);
annotateDeprecatedIfNecessary(node.getStatus(), genType);
genType.setModuleName(module.getName());
if (verboseClassComments) {
- genType.setYangSourceDefinition(YangSourceDefinition.of(module, node));
+ YangSourceDefinition.of(module, node).ifPresent(genType::setYangSourceDefinition);
TypeComments.description(node).ifPresent(genType::addComment);
node.getDescription().ifPresent(genType::setDescription);
node.getReference().ifPresent(genType::setReference);
}
if (verboseClassComments) {
- newType.setYangSourceDefinition(YangSourceDefinition.of(module));
+ YangSourceDefinition.of(module).ifPresent(newType::setYangSourceDefinition);
TypeComments.description(module).ifPresent(newType::addComment);
module.getDescription().ifPresent(newType::setDescription);
module.getReference().ifPresent(newType::setReference);
if (verboseClassComments) {
if (tiedNotifications != null) {
- listenerInterface.setYangSourceDefinition(YangSourceDefinition.of(module,
+ YangSourceDefinition.of(module,
ImmutableSet.<NotificationDefinition>builder().addAll(notifications).addAll(tiedNotifications)
- .build()));
+ .build()).ifPresent(listenerInterface::setYangSourceDefinition);
} else {
- listenerInterface.setYangSourceDefinition(YangSourceDefinition.of(module, notifications));
+ YangSourceDefinition.of(module, notifications).ifPresent(listenerInterface::setYangSourceDefinition);
}
listenerInterface.addComment(TypeComments.javadoc(
"Interface for receiving the following YANG notifications defined in module <b>" + module.getName()
interfaceBuilder.addComment(TypeComments.javadoc(
"Interface for implementing the following YANG Operation defined in module <b>" + module.getName() + "</b>")
.get());
- interfaceBuilder.setYangSourceDefinition(YangSourceDefinition.of(module, operation));
+ YangSourceDefinition.of(module, operation).ifPresent(interfaceBuilder::setYangSourceDefinition);
}
final String operationComment = encodeAngleBrackets(operation.getDescription().orElse(null));
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
-import org.opendaylight.mdsal.binding.javav2.generator.util.YangSnippetCleaner;
-import org.opendaylight.mdsal.binding.javav2.java.api.yang.txt.yangTemplateForModule;
-import org.opendaylight.mdsal.binding.javav2.java.api.yang.txt.yangTemplateForNode;
-import org.opendaylight.mdsal.binding.javav2.java.api.yang.txt.yangTemplateForNodes;
import org.opendaylight.mdsal.binding.javav2.model.api.AccessModifier;
import org.opendaylight.mdsal.binding.javav2.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedProperty;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.export.DeclaredStatementFormatter;
public final class TextTemplateUtil {
public static final String DOT = ".";
- public static final String PATTERN_CONSTANT_NAME = "PATTERN_CONSTANTS";
private static final char NEW_LINE = '\n';
private static final String UNDERSCORE = "_";
private static final Pattern TAIL_COMMENT_PATTERN = Pattern.compile("*/", Pattern.LITERAL);
private static final Pattern MULTIPLE_SPACES_PATTERN = Pattern.compile(" +");
+ private static DeclaredStatementFormatter YANG_FORMATTER = DeclaredStatementFormatter.builder()
+ .addIgnoredStatement(YangStmtMapping.CONTACT)
+ .addIgnoredStatement(YangStmtMapping.DESCRIPTION)
+ .addIgnoredStatement(YangStmtMapping.REFERENCE)
+ .addIgnoredStatement(YangStmtMapping.ORGANIZATION)
+ .build();
+
private TextTemplateUtil() {
throw new UnsupportedOperationException("Util class");
}
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().getName()).append("</b>\n")
- .append("<pre>\n")
- .append(encodeAngleBrackets(encodeJavadocSymbols(
- YangSnippetCleaner.clean(generateYangSnippet(node, def.getModule())))))
- .append("</pre>");
+ .append(def.getModule().argument()).append("</b>\n")
+ .append("<pre>\n");
+ appendYangSnippet(sb, def.getModule(), ((EffectiveStatement<?, ?>) node).getDeclared());
+ sb.append("</pre>");
if (node instanceof SchemaNode) {
sb.append("The schema path to identify an instance is\n")
.append("<i>")
- .append(formatSchemaPath(def.getModule().getName(), ((SchemaNode) node).getPath().getPathFromRoot()))
+ .append(formatSchemaPath(def.getModule().argument(), ((SchemaNode) node).getPath().getPathFromRoot()))
.append("</i>\n");
if (hasBuilderClass(type)) {
}
} else if (def instanceof Multiple) {
sb.append("<pre>\n");
- sb.append(encodeAngleBrackets(encodeJavadocSymbols(
- YangSnippetCleaner.clean(generateYangSnippet(((Multiple) def).getNodes(), def.getModule())))));
+ for (SchemaNode node : ((Multiple) def).getNodes()) {
+ appendYangSnippet(sb, def.getModule(), ((EffectiveStatement<?, ?>) node).getDeclared());
+ }
sb.append("</pre>\n");
}
}
}
- /**
- * Generate a YANG snippet for specified SchemaNode.
- *
- * @param node node for which to generate a snippet
- * @return YANG snippet
- */
- private static String generateYangSnippet(final DocumentedNode node, final Module module) {
- if (node instanceof Module) {
- return yangTemplateForModule.render((Module) node).body();
- } else if (node instanceof SchemaNode) {
- return yangTemplateForNode.render((SchemaNode) node, module).body();
+ private static void appendYangSnippet(StringBuilder sb, ModuleEffectiveStatement module,
+ DeclaredStatement<?> stmt) {
+ for (String str : YANG_FORMATTER.toYangTextSnippet(module, stmt)) {
+ sb.append(encodeAngleBrackets(encodeJavadocSymbols(str)));
}
-
- throw new IllegalArgumentException("Not supported.");
- }
-
- private static String generateYangSnippet(final Collection<? extends SchemaNode> nodes, final Module module) {
- return yangTemplateForNodes.render(nodes, module).body();
}
public static boolean hasBuilderClass(final GeneratedType type) {
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.mdsal.binding.javav2.generator.util.FormattingUtils
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.DocumentedNode
-@import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement
-@import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement
-
-@(module: Module)
-@if(module != null) {
- @generateYangSnippet(module)
-}
-
-@generateYangSnippet(module: Module) = {
- module @{module.getName()} {
- yang-version @module.getYangVersion();
- namespace "@module.getNamespace().toString()";
- prefix "@module.getPrefix()";
-
- @if(module.getImports() != null && !module.getImports().isEmpty()) {
- @for(moduleImport <- module.getImports()) {
- @if(moduleImport != null && moduleImport.getModuleName() != "") {
- import @{moduleImport.getModuleName()} {
- prefix "@{moduleImport.getPrefix()}";
- @if(moduleImport.getRevision().isPresent()) {
- revision-date @{moduleImport.getRevision().get().toString()};
- }
- }
- }
- }
- }
- @if(module.getRevision().isPresent()) {
- @for(effectiveStatement <- module.asInstanceOf[EffectiveStatement[_, _]].effectiveSubstatements()){
- @if(effectiveStatement.getDeclared().isInstanceOf[RevisionStatement]){
- @if(effectiveStatement.asInstanceOf[DocumentedNode].getDescription().isPresent()){
- revision @{module.getRevision().get().toString()} {
- description "@{effectiveStatement.asInstanceOf[DocumentedNode].getDescription().get()}";
- }
- } else {
- revision @{module.getRevision().get().toString()};
- }
- }
- }
- }
- @if(module.getTypeDefinitions() != null && !module.getTypeDefinitions().isEmpty()){
- @yangTemplateWriteTypeDefs(module.getTypeDefinitions())
- }
- @if(module.getChildNodes() != null) {
- @yangTemplateWriteDataSchemaNodes(module.getChildNodes(), module)
- }
- @if(module.getGroupings() != null && !module.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(module.getGroupings(), module)
- }
- @if(module.getAugmentations() != null && !module.getAugmentations().isEmpty()) {
- @yangTemplateWriteAugments(module.getAugmentations(), module)
- }
- @if(module.getDeviations() != null && !module.getDeviations().isEmpty()) {
- @yangTemplateWriteDeviations(module.getDeviations())
- }
- @if(module.getExtensionSchemaNodes() != null && !module.getExtensionSchemaNodes().isEmpty()) {
- @for(extension <- module.getExtensionSchemaNodes()) {
- @if(extension != null) {
- @yangTemplateWriteExtension(extension)
- }
- }
- }
- @if(module.getFeatures() != null && !module.getFeatures().isEmpty()) {
- @for(feature <- module.getFeatures()) {
- @if(feature != null) {
- @yangTemplateWriteFeature(feature)
- }
- }
- }
- @if(module.getIdentities() != null && !module.getIdentities().isEmpty()) {
- @for(identity <- module.getIdentities()) {
- @if(identity != null) {
- @yangTemplateWriteIdentity(identity)
- }
- }
- }
- @if(module.getNotifications() != null && !module.getNotifications().isEmpty()) {
- @for(notification <- module.getNotifications()) {
- @if(notification != null) {
- @yangTemplateWriteNotification(notification, module)
- }
- }
- }
- @if(module.getRpcs() != null && !module.getRpcs().isEmpty()) {
- @for(rpc <- module.getRpcs()) {
- @if(rpc != null) {
- @yangTemplateWriteRPC(rpc, module)
- }
- }
- }
- @if(module.getUnknownSchemaNodes() != null && !module.getUnknownSchemaNodes().isEmpty()) {
- @yangTemplateWriteUnknownSchemaNodes(module.getUnknownSchemaNodes(), module)
- }
- @if(module.getUses() != null && !module.getUses().isEmpty()) {
- @yangTemplateWriteUsesNodes(module.getUses(), module)
- }
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition
-@import org.opendaylight.yangtools.yang.model.api.FeatureDefinition
-@import org.opendaylight.yangtools.yang.model.api.GroupingDefinition
-@import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
-@import org.opendaylight.yangtools.yang.model.api.RpcDefinition
-@import org.opendaylight.yangtools.yang.model.api.SchemaNode
-@import org.opendaylight.yangtools.yang.model.api.TypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Status
-@import org.opendaylight.yangtools.yang.model.api.`type`.EnumTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.EnumTypeDefinition.EnumPair
-
-@(node: SchemaNode, module: Module)
-@if(node != null) {
- @generateYangSnippet(node, module)
-}
-
-@generateYangSnippet(node: SchemaNode, module: Module) = {
- @if(node.isInstanceOf[DataSchemaNode]) {
- @yangTemplateWriteDataSchemaNode(node.asInstanceOf[DataSchemaNode], module)
- }
- @if(node.isInstanceOf[EnumTypeDefinition.EnumPair]) {
- enum @{node.asInstanceOf[EnumTypeDefinition.EnumPair].getName()} {
- @if(node.asInstanceOf[EnumTypeDefinition.EnumPair].getValue() != null) {
- value @{node.asInstanceOf[EnumTypeDefinition.EnumPair].getValue()};
- } else {
- ;
- }
- }
- }
- @if(node.isInstanceOf[ExtensionDefinition]) {
- @yangTemplateWriteExtension(node.asInstanceOf[ExtensionDefinition])
- }
- @if(node.isInstanceOf[FeatureDefinition]) {
- @yangTemplateWriteFeature(node.asInstanceOf[FeatureDefinition])
- }
- @if(node.isInstanceOf[GroupingDefinition]) {
- @yangTemplateWriteGroupingDef(node.asInstanceOf[GroupingDefinition], module)
- }
- @if(node.isInstanceOf[IdentitySchemaNode]) {
- @yangTemplateWriteIdentity(node.asInstanceOf[IdentitySchemaNode])
- }
- @if(node.isInstanceOf[NotificationDefinition]) {
- @yangTemplateWriteNotification(node.asInstanceOf[NotificationDefinition], module)
- }
- @if(node.isInstanceOf[RpcDefinition]) {
- @yangTemplateWriteRPC(node.asInstanceOf[RpcDefinition], module)
- }
- @if(node.isInstanceOf[TypeDefinition[_]]) {
- type @{node.asInstanceOf[TypeDefinition[_]].getQName().getLocalName()}
- @if(node.asInstanceOf[TypeDefinition[_]].getStatus() != Status.CURRENT) {
- status @{node.asInstanceOf[TypeDefinition[_]].getStatus()};
- } else {
- ;
- }
- }
- @if(node.isInstanceOf[UnknownSchemaNode]) {
- @yangTemplateWriteUnknownSchemaNode(node.asInstanceOf[UnknownSchemaNode], module)
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
-@import org.opendaylight.yangtools.yang.model.api.RpcDefinition
-@import org.opendaylight.yangtools.yang.model.api.SchemaNode
-
-@(nodes: Collection[_ <: SchemaNode], module: Module)
-@if(nodes != null) {
- @for(node <- nodes) {
- @if(node.isInstanceOf[NotificationDefinition]) {
- @yangTemplateWriteNotification(node.asInstanceOf[NotificationDefinition], module)
- }
- @if(node.isInstanceOf[RpcDefinition]) {
- @yangTemplateWriteRPC(node.asInstanceOf[RpcDefinition], module)
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.ActionDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(action: ActionDefinition, module: Module)
-action @{action.getQName().getLocalName()} {
- @if(action.getDescription().isPresent()) {
- "@{action.getDescription().get()}";
- }
- @if(action.getGroupings() != null && !action.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(action.getGroupings(), module)
- }
- @if(action.getInput() != null && action.getInput().getChildNodes != null && !action.getInput().getChildNodes().isEmpty()) {
- input {
- @yangTemplateWriteDataSchemaNodes(action.getInput().getChildNodes, module)
- }
- }
- @if(action.getOutput() != null && action.getOutput().getChildNodes != null && !action.getOutput().getChildNodes().isEmpty()) {
- output {
- @yangTemplateWriteDataSchemaNodes(action.getOutput().getChildNodes, module)
- }
- }
- @if(action.getReference().isPresent()) {
- reference "@{action.getReference().get()}";
- }
- @if(action.getStatus() != Status.CURRENT) {
- status @{action.getStatus()};
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.ActionDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-
-@(actionDefinitions: Collection[_ <: ActionDefinition], module: Module)
-@for(actionDefinition <- actionDefinitions) {
- @yangTemplateWriteAction(actionDefinition, module)
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.mdsal.binding.javav2.generator.util.FormattingUtils
-@import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(augments: Set[_ <: AugmentationSchemaNode], module: Module)
-@for(augment <- augments) {
- @if(augment != null) {
- augment "@{FormattingUtils.formatToAugmentPath(augment.getTargetPath().getPathFromRoot())}" {
- @if(augment.getWhenCondition() != null && !augment.getWhenCondition().toString().isEmpty()) {
- when "@augment.getWhenCondition().toString()";
- }
- @if(augment.getDescription().isPresent()) {
- description "@augment.getDescription().get()";
- }
- @if(augment.getReference().isPresent()) {
- reference "@augment.getReference().get()";
- }
- @if(augment.getStatus() != Status.CURRENT) {
- status "@augment.getStatus()";
- }
- @if(augment.getChildNodes() != null && !augment.getChildNodes().isEmpty()) {
- @yangTemplateWriteDataSchemaNodes(augment.getChildNodes(), module)
- }
- @if(augment.getUses() != null && !augment.getUses().isEmpty()) {
- @yangTemplateWriteUsesNodes(augment.getUses(), module)
- }
- @if(augment.getActions() != null && !augment.getActions().isEmpty()) {
- @yangTemplateWriteActions(augment.getActions(), module)
- }
- }
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
-@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.DataSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus
-@import org.opendaylight.yangtools.yang.model.api.ElementCountConstraintAware
-@import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.MandatoryAware
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.SchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Status
-@import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
-
-@(dataSchemaNode: DataSchemaNode, module: Module)
-@if(dataSchemaNode.isInstanceOf[ContainerSchemaNode]) {
- @container(dataSchemaNode.asInstanceOf[ContainerSchemaNode], module)
-}
-@if(dataSchemaNode.isInstanceOf[AnyXmlSchemaNode]) {
- anyxml @{dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].getQName().getLocalName()}@if(dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].getStatus() == Status.CURRENT && !dataSchemaNode.asInstanceOf[AnyXmlSchemaNode].isMandatory()){;} else { {
- @mandatory(dataSchemaNode.asInstanceOf[AnyXmlSchemaNode])
- @status(dataSchemaNode)
- }}
-}
-@if(dataSchemaNode.isInstanceOf[AnyDataSchemaNode]) {
- anydata @{dataSchemaNode.asInstanceOf[AnyDataSchemaNode].getQName().getLocalName()}@if(dataSchemaNode.asInstanceOf[AnyDataSchemaNode].getStatus() == Status.CURRENT && !dataSchemaNode.asInstanceOf[AnyDataSchemaNode].isMandatory()){;} else { {
- @mandatory(dataSchemaNode.asInstanceOf[AnyDataSchemaNode])
- @status(dataSchemaNode)
- }}
-}
-@if(dataSchemaNode.isInstanceOf[LeafSchemaNode]) {
- @if(!dataSchemaNode.asInstanceOf[LeafSchemaNode].isAddedByUses() && !dataSchemaNode.asInstanceOf[LeafSchemaNode].isAugmenting()){
- leaf @{dataSchemaNode.asInstanceOf[LeafSchemaNode].getQName().getLocalName()} {
- @if(dataSchemaNode.asInstanceOf[LeafSchemaNode].getDescription() != null){
- description "@{dataSchemaNode.asInstanceOf[LeafSchemaNode].getDescription()}";
- }
- @yangTemplateWriteType(dataSchemaNode.asInstanceOf[LeafSchemaNode].getType())
- @mandatory(dataSchemaNode.asInstanceOf[LeafSchemaNode])
- @status(dataSchemaNode)
- }
- }
-}
-@if(dataSchemaNode.isInstanceOf[LeafListSchemaNode]) {
- leaf-list @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getQName().getLocalName()} {
- @if(dataSchemaNode.asInstanceOf[LeafListSchemaNode].isUserOrdered()){
- ordered-by user;
- }
- type @{dataSchemaNode.asInstanceOf[LeafListSchemaNode].getType().getQName().getLocalName()};
- @minmaxelements(dataSchemaNode.asInstanceOf[LeafListSchemaNode])
- @status(dataSchemaNode)
- }
-}
-@if(dataSchemaNode.isInstanceOf[CaseSchemaNode]) {
- case @{dataSchemaNode.asInstanceOf[CaseSchemaNode].getQName().getLocalName()} {
- @for(childNode <- dataSchemaNode.asInstanceOf[CaseSchemaNode].getChildNodes()) {
- @yangTemplateWriteDataSchemaNode(childNode, module)
- }
- @status(dataSchemaNode)
- }
-}
-@if(dataSchemaNode.isInstanceOf[ChoiceSchemaNode]) {
- choice @{dataSchemaNode.asInstanceOf[ChoiceSchemaNode].getQName().getLocalName()} {
- @mandatory(dataSchemaNode.asInstanceOf[ChoiceSchemaNode])
- @for(childNode <- dataSchemaNode.asInstanceOf[ChoiceSchemaNode].getCases().values()) {
- @yangTemplateWriteDataSchemaNode(childNode, module)
- }
- @status(dataSchemaNode)
- }
-}
-@if(dataSchemaNode.isInstanceOf[ListSchemaNode]) {
- @list(dataSchemaNode.asInstanceOf[ListSchemaNode], module)
-}
-
-@mandatory(aware: MandatoryAware) = {
- @if(aware.isMandatory()) {
- mandatory true;
- }
-}
-
-@minmaxelements(aware: ElementCountConstraintAware) = {
- @if(aware.getElementCountConstraint().isPresent()) {
- @defining(aware.getElementCountConstraint().get()) { constraint =>
- @if(constraint.getMinElements() != null) {
- min-elements @{constraint.getMinElements()}
- }
- @if(constraint.getMaxElements() != null) {
- max-elements @{constraint.getMaxElements()}
- }
- }
- }
-}
-
-@status(aware: WithStatus) = {
- @if(aware.getStatus() != Status.CURRENT) {
- status @{aware.getStatus()};
- }
-}
-@container(container: ContainerSchemaNode, module: Module) = {
- container @{container.getQName().getLocalName()} {
- @if(container.getChildNodes() != null && !container.getChildNodes().isEmpty()) {
- @yangTemplateWriteDataSchemaNodes(container.getChildNodes(), module)
- }
- @if(container.getGroupings() != null && !container.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(container.getGroupings(), module)
- }
- @if(container.getUses() != null && !container.getUses().isEmpty()) {
- @yangTemplateWriteUsesNodes(container.getUses(), module)
- }
- @if(container.getUnknownSchemaNodes() != null && !container.getUnknownSchemaNodes().isEmpty()) {
- @yangTemplateWriteUnknownSchemaNodes(container.getUnknownSchemaNodes(), module)
- }
- @if(container.getActions() != null && !container.getActions().isEmpty()) {
- @yangTemplateWriteActions(container.getActions(), module)
- }
- @status(container)
- }
-}
-
-@list(list: ListSchemaNode, module: Module) = {
- list @{list.getQName().getLocalName()} {
- @if(list.isUserOrdered()){
- ordered-by user;
- }
- @minmaxelements(list)
- key "@for(listKey <- list.getKeyDefinition()) {@{listKey.getLocalName()} }";
- @if(!list.getUniqueConstraints().isEmpty()){
- @for(listUnique <- list.getUniqueConstraints()){
- unique "@for(tagUnique <- listUnique.getTag()) {@{tagUnique.getLastComponent.getLocalName()} }";
- }
- }
- @if(list.getChildNodes() != null && !list.getChildNodes().isEmpty()) {
- @yangTemplateWriteDataSchemaNodes(list.getChildNodes(), module)
- }
- @if(list.getAvailableAugmentations() != null && !list.getAvailableAugmentations().isEmpty()) {
- @yangTemplateWriteAugments(list.getAvailableAugmentations(), module)
- }
- @if(list.getGroupings() != null && !list.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(list.getGroupings(), module)
- }
- @if(list.getUses() != null && !list.getUses().isEmpty()) {
- @yangTemplateWriteUsesNodes(list.getUses(), module)
- }
- @if(list.getUnknownSchemaNodes() != null && !list.getUnknownSchemaNodes().isEmpty()) {
- @yangTemplateWriteUnknownSchemaNodes(list.getUnknownSchemaNodes(), module)
- }
- @if(list.getActions() != null && !list.getActions().isEmpty()) {
- @yangTemplateWriteActions(list.getActions(), module)
- }
- @status(list)
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Module
-
-@(dataSchemaNodes: Collection[_ <: DataSchemaNode], module: Module)
-@for(dataSchemaNode <- dataSchemaNodes) {
- @yangTemplateWriteDataSchemaNode(dataSchemaNode, module)
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.Deviation
-@import org.opendaylight.yangtools.yang.model.api.Status
-@import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement
-
-@(deviation: Deviation)
-deviation @{deviation.asInstanceOf[DeviationEffectiveStatement].getDeclared().rawArgument()} {
- @if(deviation.getReference().isPresent()) {
- reference "@{deviation.getReference().get()}";
- }
- @if(deviation.getDescription().isPresent()) {
- description "@{deviation.getDescription().get()}";
- }
- @for(deviate <- deviation.getDeviates()) {
- @if(deviate != null && deviate.getDeviateType() != null ) {
- @if(deviate.getDeviatedDefault() == null && !deviate.getDeviatedMandatory() && deviate.getDeviatedMaxElements()==null && deviate.getDeviatedMinElements() == null) {
- deviate @{deviate.getDeviateType().name()};
- } else {
- deviate @{deviate.getDeviateType().name().toLowerCase()} {
- @if(deviate.getDeviatedDefault() != null) {
- default "@{deviate.getDeviatedDefault()}";
- }
- @if(deviate.getDeviatedMandatory() != null && deviate.getDeviatedMandatory()) {
- mandatory true;
- }
- @if(deviate.getDeviatedMinElements() != null) {
- min-elements @{deviate.getDeviatedMinElements()};
- }
- @if(deviate.getDeviatedMaxElements() != null) {
- max-elements @{deviate.getDeviatedMaxElements()};
- }
- }
- }
- }
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.Deviation
-
-@(deviations: Collection[_ <: Deviation])
-@for(deviation <- deviations) {
- @yangTemplateWriteDeviation(deviation)
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(extension: ExtensionDefinition)
-extension @{extension.getQName().getLocalName()}@if(extension.getArgument() == null || extension.getArgument().isEmpty()){;} else { {
- @if(extension.getDescription().isPresent()) {
- description "@{extension.getDescription().get()}";
- }
- @if(extension.getArgument() != null && !extension.getArgument().isEmpty()) {
- argument @{extension.getArgument()};
- }
- @if(extension.getReference().isPresent()) {
- reference "@{extension.getReference().get()}";
- }
- @if(extension.getStatus() != Status.CURRENT) {
- status @{extension.getStatus()};
- }}
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.FeatureDefinition
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(feature: FeatureDefinition)
-feature @{feature.getQName().getLocalName()} {
- @if(feature.getDescription().isPresent()) {
- description "@{feature.getDescription().get()}";
- }
- @if(feature.getReference().isPresent()) {
- reference "@{feature.getReference().get()}";
- }
- @if(feature.getStatus() != Status.CURRENT) {
- status @{feature.getStatus()};
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.GroupingDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(groupingDef: GroupingDefinition, module: Module)
-grouping @{groupingDef.getQName().getLocalName()} {
- @if(groupingDef.getGroupings() != null && !groupingDef.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(groupingDef.getGroupings(), module)
- }
- @if(groupingDef.getChildNodes() != null && !groupingDef.getChildNodes().isEmpty()) {
- @yangTemplateWriteDataSchemaNodes(groupingDef.getChildNodes(), module)
- }
- @if(groupingDef.getStatus() != Status.CURRENT) {
- status @{groupingDef.getStatus()};
- }
- @if(groupingDef.getUnknownSchemaNodes() != null && !groupingDef.getUnknownSchemaNodes().isEmpty()) {
- @yangTemplateWriteUnknownSchemaNodes(groupingDef.getUnknownSchemaNodes(), module)
- }
- @if(groupingDef.getActions() != null && !groupingDef.getActions().isEmpty()) {
- @yangTemplateWriteActions(groupingDef.getActions(), module)
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.GroupingDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-
-@(groupingDefs: Set[_ <: GroupingDefinition], module: Module)
-@for(groupingDef <- groupingDefs) {
- @if(groupingDef != null) {
- @yangTemplateWriteGroupingDef(groupingDef, module)
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(identity: IdentitySchemaNode)
-identity @{identity.getQName().getLocalName()} {
- @for(baseIdentity <- identity.getBaseIdentities()) {
- base "(@writeIdentityNs(baseIdentity))@{baseIdentity}";
- }
- @if(identity.getDescription().isPresent()) {
- description "@{identity.getDescription().get()}";
- }
- @if(identity.getReference().isPresent()) {
- reference "@{identity.getReference().get()}";
- }
- @if(identity.getStatus() != Status.CURRENT) {
- status @{identity.getStatus()};
- }
-}
-
-@writeIdentityNs(identity: IdentitySchemaNode) = {
- @if(identity.getQName().getNamespace() != null) {
- @{identity.getQName().getNamespace()}:
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(notification: NotificationDefinition, module: Module)
-notification @{notification.getQName().getLocalName()} {
- @if(notification.getDescription().isPresent()) {
- description "@{notification.getDescription().get()}";
- }
- @if(notification.getChildNodes() != null && !notification.getChildNodes().isEmpty()) {
- @yangTemplateWriteDataSchemaNodes(notification.getChildNodes(), module)
- }
- @if(notification.getAvailableAugmentations() != null && !notification.getAvailableAugmentations().isEmpty()) {
- @yangTemplateWriteAugments(notification.getAvailableAugmentations(), module)
- }
- @if(notification.getGroupings() != null && !notification.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(notification.getGroupings(), module)
- }
- @if(notification.getUses() != null && !notification.getUses().isEmpty()) {
- @yangTemplateWriteUsesNodes(notification.getUses(), module)
- }
- @if(notification.getReference().isPresent()) {
- reference "@{notification.getReference().get()}";
- }
- @if(notification.getStatus() != Status.CURRENT) {
- status @{notification.getStatus()};
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.RpcDefinition
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.Status
-
-@(rpc: RpcDefinition, module: Module)
-rpc @{rpc.getQName().getLocalName()} {
- @if(rpc.getDescription().isPresent()) {
- "@{rpc.getDescription().get()}";
- }
- @if(rpc.getGroupings() != null && !rpc.getGroupings().isEmpty()) {
- @yangTemplateWriteGroupingDefs(rpc.getGroupings(), module)
- }
- @if(rpc.getInput() != null && rpc.getInput().getChildNodes != null && !rpc.getInput().getChildNodes().isEmpty()) {
- input {
- @yangTemplateWriteDataSchemaNodes(rpc.getInput().getChildNodes, module)
- }
- }
- @if(rpc.getOutput() != null && rpc.getOutput().getChildNodes != null && !rpc.getOutput().getChildNodes().isEmpty()) {
- output {
- @yangTemplateWriteDataSchemaNodes(rpc.getOutput().getChildNodes, module)
- }
- }
- @if(rpc.getReference().isPresent()) {
- reference "@{rpc.getReference().get()}";
- }
- @if(rpc.getStatus() != Status.CURRENT) {
- status @{rpc.getStatus()};
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.TypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.BinaryTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.BitsTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.BooleanTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.DecimalTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.EmptyTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.EnumTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.IdentityrefTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.IdentityTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.InstanceIdentifierTypeDefinition
-@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.`type`.LeafrefTypeDefinition
-@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`.UnionTypeDefinition
-@import org.opendaylight.yangtools.yang.model.api.`type`.UnknownTypeDefinition
-
-@(typeDefinition: TypeDefinition[_])
- @if(typeDefinition.getBaseType() != null) {
- @if(typeDefinition.isInstanceOf[BinaryTypeDefinition]){
- type @(typeDefinition.asInstanceOf[BinaryTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[BitsTypeDefinition]){
- type @(typeDefinition.asInstanceOf[BitsTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[BooleanTypeDefinition]){
- type @(typeDefinition.asInstanceOf[BooleanTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[DecimalTypeDefinition]){
- type @(typeDefinition.asInstanceOf[DecimalTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[EmptyTypeDefinition]){
- type @(typeDefinition.asInstanceOf[EmptyTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[EnumTypeDefinition]){
- type @(typeDefinition.asInstanceOf[EnumTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[IdentityrefTypeDefinition]){
- type @(typeDefinition.asInstanceOf[IdentityrefTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[IdentityTypeDefinition]){
- type @(typeDefinition.asInstanceOf[IdentityTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[InstanceIdentifierTypeDefinition]){
- type @(typeDefinition.asInstanceOf[InstanceIdentifierTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Int8TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Int8TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Int16TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Int16TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Int32TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Int32TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Int64TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Int64TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[LeafrefTypeDefinition]){
- type @(typeDefinition.asInstanceOf[LeafrefTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[StringTypeDefinition]){
- type @(typeDefinition.asInstanceOf[StringTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[UnionTypeDefinition]){
- type @(typeDefinition.asInstanceOf[UnionTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[UnknownTypeDefinition]){
- type @(typeDefinition.asInstanceOf[UnknownTypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Uint8TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Uint8TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Uint16TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Uint16TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Uint32TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Uint32TypeDefinition].getBaseType().getQName().getLocalName());
- }
- @if(typeDefinition.isInstanceOf[Uint64TypeDefinition]){
- type @(typeDefinition.asInstanceOf[Uint64TypeDefinition].getBaseType().getQName().getLocalName());
- }
- } else {
- type @(typeDefinition.getQName().getLocalName());
- }
-
+++ /dev/null
-@*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.TypeDefinition
-
-@(typeDefinition: TypeDefinition[_])
-typedef @(typeDefinition.getQName().getLocalName()) {
- @yangTemplateWriteType(typeDefinition)
- @if(typeDefinition.getDefaultValue() != null) {
- default "@(typeDefinition.getDefaultValue())";
- }
- @if(typeDefinition.getDescription() != null) {
- default "@(typeDefinition.getDescription())";
- }
- @if(typeDefinition.getReference() != null) {
- default "@(typeDefinition.getReference())";
- }
-}
+++ /dev/null
-@*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.TypeDefinition
-
-@(typeDefinitions: Collection[_ <: TypeDefinition[_]])
-@for(typeDefinition <- typeDefinitions) {
- @yangTemplateWriteTypeDef(typeDefinition)
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.Module;
-@import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
-
-@(unknownSchemaNode: UnknownSchemaNode, module: Module)
-@if(unknownSchemaNode != null) {
- @if(unknownSchemaNode.getExtensionDefinition().getArgument() != null && !unknownSchemaNode.getExtensionDefinition().getArgument().isEmpty()){
- @{module.getPrefix}:@{unknownSchemaNode.getNodeType().getLocalName()} "@{unknownSchemaNode.getNodeParameter()}";
- } else {
- @{module.getPrefix}:@{unknownSchemaNode.getNodeType().getLocalName()};
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.Module;
-@import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
-
-@(unknownSchemaNodes: List[_ <: UnknownSchemaNode], module: Module)
-@for(unknownSchemaNode <- unknownSchemaNodes) {
- @if(unknownSchemaNode != null) {
- @yangTemplateWriteUnknownSchemaNode(unknownSchemaNode, module)
- }
-}
\ No newline at end of file
+++ /dev/null
-@*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *@
-
-@**********************************************************
-* Twirl YangTemplate for generating yang snippets. *
-* Twirl is transformed to Scala and compiled. Then, *
-* it can be called from Java with particular input *
-* parameters to render desired output code. *
-***********************************************************@
-
-@import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
-@import org.opendaylight.yangtools.yang.model.api.Module
-@import org.opendaylight.yangtools.yang.model.api.UsesNode
-
-@(usesNodes: Set[_ <: UsesNode], module: Module)
-@if(usesNodes != null) {
- @for(usesNode <- usesNodes) {
- @if(usesNode != null) {
- uses @{usesNode.getGroupingPath().getLastComponent().getLocalName()}@if(usesNode.getRefines().isEmpty()) {;} else { {
- @for(path <- usesNode.getRefines().keySet()) {
- refine @{path.getLastComponent().getLocalName()} {
- @if(usesNode.getRefines().get(path).isInstanceOf[DataSchemaNode]) {
- @if(usesNode.getRefines().get(path).asInstanceOf[DataSchemaNode].getDescription() != null){
- description "@{usesNode.getRefines().get(path).asInstanceOf[DataSchemaNode].getDescription()}";
- }
- @yangTemplateWriteDataSchemaNode(usesNode.getRefines().get(path).asInstanceOf[DataSchemaNode], module)
- }
- }
- }
- }
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2018 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.mdsal.binding.javav2.java.api.generator;
-
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.annotations.Beta;
-import java.util.Iterator;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.javav2.generator.util.YangSnippetCleaner;
-import org.opendaylight.mdsal.binding.javav2.java.api.yang.txt.yangTemplateForModule;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-@Beta
-public class YangTemplateTest {
-
- private Set<Module> modules;
-
- @Before
- public void setup() {
- this.modules = YangParserTestUtils.parseYangResourceDirectory("/yang-template").getModules();
- }
-
- @Test
- public void printYangSnippetForModule() throws Exception{
- Iterator<Module> iterator = this.modules.iterator();
- String moduleBody = yangTemplateForModule.render(iterator.next()).body().trim();
- String cleanedModuleBody = YangSnippetCleaner.clean(moduleBody);
- assertTrue(cleanedModuleBody.contains("yang-template-import"));
- assertTrue(cleanedModuleBody.contains(" extension ext;"));
- assertTrue(cleanedModuleBody.contains(" yti:ext;"));
- assertTrue(cleanedModuleBody.contains(" yti:ext-arg \"arg\""));
-
- moduleBody = yangTemplateForModule.render(iterator.next()).body().trim();
- cleanedModuleBody = YangSnippetCleaner.clean(moduleBody);
- System.out.println(cleanedModuleBody);
- assertTrue(cleanedModuleBody.contains("module yang-template-test {"));
- assertTrue(cleanedModuleBody.contains(" import yang-template-import {"));
- assertTrue(cleanedModuleBody.contains(" prefix \"yti\";"));
- assertTrue(cleanedModuleBody.contains(" revision-date 2016-06-23;"));
- assertTrue(cleanedModuleBody.contains(" }"));
- assertTrue(cleanedModuleBody.contains(" anydata simple-anydata;"));
- assertTrue(cleanedModuleBody.contains(" container simple-container-with-action {"));
- assertTrue(cleanedModuleBody.contains(" leaf-list simple-leaf-list {"));
- assertTrue(cleanedModuleBody.contains(" leaf-list simple-leaf-list-userordered {"));
- assertTrue(cleanedModuleBody.contains(" list simple-list {"));
- assertTrue(cleanedModuleBody.contains(" key \"simple-list-leaf-1\";"));
- assertTrue(cleanedModuleBody.contains(" unique \"simple-list-leaf-2\";"));
- assertTrue(cleanedModuleBody.contains(" action act {"));
- assertTrue(cleanedModuleBody.contains(" list simple-list-more-arg-in-unique {"));
- assertTrue(cleanedModuleBody.contains(" ordered-by user;"));
- assertTrue(cleanedModuleBody.contains(" choice simple-choice {"));
- assertTrue(cleanedModuleBody.contains(" anyxml simple-anyxml;"));
- assertTrue(cleanedModuleBody.contains(" uses simple-grouping {"));
- assertTrue(cleanedModuleBody.contains(" refine simple-grouping-leaf {"));
- assertTrue(cleanedModuleBody.contains(" grouping simple-grouping {"));
- assertTrue(cleanedModuleBody.contains(" augment \"/simple-container-uses\" {"));
- assertTrue(cleanedModuleBody.contains(" extension simple-extension {"));
- assertTrue(cleanedModuleBody.contains(" feature simple-feature {"));
- assertTrue(cleanedModuleBody.contains(" identity simple-identity {"));
- assertTrue(cleanedModuleBody.contains(" notification simple-notification {"));
- assertTrue(cleanedModuleBody.contains(" rpc simple-rpc {"));
- }
-}