BUG-7052: reduce StatementContextBase proliferation even more
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / RootStatementContext.java
index 52c5909149657b17f5c35bbe9cdeb1cb208451f9..7bb341e73c5dc633de57bb2f739d5b800316a736 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 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.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
@@ -61,7 +60,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         final StatementSourceReference ref, final String rawArgument) {
         super(def, ref, rawArgument);
         this.sourceContext = Preconditions.checkNotNull(sourceContext);
-        this.argument = def.parseArgumentValue(this, rawArgument);
+        this.argument = def.parseArgumentValue(this, rawStatementArgument());
     }
 
     RootStatementContext(final SourceSpecificContext sourceContext, final StatementDefinitionContext<A, D, E> def,
@@ -79,12 +78,12 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         sourceContext = Preconditions.checkNotNull(original.sourceContext);
         this.argument = original.argument;
 
-        final Collection<StatementContextBase<?, ?, ?>> declared = original.declaredSubstatements();
-        final Collection<StatementContextBase<?, ?, ?>> effective = original.effectiveSubstatements();
-        final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
+        final Collection<? extends Mutable<?, ?, ?>> declared = original.mutableDeclaredSubstatements();
+        final Collection<? extends Mutable<?, ?, ?>> effective = original.mutableEffectiveSubstatements();
+        final Collection<Mutable<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
 
-        for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
-            if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+        for (final Mutable<?, ?, ?> stmtContext : declared) {
+            if (stmtContext.isSupportedByFeatures()) {
                 buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
             }
         }
@@ -144,7 +143,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
      */
     @Override
-    public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+    public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
             final CopyType typeOfCopy) {
         return createCopy(null, newParent, typeOfCopy);
     }
@@ -189,13 +188,18 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return true;
     }
 
+    @Override
+    public boolean isInYangDataExtensionBody() {
+        return false;
+    }
+
     @Override
     public boolean isEnabledSemanticVersioning() {
         return sourceContext.isEnabledSemanticVersioning();
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(final Class<N> type, final K key,
+    public <K, V, N extends IdentifierNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
             final V value) {
         if (IncludedModuleContext.class.isAssignableFrom(type)) {
             if (includedContexts.isEmpty()) {
@@ -204,7 +208,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
             Verify.verify(value instanceof RootStatementContext);
             includedContexts.add((RootStatementContext<?, ?, ?>) value);
         }
-        super.addToLocalStorage(type, key, value);
+        return super.putToLocalStorage(type, key, value);
     }
 
     @Nullable