From 111a53e3a3788854ae96e2d0f2d8b6679ed07c42 Mon Sep 17 00:00:00 2001 From: "miroslav.kovac" Date: Tue, 1 Dec 2020 14:55:34 +0100 Subject: [PATCH] Introduce NamespaceStmtCtx We have a few namespace access methods, make sure we encapsulate them into a NamespaceStmtCtx and expose them from both StmtContext and EffectiveStmtCtx.Current. JIRA: YANGTOOLS-1185 Change-Id: I5c13406b96ab3735761749b900c244ad555f8730 Signed-off-by: miroslav.kovac Signed-off-by: Robert Varga --- .../reactor/BaseCurrentEffectiveStmtCtx.java | 22 +++-- .../parser/stmt/reactor/ReactorStmtCtx.java | 9 +- .../parser/spi/meta/EffectiveStmtCtx.java | 9 +- .../parser/spi/meta/NamespaceStmtCtx.java | 85 +++++++++++++++++++ .../yang/parser/spi/meta/StmtContext.java | 22 +---- 5 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java index f7bbc9c1dd..cd8950a294 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java @@ -70,9 +70,19 @@ final class BaseCurrentEffectiveStmtCtx> imple } @Override - public > V getFromNamespace( - final Class<@NonNull N> type, final T key) { - return delegate.getFromNamespace(type, key); + public > Map localNamespace(final Class<@NonNull N> nsType) { + return delegate.localNamespace(nsType); + } + + @Override + public > @Nullable Map namespace(final Class<@NonNull N> nsType) { + return delegate.namespace(nsType); + } + + @Override + public > V namespaceItem(final Class<@NonNull N> type, + final T key) { + return delegate.namespaceItem(type, key); } @Override @@ -116,12 +126,6 @@ final class BaseCurrentEffectiveStmtCtx> imple return ret; } - @Override - public > Map - getAllFromCurrentStmtCtxNamespace(final Class type) { - return delegate.getAllFromCurrentStmtCtxNamespace(type); - } - @Override public A argument() { return delegate.argument(); diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java index 2b20710523..1f4ba0355a 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java @@ -240,19 +240,18 @@ abstract class ReactorStmtCtx, E extends Effec // @Override - public final > V getFromNamespace( - final Class<@NonNull N> type, final T key) { + public final > V namespaceItem(final Class<@NonNull N> type, + final T key) { return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key); } @Override - public final > Map getAllFromNamespace(final Class type) { + public final > Map namespace(final Class<@NonNull N> type) { return getNamespace(type); } @Override - public final > Map getAllFromCurrentStmtCtxNamespace( - final Class type) { + public final > Map localNamespace(final Class<@NonNull N> type) { return getLocalNamespace(type); } diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java index 95791adf39..5e52a77f29 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java @@ -11,7 +11,6 @@ import static com.google.common.base.Verify.verifyNotNull; import com.google.common.annotations.Beta; import com.google.common.base.VerifyException; -import java.util.Map; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -19,7 +18,6 @@ import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; /** * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}. @@ -79,17 +77,12 @@ public interface EffectiveStmtCtx extends CommonStmtCtx, StmtContextCompat, Immu * @param Class representing declared version of this statement */ @Beta - interface Current> extends Parent, BoundStmtCtx { + interface Current> extends Parent, BoundStmtCtx, NamespaceStmtCtx { @NonNull CommonStmtCtx root(); @NonNull D declared(); - > @Nullable V getFromNamespace(Class<@NonNull N> type, - T key); - - > Map getAllFromCurrentStmtCtxNamespace(Class type); - @Nullable EffectiveStatement original(); /** diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java new file mode 100644 index 0000000000..dcfb541372 --- /dev/null +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2020 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.spi.meta; + +import com.google.common.annotations.Beta; +import java.util.Map; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; + +/** + * Support work with namespace content. + */ +@Beta +public interface NamespaceStmtCtx extends CommonStmtCtx { + /** + * Return the selected namespace. + * + * @param namespace key type + * @param namespace value type + * @param namespace type + * @param nsType namespace type class + * @return Namespace contents, if available + */ + > @Nullable Map namespace(Class<@NonNull N> nsType); + + /** + * Return a value associated with specified key within a namespace. + * + * @param nsType Namespace type + * @param key Key + * @param namespace key type + * @param namespace value type + * @param namespace type + * @param key type + * @return Value, or null if there is no element + * @throws NamespaceNotAvailableException when the namespace is not available. + */ + > @Nullable V namespaceItem(Class<@NonNull N> nsType, T key); + + > @Nullable Map localNamespace(Class<@NonNull N> nsType); + + // TODO: migrate users away + default > Map getAllFromCurrentStmtCtxNamespace( + final Class<@NonNull N> nsType) { + return localNamespace(nsType); + } + + /** + * Return the selected namespace. + * + * @param namespace key type + * @param namespace value type + * @param namespace type + * @param nsType namespace type class + * @return Namespace contents, if available + */ + // TODO: migrate users away + default > Map getAllFromNamespace(final Class nsType) { + return namespace(nsType); + } + + /** + * Return a value associated with specified key within a namespace. + * + * @param type Namespace type + * @param key Key + * @param namespace key type + * @param namespace value type + * @param namespace type + * @param key type + * @return Value, or null if there is no element + * @throws NamespaceNotAvailableException when the namespace is not available. + */ + // TODO: migrate users away + default > + @Nullable V getFromNamespace(final Class<@NonNull N> type, final T key) { + return namespaceItem(type, key); + } +} diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 15fb8fb688..f8a537394e 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -14,7 +14,6 @@ import com.google.common.base.VerifyException; import com.google.common.collect.Iterables; import com.google.common.collect.Streams; import java.util.Collection; -import java.util.Map; import java.util.Optional; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNull; @@ -37,7 +36,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc * @param Effective Statement representation */ public interface StmtContext, E extends EffectiveStatement> - extends BoundStmtCtx, StmtContextCompat { + extends BoundStmtCtx, NamespaceStmtCtx, StmtContextCompat { @Deprecated(forRemoval = true) default @NonNull StatementDefinition getPublicDefinition() { return publicDefinition(); @@ -120,25 +119,6 @@ public interface StmtContext, E extends Effect boolean isEnabledSemanticVersioning(); - /** - * Return a value associated with specified key within a namespace. - * - * @param type Namespace type - * @param key Key - * @param namespace key type - * @param namespace value type - * @param namespace type - * @param key type - * @return Value, or null if there is no element - * @throws NamespaceNotAvailableException when the namespace is not available. - */ - > @Nullable V getFromNamespace(Class<@NonNull N> type, - T key); - - > Map getAllFromNamespace(Class type); - - > Map getAllFromCurrentStmtCtxNamespace(Class type); - /** * Returns the model root for this statement. * -- 2.36.6