package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.QName;
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.stmt.FractionDigitsEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RangeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.Decimal64Specification;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.ri.type.DecimalTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
+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;
-final class Decimal64SpecificationSupport extends BaseStatementSupport<String, Decimal64Specification,
- EffectiveStatement<String, Decimal64Specification>> {
- private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
- YangStmtMapping.TYPE)
- .addMandatory(YangStmtMapping.FRACTION_DIGITS)
- .addOptional(YangStmtMapping.RANGE)
- .build();
+final class Decimal64SpecificationSupport extends AbstractTypeSupport<Decimal64Specification> {
+ private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
+ SubstatementValidator.builder(YangStmtMapping.TYPE)
+ .addMandatory(YangStmtMapping.FRACTION_DIGITS)
+ .addOptional(YangStmtMapping.RANGE)
+ .build();
- Decimal64SpecificationSupport() {
- super(YangStmtMapping.TYPE);
- }
-
- @Override
- public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return value;
+ Decimal64SpecificationSupport(final YangParserConfiguration config) {
+ super(config);
}
@Override
}
@Override
- protected Decimal64Specification createDeclared(final StmtContext<String, Decimal64Specification, ?> ctx,
+ protected Decimal64Specification createDeclared(final StmtContext<QName, Decimal64Specification, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new Decimal64SpecificationImpl(ctx.coerceRawStatementArgument(), substatements);
+ if (substatements.isEmpty()) {
+ throw noFracDigits(ctx);
+ }
+ return new Decimal64SpecificationImpl(ctx.getRawArgument(), ctx.getArgument(), substatements);
}
@Override
- protected Decimal64Specification createEmptyDeclared(final StmtContext<String, Decimal64Specification, ?> ctx) {
- throw noFracDigits(ctx);
+ protected Decimal64Specification attachDeclarationReference(final Decimal64Specification stmt,
+ final DeclarationReference reference) {
+ return new RefDecimal64Specification(stmt, reference);
}
@Override
- protected EffectiveStatement<String, Decimal64Specification> createEffective(
- final StmtContext<String, Decimal64Specification, EffectiveStatement<String, Decimal64Specification>> ctx,
- final Decimal64Specification declared,
+ protected EffectiveStatement<QName, Decimal64Specification> createEffective(
+ final Current<QName, Decimal64Specification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- final DecimalTypeBuilder builder = BaseTypes.decimalTypeBuilder(ctx.getSchemaPath().get());
- for (final EffectiveStatement<?, ?> stmt : substatements) {
- if (stmt instanceof FractionDigitsEffectiveStatement) {
- builder.setFractionDigits(((FractionDigitsEffectiveStatement) stmt).argument());
+ 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 (stmt instanceof RangeEffectiveStatement) {
- final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
+ if (subStmt instanceof RangeEffectiveStatement) {
+ final RangeEffectiveStatement range = (RangeEffectiveStatement) subStmt;
builder.setRangeConstraint(range, range.argument());
}
}
- return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
- }
-
- @Override
- protected EffectiveStatement<String, Decimal64Specification> createEmptyEffective(
- final StmtContext<String, Decimal64Specification, EffectiveStatement<String, Decimal64Specification>> ctx,
- final Decimal64Specification declared) {
- throw noFracDigits(ctx);
+ return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noFracDigits(final StmtContext<?, ?, ?> ctx) {
+ private static SourceException noFracDigits(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.3.4
*
* The "fraction-digits" statement, which is a substatement to the
* "type" statement, MUST be present if the type is "decimal64".
*/
- return new SourceException("At least one fraction-digits statement has to be present",
- ctx.getStatementSourceReference());
+ return new SourceException("At least one fraction-digits statement has to be present", stmt);
}
}
\ No newline at end of file