Bump odlparent to 10.0.0
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / deviate / AbstractDeviateStatementSupport.java
index 79cf01b7a11e59fdc2f122b98dfaabe8aa5c6de5..11dc737e53faf71429dfb4bc795b894a75fc0a1f 100644 (file)
@@ -13,9 +13,9 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 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.Empty;
@@ -37,6 +37,7 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
 import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@@ -142,6 +143,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;
+                }
+
                 final var sourceNodeStmtCtx = sourceCtxPrerequisite.resolve(ctx);
                 final var targetNodeStmtCtx = targetCtxPrerequisite.resolve(ctx);
 
@@ -169,6 +175,15 @@ abstract class AbstractDeviateStatementSupport
                 throw new InferenceException(deviateStmtCtx.coerceParentContext(), "Deviation target '%s' not found.",
                     deviationTarget);
             }
+
+            @Override
+            public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+                if (targetCtxPrerequisite.equals(unavail)) {
+                    deviateStmtCtx.setUnsupported();
+                } else {
+                    prerequisiteFailed(List.of(unavail));
+                }
+            }
         });
     }
 
@@ -188,8 +203,8 @@ abstract class AbstractDeviateStatementSupport
     }
 
     @Override
-    protected final DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx,
-            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+    protected final DeviateStatement createDeclared(final BoundStmtCtx<DeviateKind> ctx,
+            final ImmutableList<DeclaredStatement<?>> substatements) {
         return DeclaredStatements.createDeviate(ctx.getArgument(), substatements);
     }
 
@@ -242,8 +257,6 @@ abstract class AbstractDeviateStatementSupport
         return false;
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void performDeviateAdd(final StmtContext<?, ?, ?> deviateStmtCtx,
             final Mutable<?, ?, ?> targetCtx) {
         for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {
@@ -270,8 +283,6 @@ abstract class AbstractDeviateStatementSupport
         copyStatement(stmtCtxToBeAdded, targetCtx);
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void performDeviateReplace(final StmtContext<?, ?, ?> deviateStmtCtx,
             final Mutable<?, ?, ?> targetCtx) {
         for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {
@@ -321,8 +332,6 @@ abstract class AbstractDeviateStatementSupport
             stmtToBeReplaced.getStatementName(), targetCtx.argument());
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void performDeviateDelete(final StmtContext<?, ?, ?> deviateStmtCtx,
                 final Mutable<?, ?, ?> targetCtx) {
         for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {