--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.parser.spi.source;
+
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+/**
+ * namespace key class for storing augment nodes which are going to be augmented as
+ * shortHand case nodes into choice node
+ */
+public interface AugmentToChoiceNamespace extends IdentifierNamespace<StmtContext<?, ?, ?>, Boolean> {
+
+}
\ No newline at end of file
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.source.AugmentToChoiceNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
}
final SchemaPath path;
- if (StmtContextUtils.producesDeclared(getParentContext(), ChoiceStatement.class)
+ if ((StmtContextUtils.producesDeclared(getParentContext(), ChoiceStatement.class)
+ || Boolean.TRUE.equals(parent.getFromNamespace(AugmentToChoiceNamespace.class, parent)))
&& isSupportedAsShorthandCase()) {
path = parentPath.createChild(qname);
} else {
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import static org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator.MAX;
+
import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.regex.Pattern;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
augmentNode.setIsSupportedToBuildEffective(false);
return;
}
+ /**
+ * Marks case short hand in augment
+ */
+ if (augmentTargetCtx.getPublicDefinition() == Rfc6020Mapping.CHOICE) {
+ augmentNode.addToNs(AugmentToChoiceNamespace.class, augmentNode, true);
+ }
// FIXME: this is a workaround for models which augment a node which is added via an extension
// which we do not handle. This needs to be reworked in terms of unknown schema nodes.
import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
.addSupport(new OrderedByStatementImpl.Definition())
.addSupport(new WhenStatementImpl.Definition())
.addSupport(new AugmentStatementImpl.Definition())
+ .addSupport(treeScoped(AugmentToChoiceNamespace.class))
.addSupport(new RefineStatementImpl.Definition())
.addSupport(new FeatureStatementImpl.Definition())
.addSupport(new PositionStatementImpl.Definition())
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangValidationBundles;
abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
extends AbstractEffectiveDocumentedNode<A, D> implements
if (effectiveStatement instanceof DataSchemaNode) {
final DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
if (!mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
- mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
- mutablePublicChildNodes.add(dataSchemaNode);
+ /**
+ * Add case short hand when augmenting choice with short hand
+ **/
+ if (this instanceof AugmentationSchema && !(effectiveStatement instanceof ChoiceCaseNode ||
+ effectiveStatement instanceof ChoiceSchemaNode) &&
+ (YangValidationBundles.SUPPORTED_CASE_SHORTHANDS.contains(effectiveStatement.statementDefinition())) &&
+ Boolean.TRUE.equals(ctx.getFromNamespace(AugmentToChoiceNamespace.class, ctx))) {
+ final CaseShorthandImpl caseShorthand = new CaseShorthandImpl(dataSchemaNode);
+ mutableChildNodes.put(caseShorthand.getQName(), caseShorthand);
+ mutablePublicChildNodes.add(caseShorthand);
+ } else {
+ mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
+ mutablePublicChildNodes.add(dataSchemaNode);
+ }
} else {
throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
+
+public class Bug5884Test {
+ private static final String NS = "urn:yang.foo";
+ private static final String REV = "2016-01-01";
+
+ @Test
+ public void testBug5884() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException, ParseException {
+ final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
+ assertNotNull(context);
+
+ final QName root = QName.create(NS, REV, "main-container");
+ final QName choice = QName.create(NS, REV, "test-choice");
+ final QName testContainerQname = QName.create(NS, REV, "test");
+ final Date date = SimpleDateFormatUtil.getRevisionFormat().parse("2016-01-01");
+ final Module foo = context.findModuleByName("foo", date);
+ final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
+ final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(testContainerQname);
+ final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
+ final Set<AugmentationSchema> augmentations = foo.getAugmentations();
+ final Set<AugmentationSchema> availableAugmentations = dataChildByName.getAvailableAugmentations();
+ final Iterator<AugmentationSchema> iterator = augmentations.iterator();
+ final Iterator<AugmentationSchema> availableIterator = availableAugmentations.iterator();
+
+ testIterator(iterator);
+ testIterator(availableIterator);
+ }
+
+ private void testIterator(final Iterator<AugmentationSchema> iterator) {
+ AugmentationSchema allAugments;
+ while (iterator.hasNext()) {
+ allAugments = iterator.next();
+ final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
+ assertTrue(currentChoice instanceof ChoiceCaseNode);
+ }
+ }
+}
\ No newline at end of file
assertNotNull(augmentHolder2);
assertEquals(1, augment3.getChildNodes().size());
- LeafSchemaNode pause = (LeafSchemaNode) augment3.getDataChildByName("pause");
+ ChoiceCaseNode pause = (ChoiceCaseNode) augment3.getDataChildByName("pause");
assertNotNull(pause);
}
--- /dev/null
+module foo {
+ namespace "urn:yang.foo";
+ prefix "foo";
+
+ revision "2016-01-01";
+
+ container main-container {
+ uses test-grouping {
+ augment "test/test-choice" {
+ leaf short-aug-uses-inside {
+ type string;
+ }
+ }
+
+ augment "test/test-choice" {
+ case normal-aug-uses-inside {
+ leaf normal-aug-uses-inside {
+ type string;
+ }
+ }
+ }
+ }
+ }
+
+ grouping test-grouping {
+ container test {
+ choice test-choice {
+ leaf short {
+ type string;
+ }
+ case normal {
+ leaf normal {
+ type string;
+ }
+ }
+ }
+ }
+ }
+
+ choice test-choice {
+ leaf short {
+ type string;
+ }
+ case normal {
+ leaf normal {
+ type string;
+ }
+ }
+ }
+
+ augment "/test-choice" {
+ leaf short-aug-uses {
+ type string;
+ }
+ }
+
+ augment "/test-choice" {
+ case normal-aug-uses {
+ leaf normal-aug-uses {
+ type string;
+ }
+ }
+ }
+
+ augment "/main-container/test/test-choice" {
+ leaf short-aug-uses-outside {
+ type string;
+ }
+ }
+
+ augment "/main-container/test/test-choice" {
+ case normal-aug-uses-outside {
+ leaf normal-aug-uses-outside {
+ type string;
+ }
+ }
+ }
+}
\ No newline at end of file