Rework identifier path subscription
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / ModelActionBuilder.java
index 465e7fd4e9ba749752e0aacf7c529370b719bde9..b50b00924fc0e90e52760c70485109ef78dbc9eb 100644 (file)
@@ -99,11 +99,10 @@ public interface ModelActionBuilder {
          * Invoked once all prerequisites were met and forward references were resolved and inference action should be
          * applied. Implementors may perform necessary changes to mutable objects which were declared.
          *
-         * @throws InferenceException If inference action can not be processed.
-         *      Note that this exception be used for user to debug YANG sources,
-         *      so should provide helpful context to fix issue in sources.
+         * @throws InferenceException If inference action can not be processed. Note that this exception be used for
+         *         user to debug YANG sources, so should provide helpful context to fix issue in sources.
          */
-        void apply(InferenceContext ctx) throws InferenceException;
+        void apply(InferenceContext ctx);
 
         /**
          * Invoked once one of prerequisites was not met, even after all other satisfiable inference actions were
@@ -122,7 +121,7 @@ public interface ModelActionBuilder {
          *                            by user to debug YANG sources, hence it should provide helpful context to fix
          *                            the issue in sources.
          */
-        void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException;
+        void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed);
     }
 
     /**
@@ -144,7 +143,8 @@ public interface ModelActionBuilder {
         Prerequisite<D> requiresDeclared(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
 
     /**
-     * Action requires that the specified context completes specified phase.
+     * Action requires that the specified context completes specified phase before {@link #apply(InferenceAction)}
+     * may be invoked.
      *
      * @param context Statement context which needs to complete the transition.
      * @param phase ModelProcessingPhase which must have completed
@@ -160,17 +160,46 @@ public interface ModelActionBuilder {
             StmtContext<?, ?, ?> context, Class<N> namespace, NamespaceKeyCriterion<K> criterion,
             ModelProcessingPhase phase);
 
-    default @Nonnull <T extends Mutable<?, ?, ?>> Prerequisite<T> mutatesEffectiveCtx(final T stmt) {
-        return mutatesCtx(stmt, EFFECTIVE_MODEL);
+    /**
+     * Action mutates the effective model of specified statement. This is a shorthand for
+     * {@code mutatesCtx(context, EFFECTIVE_MODEL}.
+     *
+     * @param context Target statement context
+     * @return A {@link Prerequisite} returning the requested context.
+     */
+    default @Nonnull <T extends Mutable<?, ?, ?>> Prerequisite<T> mutatesEffectiveCtx(final T context) {
+        return mutatesCtx(context, EFFECTIVE_MODEL);
     }
 
     @Nonnull <K, E extends EffectiveStatement<?, ?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>>
         Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
 
-    @Nonnull <C extends StmtContext.Mutable<?, ?, ?>, CT extends C> Prerequisite<C> mutatesCtx(CT root,
+    default @Nonnull <K, E extends EffectiveStatement<?, ?>,
+            N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> Prerequisite<Mutable<?, ?, E>>
+                mutatesEffectiveCtxPath(final StmtContext<?, ?, ?> context, final Class<N> namespace,
+                        final Iterable<K> keys) {
+        throw new UnsupportedOperationException(getClass() + " does not implement mutatesEffectiveCtxPath()");
+    }
+
+    /**
+     * Action mutates the specified statement in the specified phase. Target statement cannot complete specified
+     * phase before this action is applier.
+     *
+     * @param context Target statement context
+     * @return A {@link Prerequisite} returning the requested context.
+     */
+    @Nonnull <C extends Mutable<?, ?, ?>, T extends C> Prerequisite<C> mutatesCtx(T context,
             ModelProcessingPhase phase);
 
-    void apply(InferenceAction action) throws InferenceException;
+    /**
+     * Apply an {@link InferenceAction} when this action's prerequisites are resolved.
+     *
+     * @param action Inference action to apply
+     * @throws InferenceException if the action fails
+     * @throws NullPointerException if {@code action is null}
+     * @throws IllegalStateException if this action has an inference action already associated.
+     */
+    void apply(InferenceAction action);
 
     /**
      * Create a requirement on specified statement context to be declared.