Merge "Eliminate duplicate code"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 2 Sep 2014 13:15:54 +0000 (13:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 2 Sep 2014 13:15:54 +0000 (13:15 +0000)
25 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend
code-generator/binding-java-api-generator/src/test/resources/compilation/typedef/mod-box.yang [new file with mode: 0644]
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/BoxableType.java [new file with mode: 0644]
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedType.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTypeBuilderBase.java
code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
common/parent/pom.xml
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONNormalizedNodeStreamWriter.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Decimal64Test.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ExtendedTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/UnionTypeTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/antlr/YangParser.g4
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java
yang/yang-parser-impl/src/test/resources/extensions/ext-use.yang

index c1fd71df23a3065cebb6206481f52b184f08a986..b98c48c9844f0b5067aeae72cd1894b9efd43b9c 100644 (file)
@@ -318,23 +318,61 @@ public class BindingGeneratorImpl implements BindingGenerator {
             genCtx.get(module).addChildNodeType(node, genType);
             groupingsToGenTypes(module, ((DataNodeContainer) node).getGroupings());
             processUsesAugments((DataNodeContainer) node, module);
+            if (node.isAddedByUses() || node.isAugmenting())
+                genType.setSuitableForBoxing(false);
         }
         return genType;
     }
 
+    private boolean hasWhenOrMustConstraints(final SchemaNode node) {
+        boolean hasWhenCondition;
+        boolean hasMustConstraints;
+
+        if (node instanceof ContainerSchemaNode) {
+            ContainerSchemaNode contNode = (ContainerSchemaNode)node;
+            hasWhenCondition = contNode.getConstraints().getWhenCondition() != null;
+            hasMustConstraints = !isNullOrEmpty(contNode.getConstraints().getMustConstraints());
+
+            if (hasWhenCondition || hasMustConstraints)
+                return true;
+        }
+        return false;
+    }
+
     private void containerToGenType(final Module module, final String basePackageName,
             final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final ContainerSchemaNode node) {
         final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
+
         if (genType != null) {
             constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType);
             resolveDataSchemaNodes(module, basePackageName, genType, genType, node.getChildNodes());
+
+            final String parentName = parent.getName();
+            final String childOfName = childOf.getName();
+
+            if (parent != null && !parent.getName().contains("Data"))
+                genType.setParentType(parent);
+            genType.setSuitableForBoxing(hasOnlyOneChild(node) && !hasWhenOrMustConstraints(node));
+
+            if (parentName.equals(childOfName))
+                genType.setSuitableForBoxing(false);
         }
     }
 
+    private boolean hasOnlyOneChild(final ContainerSchemaNode contNode) {
+        if (!isNullOrEmpty(contNode.getChildNodes()) && contNode.getChildNodes().size() == 1)
+            return true;
+        return false;
+    }
+
     private void listToGenType(final Module module, final String basePackageName, final GeneratedTypeBuilder parent,
             final GeneratedTypeBuilder childOf, final ListSchemaNode node) {
         final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
+
         if (genType != null) {
+            if (!parent.getName().equals(childOf) && !parent.getName().contains("Data")) {
+                genType.setParentType(parent);
+            }
             constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), Types.listTypeFor(genType));
 
             final List<String> listKeys = listKeys(node);
@@ -856,6 +894,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         if (targetTypeBuilder == null) {
             throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
         }
+        targetTypeBuilder.setSuitableForBoxing(false);
 
         if (!(targetSchemaNode instanceof ChoiceNode)) {
             String packageName = augmentPackageName;
@@ -1156,6 +1195,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
             constructGetter(parent, choiceNode.getQName().getLocalName(), choiceNode.getDescription(),
                     choiceTypeBuilder);
             choiceTypeBuilder.addImplementsType(typeForClass(DataContainer.class));
+            choiceTypeBuilder.setParentType(parent);
             genCtx.get(module).addChildNodeType(choiceNode, choiceTypeBuilder);
             generateTypesFromChoiceCases(module, basePackageName, choiceTypeBuilder.toInstance(), choiceNode);
         }
index cb7f50549e537e6a24f11e5407f35082b8f970ae..ae80a51da4b19351b95b5de666504cb80549f881 100644 (file)
@@ -342,6 +342,11 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
             return values;
         }
 
+        @Override
+        public boolean isSuitableForBoxing() {
+            return false;
+        }
+
         @Override
         public List<AnnotationType> getAnnotations() {
             return annotations;
@@ -518,5 +523,6 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
         public String getModuleName() {
             return moduleName;
         }
+
     }
 }
index 270b04ac81161374d337fe03f012d96691939920..8d1bcea0e80be00fd1ccc4bc9923747474b6f076 100644 (file)
@@ -337,5 +337,10 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
         public String getModuleName() {
             return moduleName;
         }
+
+        @Override
+        public boolean isSuitableForBoxing() {
+            return false;
+        }
     }
 }
