}
@Override
- public <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
- final Class<@NonNull N> type, final T key) {
- return delegate.getFromNamespace(type, key);
+ public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> localNamespace(final Class<@NonNull N> nsType) {
+ return delegate.localNamespace(nsType);
+ }
+
+ @Override
+ public <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> namespace(final Class<@NonNull N> nsType) {
+ return delegate.namespace(nsType);
+ }
+
+ @Override
+ public <K, V, T extends K, N extends IdentifierNamespace<K, V>> V namespaceItem(final Class<@NonNull N> type,
+ final T key) {
+ return delegate.namespaceItem(type, key);
}
@Override
return ret;
}
- @Override
- public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V>
- getAllFromCurrentStmtCtxNamespace(final Class<N> type) {
- return delegate.getAllFromCurrentStmtCtxNamespace(type);
- }
-
@Override
public A argument() {
return delegate.argument();
//
@Override
- public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
- final Class<@NonNull N> type, final T key) {
+ public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V namespaceItem(final Class<@NonNull N> type,
+ final T key) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
}
@Override
- 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> namespace(final Class<@NonNull N> type) {
return getNamespace(type);
}
@Override
- public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
- final Class<N> type) {
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> localNamespace(final Class<@NonNull N> type) {
return getLocalNamespace(type);
}
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;
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}.
* @param <D> Class representing declared version of this statement
*/
@Beta
- interface Current<A, D extends DeclaredStatement<A>> extends Parent, BoundStmtCtx<A> {
+ interface Current<A, D extends DeclaredStatement<A>> extends Parent, BoundStmtCtx<A>, NamespaceStmtCtx {
@NonNull CommonStmtCtx root();
@NonNull D declared();
- <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
- T key);
-
- <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
-
@Nullable EffectiveStatement<?, ?> original();
/**
--- /dev/null
+/*
+ * 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 <K> namespace key type
+ * @param <V> namespace value type
+ * @param <N> namespace type
+ * @param nsType namespace type class
+ * @return Namespace contents, if available
+ */
+ <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> namespace(Class<@NonNull N> nsType);
+
+ /**
+ * Return a value associated with specified key within a namespace.
+ *
+ * @param nsType 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.
+ */
+ <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 selected namespace.
+ *
+ * @param <K> namespace key type
+ * @param <V> namespace value type
+ * @param <N> namespace type
+ * @param nsType namespace type class
+ * @return Namespace contents, if available
+ */
+ // TODO: migrate users away
+ default <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> nsType) {
+ return namespace(nsType);
+ }
+
+ /**
+ * 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.
+ */
+ // TODO: migrate users away
+ default <K, V, T extends K, N extends IdentifierNamespace<K, V>>
+ @Nullable V getFromNamespace(final Class<@NonNull N> type, final T key) {
+ return namespaceItem(type, key);
+ }
+}
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;
* @param <E> Effective Statement representation
*/
public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
- extends BoundStmtCtx<A>, StmtContextCompat {
+ extends BoundStmtCtx<A>, NamespaceStmtCtx, StmtContextCompat {
@Deprecated(forRemoval = true)
default @NonNull StatementDefinition getPublicDefinition() {
return publicDefinition();
boolean isEnabledSemanticVersioning();
- /**
- * 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.
- */
- <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
- T key);
-
- <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(Class<N> type);
-
- <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
-
/**
* Returns the model root for this statement.
*