Cleanup GeneratedTypeBuilder/enclosing mechanics
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / yang / types / AbstractTypeProvider.java
index 6a08bfed69339db7166e6fbb69eff362e7ef2c53..e44daaef7f8951272947cfbf2b39565b7460b728 100644 (file)
@@ -18,15 +18,11 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
-import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -40,6 +36,7 @@ import org.opendaylight.mdsal.binding.model.api.ConcreteType;
 import org.opendaylight.mdsal.binding.model.api.Enumeration;
 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
 import org.opendaylight.mdsal.binding.model.api.Type;
@@ -59,10 +56,6 @@ import org.opendaylight.mdsal.binding.model.util.generated.type.builder.Generate
 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
@@ -75,15 +68,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
@@ -91,8 +80,6 @@ import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.ModuleDependencySort;
 import org.opendaylight.yangtools.yang.model.util.PathExpressionImpl;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -100,24 +87,21 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractTypeProvider implements TypeProvider {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractTypeProvider.class);
     private static final Pattern GROUPS_PATTERN = Pattern.compile("\\[(.*?)\\]");
-
-    // Backwards compatibility: Union types used to be instantiated in YANG namespace, which is no longer
-    // the case, as unions are emitted to their correct schema path.
-    private static final SchemaPath UNION_PATH = SchemaPath.create(true,
-        org.opendaylight.yangtools.yang.model.util.BaseTypes.UNION_QNAME);
+    private static final JavaTypeName DEPRECATED_ANNOTATION = JavaTypeName.create(Deprecated.class);
 
     /**
      * Contains the schema data red from YANG files.
      */
     private final SchemaContext schemaContext;
 
-    private final Map<String, Map<Optional<Revision>, Map<String, Type>>> genTypeDefsContextMap = new HashMap<>();
+    private final Map<String, Map<Optional<Revision>, Map<String, GeneratedType>>> genTypeDefsContextMap =
+        new HashMap<>();
 
     /**
      * The map which maps schema paths to JAVA <code>Type</code>.
      */
     private final Map<SchemaPath, Type> referencedTypes = new HashMap<>();
-    private final Map<Module, Set<Type>> additionalTypes = new HashMap<>();
+    private final Map<Module, Set<GeneratedType>> additionalTypes = new HashMap<>();
     private final Map<SchemaNode, JavaTypeName> renames;
 
     /**
@@ -153,7 +137,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         referencedTypes.put(refTypePath, refType);
     }
 
-    public Map<Module, Set<Type>> getAdditionalTypes() {
+    public Map<Module, Set<GeneratedType>> getAdditionalTypes() {
         return additionalTypes;
     }
 
@@ -267,9 +251,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         DataSchemaNode dataChildByName;
         for (QName next : parentNode.getPath().getPathFromRoot()) {
             if (current == null) {
-                dataChildByName = schemaContext.getDataChildByName(next);
+                dataChildByName = schemaContext.dataChildByName(next);
             } else {
-                dataChildByName = current.getDataChildByName(next);
+                dataChildByName = current.dataChildByName(next);
             }
             if (dataChildByName == null) {
                 return false;
@@ -337,9 +321,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
                 final Module module = findParentModule(schemaContext, typeDefinition);
                 final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
                 if (module != null) {
-                    final Map<Optional<Revision>, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(
+                    final Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate = genTypeDefsContextMap.get(
                         module.getName());
-                    final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
+                    final Map<String, GeneratedType> genTOs = modulesByDate.get(module.getRevision());
                     if (genTOs != null) {
                         returnType = genTOs.get(typedefName);
                     }
@@ -401,7 +385,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
      *             <li>if name of <code>typeDefinition</code></li>
      *             </ul>
      */
