Do not force materialization when not needed
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StatementFactory.java
index f929529c63277cefa8ac569d23af7d34606800e4..793c0e3534fb00b4cf3b97be41942d57486c5646 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
+import java.util.Collection;
 import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 
 /**
  * An entity capable of creating {@link DeclaredStatement} and {@link EffectiveStatement} instances for a particular
@@ -38,4 +40,22 @@ public interface StatementFactory<A, D extends DeclaredStatement<A>, E extends E
     @NonNull E createEffective(EffectiveStmtCtx.@NonNull Current<A, D> stmt,
         Stream<? extends StmtContext<?, ?, ?>> declaredSubstatements,
         Stream<? extends StmtContext<?, ?, ?>> effectiveSubstatements);
+
+    /**
+     * Determine reactor copy behaviour of a statement instance. Implementations classes are required to determine
+     * their operations with regard to their statements being replicated into different contexts -- potentially sharing
+     * instantiations.
+     *
+     * <p>
+     * Implementations are examine {@code copy} as to whether it would result in the same semantics as {@code current}
+     * does, provided that {@code current}'s {@code substatements} are properly propagated.
+     *
+     * @param copy Copy of current effective context
+     * @param current Current effective context
+     * @param substatements Current effective substatements
+     * @return True if the differences between {@code copy} and {@code current} do not affect this statement's effective
+     *         semantics.
+     */
+    boolean canReuseCurrent(@NonNull Current<A, D> copy, @NonNull Current<A, D> current,
+        @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
 }