Binding generator v2 - fix union getter name in camel-case
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / yang / types / TypeProviderImpl.java
index c625401f9b2176146d20027e0e4a6f6cffc2b5fc..9ec117fd87e09c9444b08404101c635dbf0c4b3a 100644 (file)
@@ -453,13 +453,14 @@ public final class TypeProviderImpl implements TypeProvider {
         if (r != null && !r.isEmpty() && returnType instanceof GeneratedTransferObject) {
             final GeneratedTransferObject gto = (GeneratedTransferObject) returnType;
             final Module module = findParentModule(schemaContext, parentNode);
+            final Module module1 = findParentModule(schemaContext, typeDefinition);
             final String basePackageName = BindingMapping.getRootPackageName(module);
             final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typeDefinition
                     .getPath(), BindingNamespaceType.Typedef);
             final String genTOName =
                     JavaIdentifierNormalizer.normalizeSpecificIdentifier(typedefName, JavaIdentifier.CLASS);
             final String name = packageName + "." + genTOName;
-            if (!(returnType.getFullyQualifiedName().equals(name))) {
+            if (module.equals(module1) && !(returnType.getFullyQualifiedName().equals(name))) {
                 returnType = shadedTOWithRestrictions(gto, r);
             }
         }
@@ -554,22 +555,17 @@ public final class TypeProviderImpl implements TypeProvider {
         final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
         Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition, schemaContext, genTypeDefsContextMap);
         if (returnType == null) {
-            if (baseTypeDef instanceof EnumTypeDefinition) {
-                final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
-                returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition, schemaContext);
-            } else {
-                final Module module = findParentModule(schemaContext, typeDefinition);
-                final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
-                if (module != null) {
-                    final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
-                    final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
-                    if (genTOs != null) {
-                        returnType = genTOs.get(typedefName);
-                    }
-                    if (returnType == null) {
-                        returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
-                                baseTypeDef, typeDefinition, r);
-                    }
+            final Module module = findParentModule(schemaContext, typeDefinition);
+            final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
+            if (module != null) {
+                final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
+                final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
+                if (genTOs != null) {
+                    returnType = genTOs.get(typedefName);
+                }
+                if (returnType == null) {
+                    returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
+                            baseTypeDef, typeDefinition, r);
                 }
             }
         }
@@ -987,7 +983,7 @@ public final class TypeProviderImpl implements TypeProvider {
         final String unionTypeName = unionSubtype.getQName().getLocalName();
         final Type genTO = findGenTO(unionTypeName, unionSubtype, schemaContext, genTypeDefsContextMap);
         if (genTO != null) {
-            updateUnionTypeAsProperty(parentUnionGenTOBuilder, genTO, genTO.getName());
+            updateUnionTypeAsProperty(parentUnionGenTOBuilder, genTO, unionTypeName);
         } else {
             final TypeDefinition<?> baseType = baseTypeDefForExtendedType(unionSubtype);
             if (unionTypeName.equals(baseType.getQName().getLocalName())) {