Binding generator v2 - Type reference fix 72/60072/3
authorJie Han <han.jie@zte.com.cn>
Fri, 30 Jun 2017 07:38:18 +0000 (15:38 +0800)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Mon, 17 Jul 2017 08:08:55 +0000 (08:08 +0000)
Change-Id: I85e08bdb4bfe09ac12604b1e57d1933f753a0176
Signed-off-by: Jie Han <han.jie@zte.com.cn>
(cherry picked from commit 23da4f4d9b685af9c40ab570158aa0263042ed57)

binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/yang/types/TypeProviderImpl.java
binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref-base.yang [new file with mode: 0644]
binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref.yang [new file with mode: 0644]
binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref2.yang [new file with mode: 0644]

index c625401f9b2176146d20027e0e4a6f6cffc2b5fc..1214fb7bfe9921d63f812dadc9ec76691742ae40 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);
                 }
             }
         }
diff --git a/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref-base.yang b/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref-base.yang
new file mode 100644 (file)
index 0000000..a4177d0
--- /dev/null
@@ -0,0 +1,17 @@
+module test-typeref-base {
+    yang-version 1.1;
+
+    namespace "urn:test:typeref:base";
+    prefix test-typeref-base;
+
+    organization "test.type.org";
+    revision "2017-06-30";
+
+    typedef as-number {
+        type uint32;
+    }
+
+    container base-cont {
+
+    }
+}
\ No newline at end of file
diff --git a/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref.yang b/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref.yang
new file mode 100644 (file)
index 0000000..0de4dff
--- /dev/null
@@ -0,0 +1,32 @@
+module test-typeref {
+    yang-version 1.1;
+
+    namespace "urn:test:typeref";
+    prefix test-typeref;
+
+    import test-typeref-base {
+        prefix base;
+        revision-date 2017-06-30;
+    }
+
+    organization "test.type.org";
+    revision "2017-06-30";
+
+    typedef local-as-number {
+        type uint32;
+    }
+
+    grouping as-number-subobject {
+        leaf as-number {
+            type base:as-number;
+        }
+
+        leaf local-as-number {
+            type local-as-number;
+        }
+    }
+
+    container my-cont {
+        uses as-number-subobject;
+    }
+}
\ No newline at end of file
diff --git a/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref2.yang b/binding2/mdsal-binding2-generator-impl/src/test/resources/uses-statement/test-typeref2.yang
new file mode 100644 (file)
index 0000000..59f4ae4
--- /dev/null
@@ -0,0 +1,30 @@
+module test-typeref2 {
+    yang-version 1.1;
+
+    namespace "urn:test:typeref2";
+    prefix test-typeref2;
+
+    typedef lsp-flag {
+        type enumeration {
+            enum unprotected {
+                value 0;
+            }
+            enum full-rerouting {
+                value 1;
+            }
+        }
+    }
+
+    grouping protection-subobject {
+        container protection-subobject {
+            leaf lsp-flag {
+                type lsp-flag;
+                mandatory true;
+            }
+        }
+    }
+
+    container my-cont {
+        uses protection-subobject;
+    }
+}
\ No newline at end of file