use of org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement in project yangtools by opendaylight.
the class SchemaInferenceStack method pushGrouping.
@NonNull
private GroupingEffectiveStatement pushGrouping(@NonNull final EffectiveStatement<?, ?> parent, @NonNull final QName nodeIdentifier) {
final GroupingEffectiveStatement ret = parent.streamEffectiveSubstatements(GroupingEffectiveStatement.class).filter(stmt -> nodeIdentifier.equals(stmt.argument())).findFirst().orElseThrow(() -> notPresent(parent, "Grouping", nodeIdentifier));
deque.push(ret);
++groupingDepth;
return ret;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement in project yangtools by opendaylight.
the class YT1233Test method testExitToGrouping.
@Test
public void testExitToGrouping() {
final GroupingEffectiveStatement baz = stack.enterGrouping(QName.create("foo", "baz"));
assertTrue(stack.inGrouping());
final DataTreeEffectiveStatement<?> xyzzy = stack.enterDataTree(QName.create("foo", "xyzzy"));
assertSame(xyzzy, stack.exitToDataTree());
assertSame(baz, stack.currentStatement());
assertSame(xyzzy, stack.enterDataTree(xyzzy.argument()));
}
use of org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement in project yangtools by opendaylight.
the class ContextReferenceTest method test.
@Test
public void test() throws Exception {
final ModuleEffectiveStatement foo = reactor.newBuild().addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/yang-ext.yang"))).addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/ctxref.yang"))).buildEffective().getModuleStatements().get(FOO);
final DataTreeEffectiveStatement<?> list = foo.findDataTreeNode(QName.create(FOO, "list")).orElseThrow();
assertThat(list, instanceOf(ListEffectiveStatement.class));
final ContextInstanceEffectiveStatement listType = list.findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
assertEquals(LIST_TYPE, listType.argument());
assertEquals(LIST_TYPE, listType.contextType().argument());
final ContextInstanceEffectiveStatement leafType = list.findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
assertEquals(LEAF_TYPE, leafType.argument());
assertEquals(LEAF_TYPE, leafType.contextType().argument());
final List<GroupingEffectiveStatement> groupings = foo.streamEffectiveSubstatements(GroupingEffectiveStatement.class).collect(Collectors.toList());
assertEquals(2, groupings.size());
final ContextReferenceEffectiveStatement listRef = groupings.get(1).findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
assertEquals(LIST_TYPE, listType.argument());
assertSame(listType.contextType(), listRef.contextType());
final ContextReferenceEffectiveStatement leafRef = groupings.get(0).findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
assertEquals(LEAF_TYPE, leafType.argument());
assertSame(leafType.contextType(), leafRef.contextType());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement in project yangtools by opendaylight.
the class YT1212Test method testContainerStatementReuse.
@Test
public void testContainerStatementReuse() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/container.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
final List<GroupingEffectiveStatement> groupings = notif.effectiveSubstatements().stream().filter(GroupingEffectiveStatement.class::isInstance).map(GroupingEffectiveStatement.class::cast).collect(Collectors.toList());
assertEquals(2, groupings.size());
final GroupingEffectiveStatement grp = groupings.get(0);
assertEquals("grp", grp.argument().getLocalName());
final GroupingEffectiveStatement barGrp = groupings.get(1);
assertEquals("bar", barGrp.argument().getLocalName());
final ContainerEffectiveStatement bar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
// Container needs to be reused
assertSame(bar.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow(), barGrp.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement in project yangtools by opendaylight.
the class Bug4610Test method findContainer.
private static ContainerEffectiveStatement findContainer(final EffectiveModelContext context, final QName grouping, final QName container) {
final ModuleEffectiveStatement module = context.getModuleStatement(grouping.getModule());
final GroupingEffectiveStatement grp = module.streamEffectiveSubstatements(GroupingEffectiveStatement.class).filter(stmt -> grouping.equals(stmt.argument())).findAny().orElseThrow();
final SchemaTreeEffectiveStatement<?> node = grp.findSchemaTreeNode(container).orElse(null);
assertThat(node, instanceOf(ContainerEffectiveStatement.class));
return (ContainerEffectiveStatement) node;
}
Aggregations