Bug 6868: If-feature argument may be boolean expression
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContextUtils.java
index 3e5589264ffc19b79c1414eb9f7e30c166196b7c..ebd0d8174bea4cfed2bc059870fcf7bfaf677aec 100644 (file)
@@ -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<QName> isFeatureSupported = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
+        final Set<QName> supportedFeatures = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
                 SupportedFeatures.SUPPORTED_FEATURES);
-        if (IfFeaturePredicates.ALL_FEATURES.equals(isFeatureSupported)) {
+        /*
+         * If set of supported features has not been provided, all features are
+         * supported by default.
+         */
+        if (supportedFeatures == null) {
             stmtContext.setSupportedByFeatures(true);
             return true;
         }
 
-        final boolean result = checkFeatureSupport(stmtContext, isFeatureSupported);
+        final boolean result = checkFeatureSupport(stmtContext, supportedFeatures);
         stmtContext.setSupportedByFeatures(result);
         return result;
     }
 
     private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
-            final Predicate<QName> isFeatureSupported) {
+            final Set<QName> supportedFeatures) {
         boolean isSupported = false;
         boolean containsIfFeature = false;
         for (final StatementContextBase<?, ?, ?> stmt : stmtContext.declaredSubstatements()) {
             if (YangStmtMapping.IF_FEATURE.equals(stmt.getPublicDefinition())) {
                 containsIfFeature = true;
-                if (isFeatureSupported.test((QName) stmt.getStatementArgument())) {
+                if (((Predicate<Set<QName>>) stmt.getStatementArgument()).test(supportedFeatures)) {
                     isSupported = true;
                 } else {
                     isSupported = false;