- List<Bit> bitsInit = new ArrayList<>();
-
- path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
-
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof Bit) {
- bitsInit.add(((Bit) effectiveStatement));
- }
- }
-
- bits = ImmutableList.copyOf(bitsInit);
- }
-
- @Override
- public List<Bit> getBits() {
- return bits;
- }
-
- @Override
- public BitsTypeDefinition getBaseType() {
- return null;
- }
-
- @Override
- public String getUnits() {
- return UNITS;
- }
-
- @Override
- public Object getDefaultValue() {
- return bits;
- }
-
- @Override
- public QName getQName() {
- return QNAME;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return Collections.emptyList();
- }
-
- @Override
- public String getDescription() {
- return DESCRIPTION;
- }
-
- @Override
- public String getReference() {
- return REFERENCE;
- }
-
- @Override
- public Status getStatus() {
- return Status.CURRENT;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Objects.hashCode(bits);
- result = prime * result + QNAME.hashCode();
- result = prime * result + path.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- BitsSpecificationEffectiveStatementImpl other = (BitsSpecificationEffectiveStatementImpl) obj;
- if (bits == null) {
- if (other.bits != null) {
- return false;
+ final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(ctx.getSchemaPath().get());
+ Long highestPosition = null;
+ for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
+ if (stmt instanceof Bit) {
+ Bit b = (Bit) stmt;
+
+ if (b.getPosition() == null) {
+ final Long newPos;
+ if (highestPosition == null) {
+ newPos = 0L;
+ } else if (highestPosition != 4294967295L) {
+ newPos = highestPosition + 1;
+ } else {
+ throw new SourceException(ctx.getStatementSourceReference(),
+ "Bit %s must have a position statement", b);
+ }
+
+ b = new BitImpl(newPos, b.getQName(), b.getPath(), b.getDescription(), b.getReference(),
+ b.getStatus(), b.getUnknownSchemaNodes());
+ }
+
+ SourceException.throwIf(b.getPosition() < 0L && b.getPosition() > 4294967295L,
+ ctx.getStatementSourceReference(), "Bit %s has illegal position", b);
+
+ if (highestPosition == null || highestPosition < b.getPosition()) {
+ highestPosition = b.getPosition();
+ }
+
+ builder.addBit(b);