BUG-6972: Do not allow root StmtContext to be copied
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
index b26b1d6349e262d046e21d0adddd27d9b25a057e..a54ae2744a74c7a4ecaef51bca0e75d16a43788f 100644 (file)
@@ -36,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();
@@ -114,9 +116,19 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
 
-    StatementContextBase<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
+    /**
+     * @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<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
+    /**
+     * @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();
@@ -125,8 +137,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     StmtContext<?, ?, ?> getOriginalCtx();
 
-    boolean isRootContext();
-
     int getOrder();
 
     ModelProcessingPhase getCompletedPhase();
@@ -142,23 +152,20 @@ 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();
 
-        @Override
         @Nonnull
-        Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+        Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements();
 
-        @Override
         @Nonnull
-        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+        Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements();
 
         /**
          * Create a new inference action to be executed during specified phase. The action cannot be cancelled
@@ -180,8 +187,8 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          * @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);
+        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
+                StmtContext<?, ?, ?> stmt);
 
         /**
          * Set version of root statement context.
@@ -224,10 +231,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
         void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
 
-        void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
-
-        void setOriginalCtx(StmtContext<?, ?, ?> originalCtx);
-
         void setOrder(int order);
 
         // FIXME: this seems to be unused, but looks useful.