Split out yang-model-ri
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / type / EffectiveTypeUtil.java
index 821320710868215183cbd0397943344c96508291..b9911deeea3995353ce71e4e0ebfea69526c6d14 100644 (file)
@@ -7,34 +7,45 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
+import static com.google.common.base.Verify.verify;
+
 import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
+import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
-import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit.BitEffectiveStatementImpl;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.model.ri.type.BitBuilder;
+import org.opendaylight.yangtools.yang.model.ri.type.EnumPairBuilder;
 
 @Beta
 final class EffectiveTypeUtil {
     private EffectiveTypeUtil() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
-    static Bit buildBit(final BitEffectiveStatementImpl stmt, final long effectivePos) {
+    static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final Uint32 effectivePos) {
+        verify(stmt instanceof WithStatus);
+        final WithStatus bit = (WithStatus) stmt;
+
         // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
-        final BitBuilder builder = BitBuilder.create(stmt.getPath(), effectivePos).setStatus(stmt.getStatus());
-        stmt.getDescription().ifPresent(builder::setDescription);
-        stmt.getReference().ifPresent(builder::setReference);
+        final BitBuilder builder = BitBuilder.create(stmt.argument(), effectivePos).setStatus(bit.getStatus());
+        bit.getDescription().ifPresent(builder::setDescription);
+        bit.getReference().ifPresent(builder::setReference);
 
         return builder.build();
     }
 
-    static EnumPair buildEnumPair(final EnumEffectiveStatementImpl stmt, final int effectiveValue) {
-        final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
-                .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
-        stmt.getDescription().ifPresent(builder::setDescription);
-        stmt.getReference().ifPresent(builder::setReference);
+    static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatement stmt, final int effectiveValue) {
+        verify(stmt instanceof WithStatus);
+        final WithStatus node = (WithStatus) stmt;
+
+        final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getDeclared().rawArgument(), effectiveValue)
+                .setStatus(node.getStatus()).setUnknownSchemaNodes(node.getUnknownSchemaNodes());
+        node.getDescription().ifPresent(builder::setDescription);
+        node.getReference().ifPresent(builder::setReference);
 
         return builder.build();
     }