Disconnect StatementSupportBundle/NamespaceBehaviour.Registry 63/105263/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Apr 2023 19:42:37 +0000 (21:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Apr 2023 20:52:37 +0000 (22:52 +0200)
StatementSupportBundle is a very concrete class and
NamespaceBehaviour.Registry is a general interface. There is a
connection between them in that other Registry implementations are using
StatementSupportBundle -- but other than that, there is just the
self-similar binding to StatementSupportBundle.parent.

Disconnect these two classes to allow them to go their separate ways.

JIRA: YANGTOOLS-1498
Change-Id: I177b11def897f15b1be7e251d2f1712386a102f8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java

index 75bc2926000ba5e8a4201ebe38693622d38d121c..b55e6b1dc42961013b020e840e9902a70609f91d 100644 (file)
@@ -145,7 +145,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     public <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);
index d1abe31f84306c57185b0a63f39c4ebad26f1e41..5e8c4a0d2f34a280ed4736e5e0afa914f42f1274 100644 (file)
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -27,8 +28,7 @@ import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class StatementSupportBundle implements Immutable, NamespaceBehaviour.Registry {
-
+public final class StatementSupportBundle implements Immutable {
     private static final StatementSupportBundle EMPTY = new StatementSupportBundle(null, null, ImmutableMap.of(),
             ImmutableMap.of(), ImmutableTable.of());
 
@@ -40,14 +40,15 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
 
     private StatementSupportBundle(final StatementSupportBundle parent,
             final ImmutableSet<YangVersion> supportedVersions,
-            final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonStatements,
-            final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?>> namespaces,
-            final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements) {
+            final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonDefinitions,
+            final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?>> namespaceDefinitions,
+            final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificDefinitions) {
         this.parent = parent;
+        // FIXME: should requireNonNull()
         this.supportedVersions = supportedVersions;
-        commonDefinitions = commonStatements;
-        namespaceDefinitions = namespaces;
-        versionSpecificDefinitions = versionSpecificStatements;
+        this.commonDefinitions = requireNonNull(commonDefinitions);
+        this.namespaceDefinitions = requireNonNull(namespaceDefinitions);
+        this.versionSpecificDefinitions = requireNonNull(versionSpecificDefinitions);
     }
 
     /**
@@ -99,20 +100,17 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
         return supportedVersions;
     }
 
-    @Override
-    @SuppressWarnings("unchecked")
-    public <K, V> NamespaceBehaviour<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> namespace) {
-        final NamespaceBehaviour<?, ?> potential = namespaceDefinitions.get(namespace);
-        if (potential != null) {
-            checkState(namespace.equals(potential.getIdentifier()));
-
-            // Safe cast, previous checkState checks equivalence of key from which type argument are derived
-            return (NamespaceBehaviour<K, V>) potential;
+    public <K, V> @Nullable NamespaceBehaviour<K, V> namespaceBehaviourOf(final ParserNamespace<K, V> namespace) {
+        final var potential = namespaceDefinitions.get(namespace);
+        if (potential == null) {
+            return parent == null ? null : parent.namespaceBehaviourOf(namespace);
         }
-        if (parent != null) {
-            return parent.getNamespaceBehaviour(namespace);
-        }
-        return null;
+
+        checkState(namespace.equals(potential.getIdentifier()));
+        // Safe cast, previous checkState checks equivalence of key from which type argument are derived
+        @SuppressWarnings("unchecked")
+        final var ret = (NamespaceBehaviour<K, V>) potential;
+        return ret;
     }
 
     public boolean hasNamespaceBehaviour(final ParserNamespace<?, ?> namespace) {