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 2c223713119f6f5732a7426805f9d2ffcee38edf..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;
@@ -209,8 +224,8 @@ public final class Types {
      *         <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);
+            final boolean isPkNameNormalized, final boolean isTypeNormalized, ModuleContext context) {
+        return new WildcardTypeImpl(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
     }
 
     /**
@@ -289,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;
         }
 
@@ -317,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);
         }
 
@@ -353,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();
         }
@@ -384,8 +405,9 @@ 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);
         }
 
         /**
@@ -401,8 +423,8 @@ public final class Types {
          *            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);
+                final boolean isTypeNormalized, ModuleContext context) {
+            super(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
         }
     }