JavaIdentifierNormalizer ThreadSafe/Memory leak fix
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / util / AbstractBaseType.java
index 296800b1da49d273735ce99c845cfbe712843a5c..de719fee4a873c2eafd96c052202022ecb63126b 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.mdsal.binding.javav2.generator.util;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import java.util.Objects;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
 
 /**
@@ -39,9 +40,59 @@ public abstract class AbstractBaseType implements Type {
      * @param name
      *            string with the name for this <code>Type</code>
      */
-    protected AbstractBaseType(final String pkName, final String name) {
-        this.packageName = Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
-        this.name = Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+    protected AbstractBaseType(final String pkName, final String name, ModuleContext context) {
+        Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
+        Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+        this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
+        Preconditions.checkNotNull(context, "In case of not having identifiers normalized, " +
+                "ModuleContext instance must be provided.");
+        this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
+    }
+
+    /**
+     * Constructs the instance of this class with the concrete package name type
+     * name.
+     *
+     * @param pkName
+     *            string with the package name to which this <code>Type</code>
+     *            belongs
+     * @param name
+     *            string with the name for this <code>Type</code>
+     * @param isNormalized
+     *            true if pkName and name are normalized
+     */
+    protected AbstractBaseType(final String pkName, final String name, final boolean isNormalized,
+            ModuleContext context) {
+        Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
+        Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+        if (isNormalized) {
+            this.packageName = pkName;
+            this.name = name;
+        } else {
+            this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
+            Preconditions.checkNotNull(context, "In case of not having identifiers normalized, " +
+                    "ModuleContext instance must be provided.");
+            this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
+        }
+    }
+
+    protected AbstractBaseType(final String pkName, final String name, final boolean isPkNameNormalized,
+            final boolean isTypeNormalized, ModuleContext context ) {
+        Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
+        Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
+        if (isPkNameNormalized) {
+            this.packageName = pkName;
+        } else {
+            this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
+        }
+
+        if (isTypeNormalized) {
+            this.name = name;
+        } else {
+            Preconditions.checkNotNull(context, "In case of not having identifiers normalized, " +
+                    "ModuleContext instance must be provided.");
+            this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
+        }
     }
 
     @Override