YangIRSource is a more concise name. Also add a bit of documentation.
Change-Id: I259c41c2defd0418854e8766f730dda83e3cb4cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.ir.IRKeyword.Unqualified;
import org.opendaylight.yangtools.yang.ir.IRStatement;
import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
import org.opendaylight.yangtools.yang.model.spi.meta.StatementDeclarations;
-public final class YangIRSchemaSource implements YangSourceRepresentation {
- private final @NonNull SourceIdentifier sourceId;
- private final @NonNull IRStatement rootStatement;
+/**
+ * A {@link YangSourceRepresentation} backed by an {@link IRStatement}.
+ */
+@NonNullByDefault
+public final class YangIRSource implements YangSourceRepresentation {
+ private final SourceIdentifier sourceId;
+ private final IRStatement statement;
private final @Nullable String symbolicName;
- public YangIRSchemaSource(final @NonNull SourceIdentifier sourceId, final @NonNull IRStatement rootStatement,
+ public YangIRSource(final SourceIdentifier sourceId, final IRStatement statement,
final @Nullable String symbolicName) {
- final var rootKeyword = rootStatement.keyword();
+ final var rootKeyword = statement.keyword();
if (!(rootKeyword instanceof Unqualified)) {
- throw new StatementSourceException(refOf(sourceId, rootStatement),
+ throw new StatementSourceException(refOf(sourceId, statement),
"Root statement has invalid keyword " + rootKeyword);
}
final var rootName = rootKeyword.identifier();
case "submodule":
break;
default:
- throw new StatementSourceException(refOf(sourceId, rootStatement),
+ throw new StatementSourceException(refOf(sourceId, statement),
"Invalid root statement keyword " + rootName);
}
- if (rootStatement.argument() == null) {
- throw new StatementSourceException(refOf(sourceId, rootStatement),
- "Root statement does not have an argument");
+ if (statement.argument() == null) {
+ throw new StatementSourceException(refOf(sourceId, statement), "Root statement does not have an argument");
}
this.sourceId = requireNonNull(sourceId);
- this.rootStatement = rootStatement;
+ this.statement = statement;
this.symbolicName = symbolicName;
}
}
@Override
- public String symbolicName() {
+ public @Nullable String symbolicName() {
return symbolicName;
}
@Override
- public Class<YangIRSchemaSource> getType() {
- return YangIRSchemaSource.class;
+ public Class<YangIRSource> getType() {
+ return YangIRSource.class;
}
/**
*
* @return Root statement.
*/
- public @NonNull IRStatement rootStatement() {
- return rootStatement;
+ public IRStatement statement() {
+ return statement;
}
// FIXME: hide this method
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.model.spi.source.YinDomSource;
import org.opendaylight.yangtools.yang.model.spi.source.YinXmlSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
final class DefaultYangParser implements YangParser {
static final @NonNull ImmutableSet<Class<? extends SourceRepresentation>> REPRESENTATIONS = ImmutableSet.of(
// In order of preference
- YangIRSchemaSource.class,
+ YangIRSource.class,
YangTextSource.class,
YinDomSource.class,
YinXmlSource.class,
static StatementStreamSource sourceToStatementStream(final SourceRepresentation source)
throws IOException, YangSyntaxErrorException {
requireNonNull(source);
- if (source instanceof YangIRSchemaSource irSource) {
+ if (source instanceof YangIRSource irSource) {
return YangStatementStreamSource.create(irSource);
} else if (source instanceof YangTextSource yangSource) {
return YangStatementStreamSource.create(yangSource);
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class AssembleSources implements AsyncFunction<List<YangIRSchemaSource>, EffectiveModelContext> {
+final class AssembleSources implements AsyncFunction<List<YangIRSource>, EffectiveModelContext> {
private static final Logger LOG = LoggerFactory.getLogger(AssembleSources.class);
- private final @NonNull Function<YangIRSchemaSource, SourceIdentifier> getIdentifier;
+ private final @NonNull Function<YangIRSource, SourceIdentifier> getIdentifier;
private final @NonNull SchemaContextFactoryConfiguration config;
private final @NonNull YangParserFactory parserFactory;
this.parserFactory = parserFactory;
this.config = config;
getIdentifier = switch (config.getStatementParserMode()) {
- case DEFAULT_MODE -> YangIRSchemaSource::sourceId;
+ case DEFAULT_MODE -> YangIRSource::sourceId;
};
}
@Override
- public FluentFuture<EffectiveModelContext> apply(final List<YangIRSchemaSource> sources) {
+ public FluentFuture<EffectiveModelContext> apply(final List<YangIRSource> sources) {
final var srcs = Maps.uniqueIndex(sources, getIdentifier);
final var deps = Maps.transformValues(srcs, YangIRSourceInfoExtractor::forIR);
LOG.debug("Resolving dependency reactor {}", deps);
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.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Stopwatch sw = Stopwatch.createStarted();
// Request all sources be loaded
- ListenableFuture<List<YangIRSchemaSource>> sf = Futures.allAsList(Collections2.transform(sources,
- identifier -> repository.getSchemaSource(identifier, YangIRSchemaSource.class)));
+ ListenableFuture<List<YangIRSource>> sf = Futures.allAsList(Collections2.transform(sources,
+ identifier -> repository.getSchemaSource(identifier, YangIRSource.class)));
// Detect mismatch between requested Source IDs and IDs that are extracted from parsed source
// Also remove duplicates if present
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressModernizer
-final class SourceIdMismatchDetector implements Function<List<YangIRSchemaSource>, List<YangIRSchemaSource>> {
+final class SourceIdMismatchDetector implements Function<List<YangIRSource>, List<YangIRSource>> {
private static final Logger LOG = LoggerFactory.getLogger(SourceIdMismatchDetector.class);
private final Set<SourceIdentifier> sourceIdentifiers;
}
@Override
- public List<YangIRSchemaSource> apply(final List<YangIRSchemaSource> input) {
- final Iterator<SourceIdentifier> srcIt = sourceIdentifiers.iterator();
- final Map<SourceIdentifier, YangIRSchemaSource> filtered = new LinkedHashMap<>();
- for (YangIRSchemaSource irSchemaSource : input) {
+ public List<YangIRSource> apply(final List<YangIRSource> input) {
+ final var srcIt = sourceIdentifiers.iterator();
+ final var filtered = new LinkedHashMap<SourceIdentifier, YangIRSource>();
+ for (var irSchemaSource : input) {
final SourceIdentifier realSId = irSchemaSource.sourceId();
if (srcIt.hasNext()) {
final SourceIdentifier expectedSId = srcIt.next();
}
}
- final YangIRSchemaSource prev = filtered.put(realSId, irSchemaSource);
+ final var prev = filtered.put(realSId, irSchemaSource);
if (prev != null) {
LOG.warn("Duplicate source for module {} detected in reactor", realSId);
}
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
private final Map<QNameModule, List<ImmutableSet<String>>> registeredFeatures = new HashMap<>();
private final AtomicReference<Optional<EffectiveModelContext>> currentSchemaContext =
new AtomicReference<>(Optional.empty());
- private final GuavaSchemaSourceCache<YangIRSchemaSource> cache;
+ private final GuavaSchemaSourceCache<YangIRSource> cache;
private final SchemaSourceRegistry registry;
private final SchemaRepository repository;
private final Registration transReg;
this.registry = requireNonNull(registry);
transReg = registry.registerSchemaSourceListener(TextToIRTransformer.create(repository, registry));
- cache = GuavaSchemaSourceCache.createSoftCache(registry, YangIRSchemaSource.class, SOURCE_LIFETIME);
+ cache = GuavaSchemaSourceCache.createSoftCache(registry, YangIRSource.class, SOURCE_LIFETIME);
}
public static @NonNull YangTextSchemaContextResolver create(final String name) {
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
.createEffectiveModelContext(requiredSources);
}
- static final SettableSchemaProvider<YangIRSchemaSource> assertYangTextResource(final String resourceName) {
- final YangIRSchemaSource yangSource;
+ static final SettableSchemaProvider<YangIRSource> assertYangTextResource(final String resourceName) {
+ final YangIRSource yangSource;
try {
yangSource = TextToIRTransformer.transformText(
new URLYangTextSource(AbstractSchemaRepositoryTest.class.getResource(resourceName)));
} catch (YangSyntaxErrorException | IOException e) {
throw new AssertionError("Failed to parse " + resourceName, e);
}
- return SettableSchemaProvider.createImmediate(yangSource, YangIRSchemaSource.class);
+ return SettableSchemaProvider.createImmediate(yangSource, YangIRSource.class);
}
static final void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
class MultipleRevImportBug6875Test extends AbstractSchemaRepositoryTest {
private static final String BAR_NS = "bar";
}
private static void setAndRegister(final SharedSchemaRepository sharedSchemaRepository,
- final SettableSchemaProvider<YangIRSchemaSource> source) {
+ final SettableSchemaProvider<YangIRSource> source) {
source.register(sharedSchemaRepository);
source.setResult();
}
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
class SharedEffectiveModelContextFactoryTest {
// Register the same provider under source id without revision
final var sIdWithoutRevision = new SourceIdentifier(provider.getId().name());
repository.registerSchemaSource(provider, PotentialSchemaSource.create(sIdWithoutRevision,
- YangIRSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
+ YangIRSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
final var schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
class SharedSchemaRepositoryTest extends AbstractSchemaRepositoryTest {
final var idNoRevision = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported.yang");
final var id2 = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported@2012-12-12.yang");
- var source = sharedSchemaRepository.getSchemaSource(idNoRevision, YangIRSchemaSource.class);
+ var source = sharedSchemaRepository.getSchemaSource(idNoRevision, YangIRSource.class);
assertEquals(idNoRevision, source.get().sourceId());
- source = sharedSchemaRepository.getSchemaSource(id2, YangIRSchemaSource.class);
+ source = sharedSchemaRepository.getSchemaSource(id2, YangIRSource.class);
assertEquals(id2, source.get().sourceId());
}
final var remoteInetTypesYang = assertYangTextResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
final var registeredSourceFuture = sharedSchemaRepository.getSchemaSource(
- remoteInetTypesYang.getId(), YangIRSchemaSource.class);
+ remoteInetTypesYang.getId(), YangIRSource.class);
assertFalse(registeredSourceFuture.isDone());
final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
verify(immediateInetTypesYang).getSource(id);
}
- static SettableSchemaProvider<YangIRSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName)
+ static SettableSchemaProvider<YangIRSource> getRemoteYangSourceProviderFromResource(final String resourceName)
throws Exception {
return SettableSchemaProvider.createRemote(TextToIRTransformer.transformText(
new URLYangTextSource(SharedSchemaRepositoryTest.class.getResource(resourceName))),
- YangIRSchemaSource.class);
+ YangIRSource.class);
}
}
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceTransformer;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.antlr.IRSupport;
@Beta
-public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSource, YangIRSchemaSource> {
+public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSource, YangIRSource> {
private TextToIRTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
- super(provider, YangTextSource.class, consumer, YangIRSchemaSource.class,
+ super(provider, YangTextSource.class, consumer, YangIRSource.class,
input -> Futures.immediateFuture(transformText(input)));
}
return new TextToIRTransformer(provider, consumer);
}
- public static @NonNull YangIRSchemaSource transformText(final YangTextSource text)
+ public static @NonNull YangIRSource transformText(final YangTextSource text)
throws YangSyntaxErrorException, IOException {
final var rootStatement = IRSupport.createStatement(YangStatementStreamSource.parseYangSource(text));
final var info = YangIRSourceInfoExtractor.forIR(rootStatement, text.sourceId());
- return new YangIRSchemaSource(info.sourceId(), rootStatement, text.symbolicName());
+ return new YangIRSource(info.sourceId(), rootStatement, text.symbolicName());
}
}
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.spi.meta.StatementDeclarations;
import org.opendaylight.yangtools.yang.model.spi.source.SourceInfo;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
/**
- * Utility class for extract {@link SourceInfo} from a {@link YangIRSchemaSource}.
+ * Utility class for extract {@link SourceInfo} from a {@link YangIRSource}.
*/
public final class YangIRSourceInfoExtractor {
private static final String BELONGS_TO = YangStmtMapping.BELONGS_TO.getStatementName().getLocalName();
* @return {@link SourceInfo}
* @throws IllegalArgumentException If the root statement is not a valid YANG module/submodule
*/
- public static @NonNull SourceInfo forIR(final YangIRSchemaSource source) {
- return forIR(source.rootStatement(), source.sourceId());
+ public static @NonNull SourceInfo forIR(final YangIRSource source) {
+ return forIR(source.statement(), source.sourceId());
}
/**
import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementLexer;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser.FileContext;
/**
* This class represents implementation of StatementStreamSource in order to emit YANG statements using supplied
* StatementWriter.
- *
- * @author Robert Varga
*/
@Beta
public final class YangStatementStreamSource extends AbstractSimpleIdentifiable<SourceIdentifier>
}
/**
- * Create a {@link YangStatementStreamSource} for a {@link YangIRSchemaSource}.
+ * Create a {@link YangStatementStreamSource} for a {@link YangIRSource}.
*
* @param source YangTextSchemaSource, must not be null
* @return A new {@link YangStatementStreamSource}
* @throws NullPointerException if {@code source} is null
*/
- public static YangStatementStreamSource create(final YangIRSchemaSource source) {
- return create(source.sourceId(), source.rootStatement(), source.symbolicName());
+ public static YangStatementStreamSource create(final YangIRSource source) {
+ return create(source.sourceId(), source.statement(), source.symbolicName());
}
public static YangStatementStreamSource create(final SourceIdentifier identifier, final IRStatement rootStatement,
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.ir.IOSupport;
import org.opendaylight.yangtools.yang.ir.IRStatement;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
class IOSupportTest {
- private static YangIRSchemaSource FOO;
+ private static YangIRSource FOO;
@BeforeAll
static void beforeClass() throws Exception {
@Test
void testSerializedSize() throws IOException {
- final byte[] bytes = serialize(FOO.rootStatement());
+ final byte[] bytes = serialize(FOO.statement());
assertEquals(485, bytes.length);
}
@Test
void testSerdes() throws IOException {
- final var orig = FOO.rootStatement();
+ final var orig = FOO.statement();
assertEquals(orig, deserialize(serialize(orig)));
}
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
@SuppressWarnings("checkstyle:illegalCatch")
private @NonNull ProcessorModuleReactor createReactor(final List<File> yangFilesInProject,
final YangParserConfiguration parserConfig, final Collection<ScannedDependency> dependencies,
- final List<Entry<FileYangTextSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
+ final List<Entry<FileYangTextSource, YangIRSource>> parsed) throws MojoExecutionException {
try {
final var sourcesInProject = new ArrayList<YangTextSource>(yangFilesInProject.size());