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();
}
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());
}
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);
}
Aggregations