Binding generator v2 - uses statement - uses inner type #1
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / util / Types.java
index 6f55283cb13fc867b53b806d698cabef73737cdf..a25bd4e12022f0e1d3a40231dd9000a4aad7867a 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Map;
 import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
 import org.opendaylight.mdsal.binding.javav2.model.api.BaseTypeWithRestrictions;
 import org.opendaylight.mdsal.binding.javav2.model.api.ConcreteType;
 import org.opendaylight.mdsal.binding.javav2.model.api.ParameterizedType;
@@ -122,6 +123,20 @@ public final class Types {
         }
     }
 
+    public static ConcreteType typeForClass(final Class<?> cls, final Restrictions restrictions,
+            final ModuleContext moduleContext) {
+        if (restrictions != null) {
+            if (restrictions instanceof DefaultRestrictions) {
+                return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
+            } else {
+                return new BaseTypeWithRestrictionsImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions,
+                        moduleContext);
+            }
+        } else {
+            return typeForClass(cls);
+        }
+    }
+
     /**
      * Returns an instance of {@link ParameterizedType} describing the typed
      * {@link Map}&lt;K,V&gt;
@@ -192,6 +207,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, ModuleContext context) {
+        return new WildcardTypeImpl(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
+    }
+
     /**
      * Creates instance of
      * {@link ParameterizedType
@@ -268,7 +304,7 @@ public final class Types {
          *            string with the name of the type
          */
         private ConcreteTypeImpl(final String pkName, final String name, final Restrictions restrictions) {
-            super(pkName, name);
+            super(pkName, name, true,null);
             this.restrictions = restrictions;
         }
 
@@ -296,7 +332,13 @@ public final class Types {
          *            string with the name of the type
          */
         private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions) {
-            super(pkName, name);
+            super(pkName, name, null);
+            this.restrictions = Preconditions.checkNotNull(restrictions);
+        }
+
+        private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions,
+                final ModuleContext moduleContext) {
+            super(pkName, name, moduleContext);
             this.restrictions = Preconditions.checkNotNull(restrictions);
         }
 
@@ -332,7 +374,7 @@ public final class Types {
          *            array of actual parameters
          */
         public ParameterizedTypeImpl(final Type rawType, final Type[] actTypes) {
-            super(rawType.getPackageName(), rawType.getName(), true);
+            super(rawType.getPackageName(), rawType.getName(), true, null);
             this.rawType = rawType;
             this.actualTypes = actTypes.clone();
         }
@@ -363,8 +405,26 @@ public final class Types {
          * @param typeName
          *            string with the name of type
          */
+        //FIXME: doesn't seem to be called at all
         public WildcardTypeImpl(final String packageName, final String typeName) {
-            super(packageName, typeName);
+            super(packageName, typeName, null);
+        }
+
+        /**
+         * 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, ModuleContext context) {
+            super(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
         }
     }