X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-generator-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fsal%2Fbinding%2Fgenerator%2Fimpl%2FYangTemplate.xtend;h=c97d4488903e5f6fac3876b13139fc8ed5e6d69c;hb=f8094ae576dda50fe5f94e2a75ded464b936ed49;hp=df1cc86b08848ddf7ee6f61c39a7ddae175a6b03;hpb=e48bd1d8063e49ea4d5604ce5dbeff9ac1de4e63;p=mdsal.git diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend index df1cc86b08..c97d448890 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend @@ -12,8 +12,7 @@ import java.util.Date import java.util.List import java.util.Map import java.util.Set -import java.util.StringTokenizer -import org.opendaylight.yangtools.yang.common.QName +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode import org.opendaylight.yangtools.yang.model.api.AugmentationSchema import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode @@ -40,20 +39,18 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode import org.opendaylight.yangtools.yang.model.api.UsesNode import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil -import com.google.common.base.CharMatcher class YangTemplate { - // FIXME: this is not thread-safe and seems to be unused! - private static var Module module = null + private static val String SKIP_PROPERTY_NAME = "mdsal.skip.verbose" - private static val CharMatcher NEWLINE_OR_TAB = CharMatcher.anyOf("\n\t") + private static val SKIP = Boolean.getBoolean(SKIP_PROPERTY_NAME); def static String generateYangSnipet(SchemaNode schemaNode) { if (schemaNode == null) return '' - + if (SKIP) + return '''(Empty due to «SKIP_PROPERTY_NAME» property = true)''' ''' «IF schemaNode instanceof DataSchemaNode» «writeDataSchemaNode(schemaNode)» @@ -87,11 +84,12 @@ class YangTemplate { «ENDIF» ''' } - + def static String generateYangSnipet(Set nodes) { if (nodes.nullOrEmpty) return '' - + if (SKIP) + return '''(Empty due to «SKIP_PROPERTY_NAME» property = true)''' ''' «FOR node : nodes» «IF node instanceof NotificationDefinition» @@ -103,17 +101,15 @@ class YangTemplate { ''' } - def static writeEnumPair(EnumPair pair) { - var boolean hasEnumPairValue = pair.value != null + def private static writeEnumPair(EnumPair pair) { ''' - enum «pair.name»«IF !hasEnumPairValue»;«ELSE»{ + enum «pair.name» { value «pair.value»; } - «ENDIF» ''' } - def static String writeModuleImports(Set moduleImports) { + def private static String writeModuleImports(Set moduleImports) { if (moduleImports.nullOrEmpty) return '' @@ -126,18 +122,19 @@ class YangTemplate { ''' } - def static writeRevision(Date moduleRevision, String moduleDescription) { + def private static writeRevision(Date moduleRevision, String moduleDescription) { val revisionIndent = 12 ''' revision «SimpleDateFormatUtil.getRevisionFormat.format(moduleRevision)» { - description "«formatToParagraph(moduleDescription, revisionIndent)»"; + description "«YangTextTemplate.formatToParagraph(moduleDescription, revisionIndent)»"; } ''' } def static String generateYangSnipet(Module module) { - + if (SKIP) + return '''(Empty due to «SKIP_PROPERTY_NAME» property = true)''' ''' module «module.name» { yang-version «module.yangVersion»; @@ -198,7 +195,7 @@ class YangTemplate { ''' } - def static writeRPCs(Set rpcDefs) { + def private static writeRPCs(Set rpcDefs) { ''' «FOR rpc : rpcDefs» «IF rpc != null» @@ -208,12 +205,9 @@ class YangTemplate { ''' } - def static writeRPC(RpcDefinition rpc) { + def private static writeRPC(RpcDefinition rpc) { var boolean isStatusDeprecated = rpc.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» rpc «rpc.QName.localName» { «IF !rpc.description.nullOrEmpty» "«rpc.description»"; @@ -238,7 +232,7 @@ class YangTemplate { ''' } - def static writeRpcInput(ContainerSchemaNode input) { + def private static writeRpcInput(ContainerSchemaNode input) { if(input == null) return '' @@ -252,7 +246,7 @@ class YangTemplate { ''' } - def static writeRpcOutput(ContainerSchemaNode output) { + def private static writeRpcOutput(ContainerSchemaNode output) { if(output == null) return '' @@ -265,7 +259,7 @@ class YangTemplate { ''' } - def static writeNotifications(Set notifications) { + def private static writeNotifications(Set notifications) { ''' «FOR notification : notifications» «IF notification != null» @@ -275,12 +269,9 @@ class YangTemplate { ''' } - def static writeNotification(NotificationDefinition notification) { + def private static writeNotification(NotificationDefinition notification) { var boolean isStatusDeprecated = notification.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» notification «notification.QName.localName» { «IF !notification.description.nullOrEmpty» description @@ -309,7 +300,7 @@ class YangTemplate { ''' } - def static writeUnknownSchemaNodes(List unknownSchemaNodes) { + def private static writeUnknownSchemaNodes(List unknownSchemaNodes) { if (unknownSchemaNodes.nullOrEmpty) return '' @@ -320,11 +311,11 @@ class YangTemplate { ''' } - def static writeUnknownSchemaNode(UnknownSchemaNode unknownSchemaNode) { + def private static writeUnknownSchemaNode(UnknownSchemaNode unknownSchemaNode) { return '' } - def static writeUsesNodes(Set usesNodes) { + def private static writeUsesNodes(Set usesNodes) { if (usesNodes == null) { return '' } @@ -338,7 +329,7 @@ class YangTemplate { ''' } - def static writeUsesNode(UsesNode usesNode) { + def private static writeUsesNode(UsesNode usesNode) { val hasRefines = !usesNode.refines.empty ''' @@ -350,7 +341,7 @@ class YangTemplate { ''' } - def static writeRefines(Map refines) { + def private static writeRefines(Map refines) { ''' «FOR path : refines.keySet» «val schemaNode = refines.get(path)» @@ -359,7 +350,7 @@ class YangTemplate { ''' } - def static writeRefine(SchemaPath path, SchemaNode schemaNode) { + def private static writeRefine(SchemaPath path, SchemaNode schemaNode) { ''' refine «path.pathFromRoot.last» { «IF schemaNode instanceof DataSchemaNode» @@ -369,22 +360,9 @@ class YangTemplate { ''' } - def static writeTypeDefinitions(Set> typeDefinitions) { - ''' - «FOR typeDefinition : typeDefinitions» - «IF typeDefinition != null» - «writeTypeDefinition(typeDefinition)» - «ENDIF» - «ENDFOR» - ''' - } - - def static writeTypeDefinition(TypeDefinition typeDefinition) { + def private static writeTypeDefinition(TypeDefinition typeDefinition) { var boolean isStatusDeprecated = typeDefinition.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» type «typeDefinition.QName.localName»«IF !isStatusDeprecated»;«ELSE» { status «typeDefinition.status»; } @@ -392,7 +370,7 @@ class YangTemplate { ''' } - def static writeIdentities(Set identities) { + def private static writeIdentities(Set identities) { if (identities.nullOrEmpty) return '' ''' @@ -402,13 +380,13 @@ class YangTemplate { ''' } - def static writeIdentity(IdentitySchemaNode identity) { + def private static writeIdentity(IdentitySchemaNode identity) { if (identity == null) return '' ''' identity «identity.QName.localName» { «IF identity.baseIdentity != null» - base "(«writeIdentityNs(identity.baseIdentity)»)«identity.baseIdentity»"; + base "()«identity.baseIdentity»"; «ENDIF» «IF !identity.description.nullOrEmpty» description @@ -425,18 +403,7 @@ class YangTemplate { ''' } - def static writeIdentityNs(IdentitySchemaNode identity) { - if(module == null) - return '' - - val identityNs = identity.QName.namespace - - if(!module.namespace.equals(identityNs)) - return identityNs + ":" - return '' - } - - def static writeFeatures(Set features) { + def private static writeFeatures(Set features) { ''' «FOR feature : features» «IF feature != null» @@ -446,7 +413,7 @@ class YangTemplate { ''' } - def static writeFeature(FeatureDefinition featureDef) { + def private static writeFeature(FeatureDefinition featureDef) { ''' feature «featureDef.QName.localName» { «IF !featureDef.description.nullOrEmpty» @@ -464,7 +431,7 @@ class YangTemplate { ''' } - def static writeExtensions(List extensions) { + def private static writeExtensions(List extensions) { ''' «FOR anExtension : extensions» «IF anExtension != null» @@ -474,13 +441,8 @@ class YangTemplate { ''' } - def static writeExtension(ExtensionDefinition extensionDef) { - var boolean isStatusDeprecated = extensionDef.status == Status::DEPRECATED - + def private static writeExtension(ExtensionDefinition extensionDef) { ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» extension «extensionDef.QName.localName» { «IF !extensionDef.description.nullOrEmpty» description @@ -500,7 +462,7 @@ class YangTemplate { ''' } - def static writeDeviations(Set deviations) { + def private static writeDeviations(Set deviations) { ''' «FOR deviation : deviations» «IF deviation != null» @@ -510,21 +472,23 @@ class YangTemplate { ''' } - def static writeDeviation(Deviation deviation) { + def private static writeDeviation(Deviation deviation) { ''' deviation «deviation.targetPath» { «IF !deviation.reference.nullOrEmpty» reference "«deviation.reference»"; «ENDIF» - «IF deviation.deviate != null && !deviation.deviate.name.nullOrEmpty» - deviation «deviation.deviate.name»; - «ENDIF» + «FOR dev : deviation.deviates» + «IF dev != null && dev.deviateType != null» + deviation «dev.deviateType.name»; + «ENDIF» + «ENDFOR» } ''' } - def static writeAugments(Set augments) { + def private static writeAugments(Set augments) { ''' «FOR augment : augments» «IF augment != null» @@ -534,7 +498,7 @@ class YangTemplate { ''' } - def static writeDataSchemaNodes(Collection dataSchemaNodes) { + def private static writeDataSchemaNodes(Collection dataSchemaNodes) { ''' «FOR schemaNode : dataSchemaNodes» «writeDataSchemaNode(schemaNode)» @@ -542,7 +506,7 @@ class YangTemplate { ''' } - def static CharSequence writeGroupingDefs(Set groupingDefs) { + def private static CharSequence writeGroupingDefs(Set groupingDefs) { ''' «FOR groupingDef : groupingDefs» «IF groupingDef != null» @@ -552,9 +516,9 @@ class YangTemplate { ''' } - def static writeAugment(AugmentationSchema augment) { + def private static writeAugment(AugmentationSchema augment) { ''' - augment «formatToAugmentPath(augment.targetPath.pathFromRoot)» { + augment «YangTextTemplate.formatToAugmentPath(augment.targetPath.pathFromRoot)» { «IF augment.whenCondition != null && !augment.whenCondition.toString.nullOrEmpty» when "«augment.whenCondition.toString»"; «ENDIF» @@ -579,12 +543,9 @@ class YangTemplate { ''' } - def static writeGroupingDef(GroupingDefinition groupingDef) { + def private static writeGroupingDef(GroupingDefinition groupingDef) { var boolean isStatusDeprecated = groupingDef.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» grouping «groupingDef.QName.localName» { «IF !groupingDef.groupings.nullOrEmpty» «writeGroupingDefs(groupingDef.groupings)» @@ -602,12 +563,9 @@ class YangTemplate { ''' } - def static writeContSchemaNode(ContainerSchemaNode contSchemaNode) { + def private static writeContSchemaNode(ContainerSchemaNode contSchemaNode) { var boolean isStatusDeprecated = contSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» container «contSchemaNode.getQName.localName» { «IF !contSchemaNode.childNodes.nullOrEmpty» «writeDataSchemaNodes(contSchemaNode.childNodes)» @@ -631,12 +589,9 @@ class YangTemplate { ''' } - def static writeAnyXmlSchemaNode(AnyXmlSchemaNode anyXmlSchemaNode) { + def private static writeAnyXmlSchemaNode(AnyXmlSchemaNode anyXmlSchemaNode) { var boolean isStatusDeprecated = anyXmlSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» anyxml «anyXmlSchemaNode.getQName.localName»«IF !isStatusDeprecated»;«ELSE» { status «anyXmlSchemaNode.status»; } @@ -644,12 +599,9 @@ class YangTemplate { ''' } - def static writeLeafSchemaNode(LeafSchemaNode leafSchemaNode) { + def private static writeLeafSchemaNode(LeafSchemaNode leafSchemaNode) { var boolean isStatusDeprecated = leafSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» leaf «leafSchemaNode.getQName.localName» { type «leafSchemaNode.type.getQName.localName»; «IF isStatusDeprecated» @@ -659,12 +611,9 @@ class YangTemplate { ''' } - def static writeLeafListSchemaNode(LeafListSchemaNode leafListSchemaNode) { + def private static writeLeafListSchemaNode(LeafListSchemaNode leafListSchemaNode) { var boolean isStatusDeprecated = leafListSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» leaf-list «leafListSchemaNode.getQName.localName» { type «leafListSchemaNode.type.getQName.localName»; «IF isStatusDeprecated» @@ -674,12 +623,9 @@ class YangTemplate { ''' } - def static writeChoiceCaseNode(ChoiceCaseNode choiceCaseNode) { + def private static writeChoiceCaseNode(ChoiceCaseNode choiceCaseNode) { var boolean isStatusDeprecated = choiceCaseNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» case «choiceCaseNode.getQName.localName» { «FOR childNode : choiceCaseNode.childNodes» «writeDataSchemaNode(childNode)» @@ -691,12 +637,9 @@ class YangTemplate { ''' } - def static writeChoiceNode(ChoiceSchemaNode choiceNode) { + def private static writeChoiceNode(ChoiceSchemaNode choiceNode) { var boolean isStatusDeprecated = choiceNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» choice «choiceNode.getQName.localName» { «FOR child : choiceNode.cases» «writeDataSchemaNode(child)» @@ -708,13 +651,10 @@ class YangTemplate { ''' } - def static writeListSchemaNode(ListSchemaNode listSchemaNode) { + def private static writeListSchemaNode(ListSchemaNode listSchemaNode) { var boolean isStatusDeprecated = listSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» list «listSchemaNode.getQName.localName» { key «FOR listKey : listSchemaNode.keyDefinition SEPARATOR " "»"«listKey.localName»" «ENDFOR» @@ -740,7 +680,7 @@ class YangTemplate { ''' } - def static CharSequence writeDataSchemaNode(DataSchemaNode child) { + def private static CharSequence writeDataSchemaNode(DataSchemaNode child) { ''' «IF child instanceof ContainerSchemaNode» «writeContSchemaNode(child)» @@ -765,99 +705,4 @@ class YangTemplate { «ENDIF» ''' } - - static def String formatSchemaPath(String moduleName, Iterable schemaPath) { - var currentElement = schemaPath.head - val StringBuilder sb = new StringBuilder() - sb.append(moduleName) - - for(pathElement : schemaPath) { - if(!currentElement.namespace.equals(pathElement.namespace)) { - currentElement = pathElement - sb.append('/') - sb.append(pathElement) - } - else { - sb.append('/') - sb.append(pathElement.localName) - } - } - return sb.toString - } - - static def String formatToParagraph(String text, int nextLineIndent) { - if (text == null || text.isEmpty()) - return ''; - - var String formattedText = text; - val StringBuilder sb = new StringBuilder(); - val StringBuilder lineBuilder = new StringBuilder(); - var boolean isFirstElementOnNewLineEmptyChar = false; - val lineIndent = computeNextLineIndent(nextLineIndent); - - formattedText = NEWLINE_OR_TAB.removeFrom(formattedText); - formattedText = formattedText.replaceAll(" +", " "); - - val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true); - - while (tokenizer.hasMoreElements()) { - val String nextElement = tokenizer.nextElement().toString(); - - if (lineBuilder.length() + nextElement.length() > 80) { - if (lineBuilder.charAt(lineBuilder.length() - 1) == ' ') { - lineBuilder.setLength(0); - lineBuilder.append(lineBuilder.substring(0, lineBuilder.length() - 1)); - } - if (lineBuilder.charAt(0) == ' ') { - lineBuilder.setLength(0); - lineBuilder.append(lineBuilder.substring(1)); - } - - sb.append(lineBuilder); - lineBuilder.setLength(0); - sb.append("\n"); - - if (nextLineIndent > 0) { - sb.append(lineIndent) - } - - if (nextElement.toString().equals(" ")) - isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar; - } - if (isFirstElementOnNewLineEmptyChar) { - isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar; - } else { - lineBuilder.append(nextElement); - } - } - sb.append(lineBuilder); - sb.append("\n"); - - return sb.toString(); - } - - def private static formatToAugmentPath(Iterable schemaPath) { - val StringBuilder sb = new StringBuilder(); - - for(pathElement : schemaPath) { - val ns = pathElement.namespace - val localName = pathElement.localName - - sb.append("\\(") - sb.append(ns) - sb.append(')') - sb.append(localName) - } - return sb.toString - } - - private static def computeNextLineIndent(int nextLineIndent) { - val StringBuilder sb = new StringBuilder() - var i = 0 - while (i < nextLineIndent) { - sb.append(' ') - i = i + 1 - } - return sb.toString - } }