Rather than having static factory methods, expose FileYinTextSource.
JIRA: YANGTOOLS-1561
Change-Id: I02399316cb1d9f009f299abffbf1c31cf666e418
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.Delegator;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* A {@link YinTextSource} backed by a file.
*/
-final class YinTextFileSource extends YinTextSource implements Delegator<Path> {
- private final @NonNull Path path;
+@NonNullByDefault
+public class FileYinTextSource extends YinTextSource implements Delegator<Path> {
+ private final Path path;
- YinTextFileSource(final @NonNull SourceIdentifier sourceId, final @NonNull Path path) {
+ public FileYinTextSource(final SourceIdentifier sourceId, final Path path) {
super(sourceId);
+ if (!Files.isRegularFile(path)) {
+ throw new IllegalArgumentException("Supplied path " + path + " is not a regular file");
+ }
this.path = requireNonNull(path);
}
+ public FileYinTextSource(final Path path) {
+ // FIXME: do not use toFile() here
+ this(SourceIdentifier.ofYinFileName(path.toFile().getName()), path);
+ }
+
@Override
- public Path getDelegate() {
+ public final Path getDelegate() {
return path;
}
@Override
- public InputStream openStream() throws IOException {
+ public final InputStream openStream() throws IOException {
return Files.newInputStream(path);
}
@Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("path", path);
+ public final @NonNull String symbolicName() {
+ return path.toString();
}
@Override
- public String symbolicName() {
- return path.toString();
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return super.addToStringAttributes(toStringHelper).add("path", path);
}
}
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YinSourceRepresentation;
protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
return toStringHelper.add("identifier", sourceId);
}
-
- public static @NonNull YinTextSource forPath(final Path path) {
- if (Files.isRegularFile(path)) {
- // FIXME: do not use toFile() here
- return new YinTextFileSource(SourceIdentifier.ofYinFileName(path.toFile().getName()), path);
- }
- throw new IllegalArgumentException("Supplied path " + path + " is not a regular file");
- }
}
*/
package org.opendaylight.yangtools.yang.stmt;
-import com.google.common.io.Files;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYinTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.FileYinTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
final var files = new File(resourceDir.toURI()).listFiles(YIN_FILE_FILTER);
final var sources = new StatementStreamSource[files.length];
for (int i = 0; i < files.length; i++) {
- final var file = files[i];
sources[i] = YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- new DelegatedYinTextSource(SourceIdentifier.ofYinFileName(file.getName()),
- Files.asByteSource(file))));
+ new FileYinTextSource(files[i].toPath())));
}
return parseYinSources(config, sources);
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
+import org.opendaylight.yangtools.yang.model.spi.source.FileYinTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
for (File file : new File(resourceDirectory).listFiles()) {
reactor.addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSource.forPath(file.toPath()))));
+ new FileYinTextSource(file.toPath()))));
}
return reactor.buildEffective();