public final void onFullDefinitionDeclared(
final Mutable<SchemaNodeIdentifier, AugmentStatement, AugmentEffectiveStatement> augmentNode) {
if (!augmentNode.isSupportedByFeatures()) {
- return;
+ // We need this augment node to be present, but it should not escape to effective world
+ augmentNode.setIsSupportedToBuildEffective(false);
}
super.onFullDefinitionDeclared(augmentNode);
*/
final boolean skipCheckOfMandatoryNodes = YangVersion.VERSION_1_1.equals(sourceCtx.getRootVersion())
&& isConditionalAugmentStmt(sourceCtx);
+ final boolean unsupported = !sourceCtx.isSupportedByFeatures();
final Collection<? extends Mutable<?, ?, ?>> declared = sourceCtx.mutableDeclaredSubstatements();
final Collection<? extends Mutable<?, ?, ?>> effective = sourceCtx.mutableEffectiveSubstatements();
final Collection<Mutable<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
for (final Mutable<?, ?, ?> originalStmtCtx : declared) {
- if (originalStmtCtx.isSupportedByFeatures()) {
- copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes);
- }
+ copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes,
+ unsupported || !originalStmtCtx.isSupportedByFeatures());
}
for (final Mutable<?, ?, ?> originalStmtCtx : effective) {
- copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes);
+ copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes, unsupported);
}
targetCtx.addEffectiveSubstatements(buffer);
private static void copyStatement(final Mutable<?, ?, ?> original, final StatementContextBase<?, ?, ?> target,
final CopyType typeOfCopy, final Collection<Mutable<?, ?, ?>> buffer,
- final boolean skipCheckOfMandatoryNodes) {
+ final boolean skipCheckOfMandatoryNodes, final boolean unsupported) {
+ // We always copy statements, but if either the source statement or the augmentation which causes it are not
+ // supported to build we also mark the target as such.
if (needToCopyByAugment(original)) {
validateNodeCanBeCopiedByAugment(original, target, typeOfCopy, skipCheckOfMandatoryNodes);
- buffer.add(target.childCopyOf(original, typeOfCopy));
- } else if (isReusedByAugment(original)) {
+ final Mutable<?, ?, ?> copy = target.childCopyOf(original, typeOfCopy);
+ if (unsupported) {
+ copy.setIsSupportedToBuildEffective(false);
+ }
+ buffer.add(copy);
+ } else if (isReusedByAugment(original) && !unsupported) {
buffer.add(original);
}
}
--- /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 com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import java.util.Optional;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+
+public class YT859Test {
+ @Test
+ public void testAugmentUnsupported() throws Exception {
+ final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/YT859/", ImmutableSet.of(),
+ StatementParserMode.DEFAULT_MODE);
+ assertEquals(4, context.getModules().size());
+
+ final DataSchemaNode named = Iterables.getOnlyElement(context.findModules("xyzzy"))
+ .findDataChildByName(QName.create("xyzzy", "xyzzy"), QName.create("xyzzy", "named")).orElseThrow();
+ assertThat(named, instanceOf(ListSchemaNode.class));
+ assertEquals(Optional.empty(), ((ListSchemaNode) named).findDataChildByName(QName.create("foo", "foo")));
+ }
+}