From d9f80c396ec9947316be896a0a0489069fa35b7d Mon Sep 17 00:00:00 2001 From: Peter Kajsa Date: Wed, 21 Dec 2016 19:16:07 +0100 Subject: [PATCH] Bug 6868: If-feature argument may be boolean expression Since Yang 1.1, "if-feature" argument may be a boolean expression over feature names. In this expression, a feature name evaluates to "true" if and only if the feature is supported by the server. Change-Id: Id68d9a101641a7775d8b2a049986431e9cb27662 Signed-off-by: Peter Kajsa --- .../model/api/stmt/IfFeatureStatement.java | 25 +-- .../model/repo/api/IfFeaturePredicates.java | 28 --- .../model/repo/api/SchemaContextFactory.java | 24 +- .../main/antlr/IfFeatureExpressionLexer.g4 | 21 ++ .../main/antlr/IfFeatureExpressionParser.g4 | 25 +++ .../repo/SharedSchemaContextFactory.java | 15 +- .../parser/spi/meta/StmtContextUtils.java | 16 +- .../source/SupportedFeaturesNamespace.java | 4 +- .../stmt/reactor/BuildGlobalContext.java | 17 +- .../reactor/CrossSourceStatementReactor.java | 27 ++- .../stmt/rfc6020/IfFeatureStatementImpl.java | 94 +++++++- .../IfFeatureEffectiveStatementImpl.java | 6 +- ...haredSchemaRepositoryWithFeaturesTest.java | 49 ++--- .../yang/parser/stmt/rfc7950/Bug6868Test.java | 108 +++++++++ .../yang/parser/stmt/rfc7950/Bug6869Test.java | 22 +- .../yang/stmt/DeclaredStatementsTest.java | 207 +++++++++--------- .../yang/stmt/IfFeatureResolutionTest.java | 163 +++++++------- .../yangtools/yang/stmt/StmtTestUtils.java | 39 ++-- .../resources/rfc7950/bug6868/invalid10.yang | 16 ++ .../resources/rfc7950/bug6868/yang11/foo.yang | 39 ++++ .../rfc7950/bug6868/yang11/imported.yang | 9 + .../yang/parser/system/test/Main.java | 6 +- .../parser/system/test/SystemTestUtils.java | 22 +- .../yang/test/util/YangParserTestUtils.java | 166 +++++++------- 24 files changed, 692 insertions(+), 456 deletions(-) delete mode 100644 yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/IfFeaturePredicates.java create mode 100644 yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionLexer.g4 create mode 100644 yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionParser.g4 create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java create mode 100644 yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/invalid10.yang create mode 100644 yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/foo.yang create mode 100644 yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/imported.yang diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureStatement.java index 2ea8ab52db..a2284e5e73 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureStatement.java @@ -19,26 +19,8 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; * * The "if-feature" statement makes its parent statement conditional. */ -// FIXME: IfFeatureStatement should extend DeclaredStatement>> and -// IfFeatureStatementImpl for Yang1.0 reworked to extend AbstractDeclaredStatement>>. -public interface IfFeatureStatement extends DeclaredStatement { - +public interface IfFeatureStatement extends DeclaredStatement>> { /** - * 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 @@ -47,7 +29,6 @@ public interface IfFeatureStatement extends DeclaredStatement { * @return Predicate on a collection of QNames against which to evaluate */ @Beta - @Nonnull default Predicate> getIfFeaturePredicate() { - return setQnames -> setQnames.contains(getName()); - } + @Nonnull + Predicate> getIfFeaturePredicate(); } \ No newline at end of file diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/IfFeaturePredicates.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/IfFeaturePredicates.java deleted file mode 100644 index e381be6cb0..0000000000 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/IfFeaturePredicates.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 ALL_FEATURES = t -> true; - - private IfFeaturePredicates() { - throw new UnsupportedOperationException("Utility class"); - } -} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java index eaa06ce6ad..91dfc946f4 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java @@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.model.repo.api; 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; @@ -33,8 +33,8 @@ public interface SchemaContextFactory { * failed. */ default CheckedFuture createSchemaContext( - @Nonnull Collection requiredSources) { - return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES); + @Nonnull final Collection requiredSources) { + return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE); } /** @@ -50,8 +50,8 @@ public interface SchemaContextFactory { * failed. */ default CheckedFuture createSchemaContext( - Collection requiredSources, StatementParserMode statementParserMode) { - return createSchemaContext(requiredSources, statementParserMode, IfFeaturePredicates.ALL_FEATURES); + final Collection requiredSources, final StatementParserMode statementParserMode) { + return createSchemaContext(requiredSources, statementParserMode, null); } /** @@ -60,16 +60,16 @@ public interface SchemaContextFactory { * * @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 createSchemaContext( - @Nonnull Collection requiredSources, Predicate isFeatureSupported) { - return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, isFeatureSupported); + @Nonnull final Collection requiredSources, final Set supportedFeatures) { + return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, supportedFeatures); } /** @@ -80,8 +80,8 @@ public interface SchemaContextFactory { * 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 @@ -89,5 +89,5 @@ public interface SchemaContextFactory { */ CheckedFuture createSchemaContext( Collection requiredSources, StatementParserMode statementParserMode, - Predicate isFeatureSupported); + Set supportedFeatures); } diff --git a/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionLexer.g4 b/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionLexer.g4 new file mode 100644 index 0000000000..6b837a81ce --- /dev/null +++ b/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionLexer.g4 @@ -0,0 +1,21 @@ +// +// 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_-]*; diff --git a/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionParser.g4 b/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionParser.g4 new file mode 100644 index 0000000000..14c58d9555 --- /dev/null +++ b/yang/yang-parser-impl/src/main/antlr/IfFeatureExpressionParser.g4 @@ -0,0 +1,25 @@ +// +// 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 diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java index cffd246daa..f4cf163821 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java @@ -27,7 +27,6 @@ import java.util.List; 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; @@ -69,10 +68,10 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { @Override public CheckedFuture createSchemaContext( final Collection requiredSources, final StatementParserMode statementParserMode, - final Predicate isFeatureSupported) { + final Set supportedFeatures) { return createSchemaContext(requiredSources, statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache, - new AssembleSources(isFeatureSupported, statementParserMode)); + new AssembleSources(supportedFeatures, statementParserMode)); } private ListenableFuture requestSource(final SourceIdentifier identifier) { @@ -170,13 +169,13 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { private static final class AssembleSources implements AsyncFunction, SchemaContext> { - private final Predicate isFeatureSupported; + private final Set supportedFeatures; private final StatementParserMode statementParserMode; private final Function getIdentifier; - private AssembleSources(final Predicate isFeatureSupported, + private AssembleSources(final Set supportedFeatures, final StatementParserMode statementParserMode) { - this.isFeatureSupported = Preconditions.checkNotNull(isFeatureSupported); + this.supportedFeatures = supportedFeatures; this.statementParserMode = Preconditions.checkNotNull(statementParserMode); switch (statementParserMode) { case SEMVER_MODE: @@ -206,7 +205,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { final Map 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 e : asts.entrySet()) { final ParserRuleContext parserRuleCtx = e.getValue(); @@ -219,7 +218,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { 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); } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java index 3e5589264f..ebd0d8174b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java @@ -13,6 +13,7 @@ import com.google.common.collect.ImmutableList; 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; @@ -24,7 +25,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement; 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; @@ -226,26 +226,30 @@ public final class StmtContextUtils { break; } - final Predicate isFeatureSupported = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class, + final Set 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 isFeatureSupported) { + final Set 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>) stmt.getStatementArgument()).test(supportedFeatures)) { isSupported = true; } else { isSupported = false; diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java index ac2632c11d..95b8f954ab 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/SupportedFeaturesNamespace.java @@ -8,12 +8,12 @@ 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> { + extends IdentifierNamespace> { enum SupportedFeatures { SUPPORTED_FEATURES diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java index 6e67cd340b..26eb77fc54 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java @@ -26,7 +26,6 @@ import java.util.Map.Entry; 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; @@ -79,13 +78,13 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private final Set supportedVersions; BuildGlobalContext(final Map supports, - final StatementParserMode statementParserMode, final Predicate isFeatureSupported) { - this(supports, ImmutableMap.of(), statementParserMode, isFeatureSupported); + final StatementParserMode statementParserMode, final Set supportedFeatures) { + this(supports, ImmutableMap.of(), statementParserMode, supportedFeatures); } BuildGlobalContext(final Map supports, final Map> supportedValidation, - final StatementParserMode statementParserMode, final Predicate isFeatureSupported) { + final StatementParserMode statementParserMode, final Set supportedFeatures) { super(); this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null"); Preconditions.checkNotNull(statementParserMode, "Statement parser mode must not be null."); @@ -95,8 +94,12 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh 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()); } @@ -336,7 +339,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh default: throw new IllegalStateException("Unsupported phase progress " + sourceProgress); } - } catch (RuntimeException ex) { + } catch (final RuntimeException ex) { throw propagateException(nextSourceCtx, ex); } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java index 8ce59f70e5..5bfb6b12ff 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java @@ -15,10 +15,9 @@ import java.util.Collection; 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; @@ -49,20 +48,20 @@ public class CrossSourceStatementReactor { } public final BuildAction newBuild() { - return newBuild(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES); + return newBuild(StatementParserMode.DEFAULT_MODE); } - public final BuildAction newBuild(final Predicate isFeatureSupported) { - return new BuildAction(StatementParserMode.DEFAULT_MODE, isFeatureSupported); + public final BuildAction newBuild(final Set 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 isFeatureSupported) { - return new BuildAction(statementParserMode, isFeatureSupported); + final Set supportedFeatures) { + return new BuildAction(statementParserMode, supportedFeatures); } public static class Builder implements org.opendaylight.yangtools.concepts.Builder { @@ -90,20 +89,20 @@ public class 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 isFeatureSupported) { - this(StatementParserMode.DEFAULT_MODE, isFeatureSupported); + public BuildAction(final Set supportedFeatures) { + this(StatementParserMode.DEFAULT_MODE, supportedFeatures); } - public BuildAction(final StatementParserMode statementParserMode, final Predicate isFeatureSupported) { + public BuildAction(final StatementParserMode statementParserMode, final Set supportedFeatures) { this.context = new BuildGlobalContext(supportedTerminology, supportedValidation, statementParserMode, - isFeatureSupported); + supportedFeatures); } public void addSource(final StatementStreamSource source) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IfFeatureStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IfFeatureStatementImpl.java index e0d4e4e302..15fb9d79b8 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IfFeatureStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IfFeatureStatementImpl.java @@ -7,8 +7,20 @@ */ 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; @@ -16,41 +28,47 @@ import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator; 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 +public class IfFeatureStatementImpl extends AbstractDeclaredStatement>> implements IfFeatureStatement { private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping .IF_FEATURE) .build(); protected IfFeatureStatementImpl( - final StmtContext context) { + final StmtContext>, IfFeatureStatement, ?> context) { super(context); } public static class Definition extends - AbstractStatementSupport> { + AbstractStatementSupport>, IfFeatureStatement, EffectiveStatement>, IfFeatureStatement>> { public Definition() { super(YangStmtMapping.IF_FEATURE); } @Override - public QName parseArgumentValue(final StmtContext ctx, final String value) { - return Utils.qNameFromArgument(ctx, value); + public Predicate> 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 ctx) { + final StmtContext>, IfFeatureStatement, ?> ctx) { return new IfFeatureStatementImpl(ctx); } @Override - public EffectiveStatement createEffective( - final StmtContext> ctx) { + public EffectiveStatement>, IfFeatureStatement> createEffective( + final StmtContext>, IfFeatureStatement, EffectiveStatement>, IfFeatureStatement>> ctx) { return new IfFeatureEffectiveStatementImpl(ctx); } @@ -58,12 +76,64 @@ public class IfFeatureStatementImpl extends AbstractDeclaredStatement protected SubstatementValidator getSubstatementValidator() { return SUBSTATEMENT_VALIDATOR; } + + private static Predicate> 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>> { + private final StmtContext stmtCtx; + + public IfFeaturePredicateVisitor(final StmtContext ctx) { + this.stmtCtx = Preconditions.checkNotNull(ctx); + } + + @Override + public Predicate> 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> 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> 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> 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> getIfFeaturePredicate() { return argument(); } - } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IfFeatureEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IfFeatureEffectiveStatementImpl.java index 7cfd2aa281..a1e3dc514d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IfFeatureEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IfFeatureEffectiveStatementImpl.java @@ -7,12 +7,14 @@ */ 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 { - public IfFeatureEffectiveStatementImpl(final StmtContext ctx) { +public final class IfFeatureEffectiveStatementImpl extends DeclaredEffectiveStatementBase>, IfFeatureStatement> { + public IfFeatureEffectiveStatementImpl(final StmtContext>, IfFeatureStatement, ?> ctx) { super(ctx); } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java index 2f6b63ebb8..42c0b83360 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java @@ -12,11 +12,11 @@ import static org.junit.Assert.assertEquals; 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; @@ -34,12 +34,7 @@ public class SharedSchemaRepositoryWithFeaturesTest { @Test public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception { - Predicate isFeatureSupported = qName -> { - Set supportedFeatures = new HashSet<>(); - supportedFeatures.add(QName.create("foobar-namespace", "1970-01-01", "test-feature-1")); - - return supportedFeatures.contains(qName); - }; + final Set supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "1970-01-01", "test-feature-1")); final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository( "shared-schema-repo-with-features-test"); @@ -53,29 +48,29 @@ public class SharedSchemaRepositoryWithFeaturesTest { .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT); final CheckedFuture 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); } @@ -98,35 +93,35 @@ public class SharedSchemaRepositoryWithFeaturesTest { 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 isFeatureSupported = qName -> false; + final Set supportedFeatures = ImmutableSet.of(); final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository( "shared-schema-repo-with-features-test"); @@ -140,18 +135,18 @@ public class SharedSchemaRepositoryWithFeaturesTest { .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT); final CheckedFuture 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); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java new file mode 100644 index 0000000000..6514223a85 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java @@ -0,0 +1,108 @@ +/* + * 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 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 supportedFeatures, final Set 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 unexpectedContainers = Sets.difference(ALL_CONTAINERS, expectedContainers); + for (final String unexpectedContainer : unexpectedContainers) { + assertNull(String.format("Unexpected container %s.", unexpectedContainer), + findNode(schemaContext, unexpectedContainer)); + } + } + + private static Set createFeaturesSet(final Set featureNames) { + final Set 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 diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6869Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6869Test.java index 5228b79914..3d90a59159 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6869Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6869Test.java @@ -15,12 +15,12 @@ import static org.junit.Assert.assertTrue; 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; @@ -43,7 +43,7 @@ public class Bug6869Test { 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 identities = getIdentities(schemaContext); @@ -59,7 +59,7 @@ public class Bug6869Test { 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 identities = getIdentities(schemaContext); @@ -78,15 +78,13 @@ public class Bug6869Test { return module.getIdentities(); } - private static Predicate createIfFeaturesPredicate(final String... featureNames) { - final Predicate ifFeaturesPredicate = qName -> { - final Set 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 createFeaturesSet(final String... featureNames) { + final Set 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 localNamesPath) { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java index c685203de4..3aa9d229c2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java @@ -17,6 +17,7 @@ import java.text.ParseException; 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; @@ -75,163 +76,163 @@ public class DeclaredStatementsTest { @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 ifFeatureStatements = anyxmlStatement.getIfFeatures(); + final Collection ifFeatureStatements = anyxmlStatement.getIfFeatures(); assertNotNull(ifFeatureStatements); assertEquals(1, ifFeatureStatements.size()); - QName ifFeatureName = ifFeatureStatements.iterator().next().getName(); - assertNotNull(ifFeatureName); + final Predicate> ifFeaturePredicate = ifFeatureStatements.iterator().next().getIfFeaturePredicate(); + assertNotNull(ifFeaturePredicate); - Collection mustStatements = anyxmlStatement.getMusts(); + final Collection 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 caseStatements = choiceStatement.getCases(); + final Collection 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 caseStatementIfFeatures = caseStatement.getIfFeatures(); + final Collection caseStatementIfFeatures = caseStatement.getIfFeatures(); assertNotNull(caseStatementIfFeatures); assertEquals(1, caseStatementIfFeatures.size()); - Collection caseStatementDataDefinitions = caseStatement.getDataDefinitions(); + final Collection 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 ifFeatureStatements = choiceStatement.getIfFeatures(); + final Collection 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 augmentationSchemas = testModule.getAugmentations(); + final Set 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 augmentStatementDataDefinitions = + final Collection augmentStatementDataDefinitions = augmentStatement.getDataDefinitions(); assertNotNull(augmentStatementDataDefinitions); assertEquals(1, augmentStatementDataDefinitions.size()); @@ -239,53 +240,53 @@ public class DeclaredStatementsTest { @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 submodules = testModule.getSubmodules(); + final Set 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()); @@ -293,24 +294,24 @@ public class DeclaredStatementsTest { @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()); @@ -321,22 +322,22 @@ public class DeclaredStatementsTest { 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()); @@ -345,7 +346,7 @@ public class DeclaredStatementsTest { 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; } @@ -358,7 +359,7 @@ public class DeclaredStatementsTest { 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()); @@ -369,59 +370,59 @@ public class DeclaredStatementsTest { @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 containerStatementIfFeatures = containerStatement.getIfFeatures(); + final Collection containerStatementIfFeatures = containerStatement.getIfFeatures(); assertNotNull(containerStatementIfFeatures); assertEquals(1, containerStatementIfFeatures.size()); - Collection containerStatementMusts = containerStatement.getMusts(); + final Collection 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 containerStatementTypedefs = containerStatement.getTypedefs(); + final Collection containerStatementTypedefs = containerStatement.getTypedefs(); assertNotNull(containerStatementTypedefs); assertEquals(1, containerStatementTypedefs.size()); - Collection containerStatementGroupings = containerStatement.getGroupings(); + final Collection containerStatementGroupings = containerStatement.getGroupings(); assertNotNull(containerStatementGroupings); assertEquals(1, containerStatementGroupings.size()); - Collection containerStatementDataDefinitions = + final Collection containerStatementDataDefinitions = containerStatement.getDataDefinitions(); assertNotNull(containerStatementDataDefinitions); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java index c26cb5ab5a..5a2a5f9d0e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IfFeatureResolutionTest.java @@ -12,9 +12,8 @@ import static org.junit.Assert.assertEquals; 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; @@ -37,105 +36,101 @@ public class IfFeatureResolutionTest { @Test public void testSomeFeaturesSupported() throws ReactorException { - Predicate isFeatureSupported = qName -> { - Set 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 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()); @@ -143,94 +138,94 @@ public class IfFeatureResolutionTest { 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()); @@ -241,7 +236,7 @@ public class IfFeatureResolutionTest { 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()); @@ -252,14 +247,14 @@ public class IfFeatureResolutionTest { 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()); @@ -267,10 +262,10 @@ public class IfFeatureResolutionTest { 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( @@ -280,57 +275,57 @@ public class IfFeatureResolutionTest { @Test public void testNoFeaturesSupported() throws ReactorException { - Predicate isFeatureSupported = qName -> false; + final Set 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()); @@ -341,7 +336,7 @@ public class IfFeatureResolutionTest { 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()); @@ -349,10 +344,10 @@ public class IfFeatureResolutionTest { 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( diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java index a3435cabc5..efd1fc33c0 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java @@ -17,14 +17,12 @@ import java.util.ArrayList; 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; @@ -101,13 +99,13 @@ public class StmtTestUtils { 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 ifFeaturePredicate, final StatementStreamSource... sources) + public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Set 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(); @@ -115,10 +113,10 @@ public class StmtTestUtils { 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 ifFeaturePredicate, final File... files) throws SourceException, + public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Set supportedFeatures, final File... files) throws SourceException, ReactorException, FileNotFoundException { final StatementStreamSource[] sources = new StatementStreamSource[files.length]; @@ -127,7 +125,7 @@ public class StmtTestUtils { 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 files) throws SourceException, ReactorException, @@ -137,7 +135,7 @@ public class StmtTestUtils { public static SchemaContext parseYangSources(final Collection 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, @@ -147,29 +145,36 @@ public class StmtTestUtils { 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 ifFeaturesPredicate) + public static SchemaContext parseYangSource(final String yangSourcePath, final Set 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 ifFeaturePredicate) + final StatementParserMode statementParserMode, final Set 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 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) diff --git a/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/invalid10.yang b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/invalid10.yang new file mode 100644 index 0000000000..5d78fb6226 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/invalid10.yang @@ -0,0 +1,16 @@ +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)"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/foo.yang b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/foo.yang new file mode 100644 index 0000000000..0e4b6866b2 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/foo.yang @@ -0,0 +1,39 @@ +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"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/imported.yang b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/imported.yang new file mode 100644 index 0000000000..8c7dfe8b86 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/rfc7950/bug6868/yang11/imported.yang @@ -0,0 +1,9 @@ +module imported { + namespace "imp"; + prefix imp; + yang-version 1; + + revision "2017-01-09"; + + feature bar; +} diff --git a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/Main.java b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/Main.java index 256ac65a1a..2f2926bad5 100644 --- a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/Main.java +++ b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/Main.java @@ -13,7 +13,6 @@ import java.util.Arrays; 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; @@ -26,7 +25,6 @@ import org.apache.commons.cli.ParseException; 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. @@ -107,15 +105,13 @@ public class Main { LOG.log(Level.INFO, "Yang model files: {0} ", yangFiles); LOG.log(Level.INFO, "Supported features: {0} ", supportedFeatures); - final Predicate 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); diff --git a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java index 7ffcfce5c3..2044840822 100644 --- a/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java +++ b/yang/yang-system-test/src/main/java/org/opendaylight/yangtools/yang/parser/system/test/SystemTestUtils.java @@ -15,7 +15,7 @@ import java.util.ArrayList; 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; @@ -35,18 +35,18 @@ class SystemTestUtils { } }; - static SchemaContext parseYangSources(final Collection files, final Predicate isFeatureSupported) + static SchemaContext parseYangSources(final Collection files, final Set supportedFeatures) throws ReactorException, FileNotFoundException { - return parseYangSources(files, StatementParserMode.DEFAULT_MODE, isFeatureSupported); + return parseYangSources(files, StatementParserMode.DEFAULT_MODE, supportedFeatures); } static SchemaContext parseYangSources(final Collection files, - final StatementParserMode statementParserMode, final Predicate isFeatureSupported) + final StatementParserMode statementParserMode, final Set 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 isFeatureSupported, + static SchemaContext parseYangSources(final Set supportedFeatures, final StatementParserMode statementParserMode, final File... files) throws ReactorException, FileNotFoundException { final YangStatementSourceImpl [] sources = new YangStatementSourceImpl[files.length]; @@ -55,21 +55,21 @@ class SystemTestUtils { 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 isFeatureSupported, + static SchemaContext parseYangSources(final Set 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 yangDirs, final List yangFiles, - final Predicate isFeatureSupported) throws FileNotFoundException, ReactorException { + final Set supportedFeatures) throws FileNotFoundException, ReactorException { final List allYangFiles = new ArrayList<>(); for (final String yangDir : yangDirs) { allYangFiles.addAll(getYangFiles(yangDir)); @@ -79,7 +79,7 @@ class SystemTestUtils { allYangFiles.add(new File(yangFile)); } - return parseYangSources(allYangFiles, isFeatureSupported); + return parseYangSources(allYangFiles, supportedFeatures); } private static Collection getYangFiles(final String yangSourcesDirectoryPath) { diff --git a/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java b/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java index 0f4e5c1366..2892589e82 100644 --- a/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java +++ b/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java @@ -20,10 +20,9 @@ import java.util.ArrayList; 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; @@ -62,14 +61,14 @@ public final class YangParserTestUtils { */ @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 @@ -78,9 +77,9 @@ public final class YangParserTestUtils { * @deprecated Migration method only, do not use. */ @Deprecated - public static SchemaContext parseYangSources(final Predicate isFeatureSupported, + public static SchemaContext parseYangSources(final Set supportedFeatures, final YangStatementSourceImpl... sources) throws ReactorException { - return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources); + return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources); } /** @@ -97,13 +96,13 @@ public final class YangParserTestUtils { @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 * @@ -111,11 +110,11 @@ public final class YangParserTestUtils { * * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangSources(final Predicate isFeatureSupported, + public static SchemaContext parseYangSources(final Set 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(); @@ -133,14 +132,14 @@ public final class YangParserTestUtils { * @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 @@ -148,9 +147,9 @@ public final class YangParserTestUtils { * @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 isFeatureSupported, final File... files) + public static SchemaContext parseYangSources(final Set supportedFeatures, final File... files) throws ReactorException, FileNotFoundException { - return parseYangSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, files); + return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files); } /** @@ -166,13 +165,13 @@ public final class YangParserTestUtils { */ 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 * @@ -181,7 +180,7 @@ public final class YangParserTestUtils { * @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 isFeatureSupported, + public static SchemaContext parseYangSources(final Set supportedFeatures, final StatementParserMode statementParserMode, final File... files) throws ReactorException, FileNotFoundException { final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length]; @@ -189,7 +188,7 @@ public final class YangParserTestUtils { sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); } - return parseYangSources(isFeatureSupported, statementParserMode, sources); + return parseYangSources(supportedFeatures, statementParserMode, sources); } /** @@ -205,14 +204,14 @@ public final class YangParserTestUtils { */ public static SchemaContext parseYangSources(final Collection 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 @@ -220,9 +219,9 @@ public final class YangParserTestUtils { * @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 files, final Predicate isFeatureSupported) + public static SchemaContext parseYangSources(final Collection files, final Set supportedFeatures) throws ReactorException, FileNotFoundException { - return parseYangSources(files, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -238,13 +237,13 @@ public final class YangParserTestUtils { */ public static SchemaContext parseYangSources(final Collection 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 * @@ -253,9 +252,9 @@ public final class YangParserTestUtils { * @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 files, final Predicate isFeatureSupported, + public static SchemaContext parseYangSources(final Collection files, final Set 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()])); } /** @@ -272,8 +271,7 @@ public final class YangParserTestUtils { */ 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); } /** @@ -281,7 +279,7 @@ public final class YangParserTestUtils { * 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 * @@ -290,9 +288,9 @@ public final class YangParserTestUtils { * @throws URISyntaxException if the specified directory does not exist */ public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, - final Predicate isFeatureSupported) throws ReactorException, FileNotFoundException, + final Set supportedFeatures) throws ReactorException, FileNotFoundException, URISyntaxException { - return parseYangSources(yangSourcesDirectoryPath, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -310,14 +308,14 @@ public final class YangParserTestUtils { 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 @@ -327,12 +325,12 @@ public final class YangParserTestUtils { * @throws URISyntaxException if the specified directory does not exist */ public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, - final Predicate isFeatureSupported, final StatementParserMode statementParserMode) + final Set 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)); } /** @@ -349,7 +347,7 @@ public final class YangParserTestUtils { */ 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); } /** @@ -357,7 +355,7 @@ public final class YangParserTestUtils { * 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 * @@ -365,9 +363,9 @@ public final class YangParserTestUtils { * @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 isFeatureSupported) + public static SchemaContext parseYangSource(final String yangSourcePath, final Set supportedFeatures) throws ReactorException, FileNotFoundException, URISyntaxException { - return parseYangSource(yangSourcePath, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -384,14 +382,14 @@ public final class YangParserTestUtils { */ 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 @@ -400,12 +398,12 @@ public final class YangParserTestUtils { * @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 isFeatureSupported, + public static SchemaContext parseYangSource(final String yangSourcePath, final Set 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); } /** @@ -423,7 +421,7 @@ public final class YangParserTestUtils { */ public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles) throws FileNotFoundException, ReactorException, URISyntaxException { - return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE); + return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE); } /** @@ -432,7 +430,7 @@ public final class YangParserTestUtils { * * @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 * @@ -441,9 +439,9 @@ public final class YangParserTestUtils { * @throws URISyntaxException if one of the specified directories or files does not exist */ public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final Predicate isFeatureSupported) throws FileNotFoundException, ReactorException, + final Set supportedFeatures) throws FileNotFoundException, ReactorException, URISyntaxException { - return parseYangSources(yangDirs, yangFiles, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -462,7 +460,7 @@ public final class YangParserTestUtils { public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException, URISyntaxException { - return parseYangSources(yangDirs, yangFiles, IfFeaturePredicates.ALL_FEATURES, statementParserMode); + return parseYangSources(yangDirs, yangFiles, null, statementParserMode); } /** @@ -470,7 +468,7 @@ public final class YangParserTestUtils { * * @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 @@ -480,7 +478,7 @@ public final class YangParserTestUtils { * @throws URISyntaxException if one of the specified directories or files does not exist */ public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final Predicate isFeatureSupported, final StatementParserMode statementParserMode) + final Set supportedFeatures, final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException, URISyntaxException { final List allYangFiles = new ArrayList<>(); for (final String yangDir : yangDirs) { @@ -492,7 +490,7 @@ public final class YangParserTestUtils { allYangFiles.add(new File(filePath)); } - return parseYangSources(allYangFiles, isFeatureSupported, statementParserMode); + return parseYangSources(allYangFiles, supportedFeatures, statementParserMode); } private static Collection getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException { @@ -513,23 +511,23 @@ public final class YangParserTestUtils { * @throws ReactorException if there is an error in one of the parsed YANG sources */ public static SchemaContext parseYangSources(final List 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 filePaths, final Predicate isFeatureSupported) + public static SchemaContext parseYangSources(final List filePaths, final Set supportedFeatures) throws ReactorException { - return parseYangSources(filePaths, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -542,15 +540,15 @@ public final class YangParserTestUtils { * * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangSources(final List filePaths,final StatementParserMode statementParserMode) - throws ReactorException { - return parseYangSources(filePaths, IfFeaturePredicates.ALL_FEATURES, statementParserMode); + public static SchemaContext parseYangSources(final List filePaths, + final StatementParserMode statementParserMode) throws ReactorException { + return parseYangSources(filePaths, (Set) 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 * @@ -559,7 +557,7 @@ public final class YangParserTestUtils { * @throws ReactorException if there is an error in one of the parsed YANG sources */ public static SchemaContext parseYangSources(final List filePaths, - final Predicate isFeatureSupported, final StatementParserMode statementParserMode) + final Set supportedFeatures, final StatementParserMode statementParserMode) throws ReactorException { final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()]; @@ -567,7 +565,7 @@ public final class YangParserTestUtils { sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i))); } - return parseYangSources(isFeatureSupported, statementParserMode, sources); + return parseYangSources(supportedFeatures, statementParserMode, sources); } /** @@ -581,7 +579,7 @@ public final class YangParserTestUtils { * @throws ReactorException if there is an error in one of the parsed YANG sources */ public static SchemaContext parseYangStreams(final List streams) throws ReactorException { - return parseYangStreams(streams, IfFeaturePredicates.ALL_FEATURES, StatementParserMode.DEFAULT_MODE); + return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE); } /** @@ -589,15 +587,15 @@ public final class YangParserTestUtils { * 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 streams, final Predicate isFeatureSupported) + public static SchemaContext parseYangStreams(final List streams, final Set supportedFeatures) throws ReactorException { - return parseYangStreams(streams, isFeatureSupported, StatementParserMode.DEFAULT_MODE); + return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** @@ -612,13 +610,13 @@ public final class YangParserTestUtils { */ public static SchemaContext parseYangStreams(final List 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 * @@ -626,10 +624,10 @@ public final class YangParserTestUtils { * * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final List streams, final Predicate isFeatureSupported, + public static SchemaContext parseYangStreams(final List streams, final Set supportedFeatures, final StatementParserMode statementParserMode) throws ReactorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( - statementParserMode, isFeatureSupported); + statementParserMode, supportedFeatures); return reactor.buildEffective(streams); } @@ -647,7 +645,7 @@ public final class YangParserTestUtils { public static SchemaContext parseYangResources(final Class clazz, final String... resources) throws ReactorException { final List 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); @@ -674,16 +672,16 @@ public final class YangParserTestUtils { * 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 isFeatureSupported, + public static SchemaContext parseYangStreams(final Set supportedFeatures, final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams), isFeatureSupported); + return parseYangStreams(Arrays.asList(streams), supportedFeatures); } /** @@ -704,7 +702,7 @@ public final class YangParserTestUtils { /** * 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 * @@ -712,9 +710,9 @@ public final class YangParserTestUtils { * * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final Predicate isFeatureSupported, + public static SchemaContext parseYangStreams(final Set supportedFeatures, final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams), isFeatureSupported, statementParserMode); + return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode); } /** @@ -728,22 +726,22 @@ public final class YangParserTestUtils { * @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 isFeatureSupported, + public static SchemaContext parseYinSources(final Set supportedFeatures, final YinStatementStreamSource... sources) throws ReactorException { - return parseYinSources(isFeatureSupported, StatementParserMode.DEFAULT_MODE, sources); + return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources); } /** @@ -758,13 +756,13 @@ public final class YangParserTestUtils { */ 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 * @@ -772,11 +770,11 @@ public final class YangParserTestUtils { * * @throws ReactorException if there is an error in one of the parsed YIN sources */ - public static SchemaContext parseYinSources(final Predicate isFeatureSupported, + public static SchemaContext parseYinSources(final Set 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(); -- 2.36.6