Remove NamespaceBehaviourRegistry 68/105268/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Apr 2023 06:30:22 +0000 (08:30 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Apr 2023 06:35:27 +0000 (08:35 +0200)
This interface is an unneeded indirection. Inline
getNamespaceBehaviour() into NamespaceStorageSupport and implement it as
appropriate.

JIRA: YANGTOOLS-1499
Change-Id: I48741ce53a9ff8d52d5a4c2095641002a8d74bfc
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-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourRegistry.java [deleted file]
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java

index 7d43e5cfc2e8ca3db2e17e7f33b6dd32e437bd0f..7af9625df8cf96cffcd373832d06f2a1bfd7b037 100644 (file)
@@ -61,7 +61,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBehaviourRegistry {
+final class BuildGlobalContext extends NamespaceStorageSupport {
     private static final Logger LOG = LoggerFactory.getLogger(BuildGlobalContext.class);
 
     private static final ModelProcessingPhase[] PHASE_EXECUTION_ORDER = {
@@ -136,12 +136,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Namesp
     }
 
     @Override
-    NamespaceBehaviourRegistry 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)).namespaceBehaviourOf(type);
diff --git a/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourRegistry.java b/parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourRegistry.java
deleted file mode 100644 (file)
index 099c0d2..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.reactor;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * An entity able to look up a {@link NamespaceBehaviour} corresponding to a {@link ParserNamespace}.
- */
-sealed interface NamespaceBehaviourRegistry permits BuildGlobalContext, SourceSpecificContext {
-    /**
-     * Get a namespace behavior.
-     *
-     * @param <K> key type
-     * @param <V> value type
-     * @param namespace Namespace type
-     * @return Namespace behaviour
-     * @throws NamespaceNotAvailableException when the namespace is not available
-     * @throws NullPointerException if {@code namespace} is {@code null}
-     */
-    <K, V> @NonNull NamespaceBehaviour<K, V> getNamespaceBehaviour(ParserNamespace<K, V> namespace);
-}
index 58ee7dade50c37672b41c1533e03d73f4da684f4..c3dd508a1eb81ea6866b4777898a444fc840a4e6 100644 (file)
@@ -14,7 +14,9 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.eclipse.jdt.annotation.NonNull;
+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.NamespaceNotAvailableException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.slf4j.Logger;
@@ -37,11 +39,16 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     public abstract NamespaceStorageNode getParentNamespaceStorage();
 
     /**
-     * Return the registry of a source context.
+     * Get a namespace behavior.
      *
-     * @return registry of source context
+     * @param <K> key type
+     * @param <V> value type
+     * @param namespace Namespace type
+     * @return Namespace behaviour
+     * @throws NamespaceNotAvailableException when the namespace is not available
+     * @throws NullPointerException if {@code namespace} is {@code null}
      */
-    abstract @NonNull NamespaceBehaviourRegistry getBehaviourRegistry();
+    abstract <K, V> @NonNull NamespaceBehaviour<K, V> getNamespaceBehaviour(ParserNamespace<K, V> namespace);
 
     // FIXME: 8.0.0: do we really need this method?
     final void checkLocalNamespaceAllowed(final ParserNamespace<?, ?> type) {
@@ -59,7 +66,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     }
 
     final <K, V> Map<K, V> getNamespace(final ParserNamespace<K, V> type) {
-        return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
+        return getNamespaceBehaviour(type).getAllFrom(this);
     }
 
     @SuppressWarnings("unchecked")
@@ -70,7 +77,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
 
     final <K, V, T extends K, U extends V> void addToNamespace(final ParserNamespace<K, V> type, final T key,
             final U value) {
-        getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
+        getNamespaceBehaviour(type).addTo(this, key, value);
     }
 
     @Override
index fdf91cf7d631eb066f00d7c57e882076d6018cd8..9b0216cd3d6024842ee82e746deece059bd0bfb2 100644 (file)
@@ -42,6 +42,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.ExecutionOrder;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 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.StatementFactory;
@@ -188,8 +189,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     public abstract Collection<? extends @NonNull StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements();
 
     @Override
-    final NamespaceBehaviourRegistry getBehaviourRegistry() {
-        return getRoot().getBehaviourRegistryImpl();
+    final <K, V> NamespaceBehaviour<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
+        return getRoot().getSourceContext().getNamespaceBehaviour(type);
     }
 
     @Override
@@ -321,7 +322,7 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
 
     @Override
     public final <K, V> V namespaceItem(final ParserNamespace<K, V> namespace, final K key) {
-        return getBehaviourRegistry().getNamespaceBehaviour(namespace).getFrom(this, key);
+        return getNamespaceBehaviour(namespace).getFrom(this, key);
     }
 
     @Override
index 5014eda95225c067dda7e3ecde1320c7daf60fb3..0e1d7ebf3148820c82c606691606a4e8a93e4129 100644 (file)
@@ -103,7 +103,7 @@ final class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Ef
         return this;
     }
 
