Convert AbstractEnumStatementSupport
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / type / EnumSpecificationEffectiveStatement.java
index f645b70d21444ae0d1bee21c515337492e4ac7c8..47e78b9165c8fb1fa9082e3b5fae73723666a8bf 100644 (file)
@@ -7,17 +7,19 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
+import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.EnumSpecification;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
@@ -33,11 +35,13 @@ final class EnumSpecificationEffectiveStatement extends DeclaredEffectiveStateme
         final EnumerationTypeBuilder builder = BaseTypes.enumerationTypeBuilder(ctx.getSchemaPath().get());
         Integer highestValue = null;
         for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
-            if (stmt instanceof EnumEffectiveStatementImpl) {
-                final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt;
+            if (stmt instanceof EnumEffectiveStatement) {
+                final EnumEffectiveStatement enumSubStmt = (EnumEffectiveStatement) stmt;
 
+                final Optional<Integer> declaredValue =
+                        enumSubStmt.findFirstEffectiveSubstatementArgument(ValueEffectiveStatement.class);
                 final int effectiveValue;
-                if (enumSubStmt.getDeclaredValue() == null) {
+                if (declaredValue.isEmpty()) {
                     if (highestValue != null) {
                         SourceException.throwIf(highestValue == 2147483647, ctx.getStatementSourceReference(),
                                 "Enum '%s' must have a value statement", enumSubStmt);
@@ -46,7 +50,7 @@ final class EnumSpecificationEffectiveStatement extends DeclaredEffectiveStateme
                         effectiveValue = 0;
                     }
                 } else {
-                    effectiveValue = enumSubStmt.getDeclaredValue();
+                    effectiveValue = declaredValue.orElseThrow();
                 }
 
                 final EnumPair pair = EffectiveTypeUtil.buildEnumPair(enumSubStmt, effectiveValue);