import java.io.IOException;
import java.io.InputStream;
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;
-final class DelegatedYinTextSource extends YinTextSource implements Delegator<ByteSource> {
- private final @NonNull ByteSource delegate;
-
- DelegatedYinTextSource(final SourceIdentifier sourceId, final ByteSource delegate) {
+/**
+ * A {@link YangTextSource} delegating to a {@link ByteSource}.
+ */
+@NonNullByDefault
+public class DelegatedYinTextSource extends YinTextSource implements Delegator<ByteSource> {
+ private final ByteSource delegate;
+
+ /**
+ * Default constructor.
+ *
+ * @param sourceId {@link SourceIdentifier} of the resulting schema source
+ * @param delegate backing {@link ByteSource} instance
+ */
+ public DelegatedYinTextSource(final SourceIdentifier sourceId, final ByteSource delegate) {
super(sourceId);
this.delegate = requireNonNull(delegate);
}
@Override
- public ByteSource getDelegate() {
+ public final ByteSource getDelegate() {
return delegate;
}
@Override
- public InputStream openStream() throws IOException {
+ public final InputStream openStream() throws IOException {
return delegate.openStream();
}
@Override
- public String symbolicName() {
+ public final @NonNull String symbolicName() {
return "[" + delegate.toString() + "]";
}
return toStringHelper.add("identifier", sourceId);
}
- /**
- * Create a new YinTextSchemaSource with a specific source identifier and backed
- * by ByteSource, which provides the actual InputStreams.
- *
- * @param identifier SourceIdentifier of the resulting schema source
- * @param delegate Backing ByteSource instance
- * @return A new YinTextSchemaSource
- */
- public static @NonNull YinTextSource delegateForByteSource(final SourceIdentifier identifier,
- final ByteSource delegate) {
- return new DelegatedYinTextSource(identifier, delegate);
- }
-
public static @NonNull YinTextSource forPath(final Path path) {
if (Files.isRegularFile(path)) {
// FIXME: do not use toFile() here
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.YangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
for (int i = 0; i < files.length; i++) {
final var file = files[i];
sources[i] = YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSource.delegateForByteSource(SourceIdentifier.ofYinFileName(file.getName()),
+ new DelegatedYinTextSource(SourceIdentifier.ofYinFileName(file.getName()),
Files.asByteSource(file))));
}