BUG-6972: eliminate StmtContext.getOrder()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
index bd0e1d83229b89b61582b26569d13e302aa65702..ac2d6a914d671982c3b48136b41236cd248b67ae 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
-import com.google.common.base.Optional;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -21,7 +21,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-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.StatementContextBase;
 
@@ -37,7 +36,9 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
     StatementDefinition getPublicDefinition();
 
     /**
-     * @return context of parent of statement
+     * Return the parent statement context, or null if this is the root statement.
+     *
+     * @return context of parent of statement, or null if this is the root statement.
      */
     @Nullable
     StmtContext<?, ?, ?> getParentContext();
@@ -53,7 +54,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     /**
      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
-     * {@link Optional#absent()} is returned.
+     * {@link Optional#empty()} is returned.
      *
      * @return Optional SchemaPath
      */
@@ -61,6 +62,15 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     boolean isConfiguration();
 
+    /**
+     * Checks whether this statement is placed within a 'yang-data' extension statement.
+     * Some YANG statements are constrained when used within a 'yang-data' statement.
+     * See the following link for more information - https://tools.ietf.org/html/rfc8040#section-8
+     *
+     * @return true if it is placed within a 'yang-data' extension statement, otherwise false
+     */
+    boolean isInYangDataExtensionBody();
+
     boolean isEnabledSemanticVersioning();
 
     @Nonnull
@@ -81,7 +91,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * @return Collection of declared substatements
      */
     @Nonnull
-    Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+    Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
 
     /**
      * Return effective substatements. These are the statements which are added as this statement's substatements
@@ -90,51 +100,42 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * @return Collection of declared substatements
      */
     @Nonnull
-    Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+    Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
 
+    /**
+     * Builds {@link DeclaredStatement} for statement context.
+     */
     D buildDeclared();
 
+    /**
+     * Builds {@link EffectiveStatement} for statement context
+     */
     E buildEffective();
 
     boolean isSupportedToBuildEffective();
 
-    void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
-
-    Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
+    Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
 
-    void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
-
-    void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
-
-    StatementContextBase<?, ?, ?> createCopy(
-            StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
-            throws SourceException;
+    /**
+     * @return copy of this considering {@link CopyType} (augment, uses)
+     *
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
+     */
+    Mutable<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
 
-    StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
-            StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
-            throws SourceException;
+    /**
+     * @return copy of this considering {@link CopyType} (augment, uses)
+     *
+     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
+     */
+    Mutable<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
+            CopyType typeOfCopy);
 
     CopyHistory getCopyHistory();
 
-    enum SupportedByFeatures {
-        UNDEFINED, SUPPORTED, NOT_SUPPORTED
-    }
-
-    SupportedByFeatures getSupportedByFeatures();
-
-    void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
-
-    StatementContextBase<?, ?, ?> getOriginalCtx();
-
-    void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
-
-    boolean isRootContext();
+    boolean isSupportedByFeatures();
 
-    void setOrder(int order);
-
-    int getOrder();
-
-    void setCompletedPhase(ModelProcessingPhase completedPhase);
+    Optional<StmtContext<?, ?, ?>> getOriginalCtx();
 
     ModelProcessingPhase getCompletedPhase();
 
@@ -149,30 +150,43 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
             extends StmtContext<A, D, E> {
 
         @Override
-        StmtContext.Mutable<?, ?, ?> getParentContext();
+        Mutable<?, ?, ?> getParentContext();
 
-        <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
-                Class<N> type, KT key, VT value)
-                throws NamespaceNotAvailableException;
+        <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, KT key,
+                VT value) throws NamespaceNotAvailableException;
 
         @Nonnull
         @Override
-        StmtContext.Mutable<?, ?, ?> getRoot();
+        Mutable<?, ?, ?> getRoot();
+
+        @Nonnull
+        Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements();
+
+        @Nonnull
+        Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements();
 
         /**
          * Create a new inference action to be executed during specified phase. The action cannot be cancelled
          * and will be executed even if its definition remains incomplete.
          *
-         * @param phase Target phase
+         * @param phase Target phase in which the action will resolved.
          * @return A new action builder.
          * @throws NullPointerException if the specified phase is null
          */
         @Nonnull ModelActionBuilder newInferenceAction(@Nonnull ModelProcessingPhase phase);
 
-        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
-                Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
-
-        void setSupportedByFeatures(boolean isSupported);
+        /**
+         * adds statement to namespace map with the key
+         *
+         * @param namespace
+         *            {@link StatementNamespace} child that determines namespace to be added to
+         * @param key
+         *            of type according to namespace class specification
+         * @param stmt
+         *            to be added to namespace map
+         */
+        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
+                StmtContext<?, ?, ?> stmt);
 
         /**
          * Set version of root statement context.
@@ -201,6 +215,10 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          */
         void addRequiredModule(ModuleIdentifier dependency);
 
+        void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
+
+        void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
+
         /**
          * Set identifier of current root context.
          *
@@ -208,5 +226,10 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          *            of current root context
          */
         void setRootIdentifier(ModuleIdentifier identifier);
+
+        void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+
+        // FIXME: this seems to be unused, but looks useful.
+        void setCompletedPhase(ModelProcessingPhase completedPhase);
     }
 }