Use instanceof pattern in AbstractCompositeRuntimeType 53/109353/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 16 Dec 2023 13:45:01 +0000 (14:45 +0100)
committerRobert Varga <nite@hq.sk>
Sat, 16 Dec 2023 15:36:08 +0000 (15:36 +0000)
Rather than a plain verify() and explicit cast, use an instanceof
pattern and an explicit throw.

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

index 92e453ca97bae9ddad571a05c6800d012e2ca130..a806f99a484f4721fd1b2e2c9408c1facb60694b 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Verify.verify;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.Functions;
+import com.google.common.base.VerifyException;
 import com.google.common.collect.ImmutableMap;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Arrays;
@@ -100,7 +101,9 @@ abstract class AbstractCompositeRuntimeType<S extends EffectiveStatement<?, ?>>
 
     private static @NonNull QName extractQName(final RuntimeType type) {
         final var stmt = type.statement();
-        verify(stmt instanceof SchemaTreeEffectiveStatement, "Unexpected statement %s in %s", stmt, type);
-        return ((SchemaTreeEffectiveStatement<?>) stmt).argument();
+        if (stmt instanceof SchemaTreeEffectiveStatement<?> schemaTreeStmt) {
+            return schemaTreeStmt.argument();
+        }
+        throw new VerifyException("Unexpected statement " + stmt + " in " + type);
     }
 }
\ No newline at end of file