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;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public void apply(final InferenceContext ctx) {
- final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.resolve(ctx);
+ if (!augmentNode.isSupportedToBuildEffective()) {
+ // We are not building effective model, hence we should not be performing any effects
+ return;
+ }
+
+ final var augmentTargetCtx = target.resolve(ctx);
if (!isSupportedAugmentTarget(augmentTargetCtx)
|| StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
- augmentNode.setIsSupportedToBuildEffective(false);
+ augmentNode.setUnsupported();
return;
}
// We are targeting a context which is creating implicit nodes. In order to keep things consistent,
// we will need to circle back when creating effective statements.
if (augmentTargetCtx.hasImplicitParentSupport()) {
- augmentNode.addToNs(AugmentImplicitHandlingNamespace.class, Empty.getInstance(), augmentTargetCtx);
+ augmentNode.addToNs(AugmentImplicitHandlingNamespace.class, Empty.value(), augmentTargetCtx);
}
- copyFromSourceToTarget((StatementContextBase<?, ?, ?>) augmentNode, augmentTargetCtx);
+ copyFromSourceToTarget(augmentNode, augmentTargetCtx);
augmentTargetCtx.addEffectiveSubstatement(augmentNode.replicaAsChildOf(augmentTargetCtx));
}
* Do not fail, if it is an uses-augment to an unknown node.
*/
if (YangStmtMapping.USES == augmentNode.coerceParentContext().publicDefinition()) {
+ if (!augmentNode.isSupportedToBuildEffective()) {
+ // We are not supported, hence the uses is not effective and we should bail
+ return;
+ }
+
final SchemaNodeIdentifier augmentArg = augmentNode.getArgument();
final Optional<StmtContext<?, ?, ?>> targetNode = SchemaTreeNamespace.findNode(
AbstractAugmentStatementSupport.getSearchRoot(augmentNode), augmentArg);
if (targetNode.isPresent() && StmtContextUtils.isUnknownStatement(targetNode.get())) {
- augmentNode.setIsSupportedToBuildEffective(false);
+ augmentNode.setUnsupported();
LOG.warn("Uses-augment to unknown node {}. Augmentation has not been performed. At line: {}",
augmentArg, augmentNode.sourceReference());
return;
throw new InferenceException(augmentNode, "Augment target '%s' not found", augmentNode.argument());
}
- private void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceCtx,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ @Override
+ public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+ if (target.equals(unavail)) {
+ augmentNode.setUnsupported();
+ } else {
+ prerequisiteFailed(List.of(unavail));
+ }
+ }
+
+ private void copyFromSourceToTarget(final StmtContext<?, ?, ?> sourceCtx, final Mutable<?, ?, ?> targetCtx) {
final CopyType typeOfCopy = sourceCtx.coerceParentContext().producesDeclared(UsesStatement.class)
? CopyType.ADDED_BY_USES_AUGMENTATION : CopyType.ADDED_BY_AUGMENTATION;
/*
final boolean skipCheckOfMandatoryNodes = statementSupport.allowsMandatory(sourceCtx);
final boolean unsupported = !sourceCtx.isSupportedByFeatures();
- final Collection<? extends Mutable<?, ?, ?>> declared = sourceCtx.mutableDeclaredSubstatements();
- final Collection<? extends Mutable<?, ?, ?>> effective = sourceCtx.mutableEffectiveSubstatements();
- final Collection<Mutable<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
+ final var declared = sourceCtx.declaredSubstatements();
+ final var effective = sourceCtx.effectiveSubstatements();
+ final var buffer = new ArrayList<Mutable<?, ?, ?>>(declared.size() + effective.size());
- for (final Mutable<?, ?, ?> originalStmtCtx : declared) {
+ for (var originalStmtCtx : declared) {
copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes,
unsupported || !originalStmtCtx.isSupportedByFeatures());
}
- for (final Mutable<?, ?, ?> originalStmtCtx : effective) {
+ for (var originalStmtCtx : effective) {
copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes, unsupported);
}
targetCtx.addEffectiveSubstatements(buffer);
}
- private static void copyStatement(final Mutable<?, ?, ?> original, final StatementContextBase<?, ?, ?> target,
+ private static void copyStatement(final StmtContext<?, ?, ?> original, final Mutable<?, ?, ?> target,
final CopyType typeOfCopy, final Collection<Mutable<?, ?, ?>> buffer,
final boolean skipCheckOfMandatoryNodes, final boolean unsupported) {
// We always copy statements, but if either the source statement or the augmentation which causes it are not
final Mutable<?, ?, ?> copy = target.childCopyOf(original, typeOfCopy);
if (unsupported) {
- copy.setIsSupportedToBuildEffective(false);
+ copy.setUnsupported();
}
buffer.add(copy);
} else if (!unsupported && original.publicDefinition() == YangStmtMapping.TYPEDEF) {
}
private static void validateNodeCanBeCopiedByAugment(final StmtContext<?, ?, ?> sourceCtx,
- final StatementContextBase<?, ?, ?> targetCtx, final CopyType typeOfCopy,
- final boolean skipCheckOfMandatoryNodes) {
+ final Mutable<?, ?, ?> targetCtx, final CopyType typeOfCopy, final boolean skipCheckOfMandatoryNodes) {
if (!skipCheckOfMandatoryNodes && typeOfCopy == CopyType.ADDED_BY_AUGMENTATION
&& requireCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
checkForMandatoryNodes(sourceCtx);
// Data definition statements must not collide on their namespace
if (sourceCtx.producesDeclared(DataDefinitionStatement.class)) {
- for (final StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) {
+ for (StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) {
if (subStatement.producesDeclared(DataDefinitionStatement.class)) {
InferenceException.throwIf(Objects.equals(sourceCtx.argument(), subStatement.argument()), sourceCtx,
"An augment cannot add node named '%s' because this name is already used in target",