use of org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement in project yangtools by opendaylight.
the class AbstractTypeStatementSupport method createDecimal.
@NonNull
private static TypeEffectiveStatement<TypeStatement> createDecimal(final Current<QName, ?> ctx, final DecimalTypeDefinition baseType, final TypeStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
final RangeRestrictedTypeBuilder<DecimalTypeDefinition, Decimal64> builder = RestrictedTypes.newDecima64Builder(baseType, typeEffectiveQName(ctx));
for (EffectiveStatement<?, ?> stmt : substatements) {
if (stmt instanceof RangeEffectiveStatement) {
final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
builder.setRangeConstraint(range, range.argument());
}
if (stmt instanceof FractionDigitsEffectiveStatement) {
final Integer digits = ((FractionDigitsEffectiveStatement) stmt).argument();
SourceException.throwIf(baseType.getFractionDigits() != digits, ctx, "Cannot override fraction-digits from base type %s to %s", baseType, digits);
}
}
return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement in project yangtools by opendaylight.
the class Decimal64SpecificationSupport method createEffective.
@Override
protected EffectiveStatement<QName, Decimal64Specification> createEffective(final Current<QName, Decimal64Specification> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
throw noFracDigits(stmt);
}
final DecimalTypeBuilder builder = BaseTypes.decimalTypeBuilder(stmt.argumentAsTypeQName());
for (final EffectiveStatement<?, ?> subStmt : substatements) {
if (subStmt instanceof FractionDigitsEffectiveStatement) {
builder.setFractionDigits(((FractionDigitsEffectiveStatement) subStmt).argument());
}
if (subStmt instanceof RangeEffectiveStatement) {
final RangeEffectiveStatement range = (RangeEffectiveStatement) subStmt;
builder.setRangeConstraint(range, range.argument());
}
}
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement in project yangtools by opendaylight.
the class AbstractTypeStatementSupport method createIntegral.
@NonNull
private static <T extends RangeRestrictedTypeDefinition<T, N>, N extends Number & Comparable<N>> TypeEffectiveStatement<TypeStatement> createIntegral(final Current<?, ?> ctx, final TypeStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final RangeRestrictedTypeBuilder<T, N> builder) {
for (EffectiveStatement<?, ?> stmt : substatements) {
if (stmt instanceof RangeEffectiveStatement) {
final RangeEffectiveStatement rangeStmt = (RangeEffectiveStatement) stmt;
builder.setRangeConstraint(rangeStmt, rangeStmt.argument());
}
}
try {
return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
} catch (InvalidRangeConstraintException e) {
throw new SourceException(ctx, e, "Invalid range constraint: %s", e.getOffendingRanges());
}
}
Aggregations