Unify NamespaceStmtCtx.localNamespacePortion() 15/94115/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Dec 2020 15:15:20 +0000 (16:15 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Dec 2020 15:54:51 +0000 (16:54 +0100)
We have two under-documented methods, localNamespace() and
getAllFromCurrentStmtCtxNamespace(). Unify them and add proper
documentation.

Change-Id: I743c63d44c7127f58cea1b207539abb71a6d78ac
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/odlext-parser-support/src/main/java/org/opendaylight/yangtools/odlext/parser/AnyxmlStatementSupportOverride.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/SubmoduleEffectiveStatementImpl.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java

index e63e60d219d2cbec258d21b6ab8c18c24ff8e2f7..7dc10a6a64e983863ebea2ba51ad70067fd960a0 100644 (file)
@@ -59,7 +59,7 @@ public final class AnyxmlStatementSupportOverride
 
         final Map<StatementDefinition, Mutable<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
                 AnyxmlSchemaLocationEffectiveStatement>> schemaLocations =
-                stmt.getAllFromCurrentStmtCtxNamespace(AnyxmlSchemaLocationNamespace.class);
+                stmt.localNamespacePortion(AnyxmlSchemaLocationNamespace.class);
         if (schemaLocations != null && !schemaLocations.isEmpty()) {
             final SchemaNodeIdentifier anyXmlSchemaNodeIdentifier = schemaLocations.values().iterator().next()
                     .argument();
index e51579b703b4743ed8036911c9f32d62e5f9f810..144c0a3b9dfa34bca29d9834f2ba42515a1b35c9 100644 (file)
@@ -296,7 +296,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     }
 
     @Override
-    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> localNamespace(final Class<@NonNull N> type) {
+    public final <K, V, N extends IdentifierNamespace<K, V>>
+            Map<K, V> localNamespacePortion(final Class<@NonNull N> type) {
         return getLocalNamespace(type);
     }
 
index c6480ee02569871e121d4f047b7818231735d1e1..6c4e8586c4b17783e47d5f707913a52b2a7596d0 100644 (file)
@@ -80,21 +80,21 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleS
         namespaceToPrefix = ImmutableMap.copyOf(tmp);
 
         final Map<String, StmtContext<?, ?, ?>> includedSubmodules =
-                stmt.getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToModuleCtx.class);
+                stmt.localNamespacePortion(IncludedSubmoduleNameToModuleCtx.class);
         nameToSubmodule = includedSubmodules == null ? ImmutableMap.of()
                 : ImmutableMap.copyOf(Maps.transformValues(includedSubmodules,
                     submodule -> (SubmoduleEffectiveStatement) submodule.buildEffective()));
 
         final Map<QName, StmtContext<?, ExtensionStatement, ExtensionEffectiveStatement>> extensions =
-                stmt.getAllFromCurrentStmtCtxNamespace(ExtensionNamespace.class);
+                stmt.localNamespacePortion(ExtensionNamespace.class);
         qnameToExtension = extensions == null ? ImmutableMap.of()
                 : ImmutableMap.copyOf(Maps.transformValues(extensions, StmtContext::buildEffective));
         final Map<QName, StmtContext<?, FeatureStatement, FeatureEffectiveStatement>> features =
-                stmt.getAllFromCurrentStmtCtxNamespace(FeatureNamespace.class);
+                stmt.localNamespacePortion(FeatureNamespace.class);
         qnameToFeature = features == null ? ImmutableMap.of()
                 : ImmutableMap.copyOf(Maps.transformValues(features, StmtContext::buildEffective));
         final Map<QName, StmtContext<?, IdentityStatement, IdentityEffectiveStatement>> identities =
-                stmt.getAllFromCurrentStmtCtxNamespace(IdentityNamespace.class);
+                stmt.localNamespacePortion(IdentityNamespace.class);
         qnameToIdentity = identities == null ? ImmutableMap.of()
                 : ImmutableMap.copyOf(Maps.transformValues(identities, StmtContext::buildEffective));
     }
index 65ada4e4e091d1f6ec8bc14cdadca1c73f853ff1..f4e50daeabd24d449a5a3c376f3df4dc7d39ad01 100644 (file)
@@ -277,7 +277,7 @@ public final class ModuleStatementSupport
     }
 
     private static Collection<StmtContext<?, ?, ?>> submoduleContexts(final Current<?, ?> stmt) {
-        final Map<String, StmtContext<?, ?, ?>> submodules = stmt.getAllFromCurrentStmtCtxNamespace(
+        final Map<String, StmtContext<?, ?, ?>> submodules = stmt.localNamespacePortion(
             IncludedSubmoduleNameToModuleCtx.class);
         return submodules == null ? List.of() : submodules.values();
     }
index 6141b8fcf7a300598cf66ad27a70fe1ba3f0c778..71b2b4bfb34c72a977f418b1f64ad64f8fa41fd7 100644 (file)
@@ -82,7 +82,7 @@ final class SubmoduleEffectiveStatementImpl
          * collect only submodule contexts here and then build them during
          * sealing of this statement.
          */
-        final Map<String, StmtContext<?, ?, ?>> includedSubmodulesMap = stmt.getAllFromCurrentStmtCtxNamespace(
+        final Map<String, StmtContext<?, ?, ?>> includedSubmodulesMap = stmt.localNamespacePortion(
             IncludedSubmoduleNameToModuleCtx.class);
         if (includedSubmodulesMap != null) {
             final Set<StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>> submoduleContextsInit =
index dcfb541372cf26f629476c5161ab1a8dcd51fa6b..8806c13c7527486dcf1d814f542fa8d7dc6bbad2 100644 (file)
@@ -43,13 +43,21 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      */
     <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V namespaceItem(Class<@NonNull N> nsType, T key);
 
-    <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> localNamespace(Class<@NonNull N> nsType);
-
-    // TODO: migrate users away
-    default <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
-            final Class<@NonNull N> nsType) {
-        return localNamespace(nsType);
-    }
+    /**
+     * Return the portion of specified namespace stored in this node. Depending on namespace behaviour this may or may
+     * not represent the complete contents of the namespace as available via {@link #namespace(Class)}.
+     *
+     * <p>
+     * This partial view is useful when the need is not to perform a proper namespace lookup, but rather act on current
+     * statement's contribution to the namespace.
+     *
+     * @param <K> namespace key type
+     * @param <V> namespace value type
+     * @param <N> namespace type
+     * @param nsType namespace type class
+     * @return Namespace portion stored in this node, if available
+     */
+    <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(Class<@NonNull N> nsType);
 
     /**
      * Return the selected namespace.