Defer copy decisions to StatementSupport
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 3674a94dc13993c7cc40e9b9d766142629e192ba..e47deaa82d0f87f5ad7702edf952a61da61b4b60 100644 (file)
@@ -748,11 +748,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 final Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> 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<?, ?, ?>) stmt, type, targetModule);
     }
@@ -794,6 +800,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;
@@ -879,7 +891,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;
         }
@@ -900,7 +912,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;
         }