X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2FAugmentStatementImpl.java;h=6a2d471f1ccad4f49e7d93c9a938b0065097b23f;hb=04fa25a4fe8957f6492618aa9a1e9a4f9af39df4;hp=731f21791fb475218ac65f99f1665f396d0793e3;hpb=66f6a6c5cadc384c13e684afb51f7e0ecb691510;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java index 731f21791f..6a2d471f1c 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java @@ -97,56 +97,52 @@ public class AugmentStatementImpl extends AbstractDeclaredStatement>> sourceCtxPrereq = augmentAction - .requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL); - final Prerequisite>> target = augmentAction.mutatesEffectiveCtx(getSearchRoot(augmentNode), SchemaNodeIdentifierBuildNamespace.class, augmentNode.getStatementArgument()); + final ModelActionBuilder augmentAction = augmentNode.newInferenceAction( + ModelProcessingPhase.EFFECTIVE_MODEL); + final ModelActionBuilder.Prerequisite>> sourceCtxPrereq = + augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL); + final Prerequisite>> target = + augmentAction.mutatesEffectiveCtx(getSearchRoot(augmentNode), SchemaNodeIdentifierBuildNamespace.class, augmentNode.getStatementArgument()); augmentAction.apply(new ModelActionBuilder.InferenceAction() { @Override - public void apply() throws InferenceException { + public void apply() { final StatementContextBase augmentTargetCtx = (StatementContextBase) target.get(); - if (!AugmentUtils.isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) { augmentNode.setIsSupportedToBuildEffective(false); return; } + + // FIXME: this is a workaround for models which augment a node which is added via an extension + // which we do not handle. This needs to be reworked in terms of unknown schema nodes. final StatementContextBase augmentSourceCtx = (StatementContextBase) augmentNode; try { - AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, - augmentTargetCtx); - augmentTargetCtx - .addEffectiveSubstatement(augmentSourceCtx); + AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx); + augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx); updateAugmentOrder(augmentSourceCtx); } catch (SourceException e) { - LOG.warn(e.getMessage(), e); + LOG.warn("Failed to add augmentation %s defined at {}", + augmentSourceCtx.getStatementSourceReference(), e); } - } - private void updateAugmentOrder( - final StatementContextBase augmentSourceCtx) { - Integer currentOrder = augmentSourceCtx - .getFromNamespace(StmtOrderingNamespace.class, - Rfc6020Mapping.AUGMENT); + private void updateAugmentOrder(final StatementContextBase augmentSourceCtx) { + Integer currentOrder = augmentSourceCtx.getFromNamespace(StmtOrderingNamespace.class, + Rfc6020Mapping.AUGMENT); if (currentOrder == null) { currentOrder = 1; } else { currentOrder++; } + augmentSourceCtx.setOrder(currentOrder); - augmentSourceCtx.addToNs(StmtOrderingNamespace.class, - Rfc6020Mapping.AUGMENT, currentOrder); + augmentSourceCtx.addToNs(StmtOrderingNamespace.class, Rfc6020Mapping.AUGMENT, currentOrder); } @Override - public void prerequisiteFailed( - final Collection> failed) - throws InferenceException { - throw new InferenceException("Augment target not found: " - + augmentNode.getStatementArgument(), augmentNode - .getStatementSourceReference()); + public void prerequisiteFailed(final Collection> failed) { + throw new InferenceException(augmentNode.getStatementSourceReference(), + "Augment target '%s' not found", augmentNode.getStatementArgument()); } }); } @@ -154,7 +150,7 @@ public class AugmentStatementImpl extends AbstractDeclaredStatement getSearchRoot(final Mutable augmentContext) { Mutable parent = augmentContext.getParentContext(); // Augment is in uses - we need to augment instantiated nodes in parent. - if(Rfc6020Mapping.USES.equals(parent.getPublicDefinition())) { + if (Rfc6020Mapping.USES.equals(parent.getPublicDefinition())) { return parent.getParentContext(); } return parent;