Augments should get disabled if target is unsupported
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / augment / AugmentInferenceAction.java
index 2f19c1a1cdafe0e34f32d866af6c361c88cad4b1..9c540052c86db8f33d2ead14e77bc7417e2c07c0 100644 (file)
@@ -14,6 +14,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -62,6 +63,11 @@ final class AugmentInferenceAction implements InferenceAction {
 
     @Override
     public void apply(final InferenceContext ctx) {
+        if (!augmentNode.isSupportedToBuildEffective()) {
+            // We are not building effective model, hence we should not be performing any effects
+            return;
+        }
+
         final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.resolve(ctx);
         if (!isSupportedAugmentTarget(augmentTargetCtx)
                 || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
@@ -99,6 +105,15 @@ final class AugmentInferenceAction implements InferenceAction {
         throw new InferenceException(augmentNode, "Augment target '%s' not found", augmentNode.argument());
     }
 
+    @Override
+    public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+        if (target.equals(unavail)) {
+            augmentNode.setIsSupportedToBuildEffective(false);
+        } else {
+            prerequisiteFailed(List.of(unavail));
+        }
+    }
+
     private void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceCtx,
             final StatementContextBase<?, ?, ?> targetCtx) {
         final CopyType typeOfCopy = sourceCtx.coerceParentContext().producesDeclared(UsesStatement.class)