Merge "Bug 2363, Bug 2205. Beta version of LeafRefContext tree computation"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 23 Apr 2015 19:37:19 +0000 (19:37 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 Apr 2015 19:37:19 +0000 (19:37 +0000)
110 files changed:
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeCandidateNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeCandidates.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/AugmentationNodeBaseParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/BaseDispatcherParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/ContainerNodeBaseParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/ListEntryNodeBaseParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/AugmentationNodeDomParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/ContainerNodeDomParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactory.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/MapEntryNodeDomParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeTip.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperation.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java [new file with mode: 0644]
yang/yang-data-impl/src/test/resources/filter-test.yang [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaSourceFilter.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/GroupingUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/TypeUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/BasicValidations.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/URLSchemaContextResolver.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModuleMap.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModifierImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementDefinitionContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/CaseStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ExtensionStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/PrefixStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UsesStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedDataNodeContainer.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedNode.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AnyXmlEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ContainerEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ExtensionEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IdentityEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/InputEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/OutputEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/RpcEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/YangFileStatementSource.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentTest.java [moved from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/augment/AugmentTest.java with 50% similarity]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportBasicTestStatementSource.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/KeyTest.java [moved from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/key/KeyTest.java with 64% similarity]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangFileStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/augment/TestAugmentSource.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/key/TestKeySource.java [deleted file]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/imported.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/foobar.yang [moved from yang/yang-parser-impl/src/test/resources/semantic-statement-parser/foo.yang with 87% similarity]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/simple-nodes-semantic.yang
yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/aug-root.yang

index dea39fdb4743e76cede31bbc856959ce723a9abd..bfdfdadc80d8721372e829c7b226eb58627e5cf1 100644 (file)
@@ -267,7 +267,7 @@ public final class QName implements Immutable, Serializable, Comparable<QName> {
      *            Local name part of QName. MUST NOT BE null.
      * @return
      * @throws NullPointerException
-     *             If any of paramaters is null.
+     *             If any of parameters is null.
      * @throws IllegalArgumentException
      *             If <code>namespace</code> is not valid URI or
      *             <code>revision</code> is not according to format
@@ -275,15 +275,34 @@ public final class QName implements Immutable, Serializable, Comparable<QName> {
      */
     public static QName create(final String namespace, final String revision, final String localName)
             throws IllegalArgumentException {
-        final URI namespaceUri;
+        final URI namespaceUri = parseNamespace(namespace);
+        final Date revisionDate = parseRevision(revision);
+        return create(namespaceUri, revisionDate, localName);
+    }
+
+    private static URI parseNamespace(final String namespace) {
         try {
-            namespaceUri = new URI(namespace);
+            return new URI(namespace);
         } catch (URISyntaxException ue) {
             throw new IllegalArgumentException(String.format("Namespace '%s' is not a valid URI", namespace), ue);
         }
+    }
 
-        Date revisionDate = parseRevision(revision);
-        return create(namespaceUri, revisionDate, localName);
+    /**
+     * Creates new QName.
+     *
+     * @param namespace
+     *            Namespace of QName, MUST NOT BE Null.
+     * @param localName
+     *            Local name part of QName. MUST NOT BE null.
+     * @return
+     * @throws NullPointerException
+     *             If any of parameters is null.
+     * @throws IllegalArgumentException
+     *             If <code>namespace</code> is not valid URI.
+     */
+    public static QName create(final String namespace, final String localName) throws IllegalArgumentException {
+        return create(parseNamespace(namespace), null, localName);
     }
 
     @Override
index 5863b31168a0d1a21323a88091dfe90041581e7e..53b8343cd18760a5977a2681c879672c10dcbfde 100644 (file)
@@ -71,12 +71,16 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
  * @see <a href="http://tools.ietf.org/html/rfc6020#section-9.13">RFC6020</a>
  */
 public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier>, Immutable, Serializable {
+    /**
+     * An empty {@link YangInstanceIdentifier}. It corresponds to the path of the conceptual
+     * root of the YANG namespace.
+     */
+    public static final YangInstanceIdentifier EMPTY = trustedCreate(Collections.<PathArgument>emptyList());
     @SuppressWarnings("rawtypes")
     private static final AtomicReferenceFieldUpdater<YangInstanceIdentifier, ImmutableList> LEGACYPATH_UPDATER =
             AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, ImmutableList.class, "legacyPath");
     private static final AtomicReferenceFieldUpdater<YangInstanceIdentifier, String> TOSTRINGCACHE_UPDATER =
             AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, String.class, "toStringCache");
-    private static final YangInstanceIdentifier EMPTY = trustedCreate(Collections.<PathArgument>emptyList());
     private static final Field PATHARGUMENTS_FIELD;
 
     private static final long serialVersionUID = 3L;
index a1db3a4a4f4453efcc92595116cd3654816a37c7..95f52d55271c2bea296b21b67bf81cd6f5aa3dfc 100644 (file)
@@ -53,18 +53,18 @@ public interface DataTreeCandidateNode {
     @Nonnull ModificationType getModificationType();
 
     /**
-     * Return the before-image of data corresponding to the node.
+     * Return the after-image of data corresponding to the node.
      *
-     * @return Node data as they were present in the tree before
-     *         the modification was applied.
+     * @return Node data as they will be present in the tree after
+     *         the modification is applied.
      */
-    Optional<NormalizedNode<?, ?>> getDataAfter();
+    @Nonnull Optional<NormalizedNode<?, ?>> getDataAfter();
 
     /**
-     * Return the after-image of data corresponding to the node.
+     * Return the before-image of data corresponding to the node.
      *
-     * @return Node data as they will be present in the tree after
-     *         the modification is applied.
+     * @return Node data as they were present in the tree before
+     *         the modification was applied.
      */
-    Optional<NormalizedNode<?, ?>> getDataBefore();
+    @Nonnull Optional<NormalizedNode<?, ?>> getDataBefore();
 }
index 441f92776373383156f78479ff9838a91e578cc1..04e3b204bcbc12f7ae3ab795bb558810e066559b 100644 (file)
@@ -10,12 +10,15 @@ package org.opendaylight.yangtools.yang.data.api.schema.tree;
 import com.google.common.annotations.Beta;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Utility class holding methods useful when dealing with {@link DataTreeCandidate} instances.
  */
 @Beta
 public final class DataTreeCandidates {
+    private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class);
     private DataTreeCandidates() {
         throw new UnsupportedOperationException();
     }
@@ -36,17 +39,21 @@ public final class DataTreeCandidates {
         switch (node.getModificationType()) {
         case DELETE:
             modification.delete(path);
+            LOG.debug("Modification {} deleted path {}", modification, path);
             break;
         case SUBTREE_MODIFIED:
+            LOG.debug("Modification {} modified path {}", modification, path);
             for (DataTreeCandidateNode child : node.getChildNodes()) {
                 applyNode(modification, path.node(child.getIdentifier()), child);
             }
             break;
         case UNMODIFIED:
+            LOG.debug("Modification {} unmodified path {}", modification, path);
             // No-op
             break;
         case WRITE:
             modification.write(path, node.getDataAfter().get());
+            LOG.debug("Modification {} written path {}", modification, path);
             break;
         default:
             throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
index 0fd44f478068ab4415afdc656cc04e89776a1b33..c7013c4a706ed9019cd4b0f31600a03fc2310224 100644 (file)
@@ -7,7 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
@@ -15,6 +20,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
@@ -22,6 +28,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableCo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public final class ImmutableNodes {
 
@@ -83,4 +91,46 @@ public final class ImmutableNodes {
     public static ChoiceNode choiceNode(final QName name) {
         return ImmutableChoiceNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(name)).build();
     }
+
+    /**
+     * Convert YangInstanceIdentifier into a normalized node structure
+     *
+     * @param ctx schema context to used during serialization
+     * @param id instance identifier to convert to node structure starting from root
+     * @return serialized normalized node for provided instance Id
+     */
+    public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id) {
+        return fromInstanceId(ctx, id, Optional.<NormalizedNode<?, ?>>absent(), Optional.<Map.Entry<QName, ModifyAction>>absent());
+    }
+
+    /**
+     * Convert YangInstanceIdentifier into a normalized node structure
+     *
+     * @param ctx schema context to used during serialization
+     * @param id instance identifier to convert to node structure starting from root
+     * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided instance Id
+     * @return serialized normalized node for provided instance Id with overridden last child.
+     */
+    public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final NormalizedNode<?, ?> deepestElement) {
+        return fromInstanceId(ctx, id, Optional.<NormalizedNode<?, ?>>of(deepestElement), Optional.<Map.Entry<QName, ModifyAction>>absent());
+    }
+
+    /**
+     * Convert YangInstanceIdentifier into a normalized node structure
+     *
+     * @param ctx schema context to used during serialization
+     * @param id instance identifier to convert to node structure starting from root
+     * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided instance Id
+     * @param operation modify operation attribute to be added to the deepest child. QName is the operation attribute key and ModifyAction is the value.
+     * @return serialized normalized node for provided instance Id with (optionally) overridden last child and (optionally) marked with specific operation attribute.
+     */
+    public static NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional<NormalizedNode<?, ?>> deepestElement, final Optional<Map.Entry<QName, ModifyAction>> operation) {
+        Preconditions.checkNotNull(ctx);
+        Preconditions.checkNotNull(id);
+        final YangInstanceIdentifier.PathArgument topLevelElement = id.getPathArguments().iterator().next();
+        final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType());
+        Preconditions.checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
+        final InstanceIdToNodes<?> instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
+        return instanceIdToNodes.create(id, deepestElement, operation);
+    }
 }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java
new file mode 100644 (file)
index 0000000..28e8d89
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2015 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.data.impl.schema;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.AttributesBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
+
+/**
+* Base strategy for converting an instance identifier into a normalized node structure for container-like types.
+*/
+abstract class InstanceIdToCompositeNodes<T extends YangInstanceIdentifier.PathArgument> extends
+        InstanceIdToNodes<T> {
+
+    protected InstanceIdToCompositeNodes(final T identifier) {
+        super(identifier);
+    }
+
+    private static YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchema augmentation) {
+        final ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder();
+        for (final DataSchemaNode child : augmentation.getChildNodes()) {
+            potentialChildren.add(child.getQName());
+        }
+        return new YangInstanceIdentifier.AugmentationIdentifier(potentialChildren.build());
+    }
+
+    private static DataNodeContainer augmentationProxy(final AugmentationSchema augmentation, final DataNodeContainer schema) {
+        final Set<DataSchemaNode> children = new HashSet<>();
+        for (final DataSchemaNode augNode : augmentation.getChildNodes()) {
+            children.add(schema.getDataChildByName(augNode.getQName()));
+        }
+        return new EffectiveAugmentationSchema(augmentation, children);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public final NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Map.Entry<QName,ModifyAction>> operation) {
+        checkNotNull(instanceId);
+        final Iterator<YangInstanceIdentifier.PathArgument> iterator = instanceId.getPathArguments().iterator();
+        final YangInstanceIdentifier.PathArgument legacyData = iterator.next();
+
+        if (!isMixin(this) && getIdentifier().getNodeType() != null) {
+            checkArgument(getIdentifier().getNodeType().equals(legacyData.getNodeType()),
+                    "Node QName must be %s was %s", getIdentifier().getNodeType(), legacyData.getNodeType());
+        }
+        final NormalizedNodeContainerBuilder builder = createBuilder(legacyData);
+
+        if (iterator.hasNext()) {
+            final YangInstanceIdentifier.PathArgument childPath = iterator.next();
+            final InstanceIdToNodes childOp = getChildOperation(childPath);
+
+            final YangInstanceIdentifier childId = YangInstanceIdentifier.create(Iterables.skip(instanceId.getPathArguments(), 1));
+            builder.addChild(childOp.create(childId, lastChild, operation));
+        } else {
+            if(lastChild.isPresent()) {
+                builder.withValue(Lists.newArrayList((Collection<?>) lastChild.get().getValue()));
+            }
+            if(operation.isPresent()) {
+                Preconditions.checkArgument(builder instanceof AttributesBuilder<?>);
+                addModifyOpIfPresent(operation, ((AttributesBuilder<?>) builder));
+            }
+        }
+
+        return builder.build();
+    }
+
+    private InstanceIdToNodes getChildOperation(final YangInstanceIdentifier.PathArgument childPath) {
+        final InstanceIdToNodes childOp;
+        try {
+            childOp = getChild(childPath);
+        } catch (final RuntimeException e) {
+            throw new IllegalArgumentException(String.format("Failed to process child node %s", childPath), e);
+        }
+        checkArgument(childOp != null, "Node %s is not allowed inside %s", childPath, getIdentifier());
+        return childOp;
+    }
+
+    @SuppressWarnings("rawtypes")
+    protected abstract NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode);
+
+    static abstract class DataContainerNormalizationOperation<T extends YangInstanceIdentifier.PathArgument> extends
+            InstanceIdToCompositeNodes<T> {
+
+        private final DataNodeContainer schema;
+        private final Map<YangInstanceIdentifier.PathArgument, InstanceIdToNodes<?>> byArg;
+
+        protected DataContainerNormalizationOperation(final T identifier, final DataNodeContainer schema) {
+            super(identifier);
+            this.schema = schema;
+            this.byArg = new ConcurrentHashMap<>();
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final YangInstanceIdentifier.PathArgument child) {
+            InstanceIdToNodes<?> potential = byArg.get(child);
+            if (potential != null) {
+                return potential;
+            }
+            potential = fromLocalSchema(child);
+            return register(potential);
+        }
+
+        private InstanceIdToNodes<?> fromLocalSchema(final YangInstanceIdentifier.PathArgument child) {
+            if (child instanceof YangInstanceIdentifier.AugmentationIdentifier) {
+                return fromSchemaAndQNameChecked(schema, ((YangInstanceIdentifier.AugmentationIdentifier) child).getPossibleChildNames()
+                        .iterator().next());
+            }
+            return fromSchemaAndQNameChecked(schema, child.getNodeType());
+        }
+
+        private InstanceIdToNodes<?> register(final InstanceIdToNodes<?> potential) {
+            if (potential != null) {
+                byArg.put(potential.getIdentifier(), potential);
+            }
+            return potential;
+        }
+    }
+
+    static final class ListItemNormalization extends
+            DataContainerNormalizationOperation<YangInstanceIdentifier.NodeIdentifierWithPredicates> {
+
+        protected ListItemNormalization(final YangInstanceIdentifier.NodeIdentifierWithPredicates identifier, final ListSchemaNode schema) {
+            super(identifier, schema);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument currentArg) {
+            final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
+                    .mapEntryBuilder().withNodeIdentifier((YangInstanceIdentifier.NodeIdentifierWithPredicates) currentArg);
+            for (final Map.Entry<QName, Object> keyValue : ((YangInstanceIdentifier.NodeIdentifierWithPredicates) currentArg).getKeyValues().entrySet()) {
+                builder.addChild(Builders.leafBuilder()
+                        //
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(keyValue.getKey())).withValue(keyValue.getValue())
+                        .build());
+            }
+            return builder;
+        }
+
+    }
+
+    static final class UnkeyedListItemNormalization extends DataContainerNormalizationOperation<YangInstanceIdentifier.NodeIdentifier> {
+
+        protected UnkeyedListItemNormalization(final ListSchemaNode schema) {
+            super(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()), schema);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.unkeyedListEntryBuilder().withNodeIdentifier(getIdentifier());
+        }
+
+    }
+
+    static final class ContainerTransformation extends DataContainerNormalizationOperation<YangInstanceIdentifier.NodeIdentifier> {
+
+        protected ContainerTransformation(final ContainerSchemaNode schema) {
+            super(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()), schema);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.containerBuilder().withNodeIdentifier(getIdentifier());
+        }
+    }
+
+    static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
+
+
+        public OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
+            super(potential);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier());
+        }
+    }
+
+    static class UnorderedLeafListMixinNormalization extends InstanceIdToCompositeNodes<YangInstanceIdentifier.NodeIdentifier> implements MixinNormalizationOp {
+
+        private final InstanceIdToNodes<?> innerOp;
+
+        public UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
+            super(new YangInstanceIdentifier.NodeIdentifier(potential.getQName()));
+            innerOp = new InstanceIdToSimpleNodes.LeafListEntryNormalization(potential);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier());
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final YangInstanceIdentifier.PathArgument child) {
+            if (child instanceof YangInstanceIdentifier.NodeWithValue) {
+                return innerOp;
+            }
+            return null;
+        }
+    }
+
+    static final class AugmentationNormalization extends DataContainerNormalizationOperation<YangInstanceIdentifier.AugmentationIdentifier> implements MixinNormalizationOp {
+
+        public AugmentationNormalization(final AugmentationSchema augmentation, final DataNodeContainer schema) {
+            super(augmentationIdentifierFrom(augmentation), augmentationProxy(augmentation, schema));
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.augmentationBuilder().withNodeIdentifier(getIdentifier());
+        }
+    }
+
+    static class UnorderedMapMixinNormalization extends InstanceIdToCompositeNodes<YangInstanceIdentifier.NodeIdentifier> implements MixinNormalizationOp {
+
+        private final ListItemNormalization innerNode;
+
+        public UnorderedMapMixinNormalization(final ListSchemaNode list) {
+            super(new YangInstanceIdentifier.NodeIdentifier(list.getQName()));
+            this.innerNode = new ListItemNormalization(new YangInstanceIdentifier.NodeIdentifierWithPredicates(list.getQName(),
+                    Collections.<QName, Object>emptyMap()), list);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.mapBuilder().withNodeIdentifier(getIdentifier());
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final YangInstanceIdentifier.PathArgument child) {
+            if (child.getNodeType().equals(getIdentifier().getNodeType())) {
+                return innerNode;
+            }
+            return null;
+        }
+    }
+
+    static final class OrderedMapMixinNormalization extends UnorderedMapMixinNormalization {
+
+        public OrderedMapMixinNormalization(final ListSchemaNode list) {
+            super(list);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier());
+        }
+
+    }
+
+    static class ChoiceNodeNormalization extends InstanceIdToCompositeNodes<YangInstanceIdentifier.NodeIdentifier> implements MixinNormalizationOp {
+
+        private final ImmutableMap<YangInstanceIdentifier.PathArgument, InstanceIdToNodes<?>> byArg;
+
+        protected ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
+            super(new YangInstanceIdentifier.NodeIdentifier(schema.getQName()));
+            final ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder();
+
+            for (final ChoiceCaseNode caze : schema.getCases()) {
+                for (final DataSchemaNode cazeChild : caze.getChildNodes()) {
+                    final InstanceIdToNodes<?> childOp = fromDataSchemaNode(cazeChild);
+                    byArgBuilder.put(childOp.getIdentifier(), childOp);
+                }
+            }
+            byArg = byArgBuilder.build();
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final YangInstanceIdentifier.PathArgument child) {
+            return byArg.get(child);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final YangInstanceIdentifier.PathArgument compositeNode) {
+            return Builders.choiceBuilder().withNodeIdentifier(getIdentifier());
+        }
+    }
+}
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java
new file mode 100644 (file)
index 0000000..0185f57
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2015 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.data.impl.schema;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.FluentIterable;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map.Entry;
+import javax.xml.transform.dom.DOMSource;
+import org.opendaylight.yangtools.concepts.Identifiable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+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.AnyXmlNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.AttributesBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+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.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+
+/**
+ * Base strategy for converting an instance identifier into a normalized node structure.
+ * Use provided static methods for generic YangInstanceIdentifier -> NormalizedNode translation in ImmutableNodes.
+ */
+abstract class InstanceIdToNodes<T extends PathArgument> implements Identifiable<T> {
+
+    private final T identifier;
+
+    @Override
+    public T getIdentifier() {
+        return identifier;
+    }
+
+    protected InstanceIdToNodes(final T identifier) {
+        this.identifier = identifier;
+    }
+
+    /**
+     * Build a strategy for the next path argument
+     *
+     * @param child child identifier
+     * @return transformation strategy for a specific child
+     */
+    abstract InstanceIdToNodes<?> getChild(final PathArgument child);
+
+    /**
+     *
+     * Convert instance identifier into a NormalizedNode structure
+     *
+     * @param instanceId Instance identifier to transform into NormalizedNodes
+     * @param deepestChild Optional normalized node to be inserted as the last child
+     * @param operation Optional modify operation to be set on the last child
+     * @return NormalizedNode structure corresponding to submitted instance ID
+     */
+    abstract NormalizedNode<?, ?> create(YangInstanceIdentifier instanceId, Optional<NormalizedNode<?, ?>> deepestChild, Optional<Entry<QName,ModifyAction>> operation);
+
+
+    public void addModifyOpIfPresent(final Optional<Entry<QName,ModifyAction>> operation, final AttributesBuilder<?> builder) {
+        if(operation.isPresent()) {
+            builder.withAttributes(Collections.singletonMap(operation.get().getKey(), modifyOperationToXmlString(operation.get().getValue())));
+        }
+    }
+
+    public static String modifyOperationToXmlString(final ModifyAction operation) {
+        return operation.name().toLowerCase();
+    }
+
+    static boolean isMixin(final InstanceIdToNodes<?> op) {
+        return op instanceof MixinNormalizationOp;
+    }
+
+    /**
+     * Marker interface for Mixin nodes normalization operations
+     */
+    interface MixinNormalizationOp {}
+
+
+    private static class UnkeyedListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> implements MixinNormalizationOp {
+
+        private final UnkeyedListItemNormalization innerNode;
+
+        public UnkeyedListMixinNormalization(final ListSchemaNode list) {
+            super(new NodeIdentifier(list.getQName()));
+            this.innerNode = new UnkeyedListItemNormalization(list);
+        }
+
+        @Override
+        protected NormalizedNodeContainerBuilder<?, ?, ?, ?> createBuilder(final PathArgument compositeNode) {
+            return Builders.unkeyedListBuilder().withNodeIdentifier(getIdentifier());
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final PathArgument child) {
+            if (child.getNodeType().equals(getIdentifier().getNodeType())) {
+                return innerNode;
+            }
+            return null;
+        }
+    }
+
+    private static class AnyXmlNormalization extends InstanceIdToNodes<NodeIdentifier> {
+
+        protected AnyXmlNormalization(final AnyXmlSchemaNode schema) {
+            super(new NodeIdentifier(schema.getQName()));
+        }
+
+        @Override
+        public InstanceIdToNodes<?> getChild(final PathArgument child) {
+            return null;
+        }
+
+        @Override
+        public NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<Entry<QName,ModifyAction>> operation) {
+            if(deepestChild.isPresent()) {
+                Preconditions.checkState(deepestChild instanceof AnyXmlNode);
+                final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
+                        Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier()).withValue(((AnyXmlNode) deepestChild).getValue());
+                addModifyOpIfPresent(operation, anyXmlBuilder);
+                return anyXmlBuilder.build();
+            }
+
+            final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> builder =
+                    Builders.anyXmlBuilder().withNodeIdentifier(getIdentifier());
+            addModifyOpIfPresent(operation, builder);
+            return builder.build();
+        }
+
+    }
+
+    private static Optional<DataSchemaNode> findChildSchemaNode(final DataNodeContainer parent, final QName child) {
+        DataSchemaNode potential = parent.getDataChildByName(child);
+        if (potential == null) {
+            final Iterable<ChoiceSchemaNode> choices = FluentIterable.from(parent.getChildNodes()).filter(ChoiceSchemaNode.class);
+            potential = findChoice(choices, child);
+        }
+        return Optional.fromNullable(potential);
+    }
+
+    static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
+        final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
+        Preconditions.checkArgument(potential.isPresent(),
+                "Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema, schema.getChildNodes());
+
+        final DataSchemaNode result = potential.get();
+        // We try to look up if this node was added by augmentation
+        if ((schema instanceof DataSchemaNode) && result.isAugmenting()) {
+            return fromAugmentation(schema, (AugmentationTarget) schema, result);
+        }
+        return fromDataSchemaNode(result);
+    }
+
+    private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
+        ChoiceSchemaNode foundChoice = null;
+        choiceLoop:
+        for (final ChoiceSchemaNode choice : choices) {
+            for (final ChoiceCaseNode caze : choice.getCases()) {
+                if (findChildSchemaNode(caze, child).isPresent()) {
+                    foundChoice = choice;
+                    break choiceLoop;
+                }
+            }
+        }
+        return foundChoice;
+    }
+
+    /**
+     * Returns a SchemaPathUtil for provided child node
+     * <p/>
+     * If supplied child is added by Augmentation this operation returns
+     * a SchemaPathUtil for augmentation,
+     * otherwise returns a SchemaPathUtil for child as
+     * call for {@link #fromDataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)}.
+     */
+    private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
+                                                          final AugmentationTarget parentAug, final DataSchemaNode child) {
+        AugmentationSchema augmentation = null;
+        for (final AugmentationSchema aug : parentAug.getAvailableAugmentations()) {
+            final DataSchemaNode potential = aug.getDataChildByName(child.getQName());
+            if (potential != null) {
+                augmentation = aug;
+                break;
+            }
+
+        }
+        if (augmentation != null) {
+            return new InstanceIdToCompositeNodes.AugmentationNormalization(augmentation, parent);
+        } else {
+            return fromDataSchemaNode(child);
+        }
+    }
+
+    static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
+        if (potential instanceof ContainerSchemaNode) {
+            return new InstanceIdToCompositeNodes.ContainerTransformation((ContainerSchemaNode) potential);
+        } else if (potential instanceof ListSchemaNode) {
+            return fromListSchemaNode((ListSchemaNode) potential);
+        } else if (potential instanceof LeafSchemaNode) {
+            return new InstanceIdToSimpleNodes.LeafNormalization((LeafSchemaNode) potential);
+        } else if (potential instanceof ChoiceSchemaNode) {
+            return new InstanceIdToCompositeNodes.ChoiceNodeNormalization((ChoiceSchemaNode) potential);
+        } else if (potential instanceof LeafListSchemaNode) {
+            return fromLeafListSchemaNode((LeafListSchemaNode) potential);
+        } else if (potential instanceof AnyXmlSchemaNode) {
+            return new AnyXmlNormalization((AnyXmlSchemaNode) potential);
+        }
+        return null;
+    }
+
+    private static InstanceIdToNodes<?> fromListSchemaNode(final ListSchemaNode potential) {
+        final List<QName> keyDefinition = potential.getKeyDefinition();
+        if (keyDefinition == null || keyDefinition.isEmpty()) {
+            return new UnkeyedListMixinNormalization(potential);
+        }
+        if (potential.isUserOrdered()) {
+            return new InstanceIdToCompositeNodes.OrderedMapMixinNormalization(potential);
+        }
+        return new InstanceIdToCompositeNodes.UnorderedMapMixinNormalization(potential);
+    }
+
+    private static InstanceIdToNodes<?> fromLeafListSchemaNode(final LeafListSchemaNode potential) {
+        if (potential.isUserOrdered()) {
+            return new InstanceIdToCompositeNodes.OrderedLeafListMixinNormalization(potential);
+        }
+        return new InstanceIdToCompositeNodes.UnorderedLeafListMixinNormalization(potential);
+    }
+
+
+}
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java
new file mode 100644 (file)
index 0000000..7a3e86a
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2015 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.data.impl.schema;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+
+/**
+* Base strategy for converting an instance identifier into a normalized node structure for leaf and leaf-list types.
+*/
+abstract class InstanceIdToSimpleNodes<T extends YangInstanceIdentifier.PathArgument> extends InstanceIdToNodes<T> {
+
+    protected InstanceIdToSimpleNodes(final T identifier) {
+        super(identifier);
+    }
+
+    @Override
+    public NormalizedNode<?, ?> create(final YangInstanceIdentifier instanceId, final Optional<NormalizedNode<?, ?>> deepestChild, final Optional<Map.Entry<QName,ModifyAction>> operation) {
+        checkNotNull(instanceId);
+        final YangInstanceIdentifier.PathArgument pathArgument = Iterables.get(instanceId.getPathArguments(), 0);
+        final NormalizedNodeAttrBuilder<? extends YangInstanceIdentifier.PathArgument, Object, ? extends NormalizedNode<? extends YangInstanceIdentifier.PathArgument, Object>> builder = getBuilder(pathArgument);
+
+        if(deepestChild.isPresent()) {
+            builder.withValue(deepestChild.get().getValue());
+        }
+
+        addModifyOpIfPresent(operation, builder);
+        return builder.build();
+    }
+
+    protected abstract NormalizedNodeAttrBuilder<? extends YangInstanceIdentifier.PathArgument, Object, ? extends NormalizedNode<? extends YangInstanceIdentifier.PathArgument, Object>> getBuilder(YangInstanceIdentifier.PathArgument node);
+
+    @Override
+    public InstanceIdToNodes<?> getChild(final YangInstanceIdentifier.PathArgument child) {
+        return null;
+    }
+
+    static final class LeafNormalization extends InstanceIdToSimpleNodes<YangInstanceIdentifier.NodeIdentifier> {
+
+        protected LeafNormalization(final LeafSchemaNode potential) {
+            super(new YangInstanceIdentifier.NodeIdentifier(potential.getQName()));
+        }
+
+        @Override
+        protected NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> getBuilder(final YangInstanceIdentifier.PathArgument node) {
+            return Builders.leafBuilder().withNodeIdentifier(getIdentifier());
+        }
+    }
+
+    static final class LeafListEntryNormalization extends InstanceIdToSimpleNodes<YangInstanceIdentifier.NodeWithValue> {
+
+        public LeafListEntryNormalization(final LeafListSchemaNode potential) {
+            super(new YangInstanceIdentifier.NodeWithValue(potential.getQName(), null));
+        }
+
+        @Override
+        protected NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> getBuilder(final YangInstanceIdentifier.PathArgument node) {
+            Preconditions.checkArgument(node instanceof YangInstanceIdentifier.NodeWithValue);
+            return Builders.leafSetEntryBuilder().withNodeIdentifier((YangInstanceIdentifier.NodeWithValue) node).withValue(((YangInstanceIdentifier.NodeWithValue) node).getValue());
+        }
+
+    }
+}
index 53bdbd84bc53550a6222e3559ef24c7615b327d9..a5c5148548418596d13c1ef26543aa89c527aff4 100644 (file)
@@ -18,10 +18,12 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
@@ -80,6 +82,19 @@ public final class SchemaUtils {
         return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName;
     }
 
