Use instantiatedPolicy() for leaf-list statements
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / BaseOperationContainerStatementSupport.java
index 02ef0c35a311c1bb57b977be393916d285bb1451..498d311c9b58c676fb9082317b1471b874096aac 100644 (file)
@@ -19,12 +19,14 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 /**
- * Specialization of {@link BaseQNameStatementSupport} for {@code input} and {@code output} statements.
+ * Specialization of {@link AbstractQNameStatementSupport} for {@code input} and {@code output} statements.
  *
  * @param <D> Declared Statement representation
  * @param <E> Effective Statement representation
@@ -36,7 +38,7 @@ public abstract class BaseOperationContainerStatementSupport<D extends DeclaredS
 
     protected BaseOperationContainerStatementSupport(final StatementDefinition publicDefinition,
             final Function<QNameModule, QName> createArgument) {
-        super(publicDefinition);
+        super(publicDefinition, uninstantiatedPolicy());
         this.createArgument = requireNonNull(createArgument);
     }
 
@@ -45,10 +47,35 @@ public abstract class BaseOperationContainerStatementSupport<D extends DeclaredS
         return createArgument.apply(StmtContextUtils.getRootModuleQName(ctx));
     }
 
+    @Override
+    protected final @NonNull E copyDeclaredEffective(final Current<QName, D> stmt, final E original) {
+        return copyDeclaredEffective(
+            EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
+            stmt, original);
+    }
+
+    protected abstract @NonNull E copyDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
+        @NonNull E original);
+
+    @Override
+    protected final @NonNull E copyUndeclaredEffective(final Current<QName, D> stmt, final E original) {
+        return copyUndeclaredEffective(
+            EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()),
+            stmt, original);
+    }
+
+    protected abstract @NonNull E copyUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
+        @NonNull E original);
+
     @Override
     protected final @NonNull E createDeclaredEffective(final Current<QName, D> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        return createDeclaredEffective(historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
+        try {
+            return createDeclaredEffective(
+                EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
+        } catch (SubstatementIndexingException e) {
+            throw new SourceException(e.getMessage(), stmt, e);
+        }
     }
 
     protected abstract @NonNull E createDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
@@ -57,7 +84,8 @@ public abstract class BaseOperationContainerStatementSupport<D extends DeclaredS
     @Override
     protected final E createUndeclaredEffective(final Current<QName, D> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        return createUndeclaredEffective(historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
+        return createUndeclaredEffective(EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements),
+            stmt, substatements);
     }
 
     protected abstract @NonNull E createUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt,