Seal SchemaSourceRepresentation hierarchy 90/102690/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 14 Oct 2022 12:00:25 +0000 (14:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 14 Oct 2022 12:21:20 +0000 (14:21 +0200)
There are really only two basic SchemaSourceRepresentations: either YIN
or YANG. Make sure we express that through sealing interfaces. This
exposes the fact IRSchemaSource is a YangSchemaSourceRepresentation.

Change-Id: Ic0e073deefeef541ff4461c17e1dacffe4324da4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/ir/IRSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaSourceRepresentation.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangSchemaSourceRepresentation.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinSchemaSourceRepresentation.java
yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java
yang/yang-repo-spi/src/test/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSourceTest.java

index 8a1257f665fc119c193530acf4aa28e6704f284a..4c00254884dcdacc8feab642a4ca9d0f782dc04b 100644 (file)
@@ -15,13 +15,13 @@ import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRKeyword.Unqualified;
 
 @Beta
 public final class IRSchemaSource extends AbstractSimpleIdentifiable<SourceIdentifier>
-        implements SchemaSourceRepresentation {
+        implements YangSchemaSourceRepresentation {
     private final @NonNull IRStatement rootStatement;
     private final @Nullable String symbolicName;
 
index 972c26f6cb96a349991bd3d140f3555720a6e942..7b923dc7fe6e6bf992f81d8e0c736bd719de4c38 100644 (file)
@@ -37,7 +37,8 @@ import org.opendaylight.yangtools.concepts.Immutable;
  * Implementations of this interface expected to comply with the {@link Immutable} contract.
  */
 @Beta
-public interface SchemaSourceRepresentation extends Identifiable<SourceIdentifier>, Immutable {
+public sealed interface SchemaSourceRepresentation extends Identifiable<SourceIdentifier>, Immutable
+        permits YangSchemaSourceRepresentation, YinSchemaSourceRepresentation {
     @Override
     SourceIdentifier getIdentifier();
 
index d927c8ce030e8f396d077f4c923d170a7d3dd115..a33a83abcb9beea29850af0371dec4ac441b6e86 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.model.repo.api;
 /**
  * A YANG {@link SchemaSourceRepresentation}.
  */
-public interface YangSchemaSourceRepresentation extends SchemaSourceRepresentation {
+public non-sealed interface YangSchemaSourceRepresentation extends SchemaSourceRepresentation {
     @Override
     Class<? extends YangSchemaSourceRepresentation> getType();
 }
index 8cd7de30be4b7f00b918948c5f51c782add7c379..907450dbaebd0101c2294097ec48c7a8b2f73974 100644 (file)
@@ -144,7 +144,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
     }
 
     @Override
-    public Class<? extends YangTextSchemaSource> getType() {
+    public final Class<YangTextSchemaSource> getType() {
         return YangTextSchemaSource.class;
     }
 
index 67a69c2bef9170a71fb6d55daa01c4688e2117bf..07927943273362abf753809b17f9ad6c6801672c 100644 (file)
@@ -133,7 +133,7 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource {
     public abstract DOMSource getSource();
 
     @Override
-    public final Class<? extends YinXmlSchemaSource> getType() {
+    public final Class<YinDomSchemaSource> getType() {
         return YinDomSchemaSource.class;
     }
 
index 5b2d6ced914e70f0a2698f2cfc92fe8a531d4b09..639b3099717e1111b91011aa418f6add9f2e4904 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.model.repo.api;
 /**
  * A YIN {@link SchemaSourceRepresentation}.
  */
-public interface YinSchemaSourceRepresentation extends SchemaSourceRepresentation {
+public non-sealed interface YinSchemaSourceRepresentation extends SchemaSourceRepresentation {
     @Override
     Class<? extends YinSchemaSourceRepresentation> getType();
 }
index e65d828bb7e5bb851388183450fbf133d406f482..27db51f28c7253969a19d18f05826cc66679d83b 100644 (file)
@@ -60,7 +60,7 @@ public abstract class YinTextSchemaSource extends ByteSource implements YinSchem
     }
 
     @Override
-    public Class<? extends YinTextSchemaSource> getType() {
+    public final Class<YinTextSchemaSource> getType() {
         return YinTextSchemaSource.class;
     }
 
index 89a7d1f1478b00b9288265556122c3ed0ce27a25..10d28f1fb459fcc5c3c1a5aca40c2801151589de 100644 (file)
@@ -17,13 +17,16 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class PotentialSchemaSourceTest {
-    private interface TestSchemaSourceRepresentation extends SchemaSourceRepresentation {
-
+    private interface TestSchemaSourceRepresentation extends YangSchemaSourceRepresentation {
+        @Override
+        default Class<TestSchemaSourceRepresentation> getType() {
+            return TestSchemaSourceRepresentation.class;
+        }
     }
 
     public final SourceIdentifier sourceIdentifier = new SourceIdentifier("foo");