BUG-865: eliminate references to ExtendedType and base types 97/39897/12
authorRobert Varga <rovarga@cisco.com>
Mon, 6 Jun 2016 17:29:59 +0000 (19:29 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 7 Jul 2016 10:36:34 +0000 (12:36 +0200)
These are no longer emitted from YANG parser, eliminate references
obvious references to them.

Change-Id: Ia89278098108da2356252dfc5bf47fddbe732198
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/BindingRuntimeContext.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySort.java [deleted file]
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySortTest.java [deleted file]
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImplTest.java

index f9806f74e07217cf663f327499f0e3ae13a81e5b..5462a14cb50d43a6f6b48d5ec992ce2a28bae31c 100644 (file)
@@ -50,7 +50,6 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition
-import org.opendaylight.yangtools.yang.model.util.ExtendedType
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.sonatype.plexus.build.incremental.BuildContext
@@ -1308,10 +1307,6 @@ class GeneratorImpl {
         «type.lengthConstraints.toLengthStmt»
     '''
 
-    private def dispatch toLength(ExtendedType type) '''
-        «type.lengthConstraints.toLengthStmt»
-    '''
-
     private def dispatch toRange(TypeDefinition<?> type) {
     }
 
@@ -1327,10 +1322,6 @@ class GeneratorImpl {
         «type.rangeConstraints.toRangeStmt»
     '''
 
-    private def dispatch toRange(ExtendedType type) '''
-        «type.rangeConstraints.toRangeStmt»
-    '''
-
     def toLengthStmt(Collection<LengthConstraint> lengths) '''
         «IF lengths != null && !lengths.empty»
             «listItem("Length restrictions:")»
index e202da9df582ad60f74d789d4bd02aacb8c0e5e4..a1b8a70c4899dc6a4ad1bea4a71f893def6febc5 100644 (file)
@@ -103,7 +103,6 @@ import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
@@ -1371,11 +1370,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
     }
 
     private static boolean isInnerType(final LeafSchemaNode leaf, final TypeDefinition<?> type) {
-        // Deal with old parser, clearing out references to typedefs
-        if (type instanceof ExtendedType) {
-            return false;
-        }
-
         // New parser with encapsulated type
         if (leaf.getPath().equals(type.getPath())) {
             return true;
@@ -1472,10 +1466,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
     }
 
     private static TypeDefinition<?> getBaseOrDeclaredType(final TypeDefinition<?> typeDef) {
-        if (typeDef instanceof ExtendedType) {
-            // Legacy behaviour returning ExtendedType is enough
-            return typeDef;
-        }
         // Returns DerivedType in case of new parser.
         final TypeDefinition<?> baseType = typeDef.getBaseType();
         return (baseType != null && baseType.getBaseType() != null) ? baseType : typeDef;
@@ -2017,10 +2007,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
 
     /**
      * Builds generated TO builders for <code>typeDef</code> of type
-     * {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or
-     * {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
-     * BitsTypeDefinition} which are also added to <code>typeBuilder</code> as
-     * enclosing transfer object.
+     * {@link UnionTypeDefinition} or {@link BitsTypeDefinition} which are
+     * also added to <code>typeBuilder</code> as enclosing transfer object.
      *
      * If more then one generated TO builder is created for enclosing then all
      * of the generated TO builders are added to <code>typeBuilder</code> as
@@ -2283,4 +2271,4 @@ public class BindingGeneratorImpl implements BindingGenerator {
             builder.addAnnotation("", "Deprecated");
         }
     }
-}
\ No newline at end of file
+}
index 48da02b8ffdbc25c65e03992a4d224150cdf7d37..7fbdcd61492bbfb52ba041379c36a99b53c740eb 100644 (file)
@@ -53,7 +53,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -342,13 +341,8 @@ public class BindingRuntimeContext implements Immutable {
     private static BiMap<String, String> getEnumMapping(final Entry<GeneratedType, Object> typeWithSchema) {
         final TypeDefinition<?> typeDef = (TypeDefinition<?>) typeWithSchema.getValue();
 
-        final EnumTypeDefinition enumType;
-        if(typeDef instanceof ExtendedType) {
-            enumType = (EnumTypeDefinition) ((ExtendedType) typeDef).getBaseType();
-        } else {
-            Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
-            enumType = (EnumTypeDefinition) typeDef;
-        }
+        Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
+        final EnumTypeDefinition enumType = (EnumTypeDefinition) typeDef;
 
         final HashBiMap<String, String> mappedEnums = HashBiMap.create();
 
index e0771573a601f6c28b365a05a9dcfc953199e4c0..397557611591c7132ce56f4ab5b342f750716b5a 100644 (file)
@@ -80,11 +80,8 @@ 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;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
-import org.opendaylight.yangtools.yang.model.util.UnionType;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
 import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
@@ -95,6 +92,11 @@ public final class TypeProviderImpl implements TypeProvider {
     private static final Logger LOG = LoggerFactory.getLogger(TypeProviderImpl.class);
     private static final Pattern NUMBERS_PATTERN = Pattern.compile("[0-9]+\\z");
 
+    // 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);
+
     /**
      * Contains the schema data red from YANG files.
      */
@@ -199,8 +201,8 @@ public final class TypeProviderImpl implements TypeProvider {
         if (typeDefinition.getBaseType() == null) {
             // We have to deal with differing handling of decimal64. The old parser used a fixed Decimal64 type
             // and generated an enclosing ExtendedType to hold any range constraints. The new parser instantiates
-            // a base type which holds these constraints -- and the class is not a Decimal64.
-            if (typeDefinition instanceof DecimalTypeDefinition && !(typeDefinition instanceof Decimal64)) {
+            // a base type which holds these constraints.
+            if (typeDefinition instanceof DecimalTypeDefinition) {
                 final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode, r);
                 if (ret != null) {
                     return ret;
@@ -1178,14 +1180,7 @@ public final class TypeProviderImpl implements TypeProvider {
         Preconditions.checkArgument(typedef != null, "typedef can't be null");
 
         final List<PatternConstraint> patternConstraints;
-        if (typedef instanceof ExtendedType) {
-            final TypeDefinition<?> strTypeDef = baseTypeDefForExtendedType(typedef);
-            if (strTypeDef instanceof StringTypeDefinition) {
-                patternConstraints = ((ExtendedType)typedef).getPatternConstraints();
-            } else {
-                patternConstraints = ImmutableList.of();
-            }
-        } else if (typedef instanceof StringTypeDefinition) {
+        if (typedef instanceof StringTypeDefinition) {
             // FIXME: run diff against base
             patternConstraints = ((StringTypeDefinition) typedef).getPatternConstraints();
         } else {
@@ -1364,7 +1359,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *         definition to the base type
      */
     private static int getTypeDefinitionDepth(final TypeDefinition<?> typeDefinition) {
-        // FIXME: rewrite this in a non-recursive manner, without ExtendedType and UnionType
+        // FIXME: rewrite this in a non-recursive manner
         if (typeDefinition == null) {
             return 1;
         }
@@ -1645,18 +1640,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 Date revision = first.getRevision();
                 Module parentModule = schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
                 String basePackageName = BindingMapping.getRootPackageName(parentModule.getQNameModule());
-
-                // 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. Create a proxy instance to meet the
-                // codepath's expectations
-                final SchemaPath typePath;
-                if (type instanceof UnionType) {
-                    typePath = type.getPath();
-                } else {
-                    typePath = UnionType.create(((UnionTypeDefinition)type).getTypes()).getPath();
-                }
-
-                String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typePath);
+                String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, UNION_PATH);
                 className = packageName + "." + BindingMapping.getClassName(node.getQName());
             }
         }
diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySort.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySort.java
deleted file mode 100644 (file)
index dfd4c8f..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.sal.binding.yang.types;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class UnionDependencySort {
-    private static final Logger LOGGER = LoggerFactory.getLogger(UnionDependencySort.class);
-
-    /**
-     * Sorts union types by mutual dependencies.
-     *
-     * At the beginning the union types are selected from
-     * <code>typeDefinitions</code> and wrapped to nodes. The nodes are sorted
-     * and then the wrapped payload is extracted.
-     *
-     * @param typeDefinitions
-     *            set of type definitions.
-     * @return list of extended type which are sorted by mutual dependencies
-     * @throws IllegalArgumentException
-     *             if <code>typeDefinitions</code> equals <code>null</code>
-     */
-    public List<ExtendedType> sort(final Set<TypeDefinition<?>> typeDefinitions) {
-        if (typeDefinitions == null) {
-            LOGGER.error("Set of Type Definitions cannot be NULL!");
-            throw new IllegalArgumentException("Set of Type Definitions " + "cannot be NULL!");
-        }
-
-        final Set<ExtendedType> extUnionTypes = unionsFromTypeDefinitions(typeDefinitions);
-
-        final Set<Node> unsorted = unionTypesToNodes(extUnionTypes);
-
-        final List<Node> sortedNodes = TopologicalSort.sort(unsorted);
-        return Lists.transform(sortedNodes, new Function<Node, ExtendedType>() {
-            @Override
-            public ExtendedType apply(final Node input) {
-                return (ExtendedType) (((NodeWrappedType) input).getWrappedType());
-            }
-        });
-    }
-
-    /**
-     * Extracts only union types from <code>typeDefinitions</code> set.
-     *
-     * @param typeDefinitions
-     *            set of all type definitions
-     * @return set of extended type which are union type definition
-     */
-    private static Set<ExtendedType> unionsFromTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
-        final Set<ExtendedType> unions = Sets.newHashSet();
-
-        for (final TypeDefinition<?> typedef : typeDefinitions) {
-            if ((typedef != null) && (typedef.getBaseType() != null) && (typedef instanceof ExtendedType)
-                    && (typedef.getBaseType() instanceof UnionTypeDefinition)) {
-                unions.add((ExtendedType) typedef);
-            }
-        }
-        return unions;
-    }
-
-    /**
-     * Wraps every extended type which represents union to node type and adds to
-     * every node information about dependencies.
-     *
-     * The mapping from union type to node is created. For every created node
-     * (next <i>nodeFrom</i>) is for its wrapped union type passed the list of
-     * inner types through and only those inner types which represent union type
-     * are next considered. For every inner union type is found its wrapping
-     * node (next as <i>nodeTo</i>). This dependency relationship between
-     * nodeFrom and all found nodesTo is modeled with creating of one edge from
-     * nodeFrom to nodeTo.
-     *
-     *
-     * @param extUnionTypes
-     *            set of extended types which represents union types
-     * @return set of nodes which contains wrapped union types set of node where
-     *         each one contains wrapped one union type
-     */
-    private static Set<Node> unionTypesToNodes(final Set<ExtendedType> extUnionTypes) {
-        final Map<ExtendedType, Node> nodeMap = Maps.newHashMap();
-        final Set<Node> resultNodes = Sets.newHashSet();
-
-        for (final ExtendedType unionType : extUnionTypes) {
-            final Node node = new NodeWrappedType(unionType);
-            nodeMap.put(unionType, node);
-            resultNodes.add(node);
-        }
-
-        for (final Node node : resultNodes) {
-            final NodeWrappedType nodeFrom = (NodeWrappedType) node;
-            final ExtendedType extUnionType = (ExtendedType) nodeFrom.getWrappedType();
-
-            final UnionTypeDefinition unionType = (UnionTypeDefinition) extUnionType.getBaseType();
-
-            final List<TypeDefinition<?>> innerTypes = unionType.getTypes();
-            for (final TypeDefinition<?> typedef : innerTypes) {
-                if (extUnionTypes.contains(typedef)) {
-                    final Node toNode = nodeMap.get(typedef);
-                    nodeFrom.addEdge(toNode);
-                }
-            }
-        }
-
-        return resultNodes;
-    }
-
-}
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySortTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/UnionDependencySortTest.java
deleted file mode 100644 (file)
index 0c3c1e1..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.sal.binding.yang.types;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.google.common.base.Optional;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-
-public class UnionDependencySortTest {
-
-    @Rule
-    public ExpectedException expException = ExpectedException.none();
-
-    @Test
-    public void testSortMethod() {
-
-        final UnionDependencySort unionDependencySort = new UnionDependencySort();
-        final Set<TypeDefinition<?>> typeDefs = new HashSet<>();
-
-        final TypeDefinition<?> stringType = BaseTypes.stringType();
-        final ExtendedType extendedType = ExtendedType.builder(QName.create("ExtendedType1"), stringType, Optional.<String> absent(), Optional.<String> absent(), SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"))).build();
-
-        typeDefs.add(stringType);
-        typeDefs.add(extendedType);
-
-        final List<ExtendedType> sortedExtendedTypes = unionDependencySort.sort(typeDefs);
-        assertNotNull(sortedExtendedTypes);
-
-        expException.expect(IllegalArgumentException.class);
-        expException.expectMessage("Set of Type Definitions cannot be NULL!");
-        unionDependencySort.sort(null);
-    }
-}
index 9507a00861c16456265ca7b7c6fa0e0f6119b5c0..3c03294ccbc688b36445031590946e41663efbb9 100644 (file)
@@ -43,8 +43,6 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder;
 
@@ -498,8 +496,8 @@ public final class BindingGeneratorUtil {
             // instantiate a temporary unconstrained type and compare them.
             //
             // FIXME: looking at the generated code it looks as though we need to pass the restrictions without
-            //        comparison and also even in the case of the old parser
-            if (type instanceof DecimalTypeDefinition && !(type instanceof Decimal64)) {
+            //        comparison
+            if (type instanceof DecimalTypeDefinition) {
                 final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type;
                 final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath());
                 tmpBuilder.setFractionDigits(decimal.getFractionDigits());
@@ -550,26 +548,7 @@ public final class BindingGeneratorUtil {
          *
          * FIXME: this probably not the best solution and needs further analysis.
          */
-        if (type instanceof ExtendedType) {
-            final ExtendedType ext = (ExtendedType)type;
-            length = ext.getLengthConstraints();
-            pattern = ext.getPatternConstraints();
-
-            // Interesting special-case...
-            List<RangeConstraint> tmp = ext.getRangeConstraints();
-            if (tmp.isEmpty()) {
-                final TypeDefinition<?> base = ext.getBaseType();
-                if (base instanceof IntegerTypeDefinition) {
-                    tmp = ((IntegerTypeDefinition)base).getRangeConstraints();
-                } else if (base instanceof UnsignedIntegerTypeDefinition) {
-                    tmp = ((UnsignedIntegerTypeDefinition)base).getRangeConstraints();
-                } else if (base instanceof DecimalTypeDefinition) {
-                    tmp = ((DecimalTypeDefinition)base).getRangeConstraints();
-                }
-            }
-
-            range = tmp;
-        } else if (type instanceof BinaryTypeDefinition) {
+        if (type instanceof BinaryTypeDefinition) {
             final BinaryTypeDefinition binary = (BinaryTypeDefinition)type;
             final BinaryTypeDefinition base = binary.getBaseType();
             if (base != null && base.getBaseType() != null) {
index d48af8e83c75ec93f28ad133ff1bef553ae1a2ff..0e32ba431eae8dde8e9c700069e709f80d34b365 100644 (file)
@@ -16,12 +16,11 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
@@ -42,20 +41,18 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.DerivedTypes;
+import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
+import org.opendaylight.yangtools.yang.model.util.type.StringTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public class BindingGeneratorUtilTest {
+    private static final SchemaPath ROOT_PATH = SchemaPath.create(true, QName.create("/root"));
 
     @Rule
     public ExpectedException expectedEx = ExpectedException.none();
@@ -316,90 +313,59 @@ public class BindingGeneratorUtilTest {
 
     @Test
     public void getRestrictionsTest() {
+        final Optional<String> absent = Optional.absent();
+        final StringTypeBuilder builder =
+                RestrictedTypes.newStringBuilder(BaseTypes.stringType(), ROOT_PATH);
 
-        Optional<String> absent = Optional.absent();
-
-        Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
-                BaseTypes.int16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
-        ArrayList<LengthConstraint> lenght = new ArrayList<LengthConstraint>();
-        ArrayList<RangeConstraint> range = new ArrayList<RangeConstraint>();
-        ArrayList<PatternConstraint> pattern = new ArrayList<PatternConstraint>();
+        builder.addPatternConstraint(BaseConstraints.newPatternConstraint(".*", absent, absent));
+        builder.setLengthAlternatives(ImmutableList.of(
+            BaseConstraints.newLengthConstraint(1, 2, absent, absent)));
 
-        lenght.add(BaseConstraints.newLengthConstraint(1, 2, absent, absent));
-        range.add(BaseConstraints.newRangeConstraint(1, 2, absent, absent));
-        pattern.add(BaseConstraints.newPatternConstraint(".*", absent, absent));
-
-        extTypeBuilder.lengths(lenght);
-        extTypeBuilder.ranges(range);
-        extTypeBuilder.patterns(pattern);
-
-        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build());
+        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(builder.build());
 
         assertNotNull(restrictions);
 
         assertEquals(1, restrictions.getLengthConstraints().size());
-        assertEquals(1, restrictions.getRangeConstraints().size());
+        assertEquals(0, restrictions.getRangeConstraints().size());
         assertEquals(1, restrictions.getPatternConstraints().size());
 
         assertFalse(restrictions.isEmpty());
         assertTrue(restrictions.getLengthConstraints().contains(
                 BaseConstraints.newLengthConstraint(1, 2, absent, absent)));
-        assertTrue(restrictions.getRangeConstraints()
-                .contains(BaseConstraints.newRangeConstraint(1, 2, absent, absent)));
         assertTrue(restrictions.getPatternConstraints().contains(
                 BaseConstraints.newPatternConstraint(".*", absent, absent)));
     }
 
     @Test
     public void getEmptyRestrictionsTest() {
-
-        Optional<String> absent = Optional.absent();
-
-        Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
-                BaseTypes.stringType(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
-        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build());
+        final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.stringType(), ROOT_PATH).build();
+        final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
 
         assertNotNull(restrictions);
         assertTrue(restrictions.isEmpty());
-
     }
 
     @Test
     public void getDefaultIntegerRestrictionsTest() {
-
-        Optional<String> absent = Optional.absent();
-
-        Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
-                BaseTypes.int16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
-        ExtendedType extType = extTypeBuilder.build();
-        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+        final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.int16Type(), ROOT_PATH).build();
+        final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
 
         assertNotNull(restrictions);
         assertFalse(restrictions.isEmpty());
-        assertEquals(((IntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+        assertEquals(((IntegerTypeDefinition) type.getBaseType()).getRangeConstraints(),
                 restrictions.getRangeConstraints());
         assertTrue(restrictions.getLengthConstraints().isEmpty());
         assertTrue(restrictions.getPatternConstraints().isEmpty());
-
     }
 
     @Test
     public void getDefaultUnsignedIntegerRestrictionsTest() {
-
-        Optional<String> absent = Optional.absent();
-
-        Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
-                BaseTypes.uint16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
-        ExtendedType extType = extTypeBuilder.build();
-        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+        final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.uint16Type(), ROOT_PATH).build();
+        final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
 
         assertNotNull(restrictions);
         assertFalse(restrictions.isEmpty());
-        assertEquals(((UnsignedIntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+        assertEquals(((UnsignedIntegerTypeDefinition) type.getBaseType()).getRangeConstraints(),
                 restrictions.getRangeConstraints());
         assertTrue(restrictions.getLengthConstraints().isEmpty());
         assertTrue(restrictions.getPatternConstraints().isEmpty());
@@ -407,23 +373,15 @@ public class BindingGeneratorUtilTest {
 
     @Test
     public void getDefaultDecimalRestrictionsTest() {
+        final DecimalTypeDefinition base = BaseTypes.decimalTypeBuilder(ROOT_PATH).setFractionDigits(10).build();
+        final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(base, ROOT_PATH).build();
 
-        Optional<String> absent = Optional.absent();
-        SchemaPath path = SchemaPath.create(true, QName.create("/root"));
-
-        Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
-                Decimal64.create(path, 10), absent, absent, path);
-
-        ExtendedType extType = extTypeBuilder.build();
-        Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+        final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
 
         assertNotNull(restrictions);
         assertFalse(restrictions.isEmpty());
-        assertEquals(((DecimalTypeDefinition) extType.getBaseType()).getRangeConstraints(),
-                restrictions.getRangeConstraints());
+        assertEquals(base.getRangeConstraints(), restrictions.getRangeConstraints());
         assertTrue(restrictions.getLengthConstraints().isEmpty());
         assertTrue(restrictions.getPatternConstraints().isEmpty());
-
     }
-
 }
index c2b4682103c3b1ecd4d1f194cb48d75f5bf65b85..00a4928f64c962b652883c53f0ff76020cf54fec 100644 (file)
@@ -12,9 +12,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-
-import com.google.common.base.Optional;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -24,9 +21,9 @@ import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.util.EnumerationType;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 
 public class EnumerationBuilderImplTest {
 
@@ -144,9 +141,8 @@ public class EnumerationBuilderImplTest {
 
     @Test
     public void testUpdateEnumPairsFromEnumTypeDef() {
-        EnumTypeDefinition.EnumPair enumPair = EnumPairImpl.create(qName);
-        EnumTypeDefinition enumTypeDefinition = EnumerationType.create(SchemaPath.SAME,
-                Arrays.asList(enumPair), Optional.of(enumPair));
+        EnumTypeDefinition enumTypeDefinition = BaseTypes.enumerationTypeBuilder(SchemaPath.SAME)
+                .addEnum(EnumPairImpl.create(qName)).build();
         enumerationBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDefinition);
     }
 
@@ -163,7 +159,7 @@ public class EnumerationBuilderImplTest {
         private final String name;
         private final Integer value;
 
-        private EnumPairImpl(QName qName) {
+        private EnumPairImpl(final QName qName) {
             qname = qName;
             path = SchemaPath.SAME;
             description = "Some Other Description";
@@ -173,7 +169,7 @@ public class EnumerationBuilderImplTest {
             value = 45;
         }
 
-        public static EnumPairImpl create(QName qName) {
+        public static EnumPairImpl create(final QName qName) {
             return new EnumPairImpl(qName);
         }