Defer copy decisions to StatementSupport
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 6a50e47d4f91992272ee7179125e6cf13fbf3811..32f546d6186c1faf4a381b999f1a80c6c8ba41a0 100644 (file)
@@ -765,12 +765,17 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         addContextToNamespace(namespace, key, stmt);
     }
 
+    @Override
+    public Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> parent, final CopyType type,
+            final QNameModule targetModule) {
+        checkEffectiveModelCompleted(this);
+        return definition.support().copyAsChildOf(this, parent, type, targetModule);
+    }
+
     @Override
     public <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>> Mutable<X, Y, Z> childCopyOf(
             final StmtContext<X, Y, Z> stmt, final CopyType type, final QNameModule targetModule) {
-        checkState(stmt.getCompletedPhase() == ModelProcessingPhase.EFFECTIVE_MODEL,
-                "Attempted to copy statement %s which has completed phase %s", stmt, stmt.getCompletedPhase());
-
+        checkEffectiveModelCompleted(stmt);
         checkArgument(stmt instanceof StatementContextBase, "Unsupported statement %s", stmt);
         return childCopyOf((StatementContextBase<X, Y, Z>)stmt, type, targetModule);
     }
@@ -812,6 +817,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return result;
     }
 
+    private static void checkEffectiveModelCompleted(final StmtContext<?, ?, ?> stmt) {
+        final ModelProcessingPhase phase = stmt.getCompletedPhase();
+        checkState(phase == ModelProcessingPhase.EFFECTIVE_MODEL,
+                "Attempted to copy statement %s which has completed phase %s", stmt, phase);
+    }
+
     @Beta
     public final boolean hasImplicitParentSupport() {
         return definition.getFactory() instanceof ImplicitParentAwareStatementSupport;
@@ -897,7 +908,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         if (fl != 0) {
             return fl == SET_IGNORE_CONFIG;
         }
-        if (definition.isIgnoringConfig() || parent.isIgnoringConfig()) {
+        if (definition.support().isIgnoringConfig() || parent.isIgnoringConfig()) {
             flags |= SET_IGNORE_CONFIG;
             return true;
         }
@@ -918,7 +929,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         if (fl != 0) {
             return fl == SET_IGNORE_IF_FEATURE;
         }
-        if (definition.isIgnoringIfFeatures() || parent.isIgnoringIfFeatures()) {
+        if (definition.support().isIgnoringIfFeatures() || parent.isIgnoringIfFeatures()) {
             flags |= SET_IGNORE_IF_FEATURE;
             return true;
         }