-    SourceSpecificContext getSourceContext() {
+    @NonNull SourceSpecificContext getSourceContext() {
         return sourceContext;
     }
 
@@ -219,10 +219,6 @@ final class RootStatementContext<A, D extends DeclaredStatement<A>, E extends Ef
         rootIdentifier = requireNonNull(identifier);
     }
 
-    @NonNull NamespaceBehaviourRegistry getBehaviourRegistryImpl() {
-        return sourceContext;
-    }
-
     @NonNull YangVersion getRootVersionImpl() {
         return rootVersion == null ? DEFAULT_VERSION : rootVersion;
     }
index 23d82eb2e25dc8f6c516bfa6d3a0341251148252..c98aacd9acba8c69faa252b76443f29cb41aabbd 100644 (file)
@@ -53,7 +53,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviourRegistry, Mutable {
+final class SourceSpecificContext implements NamespaceStorageNode, Mutable {
     enum PhaseCompletionProgress {
         NO_PROGRESS,
         PROGRESS,
@@ -300,8 +300,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
         return null;
     }
 
-    @Override
-    public <K, V> NamespaceBehaviour<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
+    <K, V> NamespaceBehaviour<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
         if (StatementSupport.NAMESPACE.equals(type)) {
             @SuppressWarnings("unchecked")
             final var ret = (NamespaceBehaviour<K, V>) statementSupports;
index 3c350cd095e48e422e25e793bd4d0387db24a26c..3bfc5cc1d197936dd398d572dd31c5656f57c7ef 100644 (file)
@@ -647,7 +647,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
 
     private <K, V> Optional<Entry<K, V>> getFromNamespace(final ParserNamespace<K, V> type,
             final NamespaceKeyCriterion<K> criterion) {
-        return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
+        return getNamespaceBehaviour(type).getFrom(this, criterion);
     }
 
     final <K, V> void waitForPhase(final Object value, final ParserNamespace<K, V> type,
@@ -661,7 +661,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     }
 
     private <K, V> NamespaceBehaviourWithListeners<K, V> getBehaviour(final ParserNamespace<K, V> type) {
-        final NamespaceBehaviour<K, V> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
+        final NamespaceBehaviour<K, V> behaviour = getNamespaceBehaviour(type);
         checkArgument(behaviour instanceof NamespaceBehaviourWithListeners, "Namespace %s does not support listeners",
             type);
 
@@ -724,7 +724,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     @Override
     public final <K, KT extends K, C extends StmtContext<?, ?, ?>> void addContext(
             final ParserNamespace<K, ? super C> namespace, final KT key, final C stmt) {
-        getBehaviourRegistry().getNamespaceBehaviour(namespace).addTo(this, key, stmt);
+        getNamespaceBehaviour(namespace).addTo(this, key, stmt);
     }
 
     @Override