Search in sources :

Example 1 with YangModelDependencyInfo

use of org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo in project yangtools by opendaylight.

the class YangModelDependencyInfo method forIR.

/**
 * Extracts {@link YangModelDependencyInfo} from an intermediate representation root statement of a YANG model.
 *
 * @param source Source identifier
 * @param rootStatement root statement
 * @return {@link YangModelDependencyInfo}
 * @throws IllegalArgumentException If the root statement is not a valid YANG module/submodule
 */
@NonNull
static YangModelDependencyInfo forIR(final IRStatement rootStatement, final SourceIdentifier source) {
    final IRKeyword keyword = rootStatement.keyword();
    checkArgument(keyword instanceof Unqualified, "Invalid root statement %s", keyword);
    final String arg = keyword.identifier();
    if (MODULE.equals(arg)) {
        return parseModuleContext(rootStatement, source);
    }
    if (SUBMODULE.equals(arg)) {
        return parseSubmoduleContext(rootStatement, source);
    }
    throw new IllegalArgumentException("Root of parsed AST must be either module or submodule");
}
Also used : IRKeyword(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword) Unqualified(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with YangModelDependencyInfo

use of org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo in project yangtools by opendaylight.

the class AssembleSources method apply.

@Override
public FluentFuture<EffectiveModelContext> apply(final List<IRSchemaSource> sources) throws SchemaResolutionException, ReactorException {
    final Map<SourceIdentifier, IRSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
    final Map<SourceIdentifier, YangModelDependencyInfo> deps = Maps.transformValues(srcs, YangModelDependencyInfo::forIR);
    LOG.debug("Resolving dependency reactor {}", deps);
    final StatementParserMode statementParserMode = config.getStatementParserMode();
    final DependencyResolver res = statementParserMode == StatementParserMode.SEMVER_MODE ? SemVerDependencyResolver.create(deps) : RevisionDependencyResolver.create(deps);
    if (!res.getUnresolvedSources().isEmpty()) {
        LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(), res.getUnsatisfiedImports());
        throw new SchemaResolutionException("Failed to resolve required models", res.getResolvedSources(), res.getUnsatisfiedImports());
    }
    final YangParser parser = parserFactory.createParser(res.parserConfig());
    config.getSupportedFeatures().ifPresent(parser::setSupportedFeatures);
    config.getModulesDeviatedByModules().ifPresent(parser::setModulesWithSupportedDeviations);
    for (final Entry<SourceIdentifier, IRSchemaSource> entry : srcs.entrySet()) {
        try {
            parser.addSource(entry.getValue());
        } catch (YangSyntaxErrorException | IOException e) {
            throw new SchemaResolutionException("Failed to add source " + entry.getKey(), e);
        }
    }
    final EffectiveModelContext schemaContext;
    try {
        schemaContext = parser.buildEffectiveModel();
    } catch (final YangParserException e) {
        throw new SchemaResolutionException("Failed to resolve required models", e);
    }
    return immediateFluentFuture(schemaContext);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) YangParser(org.opendaylight.yangtools.yang.parser.api.YangParser) IOException(java.io.IOException) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException) YangModelDependencyInfo(org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo) SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) YangSyntaxErrorException(org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException) StatementParserMode(org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

IOException (java.io.IOException)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 SchemaResolutionException (org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException)1 SemVerSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 StatementParserMode (org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode)1 YangParser (org.opendaylight.yangtools.yang.parser.api.YangParser)1 YangParserException (org.opendaylight.yangtools.yang.parser.api.YangParserException)1 YangSyntaxErrorException (org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException)1 IRKeyword (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword)1 Unqualified (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified)1 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)1 YangModelDependencyInfo (org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo)1