X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fparser%2Futil%2FYangModelBuilderUtil.java;h=e63f12839dfa8d4d883806bccf6f5e226d45a5bc;hb=1e9531138e44cd757ca27b0d86e98eccb22ccd82;hp=0df5d2cbdfc1eaf99be41250b2f220995b8251de;hpb=6e8fef270b6dc88f1dedca0c3e607a1a16e6ce2f;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java index 0df5d2cbdf..e63f12839d 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java @@ -36,7 +36,9 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.Length_stmtContex import org.opendaylight.controller.antlrv4.code.gen.YangParser.Mandatory_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Mandatory_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Max_elements_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Max_value_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Min_elements_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Min_value_argContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Must_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Numerical_restrictionsContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_argContext; @@ -372,6 +374,7 @@ public final class YangModelBuilderUtil { } if (value < -2147483648 || value > 2147483647) { throw new YangParseException( + ctx.getStart().getLine(), "Error on enum '" + name + "': the enum value MUST be in the range from -2147483648 to 2147483647, but was: " @@ -671,8 +674,8 @@ public final class YangModelBuilderUtil { try { result = Long.valueOf(value); } catch (NumberFormatException e) { - throw new YangParseException("Error on line " + line - + ": Unable to parse range value '" + value + "'.", e); + throw new YangParseException(line, + "Unable to parse range value '" + value + "'.", e); } } return result; @@ -790,7 +793,7 @@ public final class YangModelBuilderUtil { try { result = Integer.valueOf(value); } catch (NumberFormatException e) { - throw new YangParseException( + throw new YangParseException(ctx.getStart().getLine(), "Unable to parse fraction digits value '" + value + "'.", e); } @@ -888,6 +891,7 @@ public final class YangModelBuilderUtil { } if (position < 0 || position > 4294967295L) { throw new YangParseException( + ctx.getStart().getLine(), "Error on bit '" + name + "': the position value MUST be in the range 0 to 4294967295"); @@ -1004,60 +1008,51 @@ public final class YangModelBuilderUtil { List enumConstants = getEnumConstants( typeBody, actualPath, namespace, revision, prefix); + SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, + revision, prefix); + if ("decimal64".equals(typeName)) { - type = new Decimal64(actualPath, namespace, revision, - fractionDigits); + type = new Decimal64(schemaPath, fractionDigits); } else if (typeName.startsWith("int")) { if ("int8".equals(typeName)) { - type = new Int8(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Int8(schemaPath, rangeStatements, null, null); } else if ("int16".equals(typeName)) { - type = new Int16(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Int16(schemaPath, rangeStatements, null, null); } else if ("int32".equals(typeName)) { - type = new Int32(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Int32(schemaPath, rangeStatements, null, null); } else if ("int64".equals(typeName)) { - type = new Int64(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Int64(schemaPath, rangeStatements, null, null); } } else if (typeName.startsWith("uint")) { if ("uint8".equals(typeName)) { - type = new Uint8(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Uint8(schemaPath, rangeStatements, null, null); } else if ("uint16".equals(typeName)) { - type = new Uint16(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Uint16(schemaPath, rangeStatements, null, null); } else if ("uint32".equals(typeName)) { - type = new Uint32(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Uint32(schemaPath, rangeStatements, null, null); } else if ("uint64".equals(typeName)) { - type = new Uint64(actualPath, namespace, revision, - rangeStatements, null, null); + type = new Uint64(schemaPath, rangeStatements, null, null); } } else if ("enumeration".equals(typeName)) { - type = new EnumerationType(actualPath, namespace, revision, - enumConstants); + type = new EnumerationType(schemaPath, enumConstants); } else if ("string".equals(typeName)) { - type = new StringType(actualPath, namespace, revision, - lengthStatements, patternStatements); + type = new StringType(schemaPath, lengthStatements, + patternStatements); } else if ("bits".equals(typeName)) { - type = new BitsType(actualPath, namespace, revision, getBits( - typeBody, actualPath, namespace, revision, prefix)); + type = new BitsType(schemaPath, getBits(typeBody, actualPath, + namespace, revision, prefix)); } else if ("leafref".equals(typeName)) { final String path = parseLeafrefPath(typeBody); final boolean absolute = path.startsWith("/"); RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path, absolute); - type = new Leafref(actualPath, namespace, revision, xpath); + type = new Leafref(schemaPath, xpath); } else if ("binary".equals(typeName)) { List bytes = Collections.emptyList(); - type = new BinaryType(actualPath, namespace, revision, bytes, - lengthStatements, null); + type = new BinaryType(schemaPath, bytes, lengthStatements, null); } else if ("instance-identifier".equals(typeName)) { boolean requireInstance = isRequireInstance(typeBody); - type = new InstanceIdentifier(actualPath, namespace, revision, - null, requireInstance); + type = new InstanceIdentifier(schemaPath, null, requireInstance); } return type; } @@ -1193,10 +1188,10 @@ public final class YangModelBuilderUtil { 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)); - constraints.setMinElements(max); + Integer max = parseMaxElements((Max_elements_stmtContext) childNode); + constraints.setMaxElements(max); } else if (childNode instanceof Min_elements_stmtContext) { - Integer min = Integer.valueOf(stringFromNode(childNode)); + Integer min = parseMinElements((Min_elements_stmtContext) childNode); constraints.setMinElements(min); } else if (childNode instanceof Must_stmtContext) { MustDefinition must = parseMust((Must_stmtContext) childNode); @@ -1216,6 +1211,44 @@ public final class YangModelBuilderUtil { } } + private static Integer parseMinElements(Min_elements_stmtContext ctx) { + Integer result = null; + try { + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree minArg = ctx.getChild(j); + if (minArg instanceof Min_value_argContext) { + result = Integer.valueOf(stringFromNode(minArg)); + } + } + if (result == null) { + throw new IllegalArgumentException(); + } + return result; + } catch (Exception e) { + throw new YangParseException(ctx.getStart().getLine(), + "Failed to parse min-elements.", e); + } + } + + private static Integer parseMaxElements(Max_elements_stmtContext ctx) { + Integer result = null; + try { + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree maxArg = ctx.getChild(j); + if (maxArg instanceof Max_value_argContext) { + result = Integer.valueOf(stringFromNode(maxArg)); + } + } + if (result == null) { + throw new IllegalArgumentException(); + } + return result; + } catch (Exception e) { + throw new YangParseException(ctx.getStart().getLine(), + "Failed to parse max-elements.", e); + } + } + /** * Parse given context and return yin value. * @@ -1278,8 +1311,12 @@ public final class YangModelBuilderUtil { /** * Parse refine statement. - * @param refineCtx refine statement - * @return + * + * @param refineCtx + * refine statement + * @param line + * current line in yang model + * @return RefineHolder object representing this refine statement */ public static RefineHolder parseRefine(Refine_stmtContext refineCtx) { final String refineTarget = stringFromNode(refineCtx); @@ -1290,6 +1327,8 @@ public final class YangModelBuilderUtil { if (refinePom instanceof Refine_pomContext) { for (int k = 0; k < refinePom.getChildCount(); k++) { ParseTree refineStmt = refinePom.getChild(k); + parseRefineDefault(refine, refineStmt); + if (refineStmt instanceof Refine_leaf_stmtsContext) { parseRefine(refine, (Refine_leaf_stmtsContext) refineStmt); @@ -1315,6 +1354,23 @@ public final class YangModelBuilderUtil { return refine; } + private static void parseRefineDefault(RefineHolder refine, + ParseTree refineStmt) { + for (int i = 0; i < refineStmt.getChildCount(); i++) { + ParseTree refineArg = refineStmt.getChild(i); + if (refineArg instanceof Description_stmtContext) { + String description = stringFromNode(refineArg); + refine.setDescription(description); + } else if (refineArg instanceof Reference_stmtContext) { + String reference = stringFromNode(refineArg); + refine.setReference(reference); + } else if (refineArg instanceof Config_stmtContext) { + boolean config = parseConfig((Config_stmtContext) refineArg); + refine.setConfig(config); + } + } + } + private static RefineHolder parseRefine(RefineHolder refine, Refine_leaf_stmtsContext refineStmt) { for (int i = 0; i < refineStmt.getChildCount(); i++) { @@ -1362,10 +1418,10 @@ public final class YangModelBuilderUtil { MustDefinition must = parseMust((Must_stmtContext) refineArg); refine.setMust(must); } else if (refineArg instanceof Max_elements_stmtContext) { - Integer max = Integer.valueOf(stringFromNode(refineArg)); - refine.setMinElements(max); + Integer max = parseMaxElements((Max_elements_stmtContext) refineArg); + refine.setMaxElements(max); } else if (refineArg instanceof Min_elements_stmtContext) { - Integer min = Integer.valueOf(stringFromNode(refineArg)); + Integer min = parseMinElements((Min_elements_stmtContext) refineArg); refine.setMinElements(min); } } @@ -1380,10 +1436,10 @@ public final class YangModelBuilderUtil { MustDefinition must = parseMust((Must_stmtContext) refineArg); refine.setMust(must); } else if (refineArg instanceof Max_elements_stmtContext) { - Integer max = Integer.valueOf(stringFromNode(refineArg)); - refine.setMinElements(max); + Integer max = parseMaxElements((Max_elements_stmtContext) refineArg); + refine.setMaxElements(max); } else if (refineArg instanceof Min_elements_stmtContext) { - Integer min = Integer.valueOf(stringFromNode(refineArg)); + Integer min = parseMinElements((Min_elements_stmtContext) refineArg); refine.setMinElements(min); } }