- // FIXME: This reflects what the current implementation does. We really want to define an adaptArgumentValue(),
- // but how that plays with the argument and expectations needs to be investigated.
- super(YangStmtMapping.UNIQUE, StatementPolicy.contextIndependent(), config, SUBSTATEMENT_VALIDATOR);
+ super(YangStmtMapping.UNIQUE,
+ StatementPolicy.copyDeclared(
+ (copy, current, substatements) -> copy.getArgument().equals(current.getArgument())),
+ config, SUBSTATEMENT_VALIDATOR);
+ }
+
+ @Override
+ public Set<Descendant> adaptArgumentValue(
+ final StmtContext<Set<Descendant>, UniqueStatement, UniqueEffectiveStatement> ctx,
+ final QNameModule targetModule) {
+ // Copy operation to a targetNamespace -- this implies rehosting node-identifiers to target namespace. Check
+ // if that is needed first, though, so as not to copy things unnecessarily.
+ final var origArg = ctx.getArgument();
+ if (allMatch(origArg.stream().flatMap(desc -> desc.getNodeIdentifiers().stream()), targetModule)) {
+ return origArg;
+ }
+
+ return origArg.stream()
+ .map(descendant -> {
+ final var nodeIds = descendant.getNodeIdentifiers();
+ // Only update descendants that need updating
+ return allMatch(nodeIds.stream(), targetModule) ? descendant
+ : Descendant.of(Lists.transform(nodeIds, nodeId -> nodeId.bindTo(targetModule).intern()));
+ })
+ .collect(ImmutableSet.toImmutableSet());