Search in sources :

Example 1 with GroupingEffectiveStatement

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;
}
Also used : GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) NonNull(org.eclipse.jdt.annotation.NonNull) Objects.requireNonNull(java.util.Objects.requireNonNull)

Example 2 with GroupingEffectiveStatement

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()));
}
Also used : GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) Test(org.junit.Test)

Example 3 with GroupingEffectiveStatement

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());
}
Also used : LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) ListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement) ContextInstanceEffectiveStatement(org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement) LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) ContextReferenceEffectiveStatement(org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement) Test(org.junit.Test)

Example 4 with GroupingEffectiveStatement

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());
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 5 with GroupingEffectiveStatement

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;
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)

Aggregations

GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)9 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)7 Test (org.junit.Test)6 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)4 Objects.requireNonNull (java.util.Objects.requireNonNull)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)2 ContextInstanceEffectiveStatement (org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement)1 ContextReferenceEffectiveStatement (org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement)1 QName (org.opendaylight.yangtools.yang.common.QName)1 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)1 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)1 ListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement)1