- final Collection<? extends StmtContext<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
- ctx.declaredSubstatements(), StmtContext::isSupportedByFeatures);
- for (final StmtContext<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
- if (YangStmtMapping.USES == declaredSubstatement.getPublicDefinition()) {
- substatementsInit.add(declaredSubstatement);
- substatementsInit.addAll(declaredSubstatement.getEffectOfStatement());
- ((StatementContextBase<?, ?, ?>) ctx).removeStatementsFromEffectiveSubstatements(declaredSubstatement
- .getEffectOfStatement());
- } else {
+ /*
+ * This dance is required to ensure that effects of 'uses' nodes are applied in the same order as
+ * the statements were defined -- i.e. if we have something like this:
+ *
+ * container foo {
+ * uses bar;
+ * uses baz;
+ * }
+ *
+ * grouping baz {
+ * leaf baz {
+ * type string;
+ * }
+ * }
+ *
+ * grouping bar {
+ * leaf bar {
+ * type string;
+ * }
+ * }
+ *
+ * The reactor would first inline 'uses baz' as that definition is the first one completely resolved and then
+ * inline 'uses bar'. Here we are iterating in declaration order re-inline the statements.
+ *
+ * TODO: this really should be handled by UsesStatementSupport such that 'uses baz' would have a prerequisite
+ * of a resolved 'uses bar'.
+ */
+ Set<StmtContext<?, ?, ?>> filteredStatements = null;
+ for (final StmtContext<?, ?, ?> declaredSubstatement : ctx.declaredSubstatements()) {
+ if (declaredSubstatement.isSupportedByFeatures()) {