2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
10 import com.google.common.annotations.Beta;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
16 * Support work with namespace content.
19 public interface NamespaceStmtCtx extends CommonStmtCtx {
21 * Return the selected namespace.
23 * @param <K> namespace key type
24 * @param <V> namespace value type
25 * @param <N> namespace type
26 * @param nsType namespace type class
27 * @return Namespace contents, if available
29 <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> namespace(Class<@NonNull N> nsType);
32 * Return a value associated with specified key within a namespace.
34 * @param nsType Namespace type
36 * @param <K> namespace key type
37 * @param <V> namespace value type
38 * @param <N> namespace type
40 * @return Value, or null if there is no element
41 * @throws NamespaceNotAvailableException when the namespace is not available.
43 <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V namespaceItem(Class<@NonNull N> nsType, T key);
46 * Return the portion of specified namespace stored in this node. Depending on namespace behaviour this may or may
47 * not represent the complete contents of the namespace as available via {@link #namespace(Class)}.
50 * This partial view is useful when the need is not to perform a proper namespace lookup, but rather act on current
51 * statement's contribution to the namespace.
53 * @param <K> namespace key type
54 * @param <V> namespace value type
55 * @param <N> namespace type
56 * @param nsType namespace type class
57 * @return Namespace portion stored in this node, if available
59 <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(Class<@NonNull N> nsType);
62 * Return the selected namespace.
64 * @param <K> namespace key type
65 * @param <V> namespace value type
66 * @param <N> namespace type
67 * @param nsType namespace type class
68 * @return Namespace contents, if available
70 // TODO: migrate users away
71 default <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> nsType) {
72 return namespace(nsType);
76 * Return a value associated with specified key within a namespace.
78 * @param type Namespace type
80 * @param <K> namespace key type
81 * @param <V> namespace value type
82 * @param <N> namespace type
84 * @return Value, or null if there is no element
85 * @throws NamespaceNotAvailableException when the namespace is not available.
87 // TODO: migrate users away
88 default <K, V, T extends K, N extends ParserNamespace<K, V>>
89 @Nullable V getFromNamespace(final Class<@NonNull N> type, final T key) {
90 return namespaceItem(type, key);