Move findSubstatementArgument()/hasSubstatement() to BoundStmtCtx
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
index e96b8530c3da9cf38f3040ba49a61b317f3f752a..dcbafed8370a66040a122221326d568ceb72555d 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.base.VerifyException;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Streams;
 import java.util.Collection;
-import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNull;
@@ -37,7 +36,7 @@ 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 BoundStmtCtx<A> {
+        extends NamespaceStmtCtx, BoundStmtCtxCompat<A, D> {
     @Deprecated(forRemoval = true)
     default @NonNull StatementDefinition getPublicDefinition() {
         return publicDefinition();
@@ -69,8 +68,9 @@ 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();
     }
@@ -79,8 +79,9 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * Return the statement argument.
      *
      * @return statement argument, or null if this statement does not have an argument
+     * @deprecated Use {@link #argument()} instead.
      */
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @Nullable A getStatementArgument() {
         return argument();
     }
@@ -90,8 +91,9 @@ 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 #getArgument()} instead.
      */
-    // TODO: gradually migrate callers of this method
+    @Deprecated(forRemoval = true)
     default @NonNull A coerceStatementArgument() {
         return getArgument();
     }
@@ -113,29 +115,13 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         return verifyNotNull(getParentContext(), "Root context %s does not have a parent", this);
     }
 
-    boolean isConfiguration();
-
     boolean isEnabledSemanticVersioning();
 
     /**
-     * Return a value associated with specified key within a namespace.
+     * Returns the model root for this statement.
      *
-     * @param type Namespace type
-     * @param key Key
-     * @param <K> namespace key type
-     * @param <V> namespace value type
-     * @param <N> namespace type
-     * @param <T> key type
-     * @return Value, or null if there is no element
-     * @throws NamespaceNotAvailableException when the namespace is not available.
+     * @return root context of statement
      */
-    <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
-            T key);
-
-    <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(Class<N> type);
-
-    <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
-
     @NonNull RootStmtContext<?, ?, ?> getRoot();
 
     /**
@@ -161,11 +147,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         return Streams.concat(declaredSubstatements().stream(), effectiveSubstatements().stream());
     }
 
-    /**
-     * Builds {@link DeclaredStatement} for statement context.
-     */
-    D buildDeclared();
-
     /**
      * Builds {@link EffectiveStatement} for statement context.
      */
@@ -179,7 +160,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()
@@ -190,13 +171,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.
      *
@@ -214,13 +188,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.
      *
@@ -289,6 +256,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);
@@ -376,38 +354,4 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
         void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
     }
-
-    /**
-     * Search of any child statement context of specified type and return its argument. If such a statement exists, it
-     * is assumed to have the right argument. Users should be careful to use this method for statements which have
-     * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
-     *
-     * <p>
-     * The default implementation defers to
-     * {@link StmtContextDefaults#findSubstatementArgument(StmtContext, Class)}, subclasses are expected to provide
-     * optimized implementation if possible.
-     *
-     * @param <X> Substatement argument type
-     * @param <Z> Substatement effective statement representation
-     * @param type Effective statement representation being look up
-     * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
-     */
-    default <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
-            final @NonNull Class<Z> type) {
-        return StmtContextDefaults.findSubstatementArgument(this, type);
-    }
-
-    /**
-     * Check if there is any child statement context of specified type.
-     *
-     * <p>
-     * The default implementation defers to {@link StmtContextDefaults#hasSubstatement(StmtContext, Class)},
-     * subclasses are expected to provide optimized implementation if possible.
-     *
-     * @param type Effective statement representation being look up
-     * @return True if such a child statement exists, false otherwise
-     */
-    default boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
-        return StmtContextDefaults.hasSubstatement(this, type);
-    }
 }