this.moduleToPrefix = qnameToPrefix == null ? ImmutableBiMap.of() : ImmutableBiMap.copyOf(qnameToPrefix);
// Additional mappings
+ final Map<String, QNameModule> additional = new HashMap<>();
final Map<String, StmtContext<?, ?, ?>> imports = ctx.getAllFromNamespace(ImportPrefixToModuleCtx.class);
if (imports != null) {
- final Map<String, QNameModule> additional = new HashMap<>();
for (Entry<String, StmtContext<?, ?, ?>> entry : imports.entrySet()) {
if (!moduleToPrefix.containsValue(entry.getKey())) {
QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, entry.getValue());
}
}
}
- this.prefixToModule = ImmutableMap.copyOf(additional);
- } else {
- this.prefixToModule = ImmutableMap.of();
}
+ if (ctx.producesDeclared(SubmoduleStatement.class)) {
+ final Map<String, String> belongsTo = ctx.getAllFromNamespace(BelongsToPrefixToModuleName.class);
+ if (belongsTo != null) {
+ for (Entry<String, String> entry : belongsTo.entrySet()) {
+ final QNameModule module = ctx.getFromNamespace(ModuleNameToModuleQName.class, entry.getValue());
+ if (module != null && !additional.containsKey(entry.getKey())) {
+ additional.put(entry.getKey(), module);
+ }
+ }
+ }
+ }
+
+ this.prefixToModule = ImmutableMap.copyOf(additional);
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.xpath.api.YangExpr;
+import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Relative;
+import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
+
+public class YT1201Test {
+ private static final QName FOO = QName.create("foo", "foo");
+ private static final QName BAR = QName.create("foo", "bar");
+
+ @Test
+ public void testWhenPrefixes() throws Exception {
+ final DataSchemaNode bar = StmtTestUtils.parseYangSources("/bugs/YT1201/").getDataChildByName(BAR);
+ assertThat(bar, instanceOf(ContainerSchemaNode.class));
+ final YangExpr when = ((ContainerSchemaNode) bar).getWhenCondition().get().getRootExpr();
+ assertThat(when, instanceOf(Relative.class));
+ assertEquals(List.of(YangXPathAxis.CHILD.asStep(FOO)), ((Relative) when).getSteps());
+ }
+}