+ @SuppressWarnings("unchecked")
+ public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllEffectiveSubstatements(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
+ ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ for (StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
+ if (producesDeclared(subStmtContext, type)) {
+ listBuilder.add((StmtContext<AT, DT, ?>) subStmtContext);
+ }
+ }
+ return listBuilder.build();
+ }
+
+ public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllSubstatements(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
+ ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ listBuilder.addAll(findAllDeclaredSubstatements(stmtContext, type));
+ listBuilder.addAll(findAllEffectiveSubstatements(stmtContext, type));
+ return listBuilder.build();
+ }
+