Binding generator v2 - fix units field name
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / yang / types / TypeProviderImpl.java
index 7faea06392eb1bff0615126a48c687a9afed2fdb..73762e694749917d91307179801a57dbc3b24efa 100644 (file)
@@ -415,7 +415,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     public static void addUnitsToGenTO(final GeneratedTOBuilder to, final String units) {
         if (!Strings.isNullOrEmpty(units)) {
-            to.addConstant(Types.STRING, "Units", "\"" + units + "\"");
+            to.addConstant(Types.STRING, "_UNITS", "\"" + units + "\"");
             final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("UNITS");
             prop.setReturnType(Types.STRING);
             to.addToStringProperty(prop);
@@ -436,7 +436,7 @@ public final class TypeProviderImpl implements TypeProvider {
             // a base type which holds these constraints.
             if (typeDefinition instanceof DecimalTypeDefinition) {
                 final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType
-                        (typeDefinition, parentNode, r, null);
+                        (typeDefinition, parentNode, r, context);
                 if (ret != null) {
                     return ret;
                 }
@@ -576,7 +576,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 }
                 if (returnType == null) {
                     returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
-                            baseTypeDef, typeDefinition, r, null);
+                            baseTypeDef, typeDefinition, r, context);
                 }
             }
         }
@@ -642,11 +642,14 @@ public final class TypeProviderImpl implements TypeProvider {
         if (strXPath != null) {
             if (strXPath.indexOf('[') == -1) {
                 final Module module;
+                final SchemaNode actualParentSchemaNode;
                 if ((parentNode instanceof DerivableSchemaNode) && ((DerivableSchemaNode) parentNode).isAddedByUses()) {
                     final Optional<? extends SchemaNode> originalNode = ((DerivableSchemaNode) parentNode).getOriginal();
                     Preconditions.checkArgument(originalNode.isPresent(), "originalNode can not be null.");
+                    actualParentSchemaNode = originalNode.get();
                     module = findParentModule(schemaContext, originalNode.get());
                 } else {
+                    actualParentSchemaNode = parentNode;
                     module = findParentModule(schemaContext, parentNode);
                 }
                 Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
@@ -655,7 +658,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 if (xpath.isAbsolute()) {
                     dataNode = findDataSchemaNode(schemaContext, module, xpath);
                 } else {
-                    dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+                    dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, actualParentSchemaNode, xpath);
                 }
                 Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
                         strXPath, getParentModule(parentNode, schemaContext).getName(), parentNode.getQName().getModule());