Use instanceof patterns in AbstractEffectiveModule 10/103310/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Nov 2022 16:57:08 +0000 (17:57 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Nov 2022 17:27:08 +0000 (18:27 +0100)
We can reduce the number of explicit casts and make the code a bit
denser now that we have Java 17.

Change-Id: I3d1775676eb4a0a08873b1a452f40d72e27a10a7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java

index b8e455031b7d3c337bf98b8fc66a3f6e79237e49..6e9f11897bd7420e6e1f37b31779ca396adae3f1 100644 (file)
@@ -75,17 +75,14 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqual
         final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
-            if (effectiveStatement instanceof UsesNode && !mutableUses.add((UsesNode) effectiveStatement)) {
+            if (effectiveStatement instanceof UsesNode usesNode && !mutableUses.add(usesNode)) {
                 throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
             }
-            if (effectiveStatement instanceof TypedefEffectiveStatement) {
-                final TypeDefinition<?> type = ((TypedefEffectiveStatement) effectiveStatement).getTypeDefinition();
-                if (!mutableTypeDefinitions.add(type)) {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
-                }
+            if (effectiveStatement instanceof TypedefEffectiveStatement typedef
+                    && !mutableTypeDefinitions.add(typedef.getTypeDefinition())) {
+                throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
             }
-            if (effectiveStatement instanceof GroupingDefinition
-                    && !mutableGroupings.add((GroupingDefinition) effectiveStatement)) {
+            if (effectiveStatement instanceof GroupingDefinition grouping && !mutableGroupings.add(grouping)) {
                 throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
             }
         }