Improve ParserNamespace type safety
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / source / SourceParserNamespaces.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.source;
9
10 import com.google.common.collect.SetMultimap;
11 import java.util.Set;
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;
24
25 /**
26  * Namespaces related to YANG/YIN source processing.
27  */
28 public final class SourceParserNamespaces {
29     /**
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
32      * statement.
33      */
34     public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> BELONGSTO_PREFIX_TO_MODULECTX =
35         new ParserNamespace<>("belongsto-prefix-to-module");
36
37     /**
38      * Source-specific mapping of prefixes to namespaces.
39      */
40     // FIXME: bad javadoc
41     public static final @NonNull ParserNamespace<String, Unqualified> BELONGSTO_PREFIX_TO_MODULE_NAME =
42         new ParserNamespace<>("belongsto-prefix-to-name");
43
44     /**
45      * Namespace similar to {@link ParserNamespaces#MODULE} for storing modules into Yang model storage but keyed by
46      * plain name.
47      */
48     // FIXME: Better name?
49     public static final @NonNull ParserNamespace<Unqualified,
50         StmtContext<Unqualified, ModuleStatement, ModuleEffectiveStatement>> MODULE_FOR_BELONGSTO =
51         new ParserNamespace<>("module-belongsto");
52
53     /**
54      * Pre-linkage source-specific mapping of prefixes to module namespaces.
55      */
56     // FIXME: a better name?
57     public static final @NonNull ParserNamespace<String, XMLNamespace> IMP_PREFIX_TO_NAMESPACE =
58         new ParserNamespace<>("prefix-to-xmlnamespace");
59
60     /**
61      * Source-specific mapping of prefix strings to module context.
62      */
63     public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> IMPORT_PREFIX_TO_MODULECTX =
64         new ParserNamespace<>("import-prefix-to-modulectx");
65
66     // FIXME: document this
67     public static final @NonNull ParserNamespace<SourceIdentifier, StmtContext<?, ?, ?>> IMPORTED_MODULE =
68         new ParserNamespace<>("imported-module");
69
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");
74
75     /**
76      * Source-specific mapping of prefixes to namespaces.
77      */
78     // FIXME: bad javadoc
79     public static final @NonNull ParserNamespace<Unqualified, StmtContext<?, ?, ?>> INCLUDED_SUBMODULE_NAME_TO_MODULECTX
80         = new ParserNamespace<>("included-submodule-to-modulectx");
81
82     /**
83      * Source-specific mapping of prefixes to namespaces.
84      */
85     // FIXME: bad javadoc
86     public static final @NonNull ParserNamespace<Unqualified, QNameModule> MODULE_NAME_TO_QNAME =
87         new ParserNamespace<>("module-name-to-qnamemodule");
88
89     /**
90      * Global mapping of modules to QNameModules.
91      */
92     public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, QNameModule> MODULECTX_TO_QNAME =
93         new ParserNamespace<>("modulectx-to-qnamemodule");
94
95     public static final @NonNull ParserNamespace<Empty, Set<QName>> SUPPORTED_FEATURES =
96         new ParserNamespace<>("supportedFeatures");
97
98     /**
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.
102      *
103      * @see PrefixResolver
104      */
105     public static final @NonNull ParserNamespace<String, QNameModule> PREFIX_TO_MODULE =
106         new ParserNamespace<>("prefix-to-qnamemodule");
107
108     /**
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.
111      */
112     public static final @NonNull ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> MODULES_DEVIATED_BY =
113         new ParserNamespace<>("moduleDeviations");
114
115     /**
116      * Source-specific mapping of prefixes to namespaces.
117      */
118     // FIXME: bad javadoc
119     public static final @NonNull ParserNamespace<QNameModule, Unqualified> MODULE_NAMESPACE_TO_NAME =
120         new ParserNamespace<>("qnamemodule-to-name");
121
122     /**
123      * Pre-linkage global mapping of module names to namespaces.
124      */
125     public static final @NonNull ParserNamespace<Unqualified, XMLNamespace> MODULE_NAME_TO_NAMESPACE =
126         new ParserNamespace<>("module-name-to-xmlnamespace");
127
128     /**
129      * Global mapping of modules to source identifier.
130      */
131     public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> MODULECTX_TO_SOURCE =
132         new ParserNamespace<>("modulectx-to-source");
133
134     private SourceParserNamespaces() {
135         // Hidden on purpose
136     }
137 }