import org.opendaylight.yangtools.yang.model.api.stmt.DeviateEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
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.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
@Override
public final DeviateKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value),
- ctx.getStatementSourceReference(), "String '%s' is not valid deviate argument", value);
+ return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value), ctx.sourceReference(),
+ "String '%s' is not valid deviate argument", value);
}
@Override
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(),
- ChildSchemaNodeNamespace.class, deviationTarget.getNodeIdentifiers());
+ SchemaTreeNamespace.class, deviationTarget.getNodeIdentifiers());
deviateAction.apply(new InferenceAction() {
@Override
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(),
+ throw new InferenceException(deviateStmtCtx.coerceParentContext().sourceReference(),
"Deviation target '%s' not found.", deviationTarget);
}
});
@Override
protected final DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new DeviateStatementImpl(ctx, substatements);
+ return new DeviateStatementImpl(ctx.coerceRawStatementArgument(), ctx.coerceStatementArgument(), substatements);
}
@Override
}
@Override
- protected final DeviateEffectiveStatement createEffective(
- final StmtContext<DeviateKind, DeviateStatement, DeviateEffectiveStatement> ctx,
- final DeviateStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- return new DeviateEffectiveStatementImpl(declared, substatements);
- }
-
- @Override
- protected final DeviateEffectiveStatement createEmptyEffective(
- final StmtContext<DeviateKind, DeviateStatement, DeviateEffectiveStatement> ctx,
- final DeviateStatement declared) {
- // This is exceedingly unlikely, just reuse the implementation
- return createEffective(ctx, declared, ImmutableList.of());
+ protected DeviateEffectiveStatement createEffective(final Current<DeviateKind, DeviateStatement> stmt,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new DeviateEffectiveStatementImpl(stmt.declared(), substatements);
}
protected SubstatementValidator getSubstatementValidatorForDeviate(final DeviateKind deviateKind) {
private static void addStatement(final Mutable<?, ?, ?> stmtCtxToBeAdded,
final StatementContextBase<?, ?, ?> targetCtx) {
if (!StmtContextUtils.isUnknownStatement(stmtCtxToBeAdded)) {
- final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition();
+ final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.publicDefinition();
if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
- && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) {
+ && YangStmtMapping.LEAF.equals(targetCtx.publicDefinition())) {
for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
- InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.getPublicDefinition()),
- stmtCtxToBeAdded.getStatementSourceReference(),
+ InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.publicDefinition()),
+ stmtCtxToBeAdded.sourceReference(),
"Deviation cannot add substatement %s to target node %s because it is already defined "
+ "in target and can appear only once.",
stmtToBeAdded.getStatementName(), targetCtx.getStatementArgument());
private static void replaceStatement(final Mutable<?, ?, ?> stmtCtxToBeReplaced,
final StatementContextBase<?, ?, ?> targetCtx) {
- final StatementDefinition stmtToBeReplaced = stmtCtxToBeReplaced.getPublicDefinition();
+ final StatementDefinition stmtToBeReplaced = stmtCtxToBeReplaced.publicDefinition();
if (YangStmtMapping.DEFAULT.equals(stmtToBeReplaced)
- && YangStmtMapping.LEAF_LIST.equals(targetCtx.getPublicDefinition())) {
+ && YangStmtMapping.LEAF_LIST.equals(targetCtx.publicDefinition())) {
LOG.error("Deviation cannot replace substatement {} in target leaf-list {} because a leaf-list can "
+ "have multiple default statements. At line: {}", stmtToBeReplaced.getStatementName(),
- targetCtx.getStatementArgument(), stmtCtxToBeReplaced.getStatementSourceReference());
+ targetCtx.getStatementArgument(), stmtCtxToBeReplaced.sourceReference());
return;
}
for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.effectiveSubstatements()) {
- if (stmtToBeReplaced.equals(targetCtxSubstatement.getPublicDefinition())) {
+ if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
targetCtx.removeStatementFromEffectiveSubstatements(stmtToBeReplaced);
copyStatement(stmtCtxToBeReplaced, targetCtx);
return;
}
for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
- if (stmtToBeReplaced.equals(targetCtxSubstatement.getPublicDefinition())) {
+ if (stmtToBeReplaced.equals(targetCtxSubstatement.publicDefinition())) {
targetCtxSubstatement.setIsSupportedToBuildEffective(false);
copyStatement(stmtCtxToBeReplaced, targetCtx);
return;
return;
}
- throw new InferenceException(stmtCtxToBeReplaced.getStatementSourceReference(), "Deviation cannot replace "
+ throw new InferenceException(stmtCtxToBeReplaced.sourceReference(), "Deviation cannot replace "
+ "substatement %s in target node %s because it does not exist in target node.",
stmtToBeReplaced.getStatementName(), targetCtx.getStatementArgument());
}
private static void deleteStatement(final StmtContext<?, ?, ?> stmtCtxToBeDeleted,
final StatementContextBase<?, ?, ?> targetCtx) {
- final StatementDefinition stmtToBeDeleted = stmtCtxToBeDeleted.getPublicDefinition();
- final String stmtArgument = stmtCtxToBeDeleted.rawStatementArgument();
+ final StatementDefinition stmtToBeDeleted = stmtCtxToBeDeleted.publicDefinition();
+ final String stmtArgument = stmtCtxToBeDeleted.rawArgument();
for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableEffectiveSubstatements()) {
- if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.getPublicDefinition(),
- targetCtxSubstatement.rawStatementArgument())) {
+ if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.publicDefinition(),
+ targetCtxSubstatement.rawArgument())) {
targetCtx.removeStatementFromEffectiveSubstatements(stmtToBeDeleted, stmtArgument);
return;
}
}
for (final Mutable<?, ?, ?> targetCtxSubstatement : targetCtx.mutableDeclaredSubstatements()) {
- if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.getPublicDefinition(),
- targetCtxSubstatement.rawStatementArgument())) {
+ if (statementsAreEqual(stmtToBeDeleted, stmtArgument, targetCtxSubstatement.publicDefinition(),
+ targetCtxSubstatement.rawArgument())) {
targetCtxSubstatement.setIsSupportedToBuildEffective(false);
return;
}
LOG.error("Deviation cannot delete substatement {} with argument '{}' in target node {} because it does "
+ "not exist in the target node. At line: {}", stmtToBeDeleted.getStatementName(), stmtArgument,
- targetCtx.getStatementArgument(), stmtCtxToBeDeleted.getStatementSourceReference());
+ targetCtx.getStatementArgument(), stmtCtxToBeDeleted.sourceReference());
}
private static void copyStatement(final Mutable<?, ?, ?> stmtCtxToBeCopied,
private static void validateDeviationTarget(final StmtContext<?, ?, ?> deviateSubStmtCtx,
final StmtContext<?, ?, ?> targetCtx) {
InferenceException.throwIf(!isSupportedDeviationTarget(deviateSubStmtCtx, targetCtx,
- targetCtx.getRootVersion()), deviateSubStmtCtx.getStatementSourceReference(),
- "%s is not a valid deviation target for substatement %s.",
- targetCtx.getStatementArgument(), deviateSubStmtCtx.getPublicDefinition().getStatementName());
+ targetCtx.getRootVersion()), deviateSubStmtCtx.sourceReference(),
+ "%s is not a valid deviation target for substatement %s.", targetCtx.argument(),
+ deviateSubStmtCtx.publicDefinition().getStatementName());
}
private static boolean isSupportedDeviationTarget(final StmtContext<?, ?, ?> deviateSubstatementCtx,
final StmtContext<?, ?, ?> deviateTargetCtx, final YangVersion yangVersion) {
Set<StatementDefinition> supportedDeviationTargets =
YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(deviateTargetCtx.getRootVersion(),
- deviateSubstatementCtx.getPublicDefinition());
+ deviateSubstatementCtx.publicDefinition());
if (supportedDeviationTargets == null) {
supportedDeviationTargets = YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(YangVersion.VERSION_1,
- deviateSubstatementCtx.getPublicDefinition());
+ deviateSubstatementCtx.publicDefinition());
}
// if supportedDeviationTargets is null, it means that the deviate substatement is an unknown statement
return supportedDeviationTargets == null || supportedDeviationTargets.contains(
- deviateTargetCtx.getPublicDefinition());
+ deviateTargetCtx.publicDefinition());
}
}