Search in sources :

Example 1 with ListEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement in project mdsal by opendaylight.

the class CurrentAdapterSerializer method getActionPath.

@NonNull
Absolute getActionPath(@NonNull final ActionSpec<?, ?> spec) {
    final var stack = SchemaInferenceStack.of(getRuntimeContext().getEffectiveModelContext());
    final var it = toYangInstanceIdentifier(spec.path()).getPathArguments().iterator();
    verify(it.hasNext(), "Unexpected empty instance identifier for %s", spec);
    QNameModule lastNamespace;
    do {
        final var arg = it.next();
        if (arg instanceof AugmentationIdentifier) {
            final var augChildren = ((AugmentationIdentifier) arg).getPossibleChildNames();
            verify(!augChildren.isEmpty(), "Invalid empty augmentation %s", arg);
            lastNamespace = augChildren.iterator().next().getModule();
            continue;
        }
        final var qname = arg.getNodeType();
        final var stmt = stack.enterDataTree(qname);
        lastNamespace = qname.getModule();
        if (stmt instanceof ListEffectiveStatement) {
            // Lists have two steps
            verify(it.hasNext(), "Unexpected list termination at %s in %s", stmt, spec);
            // Verify just to make sure we are doing the right thing
            final var skipped = it.next();
            verify(skipped instanceof NodeIdentifier, "Unexpected skipped list entry item %s in %s", skipped, spec);
            verify(stmt.argument().equals(skipped.getNodeType()), "Mismatched list entry item %s in %s", skipped, spec);
        }
    } while (it.hasNext());
    final var stmt = stack.enterSchemaTree(BindingReflections.findQName(spec.type()).bindTo(lastNamespace));
    verify(stmt instanceof ActionEffectiveStatement, "Action %s resolved to unexpected statement %s", spec, stmt);
    return stack.toSchemaNodeIdentifier();
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) ListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement) ActionEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with ListEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement in project yangtools by opendaylight.

the class YT1195Test method testKeyStatementReuse.

@Test
public void testKeyStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1195/key.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final ListEffectiveStatement grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
    final ListEffectiveStatement foo = module.findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
    // The statements should not be the same due history being part of ListSchemaNode
    assertNotSame(foo, grpFoo);
    // The statements are instantiated in the same module, hence they should have the same argument
    assertSame(foo.argument(), grpFoo.argument());
    // The statements' key substatement should be reused
    assertSame(foo.findFirstEffectiveSubstatement(KeyEffectiveStatement.class).orElseThrow(), grpFoo.findFirstEffectiveSubstatement(KeyEffectiveStatement.class).orElseThrow());
}
Also used : ListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 3 with ListEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement in project yangtools by opendaylight.

the class YT1208Test method testListStatementReuse.

@Test
public void testListStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/list.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
    final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
    final ListEffectiveStatement grpBar = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
    final ListEffectiveStatement contBar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
    assertSame(contBar, grpBar);
}
Also used : LeafListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement) ListEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement) 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)

Aggregations

ListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement)3 Test (org.junit.Test)2 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)2 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 AugmentationIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ActionEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement)1 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)1 LeafListEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement)1 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)1