Merge "Add hooking into NormalizedNodeParsers."
authorTony Tkacik <ttkacik@cisco.com>
Thu, 30 Apr 2015 13:37:48 +0000 (13:37 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 30 Apr 2015 13:37:48 +0000 (13:37 +0000)
59 files changed:
common/checkstyle-logging/pom.xml
common/checkstyle-logging/src/test/java/org/opendaylight/yangtools/checkstyle/CheckstyleTest.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/RpcAsContainer.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeResult.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ResultAlreadySetException.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableDataContainerAttrNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNode.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/DeviateStatement.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.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/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/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.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/DeviateStatementImpl.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/IncludeStatementImpl.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/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/effective/AnyXmlEffectiveStatementImpl.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/DeviateEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.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/OutputEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveBuildTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java [new file with mode: 0644]
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/YangFileStmtTest.java
yang/yang-parser-impl/src/test/resources/model-new/bar.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/model-new/baz.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/model-new/foo.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/model-new/subfoo.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/imported.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/root.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/submod.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/aug-root.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/augmented.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-imported.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect2.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-root.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-submodule.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-test.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/aug-root.yang [deleted file]
yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/augmented.yang [deleted file]

index 889ef2b65822fdf050644d8fc97af4c80318985e..238e78c7ea509ba0ea52587cdd163fd9a7f1e7c5 100644 (file)
@@ -21,7 +21,7 @@
     <dependency>
       <groupId>com.puppycrawl.tools</groupId>
       <artifactId>checkstyle</artifactId>
-      <version>5.7</version>
+      <version>6.1.1</version>
     </dependency>
     <dependency>
         <groupId>org.slf4j</groupId>
index 24e048ad97a2027a4989bac705dbd5e471f5baab..bf59c594b4b558ccb953f048eb9d5cc733cc29b8 100644 (file)
@@ -11,14 +11,6 @@ package org.opendaylight.yangtools.checkstyle;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-
 import com.google.common.collect.Lists;
 import com.puppycrawl.tools.checkstyle.Checker;
 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
@@ -27,6 +19,12 @@ import com.puppycrawl.tools.checkstyle.PropertiesExpander;
 import com.puppycrawl.tools.checkstyle.api.AuditListener;
 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
 import com.puppycrawl.tools.checkstyle.api.Configuration;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
 
 public class CheckstyleTest {
 
@@ -36,11 +34,11 @@ public class CheckstyleTest {
     @Before
     public void setup() throws CheckstyleException {
         baos = new ByteArrayOutputStream();
-        AuditListener listener = new DefaultLogger(baos, false);
+        final AuditListener listener = new DefaultLogger(baos, false);
 
-        InputSource inputSource = new InputSource(CheckstyleTest.class.getClassLoader().getResourceAsStream(
+        final InputSource inputSource = new InputSource(CheckstyleTest.class.getClassLoader().getResourceAsStream(
                 "checkstyle-logging.xml"));
-        Configuration configuration = ConfigurationLoader.loadConfiguration(inputSource,
+        final Configuration configuration = ConfigurationLoader.loadConfiguration(inputSource,
                 new PropertiesExpander(System.getProperties()), false);
 
         checker = new Checker();
@@ -66,7 +64,7 @@ public class CheckstyleTest {
     @Test
     public void testCodingChecks() {
         verify(CheckCodingStyleTestClass.class, false, "9: Line has Windows line delimiter.", "14: Wrong order for", "24:1: Line contains a tab character.",
-                "22: Line has trailing spaces.", "22: ctor def child at indentation level 16 not at correct indentation, 8", "17:8: Unused import",
+                "22: Line has trailing spaces.", "22: 'ctor def' child have incorrect indentation level 16, expected level should be 8.", "17:8: Unused import",
                 "23: Line has trailing spaces.");
     }
 
index 0b64b2296782e939dc239f5a6b93e9abb6b8a3ef..b9fddf3ecf5a063c86ddeab1a93b958f7f07641a 100644 (file)
@@ -93,8 +93,9 @@ final class RpcAsContainer implements ContainerSchemaNode {
                 return delegate.getInput();
             case "output":
                 return delegate.getOutput();
+            default:
+                return null;
         }
-        return null;
     }
 
     @Override
@@ -114,7 +115,7 @@ final class RpcAsContainer implements ContainerSchemaNode {
 
     @Override
     public Collection<DataSchemaNode> getChildNodes() {
-        final ArrayList<DataSchemaNode> ret = new ArrayList<>();
+        final List<DataSchemaNode> ret = new ArrayList<>();
         final ContainerSchemaNode input = getInput();
         final ContainerSchemaNode output = getOutput();
         if(input != null) {
index 76b28e93aaad9a7775068b3a37e383cdf9738ac1..47723fd788f00ed91ce4f499fcd245e258e27be8 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
-import com.google.common.base.Preconditions;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 /**
@@ -33,7 +32,9 @@ public class NormalizedNodeResult {
     }
 
     void setResult(final NormalizedNode<?, ?> result) {
-        Preconditions.checkState(!this.finished, "Result was already set.");
+        if (finished) {
+            throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
+        }
         this.finished = true;
         this.result = result;
     }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ResultAlreadySetException.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ResultAlreadySetException.java
new file mode 100644 (file)
index 0000000..f73c315
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class ResultAlreadySetException extends IllegalStateException {
+    private final NormalizedNode<?, ?> resultData;
+
+    public ResultAlreadySetException(String message, NormalizedNode<?, ?> resultData) {
+        this(message, resultData, null);
+    }
+
+    public ResultAlreadySetException(String message, NormalizedNode<?, ?> resultData, Throwable cause) {
+        super(message, cause);
+        this.resultData = resultData;
+    }
+
+    public NormalizedNode<?, ?> getResultData() {
+        return resultData;
+    }
+}
index 1742c03357aee94c4e503ee98f6c4f427822990e..f382586ef2d79e121c2b3d96810a528190a777c9 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 
+// FIXME: are attributes part of hashCode/equals?
 public abstract class AbstractImmutableDataContainerAttrNode<K extends YangInstanceIdentifier.PathArgument>
         extends AbstractImmutableDataContainerNode<K>
     implements AttributesContainer {
@@ -44,26 +45,4 @@ public abstract class AbstractImmutableDataContainerAttrNode<K extends YangInsta
         return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
     }
 
-// FIXME: are attributes part of hashCode/equals?
-//    @Override
-//    protected int valueHashCode() {
-//        int result = super.valueHashCode();
-//        for (final Entry<?, ?> a : attributes.entrySet()) {
-//            result = 31 * result + a.hashCode();
-//        }
-//        return result;
-//    }
-
- // FIXME: are attributes part of hashCode/equals?
-//    @Override
-//    protected boolean valueEquals(final NormalizedNode<?, ?> other) {
-//        if (!super.valueEquals(other)) {
-//            return false;
-//        }
-//        final Set<Entry<QName, String>> tas = getAttributes().entrySet();
-//        final Set<Entry<QName, String>> oas = container.getAttributes().entrySet();
-//
-//        return tas.containsAll(oas) && oas.containsAll(tas);
-//        return true;
-//    }
 }
index ec615025ebd5def89fdadb5d04cdac283122cb48..842cf231f7126290ee13ff4e3c5ddf4ee7baa4dd 100644 (file)
@@ -43,10 +43,7 @@ public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangIns
     @Override
     protected int valueHashCode() {
         final int result = getValue() != null ? getValue().hashCode() : 1;
-// FIXME: are attributes part of hashCode/equals?
-//        for (final Entry<?, ?> a : attributes.entrySet()) {
-//            result = 31 * result + a.hashCode();
-//        }
+        // FIXME: are attributes part of hashCode/equals?
         return result;
     }
 
@@ -60,11 +57,6 @@ public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangIns
         }
 
         // FIXME: are attributes part of hashCode/equals?
-        // final Set<Entry<QName, String>> tas = getAttributes().entrySet();
-        // final Set<Entry<QName, String>> oas =
-        // container.getAttributes().entrySet();
-        //
-        // return tas.containsAll(oas) && oas.containsAll(tas);
         return true;
     }
 
index 00ec9408d4e63d00688e00ec57a083c62cd024fc..6308381916a01a400b0602194a9a8b77f7cac0d8 100644 (file)
@@ -8,10 +8,12 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import javax.annotation.Nonnull;
+
+import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
-public interface DeviateStatement extends DeclaredStatement<String> {
+public interface DeviateStatement extends DeclaredStatement<Deviation.Deviate> {
 
-    @Nonnull String getValue();
+    @Nonnull
+    Deviation.Deviate getValue();
 }
-
index 43e2014e32164c5a48bdb4b24e3009eae6646d16..5b85dc637720f4570ca90d7bf56cf2236c788906 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
 import java.util.List;
-
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -23,32 +22,44 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
+public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
 
-public interface StmtContext<A,D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
-
-    @Nonnull StatementSource getStatementSource();
+    @Nonnull
+    StatementSource getStatementSource();
 
-    @Nonnull StatementSourceReference getStatementSourceReference();
+    @Nonnull
+    StatementSourceReference getStatementSourceReference();
 
-    @Nonnull StatementDefinition getPublicDefinition();
+    @Nonnull
+    StatementDefinition getPublicDefinition();
 
-    @Nullable StmtContext<?,?,?> getParentContext();
+    @Nullable
+    StmtContext<?, ?, ?> getParentContext();
 
-    @Nullable String rawStatementArgument();
+    @Nullable
+    String rawStatementArgument();
 
-    @Nullable A getStatementArgument();
+    @Nullable
+    A getStatementArgument();
 
-    @Nullable List<Object> getArgumentsFromRoot();
+    @Nullable
+    List<Object> getArgumentsFromRoot();
 
-    //<K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
-    //       <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key)
-    @Nonnull <K,V,N extends IdentifierNamespace<K, V>> V getFromNamespace(Class<N> type, K key) throws NamespaceNotAvailableException;
+    // <K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
+    // <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT
+    // getFromNamespace(Class<N> type, K key)
+    @Nonnull
+    <K, V, N extends IdentifierNamespace<K, V>> V getFromNamespace(
+            Class<N> type, K key) throws NamespaceNotAvailableException;
 
-    <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(Class<N> type);
+    <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(
+            Class<N> type);
 
-    @Nonnull StmtContext<?,?,?> getRoot();
+    @Nonnull
+    StmtContext<?, ?, ?> getRoot();
 
-    @Nonnull Collection<StatementContextBase<?,?,?>> declaredSubstatements();
+    @Nonnull
+    Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
 
     public Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
 
@@ -56,26 +67,48 @@ public interface StmtContext<A,D extends DeclaredStatement<A>, E extends Effecti
 
     E buildEffective();
 
-    public StatementContextBase<?, ?, ?>  createCopy(QNameModule newQNameModule,StatementContextBase<?, ?, ?> newParent) throws SourceException;
+    public StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+            throws SourceException;
+
+    public static enum TypeOfCopy {
+        ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION
+    }
+
+    public TypeOfCopy getTypeOfCopy();
+
+    public void setTypeOfCopy(TypeOfCopy typeOfCopy);
+
+    public StatementContextBase<?, ?, ?> getOriginalCtx();
 
-    interface Mutable<A,D extends DeclaredStatement<A>,E extends EffectiveStatement<A, D>> extends StmtContext<A,D,E> {
+    public void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
+
+    public boolean isRootContext();
+
+    public void setCompletedPhase(ModelProcessingPhase completedPhase);
+
+    public ModelProcessingPhase getCompletedPhase();
+
+    interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+            extends StmtContext<A, D, E> {
 
         @Override
-        StmtContext.Mutable<?,?,?> getParentContext();
+        StmtContext.Mutable<?, ?, ?> getParentContext();
 
-        //<K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value)
-        <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value) throws NamespaceNotAvailableException;
+        // <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void
+        // addToNs(Class<N> type, K key, VT value)
+        <K, V, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+                Class<N> type, K key, VT value)
+                throws NamespaceNotAvailableException;
 
         @Override
-        StmtContext.Mutable<?,?,?> getRoot();
+        StmtContext.Mutable<?, ?, ?> getRoot();
 
         ModelActionBuilder newInferenceAction(ModelProcessingPhase phase);
 
-        <K,KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
-                StmtContext<?, ?, ?> stmt);
+        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
+                Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
 
     }
 
-
-
 }
index eefd87f9a98e1533e428656baaef2a3f13134857..1388ef161dcdb120dc79ba7e3590d016da21e4f8 100644 (file)
@@ -38,7 +38,6 @@ public final class StmtContextUtils {
     }
 
     @SuppressWarnings("unchecked")
-
     public static final <E extends EffectiveStatement<?, ?>> Function<StmtContext<?, ?, ? extends E>, E> buildEffective() {
         return Function.class.cast(BUILD_EFFECTIVE);
     }
index ad6d70a823c9060d454394b2460d8cc43ce4f2b3..90b41b99120af501050a5b1a8d2ec0b43f46f8d9 100644 (file)
@@ -105,7 +105,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
              */
             return (NamespaceBehaviourWithListeners<K, V, N>) potential;
         }
-        throw new NamespaceNotAvailableException("Namespace " + type + "is not available in phase " + currentPhase);
+        throw new NamespaceNotAvailableException("Namespace " + type + " is not available in phase " + currentPhase);
     }
 
     public StatementDefinitionContext<?, ?, ?> getStatementDefinition(QName name) {
@@ -195,10 +195,15 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
                     switch (sourceProgress) {
                         case FINISHED:
                             currentSource.remove();
+                            // Fallback to progress, since we were able to make progress in computation
                         case PROGRESS:
                             progressing = true;
+                            break;
                         case NO_PROGRESS:
-                            // Noop;
+                            // Noop
+                            break;
+                        default:
+                           throw new IllegalStateException("Unsupported phase progress " + sourceProgress);
                     }
                 }
             }
index 225ce471106174bf30983c23c8f57e702bc9d684..75879a54a059e3662b8ae965b35eadcc09cf3eb7 100644 (file)
@@ -64,7 +64,7 @@ class ModifierImpl implements ModelActionBuilder {
     }
 
     private void tryToResolve() throws InferenceException {
-        if(action == null) {
+        if(action == null || isApplied()) {
             // Action was not yet defined
             return;
         }
@@ -104,8 +104,13 @@ class ModifierImpl implements ModelActionBuilder {
 
     private void applyAction() throws InferenceException {
 
-        action.apply();
-        // Mark all mutations as performed, so context node could move to next.
+        try {
+            action.apply();
+        } catch (InferenceException e) {
+            actionApplied = false;
+            return;
+        }
+        // Â Mark all mutations as performed, so context node could move to next.
         actionApplied = true;
     }
 
@@ -255,11 +260,11 @@ class ModifierImpl implements ModelActionBuilder {
             return done;
         }
 
-        protected void resolvePrereq(T value) throws InferenceException {
-            Preconditions.checkState(!isDone());
+        protected boolean resolvePrereq(T value) throws InferenceException {
             this.value = value;
             this.done = true;
             tryToResolve();
+            return isApplied();
         }
 
         protected <O> Prerequisite<O> transform(final Function<? super T,O> transformation) {
@@ -300,8 +305,8 @@ class ModifierImpl implements ModelActionBuilder {
 
         @SuppressWarnings("unchecked")
         @Override
-        public void phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
-            resolvePrereq((C) (context));
+        public boolean phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
+            return resolvePrereq((C) (context));
         }
     }
 
@@ -330,8 +335,8 @@ class ModifierImpl implements ModelActionBuilder {
 
         @SuppressWarnings("unchecked")
         @Override
-        public void phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
-            resolvePrereq((C) context);
+        public boolean phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
+            return resolvePrereq((C) context);
         }
 
     }
index 695251f369a89f78a36f2a961306f368ae4e2733..d32b8cdee123346d0b072c69ee56ed515ab61348 100644 (file)
@@ -34,35 +34,38 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
     }
 
     RootStatementContext(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule) throws SourceException {
+            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+            throws SourceException {
         super(original);
 
         sourceContext = original.sourceContext;
         this.argument = original.argument;
 
-        copyDeclaredStmts(original, newQNameModule);
+        copyDeclaredStmts(original, newQNameModule, typeOfCopy);
 
-        copyEffectiveStmts(original, newQNameModule);
+        copyEffectiveStmts(original, newQNameModule, typeOfCopy);
 
     }
 
     private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule) throws SourceException {
+            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+            throws SourceException {
         Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
                 .declaredSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
-            this.addEffectiveSubstatement(stmtContext
-                    .createCopy(newQNameModule,this));
+            this.addEffectiveSubstatement(stmtContext.createCopy(
+                    newQNameModule, this, typeOfCopy));
         }
     }
 
     private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule) throws SourceException {
+            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+            throws SourceException {
         Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
                 .effectiveSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
-            this.addEffectiveSubstatement(stmtContext
-                    .createCopy(newQNameModule,this));
+            this.addEffectiveSubstatement(stmtContext.createCopy(
+                    newQNameModule, this, typeOfCopy));
         }
     }
 
@@ -96,10 +99,14 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
     }
 
     @Override
-    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
+    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
             throws SourceException {
-
-        return new RootStatementContext<>(this, newQNameModule);
+        RootStatementContext<A, D, E> copy = new RootStatementContext<>(this,
+                newQNameModule, typeOfCopy);
+        copy.setTypeOfCopy(typeOfCopy);
+        copy.setOriginalCtx(this);
+        return copy;
     }
 
     @Override
@@ -109,4 +116,8 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
         return argumentList;
     }
 
+    @Override
+    public boolean isRootContext() {
+        return true;
+    }
 }
index 847f8e988e43040f221fbcd064af34cefd225d37..4f2be08a4df5a9b255c776381b4571a0fbccfbe4 100644 (file)
@@ -175,7 +175,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
 
         boolean phaseCompleted = root.tryToCompletePhase(phase);
 
-        hasProgressed = hasProgress(currentPhaseModifiers);
+        hasProgressed = (hasProgress(currentPhaseModifiers) | hasProgressed);
 
         if(phaseCompleted && (currentPhaseModifiers.isEmpty())) {
             finishedPhase = phase;
index 43692ff0dae32f1bee0b7469e0c2ae761d854cae..4ce2f5b9f3bf3a2175eb5a086b63b31fd357864b 100644 (file)
@@ -35,18 +35,22 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
 
-public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
-        NamespaceStorageSupport implements StmtContext.Mutable<A, D, E>, Identifiable<StatementIdentifier> {
+public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+        extends NamespaceStorageSupport implements
+        StmtContext.Mutable<A, D, E>, Identifiable<StatementIdentifier> {
 
-    interface OnNamespaceItemAdded extends EventListener{
+    interface OnNamespaceItemAdded extends EventListener {
 
-        void namespaceItemAdded(StatementContextBase<?,?,?> context, Class<?> namespace, Object key, Object value) throws SourceException;
+        void namespaceItemAdded(StatementContextBase<?, ?, ?> context,
+                Class<?> namespace, Object key, Object value)
+                throws SourceException;
 
     }
 
-    interface OnPhaseFinished extends EventListener{
+    interface OnPhaseFinished extends EventListener {
 
-        void phaseFinished(StatementContextBase<?,?,?> context, ModelProcessingPhase phase) throws SourceException;
+        boolean phaseFinished(StatementContextBase<?, ?, ?> context,
+                ModelProcessingPhase phase) throws SourceException;
 
     }
 
@@ -63,13 +67,16 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         private String rawArg;
         private StatementSourceReference argRef;
 
-        public ContextBuilder(StatementDefinitionContext<A, D, E> def, StatementSourceReference sourceRef) {
+        public ContextBuilder(StatementDefinitionContext<A, D, E> def,
+                StatementSourceReference sourceRef) {
             this.definition = def;
             this.stmtRef = sourceRef;
         }
 
-        public void setArgument(@Nonnull String argument, @Nonnull StatementSourceReference argumentSource) {
-            Preconditions.checkArgument(definition.hasArgument(), "Statement does not take argument.");
+        public void setArgument(@Nonnull String argument,
+                @Nonnull StatementSourceReference argumentSource) {
+            Preconditions.checkArgument(definition.hasArgument(),
+                    "Statement does not take argument.");
             this.rawArg = Preconditions.checkNotNull(argument);
             this.argRef = Preconditions.checkNotNull(argumentSource);
         }
@@ -91,10 +98,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         }
 
         public StatementIdentifier getIdentifier() {
-            return new StatementIdentifier(definition.getStatementName(), rawArg);
+            return new StatementIdentifier(definition.getStatementName(),
+                    rawArg);
         }
 
-        public abstract StatementContextBase<A, D, E> build() throws SourceException;
+        public abstract StatementContextBase<A, D, E> build()
+                throws SourceException;
 
     }
 
@@ -102,28 +111,63 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private final StatementIdentifier identifier;
     private final StatementSourceReference statementDeclSource;
 
-    private Map<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
+    private Map<StatementIdentifier, StatementContextBase<?, ?, ?>> substatements = new LinkedHashMap<>();
 
     private Collection<StatementContextBase<?, ?, ?>> declared = new ArrayList<>();
     private Collection<StatementContextBase<?, ?, ?>> effective = new ArrayList<>();
 
     private ModelProcessingPhase completedPhase;
 
-    private Multimap<ModelProcessingPhase,OnPhaseFinished> phaseListeners = HashMultimap.create();
-    private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = HashMultimap.create();
+    private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = HashMultimap
+            .create();
+    private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = HashMultimap
+            .create();
 
     private D declaredInstance;
     private E effectiveInstance;
 
+    private StatementContextBase<?, ?, ?> originalCtx;
+    private TypeOfCopy typeOfCopy = TypeOfCopy.ORIGINAL;
 
-    StatementContextBase(@Nonnull ContextBuilder<A, D, E> builder) throws SourceException {
+    @Override
+    public TypeOfCopy getTypeOfCopy() {
+        return typeOfCopy;
+    }
+
+    @Override
+    public void setTypeOfCopy(TypeOfCopy typeOfCopy) {
+        this.typeOfCopy = typeOfCopy;
+    }
+
+    @Override
+    public StatementContextBase<?, ?, ?> getOriginalCtx() {
+        return originalCtx;
+    }
+
+    @Override
+    public void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx) {
+        this.originalCtx = originalCtx;
+    }
+
+    @Override
+    public ModelProcessingPhase getCompletedPhase() {
+        return completedPhase;
+    }
+
+    @Override
+    public void setCompletedPhase(ModelProcessingPhase completedPhase) {
+        this.completedPhase = completedPhase;
+    }
+
+    StatementContextBase(@Nonnull ContextBuilder<A, D, E> builder)
+            throws SourceException {
         this.definition = builder.getDefinition();
         this.identifier = builder.getIdentifier();
         this.statementDeclSource = builder.getStamementSource();
         this.completedPhase = null;
     }
 
-    StatementContextBase(StatementContextBase<A,D,E> original) {
+    StatementContextBase(StatementContextBase<A, D, E> original) {
         this.definition = original.definition;
         this.identifier = original.identifier;
         this.statementDeclSource = original.statementDeclSource;
@@ -136,7 +180,6 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     @Override
     public abstract RootStatementContext<?, ?, ?> getRoot();
 
-
     @Override
     public StatementIdentifier getIdentifier() {
         return identifier;
@@ -167,42 +210,45 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return Collections.unmodifiableCollection(effective);
     }
 
-    public void addEffectiveSubstatement(StatementContextBase<?, ?, ?> substatement){
+    public void addEffectiveSubstatement(
+            StatementContextBase<?, ?, ?> substatement) {
         effective.add(substatement);
     }
 
-    public void addDeclaredSubstatement(StatementContextBase<?, ?, ?> substatement){
+    public void addDeclaredSubstatement(
+            StatementContextBase<?, ?, ?> substatement) {
         declared.add(substatement);
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public ContextBuilder<?, ?, ?> substatementBuilder(StatementDefinitionContext<?, ?, ?> def,
+    public ContextBuilder<?, ?, ?> substatementBuilder(
+            StatementDefinitionContext<?, ?, ?> def,
             StatementSourceReference ref) {
         return new ContextBuilder(def, ref) {
 
             @Override
             public StatementContextBase build() throws SourceException {
-                StatementContextBase<?, ?, ?> potential = substatements.get(getIdentifier());
-                if(potential == null) {
-                    potential = new SubstatementContext(StatementContextBase.this, this);
+                StatementContextBase<?, ?, ?> potential = substatements
+                        .get(getIdentifier());
+                if (potential == null) {
+                    potential = new SubstatementContext(
+                            StatementContextBase.this, this);
                     substatements.put(getIdentifier(), potential);
                 }
                 potential.resetLists();
                 switch (this.getStamementSource().getStatementSource()) {
-                    case DECLARATION:
-                        declared.add(potential);
-                        break;
-                    case CONTEXT:
-                        effective.add(potential);
-                        break;
+                case DECLARATION:
+                    declared.add(potential);
+                    break;
+                case CONTEXT:
+                    effective.add(potential);
+                    break;
                 }
                 return potential;
             }
         };
     }
 
-
-
     @Override
     public StorageNodeType getStorageNodeType() {
         return StorageNodeType.STATEMENT_LOCAL;
@@ -210,7 +256,9 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     @Override
     public D buildDeclared() {
-        Preconditions.checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+        Preconditions
+                .checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION
+                        || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         if (declaredInstance == null) {
             declaredInstance = definition().getFactory().createDeclared(this);
         }
@@ -219,52 +267,53 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     @Override
     public E buildEffective() {
-        Preconditions.checkArgument(completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         if (effectiveInstance == null) {
             effectiveInstance = definition().getFactory().createEffective(this);
         }
         return effectiveInstance;
     }
 
-
     void resetLists() {
         declared.clear();
     }
 
-    boolean tryToCompletePhase(ModelProcessingPhase phase) throws SourceException {
-        if(phase.equals(completedPhase)) {
-            return true;
-        }
-        Iterator<ContextMutation> openMutations = phaseMutation.get(phase).iterator();
+    boolean tryToCompletePhase(ModelProcessingPhase phase)
+            throws SourceException {
+        Iterator<ContextMutation> openMutations = phaseMutation.get(phase)
+                .iterator();
         boolean finished = true;
-        while(openMutations.hasNext()) {
+        while (openMutations.hasNext()) {
             ContextMutation current = openMutations.next();
-            if(current.isFinished()) {
+            if (current.isFinished()) {
                 openMutations.remove();
             } else {
                 finished = false;
             }
         }
-        for(StatementContextBase<?, ?, ?> child: declared) {
+        for (StatementContextBase<?, ?, ?> child : declared) {
             finished &= child.tryToCompletePhase(phase);
         }
-        for(StatementContextBase<?, ?, ?> child: effective) {
+        for (StatementContextBase<?, ?, ?> child : effective) {
             finished &= child.tryToCompletePhase(phase);
         }
-        if(finished) {
+
+        if (finished) {
             onPhaseCompleted(phase);
             return true;
         }
         return false;
     }
 
-
-    private void onPhaseCompleted(ModelProcessingPhase phase) throws SourceException {
+    private void onPhaseCompleted(ModelProcessingPhase phase)
+            throws SourceException {
         completedPhase = phase;
-        Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase).iterator();
-        while(listener.hasNext()) {
-            listener.next().phaseFinished(this, phase);
-            listener.remove();
+        Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase)
+                .iterator();
+        while (listener.hasNext()) {
+            OnPhaseFinished next = listener.next();
+            if(next.phaseFinished(this, phase)) {
+             listener.remove();
+            }
         }
     }
 
@@ -276,8 +325,9 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
      * @throws SourceException
      *
      */
-    void endDeclared(StatementSourceReference ref,ModelProcessingPhase phase) throws SourceException {
-        definition().onDeclarationFinished(this,phase);
+    void endDeclared(StatementSourceReference ref, ModelProcessingPhase phase)
+            throws SourceException {
+        definition().onDeclarationFinished(this, phase);
     }
 
     protected final StatementDefinitionContext<A, D, E> definition() {
@@ -285,29 +335,35 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    protected void checkLocalNamespaceAllowed(Class<? extends IdentifierNamespace<?, ?>> type) {
+    protected void checkLocalNamespaceAllowed(
+            Class<? extends IdentifierNamespace<?, ?>> type) {
         definition().checkNamespaceAllowed(type);
     }
 
     @Override
-    protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(Class<N> type, K key, V value) {
-        //definition().onNamespaceElementAdded(this, type, key, value);
+    protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(
+            Class<N> type, K key, V value) {
+        // definition().onNamespaceElementAdded(this, type, key, value);
     }
 
-    <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, K key, final OnNamespaceItemAdded listener) throws SourceException {
+    <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(
+            final Class<N> type, K key, final OnNamespaceItemAdded listener)
+            throws SourceException {
         Object potential = getFromNamespace(type, key);
-        if(potential != null) {
+        if (potential != null) {
             listener.namespaceItemAdded(this, type, key, potential);
             return;
         }
-        NamespaceBehaviour<K,V,N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
-        if(behaviour instanceof NamespaceBehaviourWithListeners) {
-            NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K,V,N>) behaviour;
+        NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry()
+                .getNamespaceBehaviour(type);
+        if (behaviour instanceof NamespaceBehaviourWithListeners) {
+            NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
             casted.addValueListener(key, new ValueAddedListener(this) {
                 @Override
                 void onValueAdded(Object key, Object value) {
                     try {
-                        listener.namespaceItemAdded(StatementContextBase.this, type, key, value);
+                        listener.namespaceItemAdded(StatementContextBase.this,
+                                type, key, value);
                     } catch (SourceException e) {
                         throw Throwables.propagate(e);
                     }
@@ -326,10 +382,11 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return getRoot().getSourceContext().newInferenceAction(phase);
     }
 
-    void addPhaseCompletedListener(ModelProcessingPhase phase, OnPhaseFinished listener) throws SourceException {
+    void addPhaseCompletedListener(ModelProcessingPhase phase,
+            OnPhaseFinished listener) throws SourceException {
         ModelProcessingPhase finishedPhase = completedPhase;
         while (finishedPhase != null) {
-            if(phase.equals(finishedPhase)) {
+            if (phase.equals(finishedPhase)) {
                 listener.phaseFinished(this, finishedPhase);
                 return;
             }
@@ -341,8 +398,9 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     void addMutation(ModelProcessingPhase phase, ContextMutation mutation) {
         ModelProcessingPhase finishedPhase = completedPhase;
         while (finishedPhase != null) {
-            if(phase.equals(finishedPhase)) {
-                throw new IllegalStateException("Mutation registered after phase was completed.");
+            if (phase.equals(finishedPhase)) {
+                throw new IllegalStateException(
+                        "Mutation registered after phase was completed.");
             }
             finishedPhase = finishedPhase.getPreviousPhase();
         }
@@ -350,8 +408,8 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public <K,KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
+    public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
             Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt) {
-        addContextToNamespace(namespace,(K) key, stmt);
+        addContextToNamespace(namespace, (K) key, stmt);
     }
 }
index 808518d9d84b4b58c5c858c0c4aaaea36364f86c..f921e13b2adb0cae97135ab46aec2e91488d1cbe 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.GroupingUtils;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import java.util.Collection;
@@ -20,43 +19,50 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-    extends StatementContextBase<A,D,E> {
+class SubstatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+        extends StatementContextBase<A, D, E> {
 
-    private final StatementContextBase<?,?,?> parent;
+    private final StatementContextBase<?, ?, ?> parent;
     private final A argument;
 
-    SubstatementContext(StatementContextBase<?,?,?> parent,ContextBuilder<A,D,E> builder) throws SourceException {
-        //super(builder,  builder.getDefinition().parseArgumentValue(parent, builder.getRawArgument()));
+    SubstatementContext(StatementContextBase<?, ?, ?> parent,
+            ContextBuilder<A, D, E> builder) throws SourceException {
         super(builder);
-        this.parent = Preconditions.checkNotNull(parent, "Parent must not be null");
-        this.argument =   builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
+        this.parent = Preconditions.checkNotNull(parent,
+                "Parent must not be null");
+        this.argument = builder.getDefinition().parseArgumentValue(this,
+                builder.getRawArgument());
     }
 
-    SubstatementContext(SubstatementContext<A,D,E> original, QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
+    SubstatementContext(SubstatementContext<A, D, E> original,
+            QNameModule newQNameModule,
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+            throws SourceException {
         super(original);
         this.parent = newParent;
 
-        if(newQNameModule != null && original.argument instanceof QName) {
+        if (newQNameModule != null && original.argument instanceof QName) {
             QName originalQName = (QName) original.argument;
-            this.argument =  (A) QName.create(newQNameModule,originalQName.getLocalName());
+            this.argument = (A) QName.create(newQNameModule,
+                    originalQName.getLocalName());
         } else {
             this.argument = original.argument;
         }
 
-        copyDeclaredStmts(original, newQNameModule);
+        copyDeclaredStmts(original, newQNameModule, typeOfCopy);
 
-        copyEffectiveStmts(original, newQNameModule);
+        copyEffectiveStmts(original, newQNameModule, typeOfCopy);
     }
 
     private void copyDeclaredStmts(SubstatementContext<A, D, E> original,
-            QNameModule newQNameModule) throws SourceException {
+            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+            throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
                 .declaredSubstatements();
         for (StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
             if (GroupingUtils.needToCopyByUses(stmtContext)) {
-                StatementContextBase<?, ?, ?> copy = stmtContext
-                        .createCopy(newQNameModule,this);
+                StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
+                        newQNameModule, this, typeOfCopy);
                 this.addEffectiveSubstatement(copy);
             } else if (GroupingUtils.isReusedByUses(stmtContext)) {
                 this.addEffectiveSubstatement(stmtContext);
@@ -65,13 +71,14 @@ class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveS
     }
 
     private void copyEffectiveStmts(SubstatementContext<A, D, E> original,
-            QNameModule newQNameModule) throws SourceException {
+            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+            throws SourceException {
         Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
                 .effectiveSubstatements();
         for (StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
             if (GroupingUtils.needToCopyByUses(stmtContext)) {
-                StatementContextBase<?, ?, ?> copy = stmtContext
-                        .createCopy(newQNameModule,this);
+                StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
+                        newQNameModule, this, typeOfCopy);
                 this.addEffectiveSubstatement(copy);
             } else if (GroupingUtils.isReusedByUses(stmtContext)) {
                 this.addEffectiveSubstatement(stmtContext);
@@ -80,7 +87,7 @@ class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveS
     }
 
     @Override
-    public StatementContextBase<?,?,?> getParentContext() {
+    public StatementContextBase<?, ?, ?> getParentContext() {
         return parent;
     }
 
@@ -99,15 +106,20 @@ class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveS
         return parent.getRoot();
     }
 
-
     @Override
     public A getStatementArgument() {
         return argument;
     }
 
     @Override
-    public StatementContextBase<A, D, E>  createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
-        return new SubstatementContext<>(this,newQNameModule, newParent);
+    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+            throws SourceException {
+        SubstatementContext<A, D, E> copy = new SubstatementContext<>(this,
+                newQNameModule, newParent, typeOfCopy);
+        copy.setTypeOfCopy(typeOfCopy);
+        copy.setOriginalCtx(this);
+        return copy;
     }
 
     @Override
@@ -117,5 +129,8 @@ class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveS
         return argumentsFromRoot;
     }
 
-
+    @Override
+    public boolean isRootContext() {
+        return false;
+    }
 }
index 54dd02353de6eef7e5ca57ee4dede45965284a56..43af34cde4d0452c3f3132204d304ac786551b2f 100644 (file)
@@ -7,13 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
-
 import java.util.Collection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import javax.annotation.Nonnull;
-
 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.AugmentStatement;
@@ -29,27 +26,37 @@ 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.AugmentEffectiveStatementImpl;
 
-public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
+public class AugmentStatementImpl extends
+        AbstractDeclaredStatement<SchemaNodeIdentifier> implements
+        AugmentStatement {
 
-    private static final Logger LOG = LoggerFactory.getLogger(AugmentStatementImpl.class);
+    private static final Logger LOG = LoggerFactory
+            .getLogger(AugmentStatementImpl.class);
 
-    protected AugmentStatementImpl(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
+    protected AugmentStatementImpl(
+            StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
+    public static class Definition
+            extends
+            AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.AUGMENT);
         }
 
         @Override
-        public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return SchemaNodeIdentifier.create(AugmentUtils.parseAugmentPath(ctx, value), Utils.isXPathAbsolute(value));
+        public SchemaNodeIdentifier parseArgumentValue(
+                StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+            return SchemaNodeIdentifier.create(
+                    AugmentUtils.parseAugmentPath(ctx, value),
+                    Utils.isXPathAbsolute(value));
         }
 
         @Override
-        public AugmentStatement createDeclared(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
+        public AugmentStatement createDeclared(
+                StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
             return new AugmentStatementImpl(ctx);
         }
 
@@ -64,31 +71,42 @@ public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeId
                 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
                 throws SourceException {
 
-            final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(EFFECTIVE_MODEL);
+            final ModelActionBuilder augmentAction = augmentNode
+                    .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
             final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
-                    .requiresCtx(augmentNode, ModelProcessingPhase.FULL_DECLARATION);
+                    .requiresCtx(augmentNode,
+                            ModelProcessingPhase.FULL_DECLARATION);
 
             augmentAction.apply(new ModelActionBuilder.InferenceAction() {
 
                 @Override
                 public void apply() throws InferenceException {
 
-                    final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils.getAugmentTargetCtx(augmentNode);
-                    final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq.get();
+                    final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
+                            .getAugmentTargetCtx(augmentNode);
+
+                    if (augmentTargetCtx == null) {
+                        throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
+                    }
+
+                    final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq
+                            .get();
 
                     try {
-                        AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
+                        AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
+                                augmentTargetCtx);
                     } catch (SourceException e) {
                         LOG.warn(e.getMessage(), e);
                     }
+
                 }
 
                 @Override
-                public void prerequisiteFailed(final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
+                public void prerequisiteFailed(
+                        final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
                         throws InferenceException {
-                    if (failed.contains(augmentAction)) {
-                        throw new InferenceException("Augment action failed", augmentNode.getStatementSourceReference());
-                    }
+                        throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
+                                augmentNode.getStatementSourceReference());
                 }
             });
         }
index 373ec1f40e78b894f4b0e12620c864e6c57c94d1..9d99af203aa5c8077996b7e58e1bddac95bebff6 100644 (file)
@@ -7,13 +7,16 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import java.util.Iterator;
+import javax.annotation.Nullable;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 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;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -38,7 +41,8 @@ public final class AugmentUtils {
     private AugmentUtils() {
     }
 
-    public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx, String path) {
+    public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx,
+            String path) {
 
         if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) {
             throw new IllegalArgumentException(
@@ -48,8 +52,9 @@ public final class AugmentUtils {
         return Utils.parseXPath(ctx, path);
     }
 
-    public static void copyFromSourceToTarget(StatementContextBase<?, ?, ?> sourceCtx,
-                                              StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
+    public static void copyFromSourceToTarget(
+            StatementContextBase<?, ?, ?> sourceCtx,
+            StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
 
         QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceCtx);
         copyDeclaredStmts(sourceCtx, targetCtx, newQNameModule);
@@ -57,12 +62,17 @@ public final class AugmentUtils {
 
     }
 
-    public static void copyDeclaredStmts(StatementContextBase<?, ?, ?> sourceCtx,
-                                         StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
-        Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceCtx.declaredSubstatements();
+    public static void copyDeclaredStmts(
+            StatementContextBase<?, ?, ?> sourceCtx,
+            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+            throws SourceException {
+        Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceCtx
+                .declaredSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
             if (needToCopyByAugment(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx
+                        .createCopy(newQNameModule, targetCtx,
+                                TypeOfCopy.ADDED_BY_AUGMENTATION);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByAugment(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -70,12 +80,17 @@ public final class AugmentUtils {
         }
     }
 
-    public static void copyEffectiveStmts(StatementContextBase<?, ?, ?> sourceCtx,
-                                          StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
-        Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceCtx.effectiveSubstatements();
+    public static void copyEffectiveStmts(
+            StatementContextBase<?, ?, ?> sourceCtx,
+            StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+            throws SourceException {
+        Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceCtx
+                .effectiveSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
             if (needToCopyByAugment(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx
+                        .createCopy(newQNameModule, targetCtx,
+                                TypeOfCopy.ADDED_BY_AUGMENTATION);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByAugment(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -83,13 +98,15 @@ public final class AugmentUtils {
         }
     }
 
-    public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
-                                                StatementContextBase<?, ?, ?> sourceCtx) {
+    public static QNameModule getNewQNameModule(
+            StatementContextBase<?, ?, ?> targetCtx,
+            StatementContextBase<?, ?, ?> sourceCtx) {
         Object targetStmtArgument = targetCtx.getStatementArgument();
 
         final StatementContextBase<?, ?, ?> root = sourceCtx.getRoot();
         final String moduleName = (String) root.getStatementArgument();
-        final QNameModule sourceQNameModule = root.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+        final QNameModule sourceQNameModule = root.getFromNamespace(
+                ModuleNameToModuleQName.class, moduleName);
 
         if (targetStmtArgument instanceof QName) {
             QName targetQName = (QName) targetStmtArgument;
@@ -127,58 +144,121 @@ public final class AugmentUtils {
     public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
             final Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
 
-        final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument();
+        final SchemaNodeIdentifier augmentTargetNode = augmentNode
+                .getStatementArgument();
+        if (augmentTargetNode == null) {
+            throw new IllegalArgumentException(
+                    "Augment argument null, something bad happened in some of previous parsing phases");
+        }
 
         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");
-            }
+            QNameModule module = augmentTargetNode.getPathFromRoot().iterator()
+                    .next().getModule();
 
-            StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(
-                    NamespaceToModule.class, module);
+            StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode
+                    .getFromNamespace(NamespaceToModule.class, module);
             rootStatementCtxList.add(rootStatementCtx);
 
-            final Map<?, ?> subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class);
+            final Map<?, ?> subModules = rootStatementCtx
+                    .getAllFromNamespace(IncludedModuleContext.class);
             if (subModules != null) {
-                rootStatementCtxList.addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules.values());
+                rootStatementCtxList
+                        .addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules
+                                .values());
             }
 
         } else {
-            StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode.getParentContext();
+            StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode
+                    .getParentContext();
             if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) {
                 rootStatementCtxList.add(parent.getParentContext());
             } else {
-                //error
+                // error
             }
         }
 
-        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;
+            augmentTargetCtx = findCtxOfNodeInRoot(rootStatementCtx,
+                    augmentTargetNode);
+            if (augmentTargetCtx != null)
+                break;
+        }
+
+        return augmentTargetCtx;
+    }
+
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
+            StatementContextBase<?, ?, ?> rootStmtCtx,
+            final Iterable<QName> path) {
+
+        StatementContextBase<?, ?, ?> parent = rootStmtCtx;
+
+        Iterator<QName> pathIter = path.iterator();
+        while (pathIter.hasNext()) {
+            QName nextPathQName = pathIter.next();
+            StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(
+                    parent, nextPathQName);
+
+            if (foundSubstatement == null) {
+                return null;
+            }
+            if (!pathIter.hasNext()) {
+                return foundSubstatement;
+            }
+
+            parent = foundSubstatement;
         }
 
+        return null;
+    }
+
+    public static StatementContextBase<?, ?, ?> getSubstatementByQName(
+            StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
 
-        if (augmentTargetCtx == null) {
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
+                .declaredSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
+                .effectiveSubstatements();
 
-            throw new NullPointerException(String.format(
-                    "Augment path %s not found in target model so its resulting context is null",
-                    augmentNode.rawStatementArgument()));
+        Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
+        allSubstatements.addAll(declaredSubstatement);
+        allSubstatements.addAll(effectiveSubstatement);
 
+        for (StatementContextBase<?, ?, ?> substatement : allSubstatements) {
+            if (isAllowedAugmentTarget(substatement)
+                    && nextPathQName
+                            .equals(substatement.getStatementArgument())) {
+                return substatement;
+            }
         }
 
-        return augmentTargetCtx;
+        return null;
+    }
+
+    public static boolean isAllowedAugmentTarget(
+            StatementContextBase<?, ?, ?> substatement) {
+
+        /*
+         * :TODO Substatement must be allowed augment target type e.g.
+         * Container, etc... and must be not for example grouping, identity etc.
+         * It is problem in case when more than one substatements have the same
+         * QName, for example Grouping and Container are siblings and they have the
+         * same QName. We must find the Container and the Grouping must be ignored
+         * as disallowed augment target.
+         */
+
+        return true;
+    }
+
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(
+            StatementContextBase<?, ?, ?> rootStmtCtx,
+            final SchemaNodeIdentifier node) {
+        return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot());
     }
 }
index 56755e411c02d4a821a22706c820b8adfe69bfff..5186596ad14d263dfc0cb9bdca7863fe6912e19e 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviateEffectiveStatementImpl;
 
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -16,39 +17,41 @@ 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;
 
-public class DeviateStatementImpl extends AbstractDeclaredStatement<String> implements DeviateStatement {
+public class DeviateStatementImpl extends AbstractDeclaredStatement<Deviation.Deviate> implements DeviateStatement {
 
     protected DeviateStatementImpl(
-            StmtContext<String, DeviateStatement, ?> context) {
+            StmtContext<Deviation.Deviate, DeviateStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition extends AbstractStatementSupport<String,DeviateStatement,EffectiveStatement<String,DeviateStatement>> {
+    public static class Definition extends AbstractStatementSupport<Deviation.Deviate,DeviateStatement,EffectiveStatement<Deviation.Deviate,DeviateStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.DEVIATE);
         }
 
-        @Override public String parseArgumentValue(
+        @Override public Deviation.Deviate parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return value;
+            return Utils.parseDeviateFromString(value);
         }
 
         @Override public DeviateStatement createDeclared(
-                StmtContext<String, DeviateStatement, ?> ctx) {
+                StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
             return new DeviateStatementImpl(ctx);
         }
 
-        @Override public EffectiveStatement<String, DeviateStatement> createEffective(
-                StmtContext<String, DeviateStatement, EffectiveStatement<String, DeviateStatement>> ctx) {
+        @Override public EffectiveStatement<Deviation.Deviate, DeviateStatement> createEffective(
+                StmtContext<Deviation.Deviate, DeviateStatement, EffectiveStatement<Deviation.Deviate, DeviateStatement>> ctx) {
             return new DeviateEffectiveStatementImpl(ctx);
         }
+
     }
 
     @Nonnull @Override
-    public String getValue() {
-        return rawArgument();
+    public Deviation.Deviate getValue() {
+        return argument();
     }
 }
index c1194deec5e3749eeebd0627a2a5f811252e681b..9802db52b3b520c2d745005b46c46a1679d46f27 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -51,7 +53,7 @@ public final class GroupingUtils {
                 .declaredSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
             if (needToCopyByUses(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx, TypeOfCopy.ADDED_BY_USES);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByUses(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -65,7 +67,7 @@ public final class GroupingUtils {
                 .effectiveSubstatements();
         for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
             if (needToCopyByUses(originalStmtCtx)) {
-                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+                StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx, TypeOfCopy.ADDED_BY_USES);
                 targetCtx.addEffectiveSubstatement(copy);
             } else if (isReusedByUses(originalStmtCtx)) {
                 targetCtx.addEffectiveSubstatement(originalStmtCtx);
@@ -76,6 +78,9 @@ public final class GroupingUtils {
     public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
             StmtContext<?, ?, ?> stmtContext) {
         if (needToCreateNewQName(stmtContext.getPublicDefinition())) {
+            if(targetCtx.isRootContext()) {
+                return targetCtx.getFromNamespace(ModuleNameToModuleQName.class, targetCtx.rawStatementArgument());
+            }
             Object targetStmtArgument = targetCtx.getStatementArgument();
             Object sourceStmtArgument = stmtContext.getStatementArgument();
             if (targetStmtArgument instanceof QName && sourceStmtArgument instanceof QName) {
@@ -127,7 +132,7 @@ public final class GroupingUtils {
         Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = usesNode.declaredSubstatements();
         for (StatementContextBase<?, ?, ?> subStmtCtx : declaredSubstatements) {
             if (StmtContextUtils.producesDeclared(subStmtCtx, WhenStatement.class)) {
-                StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(null, targetNodeStmtCtx);
+                StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(null, targetNodeStmtCtx, TypeOfCopy.ADDED_BY_USES);
                 targetNodeStmtCtx.addEffectiveSubstatement(copy);
             }
             if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)) {
index 70effef3906ca37ae4656323a829ad26a2cbd699..509f462975a472ea637abd52217f358b39c4d7bf 100644 (file)
@@ -90,7 +90,7 @@ public class IncludeStatementImpl extends AbstractDeclaredStatement<String> impl
                 @Override
                 public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
                     if (failed.contains(requiresCtxPrerequisite)) {
-                        throw new InferenceException("Included submodule was not found.", stmt
+                        throw new InferenceException("Included submodule was not found: "+stmt.getStatementArgument(), stmt
                                 .getStatementSourceReference());
                     }
                 }
index ff306a55e47c750e957a674a03a80e17a7057f54..19f77ecd0ebac6580b54654a60fe6d3188a1ea8d 100644 (file)
@@ -28,19 +28,17 @@ 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.parser.stmt.rfc6020.effective.SubmoduleEffectiveStatementImpl;
 
 import com.google.common.base.Optional;
 
-public class SubmoduleStatementImpl extends
-        AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
+public class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
 
-    protected SubmoduleStatementImpl(
-            StmtContext<String, SubmoduleStatement, ?> context) {
+    protected SubmoduleStatementImpl(StmtContext<String, SubmoduleStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition
-            extends
+    public static class Definition extends
             AbstractStatementSupport<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> {
 
         public Definition() {
@@ -53,15 +51,14 @@ public class SubmoduleStatementImpl extends
         }
 
         @Override
-        public SubmoduleStatement createDeclared(
-                StmtContext<String, SubmoduleStatement, ?> ctx) {
+        public SubmoduleStatement createDeclared(StmtContext<String, SubmoduleStatement, ?> ctx) {
             return new SubmoduleStatementImpl(ctx);
         }
 
         @Override
         public EffectiveStatement<String, SubmoduleStatement> createEffective(
                 StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
-            throw new UnsupportedOperationException();
+            return new SubmoduleEffectiveStatementImpl(ctx);
         }
 
         @Override
@@ -69,33 +66,27 @@ public class SubmoduleStatementImpl extends
                 Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt)
                 throws SourceException {
 
-            Optional<Date> revisionDate = Optional
-                    .fromNullable(firstAttributeOf(
-                            stmt.declaredSubstatements(),
-                            RevisionStatement.class));
+            Optional<Date> revisionDate = Optional.fromNullable(firstAttributeOf(stmt.declaredSubstatements(),
+                    RevisionStatement.class));
 
-            ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl(
-                    stmt.getStatementArgument(), Optional.<URI> absent(),
-                    revisionDate);
+            ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl(stmt.getStatementArgument(),
+                    Optional.<URI> absent(), revisionDate);
 
             stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
 
-            String belongsToModuleName = firstAttributeOf(
-                    stmt.declaredSubstatements(), BelongsToStatement.class);
-            StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(
-                    stmt, 0, BelongsToStatement.class, PrefixStatement.class);
+            String belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(), BelongsToStatement.class);
+            StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(stmt, 0, BelongsToStatement.class,
+                    PrefixStatement.class);
 
-            if(prefixSubStmtCtx == null) {
+            if (prefixSubStmtCtx == null) {
                 throw new IllegalArgumentException("Prefix of belongsTo statement is missing in submodule ["
                         + stmt.getStatementArgument() + "].");
             }
 
             String prefix = (String) prefixSubStmtCtx.getStatementArgument();
 
-            stmt.addToNs(BelongsToPrefixToModuleName.class, prefix,
-                    belongsToModuleName);
+            stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
         }
-
     }
 
     @Override
index 3a62cfaab6272d4f826f35c20797cc36ba465a46..d55f99dedadace890ab11d320d9a7d16b428fc5d 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
+import java.util.Collection;
+
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -23,6 +25,7 @@ import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.antlr.v4.runtime.tree.TerminalNode;
@@ -51,7 +54,8 @@ public final class 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 CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher
+            .is('\'');
 
     private static final char SEPARATOR_NODENAME = '/';
 
@@ -62,7 +66,8 @@ public final class Utils {
 
     public static List<String> splitPathToNodeNames(String path) {
 
-        Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
+        Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME)
+                .omitEmptyStrings().trimResults();
         return keySplitter.splitToList(path);
     }
 
@@ -73,7 +78,8 @@ public final class Utils {
         try {
             xPath.compile(path);
         } catch (XPathExpressionException e) {
-            throw new IllegalArgumentException("Argument is not valid XPath string", e);
+            throw new IllegalArgumentException(
+                    "Argument is not valid XPath string", e);
         }
     }
 
@@ -96,8 +102,8 @@ public final class Utils {
         return identifier;
     }
 
-    public static boolean isValidStatementDefinition(PrefixToModule prefixes, QNameToStatementDefinition stmtDef,
-            QName identifier) {
+    public static boolean isValidStatementDefinition(PrefixToModule prefixes,
+            QNameToStatementDefinition stmtDef, QName identifier) {
         if (stmtDef.get(identifier) != null) {
             return true;
         } else {
@@ -107,8 +113,12 @@ public final class Utils {
             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) {
+                if (prefixes != null
+                        && prefixes.get(prefix) != null
+                        && stmtDef
+                                .get(new QName(
+                                        YangConstants.RFC6020_YIN_NAMESPACE,
+                                        localName)) != null) {
                     return true;
                 }
             }
@@ -116,7 +126,8 @@ public final class Utils {
         return false;
     }
 
-    public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
+    public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx,
+            String path) {
 
         validateXPath(path);
 
@@ -135,7 +146,8 @@ public final class Utils {
         return qNames;
     }
 
-    public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
+    public static String stringFromStringContext(
+            final YangStatementParser.ArgumentContext context) {
         StringBuilder sb = new StringBuilder();
         List<TerminalNode> strings = context.STRING();
         if (strings.isEmpty()) {
@@ -174,27 +186,38 @@ public final class Utils {
         case 1:
             localName = namesParts[0];
 
-            if (StmtContextUtils.producesDeclared(ctx.getRoot(), ModuleStatement.class)) {
-                prefix = firstAttributeOf(ctx.getRoot().declaredSubstatements(), PrefixStatement.class);
-                qNameModule = ctx.getFromNamespace(PrefixToModule.class, prefix);
-
-            } else if (StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
-                String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(),
-                        BelongsToStatement.class);
-                qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
+            if (StmtContextUtils.producesDeclared(ctx.getRoot(),
+                    ModuleStatement.class)) {
+                prefix = firstAttributeOf(
+                        ctx.getRoot().declaredSubstatements(),
+                        PrefixStatement.class);
+                qNameModule = ctx
+                        .getFromNamespace(PrefixToModule.class, prefix);
+
+            } else if (StmtContextUtils.producesDeclared(ctx.getRoot(),
+                    SubmoduleStatement.class)) {
+                String belongsToModuleName = firstAttributeOf(ctx.getRoot()
+                        .declaredSubstatements(), BelongsToStatement.class);
+                qNameModule = ctx.getFromNamespace(
+                        ModuleNameToModuleQName.class, belongsToModuleName);
             }
             break;
         case 2:
             prefix = namesParts[0];
             localName = namesParts[1];
 
-            ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(ImpPrefixToModuleIdentifier.class,
-                    prefix);
-            qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class, impModIdentifier);
-
-            if (qNameModule == null && StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
-                String moduleName = ctx.getRoot().getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
-                qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+            ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(
+                    ImpPrefixToModuleIdentifier.class, prefix);
+            qNameModule = ctx.getFromNamespace(
+                    ModuleIdentifierToModuleQName.class, impModIdentifier);
+
+            if (qNameModule == null
+                    && StmtContextUtils.producesDeclared(ctx.getRoot(),
+                            SubmoduleStatement.class)) {
+                String moduleName = ctx.getRoot().getFromNamespace(
+                        BelongsToPrefixToModuleName.class, prefix);
+                qNameModule = ctx.getFromNamespace(
+                        ModuleNameToModuleQName.class, moduleName);
             }
 
             break;
@@ -206,78 +229,63 @@ public final class Utils {
     }
 
     @Nullable
-    private static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
-            StatementContextBase<?, ?, ?> rootStmtCtx, final Iterable<QName> path, boolean searchInEffective) {
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
+            StatementContextBase<?, ?, ?> rootStmtCtx,
+            final Iterable<QName> path) {
 
         StatementContextBase<?, ?, ?> parent = rootStmtCtx;
 
         Iterator<QName> pathIter = path.iterator();
-        QName targetNode = pathIter.next();
-
         while (pathIter.hasNext()) {
+            QName nextPathQName = pathIter.next();
+            StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(
+                    parent, nextPathQName);
 
-            for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
-                    .declaredSubstatements()) {
-
-                if (targetNode.equals(child.getStatementArgument())) {
-                    parent = child;
-                    targetNode = pathIter.next();
-                }
-            }
-
-            if (parent.equals(rootStmtCtx)) {
-
+            if (foundSubstatement == null) {
                 return null;
             }
-        }
-
-        StatementContextBase<?, ?, ?> targetCtx = null;
-
-        for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
-                .declaredSubstatements()) {
-
-            if (targetNode.equals(child.getStatementArgument())) {
-                targetCtx = child;
+            if (!pathIter.hasNext()) {
+                return foundSubstatement;
             }
+
+            parent = foundSubstatement;
         }
 
-        return targetCtx;
+        return null;
     }
 
-    @Nullable
-    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
-            final SchemaNodeIdentifier node) {
+    public static StatementContextBase<?, ?, ?> getSubstatementByQName(
+            StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
 
-        System.out.println(node.getPathFromRoot());
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
+                .declaredSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
+                .effectiveSubstatements();
 
-        StatementContextBase<?, ?, ?> targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(),
-                false);
+        Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
+        allSubstatements.addAll(declaredSubstatement);
+        allSubstatements.addAll(effectiveSubstatement);
 
-        if (targetCtx == null) {
-
-            targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(), true);
+        for (StatementContextBase<?, ?, ?> substatement : allSubstatements) {
+            if (nextPathQName.equals(substatement.getStatementArgument())) {
+                return substatement;
+            }
         }
 
-        return targetCtx;
+        return null;
     }
 
     @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 StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(
+            StatementContextBase<?, ?, ?> rootStmtCtx,
+            final SchemaNodeIdentifier node) {
+        return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot());
     }
 
     public static SchemaPath getSchemaPath(StmtContext<?, ?, ?> ctx) {
 
-        Iterator<Object> argumentsIterator = ctx.getArgumentsFromRoot().iterator();
+        Iterator<Object> argumentsIterator = ctx.getArgumentsFromRoot()
+                .iterator();
         argumentsIterator.next(); // skip root argument
 
         List<QName> qNamesFromRoot = new LinkedList<>();
@@ -294,4 +302,19 @@ public final class Utils {
 
         return SchemaPath.create(qNamesFromRoot, true);
     }
+
+    public static Deviation.Deviate parseDeviateFromString(final String deviate) {
+        if ("not-supported".equals(deviate)) {
+            return Deviation.Deviate.NOT_SUPPORTED;
+        } else if ("add".equals(deviate)) {
+            return Deviation.Deviate.ADD;
+        } else if ("replace".equals(deviate)) {
+            return Deviation.Deviate.REPLACE;
+        } else if ("delete".equals(deviate)) {
+            return Deviation.Deviate.DELETE;
+        } else {
+            throw new IllegalArgumentException(
+                    "String %s is not valid deviate argument");
+        }
+    }
 }
index 87bfe2b3f4f9bb5cbf5cd261cebcfcb7876057db..933cf31f40652664160e89331baf2ef3e74350fa 100644 (file)
@@ -11,41 +11,36 @@ 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 java.util.Map;
 
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
-import com.google.common.collect.ImmutableMap;
-import java.util.Map;
 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 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.BelongsToPrefixToModuleName;
+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.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 
+import com.google.common.collect.ImmutableMap;
+
 public final class YangInferencePipeline {
 
     public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle.builder()
-            .addSupport(new ModuleStatementSupport())
-            .addSupport(new SubmoduleStatementImpl.Definition())
-            .addSupport(new NamespaceStatementImpl.Definition())
-            .addSupport(new ImportStatementDefinition())
-            .addSupport(new IncludeStatementImpl.Definition())
-            .addSupport(new PrefixStatementImpl.Definition())
+            .addSupport(new ModuleStatementSupport()).addSupport(new SubmoduleStatementImpl.Definition())
+            .addSupport(new NamespaceStatementImpl.Definition()).addSupport(new ImportStatementDefinition())
+            .addSupport(new IncludeStatementImpl.Definition()).addSupport(new PrefixStatementImpl.Definition())
             .addSupport(new YangVersionStatementImpl.Definition())
-            .addSupport(new DescriptionStatementImpl.Definition())
-            .addSupport(new RevisionStatementImpl.Definition())
-            .addSupport(new RevisionDateStatementImpl.Definition())
-            .addSupport(new ReferenceStatementImpl.Definition())
-            .addSupport(new ContactStatementImpl.Definition())
-            .addSupport(new OrganizationStatementImpl.Definition())
+            .addSupport(new DescriptionStatementImpl.Definition()).addSupport(new RevisionStatementImpl.Definition())
+            .addSupport(new RevisionDateStatementImpl.Definition()).addSupport(new ReferenceStatementImpl.Definition())
+            .addSupport(new ContactStatementImpl.Definition()).addSupport(new OrganizationStatementImpl.Definition())
             .addSupport(new BelongsToStatementImpl.Definition())
             .addSupport(global(ModuleNamespace.class))
             .addSupport(global(SubmoduleNamespace.class))
@@ -58,19 +53,14 @@ public final class YangInferencePipeline {
             .addSupport(sourceLocal(IncludedModuleContext.class))
             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
-            .addSupport(sourceLocal(QNameToStatementDefinition.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())
-            .addSupport(global(ExtensionNamespace.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()).addSupport(global(ExtensionNamespace.class)).build();
 
-    private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.
-            derivedFrom(STMT_DEF_BUNDLE)
+    private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
+            .derivedFrom(STMT_DEF_BUNDLE)
             .addSupport(new ContainerStatementImpl.Definition())
             .addSupport(new LeafStatementImpl.Definition())
             .addSupport(new TypeStatementImpl.Definition())
@@ -87,62 +77,48 @@ public final class YangInferencePipeline {
             .addSupport(new IfFeatureStatementImpl.Definition())
             .addSupport(new UsesStatementImpl.Definition())
             .addSupport(new GroupingStatementImpl.Definition())
-            .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
-            .addSupport(new StatusStatementImpl.Definition())
-            .addSupport(new ErrorMessageStatementImpl.Definition())
-            .addSupport(new ErrorAppTagStatementImpl.Definition())
-            .addSupport(new LeafListStatementImpl.Definition())
-            .addSupport(new ListStatementImpl.Definition())
-            .addSupport(new PresenceStatementImpl.Definition())
-            .addSupport(new KeyStatementImpl.Definition())
-            .addSupport(new MaxElementsStatementImpl.Definition())
-            .addSupport(new MinElementsStatementImpl.Definition())
-            .addSupport(new OrderedByStatementImpl.Definition())
-            .addSupport(new WhenStatementImpl.Definition())
-            .addSupport(new AugmentStatementImpl.Definition())
-            .addSupport(new RefineStatementImpl.Definition())
-            .addSupport(new IdentityStatementImpl.Definition())
-            .addSupport(new BaseStatementImpl.Definition())
-            .addSupport(new FractionDigitsStatementImpl.Definition())
-            .addSupport(new EnumStatementImpl.Definition())
-            .addSupport(new FeatureStatementImpl.Definition())
-            .addSupport(new RpcStatementImpl.Definition())
-            .addSupport(new InputStatementImpl.Definition())
-            .addSupport(new OutputStatementImpl.Definition())
-            .addSupport(new LengthStatementImpl.Definition())
-            .addSupport(new NotificationStatementImpl.Definition())
-            .addSupport(new PatternStatementImpl.Definition())
-            .addSupport(new PositionStatementImpl.Definition())
-            .addSupport(new RangeStatementImpl.Definition())
-            .addSupport(new ValueStatementImpl.Definition())
-            .addSupport(new UnitsStatementImpl.Definition())
+            .addSupport(treeScoped(GroupingNamespace.class))
+            // treeScoped
+            .addSupport(new StatusStatementImpl.Definition()).addSupport(new ErrorMessageStatementImpl.Definition())
+            .addSupport(new ErrorAppTagStatementImpl.Definition()).addSupport(new LeafListStatementImpl.Definition())
+            .addSupport(new ListStatementImpl.Definition()).addSupport(new PresenceStatementImpl.Definition())
+            .addSupport(new KeyStatementImpl.Definition()).addSupport(new MaxElementsStatementImpl.Definition())
+            .addSupport(new MinElementsStatementImpl.Definition()).addSupport(new OrderedByStatementImpl.Definition())
+            .addSupport(new WhenStatementImpl.Definition()).addSupport(new AugmentStatementImpl.Definition())
+            .addSupport(new RefineStatementImpl.Definition()).addSupport(new IdentityStatementImpl.Definition())
+            .addSupport(new BaseStatementImpl.Definition()).addSupport(new FractionDigitsStatementImpl.Definition())
+            .addSupport(new EnumStatementImpl.Definition()).addSupport(new FeatureStatementImpl.Definition())
+            .addSupport(new RpcStatementImpl.Definition()).addSupport(new InputStatementImpl.Definition())
+            .addSupport(new OutputStatementImpl.Definition()).addSupport(new LengthStatementImpl.Definition())
+            .addSupport(new NotificationStatementImpl.Definition()).addSupport(new PatternStatementImpl.Definition())
+            .addSupport(new PositionStatementImpl.Definition()).addSupport(new RangeStatementImpl.Definition())
+            .addSupport(new ValueStatementImpl.Definition()).addSupport(new UnitsStatementImpl.Definition())
             .addSupport(new RequireInstanceStatementImpl.Definition())
-            //TODO: add mapping to Rfc6020Mapping class and uncomment following. Please test it.
-//            .addSupport(new EnumSpecificationImpl.Definition())
-//            .addSupport(new Decimal64SpecificationImpl.Definition())
-//            .addSupport(new IdentityRefSpecificationImpl.Definition())
-//            .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
-//            .addSupport(new LeafrefSpecificationImpl.Definition())
-//            .addSupport(new NumericalRestrictionsImpl.Definition())
-//            .addSupport(new StringRestrictionsImpl.Definition())
-//            .addSupport(new UnionSpecificationImpl.Definition())
-//            .addSupport(new BitStatementImpl.Definition())
+            // TODO: add mapping to Rfc6020Mapping class and uncomment
+            // following. Please test it.
+            // .addSupport(new EnumSpecificationImpl.Definition())
+            // .addSupport(new Decimal64SpecificationImpl.Definition())
+            // .addSupport(new IdentityRefSpecificationImpl.Definition())
+            // .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
+            // .addSupport(new LeafrefSpecificationImpl.Definition())
+            // .addSupport(new NumericalRestrictionsImpl.Definition())
+            // .addSupport(new StringRestrictionsImpl.Definition())
+            // .addSupport(new UnionSpecificationImpl.Definition())
+            // .addSupport(new BitStatementImpl.Definition())
             .build();
 
     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
             .<ModelProcessingPhase, StatementSupportBundle> builder()
             .put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
-            .put(ModelProcessingPhase.STATEMENT_DEFINITION,STMT_DEF_BUNDLE)
-            .put(ModelProcessingPhase.FULL_DECLARATION,FULL_DECL_BUNDLE)
-            .put(ModelProcessingPhase.EFFECTIVE_MODEL,FULL_DECL_BUNDLE)
-            .build();
+            .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
+            .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
+            .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE).build();
 
     public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor.builder()
             .setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
-            .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,STMT_DEF_BUNDLE)
-            .setBundle(ModelProcessingPhase.FULL_DECLARATION,FULL_DECL_BUNDLE)
-            .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL,FULL_DECL_BUNDLE)
-            .build();
+            .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
+            .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
+            .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE).build();
 
     private YangInferencePipeline() {
         throw new UnsupportedOperationException("Utility class");
index 85a5e63d3e4c30b37cd02f436689336efbab79f8..07e503e76b4a35888d5a26d783e515114eb64ea4 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.LinkedList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
@@ -44,6 +46,25 @@ public class AnyXmlEffectiveStatementImpl extends
         this.path = Utils.getSchemaPath(ctx);
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index e748a3e9ee4288d9e72159592357dd43e860a979..50fb528446527c05441950faa092799df4bc583d 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
@@ -50,6 +51,25 @@ public class CaseEffectiveStatementImpl extends
         // :TODO init other fields
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index d74600e37d7b383f565af34968bc225e2f29182e..7c36706d07b3cb0aace0088468f6a7a40f085e51 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
@@ -52,7 +53,25 @@ public class ChoiceEffectiveStatementImpl extends AbstractEffectiveDocumentedNod
         //:TODO init other fields
 
         initSubstatementCollections();
-
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index b9501f7c1e7d77e63ef84d9cc1bc4d626d2ea33c..7cb1b79a546473e738bb59014bcc8a61e00f502b 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import java.util.HashSet;
@@ -31,15 +32,16 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 public class ContainerEffectiveStatementImpl extends
         AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
         implements ContainerSchemaNode, DerivableSchemaNode {
+
     private final QName qname;
     private final SchemaPath path;
-    private final boolean presence;
 
-    boolean augmenting;
-    boolean addedByUses;
-    boolean configuration;
-    ContainerSchemaNode original;
-    ConstraintDefinition constraints;
+    private boolean presence;
+    private boolean augmenting;
+    private boolean addedByUses;
+    private boolean configuration;
+    private ContainerSchemaNode original;
+    private ConstraintDefinition constraints;
 
     private ImmutableSet<AugmentationSchema> augmentations;
     private ImmutableList<UnknownSchemaNode> unknownNodes;
@@ -50,28 +52,52 @@ public class ContainerEffectiveStatementImpl extends
 
         qname = ctx.getStatementArgument();
         path = Utils.getSchemaPath(ctx);
-        presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
-                : true;
+
+        initCopyType(ctx);
+        initFields();
         // :TODO init other fields
+    }
 
-        initSubstatementCollections();
+    private void initCopyType(
+            StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
-    private void initSubstatementCollections() {
+    private void initFields() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
-        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
-            if (effectiveStatement instanceof UnknownSchemaNode) {
-                UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+        for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
+            if (effectiveSubstatement instanceof UnknownSchemaNode) {
+                UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
                 unknownNodesInit.add(unknownNode);
             }
-            if (effectiveStatement instanceof AugmentationSchema) {
-                AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
+            if (effectiveSubstatement instanceof AugmentationSchema) {
+                AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
                 augmentationsInit.add(augmentationSchema);
             }
+            if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
+                presence = true;
+            }
+            if (effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
+                ConfigEffectiveStatementImpl config = (ConfigEffectiveStatementImpl) effectiveSubstatement;
+                this.configuration = config.argument();
+            }
         }
 
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
index 2528b6d901a4ed4c2b467a7742ca0d31e8928326..6365a71552387f0312718cbc70df80b828b512b9 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 public class DeviateEffectiveStatementImpl extends
-        EffectiveStatementBase<String, DeviateStatement> {
+        EffectiveStatementBase<Deviation.Deviate, DeviateStatement> {
     public DeviateEffectiveStatementImpl(
-            StmtContext<String, DeviateStatement, ?> ctx) {
+            StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
         super(ctx);
     }
 }
\ No newline at end of file
index c424b9e151814b9a6c5f0b2a3af8c81718d545af..66a19f22ab3504e883ed27da28a451c5b9256e46 100644 (file)
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import java.util.LinkedList;
+import java.util.List;
+
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-public class DeviationEffectiveStatementImpl extends
-        EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement> {
+import com.google.common.collect.ImmutableList;
+
+public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+        implements Deviation, Immutable {
+
+    private SchemaPath targetPath;
+    private Deviate deviate;
+    private String reference;
+    private ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
 
-    public DeviationEffectiveStatementImpl(
-            StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+    public DeviationEffectiveStatementImpl(StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
         super(ctx);
 
+        List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
+
+        targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
+                .isAbsolute());
+
+        for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+            if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
+                deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
+                reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof UnknownSchemaNode) {
+                unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
+            }
+        }
+
+        unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
+    }
+
+    @Override
+    public SchemaPath getTargetPath() {
+        return targetPath;
+    }
+
+    @Override
+    public Deviate getDeviate() {
+        return deviate;
     }
 
+    @Override
+    public String getReference() {
+        return reference;
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownSchemaNodes;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
+        result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
+        if (targetPath == null) {
+            if (other.targetPath != null) {
+                return false;
+            }
+        } else if (!targetPath.equals(other.targetPath)) {
+            return false;
+        }
+        if (deviate == null) {
+            if (other.deviate != null) {
+                return false;
+            }
+        } else if (!deviate.equals(other.deviate)) {
+            return false;
+        }
+        if (reference == null) {
+            if (other.reference != null) {
+                return false;
+            }
+        } else if (!reference.equals(other.reference)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
+        sb.append("[");
+        sb.append("targetPath=").append(targetPath);
+        sb.append(", deviate=").append(deviate);
+        sb.append(", reference=").append(reference);
+        sb.append("]");
+        return sb.toString();
+    }
 }
\ No newline at end of file
index 7eaae54024826c854d30c7dd1b7a6d01b5530c3a..d322c22a7d82d76efa02a4f29e9faa8469bbd12a 100644 (file)
@@ -7,14 +7,99 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import java.util.Date;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-public class ImportEffectiveStatementImpl extends
-        EffectiveStatementBase<String, ImportStatement> {
+public class ImportEffectiveStatementImpl extends EffectiveStatementBase<String, ImportStatement> implements
+        ModuleImport {
+
+    private String moduleName;
+    private Date revision;
+    private String prefix;
 
-    public ImportEffectiveStatementImpl(
-            StmtContext<String, ImportStatement, ?> ctx) {
+    public ImportEffectiveStatementImpl(StmtContext<String, ImportStatement, ?> ctx) {
         super(ctx);
+
+        moduleName = ctx.getStatementArgument();
+
+        for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+            if (effectiveStatement instanceof RevisionEffectiveStatementImpl) {
+                revision = ((RevisionEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+                prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+            }
+        }
+    }
+
+    @Override
+    public String getModuleName() {
+        return moduleName;
+    }
+
+    @Override
+    public Date getRevision() {
+        return revision;
+    }
+
+    @Override
+    public String getPrefix() {
+        return prefix;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode());
+        result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+        result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj;
+        if (getModuleName() == null) {
+            if (other.getModuleName() != null) {
+                return false;
+            }
+        } else if (!getModuleName().equals(other.getModuleName())) {
+            return false;
+        }
+        if (getRevision() == null) {
+            if (other.getRevision() != null) {
+                return false;
+            }
+        } else if (!getRevision().equals(other.getRevision())) {
+            return false;
+        }
+        if (getPrefix() == null) {
+            if (other.getPrefix() != null) {
+                return false;
+            }
+        } else if (!getPrefix().equals(other.getPrefix())) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return ImportEffectiveStatementImpl.class.getSimpleName() + "[moduleName=" + moduleName + ", revision="
+                + revision + ", prefix=" + prefix + "]";
     }
 }
index e0ded9ec84b9068079599de01bac77927d4aec3b..03f1daf92892dcc0fc0211a4b8234ed6277cf876 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.HashSet;
 import java.util.LinkedList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.List;
@@ -54,6 +55,27 @@ public class InputEffectiveStatementImpl extends
         // :TODO init other fields
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index 3d59091cc528622e678dafe9b867c64fcd6fd6cc..37980b55757b646d298f8e468f61eb379757d273 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.LinkedList;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -50,6 +51,25 @@ public class LeafEffectiveStatementImpl extends
         // :TODO init other fields
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index 77487441e4167aa4ddc4c638922362d7f6c3f529..afb24b4d3306fcf27b7ff453e187297b6feb34fd 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.Collection;
 import java.util.LinkedList;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -25,7 +26,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 
-public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements LeafListSchemaNode, DerivableSchemaNode {
+public class LeafListEffectiveStatementImpl extends
+        AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements
+        LeafListSchemaNode, DerivableSchemaNode {
     private final QName qname;
     private final SchemaPath path;
 
@@ -39,13 +42,35 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
 
     private ImmutableList<UnknownSchemaNode> unknownNodes;
 
-    public LeafListEffectiveStatementImpl(StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
+    public LeafListEffectiveStatementImpl(
+            StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
         super(ctx);
         this.qname = ctx.getStatementArgument();
         this.path = Utils.getSchemaPath(ctx);
-        //:TODO init other fields
+        // :TODO init other fields
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (LeafListSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (LeafListSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
@@ -153,7 +178,8 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
+        StringBuilder sb = new StringBuilder(
+                LeafListEffectiveStatementImpl.class.getSimpleName());
         sb.append("[");
         sb.append(qname);
         sb.append("]");
index f9629a114cff9d68e18df5d5f6b83b541dad12ee..4e205bde1a1ab1b36f39cf5dfd02ded1eee51311 100644 (file)
@@ -1,7 +1,8 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -48,6 +49,25 @@ public class ListEffectiveStatementImpl extends
 
         initKeyDefinition();
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     /**
index 390769b3561df5251e74cbe9771b80b1618fd64e..a514971e287a83b0dd909c824be7c06f36e48d14 100644 (file)
@@ -7,39 +7,42 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import java.net.URI;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedList;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import java.net.URI;
-import java.util.Date;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
 import java.util.List;
 import java.util.Set;
+
+import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IncludedModuleContext;
 
-public class ModuleEffectiveStatementImpl extends
-        AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
+public class ModuleEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
         implements Module, Immutable {
 
-    private final QNameModule qnameModule;
+    private final QNameModule qNameModule;
     private final String name;
     private String sourcePath;
     private String prefix;
@@ -58,16 +61,32 @@ public class ModuleEffectiveStatementImpl extends
     private ImmutableList<UnknownSchemaNode> unknownNodes;
     private String source;
 
-    public ModuleEffectiveStatementImpl(
-            StmtContext<String, ModuleStatement, ?> ctx) {
+    public ModuleEffectiveStatementImpl(StmtContext<String, ModuleStatement, ?> ctx) {
         super(ctx);
 
         name = argument();
-        qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
-        // :TODO init other fields
+        qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
 
-        initSubstatementCollections();
+        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+            if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+                prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
+                yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
+                organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
+                contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
+            }
+        }
+
+        source = ctx.getStatementSource().name();
+
+        //ctx.getFromNamespace(IncludedModuleContext.class, ) //ModuleIdentifier
 
+        initSubstatementCollections();
     }
 
     private void initSubstatementCollections() {
@@ -75,22 +94,60 @@ public class ModuleEffectiveStatementImpl extends
 
         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+        Set<ModuleImport> importsInit = new HashSet<>();
+        Set<Module> submodulesInit = new HashSet<>();
+        Set<NotificationDefinition> notificationsInit = new HashSet<>();
+        Set<RpcDefinition> rpcsInit = new HashSet<>();
+        Set<Deviation> deviationsInit = new HashSet<>();
+        Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
+        Set<FeatureDefinition> featuresInit = new HashSet<>();
+        List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
+
+
 
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
-                UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodesInit.add(unknownNode);
+                unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
             }
             if (effectiveStatement instanceof AugmentationSchema) {
-                AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
-                augmentationsInit.add(augmentationSchema);
+                augmentationsInit.add((AugmentationSchema) effectiveStatement);
+            }
+            if (effectiveStatement instanceof ModuleImport) {
+                importsInit.add((ModuleImport) effectiveStatement);
+            }
+            if (effectiveStatement instanceof IncludeEffectiveStatementImpl) {
+//                ((IncludeEffectiveStatementImpl) effectiveStatement).
+            }
+            if (effectiveStatement instanceof NotificationDefinition) {
+                notificationsInit.add((NotificationDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof RpcDefinition) {
+                rpcsInit.add((RpcDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof Deviation) {
+                deviationsInit.add((Deviation) effectiveStatement);
+            }
+            if (effectiveStatement instanceof IdentitySchemaNode) {
+                identitiesInit.add((IdentitySchemaNode) effectiveStatement);
+            }
+            if (effectiveStatement instanceof FeatureDefinition) {
+                featuresInit.add((FeatureDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof ExtensionDefinition) {
+                extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
             }
         }
 
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-
-        // :TODO other substatement collections ...
+        this.imports = ImmutableSet.copyOf(importsInit);
+        this.submodules = ImmutableSet.copyOf(submodulesInit);
+        this.notifications = ImmutableSet.copyOf(notificationsInit);
+        this.rpcs = ImmutableSet.copyOf(rpcsInit);
+        this.deviations = ImmutableSet.copyOf(deviationsInit);
+        this.identities = ImmutableSet.copyOf(identitiesInit);
+        this.features = ImmutableSet.copyOf(featuresInit);
+        this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
     }
 
     @Override
@@ -100,7 +157,7 @@ public class ModuleEffectiveStatementImpl extends
 
     @Override
     public URI getNamespace() {
-        return qnameModule.getNamespace();
+        return qNameModule.getNamespace();
     }
 
     @Override
@@ -110,7 +167,7 @@ public class ModuleEffectiveStatementImpl extends
 
     @Override
     public Date getRevision() {
-        return qnameModule.getRevision();
+        return qNameModule.getRevision();
     }
 
     @Override
@@ -193,9 +250,8 @@ public class ModuleEffectiveStatementImpl extends
         final int prime = 31;
         int result = 1;
         result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result
-                + ((yangVersion == null) ? 0 : yangVersion.hashCode());
-        result = prime * result + qnameModule.hashCode();
+        result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+        result = prime * result + qNameModule.hashCode();
         return result;
     }
 
@@ -218,7 +274,7 @@ public class ModuleEffectiveStatementImpl extends
         } else if (!name.equals(other.name)) {
             return false;
         }
-        if (!qnameModule.equals(other.qnameModule)) {
+        if (!qNameModule.equals(other.qNameModule)) {
             return false;
         }
         if (yangVersion == null) {
@@ -231,13 +287,6 @@ public class ModuleEffectiveStatementImpl extends
         return true;
     }
 
-    // private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final
-    // Set<T> original) {
-    // TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-    // sorted.addAll(original);
-    // return Collections.unmodifiableSet(sorted);
-    // }
-
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
@@ -253,7 +302,7 @@ public class ModuleEffectiveStatementImpl extends
 
     @Override
     public QNameModule getQNameModule() {
-        return qnameModule;
+        return qNameModule;
     }
 
 }
index c6d21e86a7bc6f5a796beedfa687d6b2bc829aaa..0d061e115b260b861d0c0fcdbe095e602a6e9242 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
 import java.util.HashSet;
 import java.util.LinkedList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.List;
@@ -54,6 +55,27 @@ public class OutputEffectiveStatementImpl extends
         // :TODO init other fields
 
         initSubstatementCollections();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
+
+        TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+        switch (typeOfCopy) {
+        case ADDED_BY_AUGMENTATION:
+            augmenting = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        case ADDED_BY_USES:
+            addedByUses = true;
+            original = (ContainerSchemaNode) ctx.getOriginalCtx()
+                    .buildEffective();
+            break;
+        default:
+            break;
+        }
     }
 
     private void initSubstatementCollections() {
index 762d408b7882a1de318e0a19fec777eaa1fee8f4..380bcb10ccb3c9c2073b3be0da9c907ff937e3af 100644 (file)
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
 
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+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.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
 public class SubmoduleEffectiveStatementImpl extends
-        ModuleEffectiveStatementImpl {
+        AbstractEffectiveDocumentedDataNodeContainer<String, SubmoduleStatement> implements Module, Immutable {
 
-    public SubmoduleEffectiveStatementImpl(
-            StmtContext<String, ModuleStatement, ?> ctx) {
+    private final QNameModule qNameModule;
+    private final String name;
+    private String sourcePath;
+    private String prefix;
+    private String yangVersion;
+    private String organization;
+    private String contact;
+    private ImmutableSet<ModuleImport> imports;
+    private ImmutableSet<Module> submodules;
+    private ImmutableSet<FeatureDefinition> features;
+    private ImmutableSet<NotificationDefinition> notifications;
+    private ImmutableSet<AugmentationSchema> augmentations;
+    private ImmutableSet<RpcDefinition> rpcs;
+    private ImmutableSet<Deviation> deviations;
+    private ImmutableList<ExtensionDefinition> extensionNodes;
+    private ImmutableSet<IdentitySchemaNode> identities;
+    private ImmutableList<UnknownSchemaNode> unknownNodes;
+    private String source;
+
+    public SubmoduleEffectiveStatementImpl(StmtContext<String, SubmoduleStatement, ?> ctx) {
         super(ctx);
 
+        name = argument();
+
+        String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
+        final QNameModule belongsToModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
+        qNameModule = QNameModule.create(belongsToModule.getNamespace(), belongsToModule.getRevision());
+
+        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+            if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+                prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
+                yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
+                organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
+            }
+            if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
+                contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
+            }
+        }
+
+        source = ctx.getStatementSource().name();
+
+        initSubstatementCollections();
     }
 
+    private void initSubstatementCollections() {
+        Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+        Set<ModuleImport> importsInit = new HashSet<>();
+        Set<Module> submodulesInit = new HashSet<>();
+        Set<NotificationDefinition> notificationsInit = new HashSet<>();
+        Set<RpcDefinition> rpcsInit = new HashSet<>();
+        Set<Deviation> deviationsInit = new HashSet<>();
+        Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
+        Set<FeatureDefinition> featuresInit = new HashSet<>();
+        List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
+
+        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+            if (effectiveStatement instanceof UnknownSchemaNode) {
+                unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
+            }
+            if (effectiveStatement instanceof AugmentationSchema) {
+                augmentationsInit.add((AugmentationSchema) effectiveStatement);
+            }
+            if (effectiveStatement instanceof ModuleImport) {
+                importsInit.add((ModuleImport) effectiveStatement);
+            }
+            if (effectiveStatement instanceof Module) {
+                submodulesInit.add((Module) effectiveStatement);
+            }
+            if (effectiveStatement instanceof NotificationDefinition) {
+                notificationsInit.add((NotificationDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof RpcDefinition) {
+                rpcsInit.add((RpcDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof Deviation) {
+                deviationsInit.add((Deviation) effectiveStatement);
+            }
+            if (effectiveStatement instanceof IdentitySchemaNode) {
+                identitiesInit.add((IdentitySchemaNode) effectiveStatement);
+            }
+            if (effectiveStatement instanceof FeatureDefinition) {
+                featuresInit.add((FeatureDefinition) effectiveStatement);
+            }
+            if (effectiveStatement instanceof ExtensionDefinition) {
+                extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
+            }
+        }
+
+        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+        this.imports = ImmutableSet.copyOf(importsInit);
+        this.submodules = ImmutableSet.copyOf(submodulesInit);
+        this.notifications = ImmutableSet.copyOf(notificationsInit);
+        this.rpcs = ImmutableSet.copyOf(rpcsInit);
+        this.deviations = ImmutableSet.copyOf(deviationsInit);
+        this.identities = ImmutableSet.copyOf(identitiesInit);
+        this.features = ImmutableSet.copyOf(featuresInit);
+        this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
+    }
+
+    @Override
+    public String getModuleSourcePath() {
+        return sourcePath;
+    }
+
+    @Override
+    public URI getNamespace() {
+        return qNameModule.getNamespace();
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Date getRevision() {
+        return qNameModule.getRevision();
+    }
+
+    @Override
+    public String getPrefix() {
+        return prefix;
+    }
+
+    @Override
+    public String getYangVersion() {
+        return yangVersion;
+    }
+
+    @Override
+    public String getOrganization() {
+        return organization;
+    }
+
+    @Override
+    public String getContact() {
+        return contact;
+    }
+
+    @Override
+    public Set<ModuleImport> getImports() {
+        return imports;
+    }
+
+    @Override
+    public Set<Module> getSubmodules() {
+        return submodules;
+    }
+
+    @Override
+    public Set<FeatureDefinition> getFeatures() {
+        return features;
+    }
+
+    @Override
+    public Set<NotificationDefinition> getNotifications() {
+        return notifications;
+    }
+
+    @Override
+    public Set<AugmentationSchema> getAugmentations() {
+        return augmentations;
+    }
+
+    @Override
+    public Set<RpcDefinition> getRpcs() {
+        return rpcs;
+    }
+
+    @Override
+    public Set<Deviation> getDeviations() {
+        return deviations;
+    }
+
+    @Override
+    public List<ExtensionDefinition> getExtensionSchemaNodes() {
+        return extensionNodes;
+    }
+
+    @Override
+    public Set<IdentitySchemaNode> getIdentities() {
+        return identities;
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownNodes;
+    }
+
+    @Override
+    public String getSource() {
+        return source;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+        result = prime * result + qNameModule.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        if (!qNameModule.equals(other.qNameModule)) {
+            return false;
+        }
+        if (yangVersion == null) {
+            if (other.yangVersion != null) {
+                return false;
+            }
+        } else if (!yangVersion.equals(other.yangVersion)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
+        sb.append("[");
+        sb.append("name=").append(name);
+        sb.append(", namespace=").append(getNamespace());
+        sb.append(", revision=").append(getRevision());
+        sb.append(", prefix=").append(prefix);
+        sb.append(", yangVersion=").append(yangVersion);
+        sb.append("]");
+        return sb.toString();
+    }
+
+    @Override
+    public QNameModule getQNameModule() {
+        return qNameModule;
+    }
 }
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java
new file mode 100644 (file)
index 0000000..c7ce9e4
--- /dev/null
@@ -0,0 +1,127 @@
+package org.opendaylight.yangtools.yang.stmt.effective.build.test;
+
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+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 java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class EffectiveModuleTest {
+
+    private static final YangStatementSourceImpl ROOT_MODULE = new YangStatementSourceImpl(
+            "/semantic-statement-parser/effective-module/root.yang");
+    private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
+            "/semantic-statement-parser/effective-module/imported.yang");
+    private static final YangStatementSourceImpl SUBMODULE = new YangStatementSourceImpl(
+            "/semantic-statement-parser/effective-module/submod.yang");
+
+    private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(URI.create("root-ns"), null);
+
+    private static final QName cont = QName.create(ROOT_MODULE_QNAME, "cont");
+
+    private static final SchemaPath contSchemaPath = SchemaPath.create(true, cont);
+
+    private static Date revision;
+
+    @BeforeClass
+    public static void init() {
+        try {
+            revision = SimpleDateFormatUtil.getRevisionFormat()
+                    .parse("2000-01-01");
+        } catch (ParseException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    @Test
+    public void effectiveBuildTest() throws SourceException, ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, ROOT_MODULE, IMPORTED_MODULE, SUBMODULE);
+        EffectiveSchemaContext result = reactor.buildEffective();
+
+        assertNotNull(result);
+
+        Module rootModule = result.findModuleByName("root", null);
+        assertNotNull(rootModule);
+
+        assertEquals("root-pref", rootModule.getPrefix());
+        assertEquals("1", rootModule.getYangVersion());
+        assertEquals("kisko", rootModule.getOrganization());
+        assertEquals("kisko email", rootModule.getContact());
+
+        final Set<AugmentationSchema> augmentations = rootModule.getAugmentations();
+        assertEquals(1, augmentations.size());
+        assertEquals(contSchemaPath, augmentations.iterator().next().getTargetPath());
+
+        final Set<ModuleImport> imports = rootModule.getImports();
+        assertEquals(1, imports.size());
+        final ModuleImport importStmt = imports.iterator().next();
+        assertNotNull(importStmt);
+        assertEquals("imported", importStmt.getModuleName());
+        assertEquals(revision, importStmt.getRevision());
+        assertEquals("imp-pref", importStmt.getPrefix());
+
+        final Set<Module> submodules = rootModule.getSubmodules();
+        //assertEquals(1, submodules.size());
+        //assertEquals("submod", submodules.iterator().next().getName());
+
+        final Set<NotificationDefinition> notifications = rootModule.getNotifications();
+        assertEquals(1, notifications.size());
+        assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());
+
+        final Set<RpcDefinition> rpcs = rootModule.getRpcs();
+        assertEquals(1, rpcs.size());
+        assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());
+
+        final Set<Deviation> deviations = rootModule.getDeviations();
+        assertEquals(1, deviations.size());
+        final Deviation deviationStmt = deviations.iterator().next();
+        assertNotNull(deviationStmt);
+        assertEquals(contSchemaPath, deviationStmt.getTargetPath());
+        assertEquals(Deviation.Deviate.ADD, deviationStmt.getDeviate());
+        assertEquals("deviate reference", deviationStmt.getReference());
+
+        final Set<IdentitySchemaNode> identities = rootModule.getIdentities();
+        assertEquals(1, identities.size());
+        assertEquals("identity1", identities.iterator().next().getQName().getLocalName());
+
+//        final Set<FeatureDefinition> features = rootModule.getFeatures();
+//        assertEquals(1, features.size());
+//        assertEquals("feature1", features.iterator().next().getQName().getLocalName());
+
+        final List<ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
+        assertEquals(1, extensionSchemaNodes.size());
+        assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
+    }
+
+    private void addSources(CrossSourceStatementReactor.BuildAction reactor, YangStatementSourceImpl... sources) {
+        for (YangStatementSourceImpl source : sources) {
+            reactor.addSource(source);
+        }
+    }
+}
index d0bed87663cc6afd6b33cbcc5cb8b027e7fd55af..10cba77b1a6a035b7ea9057e8353ebe6a3157bbf 100644 (file)
@@ -2,9 +2,8 @@ package org.opendaylight.yangtools.yang.stmt.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-
+import static org.junit.Assert.assertNull;
 import java.net.URI;
-
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -21,45 +20,146 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR
 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 com.google.common.collect.ImmutableList;
 
 public class AugmentProcessTest {
 
     private static final YangStatementSourceImpl AUGMENTED = new YangStatementSourceImpl(
-            "/stmt-test/effective-build/augmented.yang");
+            "/stmt-test/augments/augmented.yang");
     private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
-            "/stmt-test/effective-build/aug-root.yang");
+            "/stmt-test/augments/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);
+    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);
 
     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");
+    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");
 
-    private final QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added1");
-    private final 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");
 
     private final QName list1 = QName.create(AUGMENTED_QNAME_MODULE, "list1");
     private final QName axml = QName.create(AUGMENTED_QNAME_MODULE, "axml");
 
-    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 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 grpCont22 = QName.create(ROOT_QNAME_MODULE,
+            "grp-cont22");
     private final QName grpAdd = QName.create(ROOT_QNAME_MODULE, "grp-add");
 
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-test.yang");
+
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT_ROOT = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-root.yang");
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT_IMPORTED = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-imported.yang");
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT_SUBMODULE = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-submodule.yang");
+
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT_INCORRECT = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-incorrect.yang");
+
+    private static final YangStatementSourceImpl MULTIPLE_AUGMENT_INCORRECT2 = new YangStatementSourceImpl(
+            "/stmt-test/augments/multiple-augment-incorrect2.yang");
+
+    @Test
+    public void multipleAugmentsAndMultipleModulesTest() throws SourceException,
+            ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        addSources(reactor, MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED, MULTIPLE_AUGMENT_SUBMODULE);
+
+        EffectiveSchemaContext result = null;
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+        assertNotNull(result);
+    }
+
+    @Test
+    public void multipleAugmentTest() throws SourceException, ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        addSources(reactor, MULTIPLE_AUGMENT);
+
+        EffectiveSchemaContext result = null;
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+        assertNotNull(result);
+    }
+
+    @Test
+    public void multipleAugmentIncorrectPathTest() throws SourceException,
+            ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        addSources(reactor, MULTIPLE_AUGMENT_INCORRECT);
+
+        EffectiveSchemaContext result = null;
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+
+        assertNull(result);
+    }
+
+    @Test
+    public void multipleAugmentIncorrectPathAndGrpTest() throws SourceException,
+            ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        addSources(reactor, MULTIPLE_AUGMENT_INCORRECT2);
+
+        EffectiveSchemaContext result = null;
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+
+        assertNull(result);
+    }
+
+    private void log(Throwable e, String indent) {
+        System.out.println(indent + e.getMessage());
+
+        Throwable[] suppressed = e.getSuppressed();
+        for (Throwable throwable : suppressed) {
+            log(throwable, indent + "        ");
+        }
+    }
+
     @Test
-    public void readAndParseYangFileTest() throws SourceException, ReactorException {
+    public void readAndParseYangFileTest() throws SourceException,
+            ReactorException {
 
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
         addSources(reactor, AUGMENTED, ROOT);
 
         final EffectiveSchemaContext root = reactor.buildEffective();
@@ -68,45 +168,61 @@ public class AugmentProcessTest {
         Module augmentedModule = root.findModuleByName("augmented", null);
         assertNotNull(augmentedModule);
 
-        ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root.getDataChildByName(augParent1);
-        ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
-        ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
+        ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root
+                .getDataChildByName(augParent1);
+        ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node
+                .getDataChildByName(augParent2);
+        ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node
+                .getDataChildByName(contTarget);
         assertNotNull(targetContNode);
 
         assertNotNull(targetContNode.getChildNodes());
         assertEquals(3, targetContNode.getChildNodes().size());
 
-        ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded1);
+        ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode
+                .getDataChildByName(contAdded1);
         assertNotNull(contAdded1Node);
-        ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node.getDataChildByName(list1);
+        ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node
+                .getDataChildByName(list1);
         assertNotNull(list1Node);
 
-        ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded2);
+        ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode
+                .getDataChildByName(contAdded2);
         assertNotNull(contAdded2Node);
-        AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node.getDataChildByName(axml);
+        AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node
+                .getDataChildByName(axml);
         assertNotNull(axmlNode);
 
-        ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode.getDataChildByName(contGrp);
+        ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode
+                .getDataChildByName(contGrp);
         assertNotNull(contGrpNode);
-        AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
+        AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode
+                .getDataChildByName(axmlGrp);
         assertNotNull(axmlGrpNode);
 
-        ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root.getDataChildByName(augCont1);
-        ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node.getDataChildByName(augCont2);
+        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);
+        ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node
+                .getDataChildByName(grpCont2);
+        ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node
+                .getDataChildByName(grpCont22);
         assertNotNull(grpCont22Node);
 
-        ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node.getDataChildByName(grpAdd);
+        ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node
+                .getDataChildByName(grpAdd);
         assertNotNull(grpAddNode);
     }
 
-    private <T extends ModelStatement> T findInStatements(QName target, ImmutableList<T> statements) {
+    private <T extends ModelStatement> T findInStatements(QName target,
+            ImmutableList<T> statements) {
 
         for (final T statement : statements) {
-            if (target.equals(statement.statementDefinition().getArgumentName())) {
+            if (target
+                    .equals(statement.statementDefinition().getArgumentName())) {
                 return statement;
             }
         }
@@ -114,7 +230,8 @@ public class AugmentProcessTest {
         return null;
     }
 
-    private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+    private void addSources(CrossSourceStatementReactor.BuildAction reactor,
+            StatementStreamSource... sources) {
         for (StatementStreamSource source : sources) {
             reactor.addSource(source);
         }
index 3ffc50c2398d64205c059e86e3f5369d6ce54543..967ec3f1800cb4d217a02e5cc3e824023d0a3ab2 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR
 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;
-
 import static org.junit.Assert.assertNotNull;
 
 public class YangFileStmtTest {
@@ -28,6 +27,21 @@ public class YangFileStmtTest {
     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");
 
+
+    private static final YangStatementSourceImpl BAR = new YangStatementSourceImpl("/model-new/bar.yang");
+    private static final YangStatementSourceImpl BAZ = new YangStatementSourceImpl("/model-new/baz.yang");
+    private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl("/model-new/foo.yang");
+    private static final YangStatementSourceImpl SUBFOO = new YangStatementSourceImpl("/model-new/subfoo.yang");
+
+    @Test
+    public void readAndParseYangFileTestModel() throws SourceException, ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+
+        addSources(reactor, BAZ,FOO,BAR,SUBFOO);
+        EffectiveModelContext result = reactor.build();
+        assertNotNull(result);
+    }
+
     @Test
     public void readAndParseYangFileTest() throws SourceException, ReactorException {
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
diff --git a/yang/yang-parser-impl/src/test/resources/model-new/bar.yang b/yang/yang-parser-impl/src/test/resources/model-new/bar.yang
new file mode 100644 (file)
index 0000000..fd0276e
--- /dev/null
@@ -0,0 +1,118 @@
+module bar {
+    yang-version 1;
+    namespace "urn:opendaylight.bar";
+    prefix "bar";
+
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+    description "This model define custom type definitions";
+
+    revision "2013-07-03" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+    typedef int32-ext1 {
+        type int32 {
+            range "2..20";
+        }
+    }
+
+    typedef int32-ext2 {
+        type int32-ext1 {
+            range "3..9|11..max";
+        }
+        units "mile";
+        default "11";
+    }
+
+    typedef string-ext1 {
+        type string {
+            pattern "[a-k]*";
+            length "5..11";
+        }
+    }
+
+    typedef string-ext2 {
+        type string-ext1 {
+            length "6..10";
+        }
+    }
+
+    typedef string-ext3 {
+        type string-ext2 {
+            pattern "[b-u]*";
+        }
+    }
+
+    typedef string-ext4 {
+        type string-ext3 {
+            pattern "[e-z]*";
+        }
+    }
+
+    typedef invalid-string-pattern {
+        type string {
+            pattern "[[A-1*-%22!^^}";
+        }
+    }
+
+    typedef multiple-pattern-string {
+        type string {
+            pattern "[[A-1*-%22!^^}";
+            pattern "[e-z]*";
+        }
+    }
+
+    typedef my-decimal-type {
+        type decimal64 {
+            fraction-digits 6;
+        }
+    }
+
+    typedef my-union {
+        type union {
+            type int16 {
+                range "1..100";
+            }
+            type int32;
+        }
+    }
+
+    typedef my-union-ext {
+        type my-union;
+    }
+
+    typedef nested-union2 {
+        type union {
+            type my-union-ext;
+            type string;
+        }
+    }
+
+    container interfaces {
+        grouping ifEntry {
+            container augment-holder;
+        }
+        list ifEntry {
+            key "ifIndex";
+
+            leaf ifIndex {
+                type uint32;
+                units minutes;
+            }
+
+            leaf ifMtu {
+                type int32;
+            }
+
+            min-elements 1;
+            max-elements 11;
+        }
+    }
+
+    extension opendaylight {
+        argument "name" {
+            yin-element "true";
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/model-new/baz.yang b/yang/yang-parser-impl/src/test/resources/model-new/baz.yang
new file mode 100644 (file)
index 0000000..862b1eb
--- /dev/null
@@ -0,0 +1,189 @@
+module baz {
+    yang-version 1;
+    namespace "urn:opendaylight.baz";
+    prefix "baz";
+
+    import bar { prefix "br"; revision-date 2013-07-03; }
+
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+    typedef union1 {
+        type union2;
+    }
+
+    typedef union2 {
+        type union {
+            type int32;
+            type br:nested-union2;
+        }
+    }
+
+    augment "/br:interfaces/br:ifEntry" {
+        when "if:ifType='ds0'";
+        container augment-holder {
+            description "Description for augment holder";
+        }
+    }
+
+    augment "/br:interfaces/br:ifEntry" {
+        when "if:ifType='ds2'";
+        container augment-holder2 {
+            description "Description for augment holder";
+        }
+    }
+
+    container network {
+        c-define point {
+        }
+
+        description "network-description";
+        reference "network-reference";
+        status obsolete;
+        config true;
+        presence "some presence text";
+    }
+
+    feature local-storage {
+        description
+                "This feature means the device supports local storage (memory,
+                flash or disk) that can be used to store syslog messages.";
+    }
+
+    extension c-define {
+        description "Takes as argument a name string. Makes the code generator use
+                the given name in the #define.";
+        argument "name" {
+            yin-element "true";
+        }
+    }
+
+    notification event {
+        leaf event-class {
+            type string;
+        }
+        anyxml reporting-entity;
+        leaf severity {
+            type string;
+        }
+    }
+
+    rpc get-config {
+        description "Retrieve all or part of a specified configuration.";
+        reference "RFC 6241, Section 7.1";
+
+        input {
+            container source {
+                description
+                                "Particular configuration to retrieve.";
+
+                choice config-source {
+                    mandatory true;
+                    description
+                                        "The configuration to retrieve.";
+                    case a {
+                        leaf candidate {
+                            if-feature candidate;
+                            type empty;
+                            description
+                                                        "The candidate configuration is the config source.";
+                        }
+                    }
+                    case b {
+                        leaf running {
+                            type empty;
+                            description
+                                                        "The running configuration is the config source.";
+                        }
+                    }
+                    case c {
+                        leaf startup {
+                            if-feature startup;
+                            type empty;
+                            description
+                                                        "The startup configuration is the config source. This is optional-to-implement
+                                                        on the server because not all servers will support filtering for
+                                                        this datastore.";
+                        }
+                    }
+                }
+            }
+
+            anyxml filter {
+                description "Subtree or XPath filter to use.";
+                baz:c-define element-attributes;
+            }
+        }
+
+        output {
+            anyxml data {
+                description
+                                "Copy of the source datastore subset that matched the filter criteria
+                                (if any). An empty data container indicates that the request did
+                                not produce any results.";
+            }
+        }
+    }
+
+    grouping target {
+        anyxml data {
+            config true;
+            description "Copy of the source datastore subset.";
+            mandatory false;
+            must "test-condition-text";
+            reference "test-no-reference";
+            status "obsolete";
+            when "test-when-text";
+        }
+        choice how {
+            description "test choice description";
+            default interval;
+            case interval {
+                leaf interval {
+                    type uint16;
+                    default 30;
+                    units minutes;
+                }
+            }
+            case daily {
+                leaf daily {
+                    type empty;
+                }
+                leaf time-of-day {
+                    type string;
+                    units 24-hour-clock;
+                    default 1am;
+                }
+            }
+        }
+        leaf address {
+            type string;
+            description "Target IP address";
+            mandatory true;
+        }
+        container port {
+            description "Target port container";
+        }
+        list addresses {
+            key "id";
+            leaf id {
+                type int8;
+            }
+        }
+        grouping target-inner {
+            description "target-inner default description";
+            leaf inner-grouping-id {
+                type int8;
+            }
+        }
+        typedef group-type {
+            type br:my-decimal-type;
+        }
+
+        br:opendaylight;
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/model-new/foo.yang b/yang/yang-parser-impl/src/test/resources/model-new/foo.yang
new file mode 100644 (file)
index 0000000..7b820cc
--- /dev/null
@@ -0,0 +1,228 @@
+module foo {
+    yang-version 1;
+    namespace "urn:opendaylight.foo";
+    prefix "foo";
+
+    import bar { prefix "br"; revision-date 2013-07-03; }
+
+    import baz { prefix "bz"; revision-date 2013-02-27; }
+
+    include subfoo {
+        revision-date "2013-02-27";
+    }
+
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+    typedef identifier {
+        type int32;
+    }
+
+    leaf int32-leaf {
+        type br:int32-ext2 {
+            range "12..max";
+        }
+    }
+
+    leaf string-leaf {
+        type br:string-ext4;
+    }
+
+    leaf invalid-pattern-string-leaf {
+        type br:invalid-string-pattern;
+    }
+
+    leaf invalid-direct-string-pattern-def-leaf {
+        type string {
+            pattern "[[A-1*-%22!^^}";
+        }
+    }
+
+    leaf multiple-pattern-string-leaf {
+        type br:multiple-pattern-string;
+    }
+
+    leaf multiple-pattern-direct-string-def-leaf {
+        type string {
+            pattern "[e-z]*";
+            pattern "[[A-1*-%22!^^}";
+            pattern "[a-d]*";
+        }
+    }
+
+    leaf length-leaf {
+        type br:string-ext2 {
+            length "7..max";
+        }
+    }
+
+    leaf decimal-leaf {
+        type br:my-decimal-type {
+            fraction-digits 4;
+        }
+    }
+
+    leaf decimal-leaf2 {
+        type br:my-decimal-type;
+    }
+
+    container ext {
+        bz:c-define "MY_INTERFACES";
+    }
+
+    leaf union-leaf {
+        type br:my-union-ext;
+    }
+
+    deviation /br:interfaces/br:ifEntry {
+        deviate add {
+            default "admin";
+            config "true";
+        }
+        reference "system/user ref";
+    }
+
+    leaf custom-union-leaf {
+        type bz:union1;
+    }
+
+    container transfer {
+        choice how {
+            default interval;
+            container input {
+            }
+            list output {
+                leaf id {
+                    type string;
+                }
+            }
+            case interval {
+                leaf interval {
+                    type uint16;
+                    default 30;
+                    units minutes;
+                }
+            }
+            case daily {
+                leaf daily {
+                    type empty;
+                }
+                leaf time-of-day {
+                    type string;
+                    units 24-hour-clock;
+                    default 1am;
+                }
+            }
+            case manual {
+                leaf manual {
+                    type empty;
+                }
+            }
+        }
+    }
+
+    anyxml datas {
+        description
+                "Copy of the source typesstore subset that matched the filter
+                criteria (if any). An empty types container indicates that the
+                request did not produce any results.";
+        status obsolete;
+    }
+
+    augment "/br:interfaces/br:ifEntry/br:augment-holder" {
+        when "if:ifType='ds0'";
+        leaf ds0ChannelNumber {
+            type string;
+        }
+        leaf interface-id {
+            type leafref {
+                path "/if:interfaces/if:interface/if:name";
+            }
+        }
+        leaf my-type {
+            type br:int32-ext2;
+        }
+        container schemas {
+        }
+        choice odl {
+            leaf id {
+                type int8;
+            }
+            case node1 {
+                description "node1";
+            }
+            case node2 {
+                description "node2";
+            }
+            container node3 {
+                description "node3";
+            }
+        }
+    }
+
+    container mycont {
+        container innercont {
+            typedef mytype {
+                type string;
+            }
+            leaf myleaf {
+                type mytype;
+            }
+        }
+    }
+
+    uses bz:target {
+        augment "how/interval" {
+            description "inner augment";
+            leaf name {
+                type string;
+            }
+        }
+    }
+
+    container peer {
+        container destination {
+            uses bz:target {
+                refine address {
+                    default "1.2.3.4";
+                    description "IP address of target node";
+                    reference "address reference added by refine";
+                    config false;
+                    mandatory false;
+                    must "ifType != 'ethernet' or " +
+                                        "(ifType = 'ethernet' and ifMTU = 1500)" {
+                        error-message "An ethernet MTU must be 1500";
+                    }
+                    mountpoint "mnt-extension";
+                }
+                refine port {
+                    description "description of port defined by refine";
+                    reference "port reference added by refine";
+                    config false;
+                    presence "presence is required";
+                }
+                refine "addresses" {
+                    description "description of addresses defined by refine";
+                    reference "addresses reference added by refine";
+                    config false;
+                    min-elements 2;
+                    max-elements unbounded;
+                }
+                refine addresses/id {
+                    description "id of address";
+                }
+            }
+        }
+    }
+
+    extension mountpoint {
+        description "enter point";
+        argument "name" {
+            yin-element "true";
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/model-new/subfoo.yang b/yang/yang-parser-impl/src/test/resources/model-new/subfoo.yang
new file mode 100644 (file)
index 0000000..1900530
--- /dev/null
@@ -0,0 +1,70 @@
+submodule subfoo {
+    yang-version 1;
+
+    belongs-to foo {
+        prefix f;
+    }
+
+    import bar {
+        prefix "br";
+        revision-date 2013-07-03;
+    }
+
+    import baz {
+        prefix "bz";
+        revision-date 2013-02-27;
+    }
+
+    revision "2013-02-27" {
+    }
+
+    leaf id {
+        type br:int32-ext2 {
+            range "12..max";
+        }
+    }
+
+    leaf foo-id {
+        type f:identifier;
+    }
+
+    container sub-ext {
+        bz:c-define "MY_INTERFACES";
+    }
+
+    container sub-transfer {
+        choice how {
+            default interval;
+            container input {
+            }
+            list output {
+                leaf id {
+                    type string;
+                }
+            }
+            case manual {
+                leaf manual {
+                    type empty;
+                }
+            }
+        }
+    }
+
+    anyxml sub-datas {
+        status obsolete;
+    }
+
+    augment "/br:interfaces/br:ifEntry/br:augment-holder" {
+        when "if:ifType='ds0'";
+        leaf subleaf {
+            type string;
+        }
+    }
+
+    extension sub-mountpoint {
+        argument "name" {
+            yin-element "true";
+        }
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/imported.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/imported.yang
new file mode 100644 (file)
index 0000000..3059998
--- /dev/null
@@ -0,0 +1,6 @@
+module imported {
+       namespace imported;
+       prefix imported;
+
+       revision "2000-01-01";
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/root.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/root.yang
new file mode 100644 (file)
index 0000000..4f07856
--- /dev/null
@@ -0,0 +1,45 @@
+module root {
+       namespace root-ns;
+       prefix root-pref;
+
+       yang-version 1;
+       organization "kisko";
+       contact "kisko email";
+
+       import imported {
+               prefix imp-pref;
+               revision "2000-01-01";
+       }
+       include submod;
+
+       container cont {
+       }
+
+       augment "/cont" {
+               container cont-aug {
+               }
+       }
+
+       notification notif1 {
+       }
+
+       rpc rpc1 {
+       }
+
+       deviation /cont {
+               deviate add {
+                       container subcont{
+                       }
+               }
+               reference "deviate reference";
+       }
+
+       identity identity1 {
+       }
+
+       feature feature1 {
+       }
+
+       extension ext1 {
+       }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/submod.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/effective-module/submod.yang
new file mode 100644 (file)
index 0000000..be060f8
--- /dev/null
@@ -0,0 +1,6 @@
+submodule submod {
+       belongs-to "root" {
+               prefix root;
+       }
+       revision "2000-01-01";
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/aug-root.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/aug-root.yang
new file mode 100644 (file)
index 0000000..42ced8d
--- /dev/null
@@ -0,0 +1,37 @@
+module aug-root {
+    namespace root;
+    prefix root;
+
+    import augmented { prefix aug; }
+
+    augment "/aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
+        container cont-added1 {
+            list list1 {
+            }
+        }
+
+        container cont-added2 {
+            anyxml axml;
+        }
+
+        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 {
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/augmented.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/augmented.yang
new file mode 100644 (file)
index 0000000..6ff2422
--- /dev/null
@@ -0,0 +1,17 @@
+module augmented {
+    namespace aug;
+    prefix aug;
+
+    container aug-parent1 {
+        container aug-parent2 {
+            container cont-target {
+            }
+        }
+    }
+
+    grouping grp {
+        container cont-grp {
+            anyxml axml-grp;
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-imported.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-imported.yang
new file mode 100644 (file)
index 0000000..0d030b2
--- /dev/null
@@ -0,0 +1,60 @@
+module multiple-augment-imported {
+
+    namespace "multiple-augment-imported";
+    prefix imp;
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+        container sub-container-from-augment4 {
+        }
+    }
+
+    container root-container {
+        uses grp1 {
+            augment container-from-grp1/sub-container-from-grp1 {
+                container container-in-uses-augment {
+                }
+            }
+        }
+    }
+
+    grouping grp1 {
+        container container-from-grp1 {
+            container sub-container-from-grp1 {
+                uses grp2 {
+                    augment container-from-grp2/sub-container-from-grp2 {
+                        container augmented-container-in-uses-grp2;
+                    }
+                }
+            }
+        }
+    }
+
+    augment /root-container/added-container-1 {
+        container added-container-2 {
+        }
+    }
+
+    grouping grp2 {
+        container container-from-grp2 {
+            container sub-container-from-grp2 {
+            }
+        }
+        uses grp3;
+    }
+
+    grouping grp3 {
+        container container-from-grp3 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment {
+        container sub-container-from-augment2 {
+        }
+    }
+    
+    grouping grp-from-import {
+        container container-from-grp-from-import {
+            
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect.yang
new file mode 100644 (file)
index 0000000..61ad3e3
--- /dev/null
@@ -0,0 +1,80 @@
+module multiple-augment-incorrect {
+
+    namespace "multiple-augment-test";
+    prefix mpa;
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+        container sub-container-from-augment4 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+        container sub-container-from-augment3 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1 {
+        container sub-container-from-augment {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+        container sub-container-from-augment6 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+        container sub-container-from-augment7 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+        container sub-container-from-augment5 {
+        }
+    }
+
+    augment /root-container/added-container-1 {
+        container added-container-2 {
+        }
+    }
+
+    augment /root-container {
+        container added-container-1 {
+        }
+    }
+
+    grouping grp1 {
+        container container-from-grp1 {
+            container sub-container-from-grp1 {
+                uses grp2 {
+                    augment container-from-grp2/sub-container-from-grp2 {
+                        container augmented-container-in-uses-grp2;
+                    }
+                }
+            }
+        }
+    }
+
+    grouping grp2 {
+        container container-from-grp2 {
+            container sub-container-from-grp2 {
+            }
+        }
+        uses grp3;
+    }
+    
+    grouping grp3 {
+      container container-from-grp3 {
+          
+      }
+    }
+    
+    container root-container {
+        uses grp1 {
+            augment container-from-grp1/sub-container-from-grp1 {
+                container container-in-uses-augment {
+                }
+            }
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect2.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-incorrect2.yang
new file mode 100644 (file)
index 0000000..c0e51c8
--- /dev/null
@@ -0,0 +1,89 @@
+module multiple-augment-incorrect2 {
+
+    namespace "multiple-augment-test";
+    prefix mpa;
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+        container sub-container-from-augment4 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+        container sub-container-from-augment3 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1 {
+        container sub-container-from-augment {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+        container sub-container-from-augment6 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+        container sub-container-from-augment7 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+        container sub-container-from-augment5 {
+        }
+    }
+
+    augment /root-container/added-container-1 {
+        container added-container-2 {
+        }
+    }
+
+    augment /root-container {
+        container added-container-1 {
+        }
+    }
+
+    grouping grp1 {
+        container container-from-grp1 {
+            container sub-container-from-grp1 {
+                uses grp2 {
+                    augment container-from-grp2/sub-container-from-grp2 {
+                        container augmented-container-in-uses-grp2;
+                    }
+                }
+            }
+        }
+    }
+
+    grouping grp2 {
+        container container-from-grp2 {
+            container sub-container-from-grp2 {
+            }
+        }
+        uses grp3;
+    }
+
+    grouping grp3 {
+        container container-from-grp3 {
+        }
+    }
+
+    container root-container {
+        uses grp1 {
+            augment container-from-grp1/sub-container-from-grp1 {
+                container container-in-uses-augment {
+                }
+            }
+        }
+    }
+    
+    container container-with-incorrect-uses {
+        uses grp4 {
+            augment unknown {
+                container new {
+                    
+                }
+            }
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-root.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-root.yang
new file mode 100644 (file)
index 0000000..88123f7
--- /dev/null
@@ -0,0 +1,54 @@
+module multiple-augment-root {
+
+    namespace "multiple-augment-root";
+    prefix root;
+
+    import multiple-augment-imported { prefix imp; revision-date 1970-01-01; }
+    
+    include multiple-augment-submodule { revision-date 1970-01-01; }
+
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-in-uses-augment/imp:sub-container-from-augment2 {
+        container sub-container-from-augment3 {
+        }
+    }
+
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1 {
+        container sub-container-from-augment {
+        }
+    }
+
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/imp:augmented-container-in-uses-grp2 {
+        container sub-container-from-augment6 {
+        }
+    }
+
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/imp:sub-container-from-augment5 {
+        container sub-container-from-augment7 {
+        }
+    }
+
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2 {
+        container sub-container-from-augment5 {
+        }
+    }
+
+    augment /imp:root-container {
+        container added-container-1 {
+        }
+    }
+    
+    container container-with-multiple-uses {
+        uses imp:grp-from-import{
+            augment container-from-grp-from-import {
+                container new {
+                }
+            }
+        }
+        uses grp-from-include{
+            augment container-from-grp-from-include {
+                container new {
+                }
+            }
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-submodule.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-submodule.yang
new file mode 100644 (file)
index 0000000..ec5b70e
--- /dev/null
@@ -0,0 +1,11 @@
+submodule multiple-augment-submodule {
+    
+    belongs-to multiple-augment-root {
+     prefix rt;   
+    }
+    
+    grouping grp-from-include{
+        container container-from-grp-from-include {
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-test.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-test.yang
new file mode 100644 (file)
index 0000000..7912b7d
--- /dev/null
@@ -0,0 +1,85 @@
+module multiple-augment-test {
+
+    namespace "multiple-augment-test";
+    prefix mpa;
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+        container sub-container-from-augment4 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+        container sub-container-from-augment3 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment {
+        container sub-container-from-augment2 {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1 {
+        container sub-container-from-augment {
+        }
+    }
+
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+        container sub-container-from-augment6 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+        container sub-container-from-augment7 {
+        }
+    }
+    
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+        container sub-container-from-augment5 {
+        }
+    }
+
+    augment /root-container/added-container-1 {
+        container added-container-2 {
+        }
+    }
+
+    augment /root-container {
+        container added-container-1 {
+        }
+    }
+
+    grouping grp1 {
+        container container-from-grp1 {
+            container sub-container-from-grp1 {
+                uses grp2 {
+                    augment container-from-grp2/sub-container-from-grp2 {
+                        container augmented-container-in-uses-grp2;
+                    }
+                }
+            }
+        }
+    }
+
+    grouping grp2 {
+        container container-from-grp2 {
+            container sub-container-from-grp2 {
+            }
+        }
+        uses grp3;
+    }
+    
+    grouping grp3 {
+      container container-from-grp3 {
+          
+      }
+    }
+    
+    container root-container {
+        uses grp1 {
+            augment container-from-grp1/sub-container-from-grp1 {
+                container container-in-uses-augment {
+                }
+            }
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/aug-root.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/aug-root.yang
deleted file mode 100644 (file)
index 2733214..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-module aug-root {
-       namespace root;
-       prefix root;
-
-       import augmented {
-               prefix aug;
-       }
-
-       augment "/aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
-               container cont-added1 {
-                       list list1 {
-                       }
-               }
-
-               container cont-added2 {
-                       anyxml axml;
-               }
-
-               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
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/augmented.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/effective-build/augmented.yang
deleted file mode 100644 (file)
index 47ca018..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-module augmented {
-       namespace aug;
-       prefix aug;
-
-       container aug-parent1 {
-               container aug-parent2 {
-                       container cont-target {
-
-                       }
-               }
-       }
-
-       grouping grp {
-               container cont-grp {
-                       anyxml axml-grp;
-               }
-       }
-}
\ No newline at end of file