index 92c5629eab8861674bb2532957d4ab0bb9239256..5b14461dbbd8d029d5af60a323b3c84a2a6d5beb 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
 
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
 import org.opendaylight.yangtools.yang.common.QName;
 
@@ -18,6 +19,8 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
     private String reference;
     private String moduleName;
     private Iterable<QName> schemaPath;
+    private boolean isSuitableForBoxing;
+    private GeneratedTypeBuilder parentType;
 
     public GeneratedTypeBuilderImpl(final String packageName, final String name) {
         super(packageName, name);
@@ -49,6 +52,21 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
         this.reference = reference;
     }
 
+    @Override
+    public void setSuitableForBoxing(boolean value) {
+        this.isSuitableForBoxing = value;
+    }
+
+    @Override
+    public void setParentType(GeneratedTypeBuilder parent) {
+        this.parentType = parent;
+    }
+
+    @Override
+    public Type getParent() {
+        return this.parentType;
+    }
+
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
@@ -86,6 +104,8 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
         private final String reference;
         private final String moduleName;
         private final Iterable<QName> schemaPath;
+        private final boolean isSuitableForBoxing;
+        private final GeneratedTypeBuilder parentType;
 
         public GeneratedTypeImpl(GeneratedTypeBuilderImpl builder) {
             super(builder);
@@ -94,6 +114,8 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
             this.reference = builder.reference;
             this.moduleName = builder.moduleName;
             this.schemaPath = builder.schemaPath;
+            this.isSuitableForBoxing = builder.isSuitableForBoxing;
+            this.parentType = builder.parentType;
         }
 
         @Override
@@ -115,5 +137,11 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
         public String getModuleName() {
             return moduleName;
         }
+
+        @Override
+        public boolean isSuitableForBoxing() {
+            return isSuitableForBoxing;
+        }
     }
+
 }
index d322833ad81ab9c69e8309462779a1f24c1a37fc..66b72cf9e62647a475bc359744bff63b7386f67a 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
 import org.opendaylight.yangtools.sal.binding.model.api.Type
 import org.opendaylight.yangtools.yang.binding.Augmentable
+import org.opendaylight.yangtools.yang.binding.ChildOf
 import org.opendaylight.yangtools.yang.binding.DataObject
 import org.opendaylight.yangtools.yang.binding.Identifiable
 
