Fix StmtContext.produces{Declared,Effective} signatures 49/93949/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 27 Nov 2020 04:05:37 +0000 (05:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 27 Nov 2020 04:05:37 +0000 (05:05 +0100)
We have bad signatures here, one of which is needlessly verbose,
the other one is actually plain wrong as it confuses X,Y for A,D.

Fix them up, which removes the need to go throw raw access to make
them work.

Change-Id: I6bfd995c8b4064b99eb673fa30c4ab8f3d52dd5c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextDefaults.java

index 337a5fba1a64da4313e4a0b9e8c30d1a94dd133b..0d3001fb5681612cd7314e41374255e1085b51b6 100644 (file)
@@ -108,12 +108,11 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         return verifyNotNull(getStatementArgument(), "Statement context %s does not have an argument", this);
     }
 
-    default <X, Y extends DeclaredStatement<X>> boolean producesDeclared(final Class<? super Y> type) {
+    default <Y extends DeclaredStatement<?>> boolean producesDeclared(final Class<? super Y> type) {
         return type.isAssignableFrom(getPublicDefinition().getDeclaredRepresentationClass());
     }
 
-    default <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<A, D>> boolean producesEffective(
-            final Class<? super Z> type) {
+    default <Z extends EffectiveStatement<?, ?>> boolean producesEffective(final Class<? super Z> type) {
         return type.isAssignableFrom(getPublicDefinition().getEffectiveRepresentationClass());
     }
 
index 59fb76f71c4b5ac85db5b6b62ef3be62bcdf4efb..0dbf3fee275813ed0d97be3c939f189bf9f9114d 100644 (file)
@@ -29,11 +29,11 @@ public final class StmtContextDefaults {
      * @param type Effective statement representation being look up
      * @return Effective statement argument, if found
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings("unchecked")
     public static <A, E extends EffectiveStatement<A, ?>> @NonNull Optional<A> findSubstatementArgument(
             final @NonNull StmtContext<?, ?, ?> stmt, final @NonNull Class<E> type) {
         return stmt.allSubstatementsStream()
-                .filter(ctx -> ctx.isSupportedToBuildEffective() && ((StmtContext) ctx).producesEffective(type))
+                .filter(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type))
                 .findAny()
                 .map(ctx -> (A) ctx.coerceStatementArgument());
     }
@@ -45,10 +45,9 @@ public final class StmtContextDefaults {
      * @param type Effective statement representation being look up
      * @return True if a match is found, false otherwise
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
     public static boolean hasSubstatement(final @NonNull StmtContext<?, ?, ?> stmt,
             final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
         return stmt.allSubstatementsStream()
-            .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ((StmtContext) ctx).producesEffective(type));
+            .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ctx.producesEffective(type));
     }
 }