import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.DeviateKind;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
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.model.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
+import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
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.AbstractStatementSupport;
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.slf4j.LoggerFactory;
abstract class AbstractDeviateStatementSupport
- extends BaseStatementSupport<DeviateKind, DeviateStatement, DeviateEffectiveStatement> {
+ extends AbstractStatementSupport<DeviateKind, DeviateStatement, DeviateEffectiveStatement> {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviateStatementSupport.class);
private static final SubstatementValidator DEVIATE_NOT_SUPPORTED_SUBSTATEMENT_VALIDATOR =
private static final ImmutableSet<YangStmtMapping> IMPLICIT_STATEMENTS = ImmutableSet.of(YangStmtMapping.CONFIG,
YangStmtMapping.MANDATORY, YangStmtMapping.MAX_ELEMENTS, YangStmtMapping.MIN_ELEMENTS);
- AbstractDeviateStatementSupport() {
- super(YangStmtMapping.DEVIATE);
+ AbstractDeviateStatementSupport(final YangParserConfiguration config) {
+ super(YangStmtMapping.DEVIATE, StatementPolicy.contextIndependent(), config);
}
@Override
public final DeviateKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value), ctx.sourceReference(),
+ return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value), ctx,
"String '%s' is not valid deviate argument", value);
}
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(deviateStmtCtx.coerceParentContext().sourceReference(),
- "Deviation target '%s' not found.", deviationTarget);
+ throw new InferenceException(deviateStmtCtx.coerceParentContext(), "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.getRawArgument(), ctx.coerceStatementArgument(), substatements);
+ return DeclaredStatements.createDeviate(ctx.getArgument(), substatements);
}
@Override
- protected final DeviateStatement createEmptyDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
- // This is exceedingly unlikely, just reuse the implementation
- return createDeclared(ctx, ImmutableList.of());
+ protected final DeviateStatement attachDeclarationReference(final DeviateStatement stmt,
+ final DeclarationReference reference) {
+ return DeclaredStatementDecorators.decorateDeviate(stmt, reference);
}
@Override
- protected DeviateEffectiveStatement createEffective(final Current<DeviateKind, DeviateStatement> stmt,
+ protected final DeviateEffectiveStatement createEffective(final Current<DeviateKind, DeviateStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- return new DeviateEffectiveStatementImpl(stmt.declared(), substatements);
+ return EffectiveStatements.createDeviate(stmt.declared(), substatements);
}
protected SubstatementValidator getSubstatementValidatorForDeviate(final DeviateKind deviateKind) {
&& YangStmtMapping.LEAF.equals(targetCtx.publicDefinition())) {
for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.publicDefinition()),
- stmtCtxToBeAdded.sourceReference(),
+ stmtCtxToBeAdded,
"Deviation cannot add substatement %s to target node %s because it is already defined "
+ "in target and can appear only once.",
stmtToBeAdded.getStatementName(), targetCtx.argument());
return;
}
- 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.argument());
+ throw new InferenceException(stmtCtxToBeReplaced,
+ "Deviation cannot replace substatement %s in target node %s because it does not exist in target node.",
+ stmtToBeReplaced.getStatementName(), targetCtx.argument());
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
// 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);
+ targetCtx.addEffectiveSubstatement(stmtCtxToBeCopied.replicaAsChildOf(targetCtx));
} else {
targetCtx.addEffectiveSubstatement(targetCtx.childCopyOf(stmtCtxToBeCopied, CopyType.ORIGINAL));
}
private static void validateDeviationTarget(final StmtContext<?, ?, ?> deviateSubStmtCtx,
final StmtContext<?, ?, ?> targetCtx) {
InferenceException.throwIf(!isSupportedDeviationTarget(deviateSubStmtCtx, targetCtx,
- targetCtx.getRootVersion()), deviateSubStmtCtx.sourceReference(),
+ targetCtx.yangVersion()), deviateSubStmtCtx,
"%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(),
+ YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(yangVersion,
deviateSubstatementCtx.publicDefinition());
if (supportedDeviationTargets == null) {