@@ -225,9 +226,9 @@ class BuilderTemplate extends BaseTemplate {
 
             Â«generateSetters»
 
-            public Â«type.name» build() {
-                return new Â«type.name»«IMPL»(this);
-            }
+            Â«generateBuildMethod»
+
+            Â«generateBuildBoxedMethod»
 
             private static final class Â«type.name»«IMPL» implements Â«type.name» {
 
@@ -251,6 +252,53 @@ class BuilderTemplate extends BaseTemplate {
         }
     '''
 
+    def private generateBuildMethod() '''
+        public Â«type.name» build() {
+            return new Â«type.name»«IMPL»(this);
+        }
+    '''
+
+    def private generateBuildBoxedMethod() {
+        if(type.suitableForBoxing && type.parentType != null && isContainerAndIsNotList(type)) {
+            val parentTypeBuilder = createParentTypeBuilder()
+            if (countMatches(parentTypeBuilder, "org") < 2) {
+                return '''
+                    public Â«type.parentType.importedName» buildBoxed() {
+                        return new Â«parentTypeBuilder»().set«type.name»(build()).build();
+                    }
+                '''
+            }
+        }
+        return ''
+    }
+
+    def private int countMatches(String string, String subString) {
+        if (string.nullOrEmpty || subString.nullOrEmpty) {
+            return 0
+        }
+        var int count = 0;
+        var int idx = 0;
+        while ((idx = string.indexOf(subString, idx)) != -1) {
+            count = count + 1;
+            idx = idx + subString.length();
+        }
+        return count;
+    }
+
+    def private createParentTypeBuilder() {
+        return type.parentType.packageName + "." + type.parentType.importedName + "Builder"
+    }
+
+    def private boolean isContainerAndIsNotList(GeneratedType type) {
+        val isList = implementsIfc(type, Types.parameterizedTypeFor(Types.typeForClass(Identifiable), type))
+        val implementsChildOf = implementsIfc(type, Types.parameterizedTypeFor(Types.typeForClass(ChildOf), type))
+
+        if (implementsChildOf && !isList) {
+            return true
+        }
+        return false;
+    }
+
     /**
      * Generate default constructor and constructor for every implemented interface from uses statements.
      */
diff --git a/code-generator/binding-java-api-generator/src/test/resources/compilation/typedef/mod-box.yang b/code-generator/binding-java-api-generator/src/test/resources/compilation/typedef/mod-box.yang
new file mode 100644 (file)
index 0000000..1334298
--- /dev/null
@@ -0,0 +1,21 @@
+
+module mod-box {
+    yang-version 1;
+    namespace "urn:opendaylight:mod:box";
+    prefix "box";
+
+    revision 2014-08-05 {
+   }
+
+       container cont1 {
+           choice choice1 {
+                       case case1 {
+                               container cont2 {
+                                       leaf leaf1 {
+                                               type string;
+                                       }
+                               }
+                       }
+           }
+       }
+}
diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/BoxableType.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/BoxableType.java
new file mode 100644 (file)
index 0000000..258c53d
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.model.api;
+
+/**
+ * Implementing this interface allows an object to hold information about that if
+ * is generated type suitable for boxing.
+ *
+ * Example:
+ * choice foo-choice {
+ *   case foo-case {
+ *     container foo {
+ *           ...
+ *     }
+ *   }
+ * }
+ *
+ * Suitable type have to implements ChildOf<T>, where !(T instanceof Identifiable) and
+ * T does not place any structural requirements (must/when) on existence/value Foo.
+ */
+public interface BoxableType {
+
+    /**
+     * Check if generated type is suitable for boxing.
+     *
+     * @return true if generated type is suitable for boxing, false otherwise.
+     */
+    boolean isSuitableForBoxing();
+}
index 0e9b51ee741f42bb5952961421d046c7c52efa2a..ef2fdcdd7e6d4e942526937a670a28c5828dccf3 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  * definitions MUST be public, so there is no need to specify the scope of
  * visibility.
  */
-public interface GeneratedType extends Type, DocumentedType {
+public interface GeneratedType extends Type, DocumentedType, BoxableType {
 
     /**
      * Returns the parent type if Generated Type is defined as enclosing type,
index 9756bd209250b207e0689bc841fd1ce5bc185903..ea2ab258e06f12a06e7c2bf8f9ea71bf021f7f39 100644 (file)
@@ -12,16 +12,29 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
 /**
  * Generated Type Builder interface is helper interface for building and
  * defining the GeneratedType.
- * 
+ *
  * @see GeneratedType
  */
 public interface GeneratedTypeBuilder extends GeneratedTypeBuilderBase<GeneratedTypeBuilder> {
 
     /**
      * Returns the <code>new</code> <i>immutable</i> instance of Generated Type.
-     * 
+     *
      * @return the <code>new</code> <i>immutable</i> instance of Generated Type.
      */
     GeneratedType toInstance();
 
+    /**
+     * Set true if generated type is suitable for boxing, false otherwise.
+     *
+     * @param value
+     */
+    public void setSuitableForBoxing(boolean value);
+
+    /**
+     * Set parent for current generated type.
+     *
+     * @param parent
+     */
+    public void setParentType(GeneratedTypeBuilder parent);
 }
index f4052150595da7b4f1043c5c5ac753c901d71ff9..70d0856fb70420784dfd897385a0cf72a9ecae37 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.sal.binding.model.api.type.builder;
 
 import java.util.List;
-
 import org.opendaylight.yangtools.sal.binding.model.api.Constant;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.common.QName;
index f1864ab1b7e5af44810b1dd9a07d5d1e81e52d6a..d48046a48b23bc76cb174d92fe70b0e9d68f686d 100644 (file)
@@ -1299,9 +1299,10 @@ public final class TypeProviderImpl implements TypeProvider {
             }
             typeDefinitionsConcreteDepth.add(unsortedTypeDefinition);
         }
-        // keys are in ascending order
-        for (Map.Entry<Integer, List<TypeDefinition<?>>> entry : typeDefinitionsDepths.entrySet()) {
-            sortedTypeDefinition.addAll(entry.getValue());
+
+        // SortedMap guarantees order corresponding to keys in ascending order
+        for (List<TypeDefinition<?>> v : typeDefinitionsDepths.values()) {
+            sortedTypeDefinition.addAll(v);
         }
 
         return sortedTypeDefinition;
index a22fe9000669ffdb048dc51374e434efc9d1bc44..15e887eb44655c77b23cda83d934afe5e5c1bc10 100644 (file)
         <repository>
             <id>opendaylight-mirror</id>
             <name>opendaylight-mirror</name>
-            <url>http://nexus.opendaylight.org/content/groups/public/</url>
+            <url>${nexusproxy}/groups/public/</url>
             <snapshots>
                 <enabled>false</enabled>
             </snapshots>
         <repository>
             <id>opendaylight-snapshot</id>
             <name>opendaylight-snapshot</name>
-            <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
             <snapshots>
                 <enabled>true</enabled>
             </snapshots>
index b03771d4c49698c676e1feb2f332a6c4257a29fc..c1a4c31d43f1c1b21146fd1dd87f84ff2ae556d9 100644 (file)
@@ -10,13 +10,11 @@ package org.opendaylight.yangtools.yang.data.codec.gson;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.gson.stream.JsonWriter;
-
 import java.io.IOException;
 import java.io.Writer;
 import java.net.URI;
 import java.util.ArrayDeque;
 import java.util.Deque;
-
 import org.opendaylight.yangtools.concepts.Codec;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -28,6 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
  * This implementation will create JSON output as output stream.
@@ -97,6 +96,22 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
         this.tracker = SchemaTracker.create(schemaContext);
     }
 
+    private JSONNormalizedNodeStreamWriter(final SchemaContext schemaContext, final SchemaPath path,
+            final Writer writer, final int indentSize) {
+        this.schemaContext = Preconditions.checkNotNull(schemaContext);
+        this.writer = Preconditions.checkNotNull(writer);
+
+        Preconditions.checkArgument(indentSize >= 0, "Indent size must be non-negative");
+        if (indentSize != 0) {
+            indent = Strings.repeat(" ", indentSize);
+        } else {
+            indent = null;
+        }
+
+        this.codecs = CodecFactory.create(schemaContext);
+        this.tracker = SchemaTracker.create(schemaContext,path);
+    }
+
     /**
      * Create a new stream writer, which writes to the specified {@link Writer}.
      *
@@ -108,6 +123,17 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
         return new JSONNormalizedNodeStreamWriter(schemaContext, writer, 0);
     }
 
+    /**
+     * Create a new stream writer, which writes to the specified {@link Writer}.
+     *
+     * @param schemaContext Schema context
+     * @param writer Output writer
+     * @return A stream writer instance
+     */
+    public static NormalizedNodeStreamWriter create(final SchemaContext schemaContext, SchemaPath path,final Writer writer) {
+        return new JSONNormalizedNodeStreamWriter(schemaContext, path, writer, 0);
+    }
+
     /**
      * Create a new stream writer, which writes to the specified output stream.
      *
@@ -200,9 +226,10 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
     public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
             throws IOException {
         tracker.startListItem(identifier);
-
-        stack.push(new TypeInfo(NodeType.OBJECT, identifier.getNodeType().getNamespace()));
         separateElementFromPreviousElement();
+        stack.push(new TypeInfo(NodeType.OBJECT, identifier.getNodeType().getNamespace()));
+
+
         writeStartObject();
         indentRight();
     }
index a75fd813ed03e8a37d02f14546d40e5b45cf0b79..4a8232e180fea95f6bb212c5c46b69adabd51c2a 100644 (file)
@@ -9,22 +9,22 @@ package org.opendaylight.yangtools.yang.data.impl.codec;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
-
 import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
-
+import java.util.HashSet;
 import javax.xml.stream.XMLStreamWriter;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.AugmentationSchemaProxy;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -91,10 +91,22 @@ public final class SchemaTracker {
 
     private SchemaNode getSchema(final PathArgument name) {
         final Object parent = getParent();
-        Preconditions.checkState(parent instanceof DataNodeContainer);
-
+        SchemaNode schema = null;
         final QName qname = name.getNodeType();
-        final SchemaNode schema = ((DataNodeContainer)parent).getDataChildByName(qname);
+        if(parent instanceof DataNodeContainer) {
+            schema = ((DataNodeContainer)parent).getDataChildByName(qname);
+
+        } else if(parent instanceof ChoiceNode) {
+            for(ChoiceCaseNode caze : ((ChoiceNode) parent).getCases()) {
+                DataSchemaNode potential = caze.getDataChildByName(qname);
+                if(potential != null) {
+                    schema = potential;
+                    break;
+                }
+            }
+        } else {
+            throw new IllegalStateException("Unsupported schema type "+ parent.getClass() +" on stack.");
+        }
         Preconditions.checkArgument(schema != null, "Could not find schema for node %s in %s", qname, parent);
         return schema;
     }
@@ -156,9 +168,15 @@ public final class SchemaTracker {
         final Object parent = getParent();
 
         Preconditions.checkArgument(parent instanceof AugmentationTarget, "Augmentation not allowed under %s", parent);
+        Preconditions.checkArgument(parent instanceof DataNodeContainer, "Augmentation allowed only in DataNodeContainer",parent);
         final AugmentationSchema schema = SchemaUtils.findSchemaForAugment((AugmentationTarget) parent, identifier.getPossibleChildNames());
-        schemaStack.push(schema);
-        return schema;
+        HashSet<DataSchemaNode> realChildSchemas = new HashSet<>();
+        for(DataSchemaNode child : schema.getChildNodes()) {
+            realChildSchemas.add(((DataNodeContainer) parent).getDataChildByName(child.getQName()));
+        }
+        AugmentationSchema resolvedSchema = new AugmentationSchemaProxy(schema, realChildSchemas);
+        schemaStack.push(resolvedSchema);
+        return resolvedSchema;
     }
 
     public AnyXmlSchemaNode anyxmlNode(final NodeIdentifier name) {
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java
new file mode 100644 (file)
index 0000000..5948d00
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.yang.model.util;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+
+import static org.junit.Assert.assertEquals;
+
+public class BaseConstraintsTest {
+
+    @Test
+    public void canCreateConstraints() {
+        Number min = 5;
+        Number max = 99;
+        String description = "Any description";
+        String reference = "any_ref";
+        String reg_exp = "x|z";
+        Optional<String> desc = Optional.of(description);
+        Optional<String> ref = Optional.of(reference);
+
+        LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
+
+        assertEquals("LengthConstraints Get min", min, lengthCons.getMin());
+        assertEquals("LengthConstraints Get max", max, lengthCons.getMax());
+        assertEquals("LengthConstraints Get description", description, lengthCons.getDescription());
+        assertEquals("LengthConstraints Get reference", reference, lengthCons.getReference());
+
+        PatternConstraint patternCons = BaseConstraints.newPatternConstraint(reg_exp, desc, ref);
+
+        assertEquals("PatternConstraints Get regex", reg_exp, patternCons.getRegularExpression());
+        assertEquals("PatternConstraints Get description", description, patternCons.getDescription());
+        assertEquals("PatternConstraints Get reference", reference, patternCons.getReference());
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java
new file mode 100644 (file)
index 0000000..1f0d806
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.yang.model.util;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class BaseTypesTest {
+
+    @Test
+    public void canCreateBaseTypes() {
+        Optional<?> int8 = BaseTypes.defaultBaseTypeFor("int8");
+        assertEquals(Optional.of(Int8.getInstance()), int8);
+
+        Optional<?> int16 = BaseTypes.defaultBaseTypeFor("int16");
+        assertEquals(Optional.of(Int16.getInstance()), int16);
+
+        Optional<?> int32 = BaseTypes.defaultBaseTypeFor("int32");
+        assertEquals(Optional.of(Int32.getInstance()), int32);
+
+        Optional<?> int64 = BaseTypes.defaultBaseTypeFor("int64");
+        assertEquals(Optional.of(Int64.getInstance()), int64);
+
+        Optional<?> int128 = BaseTypes.defaultBaseTypeFor("int128");
+        assertEquals("wrong type", Optional.absent(), int128);
+
+        Optional<?> uint8 = BaseTypes.defaultBaseTypeFor("uint8");
+        assertEquals(Optional.of(Uint8.getInstance()), uint8);
+
+        Optional<?> uint16 = BaseTypes.defaultBaseTypeFor("uint16");
+        assertEquals(Optional.of(Uint16.getInstance()), uint16);
+
+        Optional<?> uint32 =  BaseTypes.defaultBaseTypeFor("uint32");
+        assertEquals(Optional.of(Uint32.getInstance()), uint32);
+
+        Optional<?> uint64 = BaseTypes.defaultBaseTypeFor("uint64");
+        assertEquals(Optional.of(Uint64.getInstance()), uint64);
+
+        Optional<?> uint128 = BaseTypes.defaultBaseTypeFor("uint128");
+        assertEquals("wrong type", Optional.absent(), uint128);
+
+        Optional<?> stringType = BaseTypes.defaultBaseTypeFor("string");
+        assertEquals(Optional.of(StringType.getInstance()), stringType);
+
+        Optional<?> binaryType = BaseTypes.defaultBaseTypeFor("binary");
+        assertEquals(Optional.of(BinaryType.getInstance()), binaryType);
+
+        Optional<?> booleanType = BaseTypes.defaultBaseTypeFor("boolean");
+        assertEquals(Optional.of(BooleanType.getInstance()), booleanType);
+
+        Optional<?> emptyType = BaseTypes.defaultBaseTypeFor("empty");
+        assertEquals(Optional.of(EmptyType.getInstance()), emptyType);
+
+        Optional<?> instance_identifier = BaseTypes.defaultBaseTypeFor("instance_identifier");
+        assertEquals(Optional.absent(), instance_identifier);
+
+        Optional<?> whatever = BaseTypes.defaultBaseTypeFor("whatever");
+        assertEquals("wrong type", Optional.absent(), whatever);
+
+        assertFalse("whatever is not build-in type", BaseTypes.isYangBuildInType("whatever"));
+        assertTrue("int8 is build-in type", BaseTypes.isYangBuildInType("int8"));
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java
new file mode 100644 (file)
index 0000000..90dd72f
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.yang.model.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class BinaryTypeTest {
+
+    @Test
+    public void canCreateBinaryType() {
+        BinaryType binType = BinaryType.getInstance();
+        BinaryType binType1 = BinaryType.getInstance();
+        String stringBinType = binType.toString();
+
+
+        List<LengthConstraint> lengthConstraints = binType.getLengthConstraints();
+        assertTrue(lengthConstraints.toString().contains("max=9223372036854775807"));
+        assertTrue(lengthConstraints.toString().contains("min=0"));
+
+        assertEquals("Default value is []", Collections.EMPTY_LIST, binType.getDefaultValue());
+        assertEquals("CURRENT", Status.CURRENT, binType.getStatus());
+        assertEquals("Base type is null", null, binType.getBaseType());
+        assertEquals("getQName gives BINARY_QNAME", BaseTypes.BINARY_QNAME, binType.getQName());
+        assertEquals("empty string", "", binType.getUnits());
+        assertEquals("getPath gives List of BINARY_QNAME",
+                Collections.singletonList(BaseTypes.BINARY_QNAME), binType.getPath().getPathFromRoot());
+
+        assertTrue("BinType.toString should contain Description", stringBinType.contains(binType.getDescription()));
+        assertTrue("BinType.toString should contain Reference", stringBinType.contains(binType.getReference()));
+
+        assertTrue("binType1 should equal to binType",
+                binType.equals(binType1) && binType1.equals(binType));
+        assertTrue("Hash code of binType and binType1 should be equal",
+                binType.hashCode() == binType1.hashCode());
+        assertEquals("binType should equals to itself", binType, binType);
+        assertFalse("binType shouldn't equal to null", binType.equals(null));
+        assertFalse("binType shouldn't equal to object of other type", binType.equals("str"));
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java
new file mode 100644 (file)
index 0000000..431e666
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.yang.model.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BooleanTypeTest {
+
+    @Test
+    public void canCreateBooleanType() {
+        BooleanType boolType = BooleanType.getInstance();
+        String stringBoolType = boolType.toString();
+
+        assertEquals("getPath gives List of BOOLEAN_QNAME",
+                Collections.singletonList(BaseTypes.BOOLEAN_QNAME), boolType.getPath().getPathFromRoot());
+
+        assertEquals("getQName gives BOOLEAN_QNAME", BaseTypes.BOOLEAN_QNAME, boolType.getQName());
+
+        assertEquals("The boolean built-in type represents a boolean value.", boolType.getDescription());
+
+        String strPath = boolType.getPath().toString();
+        assertTrue("Should contain string of getPath", stringBoolType.contains(strPath));
+
+        assertEquals("Should be empty string", "", boolType.getUnits());
+
+        assertEquals("Base type is null", null, boolType.getBaseType());
+
+        assertEquals("Default value is false", false, boolType.getDefaultValue());
+
+        assertEquals("Status CURRENT", Status.CURRENT, boolType.getStatus());
+
+        assertEquals("Should contain empty list", Collections.EMPTY_LIST, boolType.getUnknownSchemaNodes());
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Decimal64Test.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Decimal64Test.java
new file mode 100644 (file)
index 0000000..8f4e678
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.yang.model.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class Decimal64Test {
+
+    @Test
+    public void canCreateDecimal64() {
+        Integer fractionDig = 2;
+        Decimal64 decimal64 = Decimal64.create(SchemaPath.ROOT, fractionDig);
+
+        assertEquals("Status should be CURRENT", Status.CURRENT, decimal64.getStatus());
+
+        assertEquals("Default value should be null", null, decimal64.getDefaultValue());
+
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, decimal64.getUnknownSchemaNodes());
+
+        assertEquals("Should be null", null, decimal64.getBaseType());
+
+        assertNotEquals("Description is not null", null, decimal64.getDescription());
+
+        assertNotEquals("Reference is not null", null, decimal64.getReference());
+
+        assertEquals("Should be empty string", "", decimal64.getUnits());
+
+        assertTrue("Should contain factionDigits=2", decimal64.toString().contains("fractionDigits="+fractionDig));
+
+        assertEquals("Should get farctionDig", fractionDig, decimal64.getFractionDigits());
+
+        assertEquals("Should be empty list",
+                Collections.EMPTY_LIST, decimal64.getPath().getPathFromRoot());
+
+        assertEquals("Should be DECIMAL64_QNAME", BaseTypes.DECIMAL64_QNAME, decimal64.getQName());
+
+        assertTrue("Should contain max", decimal64.getRangeConstraints().toString().contains("max=922337203685477580.7"));
+        assertTrue("Should contain min", decimal64.getRangeConstraints().toString().contains("min=-922337203685477580.8"));
+
+        Decimal64 decimal641 = decimal64;
+        assertTrue("Hash code of decimal64 and decimal641 should be equal",
+                    decimal64.hashCode() == decimal641.hashCode());
+
+        assertFalse("Decimal64 shouldn't equal to null", decimal64.equals(null));
+        assertEquals("Decimal64 should equals to itself", decimal64, decimal64);
+        assertFalse("Decimal64 shouldn't equal to object of other type", decimal64.equals("str"));
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java
new file mode 100644 (file)
index 0000000..f892483
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.yang.model.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+public class EmptyTypeTest {
+
+    @Test
+    public void canCreateEmptyType() {
+        EmptyType emptyType = EmptyType.getInstance();
+
+        assertEquals("QName", BaseTypes.EMPTY_QNAME, emptyType.getQName());
+        assertEquals("Path", Collections.singletonList(BaseTypes.EMPTY_QNAME),
+                emptyType.getPath().getPathFromRoot());
+        assertEquals("BaseType", null, emptyType.getBaseType());
+        assertEquals("DefaultValue", null, emptyType.getDefaultValue());
+        assertEquals("Status", Status.CURRENT, emptyType.getStatus());
+        assertTrue("Reference", emptyType.getReference().contains("rfc6020"));
+        assertEquals("Units", null, emptyType.getUnits());
+        assertNotEquals("Description is not null", null, emptyType.getDescription());
+        assertEquals("UnknownSchemaNodes", Collections.EMPTY_LIST, emptyType.getUnknownSchemaNodes());
+        assertTrue("toString", emptyType.toString().contains("empty"));
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ExtendedTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ExtendedTypeTest.java
new file mode 100644 (file)
index 0000000..3eb7a30
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.yang.model.util;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+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.LengthConstraint;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class ExtendedTypeTest {
+    @Test
+    public void canCreateExtendedType() {
+        String namespace = "TestType";
+        String revision = "2014-08-26";
+        String localName = "testType";
+        QName testType = QName.create(namespace, revision, localName);
+        Int32 int32 = Int32.getInstance();
+        String description = "This type is used for testing purpose";
+        Optional<String> desc = Optional.of(description);
+        String reference = "Test Reference";
+        Optional<String> ref = Optional.of(reference);
+
+        ExtendedType.Builder extendedTypeBuilder = ExtendedType.builder(testType, int32, desc, ref, SchemaPath.ROOT);
+
+        int defValue = 12;
+        extendedTypeBuilder.defaultValue(defValue);
+
+        extendedTypeBuilder.status(Status.OBSOLETE);
+        extendedTypeBuilder.addedByUses(false);
+
+        int digits = 2;
+        extendedTypeBuilder.fractionDigits(digits);
+
+        String units = "KiloTest";
+        extendedTypeBuilder.units(units);
+
+        Number min = 3;
+        Number max = 15;
+        LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
+        extendedTypeBuilder.lengths(Collections.singletonList(lengthCons));
+
+        ExtendedType extendedType = extendedTypeBuilder.build();
+
+        assertEquals("BaseType is int32", int32, extendedType.getBaseType());
+        assertEquals("Description", description, extendedType.getDescription());
+        assertEquals("Reference", reference, extendedType.getReference());
+        assertEquals("Path", SchemaPath.ROOT, extendedType.getPath());
+        assertEquals("Default Value is 12", defValue, extendedType.getDefaultValue());
+        assertEquals("Status is OBSOLETE", Status.OBSOLETE, extendedType.getStatus());
+        assertFalse("AddedByUses", extendedType.isAddedByUses());
+        assertTrue("should be 2", digits == extendedType.getFractionDigits());
+        assertTrue("Should contain description", extendedType.toString().contains(description));
+        assertEquals("Units", units, extendedType.getUnits());
+        assertEquals("Length Constraints", Collections.singletonList(lengthCons), extendedType.getLengthConstraints());
+        assertTrue("Should contain name of type", extendedType.getQName().toString().contains(localName));
+
+        assertEquals("extendedType should equals to itself",extendedType, extendedType);
+        assertFalse("extendedType shouldn't equal to null", extendedType.equals(null));
+        assertTrue("Hash code of unionType should be equal to itself",
+                extendedType.hashCode() == extendedType.hashCode());
+
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/UnionTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/UnionTypeTest.java
new file mode 100644 (file)
index 0000000..9a2f913
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.yang.model.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class UnionTypeTest {
+
+    @Test
+    public void canCreateUnion() {
+        List<TypeDefinition<?>> listTypes = new ArrayList<>();
+        Int32 int32 = Int32.getInstance();
+        listTypes.add(int32);
+        UnionType unionType = UnionType.create(listTypes);
+
+        assertEquals("GetUnits should be null", null, unionType.getUnits());
+        assertTrue("String should contain int32", unionType.toString().contains("int32"));
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, unionType.getUnknownSchemaNodes());
+        assertNotEquals("Description should not be null", null, unionType.getDescription());
+        assertNotEquals("Ref should not be null", null, unionType.getReference());
+        assertEquals("Should be CURRENT", Status.CURRENT, unionType.getStatus());
+        assertEquals("Should be int32 in list", Collections.singletonList(int32), unionType.getTypes());
+        assertEquals("Base type should be null", null, unionType.getBaseType());
+        assertEquals("Default value should be null", null, unionType.getDefaultValue());
+        assertEquals("Should be same as list of BaseTypes",
+                Collections.singletonList(BaseTypes.UNION_QNAME), unionType.getPath().getPathFromRoot());
+        assertEquals("Should be BaseTypes", BaseTypes.UNION_QNAME, unionType.getQName());
+
+        assertEquals("unionType should equals to itself", unionType, unionType);
+        assertFalse("unionType shouldn't equal to null", unionType.equals(null));
+        assertTrue("Hash code of unionType should be equal to itself",
+                unionType.hashCode() == unionType.hashCode());
+    }
+
+}
\ No newline at end of file
index c1b004dfd289baf1dbb6839b733cfe3a65ed23bd..3484b79fc342ad072c911e170fd1aed653c7a15e 100644 (file)
@@ -34,6 +34,13 @@ unknown_statement : (YIN_ELEMENT_KEYWORD | YANG_VERSION_KEYWORD | WHEN_KEYWORD |
                     ANYXML_KEYWORD | IDENTIFIER) string? (SEMICOLON | (LEFT_BRACE (unknown_statement | identifier_stmt)* RIGHT_BRACE)*);
 
 stmtend : (SEMICOLON) | (LEFT_BRACE identifier_stmt? RIGHT_BRACE);
+
+/* DO NOT replace stmtsep in rest of grammar with identifier_stmt!!! It might seems as code duplicity here, but this one is necessary.
+   Body of identifier_stmt generated from this grammar in YangParserListener is implemented in YangParserListenerImpl.
+   To ensure that all of the identifier_stmts will be resolved correctly the YangParserListenerImpl contains code that handles
+   specifcly identifier_stmts -> i.e. transforms identifier_stmt into QName. The stmtsep is used for parsing extension statements
+   placed outside of body_stmt.
+ */
 stmtsep : IDENTIFIER string? (stmtend | (LEFT_BRACE unknown_statement* RIGHT_BRACE));
 deviate_replace_stmt : DEVIATE_KEYWORD string /* REPLACE_KEYWORD */ (SEMICOLON | (LEFT_BRACE (identifier_stmt |type_stmt | units_stmt | default_stmt | config_stmt | mandatory_stmt | min_elements_stmt | max_elements_stmt )* RIGHT_BRACE));
 deviate_delete_stmt : DEVIATE_KEYWORD string /* DELETE_KEYWORD */ (SEMICOLON | (LEFT_BRACE (identifier_stmt |units_stmt | must_stmt | unique_stmt | default_stmt )* RIGHT_BRACE));
@@ -133,9 +140,9 @@ yang_version_stmt : YANG_VERSION_KEYWORD string stmtend;
 data_def_stmt : container_stmt | leaf_stmt | leaf_list_stmt | list_stmt | choice_stmt | anyxml_stmt | uses_stmt;
 body_stmts : (( identifier_stmt| extension_stmt | feature_stmt | identity_stmt | typedef_stmt | grouping_stmt | data_def_stmt | augment_stmt | rpc_stmt | notification_stmt | deviation_stmt) )*;
 revision_stmts :  (revision_stmt )* (stmtsep)*;
-linkage_stmts : (import_stmt stmtsep? | include_stmt stmtsep?)*;
-meta_stmts : (organization_stmt stmtsep? | contact_stmt stmtsep? | description_stmt stmtsep? | reference_stmt stmtsep?)*;
-submodule_header_stmts : (yang_version_stmt stmtsep? | belongs_to_stmt stmtsep?)+ ;
-module_header_stmts :  (yang_version_stmt stmtsep? | namespace_stmt stmtsep? | prefix_stmt stmtsep?)+ ;
+linkage_stmts : (import_stmt stmtsep* | include_stmt stmtsep*)*;
+meta_stmts : (organization_stmt stmtsep* | contact_stmt stmtsep* | description_stmt stmtsep* | reference_stmt stmtsep*)*;
+submodule_header_stmts : (yang_version_stmt stmtsep* | belongs_to_stmt stmtsep*)+ ;
+module_header_stmts :  (yang_version_stmt stmtsep* | namespace_stmt stmtsep* | prefix_stmt stmtsep*)+ ;
 submodule_stmt : SUBMODULE_KEYWORD string LEFT_BRACE  submodule_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
-module_stmt : MODULE_KEYWORD string LEFT_BRACE stmtsep? module_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
\ No newline at end of file
+module_stmt : MODULE_KEYWORD string LEFT_BRACE stmtsep* module_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
\ No newline at end of file
index 319f189043f4743daedc326834caeea4c2e12d1d..5a4bb3df25aa69fd2324b7def8dd1a59c69339ee 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.Multimaps;
 import com.google.common.collect.SetMultimap;
-
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -28,9 +27,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
-
 import javax.annotation.concurrent.Immutable;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
@@ -202,7 +199,7 @@ final class SchemaContextImpl implements SchemaContext {
 
     @Override
     public SchemaPath getPath() {
-        return null;
+        return SchemaPath.ROOT;
     }
 
     @Override
index f36fc15b073439b90d48e3bf4bdb6922d0b5b83d..01c1dd97247b51f645c6bd9812d50a4c509c71ad 100644 (file)
@@ -1,7 +1,19 @@
 module ext-use {
+    ext:id "http://opendaylight.org";
     yang-version 1;
+    ext:id "http://opendaylight.org";
+
+    ext:id2 "73354";
+    ext:name "test-name";
+
     namespace "urn:simple.extension.use";
+    ext:id "http://opendaylight.org";
+
+    ext:name "test-name";
+
     prefix "ext-use";
+    ext:id "http://opendaylight.org";
+    ext:name "test-name";
 
     import ext-typedef { prefix "ext"; }