@* * 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.impl.util.YangTextTemplate @import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil @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()}"; revision-date @{SimpleDateFormatUtil.getRevisionFormat().format(moduleImport.getRevision())}; } } } } @if(module.getRevision() != null) { @for(effectiveStatement <- module.asInstanceOf[EffectiveStatement[_, _]].effectiveSubstatements()){ @if(effectiveStatement.getDeclared().isInstanceOf[RevisionStatement]){ @if(effectiveStatement.asInstanceOf[DocumentedNode].getDescription() == null || effectiveStatement.asInstanceOf[DocumentedNode].getDescription().isEmpty()){ revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())}; } else { revision @{SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())} { description "@{effectiveStatement.asInstanceOf[DocumentedNode].getDescription()}"; } } } } } @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) } } }