Search in sources :

Example 1 with RangeEffectiveStatement

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);
}
Also used : DecimalTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition) Decimal64(org.opendaylight.yangtools.yang.common.Decimal64) FractionDigitsEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsEffectiveStatement) RangeEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with RangeEffectiveStatement

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);
}
Also used : DecimalTypeBuilder(org.opendaylight.yangtools.yang.model.ri.type.DecimalTypeBuilder) FractionDigitsEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsEffectiveStatement) RangeEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement)

Example 3 with RangeEffectiveStatement

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());
    }
}
Also used : InvalidRangeConstraintException(org.opendaylight.yangtools.yang.model.ri.type.InvalidRangeConstraintException) SourceException(org.opendaylight.yangtools.yang.parser.spi.source.SourceException) RangeEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

RangeEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement)3 NonNull (org.eclipse.jdt.annotation.NonNull)2 FractionDigitsEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsEffectiveStatement)2 Decimal64 (org.opendaylight.yangtools.yang.common.Decimal64)1 DecimalTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition)1 DecimalTypeBuilder (org.opendaylight.yangtools.yang.model.ri.type.DecimalTypeBuilder)1 InvalidRangeConstraintException (org.opendaylight.yangtools.yang.model.ri.type.InvalidRangeConstraintException)1 SourceException (org.opendaylight.yangtools.yang.parser.spi.source.SourceException)1