Separate out StatementSupport.applyCopyPolicy()
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / InferredStatementContext.java
index b3f7278a884c32f1c12dded48f8ab356a05bac72..fb691e3c319ed460947c4be3b48cc7d6528fdcbd 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.OnDemandSchemaTreeStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextDefaults;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.slf4j.Logger;
@@ -191,7 +190,7 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
     public <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
             final @NonNull Class<Z> type) {
         if (substatements instanceof List) {
-            return StmtContextDefaults.findSubstatementArgument(this, type);
+            return super.findSubstatementArgument(type);
         }
 
         final Optional<X> templateArg = prototype.findSubstatementArgument(type);
@@ -207,13 +206,13 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
 
     @Override
     public boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
-        return substatements instanceof List ? StmtContextDefaults.hasSubstatement(prototype, type)
+        return substatements instanceof List ? super.hasSubstatement(type)
             // We do not allow deletion of partially-materialized statements, hence this is accurate
             : prototype.hasSubstatement(type);
     }
 
     @Override
-    public <Y extends DeclaredStatement<QName>, Z extends EffectiveStatement<QName, Y>>
+    public <Y extends DeclaredStatement<QName>, Z extends SchemaTreeEffectiveStatement<Y>>
             StmtContext<QName, Y, Z> requestSchemaTreeChild(final QName qname) {
         if (substatements instanceof List) {
             // We have performed materialization, hence we have triggered creation of all our schema tree child
@@ -247,8 +246,8 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
 
         @SuppressWarnings("unchecked")
         final Mutable<QName, Y, Z> ret = (Mutable<QName, Y, Z>) copySubstatement((Mutable<?, ?, ?>) template)
-            .orElseThrow(() -> new InferenceException(sourceReference(),
-                "Failed to materialize child %s template %s", qname, template));
+            .orElseThrow(
+                () -> new InferenceException(this, "Failed to materialize child %s template %s", qname, template));
         ensureCompletedPhase(ret);
         addMaterialized(template, ret);
 
@@ -294,6 +293,14 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
         verify(substatements != SWEPT_SUBSTATEMENTS, "Attempted to access substatements of %s", this);
     }
 
+    @Override
+    void markNoParentRef() {
+        final Object local = substatements;
+        if (local != null) {
+            markNoParentRef(castEffective(local));
+        }
+    }
+
     @Override
     int sweepSubstatements() {
         final Object local = substatements;
@@ -369,6 +376,10 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
     }
 
     private Optional<? extends Mutable<?, ?, ?>> copySubstatement(final Mutable<?, ?, ?> substatement) {
+        // FIXME: YANGTOOLS-1195: this is not exactly what we want to do here, because we are deling with two different
+        //                        requests: copy for inference purposes (this method), while we also copy for purposes
+        //                        of buildEffective() -- in which case we want to probably invoke asEffectiveChildOf()
+        //                        or similar
         return substatement.copyAsChildOf(this, childCopyType, targetModule);
     }
 
@@ -450,8 +461,8 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
     }
 
     @Override
-    public boolean effectiveConfig() {
-        return isConfiguration(parent);
+    public EffectiveConfig effectiveConfig() {
+        return effectiveConfig(parent);
     }
 
     @Override