BUG-4688: Rename StmtContext.Mutable.addRequiredModule() 39/64539/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 19 Oct 2017 17:13:03 +0000 (19:13 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Oct 2017 10:00:25 +0000 (12:00 +0200)
This method is a misnomer, as we really are requiring a source to be
resolved. Rename the method to addRequiredSource() and make it work
with SourceIdentifier.

Also add a note that the method should be eliminate in favor of using
a namespace inside the reactor.

Change-Id: I39ce96da090bdf07af545e7dbd40363e5c048267
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BelongsToStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IncludeStatementImpl.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java

index 7feeeaff5ce18fbcdeecdab2a12a874a7b1c7886..69bf71821e8cdc3c98d20d799fdbaba22692d882 100644 (file)
@@ -32,7 +32,6 @@ import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.util.RecursiveObjectLeaker;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
@@ -439,21 +438,18 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     private void collectRequiredSourcesFromLib(
             final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable,
             final Set<SourceSpecificContext> requiredLibs, final SourceSpecificContext source) {
-        final Collection<ModuleIdentifier> requiredModules = source.getRequiredModules();
-        for (final ModuleIdentifier requiredModule : requiredModules) {
-            final SourceSpecificContext libSource = getRequiredLibSource(requiredModule, libSourcesTable);
+        for (final SourceIdentifier requiredSource : source.getRequiredSources()) {
+            final SourceSpecificContext libSource = getRequiredLibSource(requiredSource, libSourcesTable);
             if (libSource != null && requiredLibs.add(libSource)) {
                 collectRequiredSourcesFromLib(libSourcesTable, requiredLibs, libSource);
             }
         }
     }
 
-    private static SourceSpecificContext getRequiredLibSource(final ModuleIdentifier requiredModule,
+    private static SourceSpecificContext getRequiredLibSource(final SourceIdentifier requiredSource,
             final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable) {
-        return requiredModule.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP
-                || requiredModule.getRevision() == SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE ? getLatestRevision(
-                libSourcesTable.row(requiredModule.getName())) : libSourcesTable.get(requiredModule.getName(),
-                requiredModule.getRevision());
+        return requiredSource.getRevision() == null ? getLatestRevision(libSourcesTable.row(requiredSource.getName()))
+                : libSourcesTable.get(requiredSource.getName(), QName.parseRevision(requiredSource.getRevision()));
     }
 
     private static SourceSpecificContext getLatestRevision(final SortedMap<Date, SourceSpecificContext> sourceMap) {
index 8f6a5825bcee80b2a6c75138413638643b7ca470..2dff0ce79fd7dfecfe2fdf504928e85a19b7e89e 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 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.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 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;
@@ -48,7 +49,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     private final A argument;
 
     private YangVersion version;
-    private Collection<ModuleIdentifier> requiredModules = ImmutableSet.of();
+    private Collection<SourceIdentifier> requiredSources = ImmutableSet.of();
     private ModuleIdentifier identifier;
 
     /**
@@ -220,17 +221,22 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     @Override
-    public void addRequiredModule(final ModuleIdentifier dependency) {
+    public void addRequiredSource(final SourceIdentifier dependency) {
         checkState(sourceContext.getInProgressPhase() == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
                 "Add required module is allowed only in ModelProcessingPhase.SOURCE_PRE_LINKAGE phase");
-        if (requiredModules.isEmpty()) {
-            requiredModules = new HashSet<>();
+        if (requiredSources.isEmpty()) {
+            requiredSources = new HashSet<>();
         }
-        requiredModules.add(dependency);
+        requiredSources.add(dependency);
     }
 
-    Collection<ModuleIdentifier> getRequiredModules() {
-        return ImmutableSet.copyOf(requiredModules);
+    /**
+     * Return the set of required sources.
+     *
+     * @return Required sources.
+     */
+    Collection<SourceIdentifier> getRequiredSources() {
+        return ImmutableSet.copyOf(requiredSources);
     }
 
     @Override
index 48a06d0a7e0b1717c31244d096db13f6a05cc887..ee0cbd5db1dc4a75130a1492ffede7567dfcaa80 100644 (file)
@@ -31,6 +31,7 @@ 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.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 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.ModelProcessingPhase;
@@ -444,8 +445,8 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         currentContext.addMutableStmtToSeal(mutableStatement);
     }
 
-    Collection<ModuleIdentifier> getRequiredModules() {
-        return root.getRequiredModules();
+    Collection<SourceIdentifier> getRequiredSources() {
+        return root.getRequiredSources();
     }
 
     ModuleIdentifier getRootIdentifier() {
index a0b9710e7ef63b60d6fd669b89beb948a2ae2d6f..45f7e2eaa01b9e9936d0f5890867880000d0dcec 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
@@ -236,8 +237,8 @@ final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Eff
     }
 
     @Override
-    public void addRequiredModule(final ModuleIdentifier dependency) {
-        getRoot().addRequiredModule(dependency);
+    public void addRequiredSource(final SourceIdentifier dependency) {
+        getRoot().addRequiredSource(dependency);
     }
 
     @Override
index 1c37e2a80a4f16e1025c4101b0d889f53f463fd6..3cdfbba48d3ae50f87547ac513789ca6d820cbf0 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
@@ -71,7 +72,7 @@ public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
         @Override
         public void onPreLinkageDeclared(final StmtContext.Mutable<String, BelongsToStatement,
                 EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
-            belongsToCtx.addRequiredModule(getModuleIdentifier(belongsToCtx));
+            belongsToCtx.addRequiredSource(RevisionSourceIdentifier.create(belongsToCtx.getStatementArgument()));
         }
 
         @Override
index e6d873f219710340eadd99b4c3576d12fe97e71e..9d74b41c76512696b01575c2a564949183b0b1ae 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_PRE_LINKAGE;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
 import com.google.common.base.Verify;
@@ -29,7 +30,9 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
 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.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
@@ -90,7 +93,7 @@ public class ImportStatementDefinition extends
          * Based on this information, required modules are searched from library
          * sources.
          */
-        stmt.addRequiredModule(RevisionImport.getImportedModuleIdentifier(stmt));
+        stmt.addRequiredSource(RevisionImport.getImportedSourceIdentifier(stmt));
 
         final String moduleName = stmt.getStatementArgument();
         final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
@@ -215,8 +218,7 @@ public class ImportStatementDefinition extends
             return recentModuleEntry;
         }
 
-        private static ModuleIdentifier getImportedModuleIdentifier(
-                final StmtContext<String, ImportStatement, ?> stmt) {
+        static ModuleIdentifier getImportedModuleIdentifier(final StmtContext<String, ImportStatement, ?> stmt) {
             Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
             if (revision == null) {
                 revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
@@ -224,6 +226,12 @@ public class ImportStatementDefinition extends
 
             return ModuleIdentifierImpl.create(stmt.getStatementArgument(), Optional.empty(), Optional.of(revision));
         }
+
+        static SourceIdentifier getImportedSourceIdentifier(final StmtContext<String, ImportStatement, ?> stmt) {
+            final StmtContext<Date, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class);
+            return revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument())
+                    : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.rawStatementArgument());
+        }
     }
 
     private static class SemanticVersionImport {
index f698d2359097ec2227a77de0ff634ae914c1647f..5167eaa7decb3bd461beb81eb88a5e6e444acb96 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
 import java.util.Collection;
@@ -22,6 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
@@ -72,7 +74,9 @@ public class IncludeStatementImpl extends AbstractDeclaredStatement<String> impl
         @Override
         public void onPreLinkageDeclared(
                 final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt) {
-            stmt.addRequiredModule(getIncludeSubmoduleIdentifier(stmt));
+            final StmtContext<Date, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class);
+            stmt.addRequiredSource(revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument())
+                : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.rawStatementArgument()));
         }
 
         @Override
index 0d3dba150b1dd43cc7e943b803d9897d31a1db32..9ef9b6ada2fa8b9f3fa95444fa8fb447beb2e72f 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
@@ -227,14 +228,18 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         void addMutableStmtToSeal(MutableStatement mutableStatement);
 
         /**
-         * Add required module. Based on these dependencies are collected
-         * required sources from library sources.
+         * Add required module. Based on these dependencies are collected required sources from library sources.
          *
          * @param dependency
-         *            ModuleIdentifier of module required by current root
+         *            SourceIdentifier of module required by current root
          *            context
          */
-        void addRequiredModule(ModuleIdentifier dependency);
+        /*
+         * FIXME: this method is used solely during SOURCE_PRE_LINKAGE reactor phase and does not have a corresponding
+         *        getter -- which makes it rather strange. At some point this method needs to be deprecated and its
+         *        users migrated to use proper global namespace.
+         */
+        void addRequiredSource(SourceIdentifier dependency);
 
         void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);