Search in sources :

Example 1 with SemVerSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.

the class SemanticVersionImport method onLinkageDeclared.

static void onLinkageDeclared(final Mutable<String, ImportStatement, ImportEffectiveStatement> stmt) {
    final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
    final String moduleName = stmt.getArgument();
    final SemVer semanticVersion = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt);
    final SemanticVersionImport.CompatibleCriterion criterion = semanticVersion == null ? new NoVerCompatibleCriterion(moduleName) : new SemVerCompatibleCriterion(moduleName, semanticVersion);
    final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt, SemanticVersionModuleNamespace.class, criterion, SOURCE_LINKAGE);
    final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
    importAction.apply(new InferenceAction() {

        @Override
        public void apply(final InferenceContext ctx) {
            final StmtContext<?, ?, ?> importedModule = imported.resolve(ctx);
            final SemVer importedVersion = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt);
            final SourceIdentifier importedModuleIdentifier = importedModule.getFromNamespace(ModuleCtxToSourceIdentifier.class, importedModule);
            final SemVerSourceIdentifier semVerModuleIdentifier = createSemVerModuleIdentifier(importedModuleIdentifier, importedVersion);
            stmt.addToNs(ImportedVersionNamespace.class, Empty.value(), semVerModuleIdentifier);
            linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
            final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
            stmt.addToNs(ImportPrefixToModuleCtx.class, impPrefix, importedModule);
            stmt.addToNs(ImportPrefixToSemVerSourceIdentifier.class, impPrefix, semVerModuleIdentifier);
            final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(ModuleCtxToModuleQName.class, importedModule), stmt, "Failed to find module of %s", importedModule);
            stmt.addToNs(ModuleQNameToPrefix.class, mod, impPrefix);
        }

        @Override
        public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
            if (failed.contains(imported)) {
                throw new InferenceException(stmt, "Unable to find module compatible with requested import [%s(%s)].", moduleName, getRequestedImportVersionString(stmt));
            }
        }
    });
}
Also used : SemVer(org.opendaylight.yangtools.concepts.SemVer) InferenceAction(org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction) ImportPrefixToSemVerSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) ModuleCtxToSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) ImportPrefixToModuleCtx(org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx) ImportedModuleContext(org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext) InferenceContext(org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext) ImportPrefixToSemVerSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) ModuleCtxToSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) InferenceException(org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException) StmtContext(org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext) PrefixStatement(org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement) Mutable(org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable) SemanticVersionNamespace(org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace) ImportPrefixToSemVerSourceIdentifier(org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier) ModuleQNameToPrefix(org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix) ModelActionBuilder(org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder)

Example 2 with SemVerSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.

the class ModuleStatementSupport method addToSemVerModuleNamespace.

private static void addToSemVerModuleNamespace(final Mutable<Unqualified, ModuleStatement, ModuleEffectiveStatement> stmt, final SourceIdentifier moduleIdentifier) {
    final SemVerSourceIdentifier id = SemVerSourceIdentifier.create(stmt.getRawArgument(), stmt.getFromNamespace(SemanticVersionNamespace.class, stmt));
    stmt.addToNs(SemanticVersionModuleNamespace.class, id, stmt);
}
Also used : SemanticVersionNamespace(org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier)

Example 3 with SemVerSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.

the class AssembleSources method getSemVerIdentifier.

private static SemVerSourceIdentifier getSemVerIdentifier(final IRSchemaSource source) {
    final SourceIdentifier identifier = source.getIdentifier();
    final SemVer semver = YangModelDependencyInfo.findSemanticVersion(source.getRootStatement(), identifier);
    if (identifier instanceof SemVerSourceIdentifier && semver == null) {
        return (SemVerSourceIdentifier) identifier;
    }
    return SemVerSourceIdentifier.create(identifier.getName(), identifier.getRevision(), semver);
}
Also used : SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) SemVer(org.opendaylight.yangtools.concepts.SemVer)

Aggregations

SemVerSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier)3 SemVer (org.opendaylight.yangtools.concepts.SemVer)2 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)2 SemanticVersionNamespace (org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 PrefixStatement (org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement)1 ModuleQNameToPrefix (org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix)1 InferenceException (org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException)1 ModelActionBuilder (org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder)1 InferenceAction (org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction)1 InferenceContext (org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext)1 StmtContext (org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext)1 Mutable (org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable)1 ImportPrefixToModuleCtx (org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx)1 ImportPrefixToSemVerSourceIdentifier (org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier)1 ImportedModuleContext (org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext)1 ModuleCtxToSourceIdentifier (org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier)1