Bug 8922 - Evaluation of if-features is done regardless of ancestors
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 0fd0460571f58e8366d4e0ab999cdfb42fc770a2..c59c81552922bdb33385de73e9832e346fb2b246 100644 (file)
@@ -147,24 +147,42 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     @Override
     public boolean isSupportedByFeatures() {
+        if (OptionalBoolean.isPresent(supportedByFeatures)) {
+            return OptionalBoolean.get(supportedByFeatures);
+        }
+
         if (isIgnoringIfFeatures()) {
+            supportedByFeatures = OptionalBoolean.of(true);
             return true;
         }
-        if (OptionalBoolean.isPresent(supportedByFeatures)) {
-            return OptionalBoolean.get(supportedByFeatures);
+
+        final boolean isParentSupported = isParentSupportedByFeatures();
+        /*
+         * If parent is not supported, then this context is also not supported.
+         * So we do not need to check if-features statements of this context and
+         * we can return false immediately.
+         */
+        if (!isParentSupported) {
+            supportedByFeatures = OptionalBoolean.of(false);
+            return false;
         }
 
+        /*
+         * If parent is supported, we need to check if-features statements of
+         * this context.
+         */
         // If the set of supported features has not been provided, all features are supported by default.
         final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
-            SupportedFeatures.SUPPORTED_FEATURES);
+                SupportedFeatures.SUPPORTED_FEATURES);
         final boolean ret = supportedFeatures == null ? true
-            : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+                : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
 
         supportedByFeatures = OptionalBoolean.of(ret);
         return ret;
-
     }
 
+    protected abstract boolean isParentSupportedByFeatures();
+
     protected abstract boolean isIgnoringIfFeatures();
 
     protected abstract boolean isIgnoringConfig();