Use case arrows in mergeIntoModifiedNode()
[yangtools.git] / parser / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / DefaultYangParser.java
index b90eab781d628847b24f88d8b1355a40e65f5bfc..a1e1aaade3bfd7b82de5f12ea13d32c50975c1d8 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
 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;
@@ -39,7 +39,7 @@ import org.xml.sax.SAXException;
 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,
@@ -106,28 +106,26 @@ final class DefaultYangParser implements YangParser {
 
     static StatementStreamSource sourceToStatementStream(final SourceRepresentation source)
             throws IOException, YangSyntaxErrorException {
-        requireNonNull(source);
-        if (source instanceof YangIRSchemaSource irSource) {
-            return YangStatementStreamSource.create(irSource);
-        } else if (source instanceof YangTextSource yangSource) {
-            return YangStatementStreamSource.create(yangSource);
-        } else if (source instanceof YinDomSource yinDom) {
-            return YinStatementStreamSource.create(yinDom);
-        } else if (source instanceof YinTextSource yinText) {
-            try {
-                return YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(yinText));
-            } catch (SAXException e) {
-                throw new YangSyntaxErrorException(source.sourceId(), 0, 0, "Failed to parse XML text", e);
+        return switch (source) {
+            case YangIRSource irSource -> YangStatementStreamSource.create(irSource);
+            case YangTextSource yangSource -> YangStatementStreamSource.create(yangSource);
+            case YinDomSource yinDom -> YinStatementStreamSource.create(yinDom);
+            case YinTextSource yinText -> {
+                try {
+                    yield YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(yinText));
+                } catch (SAXException e) {
+                    throw new YangSyntaxErrorException(source.sourceId(), 0, 0, "Failed to parse XML text", e);
+                }
             }
-        } else if (source instanceof YinXmlSource yinXml) {
-            try {
-                return YinStatementStreamSource.create(yinXml);
-            } catch (TransformerException e) {
-                throw new YangSyntaxErrorException(source.sourceId(), 0, 0,
-                    "Failed to assemble in-memory representation", e);
+            case YinXmlSource yinXml -> {
+                try {
+                    yield YinStatementStreamSource.create(yinXml);
+                } catch (TransformerException e) {
+                    throw new YangSyntaxErrorException(source.sourceId(), 0, 0,
+                        "Failed to assemble in-memory representation", e);
+                }
             }
-        } else {
-            throw new IllegalArgumentException("Unsupported source " + source);
-        }
+            default -> throw new IllegalArgumentException("Unsupported source " + source);
+        };
     }
 }