Bug 4662: Introduce a SemanticVersion concept - import processing
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / RootStatementContext.java
index 8c883dd26572b680ac0537dc5297d79e1640ffae..4fc299a573a86b26d5ad850b02c3118db1b4d5e9 100644 (file)
@@ -7,16 +7,16 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
+import com.google.common.base.Optional;
 import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 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.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 /**
  * root statement class for a Yang source
@@ -27,14 +27,14 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     private final SourceSpecificContext sourceContext;
     private final A argument;
 
-    RootStatementContext(ContextBuilder<A, D, E> builder, SourceSpecificContext sourceContext) throws SourceException {
+    RootStatementContext(final ContextBuilder<A, D, E> builder, final SourceSpecificContext sourceContext) {
         super(builder);
         this.sourceContext = sourceContext;
         this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
     }
 
-    RootStatementContext(RootStatementContext<A, D, E> original, QNameModule newQNameModule, TypeOfCopy typeOfCopy)
-            throws SourceException {
+    RootStatementContext(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
+        final TypeOfCopy typeOfCopy) {
         super(original);
 
         sourceContext = original.sourceContext;
@@ -51,10 +51,10 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      *
      * @param typeOfCopy
      *            determines whether copy is used by augmentation or uses
-     * @throws SourceException
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
      */
-    private void copyDeclaredStmts(RootStatementContext<A, D, E> original, QNameModule newQNameModule,
-            TypeOfCopy typeOfCopy) throws SourceException {
+    private void copyDeclaredStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
+            final TypeOfCopy typeOfCopy) {
         Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
             this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
@@ -66,10 +66,10 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      *
      * @param typeOfCopy
      *            determines whether copy is used by augmentation or uses
-     * @throws SourceException
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException
      */
-    private void copyEffectiveStmts(RootStatementContext<A, D, E> original, QNameModule newQNameModule,
-            TypeOfCopy typeOfCopy) throws SourceException {
+    private void copyEffectiveStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
+            final TypeOfCopy typeOfCopy) {
         Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
         for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
             this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
@@ -100,6 +100,10 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return sourceContext;
     }
 
+    @Override
+    public StorageNodeType getStorageNodeType() {
+        return StorageNodeType.ROOT_STATEMENT_LOCAL;
+    }
     /**
      * @return this as its own root
      */
@@ -120,28 +124,28 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     /**
      * @return copy of this considering {@link TypeOfCopy} (augment, uses)
      *
-     * @throws SourceException instance of SourceException
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
      */
     @Override
-    public StatementContextBase<?, ?, ?> createCopy(StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
-            throws SourceException {
+    public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+            final TypeOfCopy typeOfCopy) {
         return createCopy(null, newParent, typeOfCopy);
     }
 
     /**
      * @return copy of this considering {@link TypeOfCopy} (augment, uses)
      *
-     * @throws SourceException instance of SourceException
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
      */
     @Override
-    public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
-            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy) throws SourceException {
+    public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
+            final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
         RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
 
         copy.addAllToCopyHistory(this.getCopyHistory());
         copy.addToCopyHistory(typeOfCopy);
 
-        if(this.getOriginalCtx() != null) {
+        if (this.getOriginalCtx() != null) {
             copy.setOriginalCtx(this.getOriginalCtx());
         } else {
             copy.setOriginalCtx(this);
@@ -150,32 +154,26 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return copy;
     }
 
-    /**
-     * @return this' argument as it is the only from root (this)
-     */
     @Override
-    public List<Object> getArgumentsFromRoot() {
-        List<Object> argumentList = new LinkedList<>();
-        argumentList.add(argument);
-        return argumentList;
+    public Optional<SchemaPath> getSchemaPath() {
+        return Optional.of(SchemaPath.ROOT);
     }
 
     /**
-     * @return this as it is the only\context from root (this)
+     * @return true
      */
     @Override
-    public List<StmtContext<?, ?, ?>> getStmtContextsFromRoot() {
-        List<StmtContext<?, ?, ?>> stmtContextsList = new LinkedList<>();
-        stmtContextsList.add(this);
-        return stmtContextsList;
+    public boolean isRootContext() {
+        return true;
     }
 
-    /**
-     * @return true
-     */
     @Override
-    public boolean isRootContext() {
+    public boolean isConfiguration() {
         return true;
     }
 
+    @Override
+    public boolean isEnabledSemanticVersioning() {
+        return sourceContext.isEnabledSemanticVersioning();
+    }
 }