import com.google.common.collect.ImmutableList;
import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint32;
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.BitEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.BitsSpecification;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.BitsTypeBuilder;
-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.BitsTypeBuilder;
+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;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-final class BitsSpecificationSupport
- extends BaseStatementSupport<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> {
- private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
- YangStmtMapping.TYPE)
- .addMultiple(YangStmtMapping.BIT)
- .build();
+final class BitsSpecificationSupport extends AbstractTypeSupport<BitsSpecification> {
+ private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
+ SubstatementValidator.builder(YangStmtMapping.TYPE).addMultiple(YangStmtMapping.BIT).build();
- BitsSpecificationSupport() {
- super(YangStmtMapping.TYPE);
- }
-
- @Override
- public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return value;
+ BitsSpecificationSupport(final YangParserConfiguration config) {
+ super(config);
}
@Override
}
@Override
- protected BitsSpecification createDeclared(final StmtContext<String, BitsSpecification, ?> ctx,
+ protected BitsSpecification createDeclared(final StmtContext<QName, BitsSpecification, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new BitsSpecificationImpl(ctx.coerceRawStatementArgument(), substatements);
+ if (substatements.isEmpty()) {
+ throw noBits(ctx);
+ }
+ return new BitsSpecificationImpl(ctx.getRawArgument(), ctx.getArgument(), substatements);
}
@Override
- protected BitsSpecification createEmptyDeclared(final StmtContext<String, BitsSpecification, ?> ctx) {
- throw noBits(ctx.getStatementSourceReference());
+ protected BitsSpecification attachDeclarationReference(final BitsSpecification stmt,
+ final DeclarationReference reference) {
+ return new RefBitsSpecification(stmt, reference);
}
@Override
- protected EffectiveStatement<String, BitsSpecification> createEffective(
- final Current<String, BitsSpecification> stmt,
+ protected EffectiveStatement<QName, BitsSpecification> createEffective(
+ final Current<QName, BitsSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
- throw noBits(stmt.sourceReference());
+ throw noBits(stmt);
}
- final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(stmt.getSchemaPath());
+ final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(stmt.argumentAsTypeQName());
Uint32 highestPosition = null;
for (final EffectiveStatement<?, ?> subStmt : substatements) {
if (subStmt instanceof BitEffectiveStatement) {
final Uint32 effectivePos;
if (declaredPosition.isEmpty()) {
if (highestPosition != null) {
- SourceException.throwIf(Uint32.MAX_VALUE.equals(highestPosition), stmt.sourceReference(),
+ SourceException.throwIf(Uint32.MAX_VALUE.equals(highestPosition), stmt,
"Bit %s must have a position statement", bitSubStmt);
effectivePos = Uint32.fromIntBits(highestPosition.intValue() + 1);
} else {
return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
}
- private static SourceException noBits(final StatementSourceReference ref) {
+ private static SourceException noBits(final CommonStmtCtx stmt) {
/*
* https://tools.ietf.org/html/rfc7950#section-9.7.4:
*
* The "bit" statement, which is a substatement to the "type" statement,
* MUST be present if the type is "bits".
*/
- return new SourceException("At least one bit statement has to be present", ref);
+ return new SourceException("At least one bit statement has to be present", stmt);
}
}