Do not use ModuleIdentifier to identify sources 93/64993/8
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 Oct 2017 17:09:14 +0000 (18:09 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 15:46:02 +0000 (16:46 +0100)
This eliminates the use of ModuleIdentifier for library resolution
purposes, paving a way to support semantic imports with module
library.

Change-Id: Idfb885472b191c0685b6e385c405e18934e0b84f
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/ModuleStatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java

index 0cb3897da602acc272b6467573ca2f130cfbae9f..980a17ead348ebc0f2a4950a8ca77b06ffd63d01 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Verify;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.ImmutableList;
@@ -33,7 +35,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 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;
@@ -88,7 +89,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports,
             final Map<ValidationBundleType, Collection<?>> supportedValidation,
             final StatementParserMode statementParserMode) {
-        this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null");
+        this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
 
         switch (statementParserMode) {
             case DEFAULT_MODE:
@@ -121,9 +122,9 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     void addLibSource(@Nonnull final StatementStreamSource libSource) {
-        Preconditions.checkState(!isEnabledSemanticVersioning(),
-                "Library sources are not supported in semantic version mode currently.");
-        Preconditions.checkState(currentPhase == ModelProcessingPhase.INIT,
+        checkState(!isEnabledSemanticVersioning(),
+            "Library sources are not supported in semantic version mode currently.");
+        checkState(currentPhase == ModelProcessingPhase.INIT,
                 "Add library source is allowed in ModelProcessingPhase.INIT only");
         libSources.add(new SourceSpecificContext(this, libSource));
     }
@@ -230,7 +231,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private EffectiveModelContext transform() {
-        Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+        checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
         for (final SourceSpecificContext source : sources) {
             rootStatements.add(source.getRoot().buildDeclared());
@@ -256,7 +257,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
 
     @SuppressWarnings("checkstyle:illegalCatch")
     private EffectiveSchemaContext transformEffective() throws ReactorException {
-        Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+        checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
         final List<EffectiveStatement<?, ?>> rootEffectiveStatements = new ArrayList<>(sources.size());
 
@@ -279,7 +280,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private void startPhase(final ModelProcessingPhase phase) {
-        Preconditions.checkState(Objects.equals(finishedPhase, phase.getPreviousPhase()));
+        checkState(Objects.equals(finishedPhase, phase.getPreviousPhase()));
         startPhaseFor(phase, sources);
         startPhaseFor(phase, libSources);
 
@@ -294,7 +295,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private void loadPhaseStatements() throws ReactorException {
-        Preconditions.checkState(currentPhase != null);
+        checkState(currentPhase != null);
         loadPhaseStatementsFor(sources);
         loadPhaseStatementsFor(libSources);
     }
@@ -359,10 +360,10 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
 
     @SuppressWarnings("checkstyle:illegalCatch")
     private void completePhaseActions() throws ReactorException {
-        Preconditions.checkState(currentPhase != null);
+        checkState(currentPhase != null);
         final List<SourceSpecificContext> sourcesToProgress = new ArrayList<>(sources);
         if (!libSources.isEmpty()) {
-            Preconditions.checkState(currentPhase == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
+            checkState(currentPhase == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
                     "Yang library sources should be empty after ModelProcessingPhase.SOURCE_PRE_LINKAGE, "
                             + "but current phase was %s", currentPhase);
             sourcesToProgress.addAll(libSources);
@@ -418,13 +419,13 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private Set<SourceSpecificContext> getRequiredSourcesFromLib() {
-        Preconditions.checkState(currentPhase == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
+        checkState(currentPhase == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
                 "Required library sources can be collected only in ModelProcessingPhase.SOURCE_PRE_LINKAGE phase,"
                         + " but current phase was %s", currentPhase);
         final TreeBasedTable<String, Optional<Revision>, SourceSpecificContext> libSourcesTable = TreeBasedTable.create(
             String::compareTo, Revision::compare);
         for (final SourceSpecificContext libSource : libSources) {
-            final ModuleIdentifier libSourceIdentifier = Preconditions.checkNotNull(libSource.getRootIdentifier());
+            final SourceIdentifier libSourceIdentifier = requireNonNull(libSource.getRootIdentifier());
             libSourcesTable.put(libSourceIdentifier.getName(), libSourceIdentifier.getRevision(), libSource);
         }
 
@@ -476,7 +477,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     private void endPhase(final ModelProcessingPhase phase) {
-        Preconditions.checkState(currentPhase == phase);
+        checkState(currentPhase == phase);
         finishedPhase = currentPhase;
         LOG.debug("Global phase {} finished", phase);
     }
index 2dff0ce79fd7dfecfe2fdf504928e85a19b7e89e..7d60b26c1a1b0a733d1e3e3fc364fdeb4929e0b6 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 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;
@@ -50,7 +49,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
 
     private YangVersion version;
     private Collection<SourceIdentifier> requiredSources = ImmutableSet.of();
-    private ModuleIdentifier identifier;
+    private SourceIdentifier identifier;
 
     /**
      * References to RootStatementContext of submodules which are included in this source.
@@ -66,7 +65,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
 
     RootStatementContext(final SourceSpecificContext sourceContext, final StatementDefinitionContext<A, D, E> def,
             final StatementSourceReference ref, final String rawArgument, final YangVersion version,
-            final ModuleIdentifier identifier) {
+            final SourceIdentifier identifier) {
         this(sourceContext, def, ref, rawArgument);
         this.setRootVersion(version);
         this.setRootIdentifier(identifier);
@@ -240,11 +239,11 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     @Override
-    public void setRootIdentifier(final ModuleIdentifier identifier) {
+    public void setRootIdentifier(final SourceIdentifier identifier) {
         this.identifier = requireNonNull(identifier);
     }
 
-    ModuleIdentifier getRootIdentifier() {
+    SourceIdentifier getRootIdentifier() {
         return identifier;
     }
 
index 68c58b96acd251ac594fd68ead09fbeb9db33394..d4d2e3684ed32ebe1777465e361ed02465081be3 100644 (file)
@@ -26,7 +26,6 @@ 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.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 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;
@@ -454,7 +453,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         return root.getRequiredSources();
     }
 
-    ModuleIdentifier getRootIdentifier() {
+    SourceIdentifier getRootIdentifier() {
         return root.getRootIdentifier();
     }
 }
index 45f7e2eaa01b9e9936d0f5890867880000d0dcec..f45d65c0bddde499414f17ac121510d3e9fc96fb 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.yangtools.util.OptionalBoolean;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 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;
@@ -242,7 +241,7 @@ final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Eff
     }
 
     @Override
-    public void setRootIdentifier(final ModuleIdentifier identifier) {
+    public void setRootIdentifier(final SourceIdentifier identifier) {
         getRoot().setRootIdentifier(identifier);
     }
 
index 74e6b2d17e8460875e6b7a47d8150518ae5b3100..cb61af8a4485956e07a88c8cd09acb9861810dff 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 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.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
@@ -118,7 +119,7 @@ public class ModuleStatementSupport extends
         final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
 
         stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
-        stmt.setRootIdentifier(ModuleIdentifierImpl.create(stmt.getStatementArgument(), revisionDate));
+        stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.getStatementArgument(), revisionDate));
     }
 
     @Override
index 53b71315658e845a2879c4235c10338fcd99c268..d136396805d7b7afc57d2ca0d176a669bef06f1f 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
+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.AbstractStatementSupport;
@@ -92,7 +93,8 @@ public class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleState
         @Override
         public void onPreLinkageDeclared(
                 final Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt) {
-            stmt.setRootIdentifier(getSubmoduleIdentifier(stmt));
+            stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.getStatementArgument(),
+                StmtContextUtils.getLatestRevision(stmt.declaredSubstatements())));
         }
 
         @Override
index 9ef9b6ada2fa8b9f3fa95444fa8fb447beb2e72f..939d6f2d2b5c5690f6d3c1a43977ba2525394b1b 100644 (file)
@@ -17,7 +17,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 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;
@@ -249,9 +248,9 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          * Set identifier of current root context.
          *
          * @param identifier
-         *            of current root context
+         *            of current root context, must not be null
          */
-        void setRootIdentifier(ModuleIdentifier identifier);
+        void setRootIdentifier(SourceIdentifier identifier);
 
         void setIsSupportedToBuildEffective(boolean isSupportedToBuild);