+ return ImmutableList.copyOf(filtered.values());
+ }
+ }
+
+ private static final class AssembleSources implements AsyncFunction<List<ASTSchemaSource>, SchemaContext> {
+
+ private final java.util.function.Predicate<QName> isFeatureSupported;
+ private final StatementParserMode statementParserMode;
+ private final Function<ASTSchemaSource, SourceIdentifier> getIdentifier;
+
+ private AssembleSources(final java.util.function.Predicate<QName> isFeatureSupported,
+ final StatementParserMode statementParserMode) {
+ this.isFeatureSupported = Preconditions.checkNotNull(isFeatureSupported);
+ this.statementParserMode = Preconditions.checkNotNull(statementParserMode);
+ switch (statementParserMode) {
+ case SEMVER_MODE:
+ this.getIdentifier = ASTSchemaSource.GET_SEMVER_IDENTIFIER;
+ break;
+ default:
+ this.getIdentifier = ASTSchemaSource.GET_IDENTIFIER;
+ }
+ }
+
+ @Override
+ public ListenableFuture<SchemaContext> apply(final List<ASTSchemaSource> sources) throws SchemaResolutionException,
+ SourceException, ReactorException {
+ final Map<SourceIdentifier, ASTSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
+ final Map<SourceIdentifier, YangModelDependencyInfo> deps =
+ Maps.transformValues(srcs, ASTSchemaSource.GET_DEPINFO);
+
+ LOG.debug("Resolving dependency reactor {}", deps);
+
+ final DependencyResolver res = this.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 Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource.GET_AST);
+ final CrossSourceStatementReactor.BuildAction reactor =
+ YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, isFeatureSupported);
+
+ for (final Entry<SourceIdentifier, ParserRuleContext> e : asts.entrySet()) {
+ final ParserRuleContext parserRuleCtx = e.getValue();
+ Preconditions.checkArgument(parserRuleCtx instanceof StatementContext,
+ "Unsupported context class %s for source %s", parserRuleCtx.getClass(), e.getKey());
+
+ reactor.addSource(new YangStatementSourceImpl(e.getKey(), (StatementContext) parserRuleCtx));
+ }
+
+ final SchemaContext schemaContext = reactor.buildEffective();
+
+ return Futures.immediateCheckedFuture(schemaContext);