Fixed SchemaPath resolution for base YANG types.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / util / YangModelBuilderUtil.java
index a01565fd6bee3f41022581c3cc2a1f3696193d96..fff33b63bd513baa2b4e435b6266e497ce5ea874 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Stack;
 import org.antlr.v4.runtime.tree.ParseTree;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bits_specificationContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_argContext;
@@ -29,6 +30,7 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Error_app_tag_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Error_message_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Fraction_digits_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Identityref_specificationContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leafref_specificationContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Length_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Mandatory_argContext;
@@ -61,7 +63,6 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser.Uses_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Value_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yin_element_argContext;
@@ -82,17 +83,24 @@ import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder;
-import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine;
 import org.opendaylight.controller.yang.model.util.BaseConstraints;
 import org.opendaylight.controller.yang.model.util.BinaryType;
 import org.opendaylight.controller.yang.model.util.BitsType;
+import org.opendaylight.controller.yang.model.util.Decimal64;
 import org.opendaylight.controller.yang.model.util.EnumerationType;
 import org.opendaylight.controller.yang.model.util.InstanceIdentifier;
+import org.opendaylight.controller.yang.model.util.Int16;
+import org.opendaylight.controller.yang.model.util.Int32;
+import org.opendaylight.controller.yang.model.util.Int64;
+import org.opendaylight.controller.yang.model.util.Int8;
 import org.opendaylight.controller.yang.model.util.Leafref;
 import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.controller.yang.model.util.StringType;
+import org.opendaylight.controller.yang.model.util.Uint16;
+import org.opendaylight.controller.yang.model.util.Uint32;
+import org.opendaylight.controller.yang.model.util.Uint64;
+import org.opendaylight.controller.yang.model.util.Uint8;
 import org.opendaylight.controller.yang.model.util.UnknownType;