+    @Nullable
+    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final boolean strictMode) {
+        if (strictMode) {
+            return findSchemaForChild(schema, qname);
+        }
+
+        Optional<DataSchemaNode> childSchemaOptional = findFirstSchema(qname, schema.getChildNodes());
+        if (!childSchemaOptional.isPresent()) {
+            return null;
+        }
+        return childSchemaOptional.get();
+    }
+
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Iterable<DataSchemaNode> childNodes) {
         Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
         Preconditions.checkState(childSchema.isPresent(),
index 83fdc123cd14fabfa88378ea829ceb283589892e..7c3938fe088d92bc3bb6076bfa039cb9720e8102 100644 (file)
@@ -41,7 +41,7 @@ public abstract class AugmentationNodeBaseParser<E> extends
 
     @Override
     protected final DataSchemaNode getSchemaForChild(final AugmentationSchema schema, final QName childQName) {
-        return SchemaUtils.findSchemaForChild(schema, childQName);
+        return SchemaUtils.findSchemaForChild(schema, childQName, strictParsing());
     }
 
     @Override
index fba872d2f7fc1d29049549447669b9c73a30a14f..a594e5d763a8dbe51c8a33fd03d808b97d605d97 100644 (file)
@@ -109,6 +109,10 @@ public abstract class BaseDispatcherParser<E, N extends DataContainerNode<?>, S>
         // process Child nodes
         for (QName childPartialQName : mappedChildElements.keySet()) {
             DataSchemaNode childSchema = getSchemaForChild(schema, childPartialQName);
+            //with strict parsing an exception would be already thrown, with nonstrict we want to ignore this node
+            if (childSchema == null) {
+                continue;
+            }
             List<E> childrenForQName = mappedChildElements.get(childPartialQName);
 
             // Augment
@@ -153,6 +157,10 @@ public abstract class BaseDispatcherParser<E, N extends DataContainerNode<?>, S>
         return Collections.emptyMap();
     }
 
+    protected boolean strictParsing() {
+        return true;
+    }
+
     private boolean isMarkedAs(final Map<QName, ?> mappedAugmentChildNodes, final QName qName) {
         return mappedAugmentChildNodes.containsKey(qName);
     }
index 5fff36d5499e48d0bb8a3026cf6217bc256756c8..f7cca88155f52cfe18a504ce8a5e4b0849ffef4b 100644 (file)
@@ -48,7 +48,7 @@ public abstract class ContainerNodeBaseParser<E> extends
 
     @Override
     protected final DataSchemaNode getSchemaForChild(final ContainerSchemaNode schema, final QName childQName) {
-        return SchemaUtils.findSchemaForChild(schema, childQName);
+        return SchemaUtils.findSchemaForChild(schema, childQName, strictParsing());
     }
 
     @Override
index c2ec9fc7e4ba08fc7aa2eb718934e5de11f5486a..dfa34abcc7d6881bb2ba696deb4c7e62202556c1 100644 (file)
@@ -34,7 +34,7 @@ public abstract class ListEntryNodeBaseParser<E, N extends DataContainerNode<?>>
 
     @Override
     protected final DataSchemaNode getSchemaForChild(final ListSchemaNode schema, final QName childQName) {
-        return SchemaUtils.findSchemaForChild(schema, childQName);
+        return SchemaUtils.findSchemaForChild(schema, childQName, strictParsing());
     }
 
     @Override
index 7a5b551578ba850d88b65212b83eebfe6a793edf..73167f407a522232c3c105311ef26c2e5c1b9055 100644 (file)
@@ -19,9 +19,16 @@ import com.google.common.collect.LinkedListMultimap;
 final class AugmentationNodeDomParser extends AugmentationNodeBaseParser<Element> {
 
     private final NodeParserDispatcher<Element> dispatcher;
+    private final boolean strictParsing;
 
     AugmentationNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
         this.dispatcher = Preconditions.checkNotNull(dispatcher);
+        this.strictParsing = super.strictParsing();
+    }
+
+    AugmentationNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+        this.dispatcher = Preconditions.checkNotNull(dispatcher);
+        this.strictParsing = strictParsing;
     }
 
     @Override
@@ -34,4 +41,8 @@ final class AugmentationNodeDomParser extends AugmentationNodeBaseParser<Element
         return dispatcher;
     }
 
+    @Override
+    protected boolean strictParsing() {
+        return strictParsing;
+    }
 }
index c03113af22cd5cbeae7c30feff0aa655082ea3ba..ed4f2772ed453d83430deeac6525b871091583bc 100644 (file)
@@ -21,9 +21,16 @@ import com.google.common.collect.LinkedListMultimap;
 final class ContainerNodeDomParser extends ContainerNodeBaseParser<Element> {
 
     private final NodeParserDispatcher<Element> dispatcher;
+    private final boolean strictParsing;
 
     ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
         this.dispatcher = Preconditions.checkNotNull(dispatcher);
+        this.strictParsing = super.strictParsing();
+    }
+
+    ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+        this.dispatcher = Preconditions.checkNotNull(dispatcher);
+        this.strictParsing = strictParsing;
     }
 
     @Override
@@ -40,4 +47,9 @@ final class ContainerNodeDomParser extends ContainerNodeBaseParser<Element> {
     protected LinkedListMultimap<QName, Element> mapChildElements(Iterable<Element> elements) {
         return DomUtils.mapChildElementsForSingletonNode(elements.iterator().next());
     }
+
+    @Override
+    protected boolean strictParsing() {
+        return this.strictParsing;
+    }
 }
index af58c481543eb5b0a459fb381605d484507721ac..8e6381748ef856c7963739b0caf01a164795d64b 100644 (file)
@@ -47,7 +47,7 @@ public final class DomToNormalizedNodeParserFactory implements ToNormalizedNodeP
     private final OrderedListNodeDomParser orderedListNodeParser;
     private final AnyXmlDomParser anyXmlNodeParser;
 
-    private DomToNormalizedNodeParserFactory(final XmlCodecProvider codecProvider, final SchemaContext schema) {
+    private DomToNormalizedNodeParserFactory(final XmlCodecProvider codecProvider, final SchemaContext schema, final boolean strictParsing) {
         leafNodeParser = new LeafNodeDomParser(codecProvider, schema);
         leafSetEntryNodeParser = new LeafSetEntryNodeDomParser(codecProvider, schema);
         leafSetNodeParser = new LeafSetNodeDomParser(leafSetEntryNodeParser);
@@ -57,14 +57,14 @@ public final class DomToNormalizedNodeParserFactory implements ToNormalizedNodeP
 
         };
 
-        containerNodeParser = new ContainerNodeDomParser(dispatcher);
-        mapEntryNodeParser = new MapEntryNodeDomParser(dispatcher);
+        containerNodeParser = new ContainerNodeDomParser(dispatcher, strictParsing);
+        mapEntryNodeParser = new MapEntryNodeDomParser(dispatcher, strictParsing);
         mapNodeParser = new MapNodeDomParser(mapEntryNodeParser);
         orderedListNodeParser = new OrderedListNodeDomParser(mapEntryNodeParser);
         unkeyedListEntryNodeParser = new UnkeyedListEntryNodeDomParser(dispatcher);
         unkeyedListNodeParser = new UnkeyedListNodeDomParser(unkeyedListEntryNodeParser);
         choiceNodeParser = new ChoiceNodeDomParser(dispatcher);
-        augmentationNodeParser = new AugmentationNodeDomParser(dispatcher);
+        augmentationNodeParser = new AugmentationNodeDomParser(dispatcher, strictParsing);
     }
 
     @Deprecated
@@ -88,8 +88,12 @@ public final class DomToNormalizedNodeParserFactory implements ToNormalizedNodeP
         augmentationNodeParser = new AugmentationNodeDomParser(dispatcher);
     }
 
+    public static DomToNormalizedNodeParserFactory getInstance(final XmlCodecProvider codecProvider, final SchemaContext schema, final boolean strictParsing) {
+        return new DomToNormalizedNodeParserFactory(codecProvider, schema, strictParsing);
+    }
+
     public static DomToNormalizedNodeParserFactory getInstance(final XmlCodecProvider codecProvider, final SchemaContext schema) {
-        return new DomToNormalizedNodeParserFactory(codecProvider, schema);
+        return new DomToNormalizedNodeParserFactory(codecProvider, schema, true);
     }
 
     @Deprecated
index 4d4d35aa7debb12ab7dc1fac204ba9c39a45238c..a6c467c22224159dcb4120bf84233752bb18f13a 100644 (file)
@@ -17,8 +17,16 @@ import org.w3c.dom.Element;
 
 final class MapEntryNodeDomParser extends ListEntryNodeDomParser<MapEntryNode> {
 
+    private final boolean strictParsing;
+
     MapEntryNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
         super(dispatcher);
+        this.strictParsing = super.strictParsing();
+    }
+
+    MapEntryNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+        super(dispatcher);
+        this.strictParsing = strictParsing;
     }
 
     @Override
@@ -26,4 +34,9 @@ final class MapEntryNodeDomParser extends ListEntryNodeDomParser<MapEntryNode> {
             ListSchemaNode schema) {
         return Builders.mapEntryBuilder(schema);
     }
+
+    @Override
+    protected boolean strictParsing() {
+        return strictParsing;
+    }
 }
index b2b132d1369485d14f6585afdeaf7d2f1d46a96b..9b1ef2d2ef50148aacbf47488c95ae4f718fe0d0 100644 (file)
@@ -51,7 +51,7 @@ abstract class AbstractDataTreeTip implements DataTreeTip {
 
         final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
             Optional.<TreeNode>of(currentRoot), m.getVersion());
-        Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node");
+        Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s", modification);
         return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, currentRoot, newRoot.get());
     }
 }
index ad2e60b379bb2ed4d283fce10cd0813a0f12fd77..b771bccadf616380fe98279648c54161d9a93bcb 100644 (file)
@@ -173,7 +173,7 @@ abstract class SchemaAwareApplyOperation extends ModificationApplyOperation {
         }
     }
 
-    private void checkDeleteApplicable(final NodeModification modification, final Optional<TreeNode> current) {
+    private static void checkDeleteApplicable(final NodeModification modification, final Optional<TreeNode> current) {
         // Delete is always applicable, we do not expose it to subclasses
         if (current.isPresent()) {
             LOG.trace("Delete operation turned to no-op on missing node {}", modification);
@@ -192,7 +192,7 @@ abstract class SchemaAwareApplyOperation extends ModificationApplyOperation {
             modification.resolveModificationType(ModificationType.DELETE);
             return modification.setSnapshot(Optional.<TreeNode> absent());
         case TOUCH:
-            Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification",
+            Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification %s",
                     modification);
             return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
                     version)));
diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java
new file mode 100644 (file)
index 0000000..5735ea0
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 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.data.impl.schema;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.io.ByteSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class InstanceIdToNodesTest {
+
+    private static final String NS = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test";
+    private static final String REVISION = "2014-03-13";
+    private static final QName ID = QName.create(NS, REVISION, "id");
+    private SchemaContext ctx;
+
+    private final YangInstanceIdentifier.NodeIdentifier rootContainer = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "test"));
+    private final YangInstanceIdentifier.NodeIdentifier outerContainer = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-container"));
+    private final YangInstanceIdentifier.NodeIdentifier augmentedLeaf = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "augmented-leaf"));
+    private final YangInstanceIdentifier.AugmentationIdentifier augmentation = new YangInstanceIdentifier.AugmentationIdentifier(Collections.singleton(augmentedLeaf.getNodeType()));
+
+    private final YangInstanceIdentifier.NodeIdentifier outerList = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-list"));
+    private final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListWithKey = new YangInstanceIdentifier.NodeIdentifierWithPredicates(QName.create(NS, REVISION, "outer-list"), ID, 1);
+    private final YangInstanceIdentifier.NodeIdentifier choice = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "outer-choice"));
+    private final YangInstanceIdentifier.NodeIdentifier leafFromCase = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "one"));
+
+    private final YangInstanceIdentifier.NodeIdentifier leafList = new YangInstanceIdentifier.NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list"));
+    private final YangInstanceIdentifier.NodeWithValue leafListWithValue = new YangInstanceIdentifier.NodeWithValue(leafList.getNodeType(), "abcd");
+
+    static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException {
+        final YangParserImpl parser = new YangParserImpl();
+        return parser.parseSources(Collections2.transform(Collections.singletonList("/filter-test.yang"), new Function<String, ByteSource>() {
+            @Override
+            public ByteSource apply(final String input) {
+                return new ByteSource() {
+                    @Override
+                    public InputStream openStream() throws IOException {
+                        return InstanceIdToNodesTest.class.getResourceAsStream(input);
+                    }
+                };
+            }
+        }));
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        ctx = createTestContext();
+
+    }
+
+    @Test
+    public void testInAugment() throws Exception {
+        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild(
+                        Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild(
+                                Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).build()
+                        ).build()
+                ).build()
+        ).build();
+
+        final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf));
+        assertEquals(expectedFilter, filter);
+    }
+
+    @Test
+    public void testInAugmentLeafOverride() throws Exception {
+        final LeafNode<Object> lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("randomValue").build();
+
+        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild(
+                        Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild(
+                                lastLeaf
+                        ).build()
+                ).build()
+        ).build();
+
+        final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf);
+        assertEquals(expectedFilter, filter);
+    }
+
+    @Test
+    public void testListChoice() throws Exception {
+        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                Builders.mapBuilder().withNodeIdentifier(outerList).withChild(
+                        Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
+                                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
+                        ).withChild(
+                                Builders.choiceBuilder().withNodeIdentifier(choice).withChild(
+                                        Builders.leafBuilder().withNodeIdentifier(leafFromCase).build()
+                                ).build()
+                        ).build()
+                ).build()
+        ).build();
+
+        final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase));
+        assertEquals(expectedFilter, filter);
+    }
+
+    @Test
+    public void testTopContainerLastChildOverride() throws Exception {
+        final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                Builders.mapBuilder().withNodeIdentifier(outerList).withChild(
+                        Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
+                                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
+                        ).withChild(
+                                Builders.choiceBuilder().withNodeIdentifier(choice).withChild(
+                                        Builders.leafBuilder().withNodeIdentifier(leafFromCase).build()
+                                ).build()
+                        ).build()
+                ).build()
+        ).build();
+
+        final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer), expectedStructure);
+        assertEquals(expectedStructure, filter);
+    }
+
+    @Test
+    public void testListLastChildOverride() throws Exception {
+        final MapEntryNode outerListEntry = Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild(
+                Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID)).withValue(1).build()
+        ).build();
+        final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild(
+                outerListEntry
+        ).build();
+        final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                lastChild
+        ).build();
+
+        NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry);
+        assertEquals(expectedStructure, filter);
+        filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey));
+        assertEquals(expectedStructure, filter);
+    }
+
+    @Test
+    public void testLeafList() throws Exception {
+        final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild(
+                Builders.orderedLeafSetBuilder().withNodeIdentifier(leafList).withChild(
+                        Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue).withValue(leafListWithValue.getValue()).build()
+                ).build()
+        ).build();
+
+        final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue));
+        assertEquals(expectedFilter, filter);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/test/resources/filter-test.yang b/yang/yang-data-impl/src/test/resources/filter-test.yang
new file mode 100644 (file)
index 0000000..6df5306
--- /dev/null
@@ -0,0 +1,74 @@
+module normalization-test {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test";
+    prefix "norm-test";
+
+    revision "2014-03-13" {
+        description "Initial revision.";
+    }
+
+    grouping outer-grouping {
+    }
+
+    container test {
+        list outer-list {
+            key id;
+            leaf id {
+                type uint16;
+            }
+            choice outer-choice {
+                case one {
+                    leaf one {
+                        type string;
+                    }
+                }
+                case two-three {
+                    leaf two {
+                        type string;
+                    }
+                    leaf three {
+                        type string;
+                    }
+               }
+           }
+           list inner-list {
+                key name;
+                ordered-by user;
+
+                leaf name {
+                    type string;
+                }
+                leaf value {
+                    type string;
+                }
+            }
+        }
+
+        list unkeyed-list {
+            leaf name {
+                type string;
+            }
+        }
+
+        leaf-list unordered-leaf-list {
+            type string;
+        }
+
+        leaf-list ordered-leaf-list {
+            ordered-by user;
+            type string;
+        }
+
+        container outer-container {
+        }
+
+        anyxml any-xml-data;
+    }
+
+    augment /norm-test:test/norm-test:outer-container {
+
+        leaf augmented-leaf {
+           type string;
+        }
+    }
+}
\ No newline at end of file
index 985a7cdd7d61184e10e6e7825a87acd3628b933b..cc8f6feebd684e317a80085ad86822a431b97d8b 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.common.QName;
  * Represents unique path to the every node inside the module.
  */
 public abstract class SchemaPath implements Immutable {
+
     /**
      * An absolute SchemaPath.
      */
@@ -97,6 +98,18 @@ public abstract class SchemaPath implements Immutable {
      */
     private volatile ImmutableList<QName> legacyPath;
 
+    protected SchemaPath(final SchemaPath parent, final QName qname) {
+        this.parent = parent;
+        this.qname = qname;
+
+        int h = parent == null ? 0 : parent.hashCode();
+        if (qname != null) {
+            h = h * 31 + qname.hashCode();
+        }
+
+        hash = h;
+    }
+
     private ImmutableList<QName> getLegacyPath() {
         ImmutableList<QName> ret = legacyPath;
         if (ret == null) {
@@ -120,18 +133,6 @@ public abstract class SchemaPath implements Immutable {
         return getLegacyPath();
     }
 
-    protected SchemaPath(final SchemaPath parent, final QName qname) {
-        this.parent = parent;
-        this.qname = qname;
-
-        int h = parent == null ? 0 : parent.hashCode();
-        if (qname != null) {
-            h = h * 31 + qname.hashCode();
-        }
-
-        hash = h;
-    }
-
     /**
      * Constructs new instance of this class with the concrete path.
      *
@@ -185,12 +186,12 @@ public abstract class SchemaPath implements Immutable {
             return this;
         }
 
-        SchemaPath parent = this;
+        SchemaPath parentPath = this;
         for (QName qname : relative) {
-            parent = parent.createInstance(parent, qname);
+            parentPath = parentPath.createInstance(parentPath, qname);
         }
 
-        return parent;
+        return parentPath;
     }
 
     /**
@@ -202,12 +203,12 @@ public abstract class SchemaPath implements Immutable {
     public SchemaPath createChild(final SchemaPath relative) {
         Preconditions.checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
 
-        SchemaPath parent = this;
+        SchemaPath parentPath = this;
         for (QName qname : relative.getPathFromRoot()) {
-            parent = parent.createInstance(parent, qname);
+            parentPath = parentPath.createInstance(parentPath, qname);
         }
 
-        return parent;
+        return parentPath;
     }
 
     /**
index bacf0c41cccf85070460ae24994160a4cea0497f..77c36f1b8e6f4ef28084fa9b54db9090a99375e1 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.common.QName;
  *
  */
 public abstract class SchemaNodeIdentifier implements Immutable {
+
     /**
      * An absolute schema node identifier.
      */
@@ -99,6 +100,18 @@ public abstract class SchemaNodeIdentifier implements Immutable {
      */
     private volatile ImmutableList<QName> legacyPath;
 
+    protected SchemaNodeIdentifier(final SchemaNodeIdentifier parent, final QName qname) {
+        this.parent = parent;
+        this.qname = qname;
+
+        int h = parent == null ? 0 : parent.hashCode();
+        if (qname != null) {
+            h = h * 31 + qname.hashCode();
+        }
+
+        hash = h;
+    }
+
     private ImmutableList<QName> getLegacyPath() {
         ImmutableList<QName> ret = legacyPath;
         if (ret == null) {
@@ -122,18 +135,6 @@ public abstract class SchemaNodeIdentifier implements Immutable {
         return getLegacyPath();
     }
 
-    protected SchemaNodeIdentifier(final SchemaNodeIdentifier parent, final QName qname) {
-        this.parent = parent;
-        this.qname = qname;
-
-        int h = parent == null ? 0 : parent.hashCode();
-        if (qname != null) {
-            h = h * 31 + qname.hashCode();
-        }
-
-        hash = h;
-    }
-
     /**
      * Constructs new instance of this class with the concrete path.
      *
@@ -187,12 +188,12 @@ public abstract class SchemaNodeIdentifier implements Immutable {
             return this;
         }
 
-        SchemaNodeIdentifier parent = this;
+        SchemaNodeIdentifier parentNode = this;
         for (QName qname : relative) {
-            parent = parent.createInstance(parent, qname);
+            parentNode = parentNode.createInstance(parentNode, qname);
         }
 
-        return parent;
+        return parentNode;
     }
 
     /**
@@ -204,12 +205,12 @@ public abstract class SchemaNodeIdentifier implements Immutable {
     public SchemaNodeIdentifier createChild(final SchemaNodeIdentifier relative) {
         Preconditions.checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
 
-        SchemaNodeIdentifier parent = this;
+        SchemaNodeIdentifier parentNode = this;
         for (QName qname : relative.getPathFromRoot()) {
-            parent = parent.createInstance(parent, qname);
+            parentNode = parentNode.createInstance(parentNode, qname);
         }
 
-        return parent;
+        return parentNode;
     }
 
     /**
index 0070cab71fe3d7bcf734060e9bfc4d6e63351d50..9f5e22bc9f9e22c827e51924ff8ae1a00f7de54b 100644 (file)
@@ -23,6 +23,9 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport;
  */
 @Beta
 public class SchemaResolutionException extends SchemaSourceException {
+
+    private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
+
     private static final long serialVersionUID = 1L;
     private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
     private final Collection<SourceIdentifier> resolvedSources;
@@ -48,7 +51,6 @@ public class SchemaResolutionException extends SchemaSourceException {
         this.resolvedSources = ImmutableList.copyOf(resolvedSources);
     }
 
-    private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
     private static String formatMessage(final String message, final Collection<SourceIdentifier> resolvedSources, final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
         return String.format(MESSAGE_BLUEPRINT, message, resolvedSources, unsatisfiedImports);
     }
index 6da4ee301263ffbcb72c5200fdea0b54ee87c3da..85b26a52d4ba4b3bc334971a406914d15d673767 100644 (file)
@@ -24,12 +24,12 @@ public interface SchemaSourceFilter {
      * A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
      */
     public static final SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
-        private final Iterable<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS =
+        private final Iterable<Class<? extends SchemaSourceRepresentation>> Representations =
                 Collections.<Class<? extends SchemaSourceRepresentation>>singletonList(SchemaSourceRepresentation.class);
 
         @Override
         public Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
-            return REPRESENTATIONS;
+            return Representations;
         }
 
         @Override
index f46ed3f426553be6f37a5a94e72b7d96b965c24c..0b74d4b63fbbe0549136c1e51ac805186457479f 100644 (file)
@@ -56,12 +56,22 @@ public final class SourceIdentifier implements Identifier, Immutable {
      */
     public static final Pattern REVISION_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d-\\d\\d");
 
-
     private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(SourceIdentifier.class);
     private static final long serialVersionUID = 1L;
     private final String revision;
     private final String name;
 
+    /**
+     *
+     * Creates new YANG Schema source identifier for sources without revision.
+     * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
+     *
+     * @param name Name of schema
+     */
+    public SourceIdentifier(final String name) {
+        this(name, NOT_PRESENT_FORMATTED_REVISION);
+    }
+
     /**
      * Creates new YANG Schema source identifier.
      *
@@ -93,17 +103,6 @@ public final class SourceIdentifier implements Identifier, Immutable {
         return CACHE.getReference(this);
     }
 
-    /**
-     *
-     * Creates new YANG Schema source identifier for sources without revision.
-     * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
-     *
-     * @param name Name of schema
-     */
-    public SourceIdentifier(final String name) {
-        this(name, NOT_PRESENT_FORMATTED_REVISION);
-    }
-
     /**
      * Returns model name
      *
index 975b683dd64e93e6aa962069a9c4c2eeb0838747..e98553e8009013e5b4f5c2bc2c60123fdd147630 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
 import java.util.TreeMap;
 import org.antlr.v4.runtime.tree.ParseTree;
@@ -83,6 +84,7 @@ public final class BuilderUtils {
     private static final Date NULL_DATE = new Date(0L);
     private static final String INPUT = "input";
     private static final String OUTPUT = "output";
+    private static final String CHILD_NOT_FOUND_IN_NODE_STR = "Child {} not found in node {}";
 
     private BuilderUtils() {
     }
@@ -148,7 +150,7 @@ public final class BuilderUtils {
      *            current line in yang model
      * @return module builder if found, null otherwise
      */
-    public static ModuleBuilder findModuleFromBuilders(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+    public static ModuleBuilder findModuleFromBuilders(final Map<String, NavigableMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module, final String prefix, final int line) {
         ModuleBuilder dependentModule;
         Date dependentModuleRevision;
@@ -165,7 +167,7 @@ public final class BuilderUtils {
             String dependentModuleName = dependentModuleImport.getModuleName();
             dependentModuleRevision = dependentModuleImport.getRevision();
 
-            TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
+            NavigableMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
             if (moduleBuildersByRevision == null) {
                 return null;
             }
@@ -181,12 +183,10 @@ public final class BuilderUtils {
     public static ModuleBuilder findModuleFromBuilders(ModuleImport imp, Iterable<ModuleBuilder> modules) {
         String name = imp.getModuleName();
         Date revision = imp.getRevision();
-        TreeMap<Date, ModuleBuilder> map = new TreeMap<>();
+        NavigableMap<Date, ModuleBuilder> map = new TreeMap<>();
         for (ModuleBuilder module : modules) {
-            if (module != null) {
-                if (module.getName().equals(name)) {
-                    map.put(module.getRevision(), module);
-                }
+            if (module != null && module.getName().equals(name)) {
+                map.put(module.getRevision(), module);
             }
         }
         if (map.isEmpty()) {
@@ -216,7 +216,7 @@ public final class BuilderUtils {
      */
     public static Module findModuleFromContext(final SchemaContext context, final ModuleBuilder currentModule,
             final String prefix, final int line) {
-        TreeMap<Date, Module> modulesByRevision = new TreeMap<>();
+        NavigableMap<Date, Module> modulesByRevision = new TreeMap<>();
 
         ModuleImport dependentModuleImport = currentModule.getImport(prefix);
         if (dependentModuleImport == null) {
@@ -378,9 +378,9 @@ public final class BuilderUtils {
                     node = findUnknownNode(name, parent);
                 }
             } else if (parent instanceof RpcDefinitionBuilder) {
-                if ("input".equals(name)) {
+                if (INPUT.equals(name)) {
                     node = ((RpcDefinitionBuilder) parent).getInput();
-                } else if ("output".equals(name)) {
+                } else if (OUTPUT.equals(name)) {
                     node = ((RpcDefinitionBuilder) parent).getOutput();
                 } else {
                     if (node == null) {
@@ -457,9 +457,8 @@ public final class BuilderUtils {
             return castOptional(SchemaNodeBuilder.class, findCaseInChoice((ChoiceBuilder) parent, child));
         } else if (parent instanceof RpcDefinitionBuilder) {
             return castOptional(SchemaNodeBuilder.class, findContainerInRpc((RpcDefinitionBuilder) parent, child));
-
         } else {
-            LOG.trace("Child {} not found in node {}", child, parent);
+            LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
             return Optional.absent();
         }
     }
@@ -504,7 +503,7 @@ public final class BuilderUtils {
             final QName child) {
         if (INPUT.equals(child.getLocalName())) {
             if (parent.getInput() == null) {
-                QName qname = QName.create(parent.getQName().getModule(), "input");
+                QName qname = QName.create(parent.getQName().getModule(), INPUT);
                 final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(parent.getModuleName(),
                         parent.getLine(), qname, parent.getPath().createChild(qname));
                 inputBuilder.setParent(parent);
@@ -514,7 +513,7 @@ public final class BuilderUtils {
             return Optional.of(parent.getInput());
         } else if (OUTPUT.equals(child.getLocalName())) {
             if (parent.getOutput() == null) {
-                QName qname = QName.create(parent.getQName().getModule(), "output");
+                QName qname = QName.create(parent.getQName().getModule(), OUTPUT);
                 final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(parent.getModuleName(),
                         parent.getLine(), qname, parent.getPath().createChild(qname));
                 outputBuilder.setParent(parent);
@@ -523,7 +522,7 @@ public final class BuilderUtils {
             }
             return Optional.of(parent.getOutput());
         }
-        LOG.trace("Child {} not found in node {}", child, parent);
+        LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
         return Optional.absent();
     }
 
@@ -544,7 +543,7 @@ public final class BuilderUtils {
                 return Optional.of(caze);
             }
         }
-        LOG.trace("Child {} not found in node {}", child, parent);
+        LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
         return Optional.absent();
     }
 
@@ -565,7 +564,7 @@ public final class BuilderUtils {
                 return Optional.of(childNode);
             }
         }
-        LOG.trace("Child {} not found in node {}", child, parent);
+        LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
         return Optional.absent();
     }
 
@@ -625,7 +624,7 @@ public final class BuilderUtils {
                 return Optional.<SchemaNodeBuilder> of(childNode);
             }
         }
-        LOG.trace("Child {} not found in node {}", child, builder);
+        LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, builder);
         return Optional.absent();
     }
 
@@ -730,19 +729,19 @@ public final class BuilderUtils {
         final SchemaPath schemaPath = parentPath.createChild(qname);
 
         if (node instanceof AnyXmlSchemaNode) {
-            return new AnyXmlBuilder(moduleName, line, qname, schemaPath, ((AnyXmlSchemaNode) node));
+            return new AnyXmlBuilder(moduleName, line, qname, schemaPath, (AnyXmlSchemaNode) node);
         } else if (node instanceof ChoiceSchemaNode) {
-            return new ChoiceBuilder(moduleName, line, qname, schemaPath, ((ChoiceSchemaNode) node));
+            return new ChoiceBuilder(moduleName, line, qname, schemaPath, (ChoiceSchemaNode) node);
         } else if (node instanceof ContainerSchemaNode) {
-            return new ContainerSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((ContainerSchemaNode) node));
+            return new ContainerSchemaNodeBuilder(moduleName, line, qname, schemaPath, (ContainerSchemaNode) node);
         } else if (node instanceof LeafSchemaNode) {
-            return new LeafSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((LeafSchemaNode) node));
+            return new LeafSchemaNodeBuilder(moduleName, line, qname, schemaPath, (LeafSchemaNode) node);
         } else if (node instanceof LeafListSchemaNode) {
-            return new LeafListSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((LeafListSchemaNode) node));
+            return new LeafListSchemaNodeBuilder(moduleName, line, qname, schemaPath, (LeafListSchemaNode) node);
         } else if (node instanceof ListSchemaNode) {
-            return new ListSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((ListSchemaNode) node));
+            return new ListSchemaNodeBuilder(moduleName, line, qname, schemaPath, (ListSchemaNode) node);
         } else if (node instanceof ChoiceCaseNode) {
-            return new ChoiceCaseBuilder(moduleName, line, qname, schemaPath, ((ChoiceCaseNode) node));
+            return new ChoiceCaseBuilder(moduleName, line, qname, schemaPath, (ChoiceCaseNode) node);
         } else {
             throw new YangParseException(moduleName, line, "Failed to copy node: Unknown type of DataSchemaNode: "
                     + node);
@@ -767,7 +766,7 @@ public final class BuilderUtils {
         for (TypeDefinition<?> node : nodes) {
             QName qname = QName.create(parentQName, node.getQName().getLocalName());
             SchemaPath schemaPath = parentPath.createChild(qname);
-            result.add(new TypeDefinitionBuilderImpl(moduleName, line, qname, schemaPath, ((ExtendedType) node)));
+            result.add(new TypeDefinitionBuilderImpl(moduleName, line, qname, schemaPath, (ExtendedType) node));
         }
         return result;
     }
@@ -806,8 +805,8 @@ public final class BuilderUtils {
         }
     }
 
-    public static ModuleBuilder findModule(final QName qname, final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        TreeMap<Date, ModuleBuilder> map = modules.get(qname.getNamespace());
+    public static ModuleBuilder findModule(final QName qname, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        NavigableMap<Date, ModuleBuilder> map = modules.get(qname.getNamespace());
         if (map == null) {
             return null;
         }
@@ -817,9 +816,9 @@ public final class BuilderUtils {
         return map.get(qname.getRevision());
     }
 
-    public static Map<String, TreeMap<Date, URI>> createYangNamespaceContext(
+    public static Map<String, NavigableMap<Date, URI>> createYangNamespaceContext(
             final Collection<? extends ParseTree> modules, final Optional<SchemaContext> context) {
-        Map<String, TreeMap<Date, URI>> namespaceContext = new HashMap<>();
+        Map<String, NavigableMap<Date, URI>> namespaceContext = new HashMap<>();
         Set<Submodule_stmtContext> submodules = new HashSet<>();
         // first read ParseTree collection and separate modules and submodules
         for (ParseTree module : modules) {
@@ -858,7 +857,7 @@ public final class BuilderUtils {
                         }
                     }
                     // update namespaceContext
-                    TreeMap<Date, URI> revToNs = namespaceContext.get(moduleName);
+                    NavigableMap<Date, URI> revToNs = namespaceContext.get(moduleName);
                     if (revToNs == null) {
                         revToNs = new TreeMap<>();
                         revToNs.put(rev, namespace);
@@ -872,7 +871,7 @@ public final class BuilderUtils {
         // from SchemaContext
         if (context.isPresent()) {
             for (Module module : context.get().getModules()) {
-                TreeMap<Date, URI> revToNs = namespaceContext.get(module.getName());
+                NavigableMap<Date, URI> revToNs = namespaceContext.get(module.getName());
                 if (revToNs == null) {
                     revToNs = new TreeMap<>();
                     revToNs.put(module.getRevision(), module.getNamespace());
@@ -892,13 +891,13 @@ public final class BuilderUtils {
                         ParseTree belongsCtx = subHeaderCtx.getChild(j);
                         if (belongsCtx instanceof Belongs_to_stmtContext) {
                             final String belongsTo = ParserListenerUtils.stringFromNode(belongsCtx);
-                            TreeMap<Date, URI> ns = namespaceContext.get(belongsTo);
+                            NavigableMap<Date, URI> ns = namespaceContext.get(belongsTo);
                             if (ns == null) {
                                 throw new YangParseException(moduleName, submodule.getStart().getLine(), String.format(
                                         "Unresolved belongs-to statement: %s", belongsTo));
                             }
                             // submodule get namespace and revision from module
-                            TreeMap<Date, URI> subNs = new TreeMap<>();
+                            NavigableMap<Date, URI> subNs = new TreeMap<>();
                             subNs.put(ns.firstKey(), ns.firstEntry().getValue());
                             namespaceContext.put(moduleName, subNs);
                         }
index 55cf82726d8d104a4d9c32facff1bcf6d77bc6ab..8f9ffa98b48a3e35ec4348d1074e34cc114f7824 100644 (file)
@@ -77,7 +77,7 @@ public final class CopyUtils {
         copy.setAddedByUses(old.isAddedByUses());
         copy.setConfiguration(old.isConfiguration());
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         return copy;
@@ -105,7 +105,7 @@ public final class CopyUtils {
             copy.addAugmentation(copyAugment(augment, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         return copy;
@@ -133,7 +133,7 @@ public final class CopyUtils {
             copy.addUsesNode(copyUses(oldUses, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         return copy;
@@ -174,7 +174,7 @@ public final class CopyUtils {
             copy.addAugmentation(copyAugment(augment, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         return copy;
@@ -198,7 +198,7 @@ public final class CopyUtils {
         copy.setAddedByUses(old.isAddedByUses());
         copy.setConfiguration(old.isConfiguration());
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         if (old.getType() == null) {
@@ -231,7 +231,7 @@ public final class CopyUtils {
         copy.setAddedByUses(old.isAddedByUses());
         copy.setConfiguration(old.isConfiguration());
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         if (old.getType() == null) {
@@ -279,7 +279,7 @@ public final class CopyUtils {
             copy.addAugmentation(copyAugment(augment, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         copy.setUserOrdered(old.isUserOrdered());
@@ -314,7 +314,7 @@ public final class CopyUtils {
             copy.addUsesNode(copyUses(oldUses, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+            copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
         }
 
         return copy;
@@ -352,7 +352,7 @@ public final class CopyUtils {
             }
 
             for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-                type.addUnknownNodeBuilder((copy(un, type, updateQName)));
+                type.addUnknownNodeBuilder(copy(un, type, updateQName));
             }
 
             type.setRanges(old.getRanges());
@@ -410,7 +410,7 @@ public final class CopyUtils {
             copy.addUsesNode(copyUses(oldUses, copy));
         }
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            copy.addUnknownNodeBuilder((copy(un, copy, false)));
+            copy.addUnknownNodeBuilder(copy(un, copy, false));
         }
 
         return copy;
@@ -433,7 +433,7 @@ public final class CopyUtils {
         c.setStatus(old.getStatus());
         c.setAddedByUses(old.isAddedByUses());
         for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
-            c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+            c.addUnknownNodeBuilder(copy(un, c, updateQName));
         }
         c.setExtensionBuilder(old.getExtensionBuilder());
         c.setExtensionDefinition(old.getExtensionDefinition());
index e1792c899f7fc1af26caf0c5f4559a3864cd94f3..eb06329eaab9ddd3ab3bbc1c62bf695d284e7ad1 100644 (file)
@@ -12,8 +12,8 @@ import java.net.URI;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
-import java.util.TreeMap;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
 public final class GroupingUtils {
     private static final Logger LOG = LoggerFactory.getLogger(GroupingUtils.class);
 
-    private static final Splitter COLON_SPLITTER = Splitter.on(':');
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
     private GroupingUtils() {
@@ -49,7 +48,7 @@ public final class GroupingUtils {
      *             if no grouping found
      */
     public static GroupingBuilder getTargetGroupingFromModules(final UsesNodeBuilder usesBuilder,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         final int line = usesBuilder.getLine();
 
         SchemaPath groupingPath = usesBuilder.getTargetGroupingPath();
index 7cac743689c5b8f8e51e66525fbe1ac593a06d56..120ebad9575f78081406eaa581fc3b203931042b 100644 (file)
@@ -61,6 +61,8 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
  */
 public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DocumentedNodeBuilder {
 
+    private static final String GROUPING_STR = "Grouping";
+    private static final String TYPEDEF_STR = "typedef";
     private ModuleImpl instance;
     private final String name;
     private final String sourcePath;
@@ -443,8 +445,8 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
 
     public ExtensionBuilder addExtension(final QName qname, final int line, final SchemaPath path) {
         checkNotSealed();
-        Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "extension can be defined only in module or submodule");
         }
 
@@ -455,7 +457,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
             }
         }
         final ExtensionBuilder builder = new ExtensionBuilderImpl(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
         addedExtensions.add(builder);
         return builder;
     }
@@ -464,9 +466,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
 
         return builder;
     }
@@ -475,9 +477,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(name, line, qname, schemaPath);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
         allLists.add(builder);
 
         return builder;
@@ -487,9 +489,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(name, line, qname, schemaPath);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
 
         return builder;
     }
@@ -498,9 +500,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(name, line, qname, schemaPath);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
 
         return builder;
     }
@@ -509,31 +511,31 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final GroupingBuilder builder = new GroupingBuilderImpl(name, line, qname, path);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
 
         String groupingName = qname.getLocalName();
-        if (parent.equals(this)) {
+        if (parentBuilder.equals(this)) {
             for (GroupingBuilder addedGrouping : getGroupingBuilders()) {
                 if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
-                    raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+                    raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine());
                 }
             }
             addGrouping(builder);
         } else {
-            if (parent instanceof DataNodeContainerBuilder) {
-                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+            if (parentBuilder instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder;
                 for (GroupingBuilder addedGrouping : parentNode.getGroupingBuilders()) {
                     if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
-                        raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+                        raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine());
                     }
                 }
                 parentNode.addGrouping(builder);
-            } else if (parent instanceof RpcDefinitionBuilder) {
-                RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent;
+            } else if (parentBuilder instanceof RpcDefinitionBuilder) {
+                RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parentBuilder;
                 for (GroupingBuilder child : parentNode.getGroupings()) {
                     if (child.getQName().getLocalName().equals(groupingName)) {
-                        raiseYangParserException("", "Grouping", groupingName, line, child.getLine());
+                        raiseYangParserException("", GROUPING_STR, groupingName, line, child.getLine());
                     }
                 }
                 parentNode.addGrouping(builder);
@@ -552,10 +554,10 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr,
                 targetPath, order);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
 
-        if (parent.equals(this)) {
+        if (parentBuilder.equals(this)) {
             // augment can be declared only under 'module' ...
             if (!(augmentTargetStr.startsWith("/"))) {
                 throw new YangParseException(
@@ -566,13 +568,13 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
             augmentBuilders.add(builder);
         } else {
             // ... or 'uses' statement
-            if (parent instanceof UsesNodeBuilder) {
+            if (parentBuilder instanceof UsesNodeBuilder) {
                 if (augmentTargetStr.startsWith("/")) {
                     throw new YangParseException(name, line,
                             "If 'augment' statement is a substatement to the 'uses' statement, it cannot contain absolute path ("
                                     + augmentTargetStr + ")");
                 }
-                ((UsesNodeBuilder) parent).addAugment(builder);
+                ((UsesNodeBuilder) parentBuilder).addAugment(builder);
             } else {
                 throw new YangParseException(name, line, "Augment can be declared only under module or uses statement.");
             }
@@ -586,18 +588,18 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotSealed();
         final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, grouping);
 
-        Builder parent = getActualNode();
-        usesBuilder.setParent(parent);
+        Builder parentBuilder = getActualNode();
+        usesBuilder.setParent(parentBuilder);
 
-        if (parent.equals(this)) {
+        if (parentBuilder.equals(this)) {
             addUsesNode(usesBuilder);
         } else {
-            if (!(parent instanceof DataNodeContainerBuilder)) {
+            if (!(parentBuilder instanceof DataNodeContainerBuilder)) {
                 throw new YangParseException(name, line, "Unresolved parent of uses '" + grouping + "'.");
             }
-            ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
+            ((DataNodeContainerBuilder) parentBuilder).addUsesNode(usesBuilder);
         }
-        if (parent instanceof AugmentationSchemaBuilder) {
+        if (parentBuilder instanceof AugmentationSchemaBuilder) {
             usesBuilder.setAugmenting(true);
         }
 
@@ -607,23 +609,23 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
 
     public void addRefine(final RefineHolderImpl refine) {
         checkNotSealed();
-        final Builder parent = getActualNode();
-        if (!(parent instanceof UsesNodeBuilder)) {
+        final Builder parentBuilder = getActualNode();
+        if (!(parentBuilder instanceof UsesNodeBuilder)) {
             throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
         }
-        ((UsesNodeBuilder) parent).addRefine(refine);
-        refine.setParent(parent);
+        ((UsesNodeBuilder) parentBuilder).addRefine(refine);
+        refine.setParent(parentBuilder);
     }
 
     public RpcDefinitionBuilder addRpc(final int line, final QName qname, final SchemaPath path) {
         checkNotSealed();
-        Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
         }
 
         final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(name, line, qname, path);
-        rpcBuilder.setParent(parent);
+        rpcBuilder.setParent(parentBuilder);
 
         String rpcName = qname.getLocalName();
         checkNotConflictingInDataNamespace(rpcName, line);
@@ -651,11 +653,11 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
 
     public ContainerSchemaNodeBuilder addRpcInput(final int line, final QName qname, final SchemaPath schemaPath) {
         checkNotSealed();
-        final Builder parent = getActualNode();
-        if (!(parent instanceof RpcDefinitionBuilder)) {
+        final Builder parentBuilder = getActualNode();
+        if (!(parentBuilder instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "input can be defined only in rpc statement");
         }
-        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder;
 
         final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
         inputBuilder.setParent(rpc);
@@ -666,11 +668,11 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
 
     public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {
         checkNotSealed();
-        final Builder parent = getActualNode();
-        if (!(parent instanceof RpcDefinitionBuilder)) {
+        final Builder parentBuilder = getActualNode();
+        if (!(parentBuilder instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "output can be defined only in rpc statement");
         }
-        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder;
 
         final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
         outputBuilder.setParent(rpc);
@@ -686,8 +688,8 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
 
     public NotificationBuilder addNotification(final int line, final QName qname, final SchemaPath path) {
         checkNotSealed();
-        final Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        final Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "notification can be defined only in module or submodule");
         }
 
@@ -695,20 +697,20 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         checkNotConflictingInDataNamespace(notificationName, line);
 
         final NotificationBuilder builder = new NotificationBuilder(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
         addedNotifications.add(builder);
 
         return builder;
     }
 
     public FeatureBuilder addFeature(final int line, final QName qname, final SchemaPath path) {
-        Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "feature can be defined only in module or submodule");
         }
 
         final FeatureBuilder builder = new FeatureBuilder(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
 
         String featureName = qname.getLocalName();
         for (FeatureBuilder addedFeature : addedFeatures) {
@@ -723,26 +725,26 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public ChoiceBuilder addChoice(final int line, final QName qname, final SchemaPath path) {
         final ChoiceBuilder builder = new ChoiceBuilder(name, line, qname, path);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
 
         return builder;
     }
 
     public ChoiceCaseBuilder addCase(final int line, final QName qname, final SchemaPath path) {
-        Builder parent = getActualNode();
-        if (parent == null || parent.equals(this)) {
+        Builder parentBuilder = getActualNode();
+        if (parentBuilder == null || parentBuilder.equals(this)) {
             throw new YangParseException(name, line, "'case' parent not found");
         }
 
         final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
 
-        if (parent instanceof ChoiceBuilder) {
-            ((ChoiceBuilder) parent).addCase(builder);
-        } else if (parent instanceof AugmentationSchemaBuilder) {
-            ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+        if (parentBuilder instanceof ChoiceBuilder) {
+            ((ChoiceBuilder) parentBuilder).addCase(builder);
+        } else if (parentBuilder instanceof AugmentationSchemaBuilder) {
+            ((AugmentationSchemaBuilder) parentBuilder).addChildNode(builder);
         } else {
             throw new YangParseException(name, line, "Unresolved parent of 'case' " + qname.getLocalName());
         }
@@ -753,9 +755,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public AnyXmlBuilder addAnyXml(final int line, final QName qname, final SchemaPath schemaPath) {
         final AnyXmlBuilder builder = new AnyXmlBuilder(name, line, qname, schemaPath);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
-        addChildToParent(parent, builder, qname.getLocalName());
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
+        addChildToParent(parentBuilder, builder, qname.getLocalName());
 
         return builder;
     }
@@ -765,7 +767,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         String nodeName = typedefBuilder.getQName().getLocalName();
         for (TypeDefinitionBuilder tdb : getTypeDefinitionBuilders()) {
             if (tdb.getQName().getLocalName().equals(nodeName)) {
-                raiseYangParserException("", "typedef", nodeName, typedefBuilder.getLine(), tdb.getLine());
+                raiseYangParserException("", TYPEDEF_STR, nodeName, typedefBuilder.getLine(), tdb.getLine());
             }
         }
         super.addTypedef(typedefBuilder);
@@ -774,26 +776,26 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname, final SchemaPath path) {
         final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(name, line, qname, path);
 
-        Builder parent = getActualNode();
-        builder.setParent(parent);
+        Builder parentBuilder = getActualNode();
+        builder.setParent(parentBuilder);
 
         String typedefName = qname.getLocalName();
-        if (parent.equals(this)) {
+        if (parentBuilder.equals(this)) {
             addTypedef(builder);
         } else {
-            if (parent instanceof DataNodeContainerBuilder) {
-                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+            if (parentBuilder instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder;
                 for (TypeDefinitionBuilder child : parentNode.getTypeDefinitionBuilders()) {
                     if (child.getQName().getLocalName().equals(typedefName)) {
-                        raiseYangParserException("", "typedef", typedefName, line, child.getLine());
+                        raiseYangParserException("", TYPEDEF_STR, typedefName, line, child.getLine());
                     }
                 }
                 parentNode.addTypedef(builder);
-            } else if (parent instanceof RpcDefinitionBuilder) {
-                RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent;
+            } else if (parentBuilder instanceof RpcDefinitionBuilder) {
+                RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parentBuilder;
                 for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) {
                     if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {
-                        raiseYangParserException("", "typedef", typedefName, line, tdb.getLine());
+                        raiseYangParserException("", TYPEDEF_STR, typedefName, line, tdb.getLine());
                     }
                 }
                 rpcParent.addTypedef(builder);
@@ -806,22 +808,22 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     }
 
     public void setType(final TypeDefinition<?> type) {
-        Builder parent = getActualNode();
-        if (!(parent instanceof TypeAwareBuilder)) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder instanceof TypeAwareBuilder)) {
             throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()
-                    + "'. Invalid parent node: " + parent);
+                    + "'. Invalid parent node: " + parentBuilder);
         }
-        ((TypeAwareBuilder) parent).setType(type);
+        ((TypeAwareBuilder) parentBuilder).setType(type);
     }
 
     public UnionTypeBuilder addUnionType(final int line, final QNameModule module) {
-        final Builder parent = getActualNode();
-        if (parent == null) {
+        final Builder parentBuilder = getActualNode();
+        if (parentBuilder == null) {
             throw new YangParseException(name, line, "Unresolved parent of union type");
         } else {
             final UnionTypeBuilder union = new UnionTypeBuilder(name, line);
-            if (parent instanceof TypeAwareBuilder) {
-                ((TypeAwareBuilder) parent).setTypedef(union);
+            if (parentBuilder instanceof TypeAwareBuilder) {
+                ((TypeAwareBuilder) parentBuilder).setTypedef(union);
                 return union;
             } else {
                 throw new YangParseException(name, line, "Invalid parent of union type.");
@@ -832,12 +834,12 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) {
         final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(name, line, baseString, schemaPath);
 
-        final Builder parent = getActualNode();
-        if (parent == null) {
+        final Builder parentBuilder = getActualNode();
+        if (parentBuilder == null) {
             throw new YangParseException(name, line, "Unresolved parent of identityref type.");
         } else {
-            if (parent instanceof TypeAwareBuilder) {
-                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+            if (parentBuilder instanceof TypeAwareBuilder) {
+                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parentBuilder;
                 typeParent.setTypedef(identityref);
                 dirtyNodes.add(typeParent);
             } else {
@@ -847,20 +849,20 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     }
 
     public DeviationBuilder addDeviation(final int line, final SchemaPath targetPath) {
-        Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
         }
 
         final DeviationBuilder builder = new DeviationBuilder(name, line, targetPath);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
         deviationBuilders.add(builder);
         return builder;
     }
 
     public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line, final SchemaPath path) {
-        Builder parent = getActualNode();
-        if (!(parent.equals(this))) {
+        Builder parentBuilder = getActualNode();
+        if (!(parentBuilder.equals(this))) {
             throw new YangParseException(name, line, "identity can be defined only in module or submodule");
         }
         String identityName = qname.getLocalName();
@@ -871,7 +873,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         }
 
         final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
         addedIdentities.add(builder);
         return builder;
     }
@@ -883,20 +885,20 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     }
 
     public UnknownSchemaNodeBuilderImpl addUnknownSchemaNode(final int line, final QName qname, final SchemaPath path) {
-        final Builder parent = getActualNode();
+        final Builder parentBuilder = getActualNode();
         final UnknownSchemaNodeBuilderImpl builder = new UnknownSchemaNodeBuilderImpl(name, line, qname, path);
-        builder.setParent(parent);
+        builder.setParent(parentBuilder);
         allUnknownNodes.add(builder);
 
-        if (parent.equals(this)) {
+        if (parentBuilder.equals(this)) {
             addedUnknownNodes.add(builder);
         } else {
-            if (parent instanceof SchemaNodeBuilder) {
-                parent.addUnknownNodeBuilder(builder);
-            } else if (parent instanceof DataNodeContainerBuilder) {
-                parent.addUnknownNodeBuilder(builder);
-            } else if (parent instanceof RefineHolderImpl) {
-                parent.addUnknownNodeBuilder(builder);
+            if (parentBuilder instanceof SchemaNodeBuilder) {
+                parentBuilder.addUnknownNodeBuilder(builder);
+            } else if (parentBuilder instanceof DataNodeContainerBuilder) {
+                parentBuilder.addUnknownNodeBuilder(builder);
+            } else if (parentBuilder instanceof RefineHolderImpl) {
+                parentBuilder.addUnknownNodeBuilder(builder);
             } else {
                 throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName()
                         + "'");
index 00018b8dda1128e20704ac15f5b89d9fff0859e4..f6f152fd35b2dbe441e73d9d01bed6085063b9e2 100644 (file)
@@ -8,6 +8,7 @@ import java.net.URI;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.NavigableSet;
 import java.util.Set;
 import java.util.TreeSet;
 import org.opendaylight.yangtools.concepts.Immutable;
@@ -220,7 +221,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
     }
 
     private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final Set<T> original) {
-        TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+        NavigableSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         sorted.addAll(original);
         return Collections.unmodifiableSet(sorted);
     }
index 25ad30e2dbb121cedc5040afbfe0c806cc11f5c5..1d035a125d64c6f6334bba179dae3a593ae21c8b 100644 (file)
@@ -32,6 +32,11 @@ public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<>();
     private final Set<GroupingBuilder> addedGroupings = new HashSet<>();
 
+    RpcDefinitionBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
+        super(moduleName, line, qname);
+        this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
+    }
+
     public ContainerSchemaNodeBuilder getInput() {
         return inputBuilder;
     }
@@ -40,11 +45,6 @@ public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
         return outputBuilder;
     }
 
-    RpcDefinitionBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
-        super(moduleName, line, qname);
-        this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
-    }
-
     @Override
     public RpcDefinition build() {
         if (instance != null) {
index ad1afc255bebd9177cfef8d885532124c7ab0719..a02baead8db8fb394e9d6514d84fdec4f66c3abb 100644 (file)
@@ -12,8 +12,8 @@ import static org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils.f
 import java.net.URI;
 import java.util.Date;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
-import java.util.TreeMap;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
@@ -49,7 +49,7 @@ public final class TypeUtils {
      *            current module
      */
     public static void resolveType(final TypeAwareBuilder nodeToResolve,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         QName unknownTypeQName = nodeToResolve.getTypeQName();
         final ModuleBuilder dependentModuleBuilder = BuilderUtils.findModule(unknownTypeQName, modules);
         if (dependentModuleBuilder == null) {
@@ -72,7 +72,7 @@ public final class TypeUtils {
      *            current module
      */
     public static void resolveTypeUnion(final UnionTypeBuilder union,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         // special handling for identityref types under union
         for (TypeDefinitionBuilder unionType : union.getTypedefs()) {
             if (unionType instanceof IdentityrefTypeBuilder) {
@@ -111,7 +111,7 @@ public final class TypeUtils {
      * @return TypeDefinitionBuilder of node type
      */
     private static TypeDefinitionBuilder findUnknownTypeDefinition(final TypeAwareBuilder nodeToResolve,
-            final ModuleBuilder dependentModuleBuilder, final Map<URI, TreeMap<Date, ModuleBuilder>> modules,
+            final ModuleBuilder dependentModuleBuilder, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         final int line = nodeToResolve.getLine();
         final QName unknownTypeQName = nodeToResolve.getTypeQName();
@@ -175,7 +175,7 @@ public final class TypeUtils {
     }
 
     private static TypeConstraints findConstraintsFromTypeBuilder(final TypeAwareBuilder nodeToResolve,
-            final TypeConstraints constraints, final Map<URI, TreeMap<Date, ModuleBuilder>> modules,
+            final TypeConstraints constraints, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder builder) {
 
         // union and identityref types cannot be restricted
index 5c79161116084e13f402067b4ed17ce2dee78c20..8ee273e8172a42974d7cdf2b65fa9a1249ef3956 100644 (file)
@@ -261,7 +261,7 @@ final class BasicValidations {
         Iterable<String> keyList = ValidationUtil.listKeysFromId(key);
         Set<String> duplicates = ValidationUtil.getDuplicates(keyList);
 
-        if (duplicates.size() != 0) {
+        if (!duplicates.isEmpty()) {
             ValidationUtil.ex(ValidationUtil.f("(In (sub)module:%s) %s:%s, %s:%s contains duplicates:%s",
                     rootParentName, ValidationUtil.getSimpleStatementName(parent.getClass()),
                     ValidationUtil.getName(parent), ValidationUtil.getSimpleStatementName(ctx.getClass()), key,
index 5684c045d5a08d1412b48bfdf3db5a28f2b7e21d..fdc8369f4ada260763c4fc4f2a88f906aa1f5d79 100644 (file)
@@ -141,7 +141,7 @@ public final class YangParserImpl implements YangContextParser {
 
         // module builders sorted by dependencies
         List<ModuleBuilder> sortedBuilders = ModuleDependencySort.sort(resolved);
-        Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
+        Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
         Collection<Module> unsorted = build(modules).values();
         Set<Module> result = new LinkedHashSet<>(
                 ModuleDependencySort.sort(unsorted.toArray(new Module[unsorted.size()])));
@@ -218,7 +218,7 @@ public final class YangParserImpl implements YangContextParser {
         }
 
         final List<ModuleBuilder> sorted = resolveModuleBuilders(sources, context);
-        final Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, context);
+        final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, context);
 
         final Set<Module> unsorted = new LinkedHashSet<>(build(modules).values());
         if (context != null) {
@@ -233,9 +233,9 @@ public final class YangParserImpl implements YangContextParser {
         return resolveSchemaContext(result);
     }
 
-    private static Map<URI, TreeMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
+    private static Map<URI, NavigableMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
             final SchemaContext context) {
-        final Map<URI, TreeMap<Date, ModuleBuilder>> modules = orderModules(sorted);
+        final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = orderModules(sorted);
         for (ModuleBuilder module : sorted) {
             if (module != null) {
                 for (ModuleImport imp : module.getImports().values()) {
@@ -244,7 +244,7 @@ public final class YangParserImpl implements YangContextParser {
                     if (targetModule == null) {
                         Module result = findModuleFromContext(context, module, prefix, 0);
                         targetModule = new ModuleBuilder(result);
-                        TreeMap<Date, ModuleBuilder> map = modules.get(targetModule.getNamespace());
+                        NavigableMap<Date, ModuleBuilder> map = modules.get(targetModule.getNamespace());
                         if (map == null) {
                             map = new TreeMap<>();
                             map.put(targetModule.getRevision(), targetModule);
@@ -335,7 +335,7 @@ public final class YangParserImpl implements YangContextParser {
     public Collection<Module> buildModules(final Collection<ModuleBuilder> builders) {
         Collection<ModuleBuilder> unsorted = resolveSubmodules(builders);
         List<ModuleBuilder> sorted = ModuleDependencySort.sort(unsorted);
-        Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
+        Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
         Map<ModuleBuilder, Module> builderToModule = build(modules);
         return builderToModule.values();
     }
@@ -354,7 +354,7 @@ public final class YangParserImpl implements YangContextParser {
         Map<ByteSource, ModuleBuilder> sourceToBuilder = resolveSources(sources, context);
         // sort and check for duplicates
         List<ModuleBuilder> sorted = ModuleDependencySort.sort(sourceToBuilder.values());
-        Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
+        Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
         Map<ModuleBuilder, Module> builderToModule = build(modules);
         Map<ModuleBuilder, ByteSource> builderToSource = HashBiMap.create(sourceToBuilder).inverse();
         sorted = ModuleDependencySort.sort(builderToModule.keySet());
@@ -392,7 +392,7 @@ public final class YangParserImpl implements YangContextParser {
         // validate yang
         new YangModelBasicValidator(walker).validate(sourceToTree.values());
 
-        Map<String, TreeMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
+        Map<String, NavigableMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
                 sourceToTree.values(), Optional.fromNullable(context));
         YangParserListenerImpl yangModelParser;
         for (Map.Entry<ByteSource, ParseTree> entry : sourceToTree.entrySet()) {
@@ -416,12 +416,12 @@ public final class YangParserImpl implements YangContextParser {
 
     private Map<ByteSource, ModuleBuilder> resolveSubmodules(final Map<ByteSource, ModuleBuilder> builders) {
         Map<ByteSource, ModuleBuilder> modules = new HashMap<>();
-        Map<String, TreeMap<Date, ModuleBuilder>> submodules = new HashMap<>();
+        Map<String, NavigableMap<Date, ModuleBuilder>> submodules = new HashMap<>();
         for (Map.Entry<ByteSource, ModuleBuilder> entry : builders.entrySet()) {
             ModuleBuilder builder = entry.getValue();
             if (builder.isSubmodule()) {
                 String submoduleName = builder.getName();
-                TreeMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
+                NavigableMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
                 if (map == null) {
                     map = new TreeMap<>();
                     map.put(builder.getRevision(), builder);
@@ -443,11 +443,11 @@ public final class YangParserImpl implements YangContextParser {
 
     private Collection<ModuleBuilder> resolveSubmodules(final Collection<ModuleBuilder> builders) {
         Collection<ModuleBuilder> modules = new HashSet<>();
-        Map<String, TreeMap<Date, ModuleBuilder>> submodules = new HashMap<>();
+        Map<String, NavigableMap<Date, ModuleBuilder>> submodules = new HashMap<>();
         for (ModuleBuilder builder : builders) {
             if (builder.isSubmodule()) {
                 String submoduleName = builder.getName();
-                TreeMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
+                NavigableMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
                 if (map == null) {
                     map = new TreeMap<>();
                     map.put(builder.getRevision(), builder);
@@ -478,7 +478,7 @@ public final class YangParserImpl implements YangContextParser {
      * @return collection of module builders with resolved submodules
      */
     private void resolveSubmodules(final ModuleBuilder module,
-            final Map<String, TreeMap<Date, ModuleBuilder>> submodules) {
+            final Map<String, NavigableMap<Date, ModuleBuilder>> submodules) {
         Map<String, Date> includes = module.getIncludedModules();
         for (Map.Entry<String, Date> entry : includes.entrySet()) {
             NavigableMap<Date, ModuleBuilder> subs = submodules.get(entry.getKey());
@@ -499,7 +499,7 @@ public final class YangParserImpl implements YangContextParser {
                 }
             }
 
-            if (submodule.getIncludedModules().size() > 0) {
+            if (!submodule.getIncludedModules().isEmpty()) {
                 resolveSubmodules(submodule, submodules);
             }
             addSubmoduleToModule(submodule, module);
@@ -563,8 +563,8 @@ public final class YangParserImpl implements YangContextParser {
      *            topologically sorted modules
      * @return modules ordered by namespace and revision
      */
-    private static Map<URI, TreeMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
-        final Map<URI, TreeMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
+    private static Map<URI, NavigableMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
+        final Map<URI, NavigableMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
         for (final ModuleBuilder builder : modules) {
             if (builder == null) {
                 continue;
@@ -576,7 +576,7 @@ public final class YangParserImpl implements YangContextParser {
                 rev = new Date(0);
             }
 
-            TreeMap<Date, ModuleBuilder> builderByRevision = result.get(ns);
+            NavigableMap<Date, ModuleBuilder> builderByRevision = result.get(ns);
             if (builderByRevision == null) {
                 builderByRevision = new TreeMap<>();
                 builderByRevision.put(rev, builder);
@@ -606,7 +606,7 @@ public final class YangParserImpl implements YangContextParser {
 
         // if this is submodule, add parent to filtered and pick its imports
         if (main.isSubmodule()) {
-            TreeMap<Date, ModuleBuilder> dependencies = new TreeMap<>();
+            NavigableMap<Date, ModuleBuilder> dependencies = new TreeMap<>();
             for (ModuleBuilder mb : other) {
                 if (mb.getName().equals(main.getBelongsTo())) {
                     dependencies.put(mb.getRevision(), mb);
@@ -626,11 +626,9 @@ public final class YangParserImpl implements YangContextParser {
                             filterImports(builder, other, filtered);
                         }
                     } else {
-                        if (mi.getRevision().equals(builder.getRevision())) {
-                            if (!filtered.contains(builder)) {
-                                filtered.add(builder);
-                                filterImports(builder, other, filtered);
-                            }
+                        if (!filtered.contains(builder) && mi.getRevision().equals(builder.getRevision())) {
+                            filtered.add(builder);
+                            filterImports(builder, other, filtered);
                         }
                     }
                 }
@@ -705,7 +703,7 @@ public final class YangParserImpl implements YangContextParser {
      *            all loaded modules
      * @return modules mapped on their builders
      */
-    private Map<ModuleBuilder, Module> build(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private Map<ModuleBuilder, Module> build(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         resolveDirtyNodes(modules);
         resolveAugmentsTargetPath(modules);
         resolveUsesTargetGrouping(modules);
@@ -717,7 +715,7 @@ public final class YangParserImpl implements YangContextParser {
 
         // build
         final Map<ModuleBuilder, Module> result = new LinkedHashMap<>();
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder moduleBuilder = childEntry.getValue();
                 final Module module = moduleBuilder.build();
@@ -733,8 +731,8 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveDirtyNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+    private void resolveDirtyNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder module = childEntry.getValue();
                 resolveUnknownNodes(modules, module);
@@ -752,7 +750,7 @@ public final class YangParserImpl implements YangContextParser {
      * @param module
      *            current module
      */
-    private void resolveDirtyNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+    private void resolveDirtyNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
         if (!dirtyNodes.isEmpty()) {
             for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
@@ -783,10 +781,10 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveAugmentsTargetPath(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveAugmentsTargetPath(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         // collect augments from all loaded modules
         final List<AugmentationSchemaBuilder> allAugments = new ArrayList<>();
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 allAugments.addAll(inner.getValue().getAllAugments());
             }
@@ -896,9 +894,9 @@ public final class YangParserImpl implements YangContextParser {
      *            all loaded modules topologically sorted (based on dependencies
      *            between each other)
      */
-    private void resolveAugments(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveAugments(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         List<ModuleBuilder> all = new ArrayList<>();
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 all.add(inner.getValue());
             }
@@ -934,7 +932,7 @@ public final class YangParserImpl implements YangContextParser {
      * @return true if augment process succeed
      */
     private boolean resolveUsesAugment(final AugmentationSchemaBuilder augment, final ModuleBuilder module,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         if (augment.isResolved()) {
             return true;
         }
@@ -994,7 +992,7 @@ public final class YangParserImpl implements YangContextParser {
      * @return true if augment process succeed
      */
     private boolean resolveAugment(final AugmentationSchemaBuilder augment, final ModuleBuilder module,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         if (augment.isResolved()) {
             return true;
         }
@@ -1016,8 +1014,8 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveIdentities(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+    private void resolveIdentities(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 ModuleBuilder module = inner.getValue();
                 final Set<IdentitySchemaNodeBuilder> identities = module.getAddedIdentities();
@@ -1076,9 +1074,9 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveUsesTargetGrouping(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveUsesTargetGrouping(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         final List<UsesNodeBuilder> allUses = new ArrayList<>();
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 allUses.addAll(inner.getValue().getAllUsesNodes());
             }
@@ -1097,9 +1095,9 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveUsesForGroupings(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveUsesForGroupings(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         final Set<GroupingBuilder> allGroupings = new HashSet<>();
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 ModuleBuilder module = inner.getValue();
                 allGroupings.addAll(module.getAllGroupings());
@@ -1121,8 +1119,8 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveUsesForNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+    private void resolveUsesForNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 ModuleBuilder module = inner.getValue();
                 List<UsesNodeBuilder> usesNodes = module.getAllUsesNodes();
@@ -1143,7 +1141,7 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void resolveUses(final UsesNodeBuilder usesNode, final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveUses(final UsesNodeBuilder usesNode, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
         if (!usesNode.isResolved()) {
             DataNodeContainerBuilder parent = usesNode.getParent();
             ModuleBuilder module = BuilderUtils.getParentModule(parent);
@@ -1177,11 +1175,9 @@ public final class YangParserImpl implements YangContextParser {
 
         DataSchemaNodeBuilder nextNodeAfterUses = null;
         for (DataSchemaNodeBuilder childNode : childNodes) {
-            if (!(childNode.isAddedByUses()) && !(childNode.isAugmenting())) {
-                if (childNode.getLine() > usesLine) {
-                    nextNodeAfterUses = childNode;
-                    break;
-                }
+            if (!childNode.isAddedByUses() && !childNode.isAugmenting() && childNode.getLine() > usesLine) {
+                nextNodeAfterUses = childNode;
+                break;
             }
         }
 
@@ -1202,7 +1198,7 @@ public final class YangParserImpl implements YangContextParser {
      * @param module
      *            current module
      */
-    private void resolveUnknownNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+    private void resolveUnknownNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         for (UnknownSchemaNodeBuilder usnb : module.getAllUnknownNodes()) {
             QName nodeType = usnb.getNodeType();
             String localName = usnb.getNodeType().getLocalName();
@@ -1257,8 +1253,8 @@ public final class YangParserImpl implements YangContextParser {
      * @param modules
      *            all loaded modules
      */
-    private void checkChoiceCasesForDuplicityQNames(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+    private void checkChoiceCasesForDuplicityQNames(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder moduleBuilder = childEntry.getValue();
                 final Module module = moduleBuilder.build();
@@ -1272,8 +1268,8 @@ public final class YangParserImpl implements YangContextParser {
     }
 
     private void findDuplicityNodesIn(final ChoiceSchemaNode choiceNode, final Module module, final ModuleBuilder moduleBuilder,
-            final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
-        final Set<QName> duplicityTestSet = new HashSet<QName>();
+            final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+        final Set<QName> duplicityTestSet = new HashSet<>();
 
         for (ChoiceCaseNode choiceCaseNode : choiceNode.getCases()) {
 
@@ -1294,7 +1290,7 @@ public final class YangParserImpl implements YangContextParser {
     }
 
     private List<ChoiceSchemaNode> getChoicesFrom(final Module module) {
-        final List<ChoiceSchemaNode> allChoices = new ArrayList<ChoiceSchemaNode>();
+        final List<ChoiceSchemaNode> allChoices = new ArrayList<>();
 
         for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
             findChoicesIn(dataSchemaNode, allChoices);
index 77a0a354dfa341e69805bdf0769eaa46358cb3f0..1e71e4d2c58a454ee610d62eb4bdf63d5abaa25c 100644 (file)
@@ -34,8 +34,8 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
-import java.util.TreeMap;
 import org.antlr.v4.runtime.tree.ParseTree;
 import org.antlr.v4.runtime.tree.ParseTreeWalker;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser;
@@ -103,16 +103,22 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public final class YangParserListenerImpl extends YangParserBaseListener {
     private static final Logger LOG = LoggerFactory.getLogger(YangParserListenerImpl.class);
     private static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
     private static final Splitter COLON_SPLITTER = Splitter.on(':');
     private static final String AUGMENT_STR = "augment";
 
-    private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+    private static final String IMPORT_STR = "import";
+    private static final String UNION_STR = "union";
+    private static final String UNKNOWN_NODE_STR = "unknown-node";
+
+    /**
+     * Date Format is not thread-safe so we cannot make constant from it.
+     */
+    private final DateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd");
     private final SchemaPathStack stack = new SchemaPathStack();
-    private final Map<String, TreeMap<Date, URI>> namespaceContext;
+    private final Map<String, NavigableMap<Date, URI>> namespaceContext;
     private final String sourcePath;
     private QName moduleQName = QName.create(null, new Date(0L), "dummy");
     private ModuleBuilder moduleBuilder;
@@ -120,7 +126,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     private int augmentOrder;
     private String yangModelPrefix;
 
-    public YangParserListenerImpl(final Map<String, TreeMap<Date, URI>> namespaceContext, final String sourcePath) {
+    public YangParserListenerImpl(final Map<String, NavigableMap<Date, URI>> namespaceContext, final String sourcePath) {
         this.namespaceContext = namespaceContext;
         this.sourcePath = sourcePath;
     }
@@ -138,15 +144,13 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
      * @param tree
      * @return new instance of YangParserListenerImpl
      */
-    public static YangParserListenerImpl create(final Map<String, TreeMap<Date, URI>> namespaceContext,
+    public static YangParserListenerImpl create(final Map<String, NavigableMap<Date, URI>> namespaceContext,
             final String sourcePath, final ParseTreeWalker walker, final ParseTree tree) {
         final YangParserListenerImpl ret = new YangParserListenerImpl(namespaceContext, sourcePath);
         walker.walk(ret, tree);
         return ret;
     }
 
-
-
     @Override
     public void enterModule_stmt(final YangParser.Module_stmtContext ctx) {
         moduleName = stringFromNode(ctx);
@@ -159,7 +163,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String description = null;
         String reference = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
+            final ParseTree child = ctx.getChild(i);
             if (child instanceof Description_stmtContext) {
                 description = stringFromNode(child);
             } else if (child instanceof Reference_stmtContext) {
@@ -192,7 +196,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String description = null;
         String reference = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
+            final ParseTree child = ctx.getChild(i);
             if (child instanceof Description_stmtContext) {
                 description = stringFromNode(child);
             } else if (child instanceof Reference_stmtContext) {
@@ -216,7 +220,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void enterBelongs_to_stmt(final YangParser.Belongs_to_stmtContext ctx) {
         final String belongsTo = stringFromNode(ctx);
-        TreeMap<Date, URI> context = namespaceContext.get(belongsTo);
+        final NavigableMap<Date, URI> context = namespaceContext.get(belongsTo);
         final Map.Entry<Date, URI> entry = context.firstEntry();
         // TODO
         // Submodule will contain namespace and revision from module to which it
@@ -318,19 +322,19 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     private void updateRevisionForRevisionStatement(final ParseTree treeNode) {
         final String revisionDateStr = stringFromNode(treeNode);
         try {
-            final Date revisionDate = SIMPLE_DATE_FORMAT.parse(revisionDateStr);
+            final Date revisionDate = revisionFormat.parse(revisionDateStr);
             if ((revisionDate != null) && (this.moduleQName.getRevision().compareTo(revisionDate) < 0)) {
                 this.moduleQName = QName.create(moduleQName.getNamespace(), revisionDate, moduleQName.getLocalName());
                 moduleBuilder.setQNameModule(moduleQName.getModule());
                 setLog("revision", revisionDate.toString());
                 for (int i = 0; i < treeNode.getChildCount(); ++i) {
-                    ParseTree child = treeNode.getChild(i);
+                    final ParseTree child = treeNode.getChild(i);
                     if (child instanceof Reference_stmtContext) {
                         moduleBuilder.setReference(stringFromNode(child));
                     }
                 }
             }
-        } catch (ParseException e) {
+        } catch (final ParseException e) {
             LOG.warn("Failed to parse revision string: {}", revisionDateStr, e);
         }
     }
@@ -339,7 +343,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterImport_stmt(final Import_stmtContext ctx) {
         final int line = ctx.getStart().getLine();
         final String importName = stringFromNode(ctx);
-        enterLog("import", importName, line);
+        enterLog(IMPORT_STR, importName, line);
 
         String importPrefix = null;
         Date importRevision = null;
@@ -349,10 +353,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             if (treeNode instanceof Prefix_stmtContext) {
                 importPrefix = stringFromNode(treeNode);
             } else if (treeNode instanceof Revision_date_stmtContext) {
-                String importRevisionStr = stringFromNode(treeNode);
+                final String importRevisionStr = stringFromNode(treeNode);
                 try {
-                    importRevision = SIMPLE_DATE_FORMAT.parse(importRevisionStr);
-                } catch (ParseException e) {
+                    importRevision = revisionFormat.parse(importRevisionStr);
+                } catch (final ParseException e) {
                     LOG.warn("Failed to parse import revision-date at line {}: {}", line, importRevisionStr, e);
                 }
             }
@@ -363,14 +367,14 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
     @Override
     public void exitImport_stmt(final Import_stmtContext ctx) {
-        exitLog("import");
+        exitLog(IMPORT_STR);
     }
 
     @Override
-    public void enterInclude_stmt(YangParser.Include_stmtContext ctx) {
+    public void enterInclude_stmt(final YangParser.Include_stmtContext ctx) {
         final int line = ctx.getStart().getLine();
         final String includeName = stringFromNode(ctx);
-        enterLog("import", includeName, line);
+        enterLog(IMPORT_STR, includeName, line);
 
         Date includeRevision = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -378,8 +382,8 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             if (treeNode instanceof Revision_date_stmtContext) {
                 final String importRevisionStr = stringFromNode(treeNode);
                 try {
-                    includeRevision = SIMPLE_DATE_FORMAT.parse(importRevisionStr);
-                } catch (ParseException e) {
+                    includeRevision = revisionFormat.parse(importRevisionStr);
+                } catch (final ParseException e) {
                     LOG.warn("Failed to parse import revision-date at line {}: {}", line, importRevisionStr, e);
                 }
             }
@@ -387,7 +391,8 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         moduleBuilder.addInclude(includeName, includeRevision);
     }
 
-    @Override public void exitInclude_stmt(YangParser.Include_stmtContext ctx) {
+    @Override
+    public void exitInclude_stmt(final YangParser.Include_stmtContext ctx) {
         exitLog("include");
     }
 
@@ -399,10 +404,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         stack.push();
 
         final SchemaPath targetPath = parseXPathString(augmentPath, line);
-        final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
+        final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath,
+                augmentOrder++);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
+            final ParseTree child = ctx.getChild(i);
             if (child instanceof Description_stmtContext) {
                 builder.setDescription(stringFromNode(child));
             } else if (child instanceof Reference_stmtContext) {
@@ -508,12 +514,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             } else {
                 QName qname;
                 switch (typeName) {
-                case "union":
-                    qname = BaseTypes.UNION_QNAME;
-                    stack.addNodeToPath(qname);
+                case UNION_STR:
+                    stack.addNodeToPath(BaseTypes.UNION_QNAME);
                     final UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(line, moduleQName.getModule());
-                    final Builder parent = moduleBuilder.getActualNode();
-                    unionBuilder.setParent(parent);
+                    final Builder parentBuilder = moduleBuilder.getActualNode();
+                    unionBuilder.setParent(parentBuilder);
                     moduleBuilder.enterNode(unionBuilder);
                     break;
                 case "identityref":
@@ -534,23 +539,28 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 parent.setTypeQName(typeQName);
                 moduleBuilder.markActualNodeDirty();
             } else {
-                ParserListenerUtils.parseUnknownTypeWithBody(typeBody, parent, typeQName, moduleBuilder,
-                        moduleQName, stack.currentSchemaPath());
+                ParserListenerUtils.parseUnknownTypeWithBody(typeBody, parent, typeQName, moduleBuilder, moduleQName,
+                        stack.currentSchemaPath());
             }
             stack.addNodeToPath(QName.create(moduleQName.getModule(), typeQName.getLocalName()));
         }
     }
 
     /**
-     * Method transforms string representation of yang element (i.e. leaf name, container name etc.) into QName.
-     * The namespace of QName is assigned from parent module same as revision date of module. If String qname parameter
-     * contains ":" the string is evaluated as prefix:name of element. In this case method will look into import map
-     * and extract correct ModuleImport. If such import is not present in import map the method will throw {@link YangParseException}
-     * <br>
-     * If ModuleImport is present but the value of namespace in ModuleImport is <code>null</code> the method will throw {@link YangParseException}
+     * Method transforms string representation of yang element (i.e. leaf name,
+     * container name etc.) into QName. The namespace of QName is assigned from
+     * parent module same as revision date of module. If String qname parameter
+     * contains ":" the string is evaluated as prefix:name of element. In this
+     * case method will look into import map and extract correct ModuleImport.
+     * If such import is not present in import map the method will throw
+     * {@link YangParseException} <br>
+     * If ModuleImport is present but the value of namespace in ModuleImport is
+     * <code>null</code> the method will throw {@link YangParseException}
      *
-     * @param qnameString QName value as String
-     * @param line line in Yang model document where QName occur.
+     * @param qnameString
+     *            QName value as String
+     * @param line
+     *            line in Yang model document where QName occur.
      * @return transformed string qname parameter as QName structure.
      *
      * @throws YangParseException
@@ -570,10 +580,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 if (imp == null) {
                     LOG.debug("Error in module {} at line {}: No import found with prefix {}", moduleName, line, prefix);
                     throw new YangParseException(moduleName, line, "Error in module " + moduleName
-                        + " No import found with prefix " + prefix + " not found.");
+                            + " No import found with prefix " + prefix + " not found.");
                 }
                 Date revision = imp.getRevision();
-                TreeMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
+                final NavigableMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
                 if (namespaces == null) {
                     throw new YangParseException(moduleName, line, String.format("Imported module %s not found",
                             imp.getModuleName()));
@@ -583,9 +593,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                     revision = namespaces.lastEntry().getKey();
                     namespace = namespaces.lastEntry().getValue();
                 } else {
-                    // FIXME: this lookup does not look right, as we will end up with
-                    //        a qname which does not have a namespace. At any rate we
-                    //        should arrive at a QNameModule!
+                    // FIXME: this lookup does not look right, as we will end up
+                    // with
+                    // a qname which does not have a namespace. At any rate we
+                    // should arrive at a QNameModule!
                     namespace = namespaces.get(revision);
                 }
 
@@ -599,7 +610,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void exitType_stmt(final YangParser.Type_stmtContext ctx) {
         final String typeName = stringFromNode(ctx);
-        if ("union".equals(typeName)) {
+        if (UNION_STR.equals(typeName)) {
             moduleBuilder.exitNode();
         }
         exitLog("type", stack.removeNodeFromPath());
@@ -718,7 +729,8 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         stack.push();
 
         final SchemaPath targetPath = parseXPathString(augmentPath, line);
-        final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
+        final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath,
+                augmentOrder++);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
             final ParseTree child = ctx.getChild(i);
@@ -816,10 +828,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             } else if (childNode instanceof Key_stmtContext) {
                 final Set<String> key = createListKey((Key_stmtContext) childNode);
                 builder.setKeys(key);
-            } else if (childNode instanceof YangParser.Identifier_stmtContext) {
-                if (childNode.getChild(0).toString().equals("union")) {
-                    throw new YangParseException(moduleName, line, "Union statement is not allowed inside a list statement");
-                }
+            } else if (childNode instanceof YangParser.Identifier_stmtContext
+                    && UNION_STR.equals(childNode.getChild(0).toString())) {
+                throw new YangParseException(moduleName, line, "Union statement is not allowed inside a list statement");
             }
         }
     }
@@ -938,16 +949,18 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void exitIdentifier_stmt(final YangParser.Identifier_stmtContext ctx) {
         moduleBuilder.exitNode();
-        exitLog("unknown-node", stack.removeNodeFromPath());
+        exitLog(UNKNOWN_NODE_STR, stack.removeNodeFromPath());
     }
 
-    @Override public void enterUnknown_statement(final YangParser.Unknown_statementContext ctx) {
+    @Override
+    public void enterUnknown_statement(final YangParser.Unknown_statementContext ctx) {
         handleUnknownNode(ctx.getStart().getLine(), ctx);
     }
 
-    @Override public void exitUnknown_statement(final YangParser.Unknown_statementContext ctx) {
+    @Override
+    public void exitUnknown_statement(final YangParser.Unknown_statementContext ctx) {
         moduleBuilder.exitNode();
-        exitLog("unknown-node", stack.removeNodeFromPath());
+        exitLog(UNKNOWN_NODE_STR, stack.removeNodeFromPath());
     }
 
     @Override
@@ -1056,7 +1069,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         moduleBuilder.enterNode(builder);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
+            final ParseTree child = ctx.getChild(i);
             if (child instanceof Reference_stmtContext) {
                 reference = stringFromNode(child);
             } else if (child instanceof Deviate_not_supported_stmtContext) {
@@ -1077,7 +1090,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final boolean absolute = !xpathString.isEmpty() && xpathString.charAt(0) == '/';
 
         final List<QName> path = new ArrayList<>();
-        for (String pathElement : SLASH_SPLITTER.split(xpathString)) {
+        for (final String pathElement : SLASH_SPLITTER.split(xpathString)) {
             final Iterator<String> it = COLON_SPLITTER.split(pathElement).iterator();
             final String s = it.next();
             if (it.hasNext()) {
@@ -1112,7 +1125,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         for (int i = 0; i < ctx.getChildCount(); i++) {
             final ParseTree child = ctx.getChild(i);
             if (child instanceof Base_stmtContext) {
-                String baseIdentityName = stringFromNode(child);
+                final String baseIdentityName = stringFromNode(child);
                 builder.setBaseIdentityName(baseIdentityName);
             }
         }
@@ -1146,16 +1159,19 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
     private void handleUnknownNode(final int line, final ParseTree ctx) {
         final String nodeParameter = stringFromNode(ctx);
-        enterLog("unknown-node", nodeParameter, line);
+        enterLog(UNKNOWN_NODE_STR, nodeParameter, line);
 
         final String nodeTypeStr = ctx.getChild(0).getText();
         final QName nodeType = parseQName(nodeTypeStr, line);
 
         QName qname = null;
         try {
-            //FIXME: rewrite whole method to handle unknown nodes properly.
-            // This should be bugfix for bug https://bugs.opendaylight.org/show_bug.cgi?id=1539
-            // After this fix bug https://bugs.opendaylight.org/show_bug.cgi?id=1538 MUST be fixed since
+            // FIXME: rewrite whole method to handle unknown nodes properly.
+            // This should be bugfix for bug
+            // https://bugs.opendaylight.org/show_bug.cgi?id=1539
+            // After this fix bug
+            // https://bugs.opendaylight.org/show_bug.cgi?id=1538 MUST be fixed
+            // since
             // they are dependent!!!
             if (Strings.isNullOrEmpty(nodeParameter)) {
                 qname = nodeType;
index 6a0d38e2441384cd049bb8c4fe69855c8213879b..b5b3cf02915647a449fb6b25d3086f9fcb7ed44b 100644 (file)
@@ -24,6 +24,9 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 
+import javax.annotation.concurrent.Immutable;
+
+@Immutable
 public class YangStatementParserListenerImpl extends YangStatementParserBaseListener {
 
     private StatementWriter writer;
@@ -57,7 +60,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 try {
                     QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
                             ((YangStatementParser.KeywordContext) child).children.get(0).getText());
-                    if (stmtDef != null && stmtDef.get(identifier) != null && toBeSkipped.isEmpty()) {
+                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
                         writer.startStatement(identifier, ref);
                     } else {
                         action = false;
@@ -68,11 +71,12 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 }
             } else if (child instanceof YangStatementParser.ArgumentContext) {
                 try {
-                    if (action)
+                    if (action) {
                         writer.argumentValue(
                                 Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
-                    else
+                    } else {
                         action = true;
+                    }
                 } catch (SourceException e) {
                     LOG.warn(e.getMessage(), e);
                 }
@@ -89,7 +93,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 try {
                     String statementName = ((YangStatementParser.KeywordContext) child).children.get(0).getText();
                     QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE, statementName);
-                    if (stmtDef != null && stmtDef.get(identifier) != null && toBeSkipped.isEmpty()) {
+                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
                         writer.endStatement(ref);
                     }
 
index 252a782e1567eea80aad6ed7365df494decb9bd4..91c5c18028ffd58f9d232006868055c6b96d8ab1 100644 (file)
@@ -95,7 +95,7 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
         return stream;
     }
 
-    private final class SourceContext extends AbstractObjectRegistration<URL> //
+    private final class SourceContext extends AbstractObjectRegistration<URL>
             implements Identifiable<SourceIdentifier> {
 
         final SourceIdentifier identifier;
@@ -146,7 +146,7 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
         YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this);
         LOG.debug("Trying to create schema context from {}", sourcesMap.keySet());
 
-        if (yangSourceContext.getMissingDependencies().size() != 0) {
+        if (!yangSourceContext.getMissingDependencies().isEmpty()) {
             LOG.debug("Omitting {} because of unresolved dependencies", yangSourceContext.getMissingDependencies().keySet());
             LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources());
         }
index bbe69e0410b701c924ef3972b81ca1400fb9df64..fcb2c1835f83f996caafea819f825f84c6eaa3d2 100644 (file)
@@ -62,9 +62,9 @@ public abstract class YangModelDependencyInfo {
         this.revision = formattedRevision == null ? null : QName.parseRevision(formattedRevision);
         this.moduleImports = imports;
         this.submoduleIncludes = includes;
-        this.dependencies = ImmutableSet.<ModuleImport> builder() //
-                .addAll(moduleImports) //
-                .addAll(submoduleIncludes) //
+        this.dependencies = ImmutableSet.<ModuleImport> builder()
+                .addAll(moduleImports)
+                .addAll(submoduleIncludes)
                 .build();
     }
 
@@ -214,8 +214,8 @@ public abstract class YangModelDependencyInfo {
         return builder.build();
     }
 
-    public static String getLatestRevision(final Revision_stmtsContext revision_stmts) {
-        List<Revision_stmtContext> revisions = revision_stmts.getRuleContexts(Revision_stmtContext.class);
+    public static String getLatestRevision(final Revision_stmtsContext revisionStmts) {
+        List<Revision_stmtContext> revisions = revisionStmts.getRuleContexts(Revision_stmtContext.class);
         String latestRevision = null;
         for (Revision_stmtContext revisionStmt : revisions) {
             String currentRevision = getArgumentString(revisionStmt);
@@ -248,11 +248,11 @@ public abstract class YangModelDependencyInfo {
         return builder.build();
     }
 
-    private static Date getRevision(final Revision_date_stmtContext revision_date_stmt) {
-        if (revision_date_stmt == null) {
+    private static Date getRevision(final Revision_date_stmtContext revisionDateStmt) {
+        if (revisionDateStmt == null) {
             return null;
         }
-        String formatedDate = getArgumentString(revision_date_stmt);
+        String formatedDate = getArgumentString(revisionDateStmt);
         return QName.parseRevision(formatedDate);
     }
 
@@ -285,6 +285,12 @@ public abstract class YangModelDependencyInfo {
 
         private final String belongsTo;
 
+        private SubmoduleDependencyInfo(final String name, final String latestRevision, final String belongsTo,
+                                        final ImmutableSet<ModuleImport> imports, final ImmutableSet<ModuleImport> includes) {
+            super(name, latestRevision, imports, includes);
+            this.belongsTo = belongsTo;
+        }
+
         /**
          * Returns name of parent module.
          *
@@ -293,12 +299,6 @@ public abstract class YangModelDependencyInfo {
             return belongsTo;
         }
 
-        private SubmoduleDependencyInfo(final String name, final String latestRevision, final String belongsTo,
-                final ImmutableSet<ModuleImport> imports, final ImmutableSet<ModuleImport> includes) {
-            super(name, latestRevision, imports, includes);
-            this.belongsTo = belongsTo;
-        }
-
         @Override
         public String toString() {
             return "Submodule [name=" + getName() + ", revision=" + getRevision() + ", dependencies="
index ebe602d5a72c42a06fec63899b8d63a0d8b9d2ce..f8fc1770b827327621ddd370451dd71bac370204 100644 (file)
@@ -7,22 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.repo;
 
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
@@ -31,9 +15,11 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.NavigableMap;
 import java.util.Set;
-import java.util.TreeMap;
+
 import javax.annotation.Nullable;
+
 import org.antlr.v4.runtime.ParserRuleContext;
 import org.antlr.v4.runtime.tree.ParseTreeWalker;
 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
@@ -53,6 +39,23 @@ import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
 final class SharedSchemaContextFactory implements SchemaContextFactory {
     private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper.create("resolve sources", SchemaResolutionException.class);
     private static final Logger LOG = LoggerFactory.getLogger(SharedSchemaContextFactory.class);
@@ -87,7 +90,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
 
             final Map<SourceIdentifier, ParserRuleContext> asts =
                     Maps.transformValues(srcs, ASTSchemaSource.GET_AST);
-            final Map<String, TreeMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
+            final Map<String, NavigableMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
                     asts.values(), Optional.<SchemaContext>absent());
 
             final ParseTreeWalker walker = new ParseTreeWalker();
index b0c23ea3c5ea83c4dd1463285279089da4df460d..583c0d821e67b6689934c4174ee4d44d4d8e3b27 100644 (file)
@@ -81,7 +81,7 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
      *
      */
     @Override
-    public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException, SourceException {
+    public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
         // NOOP for most implementations
     }
 
@@ -95,8 +95,7 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
      *
      */
     @Override
-    public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
-            SourceException {
+    public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
         // NOOP for most implementations
     }
 
@@ -110,7 +109,7 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
      *
      */
     @Override
-    public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException, SourceException {
+    public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
         // NOOP for most implementations
     }
 
index 129110d8537491c41716a7db9f59d40bcdcb7042..6522af9227cb35e465ba6b5b315a962ab68f8c38 100644 (file)
@@ -46,8 +46,6 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
 
         @Nullable  <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(Class<N> type, K key);
 
-        //<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromLocalStorage(Class<N> type);
-
         @Nullable  <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(Class<N> type, K key, V value);
 
     }
@@ -103,8 +101,6 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
 
     public abstract V getFrom(NamespaceStorageNode storage, K key);
 
-    //public abstract Map<K, V> getAllFrom(NamespaceStorageNode storage);
-
     public abstract void addTo(NamespaceStorageNode storage,K key,V value);
 
     @Override
@@ -116,10 +112,6 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
         return storage.getFromLocalStorage(getIdentifier(), key);
     }
 
-//    protected final Map<K, V> getAllFromLocalStorage(NamespaceStorageNode storage) {
-//        return storage.getAllFromLocalStorage(getIdentifier());
-//    }
-
     protected final void addToStorage(NamespaceStorageNode storage,K key,V value) {
         storage.addToLocalStorage(getIdentifier(),key,value);
     }
@@ -142,15 +134,6 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
             return getFromLocalStorage(current,key);
         }
 
-//        @Override
-//        public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
-//            NamespaceStorageNode current = storage;
-//            while(current.getStorageNodeType() != storageType) {
-//                current = current.getParentNamespaceStorage();
-//            }
-//            return getAllFromLocalStorage(current);
-//        }
-
         @Override
         public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, K key, V value) {
             NamespaceStorageNode current = storage;
index e270f806a91f93812d13dab32d8cd4c36c10732a..f240105a0998758a117321d47eadbd0b913bee9b 100644 (file)
@@ -69,8 +69,7 @@ public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends E
      * @param stmt
      *            Context of added statement.
      */
-     void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
-            SourceException;
+     void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
 
     /**
      *
@@ -89,8 +88,7 @@ public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends E
      *            Context of added statement. Argument and statement parent is
      *            accessible.
      */
-     void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
-            SourceException;
+     void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
 
     /**
      *
@@ -110,7 +108,6 @@ public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends E
      *            Context of added statement. Argument and statement parent is
      *            accessible.
      */
-     void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
-            SourceException;
+     void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
 
 }
\ No newline at end of file
index 01435600334c555d263c69ded77d1dff597b2452..f137faf6677280f75afacad1e806728e9fc935cd 100644 (file)
@@ -23,18 +23,18 @@ public final class StatementSupportBundle implements Immutable,NamespaceBehaviou
     private final ImmutableMap<QName, StatementSupport<?,?,?>> definitions;
     private final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
 
-    public ImmutableMap<QName, StatementSupport<?, ?, ?>> getDefinitions() {
-        return definitions;
-    }
-
     private StatementSupportBundle(StatementSupportBundle parent,
-            ImmutableMap<QName, StatementSupport<?, ?, ?>> statements,
-            ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces) {
+                                   ImmutableMap<QName, StatementSupport<?, ?, ?>> statements,
+                                   ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces) {
         this.parent = parent;
         this.definitions = statements;
         this.namespaceDefinitions = namespaces;
     }
 
+    public ImmutableMap<QName, StatementSupport<?, ?, ?>> getDefinitions() {
+        return definitions;
+    }
+
     public static Builder builder() {
         return new Builder(EMPTY);
     }
@@ -54,9 +54,7 @@ public final class StatementSupportBundle implements Immutable,NamespaceBehaviou
              * Safe cast, previous checkState checks equivalence of key from
              * which type argument are derived
              */
-            @SuppressWarnings("unchecked")
-            NamespaceBehaviour<K, V, N> casted = (NamespaceBehaviour<K, V, N>) potential;
-            return casted;
+            return (NamespaceBehaviour<K, V, N>) potential;
         }
         if (parent != null) {
             return parent.getNamespaceBehaviour(namespace);
index fa2e78bddb21689f1b33376e572be8ceea10b0d0..eefd87f9a98e1533e428656baaef2a3f13134857 100644 (file)
@@ -81,18 +81,20 @@ public final class StmtContextUtils {
     public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
             StmtContext<?, ?, ?> stmtContext, int startIndex, Class<? extends DeclaredStatement<?>>... types) {
 
-        if (startIndex >= types.length)
+        if (startIndex >= types.length) {
             return null;
+        }
 
         Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
                 .declaredSubstatements();
         for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
             if (producesDeclared(subStmtContext,types[startIndex])) {
-                if (startIndex + 1 == types.length)
+                if (startIndex + 1 == types.length) {
                     return subStmtContext;
-                else
+                } else {
                     return findFirstDeclaredSubstatement(subStmtContext,
                             ++startIndex, types);
+                }
             }
         }
         return null;
@@ -110,8 +112,9 @@ public final class StmtContextUtils {
                 if (sublevel > 1) {
                     StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(
                             subStmtContext, declaredType, --sublevel);
-                    if (result != null)
+                    if (result != null) {
                         return result;
+                    }
                 }
             }
         }
@@ -130,8 +133,9 @@ public final class StmtContextUtils {
             } else {
                 StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(
                         subStmtContext, declaredType);
-                if (result != null)
+                if (result != null) {
                     return result;
+                }
 
             }
         }
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModuleMap.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModuleMap.java
new file mode 100644 (file)
index 0000000..e01e5ae
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 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.parser.spi.source;
+
+import org.opendaylight.yangtools.yang.common.QNameModule;
+
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+
+public class PrefixToModuleMap implements PrefixToModule {
+
+    private Map<String, QNameModule> prefixToModuleMap = new HashMap<>();
+
+    public void put(String prefix, QNameModule qNameModule) {
+        prefixToModuleMap.put(prefix, qNameModule);
+    }
+
+    @Nullable
+    @Override
+    public QNameModule get(String prefix) {
+        return prefixToModuleMap.get(prefix);
+    }
+
+    @Nullable
+    @Override
+    public QNameModule getByNamespace(String namespace) {
+        return null;
+    }
+}
index f0767c7f3acd151f88258a2c153b147958c310b4..091360e04c6debc8e3f9807dd7ad3d4e05c137ef 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2015 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.parser.spi.source;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -8,15 +15,16 @@ import javax.annotation.Nullable;
 import java.util.HashMap;
 import java.util.Map;
 
-public class QNameToStatementDefinitionMap implements QNameToStatementDefinition{
+public class QNameToStatementDefinitionMap implements QNameToStatementDefinition {
 
     private Map<QName, StatementDefinition> qNameToStmtDefMap = new HashMap<>();
 
-    public void put(QName qName, StatementDefinition stDef ) {
+    public void put(QName qName, StatementDefinition stDef) {
         qNameToStmtDefMap.put(qName, stDef);
     }
 
-    @Nullable @Override
+    @Nullable
+    @Override
     public StatementDefinition get(@Nonnull QName identifier) {
         return qNameToStmtDefMap.get(identifier);
     }
index cb0dd2c3437cf505d86b9ad120de14603bd7be09..ad6d70a823c9060d454394b2460d8cc43ce4f2b3 100644 (file)
@@ -103,9 +103,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
              * Safe cast, previous checkState checks equivalence of key from
              * which type argument are derived
              */
-            @SuppressWarnings("unchecked")
-            NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) potential;
-            return casted;
+            return (NamespaceBehaviourWithListeners<K, V, N>) potential;
         }
         throw new NamespaceNotAvailableException("Namespace " + type + "is not available in phase " + currentPhase);
     }
@@ -185,7 +183,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
 
     private  void completePhaseActions() throws ReactorException {
         Preconditions.checkState(currentPhase != null);
-        ArrayList<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
+        List<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
         try {
             boolean progressing = true;
             while(progressing) {
index 638952cf3dc44241d0479ede263f6dc16569e693..225ce471106174bf30983c23c8f57e702bc9d684 100644 (file)
@@ -65,7 +65,8 @@ class ModifierImpl implements ModelActionBuilder {
 
     private void tryToResolve() throws InferenceException {
         if(action == null) {
-            return; // Action was not yet defined
+            // Action was not yet defined
+            return;
         }
         if(removeSatisfied()) {
             applyAction();
@@ -77,7 +78,8 @@ class ModifierImpl implements ModelActionBuilder {
         boolean allSatisfied = true;
         while(prereq.hasNext()) {
             if(prereq.next().isDone()) {
-                prereq.remove(); // We are removing current prerequisite from list.
+                // We are removing current prerequisite from list.
+                prereq.remove();
             } else {
                 allSatisfied  = false;
             }
index 2fe7f01138a3bdc72e3f7b136faea0a3bf55d8fe..695251f369a89f78a36f2a961306f368ae4e2733 100644 (file)
@@ -99,9 +99,7 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
     public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
             throws SourceException {
 
-        StatementContextBase<A, D, E> copy = new RootStatementContext<A, D, E>(
-                this, newQNameModule);
-        return copy;
+        return new RootStatementContext<>(this, newQNameModule);
     }
 
     @Override
index d6ddc551c228760036f7d965113169993ce672f6..847f8e988e43040f221fbcd064af34cefd225d37 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 import com.google.common.base.Preconditions;
@@ -23,6 +25,8 @@ import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
@@ -32,12 +36,15 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModuleMap;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinitionMap;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase.ContextBuilder;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 
 public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviour.Registry, Mutable {
 
@@ -57,6 +64,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     private ModelProcessingPhase inProgressPhase;
     private ModelProcessingPhase finishedPhase;
     private QNameToStatementDefinitionMap qNameToStmtDefMap = new QNameToStatementDefinitionMap();
+    private PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap();
 
 
     SourceSpecificContext(BuildGlobalContext currentContext,StatementStreamSource source) {
@@ -70,7 +78,15 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
 
     ContextBuilder<?, ?, ?> createDeclaredChild(StatementContextBase<?, ?, ?> current, QName name, StatementSourceReference ref) {
         StatementDefinitionContext<?,?,?> def = getDefinition(name);
-        Preconditions.checkArgument(def != null, "Statement %s does not have type mapping defined.",name);
+
+        //extensions
+        if (def == null) {
+            if (Utils.isValidStatementDefinition(prefixToModuleMap, qNameToStmtDefMap, name)) {
+                def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition(qNameToStmtDefMap.get(Utils.trimPrefix(name))));
+            }
+        }
+
+        Preconditions.checkArgument(def != null, "Statement %s does not have type mapping defined.", name);
         if(current == null) {
             return createDeclaredRoot(def,ref);
         }
@@ -216,13 +232,13 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
 
     void loadStatements() throws SourceException {
         switch (inProgressPhase) {
-        case SOURCE_LINKAGE:
+            case SOURCE_LINKAGE:
             source.writeLinkage(new StatementContextWriter(this, inProgressPhase),stmtDef());
             break;
-        case STATEMENT_DEFINITION:
+            case STATEMENT_DEFINITION:
             source.writeLinkageAndStatementDefinitions(new StatementContextWriter(this, inProgressPhase), stmtDef(), prefixes());
             break;
-        case FULL_DECLARATION:
+            case FULL_DECLARATION:
             source.writeFull(new StatementContextWriter(this, inProgressPhase), stmtDef(), prefixes());
             break;
         default:
@@ -231,16 +247,30 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     }
 
     private PrefixToModule prefixes() {
-        // TODO Auto-generated method stub
-        return null;
+        Map<String, QNameModule> prefixes = (Map<String, QNameModule>) currentContext.getAllFromNamespace(PrefixToModule.class);
+        for (Map.Entry<String, QNameModule> prefix : prefixes.entrySet()) {
+            prefixToModuleMap.put(prefix.getKey(), prefix.getValue());
+        }
+        return prefixToModuleMap;
     }
 
     private QNameToStatementDefinition stmtDef() {
+        //regular YANG statements added
         ImmutableMap<QName, StatementSupport<?, ?, ?>> definitions = currentContext.getSupportsForPhase(
                 inProgressPhase).getDefinitions();
         for (Map.Entry<QName, StatementSupport<?,?,?>> entry : definitions.entrySet()) {
             qNameToStmtDefMap.put(entry.getKey(), entry.getValue());
         }
+
+        //extensions added
+        if (inProgressPhase.equals(ModelProcessingPhase.FULL_DECLARATION)) {
+            Map<QName, SubstatementContext<?, ?, ?>> extensions = (Map<QName, SubstatementContext<?, ?, ?>>) currentContext.getAllFromNamespace(ExtensionNamespace.class);
+            if (extensions != null) {
+                for (Map.Entry<QName, SubstatementContext<?, ?, ?>> extension : extensions.entrySet()) {
+                    qNameToStmtDefMap.put(new QName(YangConstants.RFC6020_YIN_NAMESPACE, extension.getKey().getLocalName()), (StatementDefinition) extension.getValue().definition().getFactory());
+                }
+            }
+        }
         return qNameToStmtDefMap;
     }
 }
index 94f29a3cca5af98f830cc9697f2af775d6a662cd..43692ff0dae32f1bee0b7469e0c2ae761d854cae 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Collections;
 import java.util.EventListener;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.Map;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
@@ -101,7 +102,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private final StatementIdentifier identifier;
     private final StatementSourceReference statementDeclSource;
 
-    private LinkedHashMap<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
+    private Map<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
 
     private Collection<StatementContextBase<?, ?, ?>> declared = new ArrayList<>();
     private Collection<StatementContextBase<?, ?, ?>> effective = new ArrayList<>();
index 2e78e75ed28b8b5188df2364c3e8c392ec918496..7fd1442691ffb4ee9b412c664381372a495bc5d4 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -36,7 +35,7 @@ public class StatementDefinitionContext<A,D extends DeclaredStatement<A>,E exten
     }
 
 
-    public void checkNamespaceAllowed(Class<? extends IdentifierNamespace<?,?>> namespace) throws NamespaceNotAvailableException {
+    public void checkNamespaceAllowed(Class<? extends IdentifierNamespace<?,?>> namespace) {
         // Noop
     }
 
index 29cac6ead5da3f4ab38db09a453b014ec8c5d547..808518d9d84b4b58c5c858c0c4aaaea36364f86c 100644 (file)
@@ -107,8 +107,7 @@ class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveS
 
     @Override
     public StatementContextBase<A, D, E>  createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
-        StatementContextBase<A,D,E> copy = new SubstatementContext<A,D,E>(this,newQNameModule, newParent);
-        return copy;
+        return new SubstatementContext<>(this,newQNameModule, newParent);
     }
 
     @Override
index 3b9c18c0333b2a441a8b2e1cb21acf46e0888a01..373ec1f40e78b894f4b0e12620c864e6c57c94d1 100644 (file)
@@ -9,6 +9,9 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -18,21 +21,23 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
 public final class AugmentUtils {
 
-    private AugmentUtils() {
-    }
-
     private static final String REGEX_PATH_REL1 = "\\.\\.?\\s*/(.+)";
     private static final String REGEX_PATH_REL2 = "//.*";
 
+    private AugmentUtils() {
+    }
+
     public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx, String path) {
 
         if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) {
@@ -44,7 +49,7 @@ public final class AugmentUtils {
     }
 
     public static void copyFromSourceToTarget(StatementContextBase<?, ?, ?> sourceCtx,
-            StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
+                                              StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
 
         QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceCtx);
         copyDeclaredStmts(sourceCtx, targetCtx, newQNameModule);
@@ -53,7 +58,7 @@ public final class AugmentUtils {
     }
 
     public static void copyDeclaredStmts(StatementContextBase<?, ?, ?> sourceCtx,
-            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
+                                         StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceCtx.declaredSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
             if (needToCopyByAugment(originalStmtCtx)) {
@@ -66,7 +71,7 @@ public final class AugmentUtils {
     }
 
     public static void copyEffectiveStmts(StatementContextBase<?, ?, ?> sourceCtx,
-            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
+                                          StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceCtx.effectiveSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
             if (needToCopyByAugment(originalStmtCtx)) {
@@ -79,7 +84,7 @@ public final class AugmentUtils {
     }
 
     public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
-            StatementContextBase<?, ?, ?> sourceCtx) {
+                                                StatementContextBase<?, ?, ?> sourceCtx) {
         Object targetStmtArgument = targetCtx.getStatementArgument();
 
         final StatementContextBase<?, ?, ?> root = sourceCtx.getRoot();
@@ -106,39 +111,65 @@ public final class AugmentUtils {
         noCopyDefSet.add(Rfc6020Mapping.USES);
 
         StatementDefinition def = stmtContext.getPublicDefinition();
-        return (!noCopyDefSet.contains(def));
+        return !noCopyDefSet.contains(def);
     }
 
     public static boolean isReusedByAugment(StmtContext<?, ?, ?> stmtContext) {
 
-        HashSet<StatementDefinition> reusedDefSet = new HashSet<>();
+        Set<StatementDefinition> reusedDefSet = new HashSet<>();
         reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
 
         StatementDefinition def = stmtContext.getPublicDefinition();
-        if (reusedDefSet.contains(def))
-            return true;
-        else
-            return false;
+
+        return reusedDefSet.contains(def);
     }
 
     public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
             final Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
 
-        final SchemaNodeIdentifier augmentTargetPath = augmentNode.getStatementArgument();
+        final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument();
+
+        List<StatementContextBase<?, ?, ?>> rootStatementCtxList = new LinkedList<>();
+
+        if (augmentTargetNode.isAbsolute()) {
+
+            QNameModule module;
+            if (augmentTargetNode != null) {
+                module = augmentTargetNode.getPathFromRoot().iterator().next().getModule();
+            } else {
+                throw new IllegalArgumentException(
+                        "Augment argument null, something bad happened in some of previous parsing phases");
+            }
+
+            StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(
+                    NamespaceToModule.class, module);
+            rootStatementCtxList.add(rootStatementCtx);
+
+            final Map<?, ?> subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class);
+            if (subModules != null) {
+                rootStatementCtxList.addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules.values());
+            }
 
-        QNameModule module;
-        if (augmentTargetPath != null) {
-            module = augmentTargetPath.getPathFromRoot().iterator().next().getModule();
         } else {
-            throw new IllegalArgumentException(
-                    "Augment argument null, something bad happened in some of previous parsing phases");
+            StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode.getParentContext();
+            if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) {
+                rootStatementCtxList.add(parent.getParentContext());
+            } else {
+                //error
+            }
         }
 
-        StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(
-                NamespaceToModule.class, module);
+        List<QName> augmentTargetPath = new LinkedList<>();
+
+        augmentTargetPath.addAll((Collection<? extends QName>) augmentTargetNode.getPathFromRoot());
+
+        StatementContextBase<?, ?, ?> augmentTargetCtx = null;
+        for (final StatementContextBase<?, ?, ?> rootStatementCtx : rootStatementCtxList) {
+            augmentTargetCtx = Utils.findCtxOfNodeInRoot(rootStatementCtx,
+                    augmentTargetPath);
+            if (augmentTargetCtx != null) break;
+        }
 
-        final StatementContextBase<?, ?, ?> augmentTargetCtx = Utils.findCtxOfNodeInRoot(rootStatementCtx,
-                augmentTargetPath);
 
         if (augmentTargetCtx == null) {
 
index 316013160333f79d9b925299ca0ed70ec0513cf4..2aca8a1c806ef0e68bfc7ba4232554fef6bd5cb1 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseEffectiveStatementImpl;
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PresenceEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -24,9 +26,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseEffectiveStatementImpl;
 
 public class CaseStatementImpl extends AbstractDeclaredStatement<QName> implements CaseStatement {
 
index 2e9c54ffdd57abdf1be777a57ddc3719311f86c4..e3ff0d39fb7a3092fc9b6e062ac8c95252eb904c 100644 (file)
@@ -8,18 +8,20 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ExtensionEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public class ExtensionStatementImpl extends AbstractDeclaredStatement<QName> implements ExtensionStatement {
 
@@ -35,7 +37,7 @@ public class ExtensionStatementImpl extends AbstractDeclaredStatement<QName> imp
 
         @Override
         public QName parseArgumentValue(StmtContext<?,?,?> ctx, String value) {
-            return Utils.qNameFromArgument(ctx,value);
+            return Utils.qNameFromArgument(ctx, value);
         }
 
         @Override
@@ -48,6 +50,10 @@ public class ExtensionStatementImpl extends AbstractDeclaredStatement<QName> imp
            return new ExtensionEffectiveStatementImpl(ctx);
         }
 
+        @Override
+        public void onStatementDefinitionDeclared(final StmtContext.Mutable<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> stmt) throws InferenceException, SourceException {
+            stmt.addContext(ExtensionNamespace.class, stmt.getStatementArgument(), stmt);
+        }
     }
 
     @Override
index 4f2a7ce735e2f3b6db6649d5f23005a0a09acf82..30d6ef0769c46e933d3bf28edf829299c98469eb 100644 (file)
@@ -7,25 +7,24 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.GroupingEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import java.util.Collection;
+
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.GroupingEffectiveStatementImpl;
 
 public class GroupingStatementImpl extends AbstractDeclaredStatement<QName>
         implements GroupingStatement {
index f5a996dbe099fb2156004a0108534824ac31b4a8..c1194deec5e3749eeebd0627a2a5f811252e681b 100644 (file)
@@ -21,8 +21,8 @@ import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
@@ -36,27 +36,22 @@ public final class GroupingUtils {
      * @param targetCtx
      * @throws SourceException
      */
-    public static void copyFromSourceToTarget(
-            StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+    public static void copyFromSourceToTarget(StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
             StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
 
-        QNameModule newQNameModule = getNewQNameModule(targetCtx,
-                sourceGrpStmtCtx);
+        QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceGrpStmtCtx);
         copyDeclaredStmts(sourceGrpStmtCtx, targetCtx, newQNameModule);
         copyEffectiveStmts(sourceGrpStmtCtx, targetCtx, newQNameModule);
 
     }
 
-    public static void copyDeclaredStmts(
-            StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
-            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
-            throws SourceException {
+    public static void copyDeclaredStmts(StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceGrpStmtCtx
                 .declaredSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
             if (needToCopyByUses(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx
-                        .createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByUses(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -64,16 +59,13 @@ public final class GroupingUtils {
         }
     }
 
-    public static void copyEffectiveStmts(
-            StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
-            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
-            throws SourceException {
+    public static void copyEffectiveStmts(StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceGrpStmtCtx
                 .effectiveSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
             if (needToCopyByUses(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx
-                        .createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByUses(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -81,14 +73,12 @@ public final class GroupingUtils {
         }
     }
 
-    public static QNameModule getNewQNameModule(
-            StatementContextBase<?, ?, ?> targetCtx,
+    public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
             StmtContext<?, ?, ?> stmtContext) {
         if (needToCreateNewQName(stmtContext.getPublicDefinition())) {
             Object targetStmtArgument = targetCtx.getStatementArgument();
             Object sourceStmtArgument = stmtContext.getStatementArgument();
-            if (targetStmtArgument instanceof QName
-                    && sourceStmtArgument instanceof QName) {
+            if (targetStmtArgument instanceof QName && sourceStmtArgument instanceof QName) {
                 QName targetQName = (QName) targetStmtArgument;
                 QNameModule targetQNameModule = targetQName.getModule();
 
@@ -97,8 +87,7 @@ public final class GroupingUtils {
 
                 if (targetQNameModule.equals(sourceQNameModule)) {
                     return null;
-                }
-                else {
+                } else {
                     return targetQNameModule;
                 }
             } else {
@@ -109,8 +98,7 @@ public final class GroupingUtils {
         }
     }
 
-    public static boolean needToCreateNewQName(
-            StatementDefinition publicDefinition) {
+    public static boolean needToCreateNewQName(StatementDefinition publicDefinition) {
         return true;
     }
 
@@ -120,7 +108,7 @@ public final class GroupingUtils {
         noCopyDefSet.add(Rfc6020Mapping.USES);
 
         StatementDefinition def = stmtContext.getPublicDefinition();
-        return (!noCopyDefSet.contains(def));
+        return !noCopyDefSet.contains(def);
     }
 
     public static boolean isReusedByUses(StmtContext<?, ?, ?> stmtContext) {
@@ -129,29 +117,23 @@ public final class GroupingUtils {
         reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
 
         StatementDefinition def = stmtContext.getPublicDefinition();
-        return (reusedDefSet.contains(def));
+        return reusedDefSet.contains(def);
     }
 
     public static void resolveUsesNode(
             Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
-            StatementContextBase<?, ?, ?> targetNodeStmtCtx)
-            throws SourceException {
+            StatementContextBase<?, ?, ?> targetNodeStmtCtx) throws SourceException {
 
-        Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = usesNode
-                .declaredSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = usesNode.declaredSubstatements();
         for (StatementContextBase<?, ?, ?> subStmtCtx : declaredSubstatements) {
-            if (StmtContextUtils.producesDeclared(subStmtCtx,
-                    WhenStatement.class)) {
-                StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(
-                        null, targetNodeStmtCtx);
+            if (StmtContextUtils.producesDeclared(subStmtCtx, WhenStatement.class)) {
+                StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(null, targetNodeStmtCtx);
                 targetNodeStmtCtx.addEffectiveSubstatement(copy);
             }
-            if (StmtContextUtils.producesDeclared(subStmtCtx,
-                    RefineStatement.class)) {
+            if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)) {
                 // :TODO resolve and perform refine statement
             }
-            if (StmtContextUtils.producesDeclared(subStmtCtx,
-                    AugmentStatement.class)) {
+            if (StmtContextUtils.producesDeclared(subStmtCtx, AugmentStatement.class)) {
                 // :TODO find target node and perform augmentation
             }
             // :TODO resolve other uses substatements
index e2c6b531db1e8eae0f93b09d5327f92f82466c0d..963737a7decdb5f6320b5b228d9b9c4d4e27b251 100644 (file)
@@ -9,32 +9,32 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
-import com.google.common.base.Optional;
 import java.net.URI;
 import java.util.Date;
+
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl;
+
+import com.google.common.base.Optional;
 
 public class ModuleStatementSupport extends
         AbstractStatementSupport<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> {
index 02e94621919299b71a9cbfec5d9330c854fa086c..16dc0071c15b21bfeef6fb12cbd999e3268cab55 100644 (file)
@@ -26,7 +26,7 @@ public class PrefixStatementImpl extends AbstractDeclaredStatement<String> imple
 
         @Override
         public String parseArgumentValue(StmtContext<?, ?,?> ctx, String value) {
-            return (value);
+            return value;
         }
 
         @Override
index 7349082ec503e8610f5e2bb226838306bba575c2..ff306a55e47c750e957a674a03a80e17a7057f54 100644 (file)
@@ -7,29 +7,29 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-
-import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import com.google.common.base.Optional;
 import java.net.URI;
 import java.util.Date;
+
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import com.google.common.base.Optional;
 
 public class SubmoduleStatementImpl extends
         AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java
new file mode 100644 (file)
index 0000000..1dbb030
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 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.parser.stmt.rfc6020;
+
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nullable;
+
+public class UnknownStatementImpl extends AbstractDeclaredStatement<String> implements UnknownStatement<String> {
+
+    protected UnknownStatementImpl(StmtContext<String, ?, ?> context) {
+        super(context);
+    }
+
+    public static class Definition extends AbstractStatementSupport<String, UnknownStatement<String>, EffectiveStatement<String, UnknownStatement<String>>> {
+
+
+        public Definition(StatementDefinition publicDefinition) {
+            super(publicDefinition);
+        }
+
+        @Override
+        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+            return value;
+        }
+
+        @Override
+        public UnknownStatement createDeclared(StmtContext<String, UnknownStatement<String>, ?> ctx) {
+            return new UnknownStatementImpl(ctx);
+        }
+
+        @Override
+        public EffectiveStatement<String, UnknownStatement<String>> createEffective(StmtContext<String, UnknownStatement<String>, EffectiveStatement<String, UnknownStatement<String>>> ctx) {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    @Nullable
+    @Override
+    public String getArgument() {
+        return rawArgument();
+    }
+}
index 326e92a8073dc7215ff8e58fb5a192a95765ac5c..102ad007ff87b58aed7776614bef055331327802 100644 (file)
@@ -10,15 +10,10 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.FULL_DECLARATION;
 
 import java.util.Collection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
@@ -38,6 +33,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implements UsesStatement {
@@ -91,7 +88,8 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
                 @Override
                 public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
                     if (failed.contains(sourceGroupingPre)) {
-                        throw new InferenceException("Grouping " + groupingName + " was not resovled.", usesNode.getStatementSourceReference());
+                        throw new InferenceException("Grouping " + groupingName + " was not resolved.", usesNode
+                                .getStatementSourceReference());
                     }
                     throw new InferenceException("Unknown error occurred.", usesNode.getStatementSourceReference());
                 }
@@ -150,35 +148,4 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
     public Collection<? extends RefineStatement> getRefines() {
         return allDeclared(RefineStatement.class);
     }
-
-    @Override
-    public QName argument() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public String rawArgument() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public StatementDefinition statementDefinition() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public StatementSource getStatementSource() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
 }
index 48131623a15d624ca8715877ee1b1f244ac5eafc..3a62cfaab6272d4f826f35c20797cc36ba465a46 100644 (file)
@@ -17,16 +17,19 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-
 import javax.annotation.Nullable;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
-
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Splitter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.antlr.v4.runtime.tree.TerminalNode;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
@@ -41,25 +44,21 @@ import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdenti
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Splitter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 public final class Utils {
 
-    private Utils() {
-    }
-
     private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
     private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
     private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
 
     private static final char SEPARATOR_NODENAME = '/';
 
-    private static final String REGEX_PATH_ABS = "/[^/].+";
+    private static final String REGEX_PATH_ABS = "/[^/].*";
+
+    private Utils() {
+    }
 
     public static List<String> splitPathToNodeNames(String path) {
 
@@ -85,6 +84,38 @@ public final class Utils {
         return path.matches(REGEX_PATH_ABS);
     }
 
+    public static QName trimPrefix(QName identifier) {
+        String prefixedLocalName = identifier.getLocalName();
+        String[] namesParts = prefixedLocalName.split(":");
+
+        if (namesParts.length == 2) {
+            String localName = namesParts[1];
+            return QName.create(identifier.getModule(), localName);
+        }
+
+        return identifier;
+    }
+
+    public static boolean isValidStatementDefinition(PrefixToModule prefixes, QNameToStatementDefinition stmtDef,
+            QName identifier) {
+        if (stmtDef.get(identifier) != null) {
+            return true;
+        } else {
+            String prefixedLocalName = identifier.getLocalName();
+            String[] namesParts = prefixedLocalName.split(":");
+
+            if (namesParts.length == 2) {
+                String prefix = namesParts[0];
+                String localName = namesParts[1];
+                if (prefixes != null && prefixes.get(prefix) != null
+                        && stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
 
         validateXPath(path);
@@ -107,7 +138,7 @@ public final class Utils {
     public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
         StringBuilder sb = new StringBuilder();
         List<TerminalNode> strings = context.STRING();
-        if (strings.size() == 0) {
+        if (strings.isEmpty()) {
             strings = Arrays.asList(context.IDENTIFIER());
         }
         for (TerminalNode stringNode : strings) {
@@ -129,7 +160,7 @@ public final class Utils {
 
     public static QName qNameFromArgument(StmtContext<?, ?, ?> ctx, String value) {
 
-        String prefix = null;
+        String prefix;
         QNameModule qNameModule = null;
         try {
             qNameModule = QNameModule.create(new URI(""), new Date(0));
@@ -175,17 +206,18 @@ public final class Utils {
     }
 
     @Nullable
-    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
-            final SchemaNodeIdentifier node) {
+    private static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
+            StatementContextBase<?, ?, ?> rootStmtCtx, final Iterable<QName> path, boolean searchInEffective) {
 
         StatementContextBase<?, ?, ?> parent = rootStmtCtx;
-        final Iterator<QName> pathIter = node.getPathFromRoot().iterator();
 
+        Iterator<QName> pathIter = path.iterator();
         QName targetNode = pathIter.next();
 
         while (pathIter.hasNext()) {
 
-            for (StatementContextBase<?, ?, ?> child : parent.declaredSubstatements()) {
+            for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
+                    .declaredSubstatements()) {
 
                 if (targetNode.equals(child.getStatementArgument())) {
                     parent = child;
@@ -201,7 +233,8 @@ public final class Utils {
 
         StatementContextBase<?, ?, ?> targetCtx = null;
 
-        for (StatementContextBase<?, ?, ?> child : parent.declaredSubstatements()) {
+        for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
+                .declaredSubstatements()) {
 
             if (targetNode.equals(child.getStatementArgument())) {
                 targetCtx = child;
@@ -211,6 +244,37 @@ public final class Utils {
         return targetCtx;
     }
 
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
+            final SchemaNodeIdentifier node) {
+
+        System.out.println(node.getPathFromRoot());
+
+        StatementContextBase<?, ?, ?> targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(),
+                false);
+
+        if (targetCtx == null) {
+
+            targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(), true);
+        }
+
+        return targetCtx;
+    }
+
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
+            final Iterable<QName> path) {
+
+        StatementContextBase<?, ?, ?> targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, path, false);
+
+        if (targetCtx == null) {
+
+            targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, path, true);
+        }
+
+        return targetCtx;
+    }
+
     public static SchemaPath getSchemaPath(StmtContext<?, ?, ?> ctx) {
 
         Iterator<Object> argumentsIterator = ctx.getArgumentsFromRoot().iterator();
index 34fc0fccfd95ad8cd8a679dd3c21ac935280f717..87bfe2b3f4f9bb5cbf5cd261cebcfcb7876057db 100644 (file)
@@ -11,6 +11,7 @@ import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour
 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
 
+import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
 
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
@@ -26,6 +27,7 @@ import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
+import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 
 public final class YangInferencePipeline {
@@ -56,17 +58,15 @@ public final class YangInferencePipeline {
             .addSupport(sourceLocal(IncludedModuleContext.class))
             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
-            //.addSupport(global(ImpPrefixToModuleIdentifier.class))
-                    .build();
+            .addSupport(sourceLocal(QNameToStatementDefinition.class))
+            .build();
 
     private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.
             derivedFrom(LINKAGE_BUNDLE)
             .addSupport(new YinElementStatementImpl.Definition())
             .addSupport(new ArgumentStatementImpl.Definition())
             .addSupport(new ExtensionStatementImpl.Definition())
-            //TODO: implement extension support in SourceSpecificContext
-            // in order to prepare statements for full declaration phase,
-            // when those ones are read.
+            .addSupport(global(ExtensionNamespace.class))
             .build();
 
     private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.
index 210a837f81576413d58fc05b9bdd7ff3b3762f6c..2b6c97f8a8c8ed8b40e36ea40b9f464a3c201b30 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2015 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.parser.stmt.rfc6020;
 
 import org.antlr.v4.runtime.ANTLRInputStream;
index f0b521e21bc00e3df10866f5608572b60e821fbc..9bd91b6619ad892749081772ef61149a3f8d4b4f 100644 (file)
@@ -13,9 +13,12 @@ import com.google.common.collect.ImmutableMap;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+
+import java.util.Map;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -40,38 +43,38 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends
 
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        HashMap<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
-        HashSet<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
-        HashSet<UsesNode> uses = new HashSet<UsesNode>();
-        HashSet<TypeDefinition<?>> typeDefinitions = new HashSet<TypeDefinition<?>>();
-        HashSet<DataSchemaNode> publicChildNodes = new HashSet<DataSchemaNode>();
+        Map<QName, DataSchemaNode> mutableChildNodes = new HashMap<QName, DataSchemaNode>();
+        Set<GroupingDefinition> mutableGroupings = new HashSet<GroupingDefinition>();
+        Set<UsesNode> mutableUses = new HashSet<UsesNode>();
+        Set<TypeDefinition<?>> mutableTypeDefinitions = new HashSet<TypeDefinition<?>>();
+        Set<DataSchemaNode> mutablePublicChildNodes = new HashSet<DataSchemaNode>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof DataSchemaNode) {
                 DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
 
-                childNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
-                publicChildNodes.add(dataSchemaNode);
+                mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
+                mutablePublicChildNodes.add(dataSchemaNode);
             }
             if (effectiveStatement instanceof UsesNode) {
                 UsesNode usesNode = (UsesNode) effectiveStatement;
-                uses.add(usesNode);
+                mutableUses.add(usesNode);
             }
             if (effectiveStatement instanceof TypeDefinition) {
                 TypeDefinition<?> typeDef = (TypeDefinition<?>) effectiveStatement;
-                typeDefinitions.add(typeDef);
+                mutableTypeDefinitions.add(typeDef);
             }
             if (effectiveStatement instanceof GroupingDefinition) {
                 GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
-                groupings.add(grp);
+                mutableGroupings.add(grp);
             }
         }
 
-        this.childNodes = ImmutableMap.copyOf(childNodes);
-        this.groupings = ImmutableSet.copyOf(groupings);
-        this.publicChildNodes = ImmutableSet.copyOf(publicChildNodes);
-        this.typeDefinitions = ImmutableSet.copyOf(typeDefinitions);
-        this.uses = ImmutableSet.copyOf(uses);
+        this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
+        this.groupings = ImmutableSet.copyOf(mutableGroupings);
+        this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
+        this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
+        this.uses = ImmutableSet.copyOf(mutableUses);
     }
 
     @Override
index 23ecee547575ec4853e1d7ee725c5f45e2e73cb4..763b14216238f55b21f27703df9ebae18e9c2cad 100644 (file)
@@ -26,14 +26,16 @@ public abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredState
         DescriptionEffectiveStatementImpl descStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
         if (descStmt != null) {
             description = descStmt.argument();
-        } else
+        } else {
             description = "";
+        }
 
         ReferenceEffectiveStatementImpl refStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
         if (refStmt != null) {
             reference = refStmt.argument();
-        } else
+        } else {
             reference = "";
+        }
 
         // :TODO
         status = null;
index e84af21131271e4eab3ed1a32204323320f29748..a4a94111a430e92c5985a70f9e54a325e432a0ec 100644 (file)
@@ -19,6 +19,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableSet;
 import java.util.Set;
 import java.util.TreeSet;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -40,9 +41,9 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
 public abstract class AbstractEffectiveSchemaContext implements SchemaContext {
 
-    protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = new Supplier<TreeSet<Module>>() {
+    protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = new Supplier<NavigableSet<Module>>() {
         @Override
-        public TreeSet<Module> get() {
+        public NavigableSet<Module> get() {
             return new TreeSet<>(REVISION_COMPARATOR);
         }
     };
index ff417e0e1d8e6c1c47b7721a0cc524c148a66f52..85a5e63d3e4c30b37cd02f436689336efbab79f8 100644 (file)
@@ -49,16 +49,16 @@ public class AnyXmlEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     @Override
index 0d3f3741f768db64de227e2e8b2dc5b924086a69..39e51d1f9793ed834da551205d402d3b6d0bd66c 100644 (file)
@@ -60,16 +60,16 @@ public class AugmentEffectiveStatementImpl
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     public void setCopyOf(final AugmentationSchema build) {
index e406e610973aa71086d8a89897fcbe111db02a16..e748a3e9ee4288d9e72159592357dd43e860a979 100644 (file)
@@ -55,22 +55,22 @@ public class CaseEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index 00262b5070e97c8cae5224eb957aa2d76aff6ed7..d74600e37d7b383f565af34968bc225e2f29182e 100644 (file)
@@ -58,28 +58,28 @@ public class ChoiceEffectiveStatementImpl extends AbstractEffectiveDocumentedNod
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
-        HashSet<ChoiceCaseNode> cases = new HashSet<ChoiceCaseNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+        Set<ChoiceCaseNode> casesInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
             if (effectiveStatement instanceof ChoiceCaseNode) {
                 ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) effectiveStatement;
-                cases.add(choiceCaseNode);
+                casesInit.add(choiceCaseNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
-        this.cases = ImmutableSet.copyOf(cases);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+        this.cases = ImmutableSet.copyOf(casesInit);
     }
 
     @Override
index d7a70c4a66d020d82a79d0c09c33221200b010d6..b9501f7c1e7d77e63ef84d9cc1bc4d626d2ea33c 100644 (file)
@@ -60,22 +60,22 @@ public class ContainerEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index cc837626ed4a1159844ebf7de4eaa7391ff06b51..4cedda12fa6c55db907185ad5b05d864776a86d3 100644 (file)
@@ -42,21 +42,21 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
         this.rootEffectiveStatements = ImmutableList
                 .copyOf(rootEffectiveStatements);
 
-        HashSet<Module> modules = new HashSet<Module>();
+        Set<Module> modulesInit = new HashSet<>();
         for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
             if (rootEffectiveStatement instanceof Module) {
                 Module module = (Module) rootEffectiveStatement;
-                modules.add(module);
+                modulesInit.add(module);
             }
         }
-        this.modules = ImmutableSet.copyOf(modules);
+        this.modules = ImmutableSet.copyOf(modulesInit);
 
         final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
                 new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
         final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
                 new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
 
-        for (Module m : modules) {
+        for (Module m : modulesInit) {
             nameMap.put(m.getName(), m);
             nsMap.put(m.getNamespace(), m);
         }
index 804be7bd029e5078ad33799a20a0793911852900..fd269a1f163d67f89a47795369571e65b4231bd0 100644 (file)
@@ -51,11 +51,11 @@ abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
         Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx
                 .effectiveSubstatements();
 
-        Collection<StatementContextBase<?, ?, ?>> substatements = new LinkedList<StatementContextBase<?, ?, ?>>();
-        substatements.addAll(declaredSubstatements);
-        substatements.addAll(effectiveSubstatements);
+        Collection<StatementContextBase<?, ?, ?>> substatementsInit = new LinkedList<>();
+        substatementsInit.addAll(declaredSubstatements);
+        substatementsInit.addAll(effectiveSubstatements);
 
-        this.substatements = FluentIterable.from(substatements)
+        this.substatements = FluentIterable.from(substatementsInit)
                 .transform(StmtContextUtils.buildEffective()).toList();
     }
 
@@ -127,7 +127,7 @@ abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
             result = Collection.class.cast(Collections2.filter(substatements,
                     Predicates.instanceOf(type)));
         } catch (NoSuchElementException e) {
-            result = Collections.EMPTY_LIST;
+            result = Collections.emptyList();
         }
         return result;
     }
@@ -152,7 +152,7 @@ abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
             result = Collection.class.cast(Collections2.filter(substatements,
                     Predicates.instanceOf(type)));
         } catch (NoSuchElementException e) {
-            result = Collections.EMPTY_LIST;
+            result = Collections.emptyList();
         }
         return result;
     }
index cdea92063311b54a3887f85ff1f3598923c6e242..f9f1d8066557af3a21c814b67d07819e0b93f688 100644 (file)
@@ -54,24 +54,25 @@ public class ExtensionEffectiveStatementImpl extends
 
         if (yinElement != null) {
             this.yin = yinElement.argument();
-        } else
-            yin = false;
+        } else {
+            this.yin = false;
+        }
 
     }
 
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     @Override
index 38c982ff61cdb7034a5f937fb78f5a623ba8c0bc..8ee820a7ba2eafa961d54f59b9fc9997fad14bc0 100644 (file)
@@ -49,16 +49,16 @@ public class IdentityEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     @Override
index 54e2f10b247a8c95fc7c76db355c98358d692015..e0ded9ec84b9068079599de01bac77927d4aec3b 100644 (file)
@@ -59,22 +59,22 @@ public class InputEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index 45ecda59e1a1b81932f556c631f359fe7bcc3c29..3d59091cc528622e678dafe9b867c64fcd6fd6cc 100644 (file)
@@ -55,16 +55,16 @@ public class LeafEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     @Override
index 768a99e084d42920f9e11d598fee936fea499b30..77487441e4167aa4ddc4c638922362d7f6c3f529 100644 (file)
@@ -51,16 +51,16 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
     }
 
     @Override
index 30ba7d425bfefd941e7b0eacc05ed9b536446be1..f9629a114cff9d68e18df5d5f6b83b541dad12ee 100644 (file)
@@ -54,38 +54,38 @@ public class ListEffectiveStatementImpl extends
      *
      */
     private void initKeyDefinition() {
-        List<QName> keyDefinition = new LinkedList<QName>();
+        List<QName> keyDefinitionInit = new LinkedList<QName>();
         KeyEffectiveStatementImpl key = firstEffective(KeyEffectiveStatementImpl.class);
 
         if (key != null) {
             Collection<SchemaNodeIdentifier> keyParts = key.argument();
             for (SchemaNodeIdentifier keyPart : keyParts) {
-                keyDefinition.add(keyPart.getLastComponent());
+                keyDefinitionInit.add(keyPart.getLastComponent());
             }
         }
 
-        this.keyDefinition = ImmutableList.copyOf(keyDefinition);
+        this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit);
     }
 
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<UnknownSchemaNode>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<AugmentationSchema>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index 1e6d51cf8b27912fdf920afea11c4f1b00c1b696..390769b3561df5251e74cbe9771b80b1618fd64e 100644 (file)
@@ -73,22 +73,22 @@ public class ModuleEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
 
         // :TODO other substatement collections ...
     }
index 4afe4f4dcf554b800fc0095fd66695cb84d181ef..b53772ae92ae421fe1297951e6f15f72ba8cad4c 100644 (file)
@@ -46,22 +46,22 @@ public class NotificationEffectiveStatementImpl
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index e35efd9948d1ac9740eb90285df46ac458909acc..c6d21e86a7bc6f5a796beedfa687d6b2bc829aaa 100644 (file)
@@ -59,22 +59,22 @@ public class OutputEffectiveStatementImpl extends
     private void initSubstatementCollections() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentations.add(augmentationSchema);
+                augmentationsInit.add(augmentationSchema);
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.augmentations = ImmutableSet.copyOf(augmentations);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
     }
 
     @Override
index a0d1ad12293e1e51f739fff4e227abfaea8fc64e..1fcecde23e0ab67808ff54699d8608183a6a82c1 100644 (file)
@@ -49,22 +49,22 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<Q
     private void initSubstatements() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
-        LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
-        HashSet<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
-        HashSet<TypeDefinition<?>> typeDefinitions = new HashSet<TypeDefinition<?>>();
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<GroupingDefinition> groupingsInit = new HashSet<>();
+        Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodes.add(unknownNode);
+                unknownNodesInit.add(unknownNode);
             }
             if (effectiveStatement instanceof GroupingDefinition) {
                 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
-                groupings.add(groupingDefinition);
+                groupingsInit.add(groupingDefinition);
             }
             if (effectiveStatement instanceof TypeDefinition) {
                 TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
-                typeDefinitions.add(typeDefinition);
+                typeDefinitionsInit.add(typeDefinition);
             }
             if (this.input == null && effectiveStatement instanceof InputEffectiveStatementImpl) {
                 this.input = (InputEffectiveStatementImpl) effectiveStatement;
@@ -74,9 +74,9 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<Q
             }
         }
 
-        this.unknownNodes = ImmutableList.copyOf(unknownNodes);
-        this.groupings = ImmutableSet.copyOf(groupings);
-        this.typeDefinitions = ImmutableSet.copyOf(typeDefinitions);
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.groupings = ImmutableSet.copyOf(groupingsInit);
+        this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
     }
 
     @Override
index 105e2978910d18a52b1cb11d62d05ec4242c37b4..7d3ba2aee42f7ebc65deb6c2f4360b1670c7c252 100644 (file)
@@ -26,7 +26,7 @@ public final class TopologicalSort {
 
     /**
      * Topological sort of dependent nodes in acyclic graphs.
-     * 
+     *
      * @return Sorted {@link List} of {@link Node}s. Order: Nodes with no
      *         dependencies starting.
      * @throws IllegalStateException
@@ -61,7 +61,7 @@ public final class TopologicalSort {
     private static Set<Node> getDependentNodes(Set<Node> nodes) {
         Set<Node> dependentNodes = Sets.newHashSet();
         for (Node n : nodes) {
-            if (n.getOutEdges().size() == 0) {
+            if (n.getOutEdges().isEmpty()) {
                 dependentNodes.add(n);
             }
         }
@@ -108,6 +108,11 @@ public final class TopologicalSort {
         private final Set<Edge> inEdges;
         private final Set<Edge> outEdges;
 
+        public NodeImpl() {
+            inEdges = Sets.newHashSet();
+            outEdges = Sets.newHashSet();
+        }
+
         @Override
         public Set<Edge> getInEdges() {
             return inEdges;
@@ -123,11 +128,6 @@ public final class TopologicalSort {
             outEdges.add(e);
             to.getInEdges().add(e);
         }
-
-        public NodeImpl() {
-            inEdges = Sets.newHashSet();
-            outEdges = Sets.newHashSet();
-        }
     }
 
     /**
@@ -137,6 +137,11 @@ public final class TopologicalSort {
         private final Node from;
         private final Node to;
 
+        public EdgeImpl(Node from, Node to) {
+            this.from = from;
+            this.to = to;
+        }
+
         @Override
         public Node getFrom() {
             return from;
@@ -147,12 +152,6 @@ public final class TopologicalSort {
             return to;
         }
 
-        public EdgeImpl(Node from, Node to) {
-            this.from = from;
-            this.to = to;
-
-        }
-
         @Override
         public int hashCode() {
             final int prime = 31;
index 2ea109939976ce34986a85f2f24d07c9359b8767..74d38ae920e482d89e4bf488a0b4a392ecbb9906 100644 (file)
@@ -6,22 +6,45 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
-import com.google.common.base.Optional;
 import java.net.URI;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.util.Uint16;
-import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
+import com.google.common.base.Optional;
+
 /**
  * Test suite for increasing of test coverage of BuilderUtils implementation.
  *
@@ -67,7 +90,7 @@ public class BuilderUtilsTest {
 
     @Test
     public void testFindModuleFromBuildersWithNullPrefix() throws Exception {
-        final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+        final Map<String, NavigableMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
 
         ModuleBuilder result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, null, 12);
         assertEquals(masterModule, result);
@@ -79,8 +102,8 @@ public class BuilderUtilsTest {
         assertEquals(dependentModule, result);
     }
 
-    private Map<String, TreeMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
-        final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>();
+    private Map<String, NavigableMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
+        final Map<String, NavigableMap<Date, ModuleBuilder>> modules = new HashMap<>();
         final String module3Name = "Module3";
 
         ModuleBuilder module3 = new ModuleBuilder(module3Name, "test/module/path/module3.yang");
@@ -92,13 +115,13 @@ public class BuilderUtilsTest {
 
         dependentModule.addModuleImport(module3.getModuleName(), module3.getRevision(), "ter");
 
-        final TreeMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
+        final NavigableMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
         module1Map.put(masterModule.getRevision(), masterModule);
 
-        final TreeMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
+        final NavigableMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
         module2Map.put(dependentModule.getRevision(), dependentModule);
 
-        final TreeMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
+        final NavigableMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
         module3Map.put(module3.getRevision(), module3);
 
         modules.put(masterModule.getName(), module1Map);
@@ -110,7 +133,7 @@ public class BuilderUtilsTest {
 
     @Test(expected = YangParseException.class)
     public void testFindModuleFromBuildersWithNoImportedModule() throws Exception {
-        final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+        final Map<String, NavigableMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
 
         BuilderUtils.findModuleFromBuilders(testModules, masterModule, "eth", 12);
     }
@@ -379,8 +402,8 @@ public class BuilderUtilsTest {
 
     @Test
     public void testFindModule() {
-        final Map<URI, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
-        final TreeMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
+        final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
+        final NavigableMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
         masterModuleMap.put(masterModule.getRevision(), masterModule);
         modules.put(masterModule.getNamespace(), masterModuleMap);
 
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/YangFileStatementSource.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/YangFileStatementSource.java
deleted file mode 100644 (file)
index 9738c46..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.opendaylight.yangtools.yang.stmt.effective.build.test;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.ParseTreeWalker;
-import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementLexer;
-import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class YangFileStatementSource implements StatementStreamSource {
-
-        private YangStatementParserListenerImpl yangStatementModelParser;
-        private YangStatementParser.StatementContext statementContext;
-        private ParseTreeWalker walker;
-
-        public YangFileStatementSource(String fileName) {
-                try {
-                        statementContext = parseYangSource(loadFile(fileName));
-                        walker = new ParseTreeWalker();
-                        yangStatementModelParser = new YangStatementParserListenerImpl(REF);
-                } catch (Exception e) {
-                        e.printStackTrace();
-                }
-        }
-
-        private StatementSourceReference REF = new StatementSourceReference() {
-
-                @Override
-                public StatementSource getStatementSource() {
-                        return StatementSource.DECLARATION;
-                }
-        };
-
-        @Override
-        public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
-                yangStatementModelParser.setAttributes(writer, stmtDef);
-                walker.walk(yangStatementModelParser, statementContext);
-        }
-
-        @Override
-        public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
-                yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
-                walker.walk(yangStatementModelParser, statementContext);
-        }
-
-        @Override
-        public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
-                yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
-                walker.walk(yangStatementModelParser, statementContext);
-        }
-
-        private FileInputStream loadFile(String fileName) throws Exception {
-                return new FileInputStream(new File(getClass().getResource(fileName).toURI()));
-        }
-
-        private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException {
-                final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
-                final CommonTokenStream tokens = new CommonTokenStream(lexer);
-                final YangStatementParser parser = new YangStatementParser(tokens);
-                //TODO: no error listener yet
-                //parser.removeErrorListeners();
-                //final YangErrorListener errorListener = new YangErrorListener();
-                //parser.addErrorListener(errorListener);
-                final YangStatementParser.StatementContext result = parser.statement();
-                //errorListener.validate();
-                return result;
-        }
-}
\ No newline at end of file
index d9ecd4eef523ba1cd2e73920ff0f4a849005f640..d0bed87663cc6afd6b33cbcc5cb8b027e7fd55af 100644 (file)
@@ -3,13 +3,17 @@ package org.opendaylight.yangtools.yang.stmt.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.net.URI;
+
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.meta.ModelStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
@@ -18,7 +22,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
 
-import java.net.URI;
+import com.google.common.collect.ImmutableList;
 
 public class AugmentProcessTest {
 
@@ -27,20 +31,30 @@ public class AugmentProcessTest {
     private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
             "/stmt-test/effective-build/aug-root.yang");
 
+    private static final QNameModule ROOT_QNAME_MODULE = QNameModule.create(URI.create("root"), null);
     private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule.create(URI.create("aug"), null);
 
-    QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent1");
-    QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent2");
-    QName contTarget = QName.create(AUGMENTED_QNAME_MODULE, "cont-target");
+    private static GroupingDefinition grp2Def;
+
+    private final QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent1");
+    private final QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent2");
+    private final QName contTarget = QName.create(AUGMENTED_QNAME_MODULE, "cont-target");
 
-    QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added1");
-    QName contAdded2 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added2");
+    private final QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added1");
+    private final QName contAdded2 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added2");
 
-    QName list1 = QName.create(AUGMENTED_QNAME_MODULE, "list1");
-    QName axml = QName.create(AUGMENTED_QNAME_MODULE, "axml");
+    private final QName list1 = QName.create(AUGMENTED_QNAME_MODULE, "list1");
+    private final QName axml = QName.create(AUGMENTED_QNAME_MODULE, "axml");
 
-    QName contGrp = QName.create(AUGMENTED_QNAME_MODULE, "cont-grp");
-    QName axmlGrp = QName.create(AUGMENTED_QNAME_MODULE, "axml-grp");
+    private final QName contGrp = QName.create(AUGMENTED_QNAME_MODULE, "cont-grp");
+    private final QName axmlGrp = QName.create(AUGMENTED_QNAME_MODULE, "axml-grp");
+
+    private final QName augCont1 = QName.create(ROOT_QNAME_MODULE, "aug-cont1");
+    private final QName augCont2 = QName.create(ROOT_QNAME_MODULE, "aug-cont2");
+
+    private final QName grpCont2 = QName.create(ROOT_QNAME_MODULE, "grp-cont2");
+    private final QName grpCont22 = QName.create(ROOT_QNAME_MODULE, "grp-cont22");
+    private final QName grpAdd = QName.create(ROOT_QNAME_MODULE, "grp-add");
 
     @Test
     public void readAndParseYangFileTest() throws SourceException, ReactorException {
@@ -48,14 +62,13 @@ public class AugmentProcessTest {
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         addSources(reactor, AUGMENTED, ROOT);
 
-        final EffectiveSchemaContext result = reactor.buildEffective();
+        final EffectiveSchemaContext root = reactor.buildEffective();
+        assertNotNull(root);
 
-        assertNotNull(result);
-
-        Module augmentedModule = result.findModuleByName("augmented", null);
+        Module augmentedModule = root.findModuleByName("augmented", null);
         assertNotNull(augmentedModule);
 
-        ContainerSchemaNode augParent1Node = (ContainerSchemaNode) result.getDataChildByName(augParent1);
+        ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root.getDataChildByName(augParent1);
         ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
         ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
         assertNotNull(targetContNode);
@@ -77,6 +90,28 @@ public class AugmentProcessTest {
         assertNotNull(contGrpNode);
         AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
         assertNotNull(axmlGrpNode);
+
+        ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root.getDataChildByName(augCont1);
+        ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node.getDataChildByName(augCont2);
+        assertNotNull(augCont2Node);
+
+        ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node.getDataChildByName(grpCont2);
+        ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node.getDataChildByName(grpCont22);
+        assertNotNull(grpCont22Node);
+
+        ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node.getDataChildByName(grpAdd);
+        assertNotNull(grpAddNode);
+    }
+
+    private <T extends ModelStatement> T findInStatements(QName target, ImmutableList<T> statements) {
+
+        for (final T statement : statements) {
+            if (target.equals(statement.statementDefinition().getArgumentName())) {
+                return statement;
+            }
+        }
+
+        return null;
     }
 
     private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
similarity index 50%
rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/augment/AugmentTest.java
rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentTest.java
index 85308f284130cf8aac27560ad2d3cd9483d0a1f1..8e9399d443ceeddbf48f6cdc1b92c6eee22918f9 100644 (file)
@@ -6,7 +6,7 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.yangtools.yang.stmt.test.augment;
+package org.opendaylight.yangtools.yang.stmt.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -18,93 +18,36 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
 
 public class AugmentTest {
 
-    private static final TestAugmentSource IMPORTED = new TestAugmentSource("imp", "/a");
-    private static final TestAugmentSource VALID_ABS = new TestAugmentSource("root", "/aug1/aug11/aug111");
-    private static final TestAugmentSource VALID_ABS_PREFIXED = new TestAugmentSource("root",
-            "/imp:aug1/imp:aug11/imp:aug111", "imp");
-    private static final TestAugmentSource VALID_REL = new TestAugmentSource("root", "aug1/aug11");
-    private static final TestAugmentSource VALID_REL_PREFIXED = new TestAugmentSource("root",
-            "imp:aug1/imp:aug11/imp:aug111", "imp");
-    private static final TestAugmentSource INVALID_REL_WHITE_SPACE = new TestAugmentSource("root", "..   /aug1/aug11");
-    private static final TestAugmentSource INVALID_REL1 = new TestAugmentSource("root", "./aug1/aug11");
-    private static final TestAugmentSource INVALID_REL2 = new TestAugmentSource("root", "../aug1/aug11");
-    private static final TestAugmentSource INVALID_ABS = new TestAugmentSource("root", "//aug1/aug11/aug111");
-    private static final TestAugmentSource INVALID_ABS_PREFIXED_NO_IMP = new TestAugmentSource("root",
-            "imp:aug1/imp:aug11/imp:aug111");
-    private static final TestAugmentSource INVALID_EMPTY = new TestAugmentSource("root", "");
-    private static final TestAugmentSource INVALID_XPATH = new TestAugmentSource("root", "/aug1/-");
+    private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/imported.yang");
+
+    private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang");
+    private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang");
+    private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang");
+    private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang");
+    private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang");
+    private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang");
+    private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
+            "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang");
 
     @Test
     public void validAugAbsTest() throws SourceException, ReactorException {
 
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, VALID_ABS);
+        addSources(reactor, IMPORTED, VALID_ARGS);
 
-        try {
-            reactor.build();
-        } catch (Exception e) {
-            // if augment argument is correct we only catch an exception that it cannot be found in mock model
-            assertEquals(NullPointerException.class, e.getClass());
-        }
-    }
-
-    @Test
-    public void validAugAbsPrefixedTest() throws SourceException, ReactorException {
-
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORTED, VALID_ABS_PREFIXED);
-
-        try {
-            reactor.build();
-        } catch (Exception e) {
-            // if augment argument is correct we only catch an exception that it cannot be found in mock model
-            assertEquals(NullPointerException.class, e.getClass());
-        }
-    }
-
-    @Test
-    public void validAugRelTest() throws SourceException, ReactorException {
-
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, VALID_REL);
-
-        try {
-            reactor.build();
-        } catch (Exception e) {
-            // if augment argument is correct we only catch an exception that it cannot be found in mock model
-            assertEquals(NullPointerException.class, e.getClass());
-        }
-    }
-
-    @Test
-    public void validAugRelPrefixedTest() throws SourceException, ReactorException {
-
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORTED, VALID_REL_PREFIXED);
-
-        try {
-            reactor.build();
-        } catch (Exception e) {
-            // if augment argument is correct we only catch an exception that it cannot be found in mock model
-            assertEquals(NullPointerException.class, e.getClass());
-        }
-    }
-
-    @Test
-    public void validAugRelWhiteSpaceTest() throws SourceException, ReactorException {
-
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, INVALID_REL_WHITE_SPACE);
-
-        try {
-            reactor.build();
-            fail("reactor.process should fail due to invalid relative path");
-        } catch (Exception e) {
-            assertEquals(IllegalArgumentException.class, e.getClass());
-        }
+        final EffectiveModelContext result = reactor.build();
+        assertNotNull(result);
     }
 
     @Test
@@ -191,10 +134,9 @@ public class AugmentTest {
         }
     }
 
-    private void addSources(BuildAction reactor, TestAugmentSource... sources) {
-        for (TestAugmentSource source : sources) {
+    private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
+        for (YangStatementSourceImpl source : sources) {
             reactor.addSource(source);
         }
     }
-
 }
index cfdc863d2cbaca2a036cc408ed22ad2dcdfe79b9..a301f322fc5e50d85b5f79516261ba8fe04bbcb4 100644 (file)
@@ -22,6 +22,8 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
 
 class ImportBasicTestStatementSource implements StatementStreamSource {
 
@@ -157,6 +159,4 @@ class ImportBasicTestStatementSource implements StatementStreamSource {
         writer.endStatement(REF);
         return this;
     }
-
-
 }
similarity index 64%
rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/key/KeyTest.java
rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/KeyTest.java
index 0a1569a09424a7118c4cff51160721b544af40ae..d0ef8c2fe3d0e87c333db4b8fc902f009b422129 100644 (file)
@@ -6,7 +6,11 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.yangtools.yang.stmt.test.key;
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
@@ -14,30 +18,20 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-
-import static org.junit.Assert.*;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
 
 public class KeyTest {
 
-    private static final TestKeySource KEY_SIMPLE = new TestKeySource("root", "key");
-    private static final TestKeySource KEY_COMP = new TestKeySource("root", "key1 key2 key3");
-    private static final TestKeySource KEY_COMP_DUPLICATE = new TestKeySource("root", "key1 key1 key2");
+    private static final YangStatementSourceImpl KEY_SIMPLE_AND_COMP = new YangStatementSourceImpl(
+            "/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang");
+    private static final YangStatementSourceImpl KEY_COMP_DUPLICATE = new YangStatementSourceImpl(
+            "/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang");
 
     @Test
     public void keySimpleTest() throws SourceException, ReactorException {
 
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, KEY_SIMPLE);
-
-        EffectiveModelContext result = reactor.build();
-        assertNotNull(result);
-    }
-
-    @Test
-    public void keyCompositeTest() throws SourceException, ReactorException {
-
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, KEY_COMP);
+        addSources(reactor, KEY_SIMPLE_AND_COMP);
 
         EffectiveModelContext result = reactor.build();
         assertNotNull(result);
@@ -57,8 +51,8 @@ public class KeyTest {
         }
     }
 
-    private void addSources(BuildAction reactor, TestKeySource... sources) {
-        for (TestKeySource source : sources) {
+    private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
+        for (YangStatementSourceImpl source : sources) {
             reactor.addSource(source);
         }
     }
index ee2b10a22209a22dceb8b1a0c103d359a2d8274e..3ffc50c2398d64205c059e86e3f5369d6ce54543 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -19,45 +19,27 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceIm
 import static org.junit.Assert.assertNotNull;
 
 public class YangFileStmtTest {
-        private static final YangStatementSourceImpl YANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/test.yang");
-        private static final YangStatementSourceImpl IMPORTEDYANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/importedtest.yang");
-        private static final YangStatementSourceImpl SIMPLENODES = new YangStatementSourceImpl("/semantic-statement-parser/simple-nodes-semantic.yang");
-        private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl("/semantic-statement-parser/foo.yang");
-        private static final YangStatementSourceImpl FILE1 = new YangStatementSourceImpl("/model/bar.yang");
-        private static final YangStatementSourceImpl FILE2 = new YangStatementSourceImpl("/model/baz.yang");
-        private static final YangStatementSourceImpl FILE3 = new YangStatementSourceImpl("/model/foo.yang");
-        private static final YangStatementSourceImpl FILE4 = new YangStatementSourceImpl("/model/subfoo.yang");
-        private static final YangStatementSourceImpl EXTFILE = new YangStatementSourceImpl("/semantic-statement-parser/ext-typedef.yang");
-        private static final YangStatementSourceImpl EXTUSE = new YangStatementSourceImpl("/semantic-statement-parser/ext-use.yang");
+    //basic statements to parse and write
+    private static final YangStatementSourceImpl YANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/test.yang");
+    private static final YangStatementSourceImpl IMPORTEDYANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/importedtest.yang");
+    private static final YangStatementSourceImpl SIMPLENODES = new YangStatementSourceImpl("/semantic-statement-parser/simple-nodes-semantic.yang");
+    private static final YangStatementSourceImpl FOOBAR = new YangStatementSourceImpl("/semantic-statement-parser/foobar.yang");
+    //extension statement to parse and write
+    private static final YangStatementSourceImpl EXTFILE = new YangStatementSourceImpl("/semantic-statement-parser/ext-typedef.yang");
+    private static final YangStatementSourceImpl EXTUSE = new YangStatementSourceImpl("/semantic-statement-parser/ext-use.yang");
 
-        @Test
-        public void readAndParseYangFileTest1() throws SourceException, ReactorException {
-                CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-                addSources(reactor, YANGFILE, SIMPLENODES, IMPORTEDYANGFILE, FOO);
-                EffectiveModelContext result = reactor.build();
-                assertNotNull(result);
-        }
-
-        // TODO uncomment when Augment in Uses implemented
-//        @Test
-//        public void readAndParseYangFileTest2() throws SourceException, ReactorException {
-//                CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-//                addSources(reactor, FILE1, FILE2, FILE3, FILE4);
-//                EffectiveModelContext result = reactor.build();
-//                assertNotNull(result);
-//        }
-
-        @Test
-        public void readAndParseYangFileTest3() throws SourceException, ReactorException {
-                CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-                addSources(reactor, EXTFILE, EXTUSE);
-                EffectiveModelContext result = reactor.build();
-                assertNotNull(result);
-        }
+    @Test
+    public void readAndParseYangFileTest() throws SourceException, ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, YANGFILE, SIMPLENODES, IMPORTEDYANGFILE, FOOBAR);
+        addSources(reactor, EXTFILE, EXTUSE);
+        EffectiveModelContext result = reactor.build();
+        assertNotNull(result);
+    }
 
-        private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
-                for (StatementStreamSource source : sources) {
-                        reactor.addSource(source);
-                }
+    private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+        for (StatementStreamSource source : sources) {
+            reactor.addSource(source);
         }
+    }
 }
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/augment/TestAugmentSource.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/augment/TestAugmentSource.java
deleted file mode 100644 (file)
index 6019009..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-package org.opendaylight.yangtools.yang.stmt.test.augment;
-
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.AUGMENT;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.IMPORT;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.PREFIX;
-
-import java.util.Arrays;
-
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-
-public class TestAugmentSource implements StatementStreamSource {
-
-    private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
-
-    private final String name;
-    private final String augment;
-    private final java.util.List<String> imports;
-    private StatementWriter writer;
-    private StatementSourceReference REF = new StatementSourceReference() {
-
-        @Override
-        public StatementSource getStatementSource() {
-            return StatementSource.DECLARATION;
-        }
-    };
-
-    public TestAugmentSource(String name, String augment, String... imports) {
-        this.name = name;
-        this.augment = augment;
-        this.imports = Arrays.asList(imports);
-    }
-
-    @Override
-    public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
-            throws SourceException {
-        this.writer = writer;
-        header();
-        extensions();
-        body();
-        end();
-    }
-
-    @Override
-    public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
-        this.writer = writer;
-        header().end();
-    }
-
-    @Override
-    public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
-                                                    PrefixToModule prefixes) throws SourceException {
-        this.writer = writer;
-        header();
-        extensions();
-        end();
-    }
-
-    protected void extensions() throws SourceException {
-
-    }
-
-    protected void body() throws SourceException {
-
-        stmt(AUGMENT).arg(augment);
-        end();
-    }
-
-    TestAugmentSource header() throws SourceException {
-
-        stmt(MODULE).arg(name);
-        {
-            stmt(NAMESPACE).arg(getNamespace()).end();
-            stmt(PREFIX).arg(name).end();
-        }
-
-        for (String impEntry : imports) {
-
-            stmt(IMPORT).arg(impEntry);
-            {
-                stmt(PREFIX).arg(impEntry).end();
-            }
-            end();
-        }
-
-        return this;
-    }
-
-    private String getNamespace() {
-        return NS_PREFIX + name;
-    }
-
-    protected TestAugmentSource arg(String arg) throws SourceException {
-        writer.argumentValue(arg, REF);
-        return this;
-    }
-
-    protected TestAugmentSource stmt(Rfc6020Mapping stmt) throws SourceException {
-        writer.startStatement(stmt.getStatementName(), REF);
-        return this;
-    }
-
-    protected TestAugmentSource end() throws SourceException {
-        writer.endStatement(REF);
-        return this;
-    }
-}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/key/TestKeySource.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/key/TestKeySource.java
deleted file mode 100644 (file)
index fea5430..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.opendaylight.yangtools.yang.stmt.test.key;
-
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.KEY;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
-import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.PREFIX;
-
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-
-public class TestKeySource implements StatementStreamSource {
-
-    private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
-
-    private final String name;
-    private final String key;
-    private StatementWriter writer;
-    private StatementSourceReference REF = new StatementSourceReference() {
-
-        @Override
-        public StatementSource getStatementSource() {
-            return StatementSource.DECLARATION;
-        }
-    };
-
-    public TestKeySource(String name, String key) {
-        this.name = name;
-        this.key = key;
-    }
-
-    @Override
-    public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
-            throws SourceException {
-
-        this.writer = writer;
-
-        header();
-        extensions();
-        body();
-        end();
-    }
-
-    @Override
-    public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
-        this.writer = writer;
-        header().end();
-    }
-
-    @Override
-    public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
-            PrefixToModule prefixes) throws SourceException {
-        this.writer = writer;
-        header();
-        extensions();
-        end();
-    }
-
-    protected void extensions() throws SourceException {
-
-    }
-
-    protected void body() throws SourceException {
-
-        stmt(Rfc6020Mapping.LIST).arg("lst");
-        {
-            stmt(KEY).arg(key).end();
-        }
-        end();
-    }
-
-    TestKeySource header() throws SourceException {
-
-        stmt(MODULE).arg(name);
-        {
-            stmt(NAMESPACE).arg(getNamespace()).end();
-            stmt(PREFIX).arg(name).end();
-        }
-
-        return this;
-    }
-
-    private String getNamespace() {
-        return NS_PREFIX + name;
-    }
-
-    protected TestKeySource arg(String arg) throws SourceException {
-        writer.argumentValue(arg, REF);
-        return this;
-    }
-
-    protected TestKeySource stmt(Rfc6020Mapping stmt) throws SourceException {
-        writer.startStatement(stmt.getStatementName(), REF);
-        return this;
-    }
-
-    protected TestKeySource end() throws SourceException {
-        writer.endStatement(REF);
-        return this;
-    }
-}
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/imported.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/imported.yang
new file mode 100644 (file)
index 0000000..3fa44c4
--- /dev/null
@@ -0,0 +1,19 @@
+module imported {
+       namespace imp;
+       prefix imp;
+
+       container aug1 {
+        container aug11 {
+            container aug111 {
+
+            }
+        }
+    }
+
+    grouping grp {
+        container aug2 {
+            container aug22 {
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang
new file mode 100644 (file)
index 0000000..77802f4
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-abs-no-imp {
+       namespace root;
+       prefix root;
+
+       augment "imp:aug1/imp:aug11/imp:aug111" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang
new file mode 100644 (file)
index 0000000..ea0ed83
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-abs {
+       namespace root;
+       prefix root;
+
+       augment "//aug1/aug11/aug111" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang
new file mode 100644 (file)
index 0000000..6d46632
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-empty {
+       namespace root;
+       prefix root;
+
+       augment "" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang
new file mode 100644 (file)
index 0000000..a35f83f
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-rel1 {
+       namespace root;
+       prefix root;
+
+       augment "./aug1/aug11" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang
new file mode 100644 (file)
index 0000000..2c8d32a
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-rel2 {
+       namespace root;
+       prefix root;
+
+       augment "../aug1/aug11" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang
new file mode 100644 (file)
index 0000000..2a8e82c
--- /dev/null
@@ -0,0 +1,9 @@
+module root-invalid-xpath {
+       namespace root;
+       prefix root;
+
+       augment "/aug1/-" {
+               container add {
+               }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang
new file mode 100644 (file)
index 0000000..8683912
--- /dev/null
@@ -0,0 +1,39 @@
+module root-valid-aug-args {
+       namespace root;
+       prefix root;
+
+       import imported;
+
+       augment "/aug1/aug11/aug111" {
+               container add {
+               }
+       }
+
+       container aug1 {
+               container aug11 {
+                       container aug111 {
+
+            }
+               }
+       }
+
+    augment "/imp:aug1/imp:aug11/imp:aug111" {
+        container add {
+        }
+    }
+
+       grouping grp {
+               container aug2 {
+                       container aug22 {
+                       }
+               }
+       }
+
+       uses grp {
+
+               augment "aug2/aug22" {
+                       container add {
+                       }
+               }
+       }
+}
\ No newline at end of file
similarity index 87%
rename from yang/yang-parser-impl/src/test/resources/semantic-statement-parser/foo.yang
rename to yang/yang-parser-impl/src/test/resources/semantic-statement-parser/foobar.yang
index 6854e33aac2adcda9e0ab2ca7f20be39d242db6d..6870055629f5c491d390d786c8a7de0b0bcf19d2 100644 (file)
@@ -1,7 +1,7 @@
-module foo {
+module foobar {
     yang-version 1;
-    namespace "urn:opendaylight.foo";
-    prefix "foo";
+    namespace "urn:opendaylight.foobar";
+    prefix "foobar";
 
     revision "2015-07-08" {
     }
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang
new file mode 100644 (file)
index 0000000..e56e1f7
--- /dev/null
@@ -0,0 +1,14 @@
+module key-comp-duplicate {
+       namespace root;
+       prefix root;
+
+       list comp {
+               key "key1 key2 key2";
+               container key1 {
+        }
+               container key2 {
+        }
+               container key3 {
+        }
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang
new file mode 100644 (file)
index 0000000..86ce815
--- /dev/null
@@ -0,0 +1,20 @@
+module key-simple-and-comp {
+       namespace root;
+       prefix root;
+
+       list simple {
+               key "key1";
+               container key1 {
+               }
+       }
+
+       list comp {
+               key "key1 key2 key3";
+               container key1 {
+        }
+               container key2 {
+        }
+               container key3 {
+        }
+       }
+}
\ No newline at end of file
index dcc8578ad3838b3b2bd336f0fdbd9308456bd2d5..247aceb56512987dff3cf111b2d31e4a6a1510c0 100644 (file)
@@ -29,7 +29,7 @@ module simple-nodes {
 
 
     anyxml data {
-        config false;
+         config false;
          description "anyxml desc";
          if-feature has-name;
          mandatory true;
index 017b10820f7b03c532fe2bad0ea49c1091ad8195..27332145ace9cfa2dc035cb4e84869e4c2dfcabb 100644 (file)
@@ -6,7 +6,7 @@ module aug-root {
                prefix aug;
        }
 
-       augment "aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
+       augment "/aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
                container cont-added1 {
                        list list1 {
                        }
@@ -18,4 +18,22 @@ module aug-root {
 
                uses aug:grp;
        }
+
+       grouping grp2 {
+        container grp-cont2 {
+            container grp-cont22 {
+            }
+        }
+    }
+
+       container aug-cont1 {
+               container aug-cont2 {
+                   uses grp2 {
+                       augment "grp-cont2/grp-cont22" {
+                           container grp-add {
+                           }
+                       }
+                   }
+           }
+       }
 }
\ No newline at end of file