-    public Type generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition,
+    public GeneratedType generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition,
             final SchemaNode parentNode) {
         Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
@@ -466,9 +450,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
 
         final Module module = findParentModule(schemaContext, parentNode);
         if (module != null) {
-            final Map<Optional<Revision>, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(
+            final Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate = genTypeDefsContextMap.get(
                 module.getName());
-            final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
+            final Map<String, GeneratedType> genTOs = modulesByDate.get(module.getRevision());
             if (genTOs != null) {
                 return genTOs.get(typeDefinition.getQName().getLocalName());
             }
@@ -651,7 +635,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         enumBuilder.setModuleName(module.getName());
         enumBuilder.setSchemaPath(enumTypeDef.getPath());
         enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
-        return enumBuilder.toInstance(null);
+        return enumBuilder.toInstance();
     }
 
     /**
@@ -681,11 +665,14 @@ public abstract class AbstractTypeProvider implements TypeProvider {
                 "Local Name in EnumTypeDefinition QName cannot be NULL!");
         Preconditions.checkArgument(typeBuilder != null, "Generated Type Builder reference cannot be NULL!");
 
-        final EnumBuilder enumBuilder = typeBuilder.addEnumeration(BindingMapping.getClassName(enumName));
-
+        final EnumBuilder enumBuilder = newEnumerationBuilder(
+            typeBuilder.getIdentifier().createEnclosed(BindingMapping.getClassName(enumName), "$"));
         addEnumDescription(enumBuilder, enumTypeDef);
         enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
-        return enumBuilder.toInstance(enumBuilder);
+        final Enumeration ret = enumBuilder.toInstance();
+        typeBuilder.addEnumeration(ret);
+
+        return ret;
     }
 
     public abstract void addEnumDescription(EnumBuilder enumBuilder, EnumTypeDefinition enumTypeDef);
@@ -760,7 +747,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         final List<Module> modulesSortedByDependency = ModuleDependencySort.sort(schemaContext.getModules());
 
         for (Module module : modulesSortedByDependency) {
-            Map<Optional<Revision>, Map<String, Type>> dateTypeMap = genTypeDefsContextMap.computeIfAbsent(
+            Map<Optional<Revision>, Map<String, GeneratedType>> dateTypeMap = genTypeDefsContextMap.computeIfAbsent(
                 module.getName(), key -> new HashMap<>());
             dateTypeMap.put(module.getRevision(), Collections.emptyMap());
             genTypeDefsContextMap.put(module.getName(), dateTypeMap);
@@ -802,7 +789,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
 
         final String typedefName = typedef.getQName().getLocalName();
 
-        final Type returnType;
+        final GeneratedType returnType;
         if (baseTypedef.getBaseType() != null) {
             returnType = provideGeneratedTOFromExtendedType(typedef, baseTypedef, basePackageName,
                 module.getName());
@@ -845,10 +832,10 @@ public abstract class AbstractTypeProvider implements TypeProvider {
             returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType, module.getName());
         }
         if (returnType != null) {
-            final Map<Optional<Revision>, Map<String, Type>> modulesByDate =
+            final Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate =
                     genTypeDefsContextMap.get(module.getName());
             final Optional<Revision> moduleRevision = module.getRevision();
-            Map<String, Type> typeMap = modulesByDate.get(moduleRevision);
+            Map<String, GeneratedType> typeMap = modulesByDate.get(moduleRevision);
             if (typeMap != null) {
                 if (typeMap.isEmpty()) {
                     typeMap = new HashMap<>(4);
@@ -883,7 +870,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         genTOBuilder.addToStringProperty(genPropBuilder);
         genTOBuilder.addImplementsType(BindingTypes.scalarTypeObject(javaType));
         if (typedef.getStatus() == Status.DEPRECATED) {
-            genTOBuilder.addAnnotation("java.lang", "Deprecated");
+            genTOBuilder.addAnnotation(DEPRECATED_ANNOTATION);
         }
         if (javaType instanceof ConcreteType && "String".equals(javaType.getName()) && typedef.getBaseType() != null) {
             addStringRegExAsConstant(genTOBuilder, resolveRegExpressionsFromTypedef(typedef));
@@ -909,7 +896,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         Preconditions.checkState(!builders.isEmpty(), "No GeneratedTOBuilder objects generated from union %s", typedef);
 
         final GeneratedTOBuilder resultTOBuilder = builders.remove(0);
-        builders.forEach(resultTOBuilder::addEnclosingTransferObject);
+        builders.forEach(builder -> resultTOBuilder.addEnclosingTransferObject(builder.build()));
         return resultTOBuilder;
     }
 
@@ -1061,9 +1048,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
     private Type findGenTO(final String searchedTypeName, final SchemaNode parentNode) {
         final Module typeModule = findParentModule(schemaContext, parentNode);
         if (typeModule != null && typeModule.getName() != null) {
-            final Map<Optional<Revision>, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(
+            final Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate = genTypeDefsContextMap.get(
                 typeModule.getName());
-            final Map<String, Type> genTOs = modulesByDate.get(typeModule.getRevision());
+            final Map<String, GeneratedType> genTOs = modulesByDate.get(typeModule.getRevision());
             if (genTOs != null) {
                 return genTOs.get(searchedTypeName);
             }
@@ -1083,9 +1070,9 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         if (!(newTypeDef instanceof UnionTypeDefinition)) {
             final Module parentModule = findParentModule(schemaContext, parentNode);
             if (parentModule != null && parentModule.getName() != null) {
-                final Map<Optional<Revision>, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(
+                final Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate = genTypeDefsContextMap.get(
                     parentModule.getName());
-                final Map<String, Type> genTOsMap = modulesByDate.get(parentModule.getRevision());
+                final Map<String, GeneratedType> genTOsMap = modulesByDate.get(parentModule.getRevision());
                 genTOsMap.put(newTypeDef.getQName().getLocalName(), genTOBuilder.build());
             }
         }
@@ -1226,15 +1213,15 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         addStringRegExAsConstant(genTOBuilder, resolveRegExpressionsFromTypedef(typedef));
 
         if (typedef.getStatus() == Status.DEPRECATED) {
-            genTOBuilder.addAnnotation("java.lang", "Deprecated");
+            genTOBuilder.addAnnotation(DEPRECATED_ANNOTATION);
         }
 
         if (baseTypeDefForExtendedType(innerExtendedType) instanceof UnionTypeDefinition) {
             genTOBuilder.setIsUnion(true);
         }
 
-        Map<Optional<Revision>, Map<String, Type>> modulesByDate = null;
-        Map<String, Type> typeMap = null;
+        Map<Optional<Revision>, Map<String, GeneratedType>> modulesByDate = null;
+        Map<String, GeneratedType> typeMap = null;
         final Module parentModule = findParentModule(schemaContext, innerExtendedType);
         if (parentModule != null) {
             modulesByDate = genTypeDefsContextMap.get(parentModule.getName());
@@ -1243,7 +1230,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
 
         if (typeMap != null) {
             final String innerTypeDef = innerExtendedType.getQName().getLocalName();
-            final Type type = typeMap.get(innerTypeDef);
+            final GeneratedType type = typeMap.get(innerTypeDef);
             if (type instanceof GeneratedTransferObject) {
                 genTOBuilder.setExtendsType((GeneratedTransferObject) type);
             }
@@ -1359,269 +1346,8 @@ public abstract class AbstractTypeProvider implements TypeProvider {
         }
     }
 
-    @Override
-    public String getTypeDefaultConstruction(final LeafSchemaNode node) {
-        return getTypeDefaultConstruction(node, (String) node.getType().getDefaultValue().orElse(null));
-    }
-
-    public String getTypeDefaultConstruction(final LeafSchemaNode node, final String defaultValue) {
-        final TypeDefinition<?> type = CompatUtils.compatType(node);
-        final QName typeQName = type.getQName();
-        final TypeDefinition<?> base = baseTypeDefForExtendedType(type);
-        requireNonNull(type, () -> "Cannot provide default construction for null type of " + node);
-        requireNonNull(defaultValue, () -> "Cannot provide default construction for null default statement of "
-            + node);
-
-        final StringBuilder sb = new StringBuilder();
-        String result = null;
-        if (base instanceof BinaryTypeDefinition) {
-            result = binaryToDef(defaultValue);
-        } else if (base instanceof BitsTypeDefinition) {
-            String parentName;
-            String className;
-            final Module parent = getParentModule(node);
-            final Iterator<QName> path = node.getPath().getPathFromRoot().iterator();
-            path.next();
-            if (!path.hasNext()) {
-                parentName = BindingMapping.getClassName(parent.getName()) + "Data";
-                final String basePackageName = BindingMapping.getRootPackageName(parent.getQNameModule());
-                className = basePackageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
-            } else {
-                final String basePackageName = BindingMapping.getRootPackageName(parent.getQNameModule());
-                final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                    type.getPath());
-                parentName = BindingMapping.getClassName(parent.getName());
-                className = packageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
-            }
-            result = bitsToDef((BitsTypeDefinition) base, className, defaultValue, type.getBaseType() != null);
-        } else if (base instanceof BooleanTypeDefinition) {
-            result = typeToBooleanDef(defaultValue);
-        } else if (base instanceof DecimalTypeDefinition) {
-            result = typeToDef(BigDecimal.class, defaultValue);
-        } else if (base instanceof EmptyTypeDefinition) {
-            result = typeToBooleanDef(defaultValue);
-        } else if (base instanceof EnumTypeDefinition) {
-            final char[] defValArray = defaultValue.toCharArray();
-            final char first = Character.toUpperCase(defaultValue.charAt(0));
-            defValArray[0] = first;
-            final String newDefVal = new String(defValArray);
-            String className;
-            if (type.getBaseType() != null) {
-                final Module m = getParentModule(type);
-                final String basePackageName = BindingMapping.getRootPackageName(m.getQNameModule());
-                final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                    type.getPath());
-                className = packageName + "." + BindingMapping.getClassName(typeQName);
-            } else {
-                final Module parentModule = getParentModule(node);
-                final String basePackageName = BindingMapping.getRootPackageName(parentModule.getQNameModule());
-                final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                    node.getPath());
-                className = packageName + "." + BindingMapping.getClassName(node.getQName());
-            }
-            result = className + "." + newDefVal;
-        } else if (base instanceof IdentityrefTypeDefinition) {
-            throw new UnsupportedOperationException("Cannot get default construction for identityref type");
-        } else if (base instanceof InstanceIdentifierTypeDefinition) {
-            throw new UnsupportedOperationException("Cannot get default construction for instance-identifier type");
-        } else if (BaseTypes.isInt8(base)) {
-            result = typeToValueOfDef(Byte.class, defaultValue);
-        } else if (BaseTypes.isInt16(base)) {
-            result = typeToValueOfDef(Short.class, defaultValue);
-        } else if (BaseTypes.isInt32(base)) {
-            result = typeToValueOfDef(Integer.class, defaultValue);
-        } else if (BaseTypes.isInt64(base)) {
-            result = typeToValueOfDef(Long.class, defaultValue);
-        } else if (base instanceof LeafrefTypeDefinition) {
-            result = leafrefToDef(node, (LeafrefTypeDefinition) base, defaultValue);
-        } else if (base instanceof StringTypeDefinition) {
-            result = "\"" + defaultValue + "\"";
-        } else if (BaseTypes.isUint8(base)) {
-            result = typeToValueOfDef(Uint8.class, defaultValue);
-        } else if (BaseTypes.isUint16(base)) {
-            result = typeToValueOfDef(Uint16.class, defaultValue);
-        } else if (BaseTypes.isUint32(base)) {
-            result = typeToValueOfDef(Uint32.class, defaultValue);
-        } else if (BaseTypes.isUint64(base)) {
-            result = typeToValueOfDef(Uint64.class, defaultValue);
-        } else if (base instanceof UnionTypeDefinition) {
-            result = unionToDef(node);
-        } else {
-            result = "";
-        }
-        sb.append(result);
-
-        if (type.getBaseType() != null && !(base instanceof LeafrefTypeDefinition)
-                && !(base instanceof EnumTypeDefinition) && !(base instanceof UnionTypeDefinition)) {
-            final Module m = getParentModule(type);
-            final String basePackageName = BindingMapping.getRootPackageName(m.getQNameModule());
-            final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                type.getPath());
-            final String className = packageName + "." + BindingMapping.getClassName(typeQName);
-            sb.insert(0, "new " + className + "(");
-            sb.insert(sb.length(), ')');
-        }
-
-        return sb.toString();
-    }
-
-    private static String typeToDef(final Class<?> clazz, final String defaultValue) {
-        return "new " + clazz.getName() + "(\"" + defaultValue + "\")";
-    }
-
-    private static String typeToValueOfDef(final Class<?> clazz, final String defaultValue) {
-        return clazz.getName() + ".valueOf(\"" + defaultValue + "\")";
-    }
-
-    private static String typeToBooleanDef(final String defaultValue) {
-        switch (defaultValue) {
-            case "false":
-                return "java.lang.Boolean.FALSE";
-            case "true":
-                return "java.lang.Boolean.TRUE";
-            default:
-                return typeToValueOfDef(Boolean.class, defaultValue);
-        }
-    }
-
-    private static String binaryToDef(final String defaultValue) {
-        final StringBuilder sb = new StringBuilder();
-        final byte[] encoded = Base64.getDecoder().decode(defaultValue);
-        sb.append("new byte[] {");
-        for (int i = 0; i < encoded.length; i++) {
-            sb.append(encoded[i]);
-            if (i != encoded.length - 1) {
-                sb.append(", ");
-            }
-        }
-        sb.append('}');
-        return sb.toString();
-    }
-
-    private static final Comparator<Bit> BIT_NAME_COMPARATOR = Comparator.comparing(Bit::getName);
-
-    private static String bitsToDef(final BitsTypeDefinition type, final String className, final String defaultValue,
-            final boolean isExt) {
-        final List<Bit> bits = new ArrayList<>(type.getBits());
-        bits.sort(BIT_NAME_COMPARATOR);
-        final StringBuilder sb = new StringBuilder();
-        if (!isExt) {
-            sb.append("new ");
-            sb.append(className);
-            sb.append('(');
-        }
-        for (int i = 0; i < bits.size(); i++) {
-            if (bits.get(i).getName().equals(defaultValue)) {
-                sb.append(true);
-            } else {
-                sb.append(false);
-            }
-            if (i != bits.size() - 1) {
-                sb.append(", ");
-            }
-        }
-        if (!isExt) {
-            sb.append(')');
-        }
-        return sb.toString();
-    }
-
     private Module getParentModule(final SchemaNode node) {
         final QName qname = node.getPath().getPathFromRoot().iterator().next();
         return schemaContext.findModule(qname.getModule()).orElse(null);
     }
-
-    private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType,
-            final String defaultValue) {
-        Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
-        Preconditions.checkArgument(leafrefType.getPathStatement() != null,
-                "The Path Statement for Leafref Type Definition cannot be NULL!");
-
-        final PathExpression xpath = leafrefType.getPathStatement();
-        final String strXPath = xpath.getOriginalString();
-
-        if (strXPath != null) {
-            if (strXPath.indexOf('[') == -1) {
-                final Module module = findParentModule(schemaContext, parentNode);
-                if (module != null) {
-                    final SchemaNode dataNode;
-                    if (xpath.isAbsolute()) {
-                        dataNode = findDataTreeSchemaNode(schemaContext, module.getQNameModule(), xpath);
-                    } else {
-                        dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
-                    }
-                    final String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue);
-                    return result;
-                }
-            } else {
-                return "new java.lang.Object()";
-            }
-        }
-
-        return null;
-    }
-
-    private String unionToDef(final LeafSchemaNode node) {
-        final TypeDefinition<?> type = CompatUtils.compatType(node);
-        String parentName;
-        String className;
-
-        if (type.getBaseType() != null) {
-            final QName typeQName = type.getQName();
-            Module module = null;
-            final Collection<? extends Module> modules = schemaContext.findModules(typeQName.getNamespace());
-            if (modules.size() > 1) {
-                for (Module m : modules) {
-                    if (m.getRevision().equals(typeQName.getRevision())) {
-                        module = m;
-                        break;
-                    }
-                }
-                if (module == null) {
-                    final List<Module> modulesList = new ArrayList<>(modules);
-                    modulesList.sort((o1, o2) -> Revision.compare(o1.getRevision(), o2.getRevision()));
-                    module = modulesList.get(0);
-                }
-            } else {
-                module = modules.iterator().next();
-            }
-
-            final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
-            className = basePackageName + "." + BindingMapping.getClassName(typeQName);
-        } else {
-            final Iterator<QName> path = node.getPath().getPathFromRoot().iterator();
-            final QName first = path.next();
-            final Module parent = schemaContext.findModule(first.getModule()).orElse(null);
-            final String basePackageName = BindingMapping.getRootPackageName(parent.getQNameModule());
-            if (!path.hasNext()) {
-                parentName = BindingMapping.getClassName(parent.getName()) + "Data";
-                className = basePackageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
-            } else {
-                final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                    UNION_PATH);
-                className = packageName + "." + BindingMapping.getClassName(node.getQName());
-            }
-        }
-        return union(className, (String) node.getType().getDefaultValue().orElse(null), node);
-    }
-
-    private static String union(final String className, final String defaultValue, final LeafSchemaNode node) {
-        return new StringBuilder()
-                .append("new ")
-                .append(className)
-                .append("(\"")
-                .append(defaultValue)
-                .append("\".toCharArray())")
-                .toString();
-    }
-
-    @Override
-    public String getConstructorPropertyName(final SchemaNode node) {
-        return node instanceof TypeDefinition<?> ? TypeConstants.VALUE_PROP : "";
-    }
-
-    @Override
-    public String getParamNameFromType(final TypeDefinition<?> type) {
-        return BindingMapping.getPropertyName(type.getQName().getLocalName());
-    }
 }