-import org.opendaylight.controller.yang.model.util.YangTypesConverter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -134,18 +142,18 @@ public final class YangModelBuilderUtil {
      * @param builder
      *            builder to fill in with parsed statements
      */
-    public static void parseSchemaNodeArgs(ParseTree ctx,
-            SchemaNodeBuilder builder) {
+    public static void parseSchemaNodeArgs(final ParseTree ctx,
+            final SchemaNodeBuilder builder) {
         for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
+            final ParseTree child = ctx.getChild(i);
             if (child instanceof Description_stmtContext) {
-                String desc = stringFromNode(child);
+                final String desc = stringFromNode(child);
                 builder.setDescription(desc);
             } else if (child instanceof Reference_stmtContext) {
-                String ref = stringFromNode(child);
+                final String ref = stringFromNode(child);
                 builder.setReference(ref);
             } else if (child instanceof Status_stmtContext) {
-                Status status = parseStatus((Status_stmtContext) child);
+                final Status status = parseStatus((Status_stmtContext) child);
                 builder.setStatus(status);
             }
         }
@@ -158,7 +166,7 @@ public final class YangModelBuilderUtil {
      *            status context
      * @return value parsed from context
      */
-    public static Status parseStatus(Status_stmtContext ctx) {
+    public static Status parseStatus(final Status_stmtContext ctx) {
         Status result = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree statusArg = ctx.getChild(i);
@@ -186,7 +194,7 @@ public final class YangModelBuilderUtil {
      * @return value of units statement as string or null if there is no units
      *         statement
      */
-    public static String parseUnits(ParseTree ctx) {
+    public static String parseUnits(final ParseTree ctx) {
         String units = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
@@ -209,8 +217,9 @@ public final class YangModelBuilderUtil {
      * @param prefix
      * @return SchemaPath object.
      */
-    public static SchemaPath createActualSchemaPath(List<String> actualPath,
-            URI namespace, Date revision, String prefix) {
+    public static SchemaPath createActualSchemaPath(
+            final List<String> actualPath, final URI namespace,
+            final Date revision, final String prefix) {
         final List<QName> path = new ArrayList<QName>();
         QName qname;
         // start from index 1 - module name omited
@@ -228,9 +237,9 @@ public final class YangModelBuilderUtil {
      *            string representation of path
      * @return SchemaPath object
      */
-    public static SchemaPath parseAugmentPath(String augmentPath) {
-        boolean absolute = augmentPath.startsWith("/");
-        String[] splittedPath = augmentPath.split("/");
+    public static SchemaPath parseAugmentPath(final String augmentPath) {
+        final boolean absolute = augmentPath.startsWith("/");
+        final String[] splittedPath = augmentPath.split("/");
         List<QName> path = new ArrayList<QName>();
         QName name;
         for (String pathElement : splittedPath) {
@@ -262,8 +271,8 @@ public final class YangModelBuilderUtil {
      *            current prefix
      * @return YANG list key as java.util.List of QName objects
      */
-    public static List<QName> createListKey(String keyDefinition,
-            URI namespace, Date revision, String prefix) {
+    public static List<QName> createListKey(final String keyDefinition,
+            final URI namespace, final Date revision, final String prefix) {
         List<QName> key = new ArrayList<QName>();
         String[] splittedKey = keyDefinition.split(" ");
 
@@ -290,8 +299,8 @@ public final class YangModelBuilderUtil {
      * @return List of EnumPair object parsed from given context
      */
     private static List<EnumTypeDefinition.EnumPair> getEnumConstants(
-            Type_body_stmtsContext ctx, List<String> path, URI namespace,
-            Date revision, String prefix) {
+            final Type_body_stmtsContext ctx, final List<String> path,
+            final URI namespace, final Date revision, final String prefix) {
         List<EnumTypeDefinition.EnumPair> enumConstants = new ArrayList<EnumTypeDefinition.EnumPair>();
 
         for (int j = 0; j < ctx.getChildCount(); j++) {
@@ -330,8 +339,9 @@ public final class YangModelBuilderUtil {
      * @return EnumPair object parsed from given context
      */
     private static EnumTypeDefinition.EnumPair createEnumPair(
-            Enum_stmtContext ctx, final int highestValue, List<String> path,
-            final URI namespace, final Date revision, final String prefix) {
+            final Enum_stmtContext ctx, final int highestValue,
+            final List<String> path, final URI namespace, final Date revision,
+            final String prefix) {
         final String name = stringFromNode(ctx);
         final QName qname = new QName(namespace, revision, prefix, name);
         Integer value = null;
@@ -514,7 +524,7 @@ public final class YangModelBuilderUtil {
      * @return List of RangeConstraint created from this context
      */
     private static List<RangeConstraint> getRangeConstraints(
-            Type_body_stmtsContext ctx) {
+            final Type_body_stmtsContext ctx) {
         List<RangeConstraint> rangeConstraints = Collections.emptyList();
         outer: for (int j = 0; j < ctx.getChildCount(); j++) {
             ParseTree numRestrChild = ctx.getChild(j);
@@ -539,7 +549,7 @@ public final class YangModelBuilderUtil {
      * @return List of RangeConstraints parsed from this context
      */
     private static List<RangeConstraint> parseRangeConstraints(
-            Range_stmtContext ctx) {
+            final Range_stmtContext ctx) {
         List<RangeConstraint> rangeConstraints = new ArrayList<RangeConstraint>();
         String description = null;
         String reference = null;
@@ -582,7 +592,7 @@ public final class YangModelBuilderUtil {
      * @return List of LengthConstraint created from this context
      */
     private static List<LengthConstraint> getLengthConstraints(
-            Type_body_stmtsContext ctx) {
+            final Type_body_stmtsContext ctx) {
         List<LengthConstraint> lengthConstraints = Collections.emptyList();
         outer: for (int j = 0; j < ctx.getChildCount(); j++) {
             ParseTree stringRestrChild = ctx.getChild(j);
@@ -607,7 +617,7 @@ public final class YangModelBuilderUtil {
      * @return List of LengthConstraints parsed from this context
      */
     private static List<LengthConstraint> parseLengthConstraints(
-            Length_stmtContext ctx) {
+            final Length_stmtContext ctx) {
         List<LengthConstraint> lengthConstraints = new ArrayList<LengthConstraint>();
         String description = null;
         String reference = null;
@@ -648,7 +658,7 @@ public final class YangModelBuilderUtil {
      * @return wrapper object of primitive java type or UnknownBoundaryNumber if
      *         type is one of special YANG values 'min' or 'max'
      */
-    private static Number parseNumberConstraintValue(String value) {
+    private static Number parseNumberConstraintValue(final String value) {
         Number result = null;
         if ("min".equals(value) || "max".equals(value)) {
             result = new UnknownBoundaryNumber(value);
@@ -664,7 +674,7 @@ public final class YangModelBuilderUtil {
     }
 
     private static List<PatternConstraint> getPatternConstraint(
-            Type_body_stmtsContext ctx) {
+            final Type_body_stmtsContext ctx) {
         List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
 
         outer: for (int j = 0; j < ctx.getChildCount(); j++) {
@@ -692,7 +702,7 @@ public final class YangModelBuilderUtil {
      * @return PatternConstraint object
      */
     private static PatternConstraint parsePatternConstraint(
-            Pattern_stmtContext ctx) {
+            final Pattern_stmtContext ctx) {
         String description = null;
         String reference = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -771,7 +781,8 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Internal helper method for parsing bit statements from given type body context.
+     * Internal helper method for parsing bit statements from given type body
+     * context.
      *
      * @param ctx
      *            type body context to parse
@@ -864,7 +875,8 @@ public final class YangModelBuilderUtil {
         }
 
         final List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
-        return new BitImpl(position, qname, schemaPath, description, reference, status, unknownNodes);
+        return new BitImpl(position, qname, schemaPath, description, reference,
+                status, unknownNodes);
     }
 
     /**
@@ -962,9 +974,10 @@ public final class YangModelBuilderUtil {
      *            current prefix
      * @return TypeDefinition object based on parsed values.
      */
-    public static TypeDefinition<?> parseTypeBody(String typeName,
-            Type_body_stmtsContext typeBody, List<String> actualPath,
-            URI namespace, Date revision, String prefix) {
+    public static TypeDefinition<?> parseTypeBody(final String typeName,
+            final Type_body_stmtsContext typeBody,
+            final List<String> actualPath, final URI namespace,
+            final Date revision, final String prefix) {
         TypeDefinition<?> type = null;
 
         List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
@@ -975,20 +988,34 @@ public final class YangModelBuilderUtil {
                 typeBody, actualPath, namespace, revision, prefix);
 
         if ("decimal64".equals(typeName)) {
-            type = YangTypesConverter.javaTypeForBaseYangDecimal64Type(
-                    rangeStatements, fractionDigits);
+            type = new Decimal64(actualPath, namespace, revision, fractionDigits);
         } else if (typeName.startsWith("int")) {
-            type = YangTypesConverter.javaTypeForBaseYangSignedIntegerType(
-                    typeName, rangeStatements);
+            if (typeName.equals("int8")) {
+                type = new Int8(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("int16")) {
+                type = new Int16(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("int32")) {
+                type = new Int32(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("int64")) {
+                type = new Int64(actualPath, namespace, revision, rangeStatements, null, null);
+            }
         } else if (typeName.startsWith("uint")) {
-            type = YangTypesConverter.javaTypeForBaseYangUnsignedIntegerType(
-                    typeName, rangeStatements);
+            if (typeName.equals("uint8")) {
+                type = new Uint8(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("uint16")) {
+                type = new Uint16(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("uint32")) {
+                type = new Uint32(actualPath, namespace, revision, rangeStatements, null, null);
+            } else if (typeName.equals("uint64")) {
+                type = new Uint64(actualPath, namespace, revision, rangeStatements, null, null);
+            }
         } else if ("enumeration".equals(typeName)) {
-            type = new EnumerationType(actualPath, namespace, revision, enumConstants);
+            type = new EnumerationType(actualPath, namespace, revision,
+                    enumConstants);
         } else if ("string".equals(typeName)) {
-            type = new StringType(lengthStatements, patternStatements);
+            type = new StringType(actualPath, namespace, revision, lengthStatements, patternStatements);
         } else if ("bits".equals(typeName)) {
-            type = new BitsType(getBits(typeBody, actualPath, namespace,
+            type = new BitsType(actualPath, namespace, revision, getBits(typeBody, actualPath, namespace,
                     revision, prefix));
         } else if ("leafref".equals(typeName)) {
             final String path = parseLeafrefPath(typeBody);
@@ -998,14 +1025,32 @@ public final class YangModelBuilderUtil {
             type = new Leafref(actualPath, namespace, revision, xpath);
         } else if ("binary".equals(typeName)) {
             List<Byte> bytes = Collections.emptyList();
-            type = new BinaryType(bytes, lengthStatements, null);
+            type = new BinaryType(actualPath, namespace, revision, bytes, lengthStatements, null);
         } else if ("instance-identifier".equals(typeName)) {
             boolean requireInstance = isRequireInstance(typeBody);
-            type = new InstanceIdentifier(null, requireInstance);
+            type = new InstanceIdentifier(actualPath, namespace, revision, null, requireInstance);
         }
         return type;
     }
 
+    public static String getIdentityrefBase(Type_body_stmtsContext ctx) {
+        String result = null;
+        outer:
+        for (int i = 0; i < ctx.getChildCount(); i++) {
+            ParseTree child = ctx.getChild(i);
+            if (child instanceof Identityref_specificationContext) {
+                for (int j = 0; j < child.getChildCount(); j++) {
+                    ParseTree baseArg = child.getChild(j);
+                    if (baseArg instanceof Base_stmtContext) {
+                        result = stringFromNode(baseArg);
+                        break outer;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
     private static boolean isRequireInstance(Type_body_stmtsContext ctx) {
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
@@ -1043,7 +1088,7 @@ public final class YangModelBuilderUtil {
      *            Must_stmtContext
      * @return MustDefinition object based on parsed context
      */
-    public static MustDefinition parseMust(YangParser.Must_stmtContext ctx) {
+    public static MustDefinition parseMust(final YangParser.Must_stmtContext ctx) {
         StringBuilder mustText = new StringBuilder();
         String description = null;
         String reference = null;
@@ -1091,33 +1136,33 @@ public final class YangModelBuilderUtil {
      *
      * @param ctx
      *            context to search
-     * @param constraintsBuilder
+     * @param constraints
      *            ConstraintsBuilder to fill
      */
-    public static void parseConstraints(ParseTree ctx,
-            ConstraintsBuilder constraintsBuilder) {
+    public static void parseConstraints(final ParseTree ctx,
+            final ConstraintsBuilder constraints) {
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
             if (childNode instanceof Max_elements_stmtContext) {
                 Integer max = Integer.valueOf(stringFromNode(childNode));
-                constraintsBuilder.setMinElements(max);
+                constraints.setMinElements(max);
             } else if (childNode instanceof Min_elements_stmtContext) {
                 Integer min = Integer.valueOf(stringFromNode(childNode));
-                constraintsBuilder.setMinElements(min);
+                constraints.setMinElements(min);
             } else if (childNode instanceof Must_stmtContext) {
                 MustDefinition must = parseMust((Must_stmtContext) childNode);
-                constraintsBuilder.addMustDefinition(must);
+                constraints.addMustDefinition(must);
             } else if (childNode instanceof Mandatory_stmtContext) {
                 for (int j = 0; j < childNode.getChildCount(); j++) {
                     ParseTree mandatoryTree = ctx.getChild(j);
                     if (mandatoryTree instanceof Mandatory_argContext) {
                         Boolean mandatory = Boolean
                                 .valueOf(stringFromNode(mandatoryTree));
-                        constraintsBuilder.setMandatory(mandatory);
+                        constraints.setMandatory(mandatory);
                     }
                 }
             } else if (childNode instanceof When_stmtContext) {
-                constraintsBuilder.addWhenCondition(stringFromNode(childNode));
+                constraints.addWhenCondition(stringFromNode(childNode));
             }
         }
     }
@@ -1149,52 +1194,86 @@ public final class YangModelBuilderUtil {
         return yinValue;
     }
 
-    public static List<RefineHolder> parseRefines(Uses_stmtContext ctx) {
-        List<RefineHolder> refines = new ArrayList<RefineHolder>();
-
-        for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
-            if (child instanceof Refine_stmtContext) {
-                String refineTarget = stringFromNode(child);
-                RefineHolder refine = new RefineHolder(refineTarget);
-                for (int j = 0; j < child.getChildCount(); j++) {
-                    ParseTree refinePom = child.getChild(j);
-                    if (refinePom instanceof Refine_pomContext) {
-                        for (int k = 0; k < refinePom.getChildCount(); k++) {
-                            ParseTree refineStmt = refinePom.getChild(k);
-                            if (refineStmt instanceof Refine_leaf_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_leaf_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_container_stmtsContext) {
-                                parseRefine(
-                                        refine,
-                                        (Refine_container_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_list_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_list_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
-                                parseRefine(
-                                        refine,
-                                        (Refine_leaf_list_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_choice_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_choice_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_anyxml_stmtsContext) refineStmt);
-                            }
-                        }
+//    public static List<RefineHolder> parseRefines(Uses_stmtContext ctx) {
+//        List<RefineHolder> refines = new ArrayList<RefineHolder>();
+//
+//        for (int i = 0; i < ctx.getChildCount(); i++) {
+//            ParseTree child = ctx.getChild(i);
+//            if (child instanceof Refine_stmtContext) {
+//                final String refineTarget = stringFromNode(child);
+//                final RefineHolder refine = new RefineHolder(refineTarget);
+//                for (int j = 0; j < child.getChildCount(); j++) {
+//                    ParseTree refinePom = child.getChild(j);
+//                    if (refinePom instanceof Refine_pomContext) {
+//                        for (int k = 0; k < refinePom.getChildCount(); k++) {
+//                            ParseTree refineStmt = refinePom.getChild(k);
+//                            if (refineStmt instanceof Refine_leaf_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_leaf_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_container_stmtsContext) {
+//                                parseRefine(
+//                                        refine,
+//                                        (Refine_container_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_list_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_list_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
+//                                parseRefine(
+//                                        refine,
+//                                        (Refine_leaf_list_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_choice_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_choice_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_anyxml_stmtsContext) refineStmt);
+//                            }
+//                        }
+//                    }
+//                }
+//                refines.add(refine);
+//            }
+//        }
+//        return refines;
+//    }
+
+    public static RefineHolder parseRefine(Refine_stmtContext child) {
+        final String refineTarget = stringFromNode(child);
+        final RefineHolder refine = new RefineHolder(refineTarget);
+        for (int j = 0; j < child.getChildCount(); j++) {
+            ParseTree refinePom = child.getChild(j);
+            if (refinePom instanceof Refine_pomContext) {
+                for (int k = 0; k < refinePom.getChildCount(); k++) {
+                    ParseTree refineStmt = refinePom.getChild(k);
+                    if (refineStmt instanceof Refine_leaf_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_leaf_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_container_stmtsContext) {
+                        parseRefine(
+                                refine,
+                                (Refine_container_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_list_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_list_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
+                        parseRefine(
+                                refine,
+                                (Refine_leaf_list_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_choice_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_choice_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_anyxml_stmtsContext) refineStmt);
                     }
                 }
-                refines.add(refine);
             }
         }
-        return refines;
+        return refine;
     }
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_leaf_stmtsContext refineStmt) {
-        refine.setType(Refine.LEAF);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Default_stmtContext) {
@@ -1220,7 +1299,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_container_stmtsContext refineStmt) {
-        refine.setType(Refine.CONTAINER);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1235,7 +1313,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_list_stmtsContext refineStmt) {
-        refine.setType(Refine.LIST);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1254,7 +1331,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_leaf_list_stmtsContext refineStmt) {
-        refine.setType(Refine.LEAF_LIST);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1273,7 +1349,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_choice_stmtsContext refineStmt) {
-        refine.setType(Refine.CHOICE);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Default_stmtContext) {
@@ -1295,7 +1370,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_anyxml_stmtsContext refineStmt) {
-        refine.setType(Refine.ANYXML);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Must_stmtContext) {