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;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.DeviateKind;
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;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules.SupportedModules;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
deviateAction.apply(new InferenceAction() {
@Override
public void apply(final InferenceContext ctx) {
- // FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
- final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
- (StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.resolve(ctx);
- final StatementContextBase<?, ?, ?> targetNodeStmtCtx =
- (StatementContextBase<?, ?, ?>) targetCtxPrerequisite.resolve(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);
switch (deviateKind) {
case NOT_SUPPORTED:
- targetNodeStmtCtx.setIsSupportedToBuildEffective(false);
+ // FIXME: this can be short-circuited without an inference action
+ targetNodeStmtCtx.setUnsupported();
break;
case ADD:
performDeviateAdd(sourceNodeStmtCtx, targetNodeStmtCtx);
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));
+ }
+ }
});
}
}
@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);
}
final Mutable<DeviateKind, DeviateStatement, DeviateEffectiveStatement> deviateStmtCtx,
final SchemaNodeIdentifier deviationTarget) {
final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules = deviateStmtCtx.getFromNamespace(
- ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES);
+ ModulesDeviatedByModules.class, Empty.value());
if (modulesDeviatedByModules == null) {
return true;
}
return false;
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private static void performDeviateAdd(final StatementContextBase<?, ?, ?> deviateStmtCtx,
- final StatementContextBase<?, ?, ?> targetCtx) {
- for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {
+ private static void performDeviateAdd(final StmtContext<?, ?, ?> deviateStmtCtx,
+ final Mutable<?, ?, ?> targetCtx) {
+ for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {
validateDeviationTarget(originalStmtCtx, targetCtx);
addStatement(originalStmtCtx, targetCtx);
}
}
- private static void addStatement(final Mutable<?, ?, ?> stmtCtxToBeAdded,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ private static void addStatement(final StmtContext<?, ?, ?> stmtCtxToBeAdded, final Mutable<?, ?, ?> targetCtx) {
if (!StmtContextUtils.isUnknownStatement(stmtCtxToBeAdded)) {
final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.publicDefinition();
if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
&& YangStmtMapping.LEAF.equals(targetCtx.publicDefinition())) {
- for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
+ for (StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.publicDefinition()),
stmtCtxToBeAdded,
"Deviation cannot add substatement %s to target node %s because it is already defined "
copyStatement(stmtCtxToBeAdded, targetCtx);
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private static void performDeviateReplace(final StatementContextBase<?, ?, ?> deviateStmtCtx,
- final StatementContextBase<?, ?, ?> targetCtx) {
- for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {
+ private static void performDeviateReplace(final StmtContext<?, ?, ?> deviateStmtCtx,
+ final Mutable<?, ?, ?> targetCtx) {
+ for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {
validateDeviationTarget(originalStmtCtx, targetCtx);
replaceStatement(originalStmtCtx, targetCtx);
}
}
- private static void replaceStatement(final Mutable<?, ?, ?> stmtCtxToBeReplaced,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ private static void replaceStatement(final StmtContext<?, ?, ?> stmtCtxToBeReplaced,
+ final Mutable<?, ?, ?> targetCtx) {
final StatementDefinition stmtToBeReplaced = stmtCtxToBeReplaced.publicDefinition();
if (YangStmtMapping.DEFAULT.equals(stmtToBeReplaced)
return;
}
- for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.effectiveSubstatements()) {
+ for (StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.effectiveSubstatements()) {
if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
targetCtx.removeStatementFromEffectiveSubstatements(stmtToBeReplaced);
copyStatement(stmtCtxToBeReplaced, targetCtx);
}
}
- for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
+ for (Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
- targetCtxSubstatement.setIsSupportedToBuildEffective(false);
+ targetCtxSubstatement.setUnsupported();
copyStatement(stmtCtxToBeReplaced, targetCtx);
return;
}
stmtToBeReplaced.getStatementName(), targetCtx.argument());
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private static void performDeviateDelete(final StatementContextBase<?, ?, ?> deviateStmtCtx,
- final StatementContextBase<?, ?, ?> targetCtx) {
- for (Mutable<?, ?, ?> originalStmtCtx : deviateStmtCtx.mutableDeclaredSubstatements()) {
+ private static void performDeviateDelete(final StmtContext<?, ?, ?> deviateStmtCtx,
+ final Mutable<?, ?, ?> targetCtx) {
+ for (StmtContext<?, ?, ?> originalStmtCtx : deviateStmtCtx.declaredSubstatements()) {
validateDeviationTarget(originalStmtCtx, targetCtx);
deleteStatement(originalStmtCtx, targetCtx);
}
}
private static void deleteStatement(final StmtContext<?, ?, ?> stmtCtxToBeDeleted,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ final Mutable<?, ?, ?> targetCtx) {
final StatementDefinition stmtToBeDeleted = stmtCtxToBeDeleted.publicDefinition();
final String stmtArgument = stmtCtxToBeDeleted.rawArgument();
- for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableEffectiveSubstatements()) {
+ for (Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableEffectiveSubstatements()) {
if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.publicDefinition(),
targetCtxSubstatement.rawArgument())) {
targetCtx.removeStatementFromEffectiveSubstatements(stmtToBeDeleted, stmtArgument);
}
}
- for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
+ for (Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.publicDefinition(),
targetCtxSubstatement.rawArgument())) {
- targetCtxSubstatement.setIsSupportedToBuildEffective(false);
+ targetCtxSubstatement.setUnsupported();
return;
}
}
targetCtx.argument(), stmtCtxToBeDeleted.sourceReference());
}
- private static void copyStatement(final Mutable<?, ?, ?> stmtCtxToBeCopied,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ private static void copyStatement(final StmtContext<?, ?, ?> stmtCtxToBeCopied, final Mutable<?, ?, ?> targetCtx) {
// we need to make a copy of the statement context only if it is an unknown statement, otherwise
// we can reuse the original statement context
if (!StmtContextUtils.isUnknownStatement(stmtCtxToBeCopied)) {
+ // FIXME: I think this should be handled by the corresponding support's copy policy
targetCtx.addEffectiveSubstatement(stmtCtxToBeCopied.replicaAsChildOf(targetCtx));
} else {
targetCtx.addEffectiveSubstatement(targetCtx.childCopyOf(stmtCtxToBeCopied, CopyType.ORIGINAL));