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);
}
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);
}
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;
* 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.
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;
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);
}
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;
* {@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;
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() {
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;
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;
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.
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);
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);
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());
}
}
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);
}
}
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;
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;
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);
}
@Override
- public String argument() {
+ public UnqualifiedQName argument() {
return getDeclared().argument();
}
@Override
public String getName() {
- return argument();
+ return argument().getLocalName();
}
@Override
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) {
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;
@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);
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;
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);
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));
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);
"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()) {
@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);
}
@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)) {
@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);
}
}
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);
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;
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);
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);
}
}
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;
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);
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);
}
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;
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));
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 {
}
}
- 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);
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);
}
}
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());
* 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;
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());
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."));
}
}
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."));
}
}
}
*/
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;
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 "));
}
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 "));
}
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: "));
}
}
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;
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) {
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()));
}
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()));
}
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()));
}
}
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));
}
}