Add a missing space
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / RootStatementContext.java
index f10533b5cfb2c3ecf646608a7ea198ba386fcf83..c8a8dcc986a1fb64ad9b4d9ed771664487173ccf 100644 (file)
@@ -13,6 +13,7 @@ import static com.google.common.base.Verify.verify;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -27,25 +28,37 @@ import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 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.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 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.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.RootStmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Root statement class for a YANG source. All statements defined in that YANG source are mapped underneath an instance
  * of this class, hence recursive lookups from them cross this class.
  */
-public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
-        AbstractResumedStatement<A, D, E> {
-
+public final class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+        extends AbstractResumedStatement<A, D, E> implements RootStmtContext.Mutable<A, D, E> {
     public static final YangVersion DEFAULT_VERSION = YangVersion.VERSION_1;
 
+    private static final Logger LOG = LoggerFactory.getLogger(RootStatementContext.class);
+    // These namespaces are well-known and not needed after the root is cleaned up
+    private static final Map<Class<?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
+        GroupingNamespace.class, new SweptNamespace(GroupingNamespace.class),
+        SchemaTreeNamespace.class, new SweptNamespace(SchemaTreeNamespace.class),
+        TypeNamespace.class, new SweptNamespace(TypeNamespace.class));
+
     private final @NonNull SourceSpecificContext sourceContext;
     private final A argument;
 
@@ -62,7 +75,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         final StatementSourceReference ref, final String rawArgument) {
         super(def, ref, rawArgument);
         this.sourceContext = requireNonNull(sourceContext);
-        this.argument = def.parseArgumentValue(this, rawStatementArgument());
+        this.argument = def.parseArgumentValue(this, rawArgument());
     }
 
     RootStatementContext(final SourceSpecificContext sourceContext, final StatementDefinitionContext<A, D, E> def,
@@ -101,22 +114,23 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     @Override
-    public A getStatementArgument() {
+    public A argument() {
         return argument;
     }
 
     @Override
-    public Optional<SchemaPath> getSchemaPath() {
+    @Deprecated
+    public Optional<SchemaPath> schemaPath() {
         return Optional.of(SchemaPath.ROOT);
     }
 
     @Override
-    public boolean isConfiguration() {
-        return true;
+    public EffectiveConfig effectiveConfig() {
+        return EffectiveConfig.UNDETERMINED;
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
             final V value) {
         if (IncludedModuleContext.class.isAssignableFrom(type)) {
             if (includedContexts.isEmpty()) {
@@ -129,7 +143,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
         return getFromLocalStorage(type, key, new HashSet<>());
     }
 
@@ -137,7 +151,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      * We need to track already checked RootStatementContexts due to possible
      * circular chains of includes between submodules
      */
-    private <K, V, N extends IdentifierNamespace<K, V>> @Nullable V getFromLocalStorage(final Class<N> type,
+    private <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(final Class<N> type,
             final K key, final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
         final V potentialLocal = super.getFromLocalStorage(type, key);
         if (potentialLocal != null) {
@@ -158,7 +172,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
         return getAllFromLocalStorage(type, new HashSet<>());
     }
 
@@ -166,7 +180,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      * We need to track already checked RootStatementContexts due to possible
      * circular chains of includes between submodules
      */
-    private <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final Class<N> type,
+    private <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final Class<N> type,
             final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
         final Map<K, V> potentialLocal = super.getAllFromLocalStorage(type);
         if (potentialLocal != null) {
@@ -223,7 +237,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     boolean isEnabledSemanticVersioningImpl() {
-        return sourceContext.isEnabledSemanticVersioning();
+        return sourceContext.globalContext().isEnabledSemanticVersioning();
     }
 
     @NonNull YangVersion getRootVersionImpl() {
@@ -231,15 +245,22 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     void setRootVersionImpl(final YangVersion version) {
-        checkArgument(sourceContext.getSupportedVersions().contains(version),
-                "Unsupported yang version %s in %s", version, getStatementSourceReference());
+        checkArgument(sourceContext.globalContext().getSupportedVersions().contains(version),
+                "Unsupported yang version %s in %s", version, sourceReference());
         checkState(this.rootVersion == null, "Version of root %s has been already set to %s", argument,
                 this.rootVersion);
         this.rootVersion = requireNonNull(version);
     }
 
-    void addMutableStmtToSealImpl(final MutableStatement mutableStatement) {
-        sourceContext.addMutableStmtToSeal(mutableStatement);
+    /**
+     * Add mutable statement to seal. Each mutable statement must be sealed
+     * as the last step of statement parser processing.
+     *
+     * @param mutableStatement
+     *            mutable statement which should be sealed
+     */
+    void addMutableStmtToSeal(final MutableStatement mutableStatement) {
+        sourceContext.globalContext().addMutableStmtToSeal(mutableStatement);
     }
 
     void addRequiredSourceImpl(final SourceIdentifier dependency) {
@@ -253,6 +274,12 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
 
     @Override
     StatementContextBase<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
-        throw new UnsupportedOperationException("Root statement cannot be reparented to" + newParent);
+        throw new UnsupportedOperationException("Root statement cannot be reparented to " + newParent);
+    }
+
+    @Override
+    void sweepNamespaces() {
+        LOG.trace("Sweeping root {}", this);
+        sweepNamespaces(SWEPT_NAMESPACES);
     }
 }