* statement, otherwise false
*/
private static boolean isConditionalAugmentStmt(final StmtContext<?, ?, ?> ctx) {
- return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT && hasWhenSubstatement(ctx);
- }
-
- private static boolean hasWhenSubstatement(final StmtContext<?, ?, ?> ctx) {
- return StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null;
+ return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT
+ && StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null;
}
private static void copyStatement(final Mutable<?, ?, ?> original, final StatementContextBase<?, ?, ?> target,
}
if (!skipCheckOfMandatoryNodes && typeOfCopy == CopyType.ADDED_BY_AUGMENTATION
- && requireCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
+ && reguiredCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
checkForMandatoryNodes(sourceCtx);
}
sourceCtx.rawStatementArgument());
}
- private static boolean requireCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
+ private static boolean reguiredCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
Mutable<?, ?, ?> targetCtx) {
/*
* If the statement argument is not QName, it cannot be mandatory
* statement, therefore return false and skip mandatory nodes validation
*/
- final Object arg = sourceCtx.getStatementArgument();
- if (!(arg instanceof QName)) {
+ if (!(sourceCtx.getStatementArgument() instanceof QName)) {
return false;
}
- final QName sourceStmtQName = (QName) arg;
+ final QName sourceStmtQName = (QName) sourceCtx.getStatementArgument();
// RootStatementContext, for example
final Mutable<?, ?, ?> root = targetCtx.getRoot();
do {
- final Object targetArg = targetCtx.getStatementArgument();
- Verify.verify(targetArg instanceof QName, "Argument of augment target statement must be QName, not %s",
- targetArg);
- final QName targetStmtQName = (QName) targetArg;
+ Verify.verify(targetCtx.getStatementArgument() instanceof QName,
+ "Argument of augment target statement must be QName.");
+ final QName targetStmtQName = (QName) targetCtx.getStatementArgument();
/*
* If target is from another module, return true and perform mandatory nodes validation
*/
|| StmtContextUtils.isNotMandatoryNodeOfType(targetCtx, YangStmtMapping.LIST)) {
return false;
}
-
- // This could be an augmentation stacked on top of a previous augmentation from the same module, which is
- // conditional -- in which case we do not run further checks
- if (targetCtx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
- final Optional<StmtContext<?, ?, ?>> optOriginal = targetCtx.getOriginalCtx();
- if (optOriginal.isPresent()) {
- final StmtContext<?, ?, ?> original = optOriginal.get();
- final Object origArg = original.coerceStatementArgument();
- Verify.verify(origArg instanceof QName, "Unexpected statement argument %s", origArg);
-
- if (sourceStmtQName.getModule().equals(((QName) origArg).getModule())
- && hasWhenSubstatement(getParentAugmentation(original))) {
- return false;
- }
- }
- }
} while ((targetCtx = targetCtx.getParentContext()) != root);
/*
return false;
}
- private static StmtContext<?, ?, ?> getParentAugmentation(final StmtContext<?, ?, ?> child) {
- StmtContext<?, ?, ?> parent = Verify.verifyNotNull(child.getParentContext(), "Child %s has not parent", child);
- while (parent.getPublicDefinition() != YangStmtMapping.AUGMENT) {
- parent = Verify.verifyNotNull(parent.getParentContext(), "Failed to find augmentation parent of %s", child);
- }
- return parent;
- }
-
private static final ImmutableSet<YangStmtMapping> NOCOPY_DEF_SET = ImmutableSet.of(YangStmtMapping.USES,
YangStmtMapping.WHEN, YangStmtMapping.DESCRIPTION, YangStmtMapping.REFERENCE, YangStmtMapping.STATUS);
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-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;
-
-public class YT956Test {
- private static final QName ANOTHER_CONTAINER = QName.create("http://www.example.com/anothermodule",
- "another-container");
- private static final QName FIRST_AUGMENT = QName.create("http://www.example.com/mainmodule", "first-augment");
-
- @Test
- public void testAugmentationConditional() throws Exception {
- final DataSchemaNode another = StmtTestUtils.parseYangSources("/bugs/YT956/")
- .findDataChildByName(ANOTHER_CONTAINER).get();
- assertThat(another, isA(ContainerSchemaNode.class));
- final ContainerSchemaNode anotherContainer = (ContainerSchemaNode) another;
-
- final DataSchemaNode first = anotherContainer.findDataChildByName(FIRST_AUGMENT).get();
- assertThat(first, isA(ContainerSchemaNode.class));
- final ContainerSchemaNode firstAugment = (ContainerSchemaNode) first;
-
- // Augmentation needs to be added
- assertEquals(1, firstAugment.getChildNodes().size());
- }
-}