Expose DelegatedYinTextSource 59/109659/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 14:37:23 +0000 (15:37 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 15:22:23 +0000 (16:22 +0100)
Eliminate YinTextSource static methods in favor of making
DelegatedYinTextSource visible.

JIRA: YANGTOOLS-1561
Change-Id: I77b5223facb3de7ed216fd556ae0bd9d95fb6927
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/DelegatedYinTextSource.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/YinTextSource.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java

index d008458088d331af4ef3ccc4e157c7c5c3d24499..5a96bba5e64c3c0ed2f614278b49c44a3f6d010b 100644 (file)
@@ -14,29 +14,40 @@ import com.google.common.io.ByteSource;
 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() + "]";
     }
 
index f84f1950a484b935ffd82817bfc221da0329482a..24f6a248c529ebe4909446a20304e407907c2793 100644 (file)
@@ -58,19 +58,6 @@ public abstract class YinTextSource extends ByteSource implements YinSourceRepre
         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
index e760938fcafd02bc4eb0d86b297ede44802e9614..d5b05155a2676a2a3277c46ea72c161e1fa68ed8 100644 (file)
@@ -26,8 +26,8 @@ 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.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;
@@ -153,7 +153,7 @@ public final class StmtTestUtils {
         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))));
         }