CopyHistory and yangVersion merge
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
index 8b1a078154a36cbd62acddd3877efd155b8eab38..15fb8fb6888be08d272e047533390c8a0df03382 100644 (file)
@@ -37,18 +37,18 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc
  * @param <E> Effective Statement representation
  */
 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-        extends CommonStmtCtx {
-    // TODO: gradually migrate callers of this method
+        extends BoundStmtCtx<A>, StmtContextCompat {
+    @Deprecated(forRemoval = true)
     default @NonNull StatementDefinition getPublicDefinition() {
         return publicDefinition();
     }
 
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @NonNull StatementSource getStatementSource() {
         return source();
     }
 
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @NonNull StatementSourceReference getStatementSourceReference() {
         return sourceReference();
     }
@@ -57,8 +57,9 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * Return the statement argument in literal format.
      *
      * @return raw statement argument string, or null if this statement does not have an argument.
+     * @deprecated Use {@link #rawArgument()} instead.
      */
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @Nullable String rawStatementArgument() {
         return rawArgument();
     }
@@ -68,53 +69,51 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      *
      * @return raw statement argument string
      * @throws VerifyException if this statement does not have an argument
+     * @deprecated Use {@link #getRawArgument()} instead.
      */
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @NonNull String coerceRawStatementArgument() {
         return getRawArgument();
     }
 
-    /**
-     * 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();
-
-    /**
-     * Return the parent statement context, forcing a VerifyException if this is the root statement.
-     *
-     * @return context of parent of statement
-     * @throws VerifyException if this statement is the root statement
-     */
-    default @NonNull StmtContext<?, ?, ?> coerceParentContext() {
-        return verifyNotNull(getParentContext(), "Root context %s does not have a parent", this);
-    }
-
     /**
      * Return the statement argument.
      *
      * @return statement argument, or null if this statement does not have an argument
+     * @deprecated Use {@link #argument()} instead.
      */
-    @Nullable A getStatementArgument();
+    @Deprecated(forRemoval = true)
+    default @Nullable A getStatementArgument() {
+        return argument();
+    }
 
     /**
      * Return the statement argument in literal format.
      *
      * @return raw statement argument string
      * @throws VerifyException if this statement does not have an argument
+     * @deprecated Use {@link #getArgument()} instead.
      */
+    @Deprecated(forRemoval = true)
     default @NonNull A coerceStatementArgument() {
-        return verifyNotNull(getStatementArgument(), "Statement context %s does not have an argument", this);
+        return getArgument();
     }
 
-    default <X, Y extends DeclaredStatement<X>> boolean producesDeclared(final Class<? super Y> type) {
-        return type.isAssignableFrom(publicDefinition().getDeclaredRepresentationClass());
-    }
+    /**
+     * 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();
 
-    default <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<A, D>> boolean producesEffective(
-            final Class<? super Z> type) {
-        return type.isAssignableFrom(publicDefinition().getEffectiveRepresentationClass());
+    /**
+     * Return the parent statement context, forcing a VerifyException if this is the root statement.
+     *
+     * @return context of parent of statement
+     * @throws VerifyException if this statement is the root statement
+     */
+    default @NonNull StmtContext<?, ?, ?> coerceParentContext() {
+        return verifyNotNull(getParentContext(), "Root context %s does not have a parent", this);
     }
 
     boolean isConfiguration();
@@ -140,6 +139,11 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
 
+    /**
+     * Returns the model root for this statement.
+     *
+     * @return root context of statement
+     */
     @NonNull RootStmtContext<?, ?, ?> getRoot();
 
     /**
@@ -183,7 +187,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     /*
      * FIXME: YANGTOOLS-784: the next three methods are closely related to the copy process:
-     *        - getCopyHistory() is a brief summary of what went on
+     *        - copyHistory() is a brief summary of what went on
      *        - getOriginalContext() points to the CopyHistory.ORIGINAL
      *        - getPreviousCopyCtx() points to the immediate predecessor forming a singly-linked list terminated
      *          at getOriginalContext()
@@ -194,13 +198,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      *        and hence should become arguments to that method.
      */
 
-    /**
-     * Return the executive summary of the copy process that has produced this context.
-     *
-     * @return A simplified summary of the copy process.
-     */
-    CopyHistory getCopyHistory();
-
     /**
      * Return the statement context of the original definition, if this statement is an instantiated copy.
      *
@@ -218,13 +215,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     ModelProcessingPhase getCompletedPhase();
 
-    /**
-     * Return version of root statement context.
-     *
-     * @return version of root statement context
-     */
-    @NonNull YangVersion getRootVersion();
-
     /**
      * An mutable view of an inference context associated with an instance of a statement.
      *
@@ -293,6 +283,17 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
             return childCopyOf(stmt, type, null);
         }
 
+        /**
+         * Create a replica of this statement as a substatement of specified {@code parent}. The replica must not be
+         * modified and acts as a source of {@link EffectiveStatement} from outside of {@code parent}'s subtree.
+         *
+         * @param parent Parent of the replica statement
+         * @return replica of this statement
+         * @throws IllegalArgumentException if this statement cannot be replicated into parent, for example because it
+         *                                  comes from an alien implementation.
+         */
+        @NonNull Mutable<A, D, E> replicaAsChildOf(Mutable<?, ?, ?> parent);
+
         @Beta
         @NonNull Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(Mutable<?, ?, ?> parent, CopyType type,
                 @Nullable QNameModule targetModule);