package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
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.ri.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.ri.type.BitsTypeBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
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;
}
@Override
- protected BitsSpecification createDeclared(final StmtContext<QName, BitsSpecification, ?> ctx,
- final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ protected BitsSpecification createDeclared(final BoundStmtCtx<QName> ctx,
+ final ImmutableList<DeclaredStatement<?>> substatements) {
if (substatements.isEmpty()) {
throw noBits(ctx);
}
final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(stmt.argumentAsTypeQName());
Uint32 highestPosition = null;
- for (final EffectiveStatement<?, ?> subStmt : substatements) {
- if (subStmt instanceof BitEffectiveStatement) {
- final BitEffectiveStatement bitSubStmt = (BitEffectiveStatement) subStmt;
-
- final Optional<Uint32> declaredPosition = bitSubStmt.getDeclaredPosition();
+ for (var subStmt : substatements) {
+ if (subStmt instanceof BitEffectiveStatement bitSubStmt) {
+ var declaredPosition = bitSubStmt.findDeclaredPosition();
final Uint32 effectivePos;
if (declaredPosition.isEmpty()) {
if (highestPosition != null) {
effectivePos = Uint32.ZERO;
}
} else {
- effectivePos = declaredPosition.get();
+ effectivePos = declaredPosition.orElseThrow();
}
final Bit bit = EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos);
private static SourceException noBits(final CommonStmtCtx stmt) {
/*
- * https://tools.ietf.org/html/rfc7950#section-9.7.4:
+ * https://www.rfc-editor.org/rfc/rfc7950#section-9.7.4:
*
* The "bit" statement, which is a substatement to the "type" statement,
* MUST be present if the type is "bits".