[ONOS-4348] Yang Bits, Binary and Decimal64
Change-Id: I8e4e54a19a8f9634cbc56a07579a1730174f53f6
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
index 9f5e0cc..5e55e15 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
@@ -632,6 +632,22 @@
*
* @param currentContext current context in the parsed tree
*/
+ void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
+
+ /**
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule
+ * numericalRestrictions.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
+
+ /**
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule
+ * numericalRestrictions.
+ *
+ * @param currentContext current context in the parsed tree
+ */
void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext);
/**
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index a1daf0f..3d81e0d 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -37,11 +37,13 @@
import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
+import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
+import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
@@ -563,12 +565,22 @@
@Override
public void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- // TODO: implement the method.
+ Decimal64Listener.processDecimal64Entry(this, ctx);
}
@Override
public void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- // TODO: implement the method.
+ Decimal64Listener.processDecimal64Exit(this, ctx);
+ }
+
+ @Override
+ public void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext ctx) {
+ FractionDigitsListener.processFractionDigitsEntry(this, ctx);
+ }
+
+ @Override
+ public void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext) {
+ // do nothing
}
@Override
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
index 39084e0..4dce199 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
@@ -61,6 +61,8 @@
* ;
*/
+import java.util.Map;
+
import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -141,12 +143,13 @@
int maxPosition = 0;
boolean isPositionPresent = false;
- for (YangBit curBit : yangBits.getBitSet()) {
- if (maxPosition <= curBit.getPosition()) {
- maxPosition = curBit.getPosition();
+ for (Map.Entry<Integer, YangBit> element : yangBits.getBitPositionMap().entrySet()) {
+ if (maxPosition <= element.getKey()) {
+ maxPosition = element.getKey();
isPositionPresent = true;
}
}
+
if (isPositionPresent) {
maxPosition++;
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
new file mode 100644
index 0000000..45f58c8
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * type-body-stmts = numerical-restrictions /
+ * decimal64-specification /
+ * string-restrictions /
+ * enum-specification /
+ * leafref-specification /
+ * identityref-specification /
+ * instance-identifier-specification /
+ * bits-specification /
+ * union-specification
+ *
+ * decimal64-specification = fraction-digits-stmt [range-stmt stmtsep]
+ *
+ * fraction-digits-stmt = fraction-digits-keyword sep
+ * fraction-digits-arg-str stmtend
+ *
+ * fraction-digits-arg-str = < a string that matches the rule
+ * fraction-digits-arg >
+ *
+ * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
+ * "5" / "6" / "7" / "8"])
+ * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
+ *
+ * range-stmt = range-keyword sep range-arg-str optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [error-message-stmt stmtsep]
+ * [error-app-tag-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ * ANTLR grammar rule
+ *
+ * typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
+ * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
+ * | bitsSpecification | unionSpecification;
+ *
+ * decimal64Specification : fractionDigitStatement rangeStatement?;
+ *
+ * fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ *
+ * fraction : string;
+ */
+
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DECIMAL64_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "decimal64" rule
+ * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class Decimal64Listener {
+
+ /**
+ * Creates a new Decimal64 listener.
+ */
+ private Decimal64Listener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (decimal64), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDecimal64Entry(TreeWalkListener listener,
+ GeneratedYangParser.Decimal64SpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", ENTRY);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64 decimal64Node = new YangDecimal64();
+ typeNode.setDataTypeExtendedInfo(decimal64Node);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree.
+ * It is called when parser exits from grammar rule (decimal64).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDecimal64Exit(TreeWalkListener listener,
+ GeneratedYangParser.Decimal64SpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64<YangRangeRestriction> decimal64Node = typeNode.getDataTypeExtendedInfo();
+ try {
+ decimal64Node.validateRange();
+ } catch (DataModelException e) {
+ throw new ParserException(e);
+ }
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", EXIT));
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
new file mode 100644
index 0000000..baeb252
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * decimal64-specification = fraction-digits-stmt
+ *
+ * fraction-digits-stmt = fraction-digits-keyword sep
+ * fraction-digits-arg-str stmtend
+ *
+ * fraction-digits-arg-str = < a string that matches the rule
+ * fraction-digits-arg >
+ *
+ * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
+ * "5" / "6" / "7" / "8"])
+ * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
+ *
+ * ANTLR grammar rule
+ * decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ *
+ * fraction : string;
+ */
+
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FRACTION_DIGITS_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "fraction-digits"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class FractionDigitsListener {
+
+ /**
+ * Creates a new bit listener.
+ */
+ private FractionDigitsListener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (fraction-digits), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processFractionDigitsEntry(TreeWalkListener listener,
+ GeneratedYangParser.FractionDigitStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, FRACTION_DIGITS_DATA, ctx.fraction().getText(), ENTRY);
+
+ int value = getValidFractionDigits(ctx);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64 decimal64Node = typeNode.getDataTypeExtendedInfo();
+ decimal64Node.setFractionDigit(value);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FRACTION_DIGITS_DATA,
+ ctx.fraction().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * Validate fraction digits.
+ *
+ * @param ctx context object of the grammar rule
+ * @return validated fraction-digits
+ */
+ public static int getValidFractionDigits(GeneratedYangParser.FractionDigitStatementContext ctx) {
+ String value = ctx.fraction().getText().trim();
+ ParserException parserException;
+
+ int fractionDigits = Integer.parseInt(value);
+ if ((fractionDigits >= YangDecimal64.MIN_FRACTION_DIGITS_VALUE) &&
+ (fractionDigits <= YangDecimal64.MAX_FRACTION_DIGITS_VALUE)) {
+ return fractionDigits;
+ } else {
+ parserException =
+ new ParserException("YANG file error : fraction-digits value should be between 1 and 18.");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
index 4ae66bb..3a14927 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
@@ -109,17 +109,14 @@
switch (tmpNode.getYangConstructType()) {
case BITS_DATA: {
YangBits yangBits = (YangBits) tmpNode;
- for (YangBit curBit : yangBits.getBitSet()) {
- if (positionValue == curBit.getPosition()) {
- listener.getParsedDataStack().push(bitNode);
- ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
- "position is invalid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
listener.getParsedDataStack().push(bitNode);
+ if (yangBits.isBitPositionExists(positionValue)) {
+ ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
+ "position is invalid.");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
return positionValue;
}
default:
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
index 9c2a4bd..3b4ae43 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangDecimal64;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangRangeRestriction;
import org.onosproject.yangutils.datamodel.YangType;
@@ -25,6 +26,7 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
@@ -112,7 +114,7 @@
return;
}
- if (!(isOfRangeRestrictedType(type.getDataType()))) {
+ if (!(isOfRangeRestrictedType(type.getDataType())) && (type.getDataType() != DECIMAL64)) {
ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
"applied to a given type");
parserException.setLine(ctx.getStart().getLine());
@@ -122,8 +124,17 @@
YangRangeRestriction rangeRestriction = null;
try {
- rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(), false, ctx.range().getText(), type.getDataType());
+ if (type.getDataType() == DECIMAL64) {
+ YangDecimal64 yangDecimal64 = (YangDecimal64) type.getDataTypeExtendedInfo();
+ rangeRestriction = processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
+ ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ true, ctx.range().getText(), type.getDataType());
+ } else {
+ rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ false, ctx.range().getText(), type.getDataType());
+ }
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setCharPosition(e.getCharPositionInLine());
@@ -132,7 +143,12 @@
}
if (rangeRestriction != null) {
- type.setDataTypeExtendedInfo(rangeRestriction);
+ if (type.getDataType() == DECIMAL64) {
+ ((YangDecimal64<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+ .setRangeRestrictedExtendedInfo(rangeRestriction);
+ } else {
+ type.setDataTypeExtendedInfo(rangeRestriction);
+ }
}
listener.getParsedDataStack().push(rangeRestriction);
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index e108d14..3c7fba9 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -94,6 +94,7 @@
// Obtain the YANG data type.
YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
+ // validate type sub-statement cardinality
validateTypeSubStatementCardinality(ctx, yangDataTypes);
// Create YANG type object and fill the values.
@@ -306,6 +307,10 @@
parserException = new ParserException("YANG file error : a type bits" +
" must have atleast one bit statement.");
break;
+ case DECIMAL64:
+ parserException = new ParserException("YANG file error : a type decimal64" +
+ " must have fraction-digits statement.");
+ break;
case LEAFREF:
parserException = new ParserException("YANG file error : a type leafref" +
" must have one path statement.");
@@ -314,7 +319,6 @@
parserException = new ParserException("YANG file error : a type identityref" +
" must have base statement.");
break;
- // TODO : decimal64,
default:
return;
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 52595c7..91849b2 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -37,10 +37,13 @@
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
+import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
+import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
@@ -50,11 +53,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
@@ -97,10 +97,12 @@
return LONG;
case UINT64:
return BIG_INTEGER;
+ case BITS:
+ return BIT_SET;
case BINARY:
- return YANG_BINARY_CLASS;
+ return BYTE + SQUARE_BRACKETS;
case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
+ return BIG_DECIMAL;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
@@ -146,7 +148,7 @@
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
+ return BIG_DECIMAL;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
@@ -156,9 +158,9 @@
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
- return YANG_BITS_CLASS;
+ return BIT_SET;
case BINARY:
- return YANG_BINARY_CLASS;
+ return BYTE + SQUARE_BRACKETS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
@@ -184,8 +186,6 @@
switch (type) {
case UINT64:
return BIG_INTEGER;
- case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case ENUMERATION:
@@ -193,9 +193,9 @@
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
- return YANG_BITS_CLASS;
- case BINARY:
- return YANG_BINARY_CLASS;
+ return BIT_SET;
+ case DECIMAL64:
+ return BIG_DECIMAL;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
@@ -241,18 +241,18 @@
case UINT8:
case UINT16:
case UINT32:
+ case BINARY:
case STRING:
case BOOLEAN:
case EMPTY:
return JAVA_LANG;
case UINT64:
+ case DECIMAL64:
return JAVA_MATH;
case ENUMERATION:
return getEnumsPackage(yangType, conflictResolver);
- case DECIMAL64:
case BITS:
- case BINARY:
- return YANG_TYPES_PKG;
+ return COLLECTION_IMPORTS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
@@ -270,22 +270,20 @@
} else {
switch (type) {
case UINT64:
+ case DECIMAL64:
return JAVA_MATH;
+ case EMPTY:
case STRING:
return JAVA_LANG;
case ENUMERATION:
return getEnumsPackage(yangType, conflictResolver);
- case DECIMAL64:
case BITS:
- case BINARY:
- return YANG_TYPES_PKG;
+ return COLLECTION_IMPORTS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
return getIdentityRefPackage(yangType, conflictResolver);
- case EMPTY:
- return JAVA_LANG;
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 2f8c8d1..a5fc104 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -35,6 +35,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
+import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
@@ -54,6 +55,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
@@ -64,6 +66,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
@@ -133,6 +136,7 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
/**
* Represents generator for methods of generated files based on the file type.
@@ -296,6 +300,7 @@
case INT:
case SHORT:
case LONG:
+ case DOUBLE:
return "0";
case BOOLEAN_DATA_TYPE:
return FALSE;
@@ -748,10 +753,15 @@
JavaAttributeInfo fromStringAttributeInfo) {
String targetDataType = getReturnType(attr);
- String parseFromStringMethod = getParseFromStringMethod(targetDataType,
- fromStringAttributeInfo.getAttributeType());
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
- + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ if (fromStringAttributeInfo.getAttributeType().getDataType() == BINARY) {
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ + PERIOD + GET_BYTES + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
+ } else {
+ String parseFromStringMethod = getParseFromStringMethod(targetDataType,
+ fromStringAttributeInfo.getAttributeType());
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
+ + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ }
}
/**
@@ -1092,14 +1102,14 @@
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
+ case DECIMAL64:
+ return NEW + SPACE + BIG_DECIMAL;
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
- case DECIMAL64:
case BITS:
- case BINARY:
case UNION:
case ENUMERATION:
case DERIVED:
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index d56a2ed..fec23d3 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -197,6 +197,11 @@
public static final String PARSE_BYTE = "parseByte";
/**
+ * Static attribute for get bytes.
+ */
+ public static final String GET_BYTES = "getBytes";
+
+ /**
* Static attribute for parse boolean.
*/
public static final String PARSE_BOOLEAN = "parseBoolean";
@@ -567,6 +572,11 @@
public static final String CLOSE_CURLY_BRACKET = "}";
/**
+ * Static attribute for square brackets syntax.
+ */
+ public static final String SQUARE_BRACKETS = "[]";
+
+ /**
* Static attribute for getter method prefix.
*/
public static final String GET_METHOD_PREFIX = "get";
@@ -687,6 +697,16 @@
public static final String BIG_INTEGER = "BigInteger";
/**
+ * BigDecimal built in java type.
+ */
+ public static final String BIG_DECIMAL = "BigDecimal";
+
+ /**
+ * BitSet built in java type.
+ */
+ public static final String BIT_SET = "BitSet";
+
+ /**
* Byte java built in type.
*/
public static final String BYTE = "byte";
@@ -747,6 +767,11 @@
public static final String YANG_UINT64 = "YangUint64";
/**
+ * Double java built in wrapper type.
+ */
+ public static final String DOUBLE_WRAPPER = "Double";
+
+ /**
* List of keywords in java, this is used for checking if the input does not contain these keywords.
*/
public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
@@ -1136,16 +1161,6 @@
public static final String EVENT_LISTENER = "EventListener";
/**
- * Static attribute for YangBinary class.
- */
- public static final String YANG_BINARY_CLASS = "YangBinary";
-
- /**
- * Static attribute for YangBinary class.
- */
- public static final String YANG_BITS_CLASS = "YangBits";
-
- /**
* Static attribute for YANG types package.
*/
public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype";
@@ -1156,11 +1171,6 @@
public static final String MATH_CONTEXT = "MathContext";
/**
- * Static attribute for DECIMAL64 class.
- */
- public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
-
- /**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
diff --git a/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4 b/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
index 4fce152..eb23364 100644
--- a/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
+++ b/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
@@ -375,6 +375,13 @@
| bitsSpecification | unionSpecification;
/**
+ * decimal64-specification = ;; these stmts can appear in any order
+ * fraction-digits-stmt
+ * [range-stmt]
+ */
+ decimal64Specification : fractionDigitStatement rangeStatement?;
+
+ /**
* fraction-digits-stmt = fraction-digits-keyword sep
* fraction-digits-arg-str stmtend
*
@@ -385,7 +392,7 @@
* "5" / "6" / "7" / "8"])
* / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
*/
- decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
/**
* numerical-restrictions = range-stmt stmtsep