BUG-4688: Fix IncludedSubmoduleNameToIdentifier namespace 62/64562/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Oct 2017 09:09:46 +0000 (11:09 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Oct 2017 10:00:25 +0000 (12:00 +0200)
This namespace is used as an indirection towards lookup of submodule's
StmtContext. This is completely unnecessary, as we can easily store
the context in the namespace, as we already have it available when
include statement's prerequisite is resolved.

This eliminates the need for a ModuleIdentifier-based lookup.

Change-Id: I21b0aad832cad57ad35980df4e0b33b44d77b084
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IncludeStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedSubmoduleNameToModuleCtx.java [moved from yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/IncludedSubmoduleNameToIdentifier.java with 74% similarity]

index 5167eaa7decb3bd461beb81eb88a5e6e444acb96..fa535718d767d51b156f9a05181fa6ef7f30906e 100644 (file)
@@ -37,7 +37,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.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IncludeEffectiveStatementImpl;
 
 public class IncludeStatementImpl extends AbstractDeclaredStatement<String> implements IncludeStatement {
@@ -95,8 +95,8 @@ public class IncludeStatementImpl extends AbstractDeclaredStatement<String> impl
 
                     stmt.addToNs(IncludedModuleContext.class, includeSubmoduleIdentifier,
                             includedSubModuleContext);
-                    stmt.addToNs(IncludedSubmoduleNameToIdentifier.class,
-                            stmt.getStatementArgument(), includeSubmoduleIdentifier);
+                    stmt.addToNs(IncludedSubmoduleNameToModuleCtx.class, stmt.getStatementArgument(),
+                        includedSubModuleContext);
                 }
 
                 @Override
index ab3ee19a9cda74ba42f4be143dba8cd341a2bf3b..de77fb14a9c422edb77a257e7b66c7a41ff1386b 100644 (file)
@@ -45,7 +45,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier;
 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.IncludedSubmoduleNameToIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
@@ -137,7 +137,7 @@ public final class YangInferencePipeline {
             .addSupport(QNameCacheNamespace.getInstance())
             .addSupport(sourceLocal(ImportedModuleContext.class))
             .addSupport(sourceLocal(IncludedModuleContext.class))
-            .addSupport(sourceLocal(IncludedSubmoduleNameToIdentifier.class))
+            .addSupport(sourceLocal(IncludedSubmoduleNameToModuleCtx.class))
             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
             .addSupport(sourceLocal(BelongsToPrefixToModuleCtx.class))
             .addSupport(sourceLocal(URIStringToImpPrefix.class))
index 10c45ca49897fd3e364eb1a464822912604314e9..5d1ecb5438885ce3fbec10677164f11bcc30ba7a 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
@@ -49,11 +48,10 @@ import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 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.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> extends
@@ -119,8 +117,8 @@ abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> exte
 
         // init submodules and substatements of submodules
         final List<EffectiveStatement<?, ?>> substatementsOfSubmodules;
-        final Map<String, ModuleIdentifier> includedSubmodulesMap = ctx
-                .getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToIdentifier.class);
+        final Map<String, StmtContext<?, ?, ?>> includedSubmodulesMap = ctx
+                .getAllFromCurrentStmtCtxNamespace(IncludedSubmoduleNameToModuleCtx.class);
 
         if (includedSubmodulesMap == null || includedSubmodulesMap.isEmpty()) {
             this.submodules = ImmutableSet.of();
@@ -132,14 +130,10 @@ abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> exte
              * for modules. In case of submodules it does not make sense because
              * of possible circular chains of includes between submodules.
              */
-            final Collection<ModuleIdentifier> includedSubmodules = includedSubmodulesMap.values();
+            final Collection<StmtContext<?, ?, ?>> includedSubmodules = includedSubmodulesMap.values();
             final Set<Module> submodulesInit = new HashSet<>();
             final List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new ArrayList<>();
-            for (final ModuleIdentifier submoduleIdentifier : includedSubmodules) {
-                @SuppressWarnings("unchecked")
-                final Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx =
-                        (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
-                        .getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
+            for (final StmtContext<?, ?, ?> submoduleCtx : includedSubmodules) {
                 final SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
                         .buildEffective();
                 submodulesInit.add(submodule);
@@ -159,10 +153,9 @@ abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> exte
              */
             final Set<StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>>
                 submoduleContextsInit = new HashSet<>();
-            for (final ModuleIdentifier submoduleIdentifier : includedSubmodulesMap.values()) {
-                final StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx =
-                        ctx.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
-                submoduleContextsInit.add(submoduleCtx);
+            for (final StmtContext<?, ?, ?> submoduleCtx : includedSubmodulesMap.values()) {
+                submoduleContextsInit.add(
+                    (StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>)submoduleCtx);
             }
 
             this.submoduleContextsToBuild = ImmutableSet.copyOf(submoduleContextsInit);
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.source;
 
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 /**
  * Source-specific mapping of prefixes to namespaces.
  */
-public interface IncludedSubmoduleNameToIdentifier extends IdentifierNamespace<String, ModuleIdentifier> {
+public interface IncludedSubmoduleNameToModuleCtx extends IdentifierNamespace<String, StmtContext<?, ?, ?>> {
 
 }