import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
}
final ModelActionBuilder augmentAction = augmentNode
- .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
+ .newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
- .requiresCtx(augmentNode,
- ModelProcessingPhase.FULL_DECLARATION);
-
+ .requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
+ final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtx(getSearchRoot(augmentNode), SchemaNodeIdentifierBuildNamespace.class, augmentNode.getStatementArgument());
augmentAction.apply(new ModelActionBuilder.InferenceAction() {
@Override
public void apply() throws InferenceException {
- final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
- .getAugmentTargetCtx(augmentNode);
-
- if (augmentTargetCtx == null) {
- throw new InferenceException(
- "Augment target not found: "
- + augmentNode.getStatementArgument(),
- augmentNode.getStatementSourceReference());
- }
+ final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.get();
if (!AugmentUtils.isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
augmentNode.setIsSupportedToBuildEffective(false);
return;
}
-
final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) augmentNode;
-
try {
AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
augmentTargetCtx);
}
});
}
+
+ private Mutable<?, ?, ?> getSearchRoot(Mutable<?, ?, ?> augmentContext) {
+ Mutable<?, ?, ?> parent = augmentContext.getParentContext();
+ // Augment is in uses - we need to augment instantiated nodes in parent.
+ if(Rfc6020Mapping.USES.equals(parent.getPublicDefinition())) {
+ return parent.getParentContext();
+ }
+ return parent;
+ }
}
@Nonnull