import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@Override
public ImmutableSet<Descendant> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
final ImmutableSet<Descendant> uniqueConstraints = parseUniqueConstraintArgument(ctx, value);
- SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.getStatementSourceReference(),
- "Invalid argument value '%s' of unique statement. The value must contains at least "
- + "one descendant schema node identifier.", value);
+ SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.sourceReference(),
+ "Invalid argument value '%s' of unique statement. The value must contains at least one descendant schema "
+ + "node identifier.", value);
return uniqueConstraints;
}
}
@Override
- protected UniqueEffectiveStatement createEffective(
- final StmtContext<Set<Descendant>, UniqueStatement, UniqueEffectiveStatement> ctx,
- final UniqueStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- return new RegularUniqueEffectiveStatement(declared, substatements);
- }
+ protected UniqueEffectiveStatement createEffective(final Current<Set<Descendant>, UniqueStatement> stmt,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return substatements.isEmpty() ? new EmptyUniqueEffectiveStatement(stmt.declared())
+ : new RegularUniqueEffectiveStatement(stmt.declared(), substatements);
- @Override
- protected UniqueEffectiveStatement createEmptyEffective(
- final StmtContext<Set<Descendant>, UniqueStatement, UniqueEffectiveStatement> ctx,
- final UniqueStatement declared) {
- return new EmptyUniqueEffectiveStatement(declared);
}
private static ImmutableSet<Descendant> parseUniqueConstraintArgument(final StmtContext<?, ?, ?> ctx,
final Set<Descendant> uniqueConstraintNodes = new HashSet<>();
for (final String uniqueArgToken : SEP_SPLITTER.split(nocrlf)) {
final SchemaNodeIdentifier nodeIdentifier = ArgumentUtils.nodeIdentifierFromPath(ctx, uniqueArgToken);
- SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.getStatementSourceReference(),
- "Unique statement argument '%s' contains schema node identifier '%s' "
- + "which is not in the descendant node identifier form.", argumentValue, uniqueArgToken);
+ SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.sourceReference(),
+ "Unique statement argument '%s' contains schema node identifier '%s' which is not in the descendant "
+ + "node identifier form.", argumentValue, uniqueArgToken);
uniqueConstraintNodes.add((Descendant) nodeIdentifier);
}
return ImmutableSet.copyOf(uniqueConstraintNodes);