Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / RootStatementContext.java
index d32b8cdee123346d0b072c69ee56ed515ab61348..6b876c71f607d7f215d0aef2cbad582b2f521aec 100644 (file)
@@ -7,34 +7,33 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import java.util.List;
-
+import java.util.Collection;
 import java.util.LinkedList;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import java.util.List;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import java.util.Collection;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-        extends StatementContextBase<A, D, E> {
+/**
+ * root statement class for a Yang source
+ */
+public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
+        StatementContextBase<A, D, E> {
 
     private final SourceSpecificContext sourceContext;
     private final A argument;
 
-    RootStatementContext(ContextBuilder<A, D, E> builder,
-            SourceSpecificContext sourceContext) throws SourceException {
+    RootStatementContext(ContextBuilder<A, D, E> builder, SourceSpecificContext sourceContext) throws SourceException {
         super(builder);
         this.sourceContext = sourceContext;
-        this.argument = builder.getDefinition().parseArgumentValue(this,
-                builder.getRawArgument());
+        this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
     }
 
-    RootStatementContext(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+    RootStatementContext(RootStatementContext<A, D, E> original, QNameModule newQNameModule, TypeOfCopy typeOfCopy)
             throws SourceException {
         super(original);
 
@@ -47,43 +46,63 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
 
     }
 
-    private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
-            throws SourceException {
-        Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
-                .declaredSubstatements();
+    /**
+     * copies declared statements from original to this' substatements
+     *
+     * @param typeOfCopy
+     *            determines whether copy is used by augmentation or uses
+     * @throws SourceException
+     */
+    private void copyDeclaredStmts(RootStatementContext<A, D, E> original, QNameModule newQNameModule,
+            TypeOfCopy typeOfCopy) throws SourceException {
+        Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
-            this.addEffectiveSubstatement(stmtContext.createCopy(
-                    newQNameModule, this, typeOfCopy));
+            this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
         }
     }
 
-    private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
-            QNameModule newQNameModule, TypeOfCopy typeOfCopy)
-            throws SourceException {
-        Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
-                .effectiveSubstatements();
+    /**
+     * copies effective statements from original to this' substatements
+     *
+     * @param typeOfCopy
+     *            determines whether copy is used by augmentation or uses
+     * @throws SourceException
+     */
+    private void copyEffectiveStmts(RootStatementContext<A, D, E> original, QNameModule newQNameModule,
+            TypeOfCopy typeOfCopy) throws SourceException {
+        Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
-            this.addEffectiveSubstatement(stmtContext.createCopy(
-                    newQNameModule, this, typeOfCopy));
+            this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
         }
     }
 
+    /**
+     * @return null as root cannot have parent
+     */
     @Override
     public StatementContextBase<?, ?, ?> getParentContext() {
         return null;
     }
 
+    /**
+     * @return namespace storage of source context
+     */
     @Override
     public NamespaceStorageNode getParentNamespaceStorage() {
         return sourceContext;
     }
 
+    /**
+     * @return registry of source context
+     */
     @Override
     public Registry getBehaviourRegistry() {
         return sourceContext;
     }
 
+    /**
+     * @return this as its own root
+     */
     @Override
     public RootStatementContext<?, ?, ?> getRoot() {
         return this;
@@ -98,26 +117,57 @@ class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Effectiv
         return argument;
     }
 
+    /**
+     * @return copy of this considering {@link TypeOfCopy} (augment, uses)
+     *
+     * @throws SourceException
+     */
     @Override
-    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
-            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+    public StatementContextBase<?, ?, ?> createCopy(StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
             throws SourceException {
-        RootStatementContext<A, D, E> copy = new RootStatementContext<>(this,
-                newQNameModule, typeOfCopy);
+        return createCopy(null, newParent, typeOfCopy);
+    }
+
+    /**
+     * @return copy of this considering {@link TypeOfCopy} (augment, uses)
+     *
+     * @throws SourceException
+     */
+    @Override
+    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy) throws SourceException {
+        RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
         copy.setTypeOfCopy(typeOfCopy);
         copy.setOriginalCtx(this);
         return copy;
     }
 
+    /**
+     * @return this' argument as it is the only from root (this)
+     */
     @Override
     public List<Object> getArgumentsFromRoot() {
-        List<Object> argumentList = new LinkedList<Object>();
+        List<Object> argumentList = new LinkedList<>();
         argumentList.add(argument);
         return argumentList;
     }
 
+    /**
+     * @return this as it is the only\context from root (this)
+     */
+    @Override
+    public List<StmtContext<?, ?, ?>> getStmtContextsFromRoot() {
+        List<StmtContext<?, ?, ?>> stmtContextsList = new LinkedList<>();
+        stmtContextsList.add(this);
+        return stmtContextsList;
+    }
+
+    /**
+     * @return true
+     */
     @Override
     public boolean isRootContext() {
         return true;
     }
+
 }