From 481e4d14dd8347da64321447fecf6c89cd6b2f55 Mon Sep 17 00:00:00 2001 From: Ryan Goulding Date: Thu, 2 Jun 2016 14:01:19 -0400 Subject: [PATCH] Bug 2872: Generated Java Enumerations should contain mapping to the string counter part Changes the Enumeration API to expose the "getMappedName()" accessor, which exposes the name that is used for the Java mapped enum name. The EnumTemplate.xtend template was modified in the following way: 1) A field was added to track the "raw" enum name, the one parsed from the YANG file. 2) The constructor was modified to accept the raw enum name as a parameter, and store the parameter value in the name instance variable. 3) An accessor was added called "getName()", which exposes the name instance variable. A corresponding change in yangtools changes the EnumEffectiveStatementImpl.getName() definition to expose the "raw" name attribute parsed from the yang file: https://git.opendaylight.org/gerrit/#/c/39733/ Change-Id: If248039a2b10958ff563ee0799d7b13284570b3c Signed-off-by: Ryan Goulding --- .../sal/java/api/generator/EnumTemplate.xtend | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/EnumTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/EnumTemplate.xtend index 8fbfc43267..bfeeae5b97 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/EnumTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/EnumTemplate.xtend @@ -43,9 +43,9 @@ class EnumTemplate extends BaseTemplate { return body } - def writeEnumItem(String name, int value, String description) ''' + def writeEnumItem(String name, String mappedName, int value, String description) ''' «asJavadoc(encodeAngleBrackets(description))» - «name»(«value») + «mappedName»(«value», "«name»") ''' /** @@ -59,6 +59,7 @@ class EnumTemplate extends BaseTemplate { «writeEnumeration(enums)» + String name; int value; private static final java.util.Map VALUE_MAP; @@ -72,8 +73,18 @@ class EnumTemplate extends BaseTemplate { VALUE_MAP = b.build(); } - private «enums.name»(int value) { + private «enums.name»(int value, String name) { this.value = value; + this.name = name; + } + + /** + * Returns the name of the enumeration item as it is specified in the input yang. + * + * @return the name of the enumeration item as it is specified in the input yang + */ + public String getName() { + return name; } /** @@ -96,7 +107,7 @@ class EnumTemplate extends BaseTemplate { def writeEnumeration(Enumeration enumeration) ''' «FOR v : enumeration.values SEPARATOR ",\n" AFTER ";"» - «writeEnumItem(v.name, v.value, v.description)»« + «writeEnumItem(v.name, v.mappedName, v.value, v.description)»« ENDFOR» ''' } -- 2.36.6