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 8b33702d47636847a276288c1a8ce9726cd3c727..fff33b63bd513baa2b4e435b6266e497ce5ea874 100644 (file)
@@ -63,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;
@@ -84,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;
 
@@ -982,21 +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);
         } 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);
@@ -1006,10 +1025,10 @@ 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;
     }
@@ -1175,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) {
-                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);
-                            }
-                        }
+//    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) {
@@ -1246,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) {
@@ -1261,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) {
@@ -1280,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) {
@@ -1299,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) {
@@ -1321,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) {