BUG-6316: Fix Bit and EnumPair's position/value types
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / BitsSpecificationEffectiveStatementImpl.java
index 582695b8ec5ed0cd650ce6d948e7cbded3e525c9..35222b89167dfb84f5f0bef9ad5d398f09671aff 100644 (file)
@@ -25,31 +25,34 @@ public final class BitsSpecificationEffectiveStatementImpl extends
 
     private final BitsTypeDefinition typeDefinition;
 
-    public BitsSpecificationEffectiveStatementImpl(final StmtContext<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> ctx) {
+    public BitsSpecificationEffectiveStatementImpl(
+            final StmtContext<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> ctx) {
         super(ctx);
 
         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 (stmt instanceof BitEffectiveStatementImpl) {
+                final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt;
 
-                if (b.getPosition() == null) {
-                    final Long newPos;
-                    if (highestPosition == null) {
-                        newPos = 0L;
-                    } else if (highestPosition != 4294967295L) {
-                        newPos = highestPosition + 1;
+                final long effectivePos;
+                if (bitSubStmt.getDeclaredPosition() == null) {
+                    if (highestPosition != null) {
+                        SourceException.throwIf(highestPosition == 4294967295L, ctx.getStatementSourceReference(),
+                                "Bit %s must have a position statement", bitSubStmt);
+                        effectivePos = highestPosition + 1;
                     } else {
-                        throw new SourceException(ctx.getStatementSourceReference(),
-                            "Bit %s must have a position statement", b);
+                        effectivePos = 0L;
                     }
-
-                    b = BitBuilder.create(b.getPath(), newPos).setDescription(b.getDescription())
-                            .setReference(b.getReference()).setStatus(b.getStatus())
-                            .setUnknownSchemaNodes(b.getUnknownSchemaNodes()).build();
+                } else {
+                    effectivePos = bitSubStmt.getDeclaredPosition();
                 }
 
+                final Bit b = BitBuilder.create(bitSubStmt.getPath(), effectivePos)
+                        .setDescription(bitSubStmt.getDescription()).setReference(bitSubStmt.getReference())
+                        .setStatus(bitSubStmt.getStatus()).setUnknownSchemaNodes(bitSubStmt.getUnknownSchemaNodes())
+                        .build();
+
                 SourceException.throwIf(b.getPosition() < 0L && b.getPosition() > 4294967295L,
                         ctx.getStatementSourceReference(), "Bit %s has illegal position", b);
 
@@ -60,7 +63,7 @@ public final class BitsSpecificationEffectiveStatementImpl extends
                 builder.addBit(b);
             }
             if (stmt instanceof UnknownEffectiveStatementImpl) {
-                builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
+                builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl) stmt);
             }
         }