Make ParserNamespace an identifier 44/102144/12
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Aug 2022 08:25:19 +0000 (10:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Aug 2022 21:29:31 +0000 (23:29 +0200)
We are using Class objects to identify namespaces. This patch makes
ParserNamespace an Identifier and uses it instead of Class to refer
to namespaces.

This has the side-effect of removing a ton of classes and turning them
into singleton objects instead.

JIRA: YANGTOOLS-1453
Change-ID: I796ecf22c2c22b512ef0db4d0d4a06b8ea69c23f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
112 files changed:
parser/odlext-parser-support/src/main/java/org/opendaylight/yangtools/odlext/parser/AbstractIdentityAwareStatementSupport.java
parser/rfc8040-parser-support/src/main/java/org/opendaylight/yangtools/rfc8040/parser/OperationsCreateLeafStatements.java
parser/rfc8040-parser-support/src/main/java/org/opendaylight/yangtools/rfc8040/parser/OperationsValidateModuleAction.java
parser/rfc8040-parser-support/src/main/java/org/opendaylight/yangtools/rfc8040/parser/YangDataArgumentNamespace.java
parser/rfc8040-parser-support/src/main/java/org/opendaylight/yangtools/rfc8040/parser/YangDataStatementSupport.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ForwardingUndeclaredCurrent.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModifierImpl.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReplicaStatementContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SweptNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/namespace/ModuleQNameToPrefix.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/namespace/StmtNamespaceContext.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/namespace/YangNamespaceContextNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/reactor/CustomCrossSourceStatementReactorBuilder.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/reactor/RFC7950Reactors.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentImplicitHandlingNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/extension/ExtensionStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/AbstractIfFeatureStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/import_/ImportStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/import_/ImportedVersionNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/import_/RevisionImport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ListStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/ActionStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/BaseStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/BelongsToStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/ChoiceStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/DeviationStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/FeatureStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/GroupingStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/IdentityStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/IncludeStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/RpcStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/TypedefStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/meta/UniqueStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/QNameModuleNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/refine/RefineStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/refine/RefineTargetNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/SubmoduleEffectiveStatementImpl.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/SubmoduleStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/BaseTypeNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/IdentityRefSpecificationSupport.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/SourceGroupingNamespace.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/thirdparty/plugin/ThirdPartyExtensionEffectiveStatementImpl.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/thirdparty/plugin/ThirdPartyExtensionSupport.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/thirdparty/plugin/ThirdPartyNamespace.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ExtensionNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/FeatureNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/GroupingNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/IdentityNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ModuleNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceBehaviours.java [new file with mode: 0644]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceToModule.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ParserNamespaces.java [new file with mode: 0644]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/PreLinkageModuleNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SchemaTreeNamespace.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SchemaTreeNamespaceBehaviour.java [new file with mode: 0644]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SubmoduleNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/TypeNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractSchemaTreeStatementSupport.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ImportedNamespaceContext.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceStmtCtx.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ParserNamespace.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementDefinitions.java [moved from parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementDefinitionNamespace.java with 88% similarity]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementNamespace.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupport.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleCtx.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleName.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportPrefixToModuleCtx.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportedModuleContext.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedModuleContext.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedSubmoduleNameToModuleCtx.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToSourceIdentifier.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToModuleQName.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNamespaceForBelongsTo.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleQNameToModuleName.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModulesDeviatedByModules.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModule.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceNamespaceBehaviours.java [new file with mode: 0644]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceParserNamespaces.java [new file with mode: 0644]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java [deleted file]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/validation/ValidationBundles.java [moved from parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/validation/ValidationBundlesNamespace.java with 86% similarity]
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/validation/package-info.java
parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceTest.java [deleted file]
parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceTest.java
parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/source/NamespaceTest.java [deleted file]

index a8f72944277386bd6dea1bdadc6ce0b58ce09187..d3bdb76456d0b0be0257aeda2ec62a1453cc39e9 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@@ -47,7 +47,7 @@ abstract class AbstractIdentityAwareStatementSupport<D extends DeclaredStatement
     @Override
     public void onStatementDefinitionDeclared(final Mutable<QName, D, E> stmt) {
         final ModelActionBuilder action = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
-        action.requiresCtx(stmt, IdentityNamespace.class, stmt.getArgument(), ModelProcessingPhase.EFFECTIVE_MODEL);
+        action.requiresCtx(stmt, ParserNamespaces.IDENTITY, stmt.getArgument(), ModelProcessingPhase.EFFECTIVE_MODEL);
 
         action.apply(new InferenceAction() {
             @Override
@@ -67,7 +67,7 @@ abstract class AbstractIdentityAwareStatementSupport<D extends DeclaredStatement
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         final QName qname = stmt.getArgument();
         final StmtContext<?, ?, IdentityEffectiveStatement> identityCtx =
-            verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, qname), "Failed to find identity %s", qname);
+            verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname), "Failed to find identity %s", qname);
         return createEffective(stmt.declared(), identityCtx.buildEffective(), substatements);
     }
 
