X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frepo%2FSharedSchemaContextFactory.java;h=e9a4fc6d842f55158ae155a19327b69881e30f84;hb=1d4d5d61d5c50661d898b1b184f984d055486fba;hp=b5ee5fd53e8180befef594c9a3897ab4826270d2;hpb=b26aa45184c4a32373de46112c90d7570c092e18;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java index b5ee5fd53e..e9a4fc6d84 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.repo; -import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture; @@ -34,9 +33,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ExecutionException; -import org.antlr.v4.runtime.ParserRuleContext; import org.eclipse.jdt.annotation.NonNull; import org.gaul.modernizer_maven_annotations.SuppressModernizer; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.parser.api.YangParser; import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; @@ -45,10 +44,10 @@ import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory; import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration; import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException; +import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; -import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser.StatementContext; -import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource; +import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource; import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; @@ -81,7 +80,7 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { private @NonNull ListenableFuture createSchemaContext( final Collection requiredSources, final Cache, EffectiveModelContext> cache, - final AsyncFunction, EffectiveModelContext> assembleSources) { + final AsyncFunction, EffectiveModelContext> assembleSources) { // Make sources unique final List uniqueSourceIdentifiers = deDuplicateSources(requiredSources); @@ -92,7 +91,7 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { } // Request all sources be loaded - ListenableFuture> sf = Futures.allAsList(Collections2.transform(uniqueSourceIdentifiers, + ListenableFuture> sf = Futures.allAsList(Collections2.transform(uniqueSourceIdentifiers, this::requestSource)); // Detect mismatch between requested Source IDs and IDs that are extracted from parsed source @@ -132,8 +131,8 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { return rf; } - private ListenableFuture requestSource(final @NonNull SourceIdentifier identifier) { - return repository.getSchemaSource(identifier, ASTSchemaSource.class); + private ListenableFuture requestSource(final @NonNull SourceIdentifier identifier) { + return repository.getSchemaSource(identifier, IRSchemaSource.class); } /** @@ -154,8 +153,8 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { } @SuppressModernizer - private static final class SourceIdMismatchDetector implements Function, - List> { + private static final class SourceIdMismatchDetector implements Function, + List> { private final List sourceIdentifiers; SourceIdMismatchDetector(final List sourceIdentifiers) { @@ -163,14 +162,14 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { } @Override - public List apply(final List input) { - final Map filtered = new LinkedHashMap<>(); + public List apply(final List input) { + final Map filtered = new LinkedHashMap<>(); for (int i = 0; i < input.size(); i++) { final SourceIdentifier expectedSId = sourceIdentifiers.get(i); - final ASTSchemaSource astSchemaSource = input.get(i); - final SourceIdentifier realSId = astSchemaSource.getIdentifier(); + final IRSchemaSource irSchemaSource = input.get(i); + final SourceIdentifier realSId = irSchemaSource.getIdentifier(); if (!expectedSId.equals(realSId)) { LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. " @@ -181,17 +180,17 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { LOG.warn("Duplicate source for module {} detected in reactor", realSId); } - filtered.put(realSId, astSchemaSource); + filtered.put(realSId, irSchemaSource); } return ImmutableList.copyOf(filtered.values()); } } - private static final class AssembleSources implements AsyncFunction, EffectiveModelContext> { + private static final class AssembleSources implements AsyncFunction, EffectiveModelContext> { private final @NonNull YangParserFactory parserFactory; private final @NonNull SchemaContextFactoryConfiguration config; - private final @NonNull Function getIdentifier; + private final @NonNull Function getIdentifier; private AssembleSources(final @NonNull YangParserFactory parserFactory, final @NonNull SchemaContextFactoryConfiguration config) { @@ -199,19 +198,19 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { this.config = config; switch (config.getStatementParserMode()) { case SEMVER_MODE: - this.getIdentifier = ASTSchemaSource::getSemVerIdentifier; + this.getIdentifier = AssembleSources::getSemVerIdentifier; break; default: - this.getIdentifier = ASTSchemaSource::getIdentifier; + this.getIdentifier = IRSchemaSource::getIdentifier; } } @Override - public FluentFuture apply(final List sources) + public FluentFuture apply(final List sources) throws SchemaResolutionException, ReactorException { - final Map srcs = Maps.uniqueIndex(sources, getIdentifier); + final Map srcs = Maps.uniqueIndex(sources, getIdentifier); final Map deps = - Maps.transformValues(srcs, ASTSchemaSource::getDependencyInformation); + Maps.transformValues(srcs, YangModelDependencyInfo::forIR); LOG.debug("Resolving dependency reactor {}", deps); @@ -229,12 +228,7 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { config.getSupportedFeatures().ifPresent(parser::setSupportedFeatures); config.getModulesDeviatedByModules().ifPresent(parser::setModulesWithSupportedDeviations); - for (final Entry entry : srcs.entrySet()) { - final ASTSchemaSource ast = entry.getValue(); - final ParserRuleContext parserRuleCtx = ast.getAST(); - checkArgument(parserRuleCtx instanceof StatementContext, "Unsupported context class %s for source %s", - parserRuleCtx.getClass(), entry.getKey()); - + for (final Entry entry : srcs.entrySet()) { try { parser.addSource(entry.getValue()); } catch (YangSyntaxErrorException | IOException e) { @@ -251,5 +245,15 @@ final class SharedSchemaContextFactory implements EffectiveModelContextFactory { return immediateFluentFuture(schemaContext); } + + 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); + } } }