Use UnqualifiedQName for {Module,Submodule}Statement 10/92910/6
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 6 Oct 2020 06:14:42 +0000 (08:14 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 6 Oct 2020 08:00:23 +0000 (10:00 +0200)
UnqualifiedQName is the best approximation of a validated string
we have, even if it has a clunky name. Redefine module-like statements
to take that as an argument, forcing proper validation during
parse.

Change-Id: Ic902b8eedb0e955f00d14b41d115765c576df055
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
24 files changed:
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/BodyDeclaredStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/LinkageDeclaredStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/RevisionAwareDeclaredStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SubmoduleEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SubmoduleStatement.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/namespace/ChildSchemaNodeNamespace.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractDeclaredEffectiveRootStatement.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/EffectiveStmtUtils.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/import_/AbstractImportStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/AbstractModuleStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleEffectiveStatementImpl.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/module/ModuleStatementImpl.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/AbstractSubmoduleStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/SubmoduleEffectiveStatementImpl.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/submodule/SubmoduleStatementImpl.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7954Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/NameCollisionWithinCaseTest.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java

index 0c1665549dfc76df6b11f5088a4360a72ba03085..d7c23cd82abc8e74ad7d9a463693ec74412aafa1 100644 (file)
@@ -10,10 +10,11 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 import com.google.common.annotations.Beta;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 
 @Beta
-public interface BodyDeclaredStatement extends NotificationStatementAwareDeclaredStatement<String>,
-        DataDefinitionAwareDeclaredStatement.WithReusableDefinitions<String> {
+public interface BodyDeclaredStatement extends NotificationStatementAwareDeclaredStatement<UnqualifiedQName>,
+        DataDefinitionAwareDeclaredStatement.WithReusableDefinitions<UnqualifiedQName> {
     default @NonNull Collection<? extends ExtensionStatement> getExtensions() {
         return declaredSubstatements(ExtensionStatement.class);
     }
index 2c66bfe67c14d70008fefced09a0346edf663034..88f93c0bdee7ff6333ccdcda3c5d509e2fd37df2 100644 (file)
@@ -10,10 +10,11 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 import com.google.common.annotations.Beta;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
 @Beta
-public interface LinkageDeclaredStatement extends DeclaredStatement<String> {
+public interface LinkageDeclaredStatement extends DeclaredStatement<UnqualifiedQName> {
     default @NonNull Collection<? extends ImportStatement> getImports() {
         return declaredSubstatements(ImportStatement.class);
     }
index e13d3776b3c520e6935d394d801833c86ebe6712..7f4784e6fe6ea64633d50ba6ce305efd1f5033e7 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
@@ -18,11 +19,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
  * Effective view of a {@link ModuleStatement}.
  */
 @Beta
-// FIXME: 6.0.0: we should reshuffle the String here, as module name is in reality a YANG identifier, e.g. not just
-//               an ordinary String. We really want this to be a QName, so that we do not need the localQNameModule
-//               bit, but that may be problematic with ModuleStatement, which is getting created before we even know
-//               the namespace :( A type capture of the string may just be sufficient.
-public interface ModuleEffectiveStatement extends DataTreeAwareEffectiveStatement<String, ModuleStatement> {
+public interface ModuleEffectiveStatement extends DataTreeAwareEffectiveStatement<UnqualifiedQName, ModuleStatement> {
     /**
      * Namespace mapping all known prefixes in a module to their modules. Note this namespace includes the module
      * in which it is instantiated.
index 6a4aae3938ac11ab9d308597988e7ab4dfa87e87..e9ee57446b082337d07405bd2320325ea8e4ac13 100644 (file)
@@ -11,11 +11,12 @@ import static com.google.common.base.Verify.verifyNotNull;
 
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
-public interface ModuleStatement extends MetaDeclaredStatement<String>, ModuleHeaderGroup, LinkageDeclaredStatement,
-        RevisionAwareDeclaredStatement, BodyDeclaredStatement {
+public interface ModuleStatement extends MetaDeclaredStatement<UnqualifiedQName>, ModuleHeaderGroup,
+        LinkageDeclaredStatement, RevisionAwareDeclaredStatement, BodyDeclaredStatement {
     @Override
     default StatementDefinition statementDefinition() {
         return YangStmtMapping.MODULE;
index 4679908cc0d2d4d60d5db0e8f212615c09f7ce97..0faea315b5b17b0335499fa1bd5320e38a5ce872 100644 (file)
@@ -10,10 +10,11 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 import com.google.common.annotations.Beta;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
 @Beta
-public interface RevisionAwareDeclaredStatement extends DeclaredStatement<String> {
+public interface RevisionAwareDeclaredStatement extends DeclaredStatement<UnqualifiedQName> {
     default @NonNull Collection<? extends RevisionStatement> getRevisions() {
         return declaredSubstatements(RevisionStatement.class);
     }
index 24c7716aab55fd83425ca916741f5424babeaa65..bdf12cca658d7e7df5fff6cbf6ef81c93f7e3bb4 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
@@ -17,7 +18,8 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
  * {@link ModuleEffectiveStatement.QNameModuleToPrefixNamespace} namespaces.
  */
 @Beta
-public interface SubmoduleEffectiveStatement extends DataTreeAwareEffectiveStatement<String, SubmoduleStatement> {
+public interface SubmoduleEffectiveStatement
+        extends DataTreeAwareEffectiveStatement<UnqualifiedQName, SubmoduleStatement> {
     @Override
     default StatementDefinition statementDefinition() {
         return YangStmtMapping.SUBMODULE;
index 468ad243882fb670570a26f06a33b758db171ee4..e8fbb918be655945cc386d70c32ec8f7c14c807a 100644 (file)
@@ -12,10 +12,11 @@ import static com.google.common.base.Verify.verifyNotNull;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
-public interface SubmoduleStatement extends MetaDeclaredStatement<String>, LinkageDeclaredStatement,
+public interface SubmoduleStatement extends MetaDeclaredStatement<UnqualifiedQName>, LinkageDeclaredStatement,
         RevisionAwareDeclaredStatement, BodyDeclaredStatement {
     @Override
     default StatementDefinition statementDefinition() {
index 8cb74a5eea64518d8cef04324ba4136908f95add..b17e632c0c776a6692dd8d85d0eb616731c446a2 100644 (file)
@@ -38,6 +38,7 @@ 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.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
@@ -52,7 +53,9 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 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.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.ModulesDeviatedByModules.SupportedModules;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -242,7 +245,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
 
     private SomeModifiersUnresolvedException propagateException(final SourceSpecificContext source,
             final RuntimeException cause) throws SomeModifiersUnresolvedException {
-        final SourceIdentifier sourceId = StmtContextUtils.createSourceIdentifier(source.getRoot());
+        final SourceIdentifier sourceId = createSourceIdentifier(source.getRoot());
         if (!(cause instanceof SourceException)) {
             /*
              * This should not be happening as all our processing should provide SourceExceptions.
@@ -256,6 +259,18 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         throw new SomeModifiersUnresolvedException(currentPhase, sourceId, cause);
     }
 
+    private static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
+        final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
+        final String arg = root.coerceRawStatementArgument();
+        if (qNameModule != null) {
+            // creates SourceIdentifier for a module
+            return RevisionSourceIdentifier.create(arg, qNameModule.getRevision());
+        }
+
+        // creates SourceIdentifier for a submodule
+        return RevisionSourceIdentifier.create(arg, StmtContextUtils.getLatestRevision(root.declaredSubstatements()));
+    }
+
     @SuppressWarnings("checkstyle:illegalCatch")
     private EffectiveSchemaContext transformEffective() throws ReactorException {
         checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
@@ -344,7 +359,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
 
             if (!addedCause) {
                 addedCause = true;
-                final SourceIdentifier sourceId = StmtContextUtils.createSourceIdentifier(failedSource.getRoot());
+                final SourceIdentifier sourceId = createSourceIdentifier(failedSource.getRoot());
                 buildFailure = new SomeModifiersUnresolvedException(currentPhase, sourceId, sourceEx);
             } else {
                 buildFailure.addSuppressed(sourceEx);
index fe9c4e58c9c72ed37671d8d92fa23fad14eb8315..74a33a86f81f130a7429f3b817d09e046455ae70 100644 (file)
@@ -61,7 +61,7 @@ public final class ChildSchemaNodeNamespace<D extends DeclaredStatement<QName>,
         if (prev != null) {
             throw new SourceException(value.getStatementSourceReference(),
                 "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
-                value.getRoot().getStatementArgument(), key, prev.getStatementArgument(),
+                value.getRoot().rawStatementArgument(), key, prev.getStatementArgument(),
                 prev.getStatementSourceReference());
         }
     }
index 60fb169cddbe322ae7e3156ab4de26fb189e0116..0c75a358588731f288c69db0cdbc9323f87c4c83 100644 (file)
@@ -9,19 +9,21 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.BodyDeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LinkageDeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.MetaDeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionAwareDeclaredStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 @Beta
-public abstract class AbstractDeclaredEffectiveRootStatement<D extends DeclaredStatement<String>>
-        extends WithSubstatements implements LinkageDeclaredStatement, MetaDeclaredStatement<String>,
-                RevisionAwareDeclaredStatement, BodyDeclaredStatement {
-    protected AbstractDeclaredEffectiveRootStatement(final String rawArgument,
+public abstract class AbstractDeclaredEffectiveRootStatement<D extends DeclaredStatement<UnqualifiedQName>>
+        extends WithSubstatements<UnqualifiedQName> implements LinkageDeclaredStatement,
+                MetaDeclaredStatement<UnqualifiedQName>, RevisionAwareDeclaredStatement, BodyDeclaredStatement {
+    protected AbstractDeclaredEffectiveRootStatement(final StmtContext<UnqualifiedQName, ?, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        super(rawArgument, substatements);
+        super(ctx, substatements);
     }
 }
index 4f6ef50f3c2c4516c6fb1465ed113f7b35ff4d04..b4f1db277d05c21d3b4462b9eb11967eae7ee673 100644 (file)
@@ -26,6 +26,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.SemVer;
 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigVersionEffectiveStatement;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -63,9 +64,11 @@ import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 @Beta
-public abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>,
-        E extends DataTreeAwareEffectiveStatement<String, D>> extends WithSubstatements<String, D, E>
-        implements ModuleLike, DocumentedNodeMixin<String, D>, NotificationNodeContainerCompat<String, D, E> {
+public abstract class AbstractEffectiveModule<D extends DeclaredStatement<UnqualifiedQName>,
+        E extends DataTreeAwareEffectiveStatement<UnqualifiedQName, D>>
+        extends WithSubstatements<UnqualifiedQName, D, E>
+        implements ModuleLike, DocumentedNodeMixin<UnqualifiedQName, D>,
+            NotificationNodeContainerCompat<UnqualifiedQName, D, E> {
     private final String prefix;
     private final ImmutableSet<GroupingDefinition> groupings;
     private final ImmutableSet<UsesNode> uses;
@@ -73,7 +76,7 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<String
     private final ImmutableMap<QName, SchemaTreeEffectiveStatement<?>> schemaTreeNamespace;
 
     protected AbstractEffectiveModule(final D declared,
-            final StmtContext<String, D, ? extends EffectiveStatement<String, ?>> ctx,
+            final StmtContext<UnqualifiedQName, D, ? extends EffectiveStatement<UnqualifiedQName, ?>> ctx,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final String prefix) {
         super(declared, ctx, substatements);
 
@@ -115,13 +118,13 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<String
     }
 
     @Override
-    public String argument() {
+    public UnqualifiedQName argument() {
         return getDeclared().argument();
     }
 
     @Override
     public String getName() {
-        return argument();
+        return argument().getLocalName();
     }
 
     @Override
index 0d3ebb91558e6f92362ce86e0785a0140b59d74c..cca1829093654953c5f847c060ca0521a83fc3cb 100644 (file)
@@ -46,9 +46,7 @@ public final class EffectiveStmtUtils {
             final EffectiveStatement<?, ?> effectiveStatement) {
         return new SourceException(ctx.getStatementSourceReference(),
             "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared.",
-            ctx.getRoot().getStatementArgument(),
-            effectiveStatement.argument(),
-            effectiveStatement.argument());
+            ctx.getRoot().rawStatementArgument(), effectiveStatement.argument(), effectiveStatement.argument());
     }
 
     public static Optional<ElementCountConstraint> createElementCountConstraint(final EffectiveStatement<?, ?> stmt) {
index 2cdd064ab23c140f0deddcbb7fbcf51c2798b7fd..6ad80e9e4deb055ce56dbc22e7b64c40908cac4a 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Optional;
 import org.opendaylight.yangtools.concepts.SemVer;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 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;
@@ -66,7 +67,9 @@ abstract class AbstractImportStatementSupport
             @Override
             public void apply(final InferenceContext ctx) {
                 final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx);
-                Verify.verify(moduleName.equals(importedModuleContext.getStatementArgument()));
+                final Object importArgument = importedModuleContext.coerceStatementArgument();
+                Verify.verify(importArgument instanceof UnqualifiedQName, "Unexpected module name %s", importArgument);
+                Verify.verify(moduleName.equals(((UnqualifiedQName) importArgument).getLocalName()));
                 final URI importedModuleNamespace = importedModuleContext.getFromNamespace(ModuleNameToNamespace.class,
                         moduleName);
                 Verify.verifyNotNull(importedModuleNamespace);
index ee0b1c70adedfb51772f320a9bcc47ca61d015a8..1568859a55687e2b3f98c2b21c5c52aba9c1f7cf 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Optional;
 import org.opendaylight.yangtools.concepts.SemVer;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Submodule;
@@ -55,28 +56,33 @@ import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 abstract class AbstractModuleStatementSupport
-        extends BaseStatementSupport<String, ModuleStatement, ModuleEffectiveStatement> {
+        extends BaseStatementSupport<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> {
     AbstractModuleStatementSupport() {
         super(YangStmtMapping.MODULE);
     }
 
     @Override
-    public final String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return value;
+    public final UnqualifiedQName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+        try {
+            return UnqualifiedQName.of(value);
+        } catch (IllegalArgumentException e) {
+            throw new SourceException(e.getMessage(), ctx.getStatementSourceReference(), e);
+        }
     }
 
     @Override
-    public final void onPreLinkageDeclared(final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt) {
-        final String moduleName = stmt.getStatementArgument();
+    public final void onPreLinkageDeclared(
+            final Mutable<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> stmt) {
+        final String moduleName = stmt.coerceStatementArgument().getLocalName();
 
         final URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class);
         SourceException.throwIfNull(moduleNs, stmt.getStatementSourceReference(),
-            "Namespace of the module [%s] is missing", stmt.getStatementArgument());
+            "Namespace of the module [%s] is missing", moduleName);
         stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs);
 
         final String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
         SourceException.throwIfNull(modulePrefix, stmt.getStatementSourceReference(),
-            "Prefix of the module [%s] is missing", stmt.getStatementArgument());
+            "Prefix of the module [%s] is missing", moduleName);
         stmt.addToNs(ImpPrefixToNamespace.class, modulePrefix, moduleNs);
 
         stmt.addContext(PreLinkageModuleNamespace.class, moduleName, stmt);
@@ -85,11 +91,13 @@ abstract class AbstractModuleStatementSupport
         final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
 
         stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
-        stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.getStatementArgument(), revisionDate));
+        stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.coerceStatementArgument().getLocalName(),
+            revisionDate));
     }
 
     @Override
-    public final void onLinkageDeclared(final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt) {
+    public final void onLinkageDeclared(
+            final Mutable<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> stmt) {
 
         final Optional<URI> moduleNs = Optional.ofNullable(firstAttributeOf(stmt.declaredSubstatements(),
                 NamespaceStatement.class));
@@ -105,8 +113,8 @@ abstract class AbstractModuleStatementSupport
                     qNameModule.getNamespace(), possibleDuplicateModule.getStatementSourceReference());
         }
 
-        final SourceIdentifier moduleIdentifier = RevisionSourceIdentifier.create(stmt.getStatementArgument(),
-                revisionDate);
+        final SourceIdentifier moduleIdentifier = RevisionSourceIdentifier.create(
+            stmt.coerceStatementArgument().getLocalName(), revisionDate);
 
         stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
         stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleIdentifier.getName(), stmt);
@@ -117,10 +125,10 @@ abstract class AbstractModuleStatementSupport
             "Prefix of the module [%s] is missing", stmt.getStatementArgument());
 
         stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
-        stmt.addToNs(ModuleNameToModuleQName.class, stmt.getStatementArgument(), qNameModule);
+        stmt.addToNs(ModuleNameToModuleQName.class, stmt.getStatementArgument().getLocalName(), qNameModule);
         stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
         stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
-        stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, stmt.getStatementArgument());
+        stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, stmt.getStatementArgument().getLocalName());
         stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
 
         if (stmt.isEnabledSemanticVersioning()) {
@@ -130,7 +138,7 @@ abstract class AbstractModuleStatementSupport
 
     @Override
     protected final ImmutableList<? extends EffectiveStatement<?, ?>> buildEffectiveSubstatements(
-            final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+            final StmtContext<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> ctx,
             final List<? extends StmtContext<?, ?, ?>> substatements) {
         final ImmutableList<? extends EffectiveStatement<?, ?>> local =
                 super.buildEffectiveSubstatements(ctx, substatements);
@@ -156,19 +164,19 @@ abstract class AbstractModuleStatementSupport
     }
 
     @Override
-    protected final ModuleStatement createDeclared(final StmtContext<String, ModuleStatement, ?> ctx,
+    protected final ModuleStatement createDeclared(final StmtContext<UnqualifiedQName, ModuleStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new ModuleStatementImpl(ctx.coerceRawStatementArgument(), substatements);
+        return new ModuleStatementImpl(ctx, substatements);
     }
 
     @Override
-    protected final ModuleStatement createEmptyDeclared(final StmtContext<String, ModuleStatement, ?> ctx) {
+    protected final ModuleStatement createEmptyDeclared(final StmtContext<UnqualifiedQName, ModuleStatement, ?> ctx) {
         throw noNamespace(ctx);
     }
 
     @Override
     protected final ModuleEffectiveStatement createEffective(
-            final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+            final StmtContext<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> ctx,
             final ModuleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         final List<Submodule> submodules = new ArrayList<>();
         for (StmtContext<?, ?, ?> submoduleCtx : submoduleContexts(ctx)) {
@@ -182,7 +190,8 @@ abstract class AbstractModuleStatementSupport
 
     @Override
     protected final ModuleEffectiveStatement createEmptyEffective(
-            final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx, final ModuleStatement declared) {
+            final StmtContext<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> ctx,
+            final ModuleStatement declared) {
         throw noNamespace(ctx);
     }
 
@@ -197,9 +206,9 @@ abstract class AbstractModuleStatementSupport
     }
 
     private static void addToSemVerModuleNamespace(
-            final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt,
+            final Mutable<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> stmt,
             final SourceIdentifier moduleIdentifier) {
-        final String moduleName = stmt.coerceStatementArgument();
+        final String moduleName = stmt.coerceStatementArgument().getLocalName();
         final SemVer moduleSemVer = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt);
         final SemVerSourceIdentifier id = SemVerSourceIdentifier.create(moduleName, moduleSemVer);
         stmt.addToNs(SemanticVersionModuleNamespace.class, id, stmt);
index 93fe4f0260541c245d6ebfd0eaa663f3cd47d937..50d61ba53dbf3d8e333a7e25c9230ef85952a273 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Optional;
 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.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.Submodule;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -56,10 +57,10 @@ final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleS
     private final @NonNull QNameModule qnameModule;
     private final ImmutableList<Submodule> submodules;
 
-    ModuleEffectiveStatementImpl(final StmtContext<String, ModuleStatement, ModuleEffectiveStatement> ctx,
+    ModuleEffectiveStatementImpl(final StmtContext<UnqualifiedQName, ModuleStatement, ModuleEffectiveStatement> ctx,
             final ModuleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
             final Collection<? extends Submodule> submodules) {
-        super(declared, ctx, substatements, findPrefix(ctx, "module", ctx.getStatementArgument()));
+        super(declared, ctx, substatements, findPrefix(ctx, "module", ctx.coerceStatementArgument().getLocalName()));
 
         qnameModule = verifyNotNull(ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx));
         this.submodules = ImmutableList.copyOf(submodules);
index fab4de6aeff99c02ea3dbd970d1af8d6388b642a..55a896397a7fdec3ca7a516067a0f0a3ca0cc81c 100644 (file)
@@ -8,14 +8,16 @@
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
 
 import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveRootStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 final class ModuleStatementImpl extends AbstractDeclaredEffectiveRootStatement<ModuleStatement>
         implements ModuleStatement {
-    ModuleStatementImpl(final String rawArgument,
+    ModuleStatementImpl(final StmtContext<UnqualifiedQName, ?, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        super(rawArgument, substatements);
+        super(ctx, substatements);
     }
 }
index 849ba958527f9477e2ac1468636b910227c5b7e3..193ba16695be564276cd5512d86f0e9a54774f60 100644 (file)
@@ -11,6 +11,7 @@ import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.f
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
 import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 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;
@@ -29,33 +30,39 @@ import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModule
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 abstract class AbstractSubmoduleStatementSupport
-        extends BaseStatementSupport<String, SubmoduleStatement, SubmoduleEffectiveStatement> {
+        extends BaseStatementSupport<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> {
     AbstractSubmoduleStatementSupport() {
         super(YangStmtMapping.SUBMODULE);
     }
 
     @Override
-    public final String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return value;
+    public final UnqualifiedQName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+        try {
+            return UnqualifiedQName.of(value);
+        } catch (IllegalArgumentException e) {
+            throw new SourceException(e.getMessage(), ctx.getStatementSourceReference(), e);
+        }
     }
 
     @Override
     public final void onPreLinkageDeclared(
-            final Mutable<String, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
-        stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.getStatementArgument(),
+            final Mutable<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
+        stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.coerceStatementArgument().getLocalName(),
             StmtContextUtils.getLatestRevision(stmt.declaredSubstatements())));
     }
 
     @Override
-    public final void onLinkageDeclared(final Mutable<String, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
-        final SourceIdentifier submoduleIdentifier = RevisionSourceIdentifier.create(stmt.coerceStatementArgument(),
+    public final void onLinkageDeclared(
+            final Mutable<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
+        final SourceIdentifier submoduleIdentifier = RevisionSourceIdentifier.create(
+            stmt.coerceStatementArgument().getLocalName(),
             StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()));
 
         final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>
             possibleDuplicateSubmodule = stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
         if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
             throw new SourceException(stmt.getStatementSourceReference(), "Submodule name collision: %s. At %s",
-                    stmt.getStatementArgument(), possibleDuplicateSubmodule.getStatementSourceReference());
+                    stmt.rawStatementArgument(), possibleDuplicateSubmodule.getStatementSourceReference());
         }
 
         stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
@@ -64,34 +71,34 @@ abstract class AbstractSubmoduleStatementSupport
         final StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(stmt, 0,
                 BelongsToStatement.class, PrefixStatement.class);
         SourceException.throwIfNull(prefixSubStmtCtx, stmt.getStatementSourceReference(),
-                "Prefix of belongsTo statement is missing in submodule [%s]", stmt.getStatementArgument());
-
-        final String prefix = (String) prefixSubStmtCtx.getStatementArgument();
+                "Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawStatementArgument());
 
+        final String prefix = prefixSubStmtCtx.rawStatementArgument();
         stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
     }
 
     @Override
-    protected final SubmoduleStatement createDeclared(final StmtContext<String, SubmoduleStatement, ?> ctx,
+    protected final SubmoduleStatement createDeclared(final StmtContext<UnqualifiedQName, SubmoduleStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new SubmoduleStatementImpl(ctx.coerceRawStatementArgument(), substatements);
+        return new SubmoduleStatementImpl(ctx, substatements);
     }
 
     @Override
-    protected final SubmoduleStatement createEmptyDeclared(final StmtContext<String, SubmoduleStatement, ?> ctx) {
+    protected final SubmoduleStatement createEmptyDeclared(
+            final StmtContext<UnqualifiedQName, SubmoduleStatement, ?> ctx) {
         throw noBelongsTo(ctx);
     }
 
     @Override
     protected final SubmoduleEffectiveStatement createEffective(
-            final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+            final StmtContext<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
             final SubmoduleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         return new SubmoduleEffectiveStatementImpl(ctx, declared, substatements);
     }
 
     @Override
     protected final SubmoduleEffectiveStatement createEmptyEffective(
-            final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+            final StmtContext<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
             final SubmoduleStatement declared) {
         throw noBelongsTo(ctx);
     }
index 14b8d3b83c2f4201cb7a2d597b645fd1b194187f..d66c6cd25eca3f429fd5c094d15428561932a57a 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.Submodule;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
@@ -51,11 +52,12 @@ final class SubmoduleEffectiveStatementImpl
     private final ImmutableMap<QNameModule, String> namespaceToPrefix;
     private final QNameModule qnameModule;
 
-    private Set<StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>> submoduleContexts;
+    private Set<StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>> submoduleContexts;
     private ImmutableSet<Submodule> submodules;
     private boolean sealed;
 
-    SubmoduleEffectiveStatementImpl(final StmtContext<String, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
+    SubmoduleEffectiveStatementImpl(
+        final StmtContext<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
             final SubmoduleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         super(declared, ctx, substatements, findSubmodulePrefix(ctx));
 
@@ -85,11 +87,11 @@ final class SubmoduleEffectiveStatementImpl
         final Map<String, StmtContext<?, ?, ?>> includedSubmodulesMap = ctx.getAllFromCurrentStmtCtxNamespace(
             IncludedSubmoduleNameToModuleCtx.class);
         if (includedSubmodulesMap != null) {
-            final Set<StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>>
-                submoduleContextsInit = new HashSet<>();
+            final Set<StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>> submoduleContextsInit =
+                new HashSet<>();
             for (final StmtContext<?, ?, ?> submoduleCtx : includedSubmodulesMap.values()) {
                 submoduleContextsInit.add(
-                    (StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>)submoduleCtx);
+                    (StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>)submoduleCtx);
             }
             submoduleContexts = ImmutableSet.copyOf(submoduleContextsInit);
         } else {
@@ -145,8 +147,8 @@ final class SubmoduleEffectiveStatementImpl
         }
     }
 
-    private static @NonNull String findSubmodulePrefix(final StmtContext<String, ?, ?> ctx) {
-        final String name = ctx.getStatementArgument();
+    private static @NonNull String findSubmodulePrefix(final StmtContext<UnqualifiedQName, ?, ?> ctx) {
+        final String name = ctx.coerceStatementArgument().getLocalName();
         final StmtContext<?, ?, ?> belongsTo = SourceException.throwIfNull(
                 StmtContextUtils.findFirstDeclaredSubstatement(ctx, BelongsToStatement.class),
                 ctx.getStatementSourceReference(), "Unable to find belongs-to statement in submodule %s.", name);
index 4aa5a0ef29b50f2940adfb7bd1a4247665997014..41af2cd5bee4554f4d2f0e6e81220eac08c242e1 100644 (file)
@@ -8,14 +8,16 @@
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule;
 
 import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveRootStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 final class SubmoduleStatementImpl extends AbstractDeclaredEffectiveRootStatement<SubmoduleStatement>
         implements SubmoduleStatement {
-    SubmoduleStatementImpl(final String rawArgument,
+    SubmoduleStatementImpl(final StmtContext<UnqualifiedQName, ?, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        super(rawArgument, substatements);
+        super(ctx, substatements);
     }
 }
index 829377050e4bc94eb15ab0cf16f9d2c2342dd3b2..73e682c9de5305fdcc691de129913ced3f406563 100644 (file)
@@ -338,7 +338,7 @@ public final class UsesStatementSupport
         SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx),
                 refineSubstatementCtx.getStatementSourceReference(),
                 "Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.",
-                refineSubstatementCtx.getRoot().getStatementArgument(),
+                refineSubstatementCtx.getRoot().rawStatementArgument(),
                 refineSubstatementCtx.coerceParentContext().getStatementArgument(),
                 refineSubstatementCtx.getPublicDefinition(), refineTargetNodeCtx.getPublicDefinition());
 
index 5492924a6e9a0a798e73047593d9156446cad306..c1415160a7a808ef7f4bb6c6b46be0b221db2933 100644 (file)
@@ -5,10 +5,11 @@
  * 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.stmt;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -17,7 +18,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public class Bug7954Test {
-
     @Test
     public void testParsingTheSameModuleTwice() throws Exception {
         final File yang = new File(getClass().getResource("/bugs/bug7954/foo.yang").toURI());
@@ -27,8 +27,8 @@ public class Bug7954Test {
             fail("An exception should have been thrown because of adding the same YANG module twice.");
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith("Module namespace collision: foo-ns."));
+            assertThat(cause, instanceOf(SourceException.class));
+            assertThat(cause.getMessage(), startsWith("Module namespace collision: foo-ns."));
         }
     }
 
@@ -42,8 +42,8 @@ public class Bug7954Test {
             fail("An exception should have been thrown because of adding the same YANG submodule twice.");
         } catch (final ReactorException ex) {
             final Throwable cause = ex.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith("Submodule name collision: subbar."));
+            assertThat(cause, instanceOf(SourceException.class));
+            assertThat(cause.getMessage(), startsWith("Submodule name collision: subbar."));
         }
     }
 }
index 574654d0b0993e71713c942ac1a1eedaf66335b5..81263cbbd8cdca236879dae06cb799b5346044bc 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
@@ -22,8 +24,8 @@ public class NameCollisionWithinCaseTest {
             fail("Expected failure due to node name collision");
         } catch (ReactorException e) {
             final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith(
+            assertThat(cause, instanceOf(SourceException.class));
+            assertThat(cause.getMessage(), startsWith(
                 "Cannot add data tree child with name (foo?revision=2018-02-11)bar, a conflicting child already exists "
                         + "[at "));
         }
@@ -36,8 +38,8 @@ public class NameCollisionWithinCaseTest {
             fail("Expected failure due to node name collision");
         } catch (ReactorException e) {
             final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith(
+            assertThat(cause, instanceOf(SourceException.class));
+            assertThat(cause.getMessage(), startsWith(
                 "Cannot add data tree child with name (bar?revision=2018-02-11)bar, a conflicting child already exists "
                         + "[at "));
         }
@@ -50,8 +52,8 @@ public class NameCollisionWithinCaseTest {
             fail("Expected failure due to node name collision");
         } catch (ReactorException e) {
             final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith(
+            assertThat(cause, instanceOf(SourceException.class));
+            assertThat(cause.getMessage(), startsWith(
                 "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));
         }
     }
index 7cc59aca7a0f2b6f09fbfe1b9f44b6215de981fd..49a8ad589eb1520d83246ef23690385f9d62898c 100644 (file)
@@ -34,8 +34,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 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;
@@ -612,18 +610,6 @@ public final class StmtContextUtils {
         return null;
     }
 
-    public static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
-        final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
-        if (qNameModule != null) {
-            // creates SourceIdentifier for a module
-            return RevisionSourceIdentifier.create((String) root.getStatementArgument(), qNameModule.getRevision());
-        }
-
-        // creates SourceIdentifier for a submodule
-        final Optional<Revision> revision = getLatestRevision(root.declaredSubstatements());
-        return RevisionSourceIdentifier.create((String) root.getStatementArgument(), revision);
-    }
-
     public static Optional<Revision> getLatestRevision(final Iterable<? extends StmtContext<?, ?, ?>> subStmts) {
         Revision revision = null;
         for (final StmtContext<?, ?, ?> subStmt : subStmts) {
index a44310202c4530e4f25a6e633a19d9b54fc63449..b0e3764a0bf843eedeece207ea5317f4177b50ca 100644 (file)
@@ -132,7 +132,7 @@ public final class SubstatementValidator {
                 if (ctx.getFromNamespace(ExtensionNamespace.class, key.getStatementName()) == null) {
                     throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
                         "%s is not valid for %s. Error in module %s (%s)", key, currentStatement,
-                        ctx.getRoot().getStatementArgument(),
+                        ctx.getRoot().rawStatementArgument(),
                         ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
                 }
 
@@ -143,7 +143,7 @@ public final class SubstatementValidator {
                 if (cardinality.getMin() > value) {
                     throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
                         "Minimal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
-                        cardinality.getMin(), value, ctx.getRoot().getStatementArgument(),
+                        cardinality.getMin(), value, ctx.getRoot().rawStatementArgument(),
                         ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
                 }
 
@@ -153,7 +153,7 @@ public final class SubstatementValidator {
             if (cardinality.getMax() < value) {
                 throw new InvalidSubstatementException(ctx.getStatementSourceReference(),
                     "Maximal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
-                    cardinality.getMax(), value, ctx.getRoot().getStatementArgument(),
+                    cardinality.getMax(), value, ctx.getRoot().rawStatementArgument(),
                     ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()));
             }
         }
@@ -165,7 +165,7 @@ public final class SubstatementValidator {
 
             throw new MissingSubstatementException(ctx.getStatementSourceReference(),
                 "%s is missing %s. Minimal count is %s. Error in module %s (%s)", currentStatement, e.getKey(),
-                e.getValue().getMin(), root.getStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class,
+                e.getValue().getMin(), root.rawStatementArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class,
                     root));
         }
     }