Deviations should get disabled if target is unsupported
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / deviate / AbstractDeviateStatementSupport.java
index 0ce5325f848f971f04407e14e38b9785717a435a..f50df45df4b38e5de9f145dc7da37720e65658ba 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.SetMultimap;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -135,6 +136,11 @@ abstract class AbstractDeviateStatementSupport
         deviateAction.apply(new InferenceAction() {
             @Override
             public void apply(final InferenceContext ctx) {
+                if (!deviateStmtCtx.isSupportedToBuildEffective()) {
+                    // We are not building effective model, hence we should not be performing any effects
+                    return;
+                }
+
                 // FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
                 final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
                         (StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.resolve(ctx);
@@ -164,6 +170,15 @@ abstract class AbstractDeviateStatementSupport
                 throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(),
                     "Deviation target '%s' not found.", deviationTarget);
             }
+
+            @Override
+            public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+                if (targetCtxPrerequisite.equals(unavail)) {
+                    deviateStmtCtx.setIsSupportedToBuildEffective(false);
+                } else {
+                    prerequisiteFailed(List.of(unavail));
+                }
+            }
         });
     }