Merge "Yang parser refactoring."
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / util / TypeUtils.java
index 2839779a451fc125044430719dc3de025f60260b..16983c77f32c1018c8a6e199044797223edb3c3c 100644 (file)
@@ -7,31 +7,18 @@
  */
 package org.opendaylight.yangtools.yang.parser.util;
 
-import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.*;
+import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromBuilders;
+import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromContext;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
+import java.util.*;
 
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.*;
 import org.opendaylight.yangtools.yang.model.api.type.*;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.UnknownType;
-import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
-import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.builder.impl.*;
 
 /**
  * Utility class which contains helper methods for dealing with type operations.
@@ -44,7 +31,7 @@ public final class TypeUtils {
     /**
      * Resolve unknown type of node. It is assumed that type of node is either
      * UnknownType or ExtendedType with UnknownType as base type.
-     * 
+     *
      * @param nodeToResolve
      *            node with type to resolve
      * @param modules
@@ -68,7 +55,7 @@ public final class TypeUtils {
     /**
      * Resolve unknown type of node. It is assumed that type of node is either
      * UnknownType or ExtendedType with UnknownType as base type.
-     * 
+     *
      * @param nodeToResolve
      *            node with type to resolve
      * @param modules
@@ -121,7 +108,7 @@ public final class TypeUtils {
     public static void resolveTypeUnion(final UnionTypeBuilder union,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
         final List<TypeDefinition<?>> unionTypes = union.getTypes();
-        final List<TypeDefinition<?>> toRemove = new ArrayList<TypeDefinition<?>>();
+        final List<TypeDefinition<?>> toRemove = new ArrayList<>();
         for (TypeDefinition<?> unionType : unionTypes) {
             if (unionType instanceof UnknownType) {
                 final ModuleBuilder dependentModule = findModuleFromBuilders(modules, builder, unionType.getQName()
@@ -161,7 +148,7 @@ public final class TypeUtils {
             final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
             final SchemaContext context) {
         final List<TypeDefinition<?>> unionTypes = union.getTypes();
-        final List<TypeDefinition<?>> toRemove = new ArrayList<TypeDefinition<?>>();
+        final List<TypeDefinition<?>> toRemove = new ArrayList<>();
         for (TypeDefinition<?> unionType : unionTypes) {
             if (unionType instanceof UnknownType) {
                 resolveUnionUnknownType(union, (UnknownType) unionType, modules, module, context);
@@ -219,7 +206,7 @@ public final class TypeUtils {
 
     /**
      * Find type definition of type of unresolved node.
-     * 
+     *
      * @param nodeToResolve
      *            node with unresolved type
      * @param dependentModuleBuilder
@@ -258,7 +245,7 @@ public final class TypeUtils {
 
     /**
      * Search types for type with given name.
-     * 
+     *
      * @param types
      *            types to search
      * @param name
@@ -276,7 +263,7 @@ public final class TypeUtils {
 
     /**
      * Find type by name.
-     * 
+     *
      * @param types
      *            collection of types
      * @param typeName
@@ -295,7 +282,7 @@ public final class TypeUtils {
 
     /**
      * Pull restriction from type and add them to constraints.
-     * 
+     *
      * @param type
      *            type from which constraints will be read
      * @param constraints
@@ -326,7 +313,7 @@ public final class TypeUtils {
     /**
      * Create new type builder based on old type with new base type. Note: only
      * one of newBaseTypeBuilder or newBaseType can be specified.
-     * 
+     *
      * @param newBaseTypeBuilder
      *            new base type builder or null
      * @param newBaseType
@@ -350,7 +337,7 @@ public final class TypeUtils {
         }
 
         final TypeDefinitionBuilderImpl newType = new TypeDefinitionBuilderImpl(module.getModuleName(), line,
-                oldExtendedType.getQName());
+                oldExtendedType.getQName(), oldExtendedType.getPath());
         final TypeConstraints tc = new TypeConstraints(module.getName(), line);
         TypeConstraints constraints;
         if (newBaseType == null) {
@@ -365,7 +352,6 @@ public final class TypeUtils {
             newType.setType(newBaseType);
         }
 
-        newType.setPath(oldExtendedType.getPath());
         newType.setDescription(oldExtendedType.getDescription());
         newType.setReference(oldExtendedType.getReference());
         newType.setStatus(oldExtendedType.getStatus());
@@ -375,13 +361,12 @@ public final class TypeUtils {
         newType.setFractionDigits(constraints.getFractionDigits());
         newType.setUnits(oldExtendedType.getUnits());
         newType.setDefaultValue(oldExtendedType.getDefaultValue());
-        newType.setUnknownNodes(oldExtendedType.getUnknownSchemaNodes());
         return newType;
     }
 
     /**
      * Pull restrictions from type and add them to constraints.
-     * 
+     *
      * @param typeToResolve
      *            type from which constraints will be read
      * @param constraints
@@ -471,7 +456,7 @@ public final class TypeUtils {
 
     /**
      * Search for type definition builder by name.
-     * 
+     *
      * @param nodeToResolve
      *            node which contains unresolved type
      * @param dependentModule