import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import java.util.Collection;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
return ret;
}
+ @Override
+ public Collection<SchemaNodeIdentifier> adaptArgumentValue(
+ final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
+ EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx,
+ final QNameModule targetModule) {
+ final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
+ boolean replaced = false;
+ for (final SchemaNodeIdentifier arg : ctx.getStatementArgument()) {
+ final QName qname = arg.getLastComponent();
+ if (!targetModule.equals(qname)) {
+ final QName newQname = ctx.getFromNamespace(QNameCacheNamespace.class,
+ QName.create(targetModule, qname.getLocalName()));
+ builder.add(SchemaNodeIdentifier.create(false, newQname));
+ replaced = true;
+ } else {
+ builder.add(arg);
+ }
+ }
+
+ // This makes sure we reuse the collection when a grouping is
+ // instantiated in the same module
+ return replaced ? builder.build() : ctx.getStatementArgument();
+ }
+
@Override
public KeyStatement createDeclared(final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> ctx) {
return new KeyStatementImpl(ctx);