2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
10 import com.google.common.annotations.VisibleForTesting;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.BitsSpecification;
16 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
18 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
19 import org.opendaylight.yangtools.yang.model.util.type.BitsTypeBuilder;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit.BitEffectiveStatementImpl;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 // FIXME: 5.0.0: hide this class
27 public final class BitsSpecificationEffectiveStatement extends
28 DeclaredEffectiveStatementBase<String, BitsSpecification> implements TypeEffectiveStatement<BitsSpecification> {
30 private final @NonNull BitsTypeDefinition typeDefinition;
32 BitsSpecificationEffectiveStatement(
33 final StmtContext<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> ctx) {
36 final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(ctx.getSchemaPath().get());
37 Long highestPosition = null;
38 for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
39 if (stmt instanceof BitEffectiveStatementImpl) {
40 final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt;
42 final long effectivePos;
43 if (bitSubStmt.getDeclaredPosition() == null) {
44 if (highestPosition != null) {
45 SourceException.throwIf(highestPosition == 4294967295L, ctx.getStatementSourceReference(),
46 "Bit %s must have a position statement", bitSubStmt);
47 effectivePos = highestPosition + 1;
52 effectivePos = bitSubStmt.getDeclaredPosition().toJava();
55 final Bit bit = EffectiveTypeUtil.buildBit(bitSubStmt, effectivePos);
56 SourceException.throwIf(bit.getPosition() < 0L && bit.getPosition() > 4294967295L,
57 ctx.getStatementSourceReference(), "Bit %s has illegal position", bit);
59 if (highestPosition == null || highestPosition < bit.getPosition()) {
60 highestPosition = bit.getPosition();
65 if (stmt instanceof UnknownSchemaNode) {
66 builder.addUnknownSchemaNode((UnknownSchemaNode) stmt);
70 typeDefinition = builder.build();
74 public BitsTypeDefinition getTypeDefinition() {
75 return typeDefinition;