Binding generator v2 - Identityref - Compilability fix 69/59069/1
authorJie Han <han.jie@zte.com.cn>
Thu, 15 Jun 2017 10:05:12 +0000 (18:05 +0800)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Fri, 16 Jun 2017 10:33:33 +0000 (10:33 +0000)
- only one base support currently
- add testing yang
Change-Id: I5e277fcfbf5e92bdc31420dfefaa04d0d68b47c4
Signed-off-by: Jie Han <han.jie@zte.com.cn>
(cherry picked from commit 6c246170011dc5a4e82fc56fc74cd9cbc5c748d7)

binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/yang/types/TypeProviderImpl.java
binding2/mdsal-binding2-generator-util/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/util/Types.java
binding2/mdsal-binding2-java-api-generator/src/test/resources/test-identityref.yang [new file with mode: 0644]

index 26ef65b2d1b8ae438b909d74a3e09614156ed977..dd248e8c3e0ce6c664a08b464dc475fe67fd0337 100644 (file)
@@ -765,12 +765,13 @@ public final class TypeProviderImpl implements TypeProvider {
 
         final String basePackageName = BindingMapping.getRootPackageName(module);
         final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, identity.getPath
-                (), BindingNamespaceType.Typedef);
-        final String genTypeName =
-                JavaIdentifierNormalizer.normalizeClassIdentifier(packageName, identity.getQName().getLocalName());
+                (), BindingNamespaceType.Identity);
+
+        final String genTypeName = JavaIdentifierNormalizer.normalizeSpecificIdentifier(identity.getQName().getLocalName(),
+                JavaIdentifier.CLASS);
 
         final Type baseType = Types.typeForClass(Class.class);
-        final Type paramType = Types.wildcardTypeFor(packageName, genTypeName);
+        final Type paramType = Types.wildcardTypeFor(packageName, genTypeName, true, true);
         return Types.parameterizedTypeFor(baseType, paramType);
     }
 
index 6f55283cb13fc867b53b806d698cabef73737cdf..2c223713119f6f5732a7426805f9d2ffcee38edf 100644 (file)
@@ -192,6 +192,27 @@ public final class Types {
         return new WildcardTypeImpl(packageName, typeName);
     }
 
+    /**
+     * Creates instance of type
+     * {@link WildcardType
+     * WildcardType}
+     *
+     * @param packageName
+     *            string with the package name
+     * @param typeName
+     *            string with the type name
+     * @param isPkNameNormalized
+     *            if the package name has been normalized
+     * @param isTypeNormalized
+     *            if the type name has been normalized
+     * @return <code>WildcardType</code> representation of
+     *         <code>packageName</code> and <code>typeName</code>
+     */
+    public static WildcardType wildcardTypeFor(final String packageName, final String typeName,
+                                               final boolean isPkNameNormalized, final boolean isTypeNormalized) {
+        return new WildcardTypeImpl(packageName, typeName, isPkNameNormalized, isTypeNormalized);
+    }
+
     /**
      * Creates instance of
      * {@link ParameterizedType
@@ -366,6 +387,23 @@ public final class Types {
         public WildcardTypeImpl(final String packageName, final String typeName) {
             super(packageName, typeName);
         }
+
+        /**
+         * Creates instance of this class with concrete package and type name.
+         *
+         * @param packageName
+         *            string with the package name
+         * @param typeName
+         *            string with the name of type
+         * @param isPkNameNormalized
+         *            if the package name has been normalized
+         * @param isTypeNormalized
+         *            if the type name has been normalized
+         */
+        public WildcardTypeImpl(final String packageName, final String typeName, final boolean isPkNameNormalized,
+                                final boolean isTypeNormalized) {
+            super(packageName, typeName, isPkNameNormalized, isTypeNormalized);
+        }
     }
 
     public static <T extends Number> DefaultRestrictions<T> getDefaultRestrictions(final T min, final T max) {
diff --git a/binding2/mdsal-binding2-java-api-generator/src/test/resources/test-identityref.yang b/binding2/mdsal-binding2-java-api-generator/src/test/resources/test-identityref.yang
new file mode 100644 (file)
index 0000000..f223eae
--- /dev/null
@@ -0,0 +1,24 @@
+module test-identityref{
+    namespace "urn:test:identityref";
+    prefix idref;
+    revision 2017-01-01;
+
+    identity alg {
+    }
+
+    typedef my-identityref {
+        type identityref {
+            base alg;
+        }
+    }
+
+    leaf ext-identityref {
+        type my-identityref;
+    }
+
+    leaf leaf-identityref {
+        type identityref {
+            base alg;
+        }
+    }
+}
\ No newline at end of file