private static void copyStatement(final Mutable<?, ?, ?> stmtCtxToBeCopied, final StatementContextBase<?, ?, ?> 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)) { targetCtx.addEffectiveSubstatement(stmtCtxToBeCopied); } else { targetCtx.addEffectiveSubstatement(targetCtx.childCopyOf(stmtCtxToBeCopied, CopyType.ORIGINAL)); } }
private static void addOrReplaceNode(final Mutable<?, ?, ?> refineSubstatementCtx, final StatementContextBase<?, ?, ?> refineTargetNodeCtx) { final StatementDefinition refineSubstatementDef = refineSubstatementCtx.getPublicDefinition(); SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx), refineSubstatementCtx.getStatementSourceReference(), "Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.", refineSubstatementCtx.getRoot().getStatementArgument(), refineSubstatementCtx.coerceParentContext().getStatementArgument(), refineSubstatementCtx.getPublicDefinition(), refineTargetNodeCtx.getPublicDefinition()); if (isAllowedToAddByRefine(refineSubstatementDef)) { refineTargetNodeCtx.addEffectiveSubstatement(refineSubstatementCtx); } else { refineTargetNodeCtx.removeStatementFromEffectiveSubstatements(refineSubstatementDef); refineTargetNodeCtx.addEffectiveSubstatement(refineSubstatementCtx); } }
@Override public void apply(final InferenceContext ctx) { final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.resolve(ctx); if (!isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) { augmentNode.setIsSupportedToBuildEffective(false); return; } /** * Marks case short hand in augment */ if (augmentTargetCtx.getPublicDefinition() == YangStmtMapping.CHOICE) { augmentNode.addToNs(AugmentToChoiceNamespace.class, augmentNode, Boolean.TRUE); } // 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 { copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx); augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx); updateAugmentOrder(augmentSourceCtx); } catch (final SourceException e) { LOG.warn("Failed to add augmentation {} defined at {}", augmentTargetCtx.getStatementSourceReference(), augmentSourceCtx.getStatementSourceReference(), e); } }