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.parser.spi.source;
10 import com.google.common.collect.SetMultimap;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.Empty;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
17 import org.opendaylight.yangtools.yang.common.XMLNamespace;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 * Namespaces related to YANG/YIN source processing.
28 public final class SourceParserNamespaces {
30 * Source-specific mapping of belongsTo prefixes to module identifiers. This mapping allows source-specific context
31 * to correctly populate prefixes map for actual parsing phase and eventually, resolve QName for any valid declared
34 public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> BELONGSTO_PREFIX_TO_MODULECTX =
35 new ParserNamespace<>("belongsto-prefix-to-module");
38 * Source-specific mapping of prefixes to namespaces.
41 public static final @NonNull ParserNamespace<String, Unqualified> BELONGSTO_PREFIX_TO_MODULE_NAME =
42 new ParserNamespace<>("belongsto-prefix-to-name");
45 * Namespace similar to {@link ParserNamespaces#MODULE} for storing modules into Yang model storage but keyed by
48 // FIXME: Better name?
49 public static final @NonNull ParserNamespace<Unqualified,
50 StmtContext<Unqualified, ModuleStatement, ModuleEffectiveStatement>> MODULE_FOR_BELONGSTO =
51 new ParserNamespace<>("module-belongsto");
54 * Pre-linkage source-specific mapping of prefixes to module namespaces.
56 // FIXME: a better name?
57 public static final @NonNull ParserNamespace<String, XMLNamespace> IMP_PREFIX_TO_NAMESPACE =
58 new ParserNamespace<>("prefix-to-xmlnamespace");
61 * Source-specific mapping of prefix strings to module context.
63 public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> IMPORT_PREFIX_TO_MODULECTX =
64 new ParserNamespace<>("import-prefix-to-modulectx");
66 // FIXME: document this
67 public static final @NonNull ParserNamespace<SourceIdentifier, StmtContext<?, ?, ?>> IMPORTED_MODULE =
68 new ParserNamespace<>("imported-module");
70 // FIXME: document this
71 // FIXME: is this 'included submodule' instead?
72 public static final @NonNull ParserNamespace<SourceIdentifier, StmtContext<?, ?, ?>> INCLUDED_MODULE =
73 new ParserNamespace<>("included-module");
76 * Source-specific mapping of prefixes to namespaces.
79 public static final @NonNull ParserNamespace<Unqualified, StmtContext<?, ?, ?>> INCLUDED_SUBMODULE_NAME_TO_MODULECTX
80 = new ParserNamespace<>("included-submodule-to-modulectx");
83 * Source-specific mapping of prefixes to namespaces.
86 public static final @NonNull ParserNamespace<Unqualified, QNameModule> MODULE_NAME_TO_QNAME =
87 new ParserNamespace<>("module-name-to-qnamemodule");
90 * Global mapping of modules to QNameModules.
92 public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, QNameModule> MODULECTX_TO_QNAME =
93 new ParserNamespace<>("modulectx-to-qnamemodule");
95 public static final @NonNull ParserNamespace<Empty, Set<QName>> SUPPORTED_FEATURES =
96 new ParserNamespace<>("supportedFeatures");
99 * Source-specific mapping of prefixes to namespaces. This namespace is populated by all statements which have
100 * impact on the XML namespace, for example {@code import}, {@code belongs-to} and really anywhere a {@code prefix}
101 * statement is present.
103 * @see PrefixResolver
105 public static final @NonNull ParserNamespace<String, QNameModule> PREFIX_TO_MODULE =
106 new ParserNamespace<>("prefix-to-qnamemodule");
109 * Namespace used for storing information about modules that support deviation resolution.
110 * Map key (QNameModule) denotes a module which can be deviated by the modules specified in the Map value.
112 public static final @NonNull ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> MODULES_DEVIATED_BY =
113 new ParserNamespace<>("moduleDeviations");
116 * Source-specific mapping of prefixes to namespaces.
118 // FIXME: bad javadoc
119 public static final @NonNull ParserNamespace<QNameModule, Unqualified> MODULE_NAMESPACE_TO_NAME =
120 new ParserNamespace<>("qnamemodule-to-name");
123 * Pre-linkage global mapping of module names to namespaces.
125 public static final @NonNull ParserNamespace<Unqualified, XMLNamespace> MODULE_NAME_TO_NAMESPACE =
126 new ParserNamespace<>("module-name-to-xmlnamespace");
129 * Global mapping of modules to source identifier.
131 public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> MODULECTX_TO_SOURCE =
132 new ParserNamespace<>("modulectx-to-source");
134 private SourceParserNamespaces() {