We currently do not capture the set of supported features in
EffectiveModelContext aside from applying their effects. Improve this
by not exposing unsupported features in the effective model, so that
users can understand the set of supported features by simply looking
for all FeatureEffectiveStatements.
JIRA: YANGTOOLS-1368
Change-Id: I8c60705ad96854cd2d4dc5d7b97cc2e51dd5a032
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
e4da09169c29d790b3b835a1e88a629758d27435)
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.meta.SubstatementValidator;
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.meta.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
public final class FeatureStatementSupport
extends AbstractQNameStatementSupport<FeatureStatement, FeatureEffectiveStatement> {
public final class FeatureStatementSupport
extends AbstractQNameStatementSupport<FeatureStatement, FeatureEffectiveStatement> {
public void onFullDefinitionDeclared(final Mutable<QName, FeatureStatement, FeatureEffectiveStatement> stmt) {
super.onFullDefinitionDeclared(stmt);
stmt.addContext(FeatureNamespace.class, stmt.getArgument(), stmt);
public void onFullDefinitionDeclared(final Mutable<QName, FeatureStatement, FeatureEffectiveStatement> stmt) {
super.onFullDefinitionDeclared(stmt);
stmt.addContext(FeatureNamespace.class, stmt.getArgument(), stmt);
+
+ // Do not build effective statement if supported features does not include this feature
+ final var supportedFeatures = stmt.getFromNamespace(SupportedFeaturesNamespace.class,
+ SupportedFeatures.SUPPORTED_FEATURES);
+ if (supportedFeatures != null && !supportedFeatures.contains(stmt.getArgument())) {
+ stmt.setIsSupportedToBuildEffective(false);
+ }
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
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.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
public class Bug8922Test {
public class Bug8922Test {
- private static final String NS = "foo";
+ private static final QName MY_CON = QName.create("foo", "my-con");
+ private static final QName TARGET = QName.create("foo", "target");
@Test
public void testAllFeaturesSupported() throws Exception {
@Test
public void testAllFeaturesSupported() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
+ final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
- final SchemaNode findNode = context.findDataTreeChild(qN("target"), qN("my-con")).get();
+ final var findNode = context.findDataTreeChild(TARGET, MY_CON).get();
assertThat(findNode, instanceOf(ContainerSchemaNode.class));
assertEquals(Optional.of("New description"), findNode.getDescription());
assertThat(findNode, instanceOf(ContainerSchemaNode.class));
assertEquals(Optional.of("New description"), findNode.getDescription());
+
+ assertEquals(1, context.findModuleStatements("foo").iterator().next()
+ .streamEffectiveSubstatements(FeatureEffectiveStatement.class).count());
}
@Test
public void testNoFeatureSupported() throws Exception {
}
@Test
public void testNoFeatureSupported() throws Exception {
- final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
+ final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
- assertEquals(Optional.empty(), context.findDataTreeChild(qN("target"), qN("my-con")));
+ assertEquals(Optional.empty(), context.findDataTreeChild(TARGET, MY_CON));
assertTrue(context.getAvailableAugmentations().isEmpty());
assertTrue(context.getAvailableAugmentations().isEmpty());
- private static QName qN(final String localName) {
- return QName.create(NS, localName);
+ assertEquals(0, context.findModuleStatements("foo").iterator().next()
+ .streamEffectiveSubstatements(FeatureEffectiveStatement.class).count());