Fix StmtContext.findSubstatementArgument()/hasSubstatement() 53/93553/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Nov 2020 15:37:49 +0000 (16:37 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Nov 2020 15:40:03 +0000 (16:40 +0100)
When we are searching for a substatement we should also mind that
it can have its effective statement built. If we do not, we can end
up picking a statement which has been disabled by deviate.

Change-Id: I27743b5acbb2f617497d329423b239f363c54258
JIRA: YANGTOOLS-1157
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextDefaults.java

index a5692a860dffd4d34f432eee8fa8b3c7bac4e190..59fb76f71c4b5ac85db5b6b62ef3be62bcdf4efb 100644 (file)
@@ -33,7 +33,7 @@ public final class StmtContextDefaults {
     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 -> ((StmtContext) ctx).producesEffective(type))
+                .filter(ctx -> ctx.isSupportedToBuildEffective() && ((StmtContext) ctx).producesEffective(type))
                 .findAny()
                 .map(ctx -> (A) ctx.coerceStatementArgument());
     }
@@ -47,7 +47,8 @@ public final class StmtContextDefaults {
      */
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public static boolean hasSubstatement(final @NonNull StmtContext<?, ?, ?> stmt,
-            @SuppressWarnings("rawtypes") final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
-        return stmt.allSubstatementsStream().anyMatch(ctx -> ((StmtContext) ctx).producesEffective(type));
+            final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
+        return stmt.allSubstatementsStream()
+            .anyMatch(ctx -> ctx.isSupportedToBuildEffective() && ((StmtContext) ctx).producesEffective(type));
     }
 }