index 1f78430f0470057d3acb7694fd1bddb241863118..6eb67bef1127e3d6dd05ea9d0f85073235177e18 100644 (file)
@@ -26,13 +26,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 
@@ -57,7 +56,7 @@ final class OperationsCreateLeafStatements implements InferenceAction {
 
         final var prereqs = new ArrayList<Prerequisite<? extends StmtContext<?, ?, ?>>>();
         // FIXME: this not accurate: we need all sources, not just modules
-        for (var module : ietfRestconfModule.getAllFromNamespace(ModuleNamespace.class).values()) {
+        for (var module : ietfRestconfModule.getAllFromNamespace(ParserNamespaces.MODULE).values()) {
             if (!ietfRestconfModule.equals(module)) {
                 prereqs.add(action.requiresCtx((StmtContext<?, ?, ?>)module, ModelProcessingPhase.EFFECTIVE_MODEL));
             }
@@ -99,7 +98,7 @@ final class OperationsCreateLeafStatements implements InferenceAction {
 
     private <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>>
             StatementSupport<X, Y, Z> getSupport(final StatementDefinition def, final Class<Z> effectiveClass) {
-        final var tmp = verifyNotNull(operations.getFromNamespace(StatementSupportNamespace.class,
+        final var tmp = verifyNotNull(operations.getFromNamespace(StatementSupport.NAMESPACE,
             def.getStatementName()));
         final var repr = tmp.definition().getEffectiveRepresentationClass();
         verify(effectiveClass.equals(repr), "Unexpected support %s representation %s", tmp, repr);
index 92aaaa0f2fc30eef0497ab346e294e4d5f545fc6..beedbd0b7c03cd2b4c37094f082af63b0afb626e 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Infere
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 /**
  * An {@link InferenceAction} tasked with identifying when we are dealing with {@link YangDataConstants#RFC8040_SOURCE}.
@@ -54,7 +54,8 @@ final class OperationsValidateModuleAction implements InferenceAction {
         final Mutable<?, ?, ?> moduleCtx = prereq.resolve(ctx);
 
         // Check namespace and revision first
-        final QNameModule moduleQName = moduleCtx.getFromNamespace(ModuleCtxToModuleQName.class, moduleCtx);
+        final QNameModule moduleQName =
+            moduleCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, moduleCtx);
         if (!YangDataConstants.RFC8040_MODULE.equals(moduleQName)) {
             return;
         }
index 5a353695066ff7506ee8b4a59eccf2a9954994e0..2fe2c7aa99d633555bf388fa2c0fe623dbffdf89 100644 (file)
@@ -20,9 +20,9 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 @Beta
 // FIXME: We should not be needing this namespace, as yang-data's argument is not documented anywhere to be compatible
 //        with 'identifier', hence we cannot safely form a QName.
-public final class YangDataArgumentNamespace extends ParserNamespace<Empty, QName> {
-    public static final @NonNull NamespaceBehaviour<?, ? ,?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(YangDataArgumentNamespace.class);
+public final class YangDataArgumentNamespace {
+    public static final @NonNull ParserNamespace<Empty, QName> INSTANCE = new ParserNamespace<>("yangDataArgument");
+    public static final @NonNull NamespaceBehaviour<?, ? ,?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private YangDataArgumentNamespace() {
         // Hidden on purpose
index 6c18978c6cf8ca86666ff5ddd662e6e1013a6d54..f779c65e1e189d391037bbbc07029f546955cbad 100644 (file)
@@ -59,7 +59,7 @@ public final class YangDataStatementSupport
         // Parse and populate our argument to be picked up when we build the effective statement
         final String argument = SourceException.throwIfNull(ctx.argument(), ctx, "yang-data requires an argument");
         final QName qname = StmtContextUtils.parseIdentifier(ctx, argument);
-        ctx.addToNs(YangDataArgumentNamespace.class, Empty.value(), qname);
+        ctx.addToNs(YangDataArgumentNamespace.INSTANCE, Empty.value(), qname);
 
         // Support for 'operations' container semantics. For this we need to recognize when the model at hand matches
         // RFC8040 ietf-restconf module. In ordered to do that we hook onto this particular definition:
@@ -120,6 +120,6 @@ public final class YangDataStatementSupport
         }
 
         return new YangDataEffectiveStatementImpl(stmt, substatements,
-            verifyNotNull(stmt.namespaceItem(YangDataArgumentNamespace.class, Empty.value())));
+            verifyNotNull(stmt.namespaceItem(YangDataArgumentNamespace.INSTANCE, Empty.value())));
     }
 }
index 4a123f944eddd9b822cbf635d5d960b52dfc8054..c2bd655542abddb9f5111b9591d64788830bec1c 100644 (file)
@@ -55,13 +55,11 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedEx
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.PhaseCompletionProgress;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -79,7 +77,8 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
 
     private final Table<YangVersion, QName, StatementDefinitionContext<?, ?, ?>> definitions = HashBasedTable.create();
     private final Map<QName, StatementDefinitionContext<?, ?, ?>> modelDefinedStmtDefs = new HashMap<>();
-    private final Map<Class<?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces = new HashMap<>();
+    private final Map<ParserNamespace<?, ?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces =
+        new HashMap<>();
     private final List<MutableStatement> mutableStatementsToSeal = new ArrayList<>();
     private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports;
     private final Set<SourceSpecificContext> sources = new HashSet<>();
@@ -93,7 +92,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
             final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation) {
         this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
 
-        addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
+        addToNamespace(ValidationBundles.NAMESPACE, supportedValidation);
 
         supportedVersions = ImmutableSet.copyOf(
             verifyNotNull(supports.get(ModelProcessingPhase.INIT)).getSupportedVersions());
@@ -114,12 +113,13 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     void setSupportedFeatures(final Set<QName> supportedFeatures) {
-        addToNamespace(SupportedFeaturesNamespace.class, Empty.value(), ImmutableSet.copyOf(supportedFeatures));
+        addToNamespace(SourceParserNamespaces.SUPPORTED_FEATURES, Empty.value(),
+            ImmutableSet.copyOf(supportedFeatures));
     }
 
     void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
-        addToNamespace(ModulesDeviatedByModules.class, Empty.value(),
-                    ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
+        addToNamespace(SourceParserNamespaces.MODULES_DEVIATED_BY, Empty.value(),
+            ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
     }
 
     @Override
@@ -139,7 +139,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
 
     @Override
     public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getNamespaceBehaviour(
-            final Class<N> type) {
+            final N type) {
         NamespaceBehaviourWithListeners<?, ?, ?> potential = supportedNamespaces.get(type);
         if (potential == null) {
             final var potentialRaw = verifyNotNull(supports.get(currentPhase)).getNamespaceBehaviour(type);
@@ -236,7 +236,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     private static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
-        final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
+        final QNameModule qNameModule = root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root);
         final Object arg = root.getArgument();
         verify(arg instanceof Unqualified, "Unexpected argument %s", arg);
 
index d929dd5acac1c59ce0623dcdb0b60cabe7e1bfed..3ab4141327097fab15ab22901aef8ff30f43832b 100644 (file)
@@ -25,7 +25,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 
 public final class CrossSourceStatementReactor {
     private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supportedTerminology;
index f37214730983cc529456aa762edede34ad6eb456..5746c7a1feaecbb2288a9c689f01bf3dde1808ca 100644 (file)
@@ -80,18 +80,17 @@ final class ForwardingUndeclaredCurrent<A, D extends DeclaredStatement<A>> exten
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final Class<@NonNull N> nsType) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final @NonNull N nsType) {
         return delegate.namespace(nsType);
     }
 
     @Override
-    public <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final Class<@NonNull N> nsType,
-            final T key) {
+    public <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final @NonNull N nsType, final T key) {
         return delegate.namespaceItem(nsType, key);
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final Class<@NonNull N> nsType) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final @NonNull N nsType) {
         return delegate.localNamespacePortion(nsType);
     }
 
index af2b5bbe566d6dbe830116f35e7a9aca6ca5b4e8..e8bd61185ade2b26429124c3f5ffa805b5711510 100644 (file)
@@ -443,8 +443,8 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
         if (prototype instanceof InferredStatementContext) {
             // Note: we need to access namespace here, as the target statement may have already been populated, in which
             //       case we want to obtain the statement in local namespace storage.
-            template = (StmtContext) ((InferredStatementContext<?, ?, ?>) prototype).getFromNamespace(
-                SchemaTreeNamespace.class, templateQName);
+            template = ((InferredStatementContext<?, ?, ?>) prototype).getFromNamespace(SchemaTreeNamespace.instance(),
+                templateQName);
         } else {
             template = prototype.allSubstatementsStream()
                 .filter(stmt -> stmt.producesEffective(SchemaTreeEffectiveStatement.class)
index 6e31b1adb2f453c8acfddfeebb453b8175415445..a254d391d2f009d9de5a706540e3d0b8b30062cf 100644 (file)
@@ -89,7 +89,7 @@ final class ModifierImpl implements ModelActionBuilder {
     }
 
     private <K, C extends StmtContext<?, ?, ?>, N extends StatementNamespace<K, ?, ?>> @NonNull AbstractPrerequisite<C>
-            requiresCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key,
+            requiresCtxImpl(final StmtContext<?, ?, ?> context, final N namespace, final K key,
                     final ModelProcessingPhase phase)  {
         checkNotRegistered();
 
@@ -100,7 +100,7 @@ final class ModifierImpl implements ModelActionBuilder {
     }
 
     private <K, C extends StmtContext<?, ?, ?>, N extends StatementNamespace<K, ?, ?>> @NonNull AbstractPrerequisite<C>
-            requiresCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace,
+            requiresCtxImpl(final StmtContext<?, ?, ?> context, final N namespace,
                     final NamespaceKeyCriterion<K> criterion, final ModelProcessingPhase phase)  {
         checkNotRegistered();
 
@@ -121,15 +121,15 @@ final class ModifierImpl implements ModelActionBuilder {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private <K, C extends Mutable<?, ?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
-            AbstractPrerequisite<C> mutatesCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace,
-                    final K key, final ModelProcessingPhase phase) {
+    private <K, C extends Mutable<?, ?, ?>> AbstractPrerequisite<C> mutatesCtxImpl(final StmtContext<?, ?, ?> context,
+            final ParserNamespace<K, ? extends StmtContext<?, ?, ?>> namespace, final K key,
+            final ModelProcessingPhase phase) {
         checkNotRegistered();
 
         final PhaseModificationInNamespace<C> mod = new PhaseModificationInNamespace<>(EFFECTIVE_MODEL);
         addReq(mod);
         addMutation(mod);
-        contextImpl(context).onNamespaceItemAddedAction((Class) namespace, key, mod);
+        contextImpl(context).onNamespaceItemAddedAction((ParserNamespace) namespace, key, mod);
         return mod;
     }
 
@@ -167,22 +167,21 @@ final class ModifierImpl implements ModelActionBuilder {
 
     @Override
     public <K, N extends StatementNamespace<K, ?, ?>> Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
-            final StmtContext<?, ?, ?> context, final Class<@NonNull N> namespace, final K key,
-            final ModelProcessingPhase phase) {
+            final StmtContext<?, ?, ?> context, final N namespace, final K key, final ModelProcessingPhase phase) {
         return requiresCtxImpl(context, namespace, key, phase);
     }
 
     @Override
     public <K, N extends StatementNamespace<K, ?, ?>> Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
-            final StmtContext<?, ?, ?> context, final Class<@NonNull N> namespace,
-            final NamespaceKeyCriterion<K> criterion, final ModelProcessingPhase phase) {
+            final StmtContext<?, ?, ?> context, final N namespace, final NamespaceKeyCriterion<K> criterion,
+            final ModelProcessingPhase phase) {
         return requiresCtxImpl(context, namespace, criterion, phase);
     }
 
     @Override
     public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
             Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(final StmtContext<?, ?, ?> context,
-                final Class<N> namespace, final Iterable<K> keys, final ModelProcessingPhase phase) {
+                final N namespace, final Iterable<K> keys, final ModelProcessingPhase phase) {
         checkNotRegistered();
 
         final var ret = new PhaseRequirementInNamespacePath<StmtContext<?, ?, E>, K, N>(EFFECTIVE_MODEL, keys);
@@ -200,7 +199,7 @@ final class ModifierImpl implements ModelActionBuilder {
     @Override
     @Deprecated
     public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>> Prerequisite<D>
-            requiresDeclared(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
+            requiresDeclared(final StmtContext<?, ?, ?> context, final N namespace, final K key) {
         final AbstractPrerequisite<StmtContext<?, D, ?>> rawContext = requiresCtxImpl(context, namespace, key,
             FULL_DECLARATION);
         return rawContext.transform(StmtContext::declared);
@@ -210,7 +209,7 @@ final class ModifierImpl implements ModelActionBuilder {
     @Deprecated
     public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
             AbstractPrerequisite<StmtContext<?, D, ?>> requiresDeclaredCtx(final StmtContext<?, ?, ?> context,
-                    final Class<N> namespace, final K key) {
+                    final N namespace, final K key) {
         return requiresCtxImpl(context, namespace, key, FULL_DECLARATION);
     }
 
@@ -224,7 +223,7 @@ final class ModifierImpl implements ModelActionBuilder {
     @Override
     @Deprecated
     public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> Prerequisite<E>
-            requiresEffective(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
+            requiresEffective(final StmtContext<?, ?, ?> context, final N namespace, final K key) {
         final AbstractPrerequisite<StmtContext<?, ?, E>> rawContext = requiresCtxImpl(context, namespace, key,
             EFFECTIVE_MODEL);
         return rawContext.transform(StmtContext::buildEffective);
@@ -234,28 +233,28 @@ final class ModifierImpl implements ModelActionBuilder {
     @Deprecated
     public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
             AbstractPrerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(final StmtContext<?, ?, ?> context,
-                    final Class<N> namespace, final K key) {
+                    final N namespace, final K key) {
         return requiresCtxImpl(contextImpl(context), namespace, key, EFFECTIVE_MODEL);
     }
 
     @Override
     @Deprecated
     public <N extends ParserNamespace<?, ?>> Prerequisite<Mutable<?, ?, ?>> mutatesNs(final Mutable<?, ?, ?> context,
-            final Class<N> namespace) {
+            final N namespace) {
         return addMutation(new NamespaceMutation<>(contextImpl(context), namespace));
     }
 
     @Override
     public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
             AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(final StmtContext<?, ?, ?> context,
-                    final Class<N> namespace, final K key) {
+                    final N namespace, final K key) {
         return mutatesCtxImpl(context, namespace, key, EFFECTIVE_MODEL);
     }
 
     @Override
     public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
             AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtxPath(final StmtContext<?, ?, ?> context,
-                    final Class<N> namespace, final Iterable<K> keys) {
+                    final N namespace, final Iterable<K> keys) {
         checkNotRegistered();
 
         final var ret = new PhaseModificationInNamespacePath<Mutable<?, ?, E>, K, N>(EFFECTIVE_MODEL, keys);
@@ -334,8 +333,8 @@ final class ModifierImpl implements ModelActionBuilder {
         }
 
         @Override
-        public final void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
-            final Object key, final Object value) {
+        public final void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+                final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
             LOG.debug("Action for {} got key {}", keys, key);
 
             final StatementContextBase<?, ?, ?> target = contextImpl(value);
@@ -368,14 +367,15 @@ final class ModifierImpl implements ModelActionBuilder {
             return super.addToStringAttributes(toStringHelper).add("phase", modPhase).add("keys", keys);
         }
 
-        final void hookOnto(final StmtContext<?, ?, ?> context, final Class<?> namespace) {
+        final void hookOnto(final StmtContext<?, ?, ?> context, final ParserNamespace<?, ?> namespace) {
             checkArgument(it.hasNext(), "Namespace %s keys may not be empty", namespace);
             hookOnto(contextImpl(context), namespace, it.next());
         }
 
         @SuppressWarnings("unchecked")
-        private void hookOnto(final StatementContextBase<?, ?, ?> context, final Class<?> namespace, final K key) {
-            context.onNamespaceItemAddedAction((Class) namespace, requireNonNull(key), this);
+        private void hookOnto(final StatementContextBase<?, ?, ?> context, final ParserNamespace<?, ?> namespace,
+                final K key) {
+            context.onNamespaceItemAddedAction((ParserNamespace) namespace, requireNonNull(key), this);
         }
     }
 
@@ -404,7 +404,7 @@ final class ModifierImpl implements ModelActionBuilder {
 
     private final class NamespaceMutation<N extends ParserNamespace<?, ?>>
             extends AbstractPrerequisite<Mutable<?, ?, ?>>  {
-        NamespaceMutation(final StatementContextBase<?, ?, ?> ctx, final Class<N> namespace) {
+        NamespaceMutation(final StatementContextBase<?, ?, ?> ctx, final N namespace) {
             resolvePrereq(ctx);
         }
     }
@@ -418,8 +418,8 @@ final class ModifierImpl implements ModelActionBuilder {
         }
 
         @Override
-        public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
-                final Object key, final Object value) {
+        public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+                final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
             ((StatementContextBase<?, ?, ?>) value).addPhaseCompletedListener(phase, this);
         }
 
@@ -460,8 +460,8 @@ final class ModifierImpl implements ModelActionBuilder {
 
         @SuppressWarnings("unchecked")
         @Override
-        public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
-                final Object key, final Object value) {
+        public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+                final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
             StatementContextBase<?, ?, ?> targetCtx = contextImpl(value);
             targetCtx.addMutation(modPhase, this);
             resolvePrereq((C) targetCtx);
index 2a521e1907b6cfeddfc5bc0e5de017467567f690..7a815608f8c6db505f1c59603ad7b1edc5fd1680 100644 (file)
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
 abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     private static final Logger LOG = LoggerFactory.getLogger(NamespaceStorageSupport.class);
 
-    private Map<Class<?>, Map<?, ?>> namespaces = ImmutableMap.of();
+    private Map<ParserNamespace<?, ?>, Map<?, ?>> namespaces = ImmutableMap.of();
 
     /**
      * {@inheritDoc}
@@ -51,7 +51,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     public abstract @NonNull Registry getBehaviourRegistry();
 
     // FIXME: 8.0.0: do we really need this method?
-    final void checkLocalNamespaceAllowed(final Class<? extends ParserNamespace<?, ?>> type) {
+    final void checkLocalNamespaceAllowed(final ParserNamespace<?, ?> type) {
         // Always no-op. We used to route this towards StatementDefinitionContext, but this method remained
         // unimplemented even there.
     }
@@ -61,32 +61,32 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
      *
      * @throws SourceException instance of SourceException
      */
-    protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
+    protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final N type, final K key,
             final V value) {
         // NOOP
     }
 
-    public final <K, V, N extends ParserNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(
-            final Class<N> type, final NamespaceKeyCriterion<K> criterion) {
+    public final <K, V, N extends ParserNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(final N type,
+            final NamespaceKeyCriterion<K> criterion) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
     }
 
-    public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getNamespace(final Class<N> type) {
+    public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getNamespace(final N type) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
     }
 
     @SuppressWarnings("unchecked")
-    final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getLocalNamespace(final Class<N> type) {
+    final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getLocalNamespace(final N type) {
         return (Map<K, V>) accessNamespaces().get(type);
     }
 
-    final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(
-            final Class<N> type, final T key, final U value) {
+    final <K, V, T extends K, U extends V> void addToNamespace(final ParserNamespace<K, V> type, final T key,
+            final U value) {
         getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
     }
 
-    final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(
-            final Class<N> type, final Map<T, U> map) {
+    final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(final N type,
+            final Map<T, U> map) {
         final NamespaceBehaviour<K, V, N> behavior = getBehaviourRegistry().getNamespaceBehaviour(type);
         for (final Entry<T, U> validationBundle : map.entrySet()) {
             behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
@@ -104,35 +104,34 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
      * @throws NamespaceNotAvailableException when the namespace is not available.
      */
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final Class<N> type, final K key,
+    public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final N type, final K key,
             final StmtContext<?, ?, ?> value) {
-        getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value);
+        getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
         final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
         return localNamespace == null ? null : localNamespace.get(key);
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
         @SuppressWarnings("unchecked")
         final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
         return localNamespace;
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
-            final V value) {
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
         final V ret = ensureLocalNamespace(type).put(key, value);
         onNamespaceElementAdded(type, key, value);
         return ret;
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final Class<N> type, final K key,
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final N type, final K key,
             final V value) {
         final V ret = ensureLocalNamespace(type).putIfAbsent(key, value);
         if (ret == null) {
@@ -146,7 +145,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         LOG.trace("Swept namespace storages of {}", this);
     }
 
-    void sweepNamespaces(final Map<Class<?>, SweptNamespace> toWipe) {
+    void sweepNamespaces(final Map<ParserNamespace<?, ?>, SweptNamespace> toWipe) {
         switch (namespaces.size()) {
             case 0:
                 namespaces = ImmutableMap.copyOf(toWipe);
@@ -162,11 +161,11 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         LOG.trace("Trimmed namespace storages of {} to {}", this, namespaces.keySet());
     }
 
-    private Map<Class<?>, Map<?, ?>> accessNamespaces() {
+    private Map<ParserNamespace<?, ?>, Map<?, ?>> accessNamespaces() {
         return verifyNotNull(namespaces, "Attempted to access swept namespaces of %s", this);
     }
 
-    private <K, V, N extends ParserNamespace<K, V>> Map<K, V> ensureLocalNamespace(final Class<N> type) {
+    private <K, V, N extends ParserNamespace<K, V>> Map<K, V> ensureLocalNamespace(final N type) {
         @SuppressWarnings("unchecked")
         Map<K, V> ret = (Map<K,V>) accessNamespaces().get(type);
         if (ret == null) {
@@ -180,8 +179,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
                     break;
                 case 1:
                     // Alright, time to grow to a full HashMap
-                    final Map<Class<?>, Map<?,?>> newNamespaces = new HashMap<>(4);
-                    final Entry<Class<?>, Map<?, ?>> entry = namespaces.entrySet().iterator().next();
+                    final Map<ParserNamespace<?, ?>, Map<?,?>> newNamespaces = new HashMap<>(4);
+                    final Entry<ParserNamespace<?, ?>, Map<?, ?>> entry = namespaces.entrySet().iterator().next();
                     newNamespaces.put(entry.getKey(), entry.getValue());
                     namespaces = newNamespaces;
                     // fall through
index 1020b649d0138a820b917addf57acb70da595eea..724bbf486fc7c71b1fd36fa2a6d4fd72f5c74276 100644 (file)
@@ -48,7 +48,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -321,24 +321,23 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     //
 
     @Override
-    public final <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final Class<@NonNull N> type,
+    public final <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final @NonNull N type,
             final T key) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
     }
 
     @Override
-    public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final Class<@NonNull N> type) {
+    public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final @NonNull N type) {
         return getNamespace(type);
     }
 
     @Override
-    public final <K, V, N extends ParserNamespace<K, V>>
-            Map<K, V> localNamespacePortion(final Class<@NonNull N> type) {
+    public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final @NonNull N type) {
         return getLocalNamespace(type);
     }
 
     @Override
-    protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
+    protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final N type, final K key,
             final V value) {
         // definition().onNamespaceElementAdded(this, type, key, value);
     }
@@ -495,7 +494,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
          */
         if (isParentSupportedByFeatures()) {
             // If the set of supported features has not been provided, all features are supported by default.
-            final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class, Empty.value());
+            final Set<QName> supportedFeatures = getFromNamespace(SourceParserNamespaces.SUPPORTED_FEATURES,
+                Empty.value());
             if (supportedFeatures == null || StmtContextUtils.checkFeatureSupport(this, supportedFeatures)) {
                 flags |= SET_SUPPORTED_BY_FEATURES;
                 return true;
index 16bab426be499d7a043ed85b9a8d89f427ba2b5e..5fa5c65f5dc2eeced96049c901e4a2bbc958f446 100644 (file)
@@ -156,7 +156,7 @@ final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends
 
     @Override
     @Deprecated
-    public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final Class<@NonNull N> type,
+    public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final @NonNull N type,
             final T key, final U value) {
         throw new UnsupportedOperationException();
     }
@@ -169,7 +169,7 @@ final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends
 
     @Override
     @Deprecated
-    public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<@NonNull N> namespace,
+    public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final @NonNull N namespace,
             final KT key, final StmtContext<?, ?, ?> stmt) {
         throw new UnsupportedOperationException();
     }
index a29e6dbb9b346d25026326404a805b0e5e2f6440..d1ca478b9f7b95b5556052aa83f894b4e5ea73bb 100644 (file)
@@ -27,9 +27,8 @@ import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
@@ -37,7 +36,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Regist
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.RootStmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,10 +51,10 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
 
     private static final Logger LOG = LoggerFactory.getLogger(RootStatementContext.class);
     // These namespaces are well-known and not needed after the root is cleaned up
-    private static final Map<Class<?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
-        GroupingNamespace.class, new SweptNamespace(GroupingNamespace.class),
-        SchemaTreeNamespace.class, new SweptNamespace(SchemaTreeNamespace.class),
-        TypeNamespace.class, new SweptNamespace(TypeNamespace.class));
+    private static final Map<ParserNamespace<?, ?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
+        ParserNamespaces.GROUPING, new SweptNamespace(ParserNamespaces.GROUPING),
+        SchemaTreeNamespace.instance(), new SweptNamespace(SchemaTreeNamespace.instance()),
+        ParserNamespaces.TYPE, new SweptNamespace(ParserNamespaces.TYPE));
 
     private final @NonNull SourceSpecificContext sourceContext;
     private final A argument;
@@ -80,8 +79,8 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
             final StatementSourceReference ref, final String rawArgument, final YangVersion version,
             final SourceIdentifier identifier) {
         this(sourceContext, def, ref, rawArgument);
-        this.setRootVersion(version);
-        this.setRootIdentifier(identifier);
+        setRootVersion(version);
+        setRootIdentifier(identifier);
     }
 
     @Override
@@ -122,9 +121,8 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
-            final V value) {
-        if (IncludedModuleContext.class.isAssignableFrom(type)) {
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
+        if (SourceParserNamespaces.INCLUDED_MODULE.equals(type)) {
             if (includedContexts.isEmpty()) {
                 includedContexts = new ArrayList<>(1);
             }
@@ -135,7 +133,7 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
         return getFromLocalStorage(type, key, new HashSet<>());
     }
 
@@ -143,7 +141,7 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
      * We need to track already checked RootStatementContexts due to possible
      * circular chains of includes between submodules
      */
-    private <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(final Class<N> type,
+    private <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(final N type,
             final K key, final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
         final V potentialLocal = super.getFromLocalStorage(type, key);
         if (potentialLocal != null) {
@@ -164,7 +162,7 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
         return getAllFromLocalStorage(type, new HashSet<>());
     }
 
@@ -172,7 +170,7 @@ public final class RootStatementContext<A, D extends DeclaredStatement<A>, E ext
      * We need to track already checked RootStatementContexts due to possible
      * circular chains of includes between submodules
      */
-    private <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final Class<N> type,
+    private <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final N type,
             final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
         final Map<K, V> potentialLocal = super.getAllFromLocalStorage(type);
         if (potentialLocal != null) {
index fdbe9d81d654f918dfce7e65156bb79a7550c034..9c7db1f58fb879acfab231e62382a22c441425c0 100644 (file)
@@ -27,7 +27,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@@ -37,20 +36,14 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixResolver;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinitionMap;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.slf4j.Logger;
@@ -63,12 +56,12 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
         FINISHED
     }
 
-    private static final class SupportedStatements
-            extends NamespaceBehaviour<QName, StatementSupport<?, ?, ?>, StatementSupportNamespace> {
+    private static final class SupportedStatements extends NamespaceBehaviour<QName, StatementSupport<?, ?, ?>,
+                ParserNamespace<QName, StatementSupport<?, ?, ?>>> {
         private final QNameToStatementDefinitionMap statementDefinitions;
 
         SupportedStatements(final QNameToStatementDefinitionMap statementDefinitions) {
-            super(StatementSupportNamespace.class);
+            super(StatementSupport.NAMESPACE);
             this.statementDefinitions = requireNonNull(statementDefinitions);
         }
 
@@ -215,9 +208,9 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
         LOG.debug("Source {} started phase {}", source, phase);
     }
 
-    private void updateImportedNamespaces(final Class<?> type, final Object value) {
-        if (BelongsToPrefixToModuleCtx.class.isAssignableFrom(type)
-            || ImportedModuleContext.class.isAssignableFrom(type)) {
+    private void updateImportedNamespaces(final ParserNamespace<?, ?> type, final Object value) {
+        if (SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX.equals(type)
+            || SourceParserNamespaces.IMPORTED_MODULE.equals(type)) {
             verify(value instanceof RootStatementContext, "Unexpected imported value %s", value);
 
             if (importedNamespaces.isEmpty()) {
@@ -228,8 +221,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
-           final V value) {
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
         // RootStatementContext takes care of IncludedModuleContext and the rest...
         final V ret = getRoot().putToLocalStorage(type, key, value);
         // FIXME: what about duplicates?
@@ -238,7 +230,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final Class<N> type, final K key,
+    public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final N type, final K key,
            final V value) {
         // RootStatementContext takes care of IncludedModuleContext and the rest...
         final V ret = getRoot().putToLocalStorageIfAbsent(type, key, value);
@@ -254,7 +246,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+    public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
         final V potentialLocal = getRoot().getFromLocalStorage(type, key);
         if (potentialLocal != null) {
             return potentialLocal;
@@ -270,7 +262,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
     }
 
     @Override
-    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+    public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
         final Map<K, V> potentialLocal = getRoot().getAllFromLocalStorage(type);
         if (potentialLocal != null) {
             return potentialLocal;
@@ -288,9 +280,8 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
 
     @Override
     @SuppressWarnings("unchecked")
-    public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
-            final Class<N> type) {
-        if (StatementSupportNamespace.class.equals(type)) {
+    public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(final N type) {
+        if (StatementSupport.NAMESPACE.equals(type)) {
             return (NamespaceBehaviour<K, V, N>) statementSupports;
         }
         return globalContext.getNamespaceBehaviour(type);
@@ -427,7 +418,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
 
     private PrefixResolver preLinkagePrefixes() {
         final HashMapPrefixResolver preLinkagePrefixes = new HashMapPrefixResolver();
-        final Map<String, XMLNamespace> prefixToNamespaceMap = getAllFromLocalStorage(ImpPrefixToNamespace.class);
+        final var prefixToNamespaceMap = getAllFromLocalStorage(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE);
         if (prefixToNamespaceMap == null) {
             //:FIXME if it is a submodule without any import, the map is null. Handle also submodules and includes...
             return null;
@@ -438,18 +429,16 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
     }
 
     private PrefixResolver prefixes() {
-        final Map<String, StmtContext<?, ?, ?>> allImports = getRoot().getAllFromNamespace(
-            ImportPrefixToModuleCtx.class);
+        final var allImports = root.getAllFromNamespace(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX);
         if (allImports != null) {
             allImports.forEach((key, value) ->
-                prefixToModuleMap.put(key, getRoot().getFromNamespace(ModuleCtxToModuleQName.class, value)));
+                prefixToModuleMap.put(key, root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, value)));
         }
 
-        final Map<String, StmtContext<?, ?, ?>> allBelongsTo = getRoot().getAllFromNamespace(
-            BelongsToPrefixToModuleCtx.class);
+        final var allBelongsTo = root.getAllFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
         if (allBelongsTo != null) {
             allBelongsTo.forEach((key, value) ->
-                prefixToModuleMap.put(key, getRoot().getFromNamespace(ModuleCtxToModuleQName.class, value)));
+                prefixToModuleMap.put(key, root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, value)));
         }
 
         return prefixToModuleMap;
@@ -468,7 +457,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
 
         // We need to any and all extension statements which have been declared in the context
         final Map<QName, StatementSupport<?, ?, ?>> extensions = globalContext.getNamespace(
-                StatementDefinitionNamespace.class);
+            StatementDefinitions.NAMESPACE);
         if (extensions != null) {
             extensions.forEach((qname, support) -> {
                 final StatementSupport<?, ?, ?> existing = qnameToStmtDefMap.putIfAbsent(qname, support);
index 81adc400687ae0cf961e2923f34ac30ffe2dbc1a..0713af839db35df72e22e03da7333a22cfb01dc6 100644 (file)
@@ -72,7 +72,8 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         /**
          * Invoked whenever a new item is added to a namespace.
          */
-        void namespaceItemAdded(StatementContextBase<?, ?, ?> context, Class<?> namespace, Object key, Object value);
+        void namespaceItemAdded(StatementContextBase<?, ?, ?> context, ParserNamespace<?, ?> namespace, Object key,
+            Object value);
     }
 
     /**
@@ -263,8 +264,8 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     }
 
     @Override
-    public final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(
-            final Class<@NonNull N> type, final T key, final U value) {
+    public final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final @NonNull N type,
+            final T key, final U value) {
         addToNamespace(type, key, value);
     }
 
@@ -593,7 +594,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         return definition;
     }
 
-    final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, final K key,
+    final <K, V> void onNamespaceItemAddedAction(final ParserNamespace<K, V> type, final K key,
             final OnNamespaceItemAdded listener) {
         final Object potential = getFromNamespace(type, key);
         if (potential != null) {
@@ -610,7 +611,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         });
     }
 
-    final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type,
+    final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final N type,
             final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
             final OnNamespaceItemAdded listener) {
         final Optional<Entry<K, V>> existing = getFromNamespace(type, criterion);
@@ -636,7 +637,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         });
     }
 
-    final <K, V, N extends ParserNamespace<K, V>> void selectMatch(final Class<N> type,
+    final <K, V, N extends ParserNamespace<K, V>> void selectMatch(final N type,
             final NamespaceKeyCriterion<K> criterion, final OnNamespaceItemAdded listener) {
         final Optional<Entry<K, V>> optMatch = getFromNamespace(type, criterion);
         checkState(optMatch.isPresent(), "Failed to find a match for criterion %s in namespace %s node %s", criterion,
@@ -645,7 +646,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         listener.namespaceItemAdded(StatementContextBase.this, type, match.getKey(), match.getValue());
     }
 
-    final <K, V, N extends ParserNamespace<K, V>> void waitForPhase(final Object value, final Class<N> type,
+    final <K, V, N extends ParserNamespace<K, V>> void waitForPhase(final Object value, final N type,
             final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
             final OnNamespaceItemAdded listener) {
         ((StatementContextBase<?, ? ,?>) value).addPhaseCompletedListener(phase,
@@ -656,7 +657,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     }
 
     private <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getBehaviour(
-            final Class<N> type) {
+            final N type) {
         final NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
         checkArgument(behaviour instanceof NamespaceBehaviourWithListeners, "Namespace %s does not support listeners",
             type);
@@ -718,8 +719,8 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     }
 
     @Override
-    public final <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
-            final Class<@NonNull N> namespace, final KT key,final StmtContext<?, ?, ?> stmt) {
+    public final <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final @NonNull N namespace,
+            final KT key, final StmtContext<?, ?, ?> stmt) {
         addContextToNamespace(namespace, key, stmt);
     }
 
index e3543da2748132f90f3fc3c8543a528d795ef9cd..2054ee75b587a39b7ad62911493493c3a15fec79 100644 (file)
@@ -12,15 +12,16 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.base.VerifyException;
 import java.util.AbstractMap;
 import java.util.Set;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 
 /**
  * Placeholder namespace map which does not allow access and acts as a sentinel for namespaces which have been
  * explicitly removed from {@link NamespaceStorageSupport}.
  */
 final class SweptNamespace extends AbstractMap<Object, Object> {
-    private final Class<?> name;
+    private final ParserNamespace<?, ?> name;
 
-    SweptNamespace(final Class<?> name) {
+    SweptNamespace(final ParserNamespace<?, ?> name) {
         this.name = requireNonNull(name);
     }
 
index eed73dd3b52157bb33a4d3d08ee6b6df688a6044..269d47eb3d1e00dc503998a2846f36bec8b3799e 100644 (file)
@@ -18,9 +18,11 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
  * some quality parsing time.
  */
 @Beta
-public final class ModuleQNameToPrefix extends ParserNamespace<QNameModule, String> {
+public final class ModuleQNameToPrefix {
+    public static final @NonNull ParserNamespace<QNameModule, String> INSTANCE =
+        new ParserNamespace<>("module-qname-to-prefix");
     public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.rootStatementLocal(ModuleQNameToPrefix.class);
+        NamespaceBehaviour.rootStatementLocal(INSTANCE);
 
     private ModuleQNameToPrefix() {
         // Hidden on purpose
index fe27682865aadde7101165652916bcdc78195a3f..5124b840dc550523cc5bb20d25d4e912e457ffea 100644 (file)
@@ -7,6 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.namespace;
 
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.MODULECTX_TO_QNAME;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.MODULE_NAME_TO_QNAME;
+
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.ImmutableMap;
 import java.util.HashMap;
@@ -19,10 +24,6 @@ import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
 import org.opendaylight.yangtools.yang.common.YangNamespaceContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 
 /**
  * A {@link NamespaceContext} implementation based on the set of imports and local module namespace.
@@ -36,20 +37,19 @@ final class StmtNamespaceContext implements YangNamespaceContext {
 
     StmtNamespaceContext(final StmtContext<?, ?, ?> ctx) {
         // QNameModule -> prefix mappings
-        final Map<QNameModule, String> qnameToPrefix = ctx.getAllFromNamespace(ModuleQNameToPrefix.class);
+        final Map<QNameModule, String> qnameToPrefix = ctx.getAllFromNamespace(ModuleQNameToPrefix.INSTANCE);
         moduleToPrefix = qnameToPrefix == null ? ImmutableBiMap.of() : ImmutableBiMap.copyOf(qnameToPrefix);
 
         // Additional mappings
         final Map<String, QNameModule> additional = new HashMap<>();
-        final Map<String, StmtContext<?, ?, ?>> imports = ctx.getAllFromNamespace(ImportPrefixToModuleCtx.class);
+        final Map<String, StmtContext<?, ?, ?>> imports = ctx.getAllFromNamespace(IMPORT_PREFIX_TO_MODULECTX);
         if (imports != null) {
             for (Entry<String, StmtContext<?, ?, ?>> entry : imports.entrySet()) {
                 if (!moduleToPrefix.containsValue(entry.getKey())) {
-                    QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, entry.getValue());
+                    QNameModule qnameModule = ctx.getFromNamespace(MODULECTX_TO_QNAME, entry.getValue());
                     if (qnameModule == null && ctx.producesDeclared(SubmoduleStatement.class)) {
-                        final Unqualified moduleName = ctx.getFromNamespace(BelongsToPrefixToModuleName.class,
-                            entry.getKey());
-                        qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+                        qnameModule = ctx.getFromNamespace(MODULE_NAME_TO_QNAME,
+                            ctx.getFromNamespace(BELONGSTO_PREFIX_TO_MODULE_NAME, entry.getKey()));
                     }
 
                     if (qnameModule != null) {
@@ -59,10 +59,10 @@ final class StmtNamespaceContext implements YangNamespaceContext {
             }
         }
         if (ctx.producesDeclared(SubmoduleStatement.class)) {
-            final Map<String, Unqualified> belongsTo = ctx.getAllFromNamespace(BelongsToPrefixToModuleName.class);
+            final Map<String, Unqualified> belongsTo = ctx.getAllFromNamespace(BELONGSTO_PREFIX_TO_MODULE_NAME);
             if (belongsTo != null) {
                 for (Entry<String, Unqualified> entry : belongsTo.entrySet()) {
-                    final QNameModule module = ctx.getFromNamespace(ModuleNameToModuleQName.class, entry.getValue());
+                    final QNameModule module = ctx.getFromNamespace(MODULE_NAME_TO_QNAME, entry.getValue());
                     if (module != null && !additional.containsKey(entry.getKey())) {
                         additional.put(entry.getKey(), module);
                     }
index 76788692af614094079bf96c4b71e7d95537b0cb..ca0c27d8a24e068f946b2938f01da3a8344fc2d7 100644 (file)
@@ -19,9 +19,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 
 @Beta
-public final class YangNamespaceContextNamespace extends ParserNamespace<StmtContext<?, ?, ?>, YangNamespaceContext> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(YangNamespaceContextNamespace.class);
+public final class YangNamespaceContextNamespace {
+    public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, YangNamespaceContext> INSTANCE =
+        new ParserNamespace<>("yangNamespaceContext");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(INSTANCE);
 
     private YangNamespaceContextNamespace() {
         // Hidden on purpose
@@ -29,11 +30,11 @@ public final class YangNamespaceContextNamespace extends ParserNamespace<StmtCon
 
     public static @NonNull YangNamespaceContext computeIfAbsent(final StmtContext<?, ?, ?> ctx) {
         final RootStmtContext<?, ?, ?> root = ctx.getRoot();
-        YangNamespaceContext ret = ctx.getFromNamespace(YangNamespaceContextNamespace.class, root);
+        YangNamespaceContext ret = ctx.getFromNamespace(INSTANCE, root);
         if (ret == null) {
             verify(ctx instanceof Mutable, "Cannot populate namespace context to %s", ctx);
             ret = new StmtNamespaceContext(root);
-            ((Mutable<?, ?, ?>)ctx).addToNs(YangNamespaceContextNamespace.class, root, ret);
+            ((Mutable<?, ?, ?>)ctx).addToNs(INSTANCE, root, ret);
         }
         return ret;
     }
index 637770b020aef197150aa788fe5a98f2da74d2a2..beb1f176d4a1aa124005ebf62228eb8bbc924d78 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 
 @Beta
index ba73243d690002bc125d5586eb57abbe611abbf4..11e6910dd6726e1d0b0a2159863da4a479bf4c38 100644 (file)
@@ -99,37 +99,14 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC7950Support;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.SourceGroupingNamespace;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.UsesStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.NamespaceBehaviours;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceNamespaceBehaviours;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
 
@@ -143,9 +120,9 @@ public final class RFC7950Reactors {
     private static final ImmutableSet<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
 
     private static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle.builder(SUPPORTED_VERSIONS)
-        .addSupport(ValidationBundlesNamespace.BEHAVIOUR)
-        .addSupport(SupportedFeaturesNamespace.BEHAVIOUR)
-        .addSupport(ModulesDeviatedByModules.BEHAVIOUR)
+        .addSupport(ValidationBundles.BEHAVIOUR)
+        .addSupport(SourceNamespaceBehaviours.SUPPORTED_FEATURES)
+        .addSupport(SourceNamespaceBehaviours.MODULES_DEVIATED_BY)
         .build();
 
     private RFC7950Reactors() {
@@ -168,10 +145,10 @@ public final class RFC7950Reactors {
             .addSupport(new YangVersionStatementSupport(config))
             .addSupport(new RevisionStatementSupport(config))
             .addSupport(new RevisionDateStatementSupport(config))
-            .addSupport(ModuleNameToNamespace.BEHAVIOUR)
-            .addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
-            .addSupport(ImpPrefixToNamespace.BEHAVIOUR)
-            .addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
+            .addSupport(SourceNamespaceBehaviours.MODULE_NAME_TO_NAMESPACE)
+            .addSupport(NamespaceBehaviours.PRELINKAGE_MODULE)
+            .addSupport(SourceNamespaceBehaviours.IMP_PREFIX_TO_NAMESPACE)
+            .addSupport(SourceNamespaceBehaviours.MODULECTX_TO_QNAME)
             .addSupport(QNameModuleNamespace.BEHAVIOUR)
             .addSupport(ImportedVersionNamespace.BEHAVIOUR)
             .build();
@@ -184,21 +161,21 @@ public final class RFC7950Reactors {
             .addSupport(new ReferenceStatementSupport(config))
             .addSupport(new ContactStatementSupport(config))
             .addSupport(new OrganizationStatementSupport(config))
-            .addSupport(ModuleNamespace.BEHAVIOUR)
-            .addSupport(ModuleNamespaceForBelongsTo.BEHAVIOUR)
-            .addSupport(SubmoduleNamespace.BEHAVIOUR)
-            .addSupport(NamespaceToModule.BEHAVIOUR)
-            .addSupport(ModuleNameToModuleQName.BEHAVIOUR)
-            .addSupport(ModuleCtxToSourceIdentifier.BEHAVIOUR)
-            .addSupport(ModuleQNameToModuleName.BEHAVIOUR)
-            .addSupport(PrefixToModule.BEHAVIOUR)
-            .addSupport(ImportedModuleContext.BEHAVIOUR)
-            .addSupport(IncludedModuleContext.BEHAVIOUR)
-            .addSupport(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR)
-            .addSupport(ImportPrefixToModuleCtx.BEHAVIOUR)
-            .addSupport(BelongsToPrefixToModuleCtx.BEHAVIOUR)
+            .addSupport(NamespaceBehaviours.MODULE)
+            .addSupport(SourceNamespaceBehaviours.MODULE_FOR_BELONGSTO)
+            .addSupport(NamespaceBehaviours.SUBMODULE)
+            .addSupport(NamespaceBehaviours.NAMESPACE_TO_MODULE)
+            .addSupport(SourceNamespaceBehaviours.MODULE_NAME_TO_QNAME)
+            .addSupport(SourceNamespaceBehaviours.MODULECTX_TO_SOURCE)
+            .addSupport(SourceNamespaceBehaviours.MODULE_NAMESPACE_TO_NAME)
+            .addSupport(SourceNamespaceBehaviours.PREFIX_TO_MODULE)
+            .addSupport(SourceNamespaceBehaviours.IMPORTED_MODULE)
+            .addSupport(SourceNamespaceBehaviours.INCLUDED_MODULE)
+            .addSupport(SourceNamespaceBehaviours.INCLUDED_SUBMODULE_NAME_TO_MODULECTX)
+            .addSupport(SourceNamespaceBehaviours.IMPORT_PREFIX_TO_MODULECTX)
+            .addSupport(SourceNamespaceBehaviours.BELONGSTO_PREFIX_TO_MODULECTX)
             .addSupport(ModuleQNameToPrefix.BEHAVIOUR)
-            .addSupport(BelongsToPrefixToModuleName.BEHAVIOUR)
+            .addSupport(SourceNamespaceBehaviours.BELONGSTO_PREFIX_TO_MODULE_NAME)
             .build();
     }
 
@@ -208,13 +185,13 @@ public final class RFC7950Reactors {
             .addSupport(new YinElementStatementSupport(config))
             .addSupport(new ArgumentStatementSupport(config))
             .addSupport(new ExtensionStatementSupport(config))
-            .addSupport(SchemaTreeNamespace.BEHAVIOUR)
-            .addSupport(ExtensionNamespace.BEHAVIOUR)
+            .addSupport(SchemaTreeNamespaceBehaviour.INSTANCE)
+            .addSupport(NamespaceBehaviours.EXTENSION)
             .addSupport(new TypedefStatementSupport(config))
-            .addSupport(TypeNamespace.BEHAVIOUR)
+            .addSupport(NamespaceBehaviours.TYPE)
             .addVersionSpecificSupport(VERSION_1, IdentityStatementSupport.rfc6020Instance(config))
             .addVersionSpecificSupport(VERSION_1_1, IdentityStatementSupport.rfc7950Instance(config))
-            .addSupport(IdentityNamespace.BEHAVIOUR)
+            .addSupport(NamespaceBehaviours.IDENTITY)
             .addSupport(new DefaultStatementSupport(config))
             .addSupport(new StatusStatementSupport(config))
             .addSupport(BaseTypeNamespace.BEHAVIOUR)
@@ -252,7 +229,7 @@ public final class RFC7950Reactors {
             .addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRFC7950Support(config))
             .addSupport(new FractionDigitsStatementSupport(config))
             .addSupport(new BaseStatementSupport(config))
-            .addSupport(StatementDefinitionNamespace.BEHAVIOUR)
+            .addSupport(StatementDefinitions.BEHAVIOUR)
             .build();
     }
 
@@ -372,10 +349,10 @@ public final class RFC7950Reactors {
             .addSupport(new MandatoryStatementSupport(config))
             .addSupport(new AnyxmlStatementSupport(config))
             .addVersionSpecificSupport(VERSION_1_1, new AnydataStatementSupport(config))
-            .addSupport(FeatureNamespace.BEHAVIOUR)
+            .addSupport(NamespaceBehaviours.FEATURE)
             .addVersionSpecificSupport(VERSION_1, new IfFeatureStatementRFC6020Support(config))
             .addVersionSpecificSupport(VERSION_1_1, new IfFeatureStatementRFC7950Support(config))
-            .addSupport(GroupingNamespace.BEHAVIOUR)
+            .addSupport(NamespaceBehaviours.GROUPING)
             .addSupport(SourceGroupingNamespace.BEHAVIOUR)
             .addSupport(new UsesStatementSupport(config))
             .addSupport(new ErrorMessageStatementSupport(config))
index 323587af5c780dca35a877317616e5eff5413cf5..1a10e172e0cef75283c7a910e90a27ac9a1599f8 100644 (file)
@@ -52,8 +52,8 @@ import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.D
 import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 @Beta
 public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqualified>,
@@ -209,7 +209,7 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqual
             .map(imp -> imp.findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class).get())
             .forEach(pfx -> {
                 final StmtContext<?, ?, ?> importedCtx =
-                        verifyNotNull(stmt.getFromNamespace(ImportPrefixToModuleCtx.class, pfx),
+                        verifyNotNull(stmt.getFromNamespace(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, pfx),
                             "Failed to resolve prefix %s", pfx);
                 builder.put(pfx, (ModuleEffectiveStatement) importedCtx.buildEffective());
             });
index f771fc6c886baa6485b540f3c0f2c0a145622b72..175eb3cd8f6ee83ec4431fc4af1b43528038e1eb 100644 (file)
@@ -100,7 +100,7 @@ abstract class AbstractAugmentStatementSupport
         final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
         augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
         final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtxPath(
-            getSearchRoot(augmentNode), SchemaTreeNamespace.class, augmentNode.getArgument().getNodeIdentifiers());
+            getSearchRoot(augmentNode), SchemaTreeNamespace.instance(), augmentNode.getArgument().getNodeIdentifiers());
 
         augmentAction.apply(new AugmentInferenceAction(this, augmentNode, target));
     }
@@ -123,7 +123,7 @@ abstract class AbstractAugmentStatementSupport
             final List<? extends StmtContext<?, ?, ?>> substatements) {
         // Pick up the marker left by onFullDefinitionDeclared() inference action. If it is present we need to pass our
         // children through target's implicit wrapping.
-        final var implicitDef = stmt.getFromNamespace(AugmentImplicitHandlingNamespace.class, Empty.value());
+        final var implicitDef = stmt.getFromNamespace(AugmentImplicitHandlingNamespace.INSTANCE, Empty.value());
         return implicitDef == null ? substatements
             : Lists.transform(substatements, subCtx -> implicitDef.wrapWithImplicit(subCtx));
     }
index c3175c71739b7e03dd5648f439eceb6726457f6b..165d49497a1f7982a4d03237b9226454f5c04910 100644 (file)
@@ -19,9 +19,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
  * the effective augment has correct implicit statements created.
  */
 @Beta
-public final class AugmentImplicitHandlingNamespace extends ParserNamespace<Empty, Mutable<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(AugmentImplicitHandlingNamespace.class);
+public final class AugmentImplicitHandlingNamespace {
+    public static final @NonNull ParserNamespace<Empty, Mutable<?, ?, ?>> INSTANCE =
+        new ParserNamespace<>("augment-implicit-handling");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private AugmentImplicitHandlingNamespace() {
         // Hidden on purpose
index 80f4e7e5db8f1d55fd28e45e1a208b74fa0bcc7e..8afdb0274bdf1341b3b5994e7b98a5e820a4e78b 100644 (file)
@@ -35,8 +35,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prereq
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,7 +77,7 @@ final class AugmentInferenceAction implements InferenceAction {
         // We are targeting a context which is creating implicit nodes. In order to keep things consistent,
         // we will need to circle back when creating effective statements.
         if (augmentTargetCtx.hasImplicitParentSupport()) {
-            augmentNode.addToNs(AugmentImplicitHandlingNamespace.class, Empty.value(), augmentTargetCtx);
+            augmentNode.addToNs(AugmentImplicitHandlingNamespace.INSTANCE, Empty.value(), augmentTargetCtx);
         }
 
         copyFromSourceToTarget(augmentNode, augmentTargetCtx);
@@ -208,11 +208,9 @@ final class AugmentInferenceAction implements InferenceAction {
          * statement, therefore return false and skip mandatory nodes validation
          */
         final Object arg = sourceCtx.argument();
-        if (!(arg instanceof QName)) {
+        if (!(arg instanceof QName sourceStmtQName)) {
             return false;
         }
-        final QName sourceStmtQName = (QName) arg;
-
         // RootStatementContext, for example
         final Mutable<?, ?, ?> root = targetCtx.getRoot();
         do {
@@ -282,7 +280,7 @@ final class AugmentInferenceAction implements InferenceAction {
          * ignored as disallowed augment target.
          */
         final Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(
-            ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
+            ValidationBundles.NAMESPACE, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
 
         // if no allowed target is returned we consider all targets allowed
         return allowedAugmentTargets == null || allowedAugmentTargets.isEmpty()
index d6903c5d6e66e2516a600191a84c465706342e0f..8498486b4da82306e8954c51190843bdea77b5ce 100644 (file)
@@ -47,9 +47,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -132,7 +131,7 @@ abstract class AbstractDeviateStatementSupport
 
         final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
                 deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(),
-                    SchemaTreeNamespace.class, deviationTarget.getNodeIdentifiers());
+                    SchemaTreeNamespace.instance(), deviationTarget.getNodeIdentifiers());
 
         deviateAction.apply(new InferenceAction() {
             @Override
@@ -234,12 +233,12 @@ abstract class AbstractDeviateStatementSupport
             final Mutable<DeviateKind, DeviateStatement, DeviateEffectiveStatement> deviateStmtCtx,
             final SchemaNodeIdentifier deviationTarget) {
         final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules = deviateStmtCtx.getFromNamespace(
-                ModulesDeviatedByModules.class, Empty.value());
+                SourceParserNamespaces.MODULES_DEVIATED_BY, Empty.value());
         if (modulesDeviatedByModules == null) {
             return true;
         }
 
-        final QNameModule currentModule = deviateStmtCtx.getFromNamespace(ModuleCtxToModuleQName.class,
+        final QNameModule currentModule = deviateStmtCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME,
                 deviateStmtCtx.getRoot());
         final QNameModule targetModule = Iterables.getLast(deviationTarget.getNodeIdentifiers()).getModule();
 
index f082e97dbf6812825b3b657bec9fa96239e4994a..592b097a8ed14d09f1c8e26bbecdb100906f286b 100644 (file)
@@ -23,11 +23,11 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
@@ -60,14 +60,14 @@ public final class ExtensionStatementSupport
             final Mutable<QName, ExtensionStatement, ExtensionEffectiveStatement> stmt) {
         super.onStatementDefinitionDeclared(stmt);
 
-        stmt.addContext(ExtensionNamespace.class, stmt.getArgument(), stmt);
+        stmt.addContext(ParserNamespaces.EXTENSION, stmt.getArgument(), stmt);
 
         final StmtContext<QName, ?, ?> argument = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
             ArgumentStatement.class);
         final StmtContext<Boolean, ?, ?> yinElement = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
             YinElementStatement.class);
 
-        stmt.addToNs(StatementDefinitionNamespace.class, stmt.argument(),
+        stmt.addToNs(StatementDefinitions.NAMESPACE, stmt.argument(),
             new UnrecognizedStatementSupport(new ModelDefinedStatementDefinition(stmt.getArgument(),
                 argument != null ? argument.argument() : null, yinElement != null && yinElement.getArgument()),
                 config));
index d77c90098a11e1fa3b805b19059930dfb5e9bae3..590421fe81ea42f352f68a32a504ee6cf69252e3 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -60,7 +60,7 @@ abstract class AbstractIfFeatureStatementSupport
         final ModelActionBuilder verifyFeatures = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
         final Map<Prerequisite<?>, QName> backRef = new HashMap<>();
         for (QName feature : stmt.getArgument().getReferencedFeatures()) {
-            backRef.put(verifyFeatures.requiresCtx(stmt, FeatureNamespace.class, feature,
+            backRef.put(verifyFeatures.requiresCtx(stmt, ParserNamespaces.FEATURE, feature,
                 ModelProcessingPhase.EFFECTIVE_MODEL), feature);
         }
 
index f5beef4fd3dc0a598db4bfa8b4ac0064e45115af..c98205a6b92fc9c0a3080430a4b7720e60973188 100644 (file)
@@ -32,7 +32,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -44,9 +44,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prereq
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
 
 @Beta
@@ -90,7 +89,7 @@ public final class ImportStatementSupport
         final Unqualified moduleName = stmt.getArgument();
         final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
         final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt,
-                PreLinkageModuleNamespace.class, moduleName, SOURCE_PRE_LINKAGE);
+            ParserNamespaces.PRELINKAGE_MODULE, moduleName, SOURCE_PRE_LINKAGE);
         final Prerequisite<Mutable<?, ?, ?>> rootPrereq = importAction.mutatesCtx(stmt.getRoot(), SOURCE_PRE_LINKAGE);
 
         importAction.apply(new InferenceAction() {
@@ -98,8 +97,8 @@ public final class ImportStatementSupport
             public void apply(final InferenceContext ctx) {
                 final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx);
                 verify(moduleName.equals(importedModuleContext.getArgument()));
-                final XMLNamespace importedModuleNamespace = verifyNotNull(
-                    importedModuleContext.getFromNamespace(ModuleNameToNamespace.class, moduleName));
+                final XMLNamespace importedModuleNamespace = verifyNotNull(importedModuleContext.getFromNamespace(
+                    SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE, moduleName));
                 final String impPrefix = SourceException.throwIfNull(
                     firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
                     "Missing prefix statement");
@@ -114,7 +113,7 @@ public final class ImportStatementSupport
                     }
                 }
 
-                stmt.addToNs(ImpPrefixToNamespace.class, impPrefix, importedModuleNamespace);
+                stmt.addToNs(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE, impPrefix, importedModuleNamespace);
             }
 
             @Override
@@ -147,6 +146,6 @@ public final class ImportStatementSupport
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         InferenceException.throwIf(substatements.isEmpty(), stmt, "Unexpected empty effective import statement");
         return EffectiveStatements.createImport(stmt.declared(), substatements,
-            verifyNotNull(stmt.getFromNamespace(ImportedVersionNamespace.class, Empty.value())));
+            verifyNotNull(stmt.getFromNamespace(ImportedVersionNamespace.INSTANCE, Empty.value())));
     }
 }
index 99250dcba13f17167906b4ab69d8483a9da54109..4c9061cc2f5f9995050341ee5e479340a48aebcf 100644 (file)
@@ -18,9 +18,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
  * Statement-local namespace carrying the versioning information about how the import was satisfied.
  */
 @Beta
-public final class ImportedVersionNamespace extends ParserNamespace<Empty, SourceIdentifier> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(ImportedVersionNamespace.class);
+public final class ImportedVersionNamespace {
+    public static final @NonNull ParserNamespace<Empty, SourceIdentifier> INSTANCE =
+        new ParserNamespace<>("imported-version");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private ImportedVersionNamespace() {
         // Hidden on purpose
index f92094a8789f20fd4ab41ac0cea242ef65a03cba..0314cc2e5c39925d058802845c957af771f952bd 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
@@ -31,10 +31,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prereq
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 final class RevisionImport {
     private RevisionImport() {
@@ -47,11 +44,11 @@ final class RevisionImport {
         final Unqualified moduleName = stmt.getArgument();
         final Revision revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
         if (revision == null) {
-            imported = importAction.requiresCtx(stmt, ModuleNamespace.class,
+            imported = importAction.requiresCtx(stmt, ParserNamespaces.MODULE,
                 NamespaceKeyCriterion.latestRevisionModule(moduleName), SOURCE_LINKAGE);
         } else {
-            imported = importAction.requiresCtx(stmt, ModuleNamespace.class, new SourceIdentifier(moduleName, revision),
-                SOURCE_LINKAGE);
+            imported = importAction.requiresCtx(stmt, ParserNamespaces.MODULE,
+                new SourceIdentifier(moduleName, revision), SOURCE_LINKAGE);
         }
 
         final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
@@ -61,18 +58,19 @@ final class RevisionImport {
             public void apply(final InferenceContext ctx) {
                 final StmtContext<?, ?, ?> importedModule = imported.resolve(ctx);
 
-                final SourceIdentifier importedModuleIdentifier =
-                    stmt.getFromNamespace(ModuleCtxToSourceIdentifier.class, importedModule);
-                stmt.addToNs(ImportedVersionNamespace.class, Empty.value(), importedModuleIdentifier);
+                final SourceIdentifier importedModuleIdentifier = stmt.getFromNamespace(
+                    SourceParserNamespaces.MODULECTX_TO_SOURCE, importedModule);
+                stmt.addToNs(ImportedVersionNamespace.INSTANCE, Empty.value(), importedModuleIdentifier);
 
-                final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(
-                    ModuleCtxToModuleQName.class, importedModule), stmt, "Failed to find module of %s", importedModule);
+                final QNameModule mod = InferenceException.throwIfNull(
+                    stmt.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, importedModule), stmt,
+                    "Failed to find module of %s", importedModule);
 
-                linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class,
-                    importedModuleIdentifier, importedModule);
+                linkageTarget.resolve(ctx).addToNs(SourceParserNamespaces.IMPORTED_MODULE, importedModuleIdentifier,
+                    importedModule);
                 final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
-                stmt.addToNs(ImportPrefixToModuleCtx.class, impPrefix, importedModule);
-                stmt.addToNs(ModuleQNameToPrefix.class, mod, impPrefix);
+                stmt.addToNs(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, impPrefix, importedModule);
+                stmt.addToNs(ModuleQNameToPrefix.INSTANCE, mod, impPrefix);
             }
 
             @Override
index a6653d9c262717e5116a02df3f035acabda90475..1845521b81ffe078f331790ead4a2dde11fe747b 100644 (file)
@@ -14,9 +14,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
 @Beta
-public final class ConfigListWarningNamespace extends ParserNamespace<StatementSourceReference, Boolean> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ConfigListWarningNamespace.class);
+public final class ConfigListWarningNamespace {
+    public static final @NonNull ParserNamespace<StatementSourceReference, Boolean> INSTANCE =
+        new ParserNamespace<>("configListWarning");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(INSTANCE);
 
     private ConfigListWarningNamespace() {
         // Hidden on purpose
index 5c25cbf675de4335de3cfda181da4972419057a3..6d397f26c4ee806cf4017a4851ace9bb612d355d 100644 (file)
@@ -118,7 +118,7 @@ public final class ListStatementSupport
 
     ListStatementSupport(final YangParserConfiguration config, final SubstatementValidator validator) {
         super(YangStmtMapping.LIST, instantiatedPolicy(), config, validator);
-        this.warnForUnkeyedLists = config.warnForUnkeyedLists();
+        warnForUnkeyedLists = config.warnForUnkeyedLists();
     }
 
     public static @NonNull ListStatementSupport rfc6020Instance(final YangParserConfiguration config) {
@@ -216,12 +216,12 @@ public final class ListStatementSupport
 
     private static void warnConfigList(final @NonNull Current<QName, ListStatement> stmt) {
         final StatementSourceReference ref = stmt.sourceReference();
-        final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.class, ref);
+        final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.INSTANCE, ref);
         // Hacky check if we have issued a warning for the original statement
         if (warned == null) {
             final StmtContext<?, ?, ?> ctx = stmt.caerbannog();
             verify(ctx instanceof Mutable, "Unexpected context %s", ctx);
-            ((Mutable<?, ?, ?>) ctx).addToNs(ConfigListWarningNamespace.class, ref, Boolean.TRUE);
+            ((Mutable<?, ?, ?>) ctx).addToNs(ConfigListWarningNamespace.INSTANCE, ref, Boolean.TRUE);
             LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
                     + "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
                     + "[defined at {}]", stmt.argument(), ref);
index ca8e7426257d1bd9bd61c6c8c0fdf217f182b040..c9a155ffb58633deb6502dab3f4b7ae06bce3f98 100644 (file)
@@ -34,7 +34,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameWithFlagsEffectiveStatementState;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
@@ -133,6 +133,6 @@ public final class ActionStatementSupport extends
     private static void appendImplicitSubstatement(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt,
             final QName substatementName) {
         stmt.addEffectiveSubstatement(stmt.createUndeclaredSubstatement(
-            verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null));
+            verifyNotNull(stmt.getFromNamespace(StatementSupport.NAMESPACE, substatementName)), null));
     }
 }
index 266c0ae7dacb65027c661136619a3b7c5978476d..d75c48b065d6102531ca6bea6b5c119768b93221 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -56,7 +56,7 @@ public final class BaseStatementSupport extends AbstractQNameStatementSupport<Ba
             final QName baseIdentityQName = baseStmtCtx.getArgument();
             final ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(
                 ModelProcessingPhase.STATEMENT_DEFINITION);
-            baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName,
+            baseIdentityAction.requiresCtx(baseStmtCtx, ParserNamespaces.IDENTITY, baseIdentityQName,
                 ModelProcessingPhase.STATEMENT_DEFINITION);
             baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
 
index 56a4e4e54e0da7783f58f4b6857f9fdca5e4b50e..00f1222816a304a73b2e59772e36cc787a8ead4c 100644 (file)
@@ -36,8 +36,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 public final class BelongsToStatementSupport
         extends AbstractUnqualifiedStatementSupport<BelongsToStatement, BelongsToEffectiveStatement> {
@@ -59,12 +58,13 @@ public final class BelongsToStatementSupport
         ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE);
 
         final Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(belongsToCtx,
-            ModuleNamespaceForBelongsTo.class, belongsToCtx.getArgument(), ModelProcessingPhase.SOURCE_LINKAGE);
+            SourceParserNamespaces.MODULE_FOR_BELONGSTO, belongsToCtx.getArgument(),
+            ModelProcessingPhase.SOURCE_LINKAGE);
 
         belongsToAction.apply(new InferenceAction() {
             @Override
             public void apply(final InferenceContext ctx) {
-                belongsToCtx.addToNs(BelongsToPrefixToModuleCtx.class,
+                belongsToCtx.addToNs(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX,
                     findFirstDeclaredSubstatement(belongsToCtx, PrefixStatement.class).getArgument(),
                     belongsToPrereq.resolve(ctx));
             }
index eec559721196e33994fb2d22605a79f2c8120a8a..1161d149ef13a2500d19b6fdbe399fe9eaabd56d 100644 (file)
@@ -46,7 +46,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameWithFlagsEffectiveStatementState;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
@@ -118,7 +117,7 @@ public final class ChoiceStatementSupport
         if (!caseShorthands.contains(stmtDef)) {
             return Optional.empty();
         }
-        return Optional.of(verifyNotNull(parent.getFromNamespace(StatementSupportNamespace.class,
+        return Optional.of(verifyNotNull(parent.getFromNamespace(StatementSupport.NAMESPACE,
             YangStmtMapping.CASE.getStatementName())));
     }
 
@@ -194,8 +193,7 @@ public final class ChoiceStatementSupport
     private static CaseSchemaNode findCase(final QName qname,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         for (final EffectiveStatement<?, ?> effectiveStatement : substatements) {
-            if (effectiveStatement instanceof CaseSchemaNode) {
-                final CaseSchemaNode choiceCaseNode = (CaseSchemaNode) effectiveStatement;
+            if (effectiveStatement instanceof CaseSchemaNode choiceCaseNode) {
                 if (qname.equals(choiceCaseNode.getQName())) {
                     return choiceCaseNode;
                 }
index db4d7bb4ba23a76a04569bea872447f206b80fe8..8eda7884b5b245ef9ed128ab050468ae7e163dd0 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 public final class DeviationStatementSupport
         extends AbstractStatementSupport<Absolute, DeviationStatement, DeviationEffectiveStatement> {
@@ -52,7 +52,8 @@ public final class DeviationStatementSupport
     @Override
     public void onFullDefinitionDeclared(
             final Mutable<Absolute, DeviationStatement, DeviationEffectiveStatement> ctx) {
-        final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot());
+        final QNameModule currentModule = ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME,
+            ctx.getRoot());
         final QNameModule targetModule = Iterables.getLast(ctx.getArgument().getNodeIdentifiers()).getModule();
 
         if (currentModule.equals(targetModule)) {
index ba133040efb00be3c41c1f2ece527ac31520bb53..df7a0041654fdc96738d3489f3bb191195e16302 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -31,7 +31,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 public final class FeatureStatementSupport
         extends AbstractQNameStatementSupport<FeatureStatement, FeatureEffectiveStatement> {
@@ -55,10 +55,10 @@ public final class FeatureStatementSupport
     @Override
     public void onFullDefinitionDeclared(final Mutable<QName, FeatureStatement, FeatureEffectiveStatement> stmt) {
         super.onFullDefinitionDeclared(stmt);
-        stmt.addContext(FeatureNamespace.class, stmt.getArgument(), stmt);
+        stmt.addContext(ParserNamespaces.FEATURE, stmt.getArgument(), stmt);
 
         // Do not build effective statement if supported features does not include this feature
-        final var supportedFeatures = stmt.getFromNamespace(SupportedFeaturesNamespace.class, Empty.value());
+        final var supportedFeatures = stmt.getFromNamespace(SourceParserNamespaces.SUPPORTED_FEATURES, Empty.value());
         if (supportedFeatures != null && !supportedFeatures.contains(stmt.getArgument())) {
             stmt.setUnsupported();
         }
index d461306385fa840a3a9aace293b3475a05ea453c..e8b13e578a566fd8dce0a4414a279d31fb5eb05a 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -106,7 +106,7 @@ public final class GroupingStatementSupport
             // Shadowing check: make sure we do not trample on pre-existing definitions. This catches sibling
             // declarations and parent declarations which have already been declared.
             checkConflict(parent, stmt);
-            parent.addContext(GroupingNamespace.class, stmt.getArgument(), stmt);
+            parent.addContext(ParserNamespaces.GROUPING, stmt.getArgument(), stmt);
 
             final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
             if (grandParent != null) {
@@ -155,7 +155,7 @@ public final class GroupingStatementSupport
 
     private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) {
         final QName arg = stmt.getArgument();
-        final StmtContext<?, ?, ?> existing = parent.getFromNamespace(GroupingNamespace.class, arg);
+        final StmtContext<?, ?, ?> existing = parent.getFromNamespace(ParserNamespaces.GROUPING, arg);
         SourceException.throwIf(existing != null, stmt, "Duplicate name for grouping %s", arg);
     }
 }
index 25da02437328bb47fcca25ea69d9e7a066540323..f51bdd37b318f2fa31faf0a84edb8622bf1655fa 100644 (file)
@@ -32,7 +32,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -82,9 +82,9 @@ public final class IdentityStatementSupport
     public void onStatementDefinitionDeclared(
             final Mutable<QName, IdentityStatement, IdentityEffectiveStatement> stmt) {
         final QName qname = stmt.getArgument();
-        final StmtContext<?, ?, ?> prev = stmt.getFromNamespace(IdentityNamespace.class, qname);
+        final StmtContext<?, ?, ?> prev = stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname);
         SourceException.throwIf(prev != null, stmt, "Duplicate identity definition %s", qname);
-        stmt.addToNs(IdentityNamespace.class, qname, stmt);
+        stmt.addToNs(ParserNamespaces.IDENTITY, qname, stmt);
     }
 
     @Override
@@ -111,7 +111,7 @@ public final class IdentityStatementSupport
             if (substatement instanceof BaseEffectiveStatement) {
                 final QName qname = ((BaseEffectiveStatement) substatement).argument();
                 final IdentityEffectiveStatement identity =
-                        verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, qname),
+                        verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname),
                             "Failed to find identity %s", qname)
                         .buildEffective();
                 verify(identity instanceof IdentitySchemaNode, "%s is not a IdentitySchemaNode", identity);
index 92d86b7e2ed4d8985c966d133947ed410c6fdd15..82756214cc95976028c8e66ccfb68fef6748e224 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -42,8 +42,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
 
 @Beta
@@ -87,10 +86,10 @@ public final class IncludeStatementSupport
         final ModelActionBuilder includeAction = stmt.newInferenceAction(SOURCE_LINKAGE);
         final Prerequisite<StmtContext<?, ?, ?>> requiresCtxPrerequisite;
         if (revision == null) {
-            requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class,
+            requiresCtxPrerequisite = includeAction.requiresCtx(stmt, ParserNamespaces.SUBMODULE,
                 NamespaceKeyCriterion.latestRevisionModule(submoduleName), SOURCE_LINKAGE);
         } else {
-            requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class,
+            requiresCtxPrerequisite = includeAction.requiresCtx(stmt, ParserNamespaces.SUBMODULE,
                 new SourceIdentifier(submoduleName, revision.argument()), SOURCE_LINKAGE);
         }
 
@@ -105,10 +104,11 @@ public final class IncludeStatementSupport
                         "Cannot include a version %s submodule in a version %s module", subVersion, modVersion);
                 }
 
-                stmt.addToNs(IncludedModuleContext.class,
+                stmt.addToNs(SourceParserNamespaces.INCLUDED_MODULE,
                     new SourceIdentifier(submoduleName, revision != null ? revision.getArgument() : null),
                     includedSubModuleContext);
-                stmt.addToNs(IncludedSubmoduleNameToModuleCtx.class, stmt.argument(), includedSubModuleContext);
+                stmt.addToNs(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX, stmt.argument(),
+                    includedSubModuleContext);
             }
 
             @Override
index a228e35c6d87f06291a87c617cc49f2e13103d33..9753a9f2e3d1a394b75d721d0205689c6fa36266 100644 (file)
@@ -32,7 +32,7 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
@@ -101,6 +101,6 @@ public final class RpcStatementSupport extends AbstractSchemaTreeStatementSuppor
     private static void appendImplicitSubstatement(final Mutable<QName, RpcStatement, RpcEffectiveStatement> stmt,
             final QName substatementName) {
         stmt.addEffectiveSubstatement(stmt.createUndeclaredSubstatement(
-            verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null));
+            verifyNotNull(stmt.getFromNamespace(StatementSupport.NAMESPACE, substatementName)), null));
     }
 }
index 40f22e6c71fc44381289faa9f72070b2693f111a..ce58e47f0975f2aff65cf696b46dd0a7a29dfd2a 100644 (file)
@@ -28,7 +28,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -73,7 +73,7 @@ public final class TypedefStatementSupport extends
             // Shadowing check: make sure we do not trample on pre-existing definitions. This catches sibling
             // declarations and parent declarations which have already been declared.
             checkConflict(parent, stmt);
-            parent.addContext(TypeNamespace.class, stmt.getArgument(), stmt);
+            parent.addContext(ParserNamespaces.TYPE, stmt.getArgument(), stmt);
 
             final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
             if (grandParent != null) {
@@ -128,7 +128,7 @@ public final class TypedefStatementSupport extends
 
     private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) {
         final QName arg = stmt.getArgument();
-        final StmtContext<?, ?, ?> existing = parent.getFromNamespace(TypeNamespace.class, arg);
+        final StmtContext<?, ?, ?> existing = parent.getFromNamespace(ParserNamespaces.TYPE, arg);
         // RFC7950 sections 5.5 and 6.2.1: identifiers must not be shadowed
         SourceException.throwIf(existing != null, stmt, "Duplicate name for typedef %s", arg);
     }
index 5bec0855b7cbbc47f598f91d53e0cfc2ea4e8000..01832062bc70f428c6325cefaf52b6b5f4bdd4eb 100644 (file)
@@ -151,8 +151,10 @@ public final class UniqueStatementSupport
                 // ... and before going further ...
                 action.apply(new RequireLeafDescendants(unique,
                     // ... require that each schema node identifier resolves against the schema tree
-                    Maps.uniqueIndex(unique.getArgument(), desc -> action.requiresCtxPath(list,
-                        SchemaTreeNamespace.class, desc.getNodeIdentifiers(), ModelProcessingPhase.EFFECTIVE_MODEL))));
+                    Maps.uniqueIndex(unique.getArgument(),
+                        desc -> action.requiresCtxPath(list,
+                            (SchemaTreeNamespace) SchemaTreeNamespace.instance(), desc.getNodeIdentifiers(),
+                            ModelProcessingPhase.EFFECTIVE_MODEL))));
             }
         }
 
index 443dc353f0bb4218e8b11af75fc92c16299d3046..561c37e863031164c74e4e6190f7788be2ed9726 100644 (file)
@@ -39,7 +39,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatemen
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleStatement, ModuleEffectiveStatement>
         implements Module, ModuleEffectiveStatement {
@@ -73,7 +73,7 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleS
         namespaceToPrefix = ImmutableMap.copyOf(tmp);
 
         final Map<Unqualified, StmtContext<?, ?, ?>> includedSubmodules =
-                stmt.localNamespacePortion(IncludedSubmoduleNameToModuleCtx.class);
+                stmt.localNamespacePortion(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
         nameToSubmodule = includedSubmodules == null ? ImmutableMap.of()
                 : ImmutableMap.copyOf(Maps.transformValues(includedSubmodules,
                     submodule -> (SubmoduleEffectiveStatement) submodule.buildEffective()));
index ef45830188e0b56e16b3d4352a8f840d397b2e32..81771ec0d450e1c3d343effe047bdb58fe6730ee 100644 (file)
@@ -39,9 +39,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
@@ -50,17 +48,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 @Beta
 public final class ModuleStatementSupport
@@ -142,19 +131,19 @@ public final class ModuleStatementSupport
         final XMLNamespace moduleNs = SourceException.throwIfNull(
             firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class), stmt,
             "Namespace of the module [%s] is missing", moduleName);
-        stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs);
+        stmt.addToNs(SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE, moduleName, moduleNs);
 
         final String modulePrefix = SourceException.throwIfNull(
             firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
             "Prefix of the module [%s] is missing", moduleName);
-        stmt.addToNs(ImpPrefixToNamespace.class, modulePrefix, moduleNs);
+        stmt.addToNs(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE, modulePrefix, moduleNs);
 
-        stmt.addContext(PreLinkageModuleNamespace.class, moduleName, stmt);
+        stmt.addContext(ParserNamespaces.PRELINKAGE_MODULE, moduleName, stmt);
 
         final Revision revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null);
         final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate).intern();
 
-        stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
+        stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_QNAME, stmt, qNameModule);
         stmt.setRootIdentifier(new SourceIdentifier(stmt.getArgument(), revisionDate));
     }
 
@@ -167,7 +156,7 @@ public final class ModuleStatementSupport
         final Revision revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null);
         final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate).intern();
         final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule =
-                stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
+                stmt.getFromNamespace(ParserNamespaces.NAMESPACE_TO_MODULE, qNameModule);
         if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
             throw new SourceException(stmt, "Module namespace collision: %s. At %s", qNameModule.getNamespace(),
                 possibleDuplicateModule.sourceReference());
@@ -176,21 +165,21 @@ public final class ModuleStatementSupport
         final Unqualified moduleName = stmt.getArgument();
         final SourceIdentifier moduleIdentifier = new SourceIdentifier(moduleName, revisionDate);
 
-        stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
-        stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleName, stmt);
-        stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
+        stmt.addContext(ParserNamespaces.MODULE, moduleIdentifier, stmt);
+        stmt.addContext(SourceParserNamespaces.MODULE_FOR_BELONGSTO, moduleName, stmt);
+        stmt.addContext(ParserNamespaces.NAMESPACE_TO_MODULE, qNameModule, stmt);
 
         final String modulePrefix = SourceException.throwIfNull(
             firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
             "Prefix of the module [%s] is missing", stmt.argument());
 
-        stmt.addToNs(QNameModuleNamespace.class, Empty.value(), qNameModule);
-        stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
-        stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
-        stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
-        stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
-        stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, moduleName);
-        stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
+        stmt.addToNs(QNameModuleNamespace.INSTANCE, Empty.value(), qNameModule);
+        stmt.addToNs(SourceParserNamespaces.PREFIX_TO_MODULE, modulePrefix, qNameModule);
+        stmt.addToNs(SourceParserNamespaces.MODULE_NAME_TO_QNAME, moduleName, qNameModule);
+        stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_QNAME, stmt, qNameModule);
+        stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_SOURCE, stmt, moduleIdentifier);
+        stmt.addToNs(SourceParserNamespaces.MODULE_NAMESPACE_TO_NAME, qNameModule, moduleName);
+        stmt.addToNs(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, modulePrefix, stmt);
     }
 
     @Override
@@ -249,7 +238,7 @@ public final class ModuleStatementSupport
             submodules.add((Submodule) submodule);
         }
 
-        final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.class, Empty.value()));
+        final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.INSTANCE, Empty.value()));
         try {
             return new ModuleEffectiveStatementImpl(stmt, substatements, submodules, qnameModule);
         } catch (SubstatementIndexingException e) {
@@ -259,7 +248,7 @@ public final class ModuleStatementSupport
 
     private static Collection<StmtContext<?, ?, ?>> submoduleContexts(final Current<?, ?> stmt) {
         final Map<Unqualified, StmtContext<?, ?, ?>> submodules = stmt.localNamespacePortion(
-            IncludedSubmoduleNameToModuleCtx.class);
+            SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
         return submodules == null ? List.of() : submodules.values();
     }
 
index adf7f6188a3ab9fb162f071ba3d66bf088780cb6..cd77b0b93ea32cce9fe8c7e49aee40122bfa5003 100644 (file)
@@ -18,9 +18,9 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
  * Module-local namespace holding the module's QName.
  */
 @Beta
-public final class QNameModuleNamespace extends ParserNamespace<Empty, QNameModule> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(QNameModuleNamespace.class);
+public final class QNameModuleNamespace {
+    public static final @NonNull ParserNamespace<Empty, QNameModule> INSTANCE = new ParserNamespace<>("QNameModule");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private QNameModuleNamespace() {
         // Hidden on purpose
index fda2dc969af856317d0adc0af4d900151342a2be..49e9b24b3100146e71ca90e405efbfc65dc411bf 100644 (file)
@@ -92,7 +92,7 @@ public final class RefineStatementSupport
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         // Empty refine is exceedingly unlikely: let's be lazy and reuse the implementation
         return new RefineEffectiveStatementImpl(stmt.declared(), substatements,
-            (SchemaNode) verifyNotNull(stmt.namespaceItem(RefineTargetNamespace.class, Empty.value()))
+            (SchemaNode) verifyNotNull(stmt.namespaceItem(RefineTargetNamespace.INSTANCE, Empty.value()))
                 .buildEffective());
     }
 }
index f0d05a8d15ff0fdeef847445a7927f91df340256..9b1ebf677df6c907066b24f675bcbf2df10c8262 100644 (file)
@@ -15,9 +15,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 @Beta
-public final class RefineTargetNamespace extends ParserNamespace<Empty, StmtContext<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(RefineTargetNamespace.class);
+public final class RefineTargetNamespace {
+    public static final @NonNull ParserNamespace<Empty, StmtContext<?, ?, ?>> INSTANCE =
+        new ParserNamespace<>("refineTarget");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private RefineTargetNamespace() {
         // Hidden on purpose
index f6a388234b13242adec2a95a64c5eb83c7f2f987..2435680a3b2e37e27b2517bef731807e08d35c5f 100644 (file)
@@ -40,9 +40,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 final class SubmoduleEffectiveStatementImpl
         extends AbstractEffectiveModule<SubmoduleStatement, SubmoduleEffectiveStatement>
@@ -59,7 +58,7 @@ final class SubmoduleEffectiveStatementImpl
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         super(stmt, substatements, findSubmodulePrefix(stmt, substatements));
 
-        final QNameModule belongsToModuleQName = stmt.getFromNamespace(ModuleNameToModuleQName.class,
+        final QNameModule belongsToModuleQName = stmt.getFromNamespace(SourceParserNamespaces.MODULE_NAME_TO_QNAME,
             findBelongsTo(stmt, substatements).argument());
 
         final Builder<String, ModuleEffectiveStatement> prefixToModuleBuilder = ImmutableMap.builder();
@@ -82,7 +81,7 @@ final class SubmoduleEffectiveStatementImpl
          * sealing of this statement.
          */
         final Map<Unqualified, StmtContext<?, ?, ?>> includedSubmodulesMap = stmt.localNamespacePortion(
-            IncludedSubmoduleNameToModuleCtx.class);
+            SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
         if (includedSubmodulesMap != null) {
             final Set<StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>> submoduleContextsInit =
                 new HashSet<>();
index d0c19bc08a488e2244d36c6297471cac45255d83..da6ae7aca3ced77b5038397df8639629160755e1 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators
 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
 import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
@@ -36,8 +36,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 @Beta
 public final class SubmoduleStatementSupport
@@ -124,13 +124,13 @@ public final class SubmoduleStatementSupport
             StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null));
 
         final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>
-            possibleDuplicateSubmodule = stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
+            possibleDuplicateSubmodule = stmt.getFromNamespace(ParserNamespaces.SUBMODULE, submoduleIdentifier);
         if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
             throw new SourceException(stmt, "Submodule name collision: %s. At %s", stmt.rawArgument(),
                 possibleDuplicateSubmodule.sourceReference());
         }
 
-        stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
+        stmt.addContext(ParserNamespaces.SUBMODULE, submoduleIdentifier, stmt);
 
         final Unqualified belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(),
             BelongsToStatement.class);
@@ -139,7 +139,7 @@ public final class SubmoduleStatementSupport
             "Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawArgument());
 
         final String prefix = prefixSubStmtCtx.rawArgument();
-        stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
+        stmt.addToNs(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME, prefix, belongsToModuleName);
     }
 
     @Override
index aea249a6ac74de6a985c5aa13f58c3da4661b016..c9590bcf404da74b4f896a21d2a3cd7005487d4c 100644 (file)
@@ -69,7 +69,7 @@ import org.opendaylight.yangtools.yang.model.ri.type.RequireInstanceRestrictedTy
 import org.opendaylight.yangtools.yang.model.ri.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.model.ri.type.StringTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -146,12 +146,12 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
         final QName typeQName = stmt.getArgument();
         final BuiltinEffectiveStatement builtin = STATIC_BUILT_IN_TYPES.get(typeQName);
         if (builtin != null) {
-            stmt.addToNs(BaseTypeNamespace.class, Empty.value(), builtin);
+            stmt.addToNs(BaseTypeNamespace.INSTANCE, Empty.value(), builtin);
             return;
         }
 
         final ModelActionBuilder typeAction = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
-        final Prerequisite<StmtContext<?, ?, ?>> typePrereq = typeAction.requiresCtx(stmt, TypeNamespace.class,
+        final Prerequisite<StmtContext<?, ?, ?>> typePrereq = typeAction.requiresCtx(stmt, ParserNamespaces.TYPE,
                 typeQName, ModelProcessingPhase.EFFECTIVE_MODEL);
         typeAction.mutatesEffectiveCtx(stmt.getParentContext());
 
@@ -163,7 +163,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
             @Override
             public void apply(final InferenceContext ctx) {
                 // Note: do not attempt to call buildEffective() here
-                stmt.addToNs(BaseTypeNamespace.class, Empty.value(), typePrereq.resolve(ctx));
+                stmt.addToNs(BaseTypeNamespace.INSTANCE, Empty.value(), typePrereq.resolve(ctx));
             }
 
             @Override
@@ -296,7 +296,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
      * @throws SourceException if the target type cannot be found
      */
     private static @NonNull TypeEffectiveStatement<TypeStatement> resolveType(final NamespaceStmtCtx ctx) {
-        final Object obj = verifyNotNull(ctx.namespaceItem(BaseTypeNamespace.class, Empty.value()));
+        final Object obj = verifyNotNull(ctx.namespaceItem(BaseTypeNamespace.INSTANCE, Empty.value()));
         if (obj instanceof BuiltinEffectiveStatement) {
             return (BuiltinEffectiveStatement) obj;
         } else if (obj instanceof StmtContext) {
@@ -314,9 +314,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
                 RestrictedTypes.newBinaryBuilder(baseType, typeEffectiveQName(ctx));
 
         for (EffectiveStatement<?, ?> stmt : substatements) {
-            if (stmt instanceof LengthEffectiveStatement) {
-                final LengthEffectiveStatement length = (LengthEffectiveStatement)stmt;
-
+            if (stmt instanceof LengthEffectiveStatement length) {
                 try {
                     builder.setLengthConstraint(length, length.argument());
                 } catch (IllegalStateException e) {
@@ -361,8 +359,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
                 RestrictedTypes.newDecima64Builder(baseType, typeEffectiveQName(ctx));
 
         for (EffectiveStatement<?, ?> stmt : substatements) {
-            if (stmt instanceof RangeEffectiveStatement) {
-                final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
+            if (stmt instanceof RangeEffectiveStatement range) {
                 builder.setRangeConstraint(range, range.argument());
             }
             if (stmt instanceof FractionDigitsEffectiveStatement) {
@@ -427,8 +424,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
                 final TypeStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
                 final RangeRestrictedTypeBuilder<T, N> builder) {
         for (EffectiveStatement<?, ?> stmt : substatements) {
-            if (stmt instanceof RangeEffectiveStatement) {
-                final RangeEffectiveStatement rangeStmt = (RangeEffectiveStatement)stmt;
+            if (stmt instanceof RangeEffectiveStatement rangeStmt) {
                 builder.setRangeConstraint(rangeStmt, rangeStmt.argument());
             }
         }
@@ -461,9 +457,7 @@ abstract class AbstractTypeStatementSupport extends AbstractTypeSupport<TypeStat
             AbstractTypeStatementSupport.typeEffectiveQName(ctx));
 
         for (EffectiveStatement<?, ?> stmt : substatements) {
-            if (stmt instanceof LengthEffectiveStatement) {
-                final LengthEffectiveStatement length = (LengthEffectiveStatement)stmt;
-
+            if (stmt instanceof LengthEffectiveStatement length) {
                 try {
                     builder.setLengthConstraint(length, length.argument());
                 } catch (IllegalStateException e) {
index 66b69ebbda044c743b88287cc17ab33ed1ff0f9c..6fdf016dc6b4e1b914280bcbe1b5628475123d7a 100644 (file)
@@ -14,9 +14,9 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 
 @Beta
-public final class BaseTypeNamespace extends ParserNamespace<Empty, Object> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(BaseTypeNamespace.class);
+public final class BaseTypeNamespace {
+    public static final @NonNull ParserNamespace<Empty, Object> INSTANCE = new ParserNamespace<>("baseType");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private BaseTypeNamespace() {
         // Hidden on purpose
index b325719a7bac3504892f72fb84740dbbf38f3d71..2b3b136b23c1ed57948dfcb7c7ad38d084df9cd2 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefS
 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
 import org.opendaylight.yangtools.yang.model.ri.type.IdentityrefTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
@@ -65,7 +65,7 @@ final class IdentityRefSpecificationSupport extends AbstractTypeSupport<Identity
                 StmtContextUtils.findAllDeclaredSubstatements(stmt, BaseStatement.class);
         for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) {
             final QName baseIdentity = baseStmt.getArgument();
-            final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(IdentityNamespace.class, baseIdentity);
+            final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(ParserNamespaces.IDENTITY, baseIdentity);
             InferenceException.throwIfNull(stmtCtx, stmt,
                 "Referenced base identity '%s' doesn't exist in given scope (module, imported modules, submodules)",
                 baseIdentity.getLocalName());
@@ -100,7 +100,7 @@ final class IdentityRefSpecificationSupport extends AbstractTypeSupport<Identity
             if (subStmt instanceof BaseEffectiveStatement) {
                 final QName identityQName = ((BaseEffectiveStatement) subStmt).argument();
                 final IdentityEffectiveStatement baseIdentity =
-                    verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, identityQName)).buildEffective();
+                    verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, identityQName)).buildEffective();
                 verify(baseIdentity instanceof IdentitySchemaNode, "Statement %s is not an IdentitySchemaNode",
                     baseIdentity);
                 builder.addIdentity((IdentitySchemaNode) baseIdentity);
index 64239b2c6a76b0438bf76466b45eff22f0205224..20f5b165a407d51e6faf2c3dab1de9bf819f85ec 100644 (file)
@@ -15,9 +15,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 @Beta
-public final class SourceGroupingNamespace extends ParserNamespace<Empty, StmtContext<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(SourceGroupingNamespace.class);
+public final class SourceGroupingNamespace {
+    public static final @NonNull ParserNamespace<Empty, StmtContext<?, ?, ?>> INSTANCE =
+        new ParserNamespace<>("sourceGrouping");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private SourceGroupingNamespace() {
         // Hidden on purpose
index b2be7e546521c3c7df7f24378eb28942e685840b..08359da63a7238d451b9a72672c5145fd1fa6f96 100644 (file)
@@ -43,7 +43,7 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBund
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineTargetNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
 import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
@@ -59,10 +59,10 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -100,9 +100,9 @@ public final class UsesStatementSupport
         final QName groupingName = usesNode.argument();
 
         final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode,
-                GroupingNamespace.class, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
+            ParserNamespaces.GROUPING, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
         final Prerequisite<? extends Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesEffectiveCtx(
-                usesNode.getParentContext());
+            usesNode.getParentContext());
 
         usesAction.apply(new InferenceAction() {
 
@@ -114,7 +114,7 @@ public final class UsesStatementSupport
                 copyFromSourceToTarget(sourceGrpStmtCtx, targetNodeStmtCtx, usesNode);
                 resolveUsesNode(usesNode, targetNodeStmtCtx);
                 StmtContextUtils.validateIfFeatureAndWhenOnListKeys(usesNode);
-                usesNode.addToNs(SourceGroupingNamespace.class, Empty.value(), sourceGrpStmtCtx);
+                usesNode.addToNs(SourceGroupingNamespace.INSTANCE, Empty.value(), sourceGrpStmtCtx);
             }
 
             @Override
@@ -141,7 +141,7 @@ public final class UsesStatementSupport
     protected UsesEffectiveStatement createEffective(final Current<QName, UsesStatement> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         final EffectiveStatement<?, ?> source =
-            verifyNotNull(stmt.getFromNamespace(SourceGroupingNamespace.class, Empty.value())).buildEffective();
+            verifyNotNull(stmt.getFromNamespace(SourceGroupingNamespace.INSTANCE, Empty.value())).buildEffective();
         verify(source instanceof GroupingDefinition, "Unexpected source %s", source);
         final GroupingDefinition sourceGrouping = (GroupingDefinition) source;
 
@@ -169,8 +169,7 @@ public final class UsesStatementSupport
         final Map<Descendant, SchemaNode> refines = new LinkedHashMap<>();
 
         for (EffectiveStatement<?, ?> effectiveStatement : substatements) {
-            if (effectiveStatement instanceof RefineEffectiveStatementImpl) {
-                final RefineEffectiveStatementImpl refineStmt = (RefineEffectiveStatementImpl) effectiveStatement;
+            if (effectiveStatement instanceof RefineEffectiveStatementImpl refineStmt) {
                 refines.put(refineStmt.argument(), refineStmt.getRefineTargetNode());
             }
         }
@@ -257,7 +256,7 @@ public final class UsesStatementSupport
     private static QNameModule getNewQNameModule(final StmtContext<?, ?, ?> targetCtx,
             final StmtContext<?, ?, ?> stmtContext) {
         if (targetCtx.getParentContext() == null) {
-            return targetCtx.getFromNamespace(ModuleCtxToModuleQName.class, targetCtx);
+            return targetCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, targetCtx);
         }
         if (targetCtx.publicDefinition() == YangStmtMapping.AUGMENT) {
             return StmtContextUtils.getRootModuleQName(targetCtx);
@@ -317,7 +316,7 @@ public final class UsesStatementSupport
         // Target is a prerequisite for the 'refine', hence if the target is not supported, the refine is not supported
         // as well. Otherwise add a pointer to the target into refine's local namespace.
         if (refineTargetNodeCtx.isSupportedToBuildEffective()) {
-            subStmtCtx.addToNs(RefineTargetNamespace.class, Empty.value(), refineTargetNodeCtx);
+            subStmtCtx.addToNs(RefineTargetNamespace.INSTANCE, Empty.value(), refineTargetNodeCtx);
         } else {
             subStmtCtx.setUnsupported();
         }
@@ -358,7 +357,7 @@ public final class UsesStatementSupport
 
     private static boolean isSupportedRefineSubstatement(final StmtContext<?, ?, ?> refineSubstatementCtx) {
         final Collection<?> supportedRefineSubstatements = refineSubstatementCtx.getFromNamespace(
-                ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
+                ValidationBundles.NAMESPACE, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
 
         return supportedRefineSubstatements == null || supportedRefineSubstatements.isEmpty()
                 || supportedRefineSubstatements.contains(refineSubstatementCtx.publicDefinition())
index d17a74e273cc417506b395071abb79bde962c6ef..d4a32c5ff71ffde91801fa204c199807fde734bd 100644 (file)
@@ -22,7 +22,7 @@ final class ThirdPartyExtensionEffectiveStatementImpl
     ThirdPartyExtensionEffectiveStatementImpl(final Current<String, ThirdPartyExtensionStatement> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         super(stmt.declared(), stmt.argument(), stmt.history(), substatements);
-        valueFromNamespace = stmt.getFromNamespace(ThirdPartyNamespace.class, Empty.value());
+        valueFromNamespace = stmt.getFromNamespace(ThirdPartyNamespace.INSTANCE, Empty.value());
     }
 
     @Override
index 0b23fde5c36b12bc3ee2bd7b69372836a6a51a15..77756860bbeb12fdb37c4f06f083c6fca50959fd 100644 (file)
@@ -28,7 +28,7 @@ public final class ThirdPartyExtensionSupport
     public void onFullDefinitionDeclared(
             final Mutable<String, ThirdPartyExtensionStatement, ThirdPartyExtensionEffectiveStatement> stmt) {
         super.onFullDefinitionDeclared(stmt);
-        stmt.addToNs(ThirdPartyNamespace.class, Empty.value(), "Third-party namespace test.");
+        stmt.addToNs(ThirdPartyNamespace.INSTANCE, Empty.value(), "Third-party namespace test.");
     }
 
     @Override
index be92f06b232f1a17d1a5c52178812c9ce09e0950..ab130edd8d932017f470e42b525ccc8fdf3ec490 100644 (file)
@@ -15,9 +15,9 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 /**
  * ThirdPartyNamespace.
  */
-public final class ThirdPartyNamespace extends ParserNamespace<Empty, String> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.statementLocal(ThirdPartyNamespace.class);
+public final class ThirdPartyNamespace {
+    public static final @NonNull ParserNamespace<Empty, String> INSTANCE = new ParserNamespace<>("third-party");
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
 
     private ThirdPartyNamespace() {
         // Hidden on purpose
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ExtensionNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ExtensionNamespace.java
deleted file mode 100644 (file)
index 2dc9160..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Extension namespace. All extension names defined in a module and its submodules share the same extension identifier
- * namespace, where each extension is identified by a QName formed from the defining module's QNameModule and the
- * identifier specified in extension statement's argument.
- */
-public final class ExtensionNamespace
-        extends StatementNamespace<QName, ExtensionStatement, ExtensionEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ExtensionNamespace.class);
-
-    private ExtensionNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/FeatureNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/FeatureNamespace.java
deleted file mode 100644 (file)
index dad26b2..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Feature namespace. All feature names defined in a module and its submodules share the same feature identifier
- * namespace. Each feature is identified by a QName formed from the defining module's QNameModule and the feature name.
- */
-public final class FeatureNamespace extends StatementNamespace<QName, FeatureStatement, FeatureEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(FeatureNamespace.class);
-
-    private FeatureNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/GroupingNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/GroupingNamespace.java
deleted file mode 100644 (file)
index c3d010c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
-
-/**
- * Grouping namespace. * All grouping names defined within a parent node or at the top level of the module
- * or its submodules share the same grouping identifier namespace. This namespace is scoped to all
- * descendant nodes of the parent node or module.
- *
- * <p>
- * This means that any descendant node may use that grouping, and it MUST NOT define a grouping with the same name.
- */
-public final class GroupingNamespace extends TreeScoped<QName, GroupingStatement, GroupingEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.treeScoped(GroupingNamespace.class);
-
-    private GroupingNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/IdentityNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/IdentityNamespace.java
deleted file mode 100644 (file)
index ac101ff..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Identity namespace. All identity names defined in a module and its submodules share the same identity identifier
- * namespace.
- */
-public final class IdentityNamespace extends StatementNamespace<QName, IdentityStatement, IdentityEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(IdentityNamespace.class);
-
-    private IdentityNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ModuleNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ModuleNamespace.java
deleted file mode 100644 (file)
index daf6162..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Module namespace. All modules known to the reactor are populated to this namespace. Each module is identified
- * by a {@link SourceIdentifier}.
- */
-public final class ModuleNamespace
-        extends StatementNamespace<SourceIdentifier, ModuleStatement, ModuleEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleNamespace.class);
-
-    private ModuleNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceBehaviours.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceBehaviours.java
new file mode 100644 (file)
index 0000000..b3f451b
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2022 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;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+/**
+ * {@link NamespaceBehaviour}s corresponding to {@link ParserNamespaces}.
+ */
+public final class NamespaceBehaviours {
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> EXTENSION =
+        NamespaceBehaviour.global(ParserNamespaces.EXTENSION);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> FEATURE =
+        NamespaceBehaviour.global(ParserNamespaces.FEATURE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> GROUPING =
+        NamespaceBehaviour.treeScoped(ParserNamespaces.GROUPING);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> IDENTITY =
+        NamespaceBehaviour.global(ParserNamespaces.IDENTITY);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE =
+        NamespaceBehaviour.global(ParserNamespaces.MODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> SUBMODULE =
+        NamespaceBehaviour.global(ParserNamespaces.SUBMODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> TYPE =
+        NamespaceBehaviour.treeScoped(ParserNamespaces.TYPE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> NAMESPACE_TO_MODULE =
+        NamespaceBehaviour.global(ParserNamespaces.NAMESPACE_TO_MODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> PRELINKAGE_MODULE =
+        NamespaceBehaviour.global(ParserNamespaces.PRELINKAGE_MODULE);
+
+    private NamespaceBehaviours() {
+        // Hidden on purpose
+    }
+}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceToModule.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceToModule.java
deleted file mode 100644 (file)
index 7218155..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * A derived namespace allowing lookup of modules based on their {@link QNameModule}.
- */
-public final class NamespaceToModule
-        extends StatementNamespace<QNameModule, ModuleStatement, ModuleEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(NamespaceToModule.class);
-
-    private NamespaceToModule() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ParserNamespaces.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/ParserNamespaces.java
new file mode 100644 (file)
index 0000000..fe266db
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2022 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;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
+
+/**
+ * Baseline {@link ParserNamespace}s mostly derived from YANG specification.
+ */
+public final class ParserNamespaces {
+    /**
+     * Extension namespace. All extension names defined in a module and its submodules share the same extension
+     * identifier namespace, where each extension is identified by a QName formed from the defining module's QNameModule
+     * and the identifier specified in extension statement's argument.
+     */
+    public static final @NonNull StatementNamespace<QName, ExtensionStatement, ExtensionEffectiveStatement> EXTENSION =
+        new StatementNamespace<>("extension");
+
+    /**
+     * Feature namespace. All feature names defined in a module and its submodules share the same feature identifier
+     * namespace. Each feature is identified by a QName formed from the defining module's QNameModule and the feature
+     * name.
+     */
+    public static final @NonNull StatementNamespace<QName, FeatureStatement, FeatureEffectiveStatement> FEATURE =
+        new StatementNamespace<>("feature");
+
+    /**
+     * Grouping namespace. * All grouping names defined within a parent node or at the top level of the module
+     * or its submodules share the same grouping identifier namespace. This namespace is scoped to all
+     * descendant nodes of the parent node or module.
+     *
+     * <p>
+     * This means that any descendant node may use that grouping, and it MUST NOT define a grouping with the same name.
+     */
+    public static final @NonNull TreeScoped<QName, GroupingStatement, GroupingEffectiveStatement> GROUPING =
+        new TreeScoped<>("grouping");
+
+    /**
+     * Identity namespace. All identity names defined in a module and its submodules share the same identity identifier
+     * namespace.
+     */
+    public static final @NonNull StatementNamespace<QName, IdentityStatement, IdentityEffectiveStatement> IDENTITY =
+        new StatementNamespace<>("identity");
+
+    /**
+     * Module namespace. All modules known to the reactor are populated to this namespace. Each module is identified
+     * by a {@link SourceIdentifier}.
+     */
+    public static final @NonNull StatementNamespace<SourceIdentifier, ModuleStatement, ModuleEffectiveStatement> MODULE
+        = new StatementNamespace<>("module");
+
+    /**
+     * Submodule equivalent of {@link #MODULE}.
+     */
+    public static final @NonNull StatementNamespace<SourceIdentifier, SubmoduleStatement, SubmoduleEffectiveStatement>
+        SUBMODULE = new StatementNamespace<>("submodule");
+
+    /**
+     * Derived types namespace. All derived type names defined within a parent node or at the top level of the module
+     * (or its submodules) share the same type identifier namespace.
+     *
+     * <p>
+     * This namespace is scoped to all descendant nodes of the parent node or module. This means that any descendant
+     * node may use that typedef, and it MUST NOT define a typedef with the same name.
+     *
+     * <p>
+     * This namespace includes all type definitions implied by the language in which the current statement resides
+     * (e.g. RFC6020/RFC7950 for YANG 1.0/1.1).
+     */
+    public static final @NonNull TreeScoped<QName, TypedefStatement, TypedefEffectiveStatement> TYPE =
+        new TreeScoped<>("typedef");
+
+    /**
+     * A derived namespace allowing lookup of modules based on their {@link QNameModule}.
+     */
+    public static final @NonNull StatementNamespace<QNameModule, ModuleStatement, ModuleEffectiveStatement>
+        NAMESPACE_TO_MODULE = new StatementNamespace<>("namespace-to-module");
+
+    /**
+     * Intermediate-stage namespace equivalent to {@link #MODULE} except it is keyed by module names. This namespace is
+     * used to resolve inter-module references before actual linkage occurs.
+     */
+    public static final @NonNull StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement>
+        PRELINKAGE_MODULE = new StatementNamespace<>("prelinkage-module");
+
+    private ParserNamespaces() {
+        // Hidden on purpose
+    }
+}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/PreLinkageModuleNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/PreLinkageModuleNamespace.java
deleted file mode 100644 (file)
index 141ecfe..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Intermediate-stage namespace equivalent to ModuleNamespace except it is keyed by module names. This namespace is
- * used to resolve inter-module references before actual linkage occurs.
- */
-public final class PreLinkageModuleNamespace
-        extends StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(PreLinkageModuleNamespace.class);
-
-    private PreLinkageModuleNamespace() {
-        // Hidden on purpose
-    }
-}
index 4402843ea98f9a0616a0d82a46137edc421976a9..325f7fe0078dc3a1e7005be242e1cf23eeec8340 100644 (file)
@@ -7,13 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi;
 
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.annotations.Beta;
+import java.io.Serial;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -22,11 +19,9 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 /**
  * Statement local namespace, which holds direct schema node descendants. This corresponds to the contents of the schema
@@ -37,72 +32,18 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 @Beta
 public final class SchemaTreeNamespace<D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
         extends StatementNamespace<QName, D, E> {
-    public static final class Behaviour<D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
-            extends NamespaceBehaviour<QName, StmtContext<?, D, E>, SchemaTreeNamespace<D, E>> {
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        Behaviour() {
-            super((Class) SchemaTreeNamespace.class);
-        }
-
-        /**
-         * {@inheritDoc}
-         *
-         * <p>
-         * This method is analogous to {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)}.
-         */
-        @Override
-        public StmtContext<?, D, E> getFrom(final NamespaceStorageNode storage, final QName key) {
-            // Get the backing storage node for the requested storage
-            final NamespaceStorageNode storageNode = globalOrStatementSpecific(storage);
-            // Check try to look up existing node
-            final StmtContext<?, D, E> existing = storageNode.getFromLocalStorage(getIdentifier(), key);
-
-            // An existing node takes precedence, if it does not exist try to request it
-            return existing != null ? existing : requestFrom(storageNode, key);
-        }
-
-        @Override
-        public Map<QName, StmtContext<?, D, E>> getAllFrom(final NamespaceStorageNode storage) {
-            // FIXME: 7.0.0: this method needs to be well-defined
-            return null;
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
-            final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
-                SchemaTreeNamespace.class, key, value);
-
-            if (prev != null) {
-                throw new SourceException(value,
-                    "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
-                    value.getRoot().rawArgument(), key, prev.argument(), prev.sourceReference());
-            }
-        }
+    @Serial
+    private static final long serialVersionUID = 1L;
+    private static final @NonNull SchemaTreeNamespace<?, ?> INSTANCE = new SchemaTreeNamespace<>();
 
-        private static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
-                StmtContext<?, D, E> requestFrom(final NamespaceStorageNode storageNode, final QName key) {
-            return storageNode instanceof OnDemandSchemaTreeStorageNode ondemand ? ondemand.requestSchemaTreeChild(key)
-                : null;
-        }
-
-        private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
-            NamespaceStorageNode current = requireNonNull(storage);
-            while (!isLocalOrGlobal(current.getStorageNodeType())) {
-                current = verifyNotNull(current.getParentNamespaceStorage());
-            }
-            return current;
-        }
-
-        private static boolean isLocalOrGlobal(final StorageNodeType type) {
-            return type == StorageNodeType.STATEMENT_LOCAL || type == StorageNodeType.GLOBAL;
-        }
+    private SchemaTreeNamespace() {
+        super("schemaTree");
     }
 
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = new Behaviour<>();
-
-    private SchemaTreeNamespace() {
-        // Hidden on purpose
+    @SuppressWarnings("unchecked")
+    public static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
+            @NonNull SchemaTreeNamespace<D, E> instance() {
+        return (SchemaTreeNamespace<D, E>) INSTANCE;
     }
 
     /**
@@ -122,17 +63,13 @@ public final class SchemaTreeNamespace<D extends DeclaredStatement<QName>, E ext
         }
 
         QName nextPath = iterator.next();
-        @SuppressWarnings("unchecked")
-        StmtContext<?, ?, ?> current = (StmtContext<?, ?, ?>) root.getFromNamespace(SchemaTreeNamespace.class,
-            nextPath);
+        StmtContext<?, ?, ?> current = root.getFromNamespace(SchemaTreeNamespace.INSTANCE, nextPath);
         if (current == null) {
             return Optional.ofNullable(tryToFindUnknownStatement(nextPath.getLocalName(), root));
         }
         while (current != null && iterator.hasNext()) {
             nextPath = iterator.next();
-            @SuppressWarnings("unchecked")
-            final StmtContext<?, ?, ?> nextNodeCtx = (StmtContext<?, ?, ?>) current.getFromNamespace(
-                SchemaTreeNamespace.class, nextPath);
+            final StmtContext<?, ?, ?> nextNodeCtx = current.getFromNamespace(SchemaTreeNamespace.INSTANCE, nextPath);
             if (nextNodeCtx == null) {
                 return Optional.ofNullable(tryToFindUnknownStatement(nextPath.getLocalName(), current));
             }
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SchemaTreeNamespaceBehaviour.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SchemaTreeNamespaceBehaviour.java
new file mode 100644 (file)
index 0000000..0839c0e
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2022 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;
+
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+/**
+ * {@link NamespaceBehaviour} handling {@link SchemaTreeNamespace}.
+ */
+public final class SchemaTreeNamespaceBehaviour<D extends DeclaredStatement<QName>,
+            E extends SchemaTreeEffectiveStatement<D>>
+        extends NamespaceBehaviour<QName, StmtContext<?, D, E>, SchemaTreeNamespace<D, E>> {
+    public static final @NonNull SchemaTreeNamespaceBehaviour<?, ?> INSTANCE = new SchemaTreeNamespaceBehaviour<>();
+
+    private SchemaTreeNamespaceBehaviour() {
+        super(SchemaTreeNamespace.instance());
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * <p>
+     * This method is analogous to {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)}.
+     */
+    @Override
+    public StmtContext<?, D, E> getFrom(final NamespaceStorageNode storage, final QName key) {
+        // Get the backing storage node for the requested storage
+        final NamespaceStorageNode storageNode = globalOrStatementSpecific(storage);
+        // Check try to look up existing node
+        final StmtContext<?, D, E> existing = storageNode.getFromLocalStorage(getIdentifier(), key);
+
+        // An existing node takes precedence, if it does not exist try to request it
+        return existing != null ? existing : requestFrom(storageNode, key);
+    }
+
+    @Override
+    public Map<QName, StmtContext<?, D, E>> getAllFrom(final NamespaceStorageNode storage) {
+        // FIXME: 7.0.0: this method needs to be well-defined
+        return null;
+    }
+
+    @Override
+    public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
+        final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
+            SchemaTreeNamespace.instance(), key, value);
+
+        if (prev != null) {
+            throw new SourceException(value,
+                "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
+                value.getRoot().rawArgument(), key, prev.argument(), prev.sourceReference());
+        }
+    }
+
+    private static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
+            StmtContext<?, D, E> requestFrom(final NamespaceStorageNode storageNode, final QName key) {
+        return storageNode instanceof OnDemandSchemaTreeStorageNode ondemand ? ondemand.requestSchemaTreeChild(key)
+            : null;
+    }
+
+    private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
+        NamespaceStorageNode current = requireNonNull(storage);
+        while (!isLocalOrGlobal(current.getStorageNodeType())) {
+            current = verifyNotNull(current.getParentNamespaceStorage());
+        }
+        return current;
+    }
+
+    private static boolean isLocalOrGlobal(final StorageNodeType type) {
+        return type == StorageNodeType.STATEMENT_LOCAL || type == StorageNodeType.GLOBAL;
+    }
+}
\ No newline at end of file
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SubmoduleNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SubmoduleNamespace.java
deleted file mode 100644 (file)
index cd5009c..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Submodule equivalent of ModuleNamespace.
- */
-// FIXME: describe scoping of this namespace
-public final class SubmoduleNamespace
-        extends StatementNamespace<SourceIdentifier, SubmoduleStatement, SubmoduleEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(SubmoduleNamespace.class);
-
-    private SubmoduleNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/TypeNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/TypeNamespace.java
deleted file mode 100644 (file)
index 49966d9..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
-
-/**
- * Derived types namespace. All derived type names defined within a parent node or at the top level of the module
- * (or its submodules) share the same type identifier namespace.
- *
- * <p>
- * This namespace is scoped to all descendant nodes of the parent node or module. This means that any descendant node
- * may use that typedef, and it MUST NOT define a typedef with the same name.
- *
- * <p>
- * This namespace includes all type definitions implied by the language in which the current statement resides
- * (e.g. RFC6020/RFC7950 for YANG 1.0/1.1).
- */
-public final class TypeNamespace extends TreeScoped<QName, TypedefStatement, TypedefEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.treeScoped(TypeNamespace.class);
-
-    private TypeNamespace() {
-        // Hidden on purpose
-    }
-}
index 9d70d31829490b3fb07cb111913e75ab5c13c78e..386026162f883be713a8b7a7a4fef7cd83f49c4c 100644 (file)
@@ -112,7 +112,7 @@ public abstract class AbstractSchemaTreeStatementSupport<D extends DeclaredState
      */
     @Override
     public void onStatementAdded(final Mutable<QName, D, E> stmt) {
-        stmt.coerceParentContext().addToNs(SchemaTreeNamespace.class, stmt.getArgument(), stmt);
+        stmt.coerceParentContext().addToNs(SchemaTreeNamespace.instance(), stmt.getArgument(), stmt);
     }
 
     // Non-final because {@code input} and {@code output} are doing their own thing.
index b65895154cd4d03802dd33b899a34ad36e5ca5f1..a793f01da407c3f82ba1b861b60d37035f097793 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * An {@link NamespaceBehaviour} which derives keys from a different namespace.
@@ -24,14 +25,14 @@ import java.util.Map;
 public abstract class DerivedNamespaceBehaviour<K, V, L, N extends ParserNamespace<K, V>,
        O extends ParserNamespace<L, ?>> extends NamespaceBehaviour<K, V, N> {
 
-    private final Class<O> derivedFrom;
+    private final @NonNull O derivedFrom;
 
-    protected DerivedNamespaceBehaviour(final Class<N> identifier, final Class<O> derivedFrom) {
+    protected DerivedNamespaceBehaviour(final N identifier, final O derivedFrom) {
         super(identifier);
         this.derivedFrom = requireNonNull(derivedFrom);
     }
 
-    public Class<O> getDerivedFrom() {
+    public final @NonNull O getDerivedFrom() {
         return derivedFrom;
     }
 
@@ -52,6 +53,6 @@ public abstract class DerivedNamespaceBehaviour<K, V, L, N extends ParserNamespa
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
-        return helper.add("derivedFrom", derivedFrom.getName());
+        return helper.add("derivedFrom", derivedFrom);
     }
 }
index 0c51ce934c9d81b81a1fe18720d4aa34daf53767..d6af8b8755c3883ee8674f3fa09539094b242597 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
+import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Special namespace which allows import of namespaces from other sources.
  *
@@ -20,6 +23,11 @@ package org.opendaylight.yangtools.yang.parser.spi.meta;
  *
  * @param <K> Imported context identifier
  */
-public abstract class ImportedNamespaceContext<K> extends ParserNamespace<K, StmtContext<?, ?, ?>> {
+public final class ImportedNamespaceContext<K> extends ParserNamespace<K, StmtContext<?, ?, ?>> {
+    @Serial
+    private static final long serialVersionUID = 1L;
 
+    public ImportedNamespaceContext(final @NonNull String name) {
+        super(name);
+    }
 }
index b73d1eaa4a1807fd5896667b8ace2f70149efa94..206f5e018ca99c865198bcc4e3812bfda455f2eb 100644 (file)
@@ -156,7 +156,7 @@ public interface ModelActionBuilder {
      */
     @Deprecated
     <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
-        @NonNull Prerequisite<D> requiresDeclared(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
+        @NonNull Prerequisite<D> requiresDeclared(StmtContext<?, ?, ?> context, N namespace, K key);
 
     /**
      * Action requires that the specified context completes specified phase before {@link #apply(InferenceAction)}
@@ -170,14 +170,14 @@ public interface ModelActionBuilder {
         requiresCtx(StmtContext<A, D, E> context, ModelProcessingPhase phase);
 
     <K, N extends StatementNamespace<K, ?, ?>> @NonNull Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
-        StmtContext<?, ?, ?> context, Class<@NonNull N> namespace, K key, ModelProcessingPhase phase);
+        StmtContext<?, ?, ?> context, @NonNull N namespace, K key, ModelProcessingPhase phase);
 
     <K, N extends StatementNamespace<K, ?, ?>> @NonNull Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
-            StmtContext<?, ?, ?> context, Class<@NonNull N> namespace, NamespaceKeyCriterion<K> criterion,
+            StmtContext<?, ?, ?> context, @NonNull N namespace, NamespaceKeyCriterion<K> criterion,
             ModelProcessingPhase phase);
 
     <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
-        @NonNull Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(StmtContext<?, ?, ?> context, Class<N> namespace,
+        @NonNull Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(StmtContext<?, ?, ?> context, N namespace,
             Iterable<K> keys, ModelProcessingPhase phase);
 
     /**
@@ -192,12 +192,11 @@ public interface ModelActionBuilder {
     }
 
     <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
-        @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, Class<N> namespace,
-                K key);
+        @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, N namespace, K key);
 
     <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
         @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtxPath(StmtContext<?, ?, ?> context,
-                Class<N> namespace, Iterable<K> keys);
+                N namespace, Iterable<K> keys);
 
     /**
      * Action mutates the specified statement in the specified phase. Target statement cannot complete specified
@@ -227,7 +226,7 @@ public interface ModelActionBuilder {
     @Deprecated
     <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
         @NonNull Prerequisite<StmtContext<?, D, ?>> requiresDeclaredCtx(StmtContext<?, ?, ?> context,
-                Class<N> namespace, K key);
+                N namespace, K key);
 
     /**
      * Create a requirement on specified statement to become effective.
@@ -245,7 +244,7 @@ public interface ModelActionBuilder {
      */
     @Deprecated
     <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
-        @NonNull Prerequisite<E> requiresEffective(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
+        @NonNull Prerequisite<E> requiresEffective(StmtContext<?, ?, ?> context, N namespace, K key);
 
     /**
      * Create a requirement on specified statement context to become effective.
@@ -254,8 +253,8 @@ public interface ModelActionBuilder {
      */
     @Deprecated
     <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
-        @NonNull Prerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(StmtContext<?, ?, ?> context,
-                Class<N> namespace, K key);
+        @NonNull Prerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(StmtContext<?, ?, ?> context, N namespace,
+            K key);
 
     /**
      * Mark the fact that this action is mutating a namespace.
@@ -263,6 +262,5 @@ public interface ModelActionBuilder {
      * @deprecated Undocumented method. Use at your own risk.
      */
     @Deprecated
-    <N extends ParserNamespace<?, ?>> @NonNull Prerequisite<Mutable<?,?,?>> mutatesNs(Mutable<?,?, ?> ctx,
-            Class<N> namespace);
+    <N extends ParserNamespace<?, ?>> @NonNull Prerequisite<Mutable<?,?,?>> mutatesNs(Mutable<?,?, ?> ctx, N namespace);
 }
index 7a9a2ed034ca2a4fd95c65fd5c6819d836f0a9a5..aef36d9250fe9eb2f1742d1ef74e406ec3042a49 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespaceBehaviour;
 
 /**
  * Definition / implementation of specific Identifier Namespace behaviour. A namespace behaviour is built on top
@@ -30,15 +30,15 @@ import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
  * n {@link StorageNodeType}.
  *
  * <p>
- * For common behaviour models please use static factories {@link #global(Class)}, {@link #sourceLocal(Class)} and
- * {@link #treeScoped(Class)}.
+ * For common behaviour models please use static factories {@link #global(ParserNamespace)},
+ * {@link #sourceLocal(ParserNamespace)} and {@link #treeScoped(ParserNamespace)}.
  *
  * @param <K> Key type
  * @param <V> Value type
  * @param <N> Namespace Type
  */
-public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
-        extends AbstractSimpleIdentifiable<Class<N>> {
+// FIXME: remove the 'N' parameter?
+public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>> extends AbstractSimpleIdentifiable<N> {
 
     public enum StorageNodeType {
         /**
@@ -71,7 +71,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
          * @return Namespace behaviour
          * @throws NamespaceNotAvailableException when the namespace is not available
          */
-        <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
+        <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(N type);
     }
 
     public interface NamespaceStorageNode {
@@ -84,9 +84,9 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
 
         @Nullable NamespaceStorageNode getParentNamespaceStorage();
 
-        <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(Class<N> type, K key);
+        <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(N type, K key);
 
-        <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(Class<N> type);
+        <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(N type);
 
         /**
          * Populate specified namespace with a key/value pair, overwriting previous contents. Similar to
@@ -97,7 +97,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
          * @param value Value
          * @return Previously-stored value, or null if the key was not present
          */
-        <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorage(Class<N> type, K key, V value);
+        <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorage(N type, K key, V value);
 
         /**
          * Populate specified namespace with a key/value pair unless the key is already associated with a value. Similar
@@ -108,7 +108,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
          * @param value Value
          * @return Preexisting value or null if there was no previous mapping
          */
-        <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(Class<N> type, K key, V value);
+        <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(N type, K key, V value);
     }
 
     /**
@@ -122,7 +122,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
          * Request that a new member of this node's schema tree statement be added. Implementations are required to
          * perform lookup in their internal structure and create a child if tractable. Resulting node is expected to
          * have been registered with local storage, so that it is accessible through
-         * {@link #getFromLocalStorage(Class, Object)}.
+         * {@link #getFromLocalStorage(ParserNamespace, Object)}.
          *
          * <p>
          * This method must not change its mind about a child's presence -- once it returns non-present, it has to be
@@ -131,7 +131,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
          * <p>
          * The results produced by this method are expected to be consistent with
          * {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)} and
-         * {@link SchemaTreeNamespace.Behaviour#getFrom(NamespaceStorageNode, QName)}.
+         * {@link SchemaTreeNamespaceBehaviour#getFrom(NamespaceStorageNode, QName)}.
          *
          * @param qname node identifier of the child being requested
          * @return Requested child, if it is present.
@@ -141,7 +141,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
             @Nullable StmtContext<QName, D, E> requestSchemaTreeChild(QName qname);
     }
 
-    protected NamespaceBehaviour(final Class<N> identifier) {
+    protected NamespaceBehaviour(final N identifier) {
         super(identifier);
     }
 
@@ -156,7 +156,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
      * @return global namespace behaviour for supplied namespace type.
      */
     public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> global(
-            final Class<N> identifier) {
+            final N identifier) {
         return new StorageSpecific<>(identifier, StorageNodeType.GLOBAL);
     }
 
@@ -172,12 +172,12 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
      * @return source-local namespace behaviour for supplied namespace type.
      */
     public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> sourceLocal(
-            final Class<N> identifier) {
+            final N identifier) {
         return new StorageSpecific<>(identifier, StorageNodeType.SOURCE_LOCAL_SPECIAL);
     }
 
     public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> statementLocal(
-           final Class<N> identifier) {
+           final N identifier) {
         return new StatementLocal<>(identifier);
     }
 
@@ -193,7 +193,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
      * @return root-statement-local namespace behaviour for supplied namespace type.
      */
     public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> rootStatementLocal(
-            final Class<N> identifier) {
+            final N identifier) {
         return new StorageSpecific<>(identifier, StorageNodeType.ROOT_STATEMENT_LOCAL);
     }
 
@@ -209,7 +209,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
      * @return tree-scoped namespace behaviour for supplied namespace type.
      */
     public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> treeScoped(
-            final Class<N> identifier) {
+            final N identifier) {
         return new TreeScoped<>(identifier);
     }
 
@@ -286,9 +286,8 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
         storage.putToLocalStorage(getIdentifier(), key, value);
     }
 
-    abstract static class AbstractSpecific<K, V, N extends ParserNamespace<K, V>>
-            extends NamespaceBehaviour<K, V, N> {
-        AbstractSpecific(final Class<N> identifier) {
+    abstract static class AbstractSpecific<K, V, N extends ParserNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
+        AbstractSpecific(final N identifier) {
             super(identifier);
         }
 
@@ -311,7 +310,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
     }
 
     static final class StatementLocal<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
-        StatementLocal(final Class<N> identifier) {
+        StatementLocal(final N identifier) {
             super(identifier);
         }
 
@@ -324,7 +323,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
     static final class StorageSpecific<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
         private final StorageNodeType storageType;
 
-        StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+        StorageSpecific(final N identifier, final StorageNodeType type) {
             super(identifier);
             storageType = requireNonNull(type);
         }
@@ -341,7 +340,7 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
     }
 
     static final class TreeScoped<K, V, N extends ParserNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
-        TreeScoped(final Class<N> identifier) {
+        TreeScoped(final N identifier) {
             super(identifier);
         }
 
@@ -389,6 +388,6 @@ public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
-        return helper.add("identifier", getIdentifier().getName());
+        return helper.add("identifier", getIdentifier());
     }
 }
index 95fa54cec56feeb20e68af94bf1659184acde821..ac0806e0a0f58a8c7653fa2bebde2769e6de44b3 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.jdt.annotation.Nullable;
 /**
  * Support work with namespace content.
  */
+// FIXME: ditch <N> parameters
 @Beta
 public interface NamespaceStmtCtx extends CommonStmtCtx {
     /**
@@ -26,7 +27,7 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      * @param nsType namespace type class
      * @return Namespace contents, if available
      */
-    <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> namespace(Class<@NonNull N> nsType);
+    <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> namespace(@NonNull N nsType);
 
     /**
      * Return a value associated with specified key within a namespace.
@@ -40,11 +41,11 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      * @return Value, or null if there is no element
      * @throws NamespaceNotAvailableException when the namespace is not available.
      */
-    <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V namespaceItem(Class<@NonNull N> nsType, T key);
+    <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V namespaceItem(@NonNull N nsType, T key);
 
     /**
      * Return the portion of specified namespace stored in this node. Depending on namespace behaviour this may or may
-     * not represent the complete contents of the namespace as available via {@link #namespace(Class)}.
+     * not represent the complete contents of the namespace as available via {@link #namespace(ParserNamespace)}.
      *
      * <p>
      * This partial view is useful when the need is not to perform a proper namespace lookup, but rather act on current
@@ -56,7 +57,7 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      * @param nsType namespace type class
      * @return Namespace portion stored in this node, if available
      */
-    <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(Class<@NonNull N> nsType);
+    <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(@NonNull N nsType);
 
     /**
      * Return the selected namespace.
@@ -68,7 +69,7 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      * @return Namespace contents, if available
      */
     // TODO: migrate users away
-    default <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> nsType) {
+    default <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromNamespace(final @NonNull N nsType) {
         return namespace(nsType);
     }
 
@@ -85,8 +86,8 @@ public interface NamespaceStmtCtx extends CommonStmtCtx {
      * @throws NamespaceNotAvailableException when the namespace is not available.
      */
     // TODO: migrate users away
-    default <K, V, T extends K, N extends ParserNamespace<K, V>>
-            @Nullable V getFromNamespace(final Class<@NonNull N> type, final T key) {
+    default <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V getFromNamespace(
+            final @NonNull N type, final T key) {
         return namespaceItem(type, key);
     }
 }
index ed4089c73ae7149517d37d740b75ff0c2b599b79..c6c07c917f40422aae82b638a78520999b72290d 100644 (file)
@@ -7,21 +7,35 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects;
+import java.io.Serial;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.Identifier;
 
 /**
  * {@link ParserNamespace} serves as common superclass for namespaces used during parser operation. Each such namespace,
  * is a type-captured subclass. This type capture of namespace allows for handy type-safe reading methods such as
- * {@link NamespaceStmtCtx#getFromNamespace(Class, Object)} and still allows introduction of new namespaces without need
- * to change APIs.
+ * {@link NamespaceStmtCtx#getFromNamespace(ParserNamespace, Object)} and still allows introduction of new namespaces
+ * without need to change APIs.
  *
  * @param <K> Identifier type
  * @param <V> Value type
  */
 @NonNullByDefault
-public abstract class ParserNamespace<K, V> {
+public class ParserNamespace<K, V> implements Identifier {
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    private final String name;
+
+    // FIXME: hide this constructor once we collapse the type hierarchy
+    public ParserNamespace(final String name) {
+        this.name = requireNonNull(name);
+    }
+
     @Override
     public final int hashCode() {
         return super.hashCode();
@@ -34,6 +48,6 @@ public abstract class ParserNamespace<K, V> {
 
     @Override
     public final String toString() {
-        return MoreObjects.toStringHelper(this).toString();
+        return MoreObjects.toStringHelper(this).add("name", name).toString();
     }
 }
@@ -34,11 +34,14 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 // At the end of the day this feels like an under-utilized namespace: provided the contents of ExtensionNamespace and
 // StatementSupportBundles, SourceSpecificSpecificContext should be able to work its magic even without this namespace.
 @Beta
-public final class StatementDefinitionNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(StatementDefinitionNamespace.class);
+public final class StatementDefinitions {
 
-    private StatementDefinitionNamespace() {
+    public static final @NonNull ParserNamespace<QName, StatementSupport<?, ?, ?>> NAMESPACE =
+        new ParserNamespace<>("statementDefinitions");
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(NAMESPACE);
+
+    private StatementDefinitions() {
         // Hidden on purpose
     }
 }
index 28b4fa51ec7e8cd4dbb0fcaaa74614d86cb2fbf8..ed9fb9f9e0426a7b40e0136346aa92fe5e827c62 100644 (file)
@@ -7,13 +7,29 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
+import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
-public abstract class StatementNamespace<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
+// FIXME: is this subclass useful at all?
+public class StatementNamespace<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
         extends ParserNamespace<K, StmtContext<?, D, E>> {
-    public abstract static class TreeScoped<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    public StatementNamespace(final @NonNull String name) {
+        super(name);
+    }
+
+    // FIXME: is this subclass useful at all?
+    public static class TreeScoped<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
             extends StatementNamespace<K, D, E> {
+        @Serial
+        private static final long serialVersionUID = 1L;
 
+        public TreeScoped(final @NonNull String name) {
+            super(name);
+        }
     }
 }
index 0cef4bc7b1dfa763c37d45cad948eeae4e74992e..dc735bd0cb9c5594faace265835d8ad92f327fbc 100644 (file)
@@ -195,6 +195,17 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
             @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
     }
 
+    /**
+     * Projection of {@link StatementSupport}s available within a particular source. This namespace is purely virtual
+     * and its behaviour corresponds to {@link NamespaceBehaviour#rootStatementLocal(ParserNamespace)} and is always
+     * available.
+     * Its contents are derived from {@link StatementSupportBundle}s active in the current {@link ModelProcessingPhase}
+     * as well as {@link StatementDefinitions} and {@link StmtContext#yangVersion()} of the source root statement.
+     */
+    @Beta
+    public static final @NonNull ParserNamespace<QName, StatementSupport<?, ?, ?>> NAMESPACE =
+        new ParserNamespace<>("statementSupports");
+
     private final @NonNull StatementPolicy<A, D> policy;
     private final @NonNull StatementDefinition publicDefinition;
     private final @NonNull CopyPolicy copyPolicy;
index 246447fa4ed1f0b0a20b29b486d5f66e4002a054..5c340842e80f0fe5352f47ff1fc3523d105f1765 100644 (file)
@@ -35,13 +35,13 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
     private final StatementSupportBundle parent;
     private final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonDefinitions;
     private final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificDefinitions;
-    private final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
+    private final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
     private final ImmutableSet<YangVersion> supportedVersions;
 
     private StatementSupportBundle(final StatementSupportBundle parent,
             final ImmutableSet<YangVersion> supportedVersions,
             final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonStatements,
-            final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces,
+            final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaces,
             final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements) {
         this.parent = parent;
         this.supportedVersions = supportedVersions;
@@ -83,7 +83,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
         return versionSpecificDefinitions;
     }
 
-    public ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> getNamespaceDefinitions() {
+    public ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> getNamespaceDefinitions() {
         return namespaceDefinitions;
     }
 
@@ -102,7 +102,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
     @Override
     @SuppressWarnings("unchecked")
     public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
-            final Class<N> namespace) {
+            final N namespace) {
         final NamespaceBehaviour<?, ?, ?> potential = namespaceDefinitions.get(namespace);
         if (potential != null) {
             checkState(namespace.equals(potential.getIdentifier()));
@@ -116,7 +116,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
         return null;
     }
 
-    public boolean hasNamespaceBehaviour(final Class<? extends ParserNamespace<?, ?>> namespace) {
+    public boolean hasNamespaceBehaviour(final ParserNamespace<?, ?> namespace) {
         if (namespaceDefinitions.containsKey(namespace)) {
             return true;
         }
@@ -165,7 +165,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
         private final Map<QName, StatementSupport<?, ?, ?>> commonStatements = new HashMap<>();
         private final Table<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements =
             HashBasedTable.create();
-        private final Map<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces = new HashMap<>();
+        private final Map<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaces = new HashMap<>();
 
         private final ImmutableSet<YangVersion> supportedVersions;
         private StatementSupportBundle parent;
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportNamespace.java
deleted file mode 100644 (file)
index 685c9a6..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2021 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 org.opendaylight.yangtools.yang.common.QName;
-
-/**
- * Projection of {@link StatementSupport}s available within a particular source. This namespace is purely virtual and
- * its behaviour corresponds to {@link NamespaceBehaviour#rootStatementLocal(Class)} and is always available. Its
- * contents are derived from {@link StatementSupportBundle}s active in the current {@link ModelProcessingPhase} as well
- * as {@link StatementDefinitionNamespace} and {@link StmtContext#yangVersion()} of the source root statement.
- */
-@Beta
-public final class StatementSupportNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
-    StatementSupportNamespace() {
-        // FIXME: is this really used?!
-    }
-}
index d940675907e05ad0d2076eaa008929102d3106d3..803e982c83230d51c3c4ee1a273e8d256e09dbe0 100644 (file)
@@ -194,8 +194,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          * @param <U> value type
          * @throws NamespaceNotAvailableException when the namespace is not available.
          */
-        <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(Class<@NonNull N> type,
-                T key, U value);
+        <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(@NonNull N type, T key, U value);
 
         @Override
         RootStmtContext.Mutable<?, ?, ?> getRoot();
@@ -266,7 +265,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          * @param stmt
          *            to be added to namespace map
          */
-        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<@NonNull N> namespace, KT key,
+        <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(@NonNull N namespace, KT key,
                 StmtContext<?, ?, ?> stmt);
 
         /**
index 714e1ab49a3a4475b7f063078875771ea8ad9331..e8024bc47b72588c9eb92c32223fd004111bc154 100644 (file)
@@ -40,12 +40,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Infere
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 public final class StmtContextUtils {
     private StmtContextUtils() {
@@ -553,7 +549,7 @@ public final class StmtContextUtils {
         if (ctx.producesDeclared(ModuleStatement.class)) {
             return lookupModuleQName(ctx, ctx);
         } else if (ctx.producesDeclared(SubmoduleStatement.class)) {
-            final var belongsTo = ctx.getAllFromNamespace(BelongsToPrefixToModuleCtx.class);
+            final var belongsTo = ctx.getAllFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
             if (belongsTo == null || belongsTo.isEmpty()) {
                 throw new IllegalArgumentException(ctx + " does not have belongs-to linkage resolved");
             }
@@ -565,7 +561,7 @@ public final class StmtContextUtils {
 
     private static @NonNull QNameModule lookupModuleQName(final NamespaceStmtCtx storage,
             final StmtContext<?, ?, ?> module) {
-        final var ret = storage.getFromNamespace(ModuleCtxToModuleQName.class, module);
+        final var ret = storage.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, module);
         if (ret == null) {
             throw new IllegalArgumentException("Failed to look up QNameModule for " + module + " in " + storage);
         }
@@ -574,15 +570,16 @@ public final class StmtContextUtils {
 
     public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) {
         final StmtContext<?, ?, ?> root = ctx.getRoot();
-        final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(ImportPrefixToModuleCtx.class, prefix);
-        final QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, importedModule);
+        final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(
+            SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, prefix);
+        final QNameModule qnameModule = ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, importedModule);
         if (qnameModule != null) {
             return qnameModule;
         }
 
         if (root.producesDeclared(SubmoduleStatement.class)) {
-            final var moduleName = root.getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
-            return ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+            return ctx.getFromNamespace(SourceParserNamespaces.MODULE_NAME_TO_QNAME,
+                root.getFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME, prefix));
         }
 
         return null;
index 8992f5f0b2ab89510bf745e6282116cb98e8a95f..975a3ca79330cfb983453729b57337b773fdff4a 100644 (file)
@@ -15,8 +15,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
 
 public final class SubstatementValidator {
     private final ImmutableMap<StatementDefinition, Cardinality> cardinalityMap;
@@ -24,9 +24,9 @@ public final class SubstatementValidator {
     private final StatementDefinition currentStatement;
 
     private SubstatementValidator(final Builder builder) {
-        this.cardinalityMap = builder.cardinalityMap.build();
-        this.currentStatement = builder.currentStatement;
-        this.mandatoryStatements = ImmutableMap.copyOf(Maps.filterValues(cardinalityMap, c -> c.getMin() > 0));
+        cardinalityMap = builder.cardinalityMap.build();
+        currentStatement = builder.currentStatement;
+        mandatoryStatements = ImmutableMap.copyOf(Maps.filterValues(cardinalityMap, c -> c.getMin() > 0));
     }
 
     public static Builder builder(final StatementDefinition currentStatement) {
@@ -129,10 +129,11 @@ public final class SubstatementValidator {
             final int value = entry.getValue().getValue();
 
             if (cardinality == null) {
-                if (ctx.getFromNamespace(ExtensionNamespace.class, key.getStatementName()) == null) {
+                if (ctx.getFromNamespace(ParserNamespaces.EXTENSION, key.getStatementName()) == null) {
                     final StmtContext<?, ?, ?> root = ctx.getRoot();
                     throw new InvalidSubstatementException(ctx, "%s is not valid for %s. Error in module %s (%s)", key,
-                        currentStatement, root.rawArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+                        currentStatement, root.rawArgument(),
+                        ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
                 }
 
                 continue;
@@ -144,7 +145,7 @@ public final class SubstatementValidator {
                     throw new InvalidSubstatementException(ctx,
                         "Minimal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
                         cardinality.getMin(), value, root.rawArgument(),
-                        ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+                        ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
                 }
 
                 // Encountered a mandatory statement, hence we are not missing it
@@ -155,7 +156,7 @@ public final class SubstatementValidator {
                 throw new InvalidSubstatementException(ctx,
                     "Maximal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
                     cardinality.getMax(), value, root.rawArgument(),
-                    ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+                    ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
             }
         }
 
@@ -166,7 +167,8 @@ public final class SubstatementValidator {
 
             throw new MissingSubstatementException(ctx,
                 "%s is missing %s. Minimal count is %s. Error in module %s (%s)", currentStatement, e.getKey(),
-                e.getValue().getMin(), root.rawArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+                e.getValue().getMin(), root.rawArgument(),
+                ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
         }
     }
 
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleCtx.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleCtx.java
deleted file mode 100644 (file)
index 5e7a169..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-/**
- * Source-specific mapping of belongsTo prefixes to module identifiers. This mapping allows source-specific context
- * to correctly populate prefixes map for actual parsing phase and eventually, resolve QName for any valid declared
- * statement.
- */
-public final class BelongsToPrefixToModuleCtx extends ImportedNamespaceContext<String> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(BelongsToPrefixToModuleCtx.class);
-
-    private BelongsToPrefixToModuleCtx() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleName.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/BelongsToPrefixToModuleName.java
deleted file mode 100644 (file)
index c576f3d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class BelongsToPrefixToModuleName extends ParserNamespace<String, Unqualified> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(BelongsToPrefixToModuleName.class);
-
-    private BelongsToPrefixToModuleName() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToNamespace.java
deleted file mode 100644 (file)
index 6d506a7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Pre-linkage source-specific mapping of prefixes to module namespaces.
- */
-public final class ImpPrefixToNamespace extends ParserNamespace<String, XMLNamespace> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.rootStatementLocal(ImpPrefixToNamespace.class);
-
-    private ImpPrefixToNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportPrefixToModuleCtx.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportPrefixToModuleCtx.java
deleted file mode 100644 (file)
index 68d9d19..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Source-specific mapping of prefix strings to module context.
- */
-public final class ImportPrefixToModuleCtx extends ParserNamespace<String, StmtContext<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.rootStatementLocal(ImportPrefixToModuleCtx.class);
-
-    private ImportPrefixToModuleCtx() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportedModuleContext.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImportedModuleContext.java
deleted file mode 100644 (file)
index 42add72..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-public final class ImportedModuleContext extends ImportedNamespaceContext<SourceIdentifier> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(ImportedModuleContext.class);
-
-    private ImportedModuleContext() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedModuleContext.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedModuleContext.java
deleted file mode 100644 (file)
index b3986af..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-public final class IncludedModuleContext extends ImportedNamespaceContext<SourceIdentifier> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(IncludedModuleContext.class);
-
-    private IncludedModuleContext() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedSubmoduleNameToModuleCtx.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedSubmoduleNameToModuleCtx.java
deleted file mode 100644 (file)
index 621d995..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class IncludedSubmoduleNameToModuleCtx extends ParserNamespace<Unqualified, StmtContext<?, ?, ?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(IncludedSubmoduleNameToModuleCtx.class);
-
-    private IncludedSubmoduleNameToModuleCtx() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java
deleted file mode 100644 (file)
index c6404ac..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Global mapping of modules to QNameModules.
- */
-public final class ModuleCtxToModuleQName extends ParserNamespace<StmtContext<?,?,?>, QNameModule> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleCtxToModuleQName.class);
-
-    private ModuleCtxToModuleQName() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToSourceIdentifier.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToSourceIdentifier.java
deleted file mode 100644 (file)
index 52cf3bf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Global mapping of modules to source identifier.
- */
-public final class ModuleCtxToSourceIdentifier extends ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleCtxToSourceIdentifier.class);
-
-    private ModuleCtxToSourceIdentifier() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToModuleQName.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToModuleQName.java
deleted file mode 100644 (file)
index d66d513..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class ModuleNameToModuleQName extends ParserNamespace<Unqualified, QNameModule> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.sourceLocal(ModuleNameToModuleQName.class);
-
-    private ModuleNameToModuleQName() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNameToNamespace.java
deleted file mode 100644 (file)
index 1347b91..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Pre-linkage global mapping of module names to namespaces.
- */
-public final class ModuleNameToNamespace extends ParserNamespace<Unqualified, XMLNamespace> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleNameToNamespace.class);
-
-    private ModuleNameToNamespace() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNamespaceForBelongsTo.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleNamespaceForBelongsTo.java
deleted file mode 100644 (file)
index 78a8223..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Namespace class similar to {@link org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace} for storing modules
- * into Yang model storage but keyed by plain name.
- */
-public final class ModuleNamespaceForBelongsTo
-        extends StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleNamespaceForBelongsTo.class);
-
-    private ModuleNamespaceForBelongsTo() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleQNameToModuleName.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleQNameToModuleName.java
deleted file mode 100644 (file)
index 5abe546..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class ModuleQNameToModuleName extends ParserNamespace<QNameModule, Unqualified> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModuleQNameToModuleName.class);
-
-    private ModuleQNameToModuleName() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModulesDeviatedByModules.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModulesDeviatedByModules.java
deleted file mode 100644 (file)
index cb11446..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2017 Pantheon Technologies 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.source;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.SetMultimap;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Namespace used for storing information about modules that support deviation resolution.
- * Map key (QNameModule) denotes a module which can be deviated by the modules specified in the Map value.
- */
-@Beta
-public final class ModulesDeviatedByModules extends ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ModulesDeviatedByModules.class);
-
-    private ModulesDeviatedByModules() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModule.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/PrefixToModule.java
deleted file mode 100644 (file)
index ba97db2..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces. This namespace is populated by all statements which have impact
- * on the XML namespace, for example {@code import}, {@code belongs-to} and really anywhere a {@code prefix} statement
- * is present.
- *
- * @see PrefixResolver
- */
-public final class PrefixToModule extends ParserNamespace<String, QNameModule> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(PrefixToModule.class);
-
-    private PrefixToModule() {
-        // Hidden on purpose
-    }
-}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceNamespaceBehaviours.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceNamespaceBehaviours.java
new file mode 100644 (file)
index 0000000..aaa5ab1
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2022 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.source;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+/**
+ * {@link NamespaceBehaviour}s corresponding to {@link SourceParserNamespaces}.
+ */
+public final class SourceNamespaceBehaviours {
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BELONGSTO_PREFIX_TO_MODULECTX =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BELONGSTO_PREFIX_TO_MODULE_NAME =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAME_TO_QNAME =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.MODULE_NAME_TO_QNAME);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> IMPORTED_MODULE =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.IMPORTED_MODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> INCLUDED_MODULE =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.INCLUDED_MODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULECTX_TO_QNAME =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULECTX_TO_QNAME);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> INCLUDED_SUBMODULE_NAME_TO_MODULECTX =
+        NamespaceBehaviour.sourceLocal(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> IMP_PREFIX_TO_NAMESPACE =
+        NamespaceBehaviour.rootStatementLocal(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> IMPORT_PREFIX_TO_MODULECTX =
+        NamespaceBehaviour.rootStatementLocal(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_FOR_BELONGSTO =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULE_FOR_BELONGSTO);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> SUPPORTED_FEATURES =
+        NamespaceBehaviour.global(SourceParserNamespaces.SUPPORTED_FEATURES);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> PREFIX_TO_MODULE =
+        NamespaceBehaviour.global(SourceParserNamespaces.PREFIX_TO_MODULE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULES_DEVIATED_BY =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULES_DEVIATED_BY);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAMESPACE_TO_NAME =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULE_NAMESPACE_TO_NAME);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAME_TO_NAMESPACE =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE);
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULECTX_TO_SOURCE =
+        NamespaceBehaviour.global(SourceParserNamespaces.MODULECTX_TO_SOURCE);
+
+    private SourceNamespaceBehaviours() {
+        // Hidden on purpose
+    }
+}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceParserNamespaces.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SourceParserNamespaces.java
new file mode 100644 (file)
index 0000000..e0e3919
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2022 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.source;
+
+import com.google.common.collect.SetMultimap;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+/**
+ * Namespaces related to YANG/YIN source processing.
+ */
+public final class SourceParserNamespaces {
+    /**
+     * Source-specific mapping of belongsTo prefixes to module identifiers. This mapping allows source-specific context
+     * to correctly populate prefixes map for actual parsing phase and eventually, resolve QName for any valid declared
+     * statement.
+     */
+    public static final @NonNull ImportedNamespaceContext<String> BELONGSTO_PREFIX_TO_MODULECTX =
+        new ImportedNamespaceContext<>("belongsto-prefix-to-module");
+
+    /**
+     * Source-specific mapping of prefixes to namespaces.
+     */
+    // FIXME: bad javadoc
+    public static final @NonNull ParserNamespace<String, Unqualified> BELONGSTO_PREFIX_TO_MODULE_NAME =
+        new ParserNamespace<>("belongsto-prefix-to-name");
+
+    /**
+     * Namespace similar to {@link ParserNamespaces#MODULE} for storing modules into Yang model storage but keyed by
+     * plain name.
+     */
+    // FIXME: Better name?
+    public static final @NonNull StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement>
+        MODULE_FOR_BELONGSTO = new StatementNamespace<>("module-belongsto");
+
+    /**
+     * Pre-linkage source-specific mapping of prefixes to module namespaces.
+     */
+    // FIXME: a better name?
+    public static final @NonNull ParserNamespace<String, XMLNamespace> IMP_PREFIX_TO_NAMESPACE =
+        new ParserNamespace<>("prefix-to-xmlnamespace");
+
+    /**
+     * Source-specific mapping of prefix strings to module context.
+     */
+    public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> IMPORT_PREFIX_TO_MODULECTX =
+        new ParserNamespace<>("import-prefix-to-modulectx");
+
+    // FIXME: document this
+    public static final @NonNull ImportedNamespaceContext<SourceIdentifier> IMPORTED_MODULE =
+        new ImportedNamespaceContext<>("imported-module");
+
+    // FIXME: document this
+    // FIXME: is this 'included submodule' instead?
+    public static final @NonNull ImportedNamespaceContext<SourceIdentifier> INCLUDED_MODULE =
+        new ImportedNamespaceContext<>("included-module");
+
+    /**
+     * Source-specific mapping of prefixes to namespaces.
+     */
+    // FIXME: bad javadoc
+    public static final @NonNull ParserNamespace<Unqualified, StmtContext<?, ?, ?>> INCLUDED_SUBMODULE_NAME_TO_MODULECTX
+        = new ParserNamespace<>("included-submodule-to-modulectx");
+
+    /**
+     * Source-specific mapping of prefixes to namespaces.
+     */
+    // FIXME: bad javadoc
+    public static final @NonNull ParserNamespace<Unqualified, QNameModule> MODULE_NAME_TO_QNAME =
+        new ParserNamespace<>("module-name-to-qnamemodule");
+
+    /**
+     * Global mapping of modules to QNameModules.
+     */
+    public static final @NonNull ParserNamespace<StmtContext<?,?,?>, QNameModule> MODULECTX_TO_QNAME =
+        new ParserNamespace<>("modulectx-to-qnamemodule");
+
+    public static final @NonNull ParserNamespace<Empty, Set<QName>> SUPPORTED_FEATURES =
+        new ParserNamespace<>("supportedFeatures");
+
+    /**
+     * Source-specific mapping of prefixes to namespaces. This namespace is populated by all statements which have
+     * impact on the XML namespace, for example {@code import}, {@code belongs-to} and really anywhere a {@code prefix}
+     * statement is present.
+     *
+     * @see PrefixResolver
+     */
+    public static final @NonNull ParserNamespace<String, QNameModule> PREFIX_TO_MODULE =
+        new ParserNamespace<>("prefix-to-qnamemodule");
+
+    /**
+     * Namespace used for storing information about modules that support deviation resolution.
+     * Map key (QNameModule) denotes a module which can be deviated by the modules specified in the Map value.
+     */
+    public static final @NonNull ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> MODULES_DEVIATED_BY =
+        new ParserNamespace<>("moduleDeviations");
+
+    /**
+     * Source-specific mapping of prefixes to namespaces.
+     */
+    // FIXME: bad javadoc
+    public static final @NonNull ParserNamespace<QNameModule, Unqualified> MODULE_NAMESPACE_TO_NAME =
+        new ParserNamespace<>("qnamemodule-to-name");
+
+    /**
+     * Pre-linkage global mapping of module names to namespaces.
+     */
+    public static final @NonNull ParserNamespace<Unqualified, XMLNamespace> MODULE_NAME_TO_NAMESPACE =
+        new ParserNamespace<>("module-name-to-xmlnamespace");
+
+    /**
+     * Global mapping of modules to source identifier.
+     */
+    public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> MODULECTX_TO_SOURCE =
+        new ParserNamespace<>("modulectx-to-source");
+
+    private SourceParserNamespaces() {
+        // Hidden on purpose
+    }
+}
diff --git a/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java b/parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java
deleted file mode 100644 (file)
index 6b7c87f..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import java.util.Set;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-public final class SupportedFeaturesNamespace extends ParserNamespace<Empty, Set<QName>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(SupportedFeaturesNamespace.class);
-
-    private SupportedFeaturesNamespace() {
-        // Hidden on purpose
-    }
-}
@@ -17,15 +17,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
  * Namespace used for validating whether a node is of some type, e.g. usable target for some operation or has other
  * significant properties.
  */
-public final class ValidationBundlesNamespace
-        extends ParserNamespace<ValidationBundlesNamespace.ValidationBundleType, Collection<?>> {
-    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
-        NamespaceBehaviour.global(ValidationBundlesNamespace.class);
-
-    private ValidationBundlesNamespace() {
-        // Hidden on purpose
-    }
-
+public final class ValidationBundles {
     public enum ValidationBundleType {
         /**
          * Whether a node is suitable refine substatement.
@@ -54,4 +46,13 @@ public final class ValidationBundlesNamespace
          */
         SUPPORTED_DATA_NODES
     }
+
+    public static final @NonNull ParserNamespace<ValidationBundleType, Collection<?>> NAMESPACE =
+        new ParserNamespace<>("validationBundles");
+
+    public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(NAMESPACE);
+
+    private ValidationBundles() {
+        // Hidden on purpose
+    }
 }
index 1d13f8f85c8ffa9ba0ffe78d153ac4f01a0a2bd6..e73c67e8ad052d1e603ed5c6d8cbcdfa814f73c3 100644 (file)
@@ -11,7 +11,7 @@
  * Currently, this package contains an interface which represents a namespace used
  * by the validation process. This namespace contains different types of validation
  * bundles or collections. Allowed types of validation bundles are defined by the
- * enumeration {@link ValidationBundlesNamespace.ValidationBundleType} which is
+ * enumeration {@link ValidationBundles.ValidationBundleType} which is
  * provided by this package.
  */
 package org.opendaylight.yangtools.yang.parser.spi.validation;
\ No newline at end of file
diff --git a/parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceTest.java b/parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/NamespaceTest.java
deleted file mode 100644 (file)
index c8ae439..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2017 Pantheon Technologies 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;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class NamespaceTest {
-    @Test
-    public void testNamespaces() {
-        // Touch behaviors
-        // FIXME: add more checks/split this up when behaviours are testable
-        assertNotNull(ExtensionNamespace.BEHAVIOUR);
-        assertNotNull(GroupingNamespace.BEHAVIOUR);
-        assertNotNull(IdentityNamespace.BEHAVIOUR);
-        assertNotNull(ModuleNamespace.BEHAVIOUR);
-        assertNotNull(PreLinkageModuleNamespace.BEHAVIOUR);
-        assertNotNull(SubmoduleNamespace.BEHAVIOUR);
-        assertNotNull(TypeNamespace.BEHAVIOUR);
-
-        assertNotNull(NamespaceToModule.BEHAVIOUR);
-    }
-}
index 5c4479bf7eb1356de15babf1c809412706903937..b4d9ca6c7e6c398526e207219d3001ef96e31a9f 100644 (file)
@@ -16,6 +16,6 @@ public class NamespaceTest {
     public void testNamespaces() {
         // Touch behaviors
         // FIXME: add more checks/split this up when behaviours are testable
-        assertNotNull(StatementDefinitionNamespace.BEHAVIOUR);
+        assertNotNull(StatementDefinitions.BEHAVIOUR);
     }
 }
diff --git a/parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/source/NamespaceTest.java b/parser/yang-parser-spi/src/test/java/org/opendaylight/yangtools/yang/parser/spi/source/NamespaceTest.java
deleted file mode 100644 (file)
index 8c3a8cd..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2017 Pantheon Technologies 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.source;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class NamespaceTest {
-    @Test
-    public void testNamespaces() {
-        // Touch behaviors
-        // FIXME: add more checks/split this up when behaviours are testable
-        assertNotNull(BelongsToPrefixToModuleCtx.BEHAVIOUR);
-        assertNotNull(BelongsToPrefixToModuleName.BEHAVIOUR);
-        assertNotNull(ImpPrefixToNamespace.BEHAVIOUR);
-        assertNotNull(ImportedModuleContext.BEHAVIOUR);
-        assertNotNull(ImportPrefixToModuleCtx.BEHAVIOUR);
-        assertNotNull(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR);
-        assertNotNull(IncludedModuleContext.BEHAVIOUR);
-        assertNotNull(ModuleCtxToModuleQName.BEHAVIOUR);
-        assertNotNull(ModuleNameToNamespace.BEHAVIOUR);
-        assertNotNull(ModuleQNameToModuleName.BEHAVIOUR);
-        assertNotNull(ModuleCtxToSourceIdentifier.BEHAVIOUR);
-        assertNotNull(ModuleNamespaceForBelongsTo.BEHAVIOUR);
-        assertNotNull(ModuleNameToModuleQName.BEHAVIOUR);
-        assertNotNull(ModulesDeviatedByModules.BEHAVIOUR);
-        assertNotNull(PrefixToModule.BEHAVIOUR);
-        assertNotNull(SupportedFeaturesNamespace.BEHAVIOUR);
-    }
-}