Rename NamespaceStorageSupport
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / BuildGlobalContext.java
index d66cc0c31301beb791875bed39ffadf944fabea1..c8cdf662c634f375c1317ae3ddf99e619b31dd4b 100644 (file)
@@ -12,7 +12,6 @@ import static com.google.common.base.Verify.verify;
 import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Verify;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -47,16 +46,12 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour
 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;
-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.NamespaceNotAvailableException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceStorage;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-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.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
@@ -65,7 +60,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
+final class BuildGlobalContext extends AbstractNamespaceStorage {
     private static final Logger LOG = LoggerFactory.getLogger(BuildGlobalContext.class);
 
     private static final ModelProcessingPhase[] PHASE_EXECUTION_ORDER = {
@@ -130,25 +125,20 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     @Override
-    public StorageNodeType getStorageNodeType() {
-        return StorageNodeType.GLOBAL;
+    public StorageType getStorageType() {
+        return StorageType.GLOBAL;
     }
 
     @Override
-    public NamespaceStorageNode getParentNamespaceStorage() {
+    public NamespaceStorage getParentStorage() {
         return null;
     }
 
     @Override
-    Registry getBehaviourRegistry() {
-        return this;
-    }
-
-    @Override
-    public <K, V> NamespaceBehaviourWithListeners<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
+    <K, V> NamespaceBehaviourWithListeners<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
         NamespaceBehaviourWithListeners<?, ?> potential = supportedNamespaces.get(type);
         if (potential == null) {
-            final var potentialRaw = verifyNotNull(supports.get(currentPhase)).getNamespaceBehaviour(type);
+            final var potentialRaw = verifyNotNull(supports.get(currentPhase)).namespaceBehaviourOf(type);
             if (potentialRaw != null) {
                 potential = createNamespaceContext(potentialRaw);
                 supportedNamespaces.put(type, potential);
@@ -158,7 +148,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
             }
         }
 
-        Verify.verify(type.equals(potential.getIdentifier()));
+        verify(type.equals(potential.namespace()));
         /*
          * Safe cast, previous checkState checks equivalence of key from which
          * type argument are derived
@@ -218,16 +208,16 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
 
     private ReactorDeclaredModel transform() {
         checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
-        final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
-        for (final SourceSpecificContext source : sources) {
-            rootStatements.add(source.getRoot().declared());
+        final var rootStatements = new ArrayList<DeclaredStatement<?>>(sources.size());
+        for (var source : sources) {
+            rootStatements.add(source.declaredRoot());
         }
         return new ReactorDeclaredModel(rootStatements);
     }
 
     private SomeModifiersUnresolvedException propagateException(final SourceSpecificContext source,
             final RuntimeException cause) throws SomeModifiersUnresolvedException {
-        final SourceIdentifier sourceId = createSourceIdentifier(source.getRoot());
+        final SourceIdentifier sourceId = source.identifySource();
         if (!(cause instanceof SourceException)) {
             /*
              * This should not be happening as all our processing should provide SourceExceptions.
@@ -241,32 +231,16 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
         throw new SomeModifiersUnresolvedException(currentPhase, sourceId, cause);
     }
 
-    private static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
-        final QNameModule qNameModule = root.namespaceItem(ParserNamespaces.MODULECTX_TO_QNAME, root);
-        final Object arg = root.getArgument();
-        verify(arg instanceof Unqualified, "Unexpected argument %s", arg);
-
-        if (qNameModule != null) {
-            // creates SourceIdentifier for a module
-            return new SourceIdentifier((Unqualified) arg, qNameModule.getRevision().orElse(null));
-        }
-
-        // creates SourceIdentifier for a submodule
-        return new SourceIdentifier((Unqualified) arg,
-            StmtContextUtils.getLatestRevision(root.declaredSubstatements()).orElse(null));
-    }
-
     @SuppressWarnings("checkstyle:illegalCatch")
     private EffectiveSchemaContext transformEffective() throws ReactorException {
         checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
-        final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
-        final List<EffectiveStatement<?, ?>> rootEffectiveStatements = new ArrayList<>(sources.size());
+        final var rootStatements = new ArrayList<DeclaredStatement<?>>(sources.size());
+        final var rootEffectiveStatements = new ArrayList<EffectiveStatement<?, ?>>(sources.size());
 
-        for (final SourceSpecificContext source : sources) {
-            final RootStatementContext<?, ?, ?> root = source.getRoot();
+        for (var source : sources) {
             try {
-                rootStatements.add(root.declared());
-                rootEffectiveStatements.add(root.buildEffective());
+                rootStatements.add(source.declaredRoot());
+                rootEffectiveStatements.add(source.effectiveRoot());
             } catch (final RuntimeException ex) {
                 throw propagateException(source, ex);
             }
@@ -340,7 +314,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
 
             if (!addedCause) {
                 addedCause = true;
-                final SourceIdentifier sourceId = createSourceIdentifier(failedSource.getRoot());
+                final SourceIdentifier sourceId = failedSource.identifySource();
                 buildFailure = new SomeModifiersUnresolvedException(currentPhase, sourceId, sourceEx);
             } else {
                 buildFailure.addSuppressed(sourceEx);