2 * Copyright (c) 2022 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.model.api.stmt;
10 import com.google.common.annotations.Beta;
11 import java.util.Collection;
13 import java.util.Map.Entry;
14 import java.util.Optional;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 * Common interface capturing general layout of a top-level YANG declared statement -- either
23 * a {@link ModuleEffectiveStatement} or a {@link SubmoduleEffectiveStatement}.
26 * Both these statements have a relationship to lexical and semantic interpretation of a particular YANG (or YIN) file.
27 * The core principle is that every XML prefix is bound to a particular {@link ModuleEffectiveStatement}, exposed via
28 * {@link #findReachableModule(String)} and {@link #reachableModules()}. The secondary effect of it is that each known
29 * {@link QNameModule} is known under a (preferred) prefix, exposed via {@link #findNamespacePrefix(QNameModule)}.
32 public sealed interface RootEffectiveStatement<D extends RootDeclaredStatement>
33 extends EffectiveStatement<Unqualified, D> permits ModuleEffectiveStatement, SubmoduleEffectiveStatement {
35 * Find the {@link ModuleEffectiveStatement} statement based on {@link PrefixEffectiveStatement}s, be it direct
36 * substatement or a substatement of a {@link ImportEffectiveStatement} substatement.
38 * @return prefix Imported {@link ModuleEffectiveStatement}, or absent
39 * @throws NullPointerException if {@code prefix} is {@code null}
41 @NonNull Optional<ModuleEffectiveStatement> findReachableModule(@NonNull String prefix);
44 * Enumerate all modules reachable from this module. This is recursive relationship: every
45 * {@link RootEffectiveStatement} is considered reachable from itself under its local prefix. Returned collection
46 * is guaranteed not to contain more than one element with the same {@link Entry#getKey()}.
48 * @return All {@link ModuleEffectiveStatement}s reachable in this {@code module} or {@code submodule}, coupled with
49 * their preferred prefix.
51 @NonNull Collection<Entry<String, ModuleEffectiveStatement>> reachableModules();
54 * Find the preferred prefix to use with a particular namespace.
56 * @param namespace A bound namespace, represented as {@link QNameModule}
57 * @return Preferred prefix, or empty
58 * @throws NullPointerException if {@code namespace} is {@code null}
60 @NonNull Optional<String> findNamespacePrefix(@NonNull QNameModule namespace);
63 * Enumeration of all namespace-to-prefix mappings. This generally corresponds to a {@link Map#entrySet()}, but we
64 * do not want to be bogged down by a {@link Set}.
66 Collection<Entry<QNameModule, String>> namespacePrefixes();