+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-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.TypeEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.Decimal64Specification;
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
-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.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-final class Decimal64SpecificationEffectiveStatement
- extends DeclaredEffectiveStatementBase<String, Decimal64Specification>
- implements TypeEffectiveStatement<Decimal64Specification> {
-
- private final @NonNull DecimalTypeDefinition typeDefinition;
-
- Decimal64SpecificationEffectiveStatement(
- final StmtContext<String, Decimal64Specification, EffectiveStatement<String, Decimal64Specification>> ctx) {
- super(ctx);
-
- final DecimalTypeBuilder builder = BaseTypes.decimalTypeBuilder(ctx.getSchemaPath().get());
- for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
- if (stmt instanceof FractionDigitsEffectiveStatement) {
- builder.setFractionDigits(((FractionDigitsEffectiveStatement) stmt).argument());
- }
- if (stmt instanceof RangeEffectiveStatement) {
- final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
- builder.setRangeConstraint(range, range.argument());
- }
- if (stmt instanceof UnknownSchemaNode) {
- builder.addUnknownSchemaNode((UnknownSchemaNode)stmt);
- }
- }
-
- typeDefinition = builder.build();
- }
-
- @Override
- public DecimalTypeDefinition getTypeDefinition() {
- return typeDefinition;
- }
-}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.Decimal64Specification;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class Decimal64SpecificationImpl extends AbstractDeclaredStatement<String> implements Decimal64Specification {
- Decimal64SpecificationImpl(final StmtContext<String, Decimal64Specification, ?> context) {
- super(context);
+final class Decimal64SpecificationImpl extends WithSubstatements implements Decimal64Specification {
+ Decimal64SpecificationImpl(final StmtContext<String, ?, ?> context,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(context, substatements);
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.parser.spi.meta.AbstractStatementSupport;
+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.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 AbstractStatementSupport<String, Decimal64Specification,
+final class Decimal64SpecificationSupport extends BaseStatementSupport<String, Decimal64Specification,
EffectiveStatement<String, Decimal64Specification>> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
YangStmtMapping.TYPE)
}
@Override
- public Decimal64Specification createDeclared(final StmtContext<String, Decimal64Specification, ?> ctx) {
- return new Decimal64SpecificationImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- public EffectiveStatement<String, Decimal64Specification> createEffective(final StmtContext<String,
- Decimal64Specification, EffectiveStatement<String, Decimal64Specification>> ctx) {
- return new Decimal64SpecificationEffectiveStatement(ctx);
+ protected Decimal64Specification createDeclared(final StmtContext<String, Decimal64Specification, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new Decimal64SpecificationImpl(ctx, substatements);
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ protected Decimal64Specification createEmptyDeclared(final StmtContext<String, Decimal64Specification, ?> ctx) {
+ throw noFracDigits(ctx);
+ }
+
+ @Override
+ protected EffectiveStatement<String, Decimal64Specification> createEffective(
+ final StmtContext<String, Decimal64Specification, EffectiveStatement<String, Decimal64Specification>> ctx,
+ final Decimal64Specification declared,
+ 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 (stmt instanceof RangeEffectiveStatement) {
+ final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
+ 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);
+ }
+
+ private static SourceException noFracDigits(final StmtContext<?, ?, ?> ctx) {
+ /*
+ * 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());
}
}
\ No newline at end of file