*
* The "if-feature" statement makes its parent statement conditional.
*/
-// FIXME: IfFeatureStatement should extend DeclaredStatement<Predicate<Set<QName>>> and
-// IfFeatureStatementImpl for Yang1.0 reworked to extend AbstractDeclaredStatement<Predicate<Set<QName>>>.
-public interface IfFeatureStatement extends DeclaredStatement<QName> {
-
+public interface IfFeatureStatement extends DeclaredStatement<Predicate<Set<QName>>> {
/**
- * Used in YANG 1.0 (RFC6020) implementation of IfFeatureStatement
- * where the argument is the name of a feature
- * as defined by a "feature" statement.
- *
- * To be replaced by {@link #getIfFeaturePredicate() getIfFeaturePredicate} method.
- *
- * @return QName object for the feature
- */
- @Deprecated
- @Nonnull QName getName();
-
- /**
- * This method should be overridden for all Yang 1.1 implementation.
- * The default implementation is only applicable for Yang 1.0 (RFC6020).
- *
* In Yang 1.1 (RFC7950) implementation of IfFeatureStatement, the
* argument is a boolean expression over feature names defined by
* "feature" statements. Hence, add implementation to return a
* @return Predicate on a collection of QNames against which to evaluate
*/
@Beta
- @Nonnull default Predicate<Set<QName>> getIfFeaturePredicate() {
- return setQnames -> setQnames.contains(getName());
- }
+ @Nonnull
+ Predicate<Set<QName>> getIfFeaturePredicate();
}
\ No newline at end of file
+++ /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.model.repo.api;
-
-import com.google.common.annotations.Beta;
-import java.util.function.Predicate;
-import org.opendaylight.yangtools.yang.common.QName;
-
-@Beta
-/**
- * If-feature predicate constants.
- */
-public final class IfFeaturePredicates {
- /**
- * All features predicate constant. Using of this constant improves
- * performance of schema context resolution.
- */
- public static final Predicate<QName> ALL_FEATURES = t -> true;
-
- private IfFeaturePredicates() {
- throw new UnsupportedOperationException("Utility class");
- }
-}
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.CheckedFuture;
import java.util.Collection;
-import java.util.function.Predicate;
+import java.util.Set;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
* failed.
*/
default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
- @Nonnull Collection<SourceIdentifier> requiredSources) {
- return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
+ @Nonnull final Collection<SourceIdentifier> requiredSources) {
+ return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE);
}
/**
* failed.
*/
default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
- Collection<SourceIdentifier> requiredSources, StatementParserMode statementParserMode) {
- return createSchemaContext(requiredSources, statementParserMode, IfFeaturePredicates.ALL_FEATURES);
+ final Collection<SourceIdentifier> requiredSources, final StatementParserMode statementParserMode) {
+ return createSchemaContext(requiredSources, statementParserMode, null);
}
/**
*
* @param requiredSources
* a collection of sources which are required to be present
- * @param isFeatureSupported
- * a predicate based on which all if-feature statements in the
+ * @param supportedFeatures
+ * set of supported features based on which all if-feature statements in the
* parsed yang models are resolved
* @return A checked future, which will produce a schema context, or fail
* with an explanation why the creation of the schema context
* failed.
*/
default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
- @Nonnull Collection<SourceIdentifier> requiredSources, Predicate<QName> isFeatureSupported) {
- return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, isFeatureSupported);
+ @Nonnull final Collection<SourceIdentifier> requiredSources, final Set<QName> supportedFeatures) {
+ return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
/**
* a collection of sources which are required to be present
* @param statementParserMode
* mode of statement parser
- * @param isFeatureSupported
- * a predicate based on which all if-feature statements in the
+ * @param supportedFeatures
+ * set of supported features based on which all if-feature statements in the
* parsed yang models are resolved
* @return A checked future, which will produce a schema context, or fail
* with an explanation why the creation of the schema context
*/
CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
Collection<SourceIdentifier> requiredSources, StatementParserMode statementParserMode,
- Predicate<QName> isFeatureSupported);
+ Set<QName> supportedFeatures);
}
--- /dev/null
+//
+// Copyright (c) 2017 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
+//
+lexer grammar IfFeatureExpressionLexer;
+
+@header {
+package org.opendaylight.yangtools.antlrv4.code.gen;
+}
+
+NOT : 'not';
+LP : '(';
+RP : ')';
+AND : 'and';
+OR : 'or';
+COLON : ':';
+SEP: [ \n\r\t]+;
+IDENTIFIER : [a-zA-Z][a-zA-Z0-9_-]*;
--- /dev/null
+//
+// Copyright (c) 2017 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
+//
+parser grammar IfFeatureExpressionParser;
+
+@header {
+package org.opendaylight.yangtools.antlrv4.code.gen;
+}
+
+options{
+ tokenVocab = IfFeatureExpressionLexer;
+}
+
+
+if_feature_expr: if_feature_term (SEP OR SEP if_feature_expr)?;
+if_feature_term: if_feature_factor (SEP AND SEP if_feature_term)?;
+if_feature_factor: NOT SEP if_feature_factor
+ | LP SEP? if_feature_expr SEP? RP
+ | identifier_ref_arg;
+
+identifier_ref_arg : (IDENTIFIER COLON)? IDENTIFIER;
\ No newline at end of file
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.function.Predicate;
import javax.annotation.Nonnull;
import org.antlr.v4.runtime.ParserRuleContext;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext;
@Override
public CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
final Collection<SourceIdentifier> requiredSources, final StatementParserMode statementParserMode,
- final Predicate<QName> isFeatureSupported) {
+ final Set<QName> supportedFeatures) {
return createSchemaContext(requiredSources,
statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache,
- new AssembleSources(isFeatureSupported, statementParserMode));
+ new AssembleSources(supportedFeatures, statementParserMode));
}
private ListenableFuture<ASTSchemaSource> requestSource(final SourceIdentifier identifier) {
private static final class AssembleSources implements AsyncFunction<List<ASTSchemaSource>, SchemaContext> {
- private final Predicate<QName> isFeatureSupported;
+ private final Set<QName> supportedFeatures;
private final StatementParserMode statementParserMode;
private final Function<ASTSchemaSource, SourceIdentifier> getIdentifier;
- private AssembleSources(final Predicate<QName> isFeatureSupported,
+ private AssembleSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode) {
- this.isFeatureSupported = Preconditions.checkNotNull(isFeatureSupported);
+ this.supportedFeatures = supportedFeatures;
this.statementParserMode = Preconditions.checkNotNull(statementParserMode);
switch (statementParserMode) {
case SEMVER_MODE:
final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource::getAST);
final CrossSourceStatementReactor.BuildAction reactor =
- YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, isFeatureSupported);
+ YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, supportedFeatures);
for (final Entry<SourceIdentifier, ParserRuleContext> e : asts.entrySet()) {
final ParserRuleContext parserRuleCtx = e.getValue();
final SchemaContext schemaContext;
try {
schemaContext = reactor.buildEffective();
- } catch (ReactorException ex) {
+ } catch (final ReactorException ex) {
throw new SchemaResolutionException("Failed to resolve required models", ex.getSourceIdentifier(), ex);
}
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import java.util.Collection;
+import java.util.Set;
import java.util.function.Predicate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.RootStatementContext;
break;
}
- final Predicate<QName> isFeatureSupported = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
+ final Set<QName> supportedFeatures = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
SupportedFeatures.SUPPORTED_FEATURES);
- if (IfFeaturePredicates.ALL_FEATURES.equals(isFeatureSupported)) {
+ /*
+ * If set of supported features has not been provided, all features are
+ * supported by default.
+ */
+ if (supportedFeatures == null) {
stmtContext.setSupportedByFeatures(true);
return true;
}
- final boolean result = checkFeatureSupport(stmtContext, isFeatureSupported);
+ final boolean result = checkFeatureSupport(stmtContext, supportedFeatures);
stmtContext.setSupportedByFeatures(result);
return result;
}
private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
- final Predicate<QName> isFeatureSupported) {
+ final Set<QName> supportedFeatures) {
boolean isSupported = false;
boolean containsIfFeature = false;
for (final StatementContextBase<?, ?, ?> stmt : stmtContext.declaredSubstatements()) {
if (YangStmtMapping.IF_FEATURE.equals(stmt.getPublicDefinition())) {
containsIfFeature = true;
- if (isFeatureSupported.test((QName) stmt.getStatementArgument())) {
+ if (((Predicate<Set<QName>>) stmt.getStatementArgument()).test(supportedFeatures)) {
isSupported = true;
} else {
isSupported = false;
package org.opendaylight.yangtools.yang.parser.spi.source;
-import java.util.function.Predicate;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
public interface SupportedFeaturesNamespace
- extends IdentifierNamespace<SupportedFeaturesNamespace.SupportedFeatures, Predicate<QName>> {
+ extends IdentifierNamespace<SupportedFeaturesNamespace.SupportedFeatures, Set<QName>> {
enum SupportedFeatures {
SUPPORTED_FEATURES
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import java.util.function.Predicate;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangVersion;
private final Set<YangVersion> supportedVersions;
BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports,
- final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported) {
- this(supports, ImmutableMap.of(), statementParserMode, isFeatureSupported);
+ final StatementParserMode statementParserMode, final Set<QName> supportedFeatures) {
+ this(supports, ImmutableMap.of(), statementParserMode, supportedFeatures);
}
BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports,
final Map<ValidationBundleType, Collection<?>> supportedValidation,
- final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported) {
+ final StatementParserMode statementParserMode, final Set<QName> supportedFeatures) {
super();
this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null");
Preconditions.checkNotNull(statementParserMode, "Statement parser mode must not be null.");
addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue());
}
- addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
- Preconditions.checkNotNull(isFeatureSupported, "Supported feature predicate must not be null."));
+ if (supportedFeatures != null) {
+ addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
+ ImmutableSet.copyOf(supportedFeatures));
+ } else {
+ LOG.warn("Set of supported features has not been provided, so all features are supported by default.");
+ }
this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
}
default:
throw new IllegalStateException("Unsupported phase progress " + sourceProgress);
}
- } catch (RuntimeException ex) {
+ } catch (final RuntimeException ex) {
throw propagateException(nextSourceCtx, ex);
}
}
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Predicate;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
}
public final BuildAction newBuild() {
- return newBuild(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
+ return newBuild(StatementParserMode.DEFAULT_MODE);
}
- public final BuildAction newBuild(final Predicate<QName> isFeatureSupported) {
- return new BuildAction(StatementParserMode.DEFAULT_MODE, isFeatureSupported);
+ public final BuildAction newBuild(final Set<QName> supportedFeatures) {
+ return new BuildAction(StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
public final BuildAction newBuild(final StatementParserMode statementParserMode) {
- return new BuildAction(statementParserMode, IfFeaturePredicates.ALL_FEATURES);
+ return new BuildAction(statementParserMode, null);
}
public final BuildAction newBuild(final StatementParserMode statementParserMode,
- final Predicate<QName> isFeatureSupported) {
- return new BuildAction(statementParserMode, isFeatureSupported);
+ final Set<QName> supportedFeatures) {
+ return new BuildAction(statementParserMode, supportedFeatures);
}
public static class Builder implements org.opendaylight.yangtools.concepts.Builder<CrossSourceStatementReactor> {
private final BuildGlobalContext context;
public BuildAction() {
- this(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
+ this(StatementParserMode.DEFAULT_MODE);
}
public BuildAction(final StatementParserMode statementParserMode) {
- this(statementParserMode, IfFeaturePredicates.ALL_FEATURES);
+ this(statementParserMode, null);
}
- public BuildAction(final Predicate<QName> isFeatureSupported) {
- this(StatementParserMode.DEFAULT_MODE, isFeatureSupported);
+ public BuildAction(final Set<QName> supportedFeatures) {
+ this(StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
- public BuildAction(final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported) {
+ public BuildAction(final StatementParserMode statementParserMode, final Set<QName> supportedFeatures) {
this.context = new BuildGlobalContext(supportedTerminology, supportedValidation, statementParserMode,
- isFeatureSupported);
+ supportedFeatures);
}
public void addSource(final StatementStreamSource source) {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import javax.annotation.Nonnull;
+import com.google.common.base.Preconditions;
+import java.util.Set;
+import java.util.function.Predicate;
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionLexer;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParser;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParser.Identifier_ref_argContext;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParser.If_feature_exprContext;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParser.If_feature_factorContext;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParser.If_feature_termContext;
+import org.opendaylight.yangtools.antlrv4.code.gen.IfFeatureExpressionParserBaseVisitor;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IfFeatureEffectiveStatementImpl;
-public class IfFeatureStatementImpl extends AbstractDeclaredStatement<QName>
+public class IfFeatureStatementImpl extends AbstractDeclaredStatement<Predicate<Set<QName>>>
implements IfFeatureStatement {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
.IF_FEATURE)
.build();
protected IfFeatureStatementImpl(
- final StmtContext<QName, IfFeatureStatement, ?> context) {
+ final StmtContext<Predicate<Set<QName>>, IfFeatureStatement, ?> context) {
super(context);
}
public static class Definition
extends
- AbstractStatementSupport<QName, IfFeatureStatement, EffectiveStatement<QName, IfFeatureStatement>> {
+ AbstractStatementSupport<Predicate<Set<QName>>, IfFeatureStatement, EffectiveStatement<Predicate<Set<QName>>, IfFeatureStatement>> {
public Definition() {
super(YangStmtMapping.IF_FEATURE);
}
@Override
- public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return Utils.qNameFromArgument(ctx, value);
+ public Predicate<Set<QName>> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ if(YangVersion.VERSION_1_1.equals(ctx.getRootVersion())) {
+ return parseIfFeatureExpression(ctx, value);
+ } else {
+ final QName qName = Utils.qNameFromArgument(ctx, value);
+ return setQNames -> setQNames.contains(qName);
+ }
}
@Override
public IfFeatureStatement createDeclared(
- final StmtContext<QName, IfFeatureStatement, ?> ctx) {
+ final StmtContext<Predicate<Set<QName>>, IfFeatureStatement, ?> ctx) {
return new IfFeatureStatementImpl(ctx);
}
@Override
- public EffectiveStatement<QName, IfFeatureStatement> createEffective(
- final StmtContext<QName, IfFeatureStatement, EffectiveStatement<QName, IfFeatureStatement>> ctx) {
+ public EffectiveStatement<Predicate<Set<QName>>, IfFeatureStatement> createEffective(
+ final StmtContext<Predicate<Set<QName>>, IfFeatureStatement, EffectiveStatement<Predicate<Set<QName>>, IfFeatureStatement>> ctx) {
return new IfFeatureEffectiveStatementImpl(ctx);
}
protected SubstatementValidator getSubstatementValidator() {
return SUBSTATEMENT_VALIDATOR;
}
+
+ private static Predicate<Set<QName>> parseIfFeatureExpression(final StmtContext<?, ?, ?> ctx, final String value) {
+ final IfFeatureExpressionLexer lexer = new IfFeatureExpressionLexer(new ANTLRInputStream(value));
+ final CommonTokenStream tokens = new CommonTokenStream(lexer);
+ final IfFeatureExpressionParser parser = new IfFeatureExpressionParser(tokens);
+
+ return new IfFeaturePredicateVisitor(ctx).visit(parser.if_feature_expr());
+ }
+
+ private static class IfFeaturePredicateVisitor extends IfFeatureExpressionParserBaseVisitor<Predicate<Set<QName>>> {
+ private final StmtContext<?, ?, ?> stmtCtx;
+
+ public IfFeaturePredicateVisitor(final StmtContext<?, ?, ?> ctx) {
+ this.stmtCtx = Preconditions.checkNotNull(ctx);
+ }
+
+ @Override
+ public Predicate<Set<QName>> visitIf_feature_expr(final If_feature_exprContext ctx) {
+ if (ctx.if_feature_expr() != null) {
+ return visitIf_feature_term(ctx.if_feature_term()).or(visitIf_feature_expr(ctx.if_feature_expr()));
+ } else {
+ return visitIf_feature_term(ctx.if_feature_term());
+ }
+ }
+
+ @Override
+ public Predicate<Set<QName>> visitIf_feature_term(final If_feature_termContext ctx) {
+ if (ctx.if_feature_term() != null) {
+ return visitIf_feature_factor(ctx.if_feature_factor()).and(visitIf_feature_term(ctx.if_feature_term()));
+ } else {
+ return visitIf_feature_factor(ctx.if_feature_factor());
+ }
+ }
+
+ @Override
+ public Predicate<Set<QName>> visitIf_feature_factor(final If_feature_factorContext ctx) {
+ if (ctx.if_feature_expr() != null) {
+ return visitIf_feature_expr(ctx.if_feature_expr());
+ } else if (ctx.if_feature_factor() != null) {
+ return visitIf_feature_factor(ctx.if_feature_factor()).negate();
+ } else if (ctx.identifier_ref_arg() != null) {
+ return visitIdentifier_ref_arg(ctx.identifier_ref_arg());
+ }
+
+ throw new SourceException("Unexpected grammar context during parsing of IfFeature expression. "
+ + "Most probably IfFeature grammar has been changed.", stmtCtx.getStatementSourceReference());
+ }
+
+ @Override
+ public Predicate<Set<QName>> visitIdentifier_ref_arg(final Identifier_ref_argContext ctx) {
+ final QName featureQName = Utils.qNameFromArgument(stmtCtx, ctx.getText());
+ return setQNames -> setQNames.contains(featureQName);
+ }
+ }
}
- @Nonnull
@Override
- public QName getName() {
+ public Predicate<Set<QName>> getIfFeaturePredicate() {
return argument();
}
-
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import java.util.Set;
+import java.util.function.Predicate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public final class IfFeatureEffectiveStatementImpl extends DeclaredEffectiveStatementBase<QName, IfFeatureStatement> {
- public IfFeatureEffectiveStatementImpl(final StmtContext<QName, IfFeatureStatement, ?> ctx) {
+public final class IfFeatureEffectiveStatementImpl extends DeclaredEffectiveStatementBase<Predicate<Set<QName>>, IfFeatureStatement> {
+ public IfFeatureEffectiveStatementImpl(final StmtContext<Predicate<Set<QName>>, IfFeatureStatement, ?> ctx) {
super(ctx);
}
}
\ No newline at end of file
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.CheckedFuture;
-import java.util.HashSet;
import java.util.Set;
-import java.util.function.Predicate;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@Test
public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
- Predicate<QName> isFeatureSupported = qName -> {
- Set<QName> supportedFeatures = new HashSet<>();
- supportedFeatures.add(QName.create("foobar-namespace", "1970-01-01", "test-feature-1"));
-
- return supportedFeatures.contains(qName);
- };
+ final Set<QName> supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "1970-01-01", "test-feature-1"));
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
"shared-schema-repo-with-features-test");
.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
final CheckedFuture<SchemaContext, SchemaResolutionException> testSchemaContextFuture =
- fact.createSchemaContext(Lists.newArrayList(foobar.getId()), isFeatureSupported);
+ fact.createSchemaContext(Lists.newArrayList(foobar.getId()), supportedFeatures);
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
- Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+ final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
assertNotNull(module);
assertEquals(2, module.getChildNodes().size());
- ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-a"));
assertNotNull(testContainerA);
- LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
+ final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-a"));
assertNotNull(testLeafA);
- ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-b"));
assertNull(testContainerB);
- ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
- LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
+ final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
}
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
- Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+ final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
assertNotNull(module);
assertEquals(3, module.getChildNodes().size());
- ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-a"));
assertNotNull(testContainerA);
- LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
+ final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-a"));
assertNotNull(testLeafA);
- ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-b"));
assertNotNull(testContainerB);
- LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
+ final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-b"));
assertNotNull(testLeafB);
- ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
- LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
+ final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
}
@Test
public void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
- Predicate<QName> isFeatureSupported = qName -> false;
+ final Set<QName> supportedFeatures = ImmutableSet.of();
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
"shared-schema-repo-with-features-test");
.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
final CheckedFuture<SchemaContext, SchemaResolutionException> testSchemaContextFuture = fact
- .createSchemaContext(Lists.newArrayList(foobar.getId()), isFeatureSupported);
+ .createSchemaContext(Lists.newArrayList(foobar.getId()), supportedFeatures);
assertTrue(testSchemaContextFuture.isDone());
assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
- Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+ final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
assertNotNull(module);
assertEquals(1, module.getChildNodes().size());
- ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
+ final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(
QName.create(module.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
- LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
+ final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
QName.create(module.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.stmt.rfc7950;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+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.SchemaPath;
+import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+
+public class Bug6868Test {
+ private static final String FOO_NS = "foo";
+ private static final String FOO_REV = "1970-01-01";
+ private static final String IMP_NS = "imp";
+ private static final String IMP_REV = "2017-01-09";
+ private static final Set<String> ALL_CONTAINERS = ImmutableSet.of("my-container-1", "my-container-2",
+ "my-container-3", "foo", "not-foo", "imp-bar", "imp-bar-2");
+
+ @Test
+ public void ifFeatureYang11ResolutionTest() throws ReactorException, SourceException, FileNotFoundException,
+ URISyntaxException {
+ assertSchemaContextFor(null, ALL_CONTAINERS);
+ assertSchemaContextFor(ImmutableSet.of(), ImmutableSet.of("my-container-1", "my-container-2", "not-foo"));
+ assertSchemaContextFor(ImmutableSet.of("foo"), ImmutableSet.of("foo"));
+ assertSchemaContextFor(ImmutableSet.of("baz"),
+ ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
+ assertSchemaContextFor(ImmutableSet.of("bar", "baz"),
+ ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "not-foo"));
+ assertSchemaContextFor(ImmutableSet.of("foo", "bar", "baz"),
+ ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo"));
+ assertSchemaContextFor(ImmutableSet.of("foo", "bar", "baz", "imp:bar"),
+ ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo", "imp-bar"));
+ assertSchemaContextFor(ImmutableSet.of("foo", "baz", "imp:bar"), ImmutableSet.of("foo", "imp-bar", "imp-bar-2"));
+ }
+
+ private static void assertSchemaContextFor(final Set<String> supportedFeatures, final Set<String> expectedContainers)
+ throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6868/yang11",
+ supportedFeatures != null ? createFeaturesSet(supportedFeatures) : null,
+ StatementParserMode.DEFAULT_MODE);
+ assertNotNull(schemaContext);
+
+ for (final String expectedContainer : expectedContainers) {
+ assertTrue(String.format("Expected container %s not found.", expectedContainer),
+ findNode(schemaContext, expectedContainer) instanceof ContainerSchemaNode);
+ }
+
+ final Set<String> unexpectedContainers = Sets.difference(ALL_CONTAINERS, expectedContainers);
+ for (final String unexpectedContainer : unexpectedContainers) {
+ assertNull(String.format("Unexpected container %s.", unexpectedContainer),
+ findNode(schemaContext, unexpectedContainer));
+ }
+ }
+
+ private static Set<QName> createFeaturesSet(final Set<String> featureNames) {
+ final Set<QName> supportedFeatures = new HashSet<>();
+ for (final String featureName : featureNames) {
+ if (featureName.indexOf(':') == -1) {
+ supportedFeatures.add(QName.create(FOO_NS, FOO_REV, featureName));
+ } else {
+ supportedFeatures
+ .add(QName.create(IMP_NS, IMP_REV, featureName.substring(featureName.indexOf(':') + 1)));
+ }
+ }
+
+ return ImmutableSet.copyOf(supportedFeatures);
+ }
+
+ private static SchemaNode findNode(final SchemaContext context, final String localName) {
+ return SchemaContextUtil.findDataSchemaNode(context,
+ SchemaPath.create(true, QName.create(FOO_NS, FOO_REV, localName)));
+ }
+
+ @Test
+ public void invalidYang10Test() throws ReactorException, SourceException, FileNotFoundException, URISyntaxException {
+ try {
+ StmtTestUtils.parseYangSource("/rfc7950/bug6868/invalid10.yang");
+ fail("Test should fail due to invalid Yang 1.0");
+ } catch (final SomeModifiersUnresolvedException e) {
+ assertTrue(e.getCause().getMessage()
+ .startsWith("Parameter 'localName':'(not foo) or (bar and baz)' contains illegal character '('"));
+ }
+ }
+}
\ No newline at end of file
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Set;
-import java.util.function.Predicate;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
public void identityNoFeaureTest() throws ReactorException, SourceException, FileNotFoundException,
URISyntaxException {
final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
- createIfFeaturesPredicate("no-feature"));
+ ImmutableSet.of());
assertNotNull(schemaContext);
final Set<IdentitySchemaNode> identities = getIdentities(schemaContext);
public void identityAllFeauresTest() throws ReactorException, SourceException, FileNotFoundException,
URISyntaxException {
final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
- createIfFeaturesPredicate("identity-feature", "mandatory-leaf", "tls", "ssh", "two", "three"));
+ createFeaturesSet("identity-feature", "mandatory-leaf", "tls", "ssh", "two", "three"));
assertNotNull(schemaContext);
final Set<IdentitySchemaNode> identities = getIdentities(schemaContext);
return module.getIdentities();
}
- private static Predicate<QName> createIfFeaturesPredicate(final String... featureNames) {
- final Predicate<QName> ifFeaturesPredicate = qName -> {
- final Set<QName> supportedFeatures = new HashSet<>();
- for (final String featureName : featureNames) {
- supportedFeatures.add(QName.create(FOO_NS, FOO_REV, featureName));
- }
- return supportedFeatures.contains(qName);
- };
- return ifFeaturesPredicate;
+ private static Set<QName> createFeaturesSet(final String... featureNames) {
+ final Set<QName> supportedFeatures = new HashSet<>();
+ for (final String featureName : featureNames) {
+ supportedFeatures.add(QName.create(FOO_NS, FOO_REV, featureName));
+ }
+
+ return ImmutableSet.copyOf(supportedFeatures);
}
private static SchemaNode findNode(final SchemaContext context, final Iterable<String> localNamesPath) {
import java.util.Collection;
import java.util.Date;
import java.util.Set;
+import java.util.function.Predicate;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
@Test
public void testDeclaredAnyXml() throws ReactorException {
- YangStatementSourceImpl anyxmlStmtModule =
+ final YangStatementSourceImpl anyxmlStmtModule =
new YangStatementSourceImpl("/declared-statements-test/anyxml-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(anyxmlStmtModule);
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("anyxml-declared-test", null);
+ final Module testModule = schemaContext.findModuleByName("anyxml-declared-test", null);
assertNotNull(testModule);
- AnyXmlSchemaNode anyxmlSchemaNode = (AnyXmlSchemaNode) testModule.getDataChildByName(
+ final AnyXmlSchemaNode anyxmlSchemaNode = (AnyXmlSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "foobar"));
assertNotNull(anyxmlSchemaNode);
- AnyxmlStatement anyxmlStatement = ((AnyXmlEffectiveStatementImpl) anyxmlSchemaNode).getDeclared();
+ final AnyxmlStatement anyxmlStatement = ((AnyXmlEffectiveStatementImpl) anyxmlSchemaNode).getDeclared();
- QName name = anyxmlStatement.getName();
+ final QName name = anyxmlStatement.getName();
assertNotNull(name);
- WhenStatement whenStatement = anyxmlStatement.getWhenStatement();
+ final WhenStatement whenStatement = anyxmlStatement.getWhenStatement();
assertNotNull(whenStatement);
- RevisionAwareXPath whenRevisionAwareXPath = whenStatement.getCondition();
+ final RevisionAwareXPath whenRevisionAwareXPath = whenStatement.getCondition();
assertNotNull(whenRevisionAwareXPath);
- DescriptionStatement whenStatementDescription = whenStatement.getDescription();
+ final DescriptionStatement whenStatementDescription = whenStatement.getDescription();
assertNotNull(whenStatementDescription);
- ReferenceStatement whenStatementReference = whenStatement.getReference();
+ final ReferenceStatement whenStatementReference = whenStatement.getReference();
assertNotNull(whenStatementReference);
- Collection<? extends IfFeatureStatement> ifFeatureStatements = anyxmlStatement.getIfFeatures();
+ final Collection<? extends IfFeatureStatement> ifFeatureStatements = anyxmlStatement.getIfFeatures();
assertNotNull(ifFeatureStatements);
assertEquals(1, ifFeatureStatements.size());
- QName ifFeatureName = ifFeatureStatements.iterator().next().getName();
- assertNotNull(ifFeatureName);
+ final Predicate<Set<QName>> ifFeaturePredicate = ifFeatureStatements.iterator().next().getIfFeaturePredicate();
+ assertNotNull(ifFeaturePredicate);
- Collection<? extends MustStatement> mustStatements = anyxmlStatement.getMusts();
+ final Collection<? extends MustStatement> mustStatements = anyxmlStatement.getMusts();
assertNotNull(mustStatements);
assertEquals(1, mustStatements.size());
- MustStatement mustStatement = mustStatements.iterator().next();
- RevisionAwareXPath mustRevisionAwareXPath = mustStatement.getCondition();
+ final MustStatement mustStatement = mustStatements.iterator().next();
+ final RevisionAwareXPath mustRevisionAwareXPath = mustStatement.getCondition();
assertNotNull(mustRevisionAwareXPath);
- ErrorAppTagStatement errorAppTagStatement = mustStatement.getErrorAppTagStatement();
+ final ErrorAppTagStatement errorAppTagStatement = mustStatement.getErrorAppTagStatement();
assertNotNull(errorAppTagStatement);
- ErrorMessageStatement errorMessageStatement = mustStatement.getErrorMessageStatement();
+ final ErrorMessageStatement errorMessageStatement = mustStatement.getErrorMessageStatement();
assertNotNull(errorMessageStatement);
- DescriptionStatement mustStatementDescription = mustStatement.getDescription();
+ final DescriptionStatement mustStatementDescription = mustStatement.getDescription();
assertNotNull(mustStatementDescription);
- ReferenceStatement mustStatementReference = mustStatement.getReference();
+ final ReferenceStatement mustStatementReference = mustStatement.getReference();
assertNotNull(mustStatementReference);
- ConfigStatement configStatement = anyxmlStatement.getConfig();
+ final ConfigStatement configStatement = anyxmlStatement.getConfig();
assertNotNull(configStatement);
assertFalse(configStatement.getValue());
- StatusStatement statusStatement = anyxmlStatement.getStatus();
+ final StatusStatement statusStatement = anyxmlStatement.getStatus();
assertNotNull(statusStatement);
- Status status = statusStatement.getValue();
+ final Status status = statusStatement.getValue();
assertNotNull(status);
- DescriptionStatement descriptionStatement = anyxmlStatement.getDescription();
+ final DescriptionStatement descriptionStatement = anyxmlStatement.getDescription();
assertNotNull(descriptionStatement);
assertEquals("anyxml description", descriptionStatement.getText());
- ReferenceStatement referenceStatement = anyxmlStatement.getReference();
+ final ReferenceStatement referenceStatement = anyxmlStatement.getReference();
assertNotNull(referenceStatement);
assertEquals("anyxml reference", referenceStatement.getText());
- MandatoryStatement mandatoryStatement = anyxmlStatement.getMandatory();
+ final MandatoryStatement mandatoryStatement = anyxmlStatement.getMandatory();
assertNotNull(mandatoryStatement);
}
@Test
public void testDeclaredChoice() throws ReactorException {
- YangStatementSourceImpl choiceStmtModule =
+ final YangStatementSourceImpl choiceStmtModule =
new YangStatementSourceImpl("/declared-statements-test/choice-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(choiceStmtModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(choiceStmtModule);
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("choice-declared-test", null);
+ final Module testModule = schemaContext.findModuleByName("choice-declared-test", null);
assertNotNull(testModule);
- ChoiceSchemaNode choiceSchemaNode = (ChoiceSchemaNode) testModule.getDataChildByName(
+ final ChoiceSchemaNode choiceSchemaNode = (ChoiceSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-choice"));
assertNotNull(choiceSchemaNode);
- ChoiceStatement choiceStatement = ((ChoiceEffectiveStatementImpl) choiceSchemaNode).getDeclared();
+ final ChoiceStatement choiceStatement = ((ChoiceEffectiveStatementImpl) choiceSchemaNode).getDeclared();
- QName name = choiceStatement.getName();
+ final QName name = choiceStatement.getName();
assertNotNull(name);
- DefaultStatement defaultStatement = choiceStatement.getDefault();
+ final DefaultStatement defaultStatement = choiceStatement.getDefault();
assertNotNull(defaultStatement);
assertEquals("case-two", defaultStatement.getValue());
- ConfigStatement configStatement = choiceStatement.getConfig();
+ final ConfigStatement configStatement = choiceStatement.getConfig();
assertNotNull(configStatement);
- MandatoryStatement mandatoryStatement = choiceStatement.getMandatory();
+ final MandatoryStatement mandatoryStatement = choiceStatement.getMandatory();
assertNotNull(mandatoryStatement);
- Collection<? extends CaseStatement> caseStatements = choiceStatement.getCases();
+ final Collection<? extends CaseStatement> caseStatements = choiceStatement.getCases();
assertNotNull(caseStatements);
assertEquals(3, caseStatements.size());
- CaseStatement caseStatement = caseStatements.iterator().next();
- QName caseStatementName = caseStatement.getName();
+ final CaseStatement caseStatement = caseStatements.iterator().next();
+ final QName caseStatementName = caseStatement.getName();
assertNotNull(caseStatementName);
- WhenStatement caseStatementWhen = caseStatement.getWhenStatement();
+ final WhenStatement caseStatementWhen = caseStatement.getWhenStatement();
assertNotNull(caseStatementWhen);
- Collection<? extends IfFeatureStatement> caseStatementIfFeatures = caseStatement.getIfFeatures();
+ final Collection<? extends IfFeatureStatement> caseStatementIfFeatures = caseStatement.getIfFeatures();
assertNotNull(caseStatementIfFeatures);
assertEquals(1, caseStatementIfFeatures.size());
- Collection<? extends DataDefinitionStatement> caseStatementDataDefinitions = caseStatement.getDataDefinitions();
+ final Collection<? extends DataDefinitionStatement> caseStatementDataDefinitions = caseStatement.getDataDefinitions();
assertNotNull(caseStatementDataDefinitions);
assertEquals(1, caseStatementDataDefinitions.size());
- StatusStatement caseStatementStatus = caseStatement.getStatus();
+ final StatusStatement caseStatementStatus = caseStatement.getStatus();
assertNotNull(caseStatementStatus);
- DescriptionStatement caseStatementDescription = caseStatement.getDescription();
+ final DescriptionStatement caseStatementDescription = caseStatement.getDescription();
assertNotNull(caseStatementDescription);
- ReferenceStatement caseStatementReference = caseStatement.getReference();
+ final ReferenceStatement caseStatementReference = caseStatement.getReference();
assertNotNull(caseStatementReference);
- WhenStatement whenStatement = choiceStatement.getWhenStatement();
+ final WhenStatement whenStatement = choiceStatement.getWhenStatement();
assertNotNull(whenStatement);
- Collection<? extends IfFeatureStatement> ifFeatureStatements = choiceStatement.getIfFeatures();
+ final Collection<? extends IfFeatureStatement> ifFeatureStatements = choiceStatement.getIfFeatures();
assertNotNull(ifFeatureStatements);
assertEquals(1, ifFeatureStatements.size());
- StatusStatement statusStatement = choiceStatement.getStatus();
+ final StatusStatement statusStatement = choiceStatement.getStatus();
assertNotNull(statusStatement);
- DescriptionStatement descriptionStatement = choiceStatement.getDescription();
+ final DescriptionStatement descriptionStatement = choiceStatement.getDescription();
assertNotNull(descriptionStatement);
- ReferenceStatement referenceStatement = choiceStatement.getReference();
+ final ReferenceStatement referenceStatement = choiceStatement.getReference();
assertNotNull(referenceStatement);
}
@Test
public void testDeclaredAugment() throws ReactorException {
- YangStatementSourceImpl augmentStmtModule =
+ final YangStatementSourceImpl augmentStmtModule =
new YangStatementSourceImpl("/declared-statements-test/augment-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(augmentStmtModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(augmentStmtModule);
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("augment-declared-test", null);
+ final Module testModule = schemaContext.findModuleByName("augment-declared-test", null);
assertNotNull(testModule);
- Set<AugmentationSchema> augmentationSchemas = testModule.getAugmentations();
+ final Set<AugmentationSchema> augmentationSchemas = testModule.getAugmentations();
assertNotNull(augmentationSchemas);
assertEquals(1, augmentationSchemas.size());
- AugmentationSchema augmentationSchema = augmentationSchemas.iterator().next();
- AugmentStatement augmentStatement = ((AugmentEffectiveStatementImpl) augmentationSchema).getDeclared();
+ final AugmentationSchema augmentationSchema = augmentationSchemas.iterator().next();
+ final AugmentStatement augmentStatement = ((AugmentEffectiveStatementImpl) augmentationSchema).getDeclared();
- SchemaNodeIdentifier targetNode = augmentStatement.getTargetNode();
+ final SchemaNodeIdentifier targetNode = augmentStatement.getTargetNode();
assertNotNull(targetNode);
- Collection<? extends DataDefinitionStatement> augmentStatementDataDefinitions =
+ final Collection<? extends DataDefinitionStatement> augmentStatementDataDefinitions =
augmentStatement.getDataDefinitions();
assertNotNull(augmentStatementDataDefinitions);
assertEquals(1, augmentStatementDataDefinitions.size());
@Test
public void testDeclaredModuleAndSubmodule() throws ReactorException {
- YangStatementSourceImpl parentModule =
+ final YangStatementSourceImpl parentModule =
new YangStatementSourceImpl("/declared-statements-test/parent-module-declared-test.yang", false);
- YangStatementSourceImpl childModule =
+ final YangStatementSourceImpl childModule =
new YangStatementSourceImpl("/declared-statements-test/child-module-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("parent-module-declared-test", null);
+ final Module testModule = schemaContext.findModuleByName("parent-module-declared-test", null);
assertNotNull(testModule);
- ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
+ final ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
- String moduleStatementName = moduleStatement.getName();
+ final String moduleStatementName = moduleStatement.getName();
assertNotNull(moduleStatementName);
- YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
+ final YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
assertNotNull(moduleStatementYangVersion);
assertNotNull(moduleStatementYangVersion.getValue());
- NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
+ final NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
assertNotNull(moduleStatementNamspace);
assertNotNull(moduleStatementNamspace.getUri());
- PrefixStatement moduleStatementPrefix= moduleStatement.getPrefix();
+ final PrefixStatement moduleStatementPrefix= moduleStatement.getPrefix();
assertNotNull(moduleStatementPrefix);
assertNotNull(moduleStatementPrefix.getValue());
assertEquals(1, moduleStatement.getIncludes().size());
- IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
+ final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
assertEquals("child-module-declared-test", includeStatement.getModule());
- Set<Module> submodules = testModule.getSubmodules();
+ final Set<Module> submodules = testModule.getSubmodules();
assertNotNull(submodules);
assertEquals(1, submodules.size());
- Module submodule = submodules.iterator().next();
- SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatementImpl) submodule).getDeclared();
+ final Module submodule = submodules.iterator().next();
+ final SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatementImpl) submodule).getDeclared();
- String submoduleStatementName = submoduleStatement.getName();
+ final String submoduleStatementName = submoduleStatement.getName();
assertNotNull(submoduleStatementName);
- YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
+ final YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
assertNotNull(submoduleStatementYangVersion);
- BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
+ final BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
assertNotNull(belongsToStatement);
assertNotNull(belongsToStatement.getModule());
assertNotNull(belongsToStatement.getPrefix());
@Test
public void testDeclaredModule() throws ReactorException, ParseException {
- YangStatementSourceImpl rootModule =
+ final YangStatementSourceImpl rootModule =
new YangStatementSourceImpl("/declared-statements-test/root-module-declared-test.yang", false);
- YangStatementSourceImpl importedModule =
+ final YangStatementSourceImpl importedModule =
new YangStatementSourceImpl("/declared-statements-test/imported-module-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
assertNotNull(schemaContext);
- Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-09-28");
+ final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-09-28");
- Module testModule = schemaContext.findModuleByName("root-module-declared-test", revision);
+ final Module testModule = schemaContext.findModuleByName("root-module-declared-test", revision);
assertNotNull(testModule);
- ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
+ final ModuleStatement moduleStatement = ((ModuleEffectiveStatementImpl) testModule).getDeclared();
assertEquals(1, moduleStatement.getImports().size());
- ImportStatement importStatement = moduleStatement.getImports().iterator().next();
+ final ImportStatement importStatement = moduleStatement.getImports().iterator().next();
assertEquals("imported-module-declared-test", importStatement.getModule());
assertEquals("imdt", importStatement.getPrefix().getValue());
assertEquals(revision, importStatement.getRevisionDate().getDate());
assertEquals("test contact", moduleStatement.getContact().getText());
assertEquals(1, moduleStatement.getRevisions().size());
- RevisionStatement revisionStatement = moduleStatement.getRevisions().iterator().next();
+ final RevisionStatement revisionStatement = moduleStatement.getRevisions().iterator().next();
assertEquals(revision, revisionStatement.getDate());
assertEquals("test description", revisionStatement.getDescription().getText());
assertEquals("test reference", revisionStatement.getReference().getText());
assertEquals(1, moduleStatement.getExtensions().size());
- ExtensionStatement extensionStatement = moduleStatement.getExtensions().iterator().next();
+ final ExtensionStatement extensionStatement = moduleStatement.getExtensions().iterator().next();
assertEquals(Status.CURRENT, extensionStatement.getStatus().getValue());
assertEquals("test description", extensionStatement.getDescription().getText());
assertEquals("test reference", extensionStatement.getReference().getText());
- ArgumentStatement argumentStatement = extensionStatement.getArgument();
+ final ArgumentStatement argumentStatement = extensionStatement.getArgument();
assertEquals("ext-argument", argumentStatement.getName().getLocalName());
assertTrue(argumentStatement.getYinElement().getValue());
assertEquals(1, moduleStatement.getFeatures().size());
- FeatureStatement featureStatement = moduleStatement.getFeatures().iterator().next();
+ final FeatureStatement featureStatement = moduleStatement.getFeatures().iterator().next();
assertEquals(Status.CURRENT, featureStatement.getStatus().getValue());
assertEquals("test description", featureStatement.getDescription().getText());
assertEquals("test reference", featureStatement.getReference().getText());
assertEquals(2, moduleStatement.getIdentities().size());
IdentityStatement identityStatement = null;
- for (IdentityStatement identity : moduleStatement.getIdentities()) {
+ for (final IdentityStatement identity : moduleStatement.getIdentities()) {
if (identity.getName().getLocalName().equals("test-id")) {
identityStatement = identity;
}
assertEquals("test-id", identityStatement.getName().getLocalName());
assertEquals(1, moduleStatement.getTypedefs().size());
- TypedefStatement typedefStatement = moduleStatement.getTypedefs().iterator().next();
+ final TypedefStatement typedefStatement = moduleStatement.getTypedefs().iterator().next();
assertEquals(Status.CURRENT, typedefStatement.getStatus().getValue());
assertEquals("test description", typedefStatement.getDescription().getText());
assertEquals("test reference", typedefStatement.getReference().getText());
@Test
public void testDeclaredContainer() throws ReactorException {
- YangStatementSourceImpl containerStmtModule =
+ final YangStatementSourceImpl containerStmtModule =
new YangStatementSourceImpl("/declared-statements-test/container-declared-test.yang", false);
- SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(containerStmtModule);
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("container-declared-test", null);
+ final Module testModule = schemaContext.findModuleByName("container-declared-test", null);
assertNotNull(testModule);
- ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container"));
assertNotNull(containerSchemaNode);
- ContainerStatement containerStatement = ((ContainerEffectiveStatementImpl) containerSchemaNode).getDeclared();
+ final ContainerStatement containerStatement = ((ContainerEffectiveStatementImpl) containerSchemaNode).getDeclared();
- QName name = containerStatement.getName();
+ final QName name = containerStatement.getName();
assertNotNull(name);
- WhenStatement containerStatementWhen = containerStatement.getWhenStatement();
+ final WhenStatement containerStatementWhen = containerStatement.getWhenStatement();
assertNotNull(containerStatementWhen);
- Collection<? extends IfFeatureStatement> containerStatementIfFeatures = containerStatement.getIfFeatures();
+ final Collection<? extends IfFeatureStatement> containerStatementIfFeatures = containerStatement.getIfFeatures();
assertNotNull(containerStatementIfFeatures);
assertEquals(1, containerStatementIfFeatures.size());
- Collection<? extends MustStatement> containerStatementMusts = containerStatement.getMusts();
+ final Collection<? extends MustStatement> containerStatementMusts = containerStatement.getMusts();
assertNotNull(containerStatementMusts);
assertEquals(1, containerStatementMusts.size());
- PresenceStatement containerStatementPresence = containerStatement.getPresence();
+ final PresenceStatement containerStatementPresence = containerStatement.getPresence();
assertNotNull(containerStatementPresence);
assertNotNull(containerStatementPresence.getValue());
- ConfigStatement containerStatementConfig = containerStatement.getConfig();
+ final ConfigStatement containerStatementConfig = containerStatement.getConfig();
assertNotNull(containerStatementConfig);
- StatusStatement containerStatementStatus = containerStatement.getStatus();
+ final StatusStatement containerStatementStatus = containerStatement.getStatus();
assertNotNull(containerStatementStatus);
- DescriptionStatement containerStatementDescription = containerStatement.getDescription();
+ final DescriptionStatement containerStatementDescription = containerStatement.getDescription();
assertNotNull(containerStatementDescription);
- ReferenceStatement containerStatementReference = containerStatement.getReference();
+ final ReferenceStatement containerStatementReference = containerStatement.getReference();
assertNotNull(containerStatementReference);
- Collection<? extends TypedefStatement> containerStatementTypedefs = containerStatement.getTypedefs();
+ final Collection<? extends TypedefStatement> containerStatementTypedefs = containerStatement.getTypedefs();
assertNotNull(containerStatementTypedefs);
assertEquals(1, containerStatementTypedefs.size());
- Collection<? extends GroupingStatement> containerStatementGroupings = containerStatement.getGroupings();
+ final Collection<? extends GroupingStatement> containerStatementGroupings = containerStatement.getGroupings();
assertNotNull(containerStatementGroupings);
assertEquals(1, containerStatementGroupings.size());
- Collection<? extends DataDefinitionStatement> containerStatementDataDefinitions =
+ final Collection<? extends DataDefinitionStatement> containerStatementDataDefinitions =
containerStatement.getDataDefinitions();
assertNotNull(containerStatementDataDefinitions);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import java.util.HashSet;
+import com.google.common.collect.ImmutableSet;
import java.util.Set;
-import java.util.function.Predicate;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
@Test
public void testSomeFeaturesSupported() throws ReactorException {
- Predicate<QName> isFeatureSupported = qName -> {
- Set<QName> supportedFeatures = new HashSet<>();
- supportedFeatures.add(QName.create("foo-namespace", "1970-01-01", "test-feature-1"));
- supportedFeatures.add(QName.create("foo-namespace", "1970-01-01", "test-feature-2"));
- supportedFeatures.add(QName.create("foo-namespace", "1970-01-01", "test-feature-3"));
- supportedFeatures.add(QName.create("bar-namespace", "1970-01-01", "imp-feature"));
+ final Set<QName> supportedFeatures = ImmutableSet.of(
+ QName.create("foo-namespace", "1970-01-01", "test-feature-1"),
+ QName.create("foo-namespace", "1970-01-01", "test-feature-2"),
+ QName.create("foo-namespace", "1970-01-01", "test-feature-3"),
+ QName.create("bar-namespace", "1970-01-01", "imp-feature"));
- return supportedFeatures.contains(qName);
- };
-
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(isFeatureSupported);
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
reactor.addSources(FOO_MODULE, BAR_MODULE);
- SchemaContext schemaContext = reactor.buildEffective();
+ final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("foo", null);
+ final Module testModule = schemaContext.findModuleByName("foo", null);
assertNotNull(testModule);
assertEquals(9, testModule.getChildNodes().size());
- ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-a"));
assertNull(testContainerA);
- ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-b"));
assertNotNull(testContainerB);
- LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
+ final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-b"));
assertNotNull(testLeafB);
- ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
- LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
+ final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
- ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-d"));
assertNull(testContainerD);
- ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
- ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
+ final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
- LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
+ final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNull(testLeafE);
- ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
- ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
+ final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNull(testSubContainerF);
- ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(1, testContainerG.getAvailableAugmentations().size());
- LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
- LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNull(augmentingTestLeafG);
- AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
+ final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
- ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(0, testContainerH.getChildNodes().size());
assertEquals(0, testContainerH.getUses().size());
- ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
- LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNull(testGroupingLeaf);
- ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-j"));
assertNotNull(testContainerJ);
- LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
+ final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-j"));
assertNotNull(testLeafJ);
- ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
- LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNotNull(augmentingTestGroupingLeaf);
- LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNull(augmentingTestGroupingLeaf2);
}
@Test
public void testAllFeaturesSupported() throws ReactorException {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
reactor.addSources(FOO_MODULE, BAR_MODULE);
- SchemaContext schemaContext = reactor.buildEffective();
+ final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("foo", null);
+ final Module testModule = schemaContext.findModuleByName("foo", null);
assertNotNull(testModule);
assertEquals(11, testModule.getChildNodes().size());
- ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-a"));
assertNotNull(testContainerA);
- LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
+ final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-a"));
assertNotNull(testLeafA);
- ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-b"));
assertNotNull(testContainerB);
- LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
+ final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-b"));
assertNotNull(testLeafB);
- ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-c"));
assertNotNull(testContainerC);
- LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
+ final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-c"));
assertNotNull(testLeafC);
- ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-d"));
assertNotNull(testContainerD);
- LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
+ final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-d"));
assertNotNull(testLeafD);
- ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
- ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
+ final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
- LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
+ final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNotNull(testLeafE);
- ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
- ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
+ final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNotNull(testSubContainerF);
- ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
+ final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
assertNotNull(testSubSubContainerF);
- LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
+ final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-f"));
assertNotNull(testLeafF);
- ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(2, testContainerG.getAvailableAugmentations().size());
- LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
- LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNotNull(augmentingTestLeafG);
- AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
+ final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
- ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(1, testContainerH.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNotNull(testGroupingLeaf);
- ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNotNull(testGroupingLeaf);
- ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-j"));
assertNotNull(testContainerJ);
- LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
+ final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-j"));
assertNotNull(testLeafJ);
- ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
- LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNotNull(augmentingTestGroupingLeaf);
- LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNotNull(augmentingTestGroupingLeaf2);
testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
@Test
public void testNoFeaturesSupported() throws ReactorException {
- Predicate<QName> isFeatureSupported = qName -> false;
+ final Set<QName> supportedFeatures = ImmutableSet.of();
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(isFeatureSupported);
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
reactor.addSources(FOO_MODULE, BAR_MODULE);
- SchemaContext schemaContext = reactor.buildEffective();
+ final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
- Module testModule = schemaContext.findModuleByName("foo", null);
+ final Module testModule = schemaContext.findModuleByName("foo", null);
assertNotNull(testModule);
assertEquals(6, testModule.getChildNodes().size());
- ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-e"));
assertNotNull(testContainerE);
- ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
+ final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
assertNotNull(testSubContainerE);
- LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
+ final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-e"));
assertNull(testLeafE);
- ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-f"));
assertNotNull(testContainerF);
- ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
+ final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
assertNull(testSubContainerF);
- ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-g"));
assertNotNull(testContainerG);
assertEquals(1, testContainerG.getAvailableAugmentations().size());
- LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-leaf-g"));
assertNotNull(testLeafG);
- LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
+ final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
assertNull(augmentingTestLeafG);
- AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
+ final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
assertNotNull(augmentingTestAnyxmlG);
- ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-h"));
assertNotNull(testContainerH);
assertEquals(0, testContainerH.getChildNodes().size());
assertEquals(0, testContainerH.getUses().size());
- ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-i"));
assertNotNull(testContainerI);
assertEquals(1, testContainerI.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
assertNull(testGroupingLeaf);
- ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
+ final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModule.getQNameModule(), "test-container-k"));
assertNotNull(testContainerK);
assertEquals(1, testContainerK.getUses().size());
QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
assertNotNull(testGroupingSubContainer);
assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
- LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
assertNull(augmentingTestGroupingLeaf);
- LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
+ final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
assertNull(augmentingTestGroupingLeaf2);
testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
import java.util.Collection;
import java.util.List;
import java.util.Set;
-import java.util.function.Predicate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public static SchemaContext parseYangSources(final StatementStreamSource... sources) throws SourceException,
ReactorException {
- return parseYangSources(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES, sources);
+ return parseYangSources(StatementParserMode.DEFAULT_MODE, null, sources);
}
- public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate, final StatementStreamSource... sources)
+ public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Set<QName> supportedFeatures, final StatementStreamSource... sources)
throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, ifFeaturePredicate);
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, supportedFeatures);
reactor.addSources(sources);
return reactor.buildEffective();
public static SchemaContext parseYangSources(final File... files) throws SourceException, ReactorException,
FileNotFoundException {
- return parseYangSources(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES, files);
+ return parseYangSources(StatementParserMode.DEFAULT_MODE, null, files);
}
- public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate, final File... files) throws SourceException,
+ public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Set<QName> supportedFeatures, final File... files) throws SourceException,
ReactorException, FileNotFoundException {
final StatementStreamSource[] sources = new StatementStreamSource[files.length];
sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
}
- return parseYangSources(statementParserMode, ifFeaturePredicate, sources);
+ return parseYangSources(statementParserMode, supportedFeatures, sources);
}
public static SchemaContext parseYangSources(final Collection<File> files) throws SourceException, ReactorException,
public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
throws SourceException, ReactorException, FileNotFoundException {
- return parseYangSources(statementParserMode, IfFeaturePredicates.ALL_FEATURES, files.toArray(new File[files.size()]));
+ return parseYangSources(statementParserMode, null, files.toArray(new File[files.size()]));
}
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws SourceException,
public static SchemaContext parseYangSource(final String yangSourcePath) throws SourceException, ReactorException,
FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
+ return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, null);
}
- public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> ifFeaturesPredicate)
+ public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
- return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, ifFeaturesPredicate);
+ return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
public static SchemaContext parseYangSource(final String yangSourcePath,
- final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate)
+ final StatementParserMode statementParserMode, final Set<QName> supportedFeatures)
throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
final URL source = StmtTestUtils.class.getResource(yangSourcePath);
final File sourceFile = new File(source.toURI());
- return parseYangSources(statementParserMode, ifFeaturePredicate, sourceFile);
+ return parseYangSources(statementParserMode, supportedFeatures, sourceFile);
}
- public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, final StatementParserMode statementParserMode)
- throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
+ public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
+ final StatementParserMode statementParserMode) throws SourceException, ReactorException,
+ FileNotFoundException, URISyntaxException {
+ return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
+ }
+
+ public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
+ final Set<QName> supportedFeatures, final StatementParserMode statementParserMode) throws SourceException,
+ ReactorException, FileNotFoundException, URISyntaxException {
final URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
final File testSourcesDir = new File(resourceDir.toURI());
- return parseYangSources(statementParserMode, IfFeaturePredicates.ALL_FEATURES, testSourcesDir.listFiles(YANG_FILE_FILTER));
+ return parseYangSources(statementParserMode, supportedFeatures, testSourcesDir.listFiles(YANG_FILE_FILTER));
}
public static SchemaContext parseYinSources(final String yinSourcesDirectoryPath, final StatementParserMode statementParserMode)
--- /dev/null
+module foo {
+ namespace "foo";
+ prefix foo;
+
+ container my-container-1 {
+ if-feature "(not foo) or (bar and baz)";
+ }
+
+ container my-container-2 {
+ if-feature "not foo or bar and baz";
+ }
+
+ container my-container-3 {
+ if-feature "(not foo or bar) and baz)";
+ }
+}
--- /dev/null
+module foo {
+ namespace "foo";
+ prefix foo;
+ yang-version 1.1;
+
+ import imported { prefix imp; revision-date 2017-01-09; }
+
+ feature foo;
+ feature bar;
+ feature baz;
+
+ container my-container-1 {
+ if-feature "(not foo) or (bar and baz)";
+ }
+
+ container my-container-2 {
+ if-feature "not foo or bar and baz";
+ }
+
+ container my-container-3 {
+ if-feature "((not foo or bar) and baz)";
+ }
+
+ container foo {
+ if-feature "foo";
+ }
+
+ container not-foo {
+ if-feature "not foo";
+ }
+
+ container imp-bar {
+ if-feature "imp:bar";
+ }
+
+ container imp-bar-2 {
+ if-feature "imp:bar and not bar";
+ }
+}
--- /dev/null
+module imported {
+ namespace "imp";
+ prefix imp;
+ yang-version 1;
+
+ revision "2017-01-09";
+
+ feature bar;
+}
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
-import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.BasicParser;
import org.apache.log4j.BasicConfigurator;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
/**
* Main class of Yang parser system test.
LOG.log(Level.INFO, "Yang model files: {0} ", yangFiles);
LOG.log(Level.INFO, "Supported features: {0} ", supportedFeatures);
- final Predicate<QName> isFeatureSupported = supportedFeatures == null ? IfFeaturePredicates.ALL_FEATURES
- : q -> supportedFeatures.contains(q);
SchemaContext context = null;
printMemoryInfo("start");
final Stopwatch stopWatch = Stopwatch.createStarted();
try {
- context = SystemTestUtils.parseYangSources(yangDirs, yangFiles, isFeatureSupported);
+ context = SystemTestUtils.parseYangSources(yangDirs, yangFiles, supportedFeatures);
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Failed to create SchemaContext.", e);
System.exit(1);
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.function.Predicate;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
}
};
- static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported)
+ static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
throws ReactorException, FileNotFoundException {
- return parseYangSources(files, StatementParserMode.DEFAULT_MODE, isFeatureSupported);
+ return parseYangSources(files, StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
static SchemaContext parseYangSources(final Collection<File> files,
- final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported)
+ final StatementParserMode statementParserMode, final Set<QName> supportedFeatures)
throws ReactorException, FileNotFoundException {
- return parseYangSources(isFeatureSupported, statementParserMode, files.toArray(new File[files.size()]));
+ return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
}
- static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
+ static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final File... files) throws ReactorException,
FileNotFoundException {
final YangStatementSourceImpl [] sources = new YangStatementSourceImpl[files.length];
sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
}
- return parseYangSources(isFeatureSupported, statementParserMode, sources);
+ return parseYangSources(supportedFeatures, statementParserMode, sources);
}
- static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
+ static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, isFeatureSupported);
+ statementParserMode, supportedFeatures);
reactor.addSources(sources);
return reactor.buildEffective();
}
static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final Predicate<QName> isFeatureSupported) throws FileNotFoundException, ReactorException {
+ final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException {
final List<File> allYangFiles = new ArrayList<>();
for (final String yangDir : yangDirs) {
allYangFiles.addAll(getYangFiles(yangDir));
allYangFiles.add(new File(yangFile));
}
- return parseYangSources(allYangFiles, isFeatureSupported);
+ return parseYangSources(allYangFiles, supportedFeatures);
}
private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) {
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.function.Predicate;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
*/
@Deprecated
public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
+ return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param sources YANG sources to be parsed
*
* @return effective schema context
* @deprecated Migration method only, do not use.
*/
@Deprecated
- public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
+ return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
}
/**
@Deprecated
public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
+ return parseYangSources(null, statementParserMode, sources);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param sources YANG sources to be parsed
*
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, isFeatureSupported);
+ statementParserMode, supportedFeatures);
reactor.addSources(sources);
return reactor.buildEffective();
* @throws FileNotFoundException if one of the specified files does not exist
*/
public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
- return parseYangSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, files);
+ return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param files YANG files to be parsed
*
* @return effective schema context
* @throws ReactorException if there is an error in one of the parsed YANG sources
* @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported, final File... files)
+ public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
throws ReactorException, FileNotFoundException {
- return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, files);
+ return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
}
/**
*/
public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
throws ReactorException, FileNotFoundException {
- return parseYangSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, files);
+ return parseYangSources(null, statementParserMode, files);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param files YANG files to be parsed
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
* @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final File... files) throws ReactorException,
FileNotFoundException {
final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
}
- return parseYangSources(isFeatureSupported, statementParserMode, sources);
+ return parseYangSources(supportedFeatures, statementParserMode, sources);
}
/**
*/
public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
FileNotFoundException {
- return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param files collection of YANG files to be parsed
*
* @return effective schema context
* @throws ReactorException if there is an error in one of the parsed YANG sources
* @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported)
+ public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
throws ReactorException, FileNotFoundException {
- return parseYangSources(files, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
*/
public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
throws ReactorException, FileNotFoundException {
- return parseYangSources(files, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ return parseYangSources(files, null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param files collection of YANG files to be parsed
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
* @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Collection<File> files, final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
- return parseYangSources(isFeatureSupported, statementParserMode, files.toArray(new File[files.size()]));
+ return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
}
/**
*/
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
FileNotFoundException, URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES,
- StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
}
/**
* default mode.
*
* @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
*
* @return effective schema context
*
* @throws URISyntaxException if the specified directory does not exist
*/
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
- final Predicate<QName> isFeatureSupported) throws ReactorException, FileNotFoundException,
+ final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
* @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
*
* @return effective schema context
* @throws URISyntaxException if the specified directory does not exist
*/
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
- final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
+ final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
throws ReactorException, FileNotFoundException, URISyntaxException {
final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
final File dir = new File(directoryPath);
- return parseYangSources(isFeatureSupported, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
+ return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
}
/**
*/
public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
+ return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
}
/**
* default mode.
*
* @param yangSourcePath relative path to the YANG file to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG model are resolved
*
* @return effective schema context
*
* @throws FileNotFoundException if the specified file does not exist
* @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported)
+ public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
throws ReactorException, FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
*/
public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
throws ReactorException, FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ return parseYangSource(yangSourcePath, null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG source.
*
* @param yangSourcePath relative path to the YANG file to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG model are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG model are resolved
* @param statementParserMode mode of statement parser
*
* @return effective schema context
* @throws FileNotFoundException if the specified file does not exist
* @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
URISyntaxException {
final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
final File sourceFile = new File(sourcePath);
- return parseYangSources(isFeatureSupported, statementParserMode, sourceFile);
+ return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
}
/**
*/
public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
throws FileNotFoundException, ReactorException, URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
}
/**
*
* @param yangDirs relative paths to the directories containing YANG files to be parsed
* @param yangFiles relative paths to the YANG files to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
*
* @return effective schema context
*
* @throws URISyntaxException if one of the specified directories or files does not exist
*/
public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final Predicate<QName> isFeatureSupported) throws FileNotFoundException, ReactorException,
+ final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
}
/**
*
* @param yangDirs relative paths to the directories containing YANG files to be parsed
* @param yangFiles relative paths to the YANG files to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
*
* @return effective schema context
* @throws URISyntaxException if one of the specified directories or files does not exist
*/
public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
+ final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
throws FileNotFoundException, ReactorException, URISyntaxException {
final List<File> allYangFiles = new ArrayList<>();
for (final String yangDir : yangDirs) {
allYangFiles.add(new File(filePath));
}
- return parseYangSources(allYangFiles, isFeatureSupported, statementParserMode);
+ return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
}
private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
- return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param filePaths relative paths to the YANG files to be parsed
*
* @return effective schema context
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final List<String> filePaths, final Predicate<QName> isFeatureSupported)
+ public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
throws ReactorException {
- return parseYangSources(filePaths, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final List<String> filePaths,final StatementParserMode statementParserMode)
- throws ReactorException {
- return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ public static SchemaContext parseYangSources(final List<String> filePaths,
+ final StatementParserMode statementParserMode) throws ReactorException {
+ return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param filePaths relative paths to the YANG files to be parsed
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
public static SchemaContext parseYangSources(final List<String> filePaths,
- final Predicate<QName> isFeatureSupported, final StatementParserMode statementParserMode)
+ final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
throws ReactorException {
final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
}
- return parseYangSources(isFeatureSupported, statementParserMode, sources);
+ return parseYangSources(supportedFeatures, statementParserMode, sources);
}
/**
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
- return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE);
+ return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
}
/**
* default mode.
*
* @param streams input streams containing YANG sources to be parsed
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
*
* @return effective schema context
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final List<InputStream> streams, final Predicate<QName> isFeatureSupported)
+ public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
throws ReactorException {
- return parseYangStreams(streams, isFeatureSupported, StatementParserMode.DEFAULT_MODE);
+ return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
*/
public static SchemaContext parseYangStreams(final List<InputStream> streams, final StatementParserMode statementParserMode)
throws ReactorException {
- return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, statementParserMode);
+ return parseYangStreams(streams, null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param streams input streams containing YANG sources to be parsed
*
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final List<InputStream> streams, final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode) throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, isFeatureSupported);
+ statementParserMode, supportedFeatures);
return reactor.buildEffective(streams);
}
public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
throws ReactorException {
final List<InputStream> streams = new ArrayList<>(resources.length);
- for (String r : resources) {
+ for (final String r : resources) {
final InputStream is = clazz.getResourceAsStream(r);
Preconditions.checkArgument(is != null, "Resource %s not found", r);
streams.add(is);
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param streams input streams containing YANG sources to be parsed
*
* @return effective schema context
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams), isFeatureSupported);
+ return parseYangStreams(Arrays.asList(streams), supportedFeatures);
}
/**
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YANG models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG models are resolved
* @param statementParserMode mode of statement parser
* @param streams input streams containing YANG sources to be parsed
*
*
* @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams), isFeatureSupported, statementParserMode);
+ return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
}
/**
* @throws ReactorException if there is an error in one of the parsed YIN sources
*/
public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
- return parseYinSources(IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE, sources);
+ return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
}
/**
* Creates a new effective schema context containing the specified YIN sources. Statement parser mode is set to
* default mode.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN models are resolved
* @param sources YIN sources to be parsed
*
* @return effective schema context
* @throws ReactorException if there is an error in one of the parsed YIN sources
*/
- public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
final YinStatementStreamSource... sources) throws ReactorException {
- return parseYinSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources);
+ return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
}
/**
*/
public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
final YinStatementStreamSource... sources) throws ReactorException {
- return parseYinSources(IfFeaturePredicates.ALL_FEATURES, statementParserMode, sources);
+ return parseYinSources(null, statementParserMode, sources);
}
/**
* Creates a new effective schema context containing the specified YIN sources.
*
- * @param isFeatureSupported predicate based on which all if-feature statements in the parsed YIN models are resolved
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN models are resolved
* @param statementParserMode mode of statement parser
* @param sources YIN sources to be parsed
*
*
* @throws ReactorException if there is an error in one of the parsed YIN sources
*/
- public static SchemaContext parseYinSources(final Predicate<QName> isFeatureSupported,
+ public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, isFeatureSupported);
+ statementParserMode, supportedFeatures);
reactor.addSources(sources);
return reactor.buildEffective();