Cleanup NamespaceStorageSupport/StmtContext API conflict 87/87287/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 27 Jan 2020 17:58:58 +0000 (18:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jan 2020 10:41:44 +0000 (11:41 +0100)
StmtContext has a few methods that are logically implemented by
NamespaceStorageSupport. Since NamespaceStorageSupport does not
implements StmtContext (nor should it), these methods happen to
work as they overlap with StmtContextBase's mixin -- and they
cannot be simply found by looking for implementations.

Resolve the naming conflict in the most logical way, thus improving
quality of life for everyone :)

Change-Id: I0186a94699c5945b7140bf57ba9e5900e49019d4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit a1721ffa2582da72cb3000cad5c3d7df8a8878e4)
(cherry picked from commit 4e21b29d53a6876a83d0c54af6da08c6456f398a)

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java

index f2a25b45757f9d9279a73890d301bcaf9bd80d15..082f62991679e19e50fe5fa3baafc2e352d983c0 100644 (file)
@@ -26,7 +26,6 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
@@ -104,9 +103,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
                 throw new IllegalArgumentException("Unhandled parser mode " + statementParserMode);
         }
 
-        for (final Entry<ValidationBundleType, Collection<?>> validationBundle : supportedValidation.entrySet()) {
-            addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue());
-        }
+        addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
 
         this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
     }
@@ -132,12 +129,12 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     void setSupportedFeatures(final Set<QName> supportedFeatures) {
-        addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
+        addToNamespace(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
                     ImmutableSet.copyOf(supportedFeatures));
     }
 
     void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
-        addToNs(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
+        addToNamespace(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
                     ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
     }
 
index 8ee75f996dae24866275c362bc9d958a528b0301..eb6dd6a3209412310b949cc5ecf22a57577dcb22 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+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.NamespaceKeyCriterion;
@@ -49,54 +50,31 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         // NOOP
     }
 
-    /**
-     * Return a value associated with specified key within a namespace.
-     *
-     * @param type Namespace type
-     * @param key Key
-     * @param <K> namespace key type
-     * @param <V> namespace value type
-     * @param <N> namespace type
-     * @param <T> key type
-     * @return Value, or null if there is no element
-     * @throws NamespaceNotAvailableException when the namespace is not available.
-     */
-    public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type,
-            final T key) {
-        return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
-    }
-
     public final <K, V, N extends IdentifierNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(
             final Class<N> type, final NamespaceKeyCriterion<K> criterion) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
     }
 
-    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
+    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getNamespace(final Class<N> type) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
     }
 
     @SuppressWarnings("unchecked")
-    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
-            final Class<N> type) {
+    final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getLocalNamespace(final Class<N> type) {
         return (Map<K, V>) namespaces.get(type);
     }
 
-    /**
-     * Associate a value with a key within a namespace.
-     *
-     * @param type Namespace type
-     * @param key Key
-     * @param value value
-     * @param <K> namespace key type
-     * @param <V> namespace value type
-     * @param <N> namespace type
-     * @param <T> key type
-     * @param <U> value type
-     * @throws NamespaceNotAvailableException when the namespace is not available.
-     */
-    public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+    final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNamespace(
             final Class<N> type, final T key, final U value) {
-        getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value);
+        getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
+    }
+
+    final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNamespace(
+            final Class<N> type, final Map<T, U> map) {
+        final NamespaceBehaviour<K, V, N> behavior = getBehaviourRegistry().getNamespaceBehaviour(type);
+        for (final Entry<T, U> validationBundle : map.entrySet()) {
+            behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
+        }
     }
 
     /**
index 9efd3a70e478cbf6d8a72429e9dd357c7c4ede1f..648aae7cdbb11bbc00c07cca0a1d3fbb56799fa5 100644 (file)
@@ -429,7 +429,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         }
 
         // We need to any and all extension statements which have been declared in the context
-        final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getAllFromNamespace(
+        final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getNamespace(
                 StatementDefinitionNamespace.class);
         if (extensions != null) {
             extensions.forEach((qname, support) -> {
index be0948c463e1a9cbd758f51574de9a0f93e42a6d..4d1158bf489723b86866df3e57a80eb39633fa94 100644 (file)
@@ -28,6 +28,7 @@ import java.util.EnumMap;
 import java.util.EventListener;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Optional;
@@ -60,6 +61,7 @@ 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.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -308,9 +310,57 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return getStatementSourceReference().getStatementSource();
     }
 
+    @Override
+    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
+            final Class<N> type) {
+        return getLocalNamespace(type);
+    }
+
+    @Override
+    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
+        return getNamespace(type);
+    }
+
+    /**
+     * Associate a value with a key within a namespace.
+     *
+     * @param type Namespace type
+     * @param key Key
+     * @param value value
+     * @param <K> namespace key type
+     * @param <V> namespace value type
+     * @param <N> namespace type
+     * @param <T> key type
+     * @param <U> value type
+     * @throws NamespaceNotAvailableException when the namespace is not available.
+     */
+    @Override
+    public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+            final Class<N> type, final T key, final U value) {
+        addToNamespace(type, key, value);
+    }
+
     @Override
     public abstract Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements();
 
+    /**
+     * Return a value associated with specified key within a namespace.
+     *
+     * @param type Namespace type
+     * @param key Key
+     * @param <K> namespace key type
+     * @param <V> namespace value type
+     * @param <N> namespace type
+     * @param <T> key type
+     * @return Value, or null if there is no element
+     * @throws NamespaceNotAvailableException when the namespace is not available.
+     */
+    @Override
+    public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type,
+            final T key) {
+        return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
+    }
+
     @Override
     public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
         if (effective instanceof ImmutableCollection) {