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");
}
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);
}
Aggregations