Optimizing Generate Code Function in Translator and updating enum/union to support a special hierarchical scenario
Change-Id: I14a971ff6fcda6ae5e86ffe4c11d17a844e371ce
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
index 469809c..f004d5e 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -31,18 +31,19 @@
/**
* Represents the enumeration data type information.
*/
-public class YangEnumeration implements Parsable {
+public class YangEnumeration extends YangNode implements Parsable {
// Enumeration info set.
private Set<YangEnum> enumSet;
// Enumeration name.
- private String enumerationName;
+ private String name;
/**
* Creates an enumeration object.
*/
public YangEnumeration() {
+ super(YangNodeType.ENUMERATION_NODE);
setEnumSet(new HashSet<YangEnum>());
}
@@ -77,21 +78,23 @@
}
/**
- * Return enumeration name.
+ * Returns enumeration name.
*
* @return the enumeration name
*/
- public String getEnumerationName() {
- return enumerationName;
+ @Override
+ public String getName() {
+ return name;
}
/**
* Sets the enumeration name.
*
- * @param enumerationName enumeration name
+ * @param name enumeration name
*/
- public void setEnumerationName(String enumerationName) {
- this.enumerationName = enumerationName;
+ @Override
+ public void setName(String name) {
+ this.name = name;
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
index 174ca39..35fe918 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
@@ -95,6 +95,11 @@
RPC_NODE,
/**
+ * Node contains "YANG's union" information.
+ */
+ UNION_NODE,
+
+ /**
* Node contains "YANG's list" information.
*/
LIST_NODE
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java b/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
index 5170871..21aabc0 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
@@ -16,13 +16,13 @@
package org.onosproject.yangutils.datamodel;
-import java.util.LinkedList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
+import java.util.LinkedList;
+import java.util.List;
+
/*
* Reference RFC 6020.
*
@@ -48,19 +48,24 @@
/**
* Represents data model node to maintain information defined in YANG union.
*/
-public class YangUnion implements Parsable {
+public class YangUnion extends YangNode implements Parsable {
// List of YANG type.
private List<YangType<?>> typeList;
// Name of union.
- private String unionName;
+ private String name;
+
+ // Current child union number.
+ private int childUnionNumber;
/**
* Creates a YANG union node.
*/
public YangUnion() {
+ super(YangNodeType.UNION_NODE);
typeList = new LinkedList<>();
+ childUnionNumber = 1;
}
/**
@@ -73,15 +78,6 @@
}
/**
- * Returns union name.
- *
- * @return the union name
- */
- public String getUnionName() {
- return unionName;
- }
-
- /**
* Sets the list of YANG type.
*
* @param typeList list of YANG type.
@@ -91,13 +87,31 @@
}
/**
- * Adds YANG type to type list.
+ * Returns running child union number.
+ *
+ * @return running child union number
+ */
+ public int getChildUnionNumber() {
+ return childUnionNumber;
+ }
+
+ /**
+ * Sets the running child union number.
+ *
+ * @param childUnionNumber running child union number
+ */
+ public void setChildUnionNumber(int childUnionNumber) {
+ this.childUnionNumber = childUnionNumber;
+ }
+
+ /**
+ * Add YANG type to type list.
*
* @param yangType YANG type to be added to list
* @throws DataModelException union member type must not be one of the
* built-in types "empty" or "leafref"
*/
- public void addToTypeList(YangType<?> yangType) throws DataModelException {
+ public void addType(YangType<?> yangType) throws DataModelException {
if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " +
"\"leafref\"");
@@ -106,12 +120,23 @@
}
/**
+ * Returns union name.
+ *
+ * @return the union name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
* Sets the union name.
*
- * @param unionName name of the union.
+ * @param name union name
*/
- public void setUnionName(String unionName) {
- this.unionName = unionName;
+ @Override
+ public void setName(String name) {
+ this.name = name;
}
@Override