Use Module.asEffectiveStatement() 49/109349/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 16 Dec 2023 12:07:30 +0000 (13:07 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 16 Dec 2023 12:10:12 +0000 (13:10 +0100)
Eliminate a verifyication by cleanly translating Module to
ModuleEffectiveStatement.

Change-Id: I65a08a388e54132457ac8d99d981cbd332d0c009
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/GeneratorReactor.java

index d2cc1ecc1c4f760df0763a3752215aa395c0f1e7..2907f0e2324be93feb2c6a1c1cbb6f1639abf6dd 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.binding.ChoiceIn;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.PathExpression;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
@@ -79,10 +80,8 @@ public final class GeneratorReactor extends GeneratorContext implements Mutable
         // AugmentGenerators without having forward references.
         // FIXME: migrate to new ModuleDependencySort when it is available, which streamline things here
         children = ModuleDependencySort.sort(context.getModules()).stream()
-            .map(module -> {
-                verify(module instanceof ModuleEffectiveStatement, "Unexpected module %s", module);
-                return new ModuleGenerator((ModuleEffectiveStatement) module);
-            })
+            .map(Module::asEffectiveStatement)
+            .map(ModuleGenerator::new)
             .collect(Collectors.toUnmodifiableList());
         generators = Maps.uniqueIndex(children, gen -> gen.statement().localQNameModule());
     }