[ONOS-4070] Translator of YANG union.
Change-Id: I5216687b6ea7cb6baeb3ef8e905719468370a1f4
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index b652f48..b02b4e2 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -21,8 +21,9 @@
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfAttribute;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfLeafAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
/**
@@ -65,9 +66,9 @@
/**
* Creates object of java attribute info.
*
- * @param attrType YANG type
- * @param name attribute name
- * @param isListAttr is list attribute
+ * @param attrType YANG type
+ * @param name attribute name
+ * @param isListAttr is list attribute
* @param isQualifiedName is qualified name
*/
public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
@@ -78,6 +79,51 @@
}
/**
+ * Creates an attribute info object corresponding to the passed type's attribute
+ * information and return it.
+ *
+ * @param curNode current data model node for which the java file is being generated
+ * @param referredTypesAttrInfo attribute of referred type
+ * @return JavaAttributeInfo attribute details required to add in temporary files
+ */
+ public static JavaAttributeInfo getFromStringAttributeInfo(YangNode curNode,
+ JavaAttributeInfo referredTypesAttrInfo) {
+
+ JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(referredTypesAttrInfo);
+ /*
+ * Create a new java attribute info with qualified information of
+ * wrapper classes.
+ */
+ return getAttributeInfoForTheData(qualifiedInfoOfFromString, referredTypesAttrInfo.getAttributeName(),
+ referredTypesAttrInfo.getAttributeType(), curNode, false);
+ }
+
+ /**
+ * Creates an attribute info object corresponding to the passed type attribute
+ * information and return it.
+ *
+ * @param curNode current data model node for which the java file is being
+ * generated
+ * @param attributeType leaf data type
+ * @param attributeName leaf name
+ * @param isListAttribute is the current added attribute needs to be a list
+ * @return AttributeInfo attribute details required to add in temporary
+ * files
+ */
+ public static JavaAttributeInfo getAttributeInfoOfType(YangNode curNode,
+ YangType<?> attributeType, String attributeName,
+ boolean isListAttribute) {
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
+ attributeType, attributeName, isListAttribute);
+
+ return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
+ }
+
+ /**
* Returns the data type info of attribute.
*
* @return the data type info of attribute
@@ -144,7 +190,7 @@
* manner.
*
* @return the if the added attribute has to be accessed in a fully
- * qualified manner.
+ * qualified manner.
*/
public boolean isQualifiedName() {
return isQualifiedName;
@@ -155,7 +201,7 @@
* manner.
*
* @param isQualified if the added attribute has to be accessed in a fully
- * qualified manner
+ * qualified manner
*/
public void setIsQualifiedAccess(boolean isQualified) {
isQualifiedName = isQualified;
@@ -184,23 +230,23 @@
* Creates an attribute info object corresponding to the passed leaf
* information and return it.
*
- * @param curNode current data model node for which the java file is being
- * generated
- * @param attributeType leaf data type
- * @param attributeName leaf name
+ * @param curNode current data model node for which the java file is being
+ * generated
+ * @param attributeType leaf data type
+ * @param attributeName leaf name
* @param isListAttribute is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
- * files
+ * files
*/
public static JavaAttributeInfo getAttributeInfoOfLeaf(YangNode curNode,
- YangType<?> attributeType, String attributeName,
- boolean isListAttribute) {
+ YangType<?> attributeType, String attributeName,
+ boolean isListAttribute) {
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
- JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
+ JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
attributeType, attributeName, isListAttribute);
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
@@ -210,12 +256,12 @@
* Creates an attribute info object corresponding to a data model node and
* return it.
*
- * @param curNode current data model node for which the java code generation
- * is being handled
+ * @param curNode current data model node for which the java code generation
+ * is being handled
* @param parentNode parent node in which the current node is an attribute
* @param isListNode is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
- * files
+ * files
*/
public static JavaAttributeInfo getCurNodeAsAttributeInParent(
YangNode curNode, YangNode parentNode, boolean isListNode) {
@@ -233,43 +279,18 @@
}
/**
- * Creates an attribute info object corresponding to the passed type def attribute
- * information and return it.
- *
- * @param curNode current data model node for which the java file is being
- * generated
- * @param attributeType leaf data type
- * @param attributeName leaf name
- * @param isListAttribute is the current added attribute needs to be a list
- * @return AttributeInfo attribute details required to add in temporary
- * files
- */
- public static JavaAttributeInfo getAttributeInfoOfTypeDef(YangNode curNode,
- YangType<?> attributeType, String attributeName,
- boolean isListAttribute) {
-
- /*
- * Get the import info corresponding to the attribute for import in
- * generated java files or qualified access
- */
- JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
- attributeType, attributeName, isListAttribute);
-
- return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
- }
-
- /**
* Returns java attribute info.
*
- * @param importInfo java qualified type info
- * @param attributeName attribute name
- * @param attributeType attribute type
- * @param curNode current YANG node
+ * @param importInfo java qualified type info
+ * @param attributeName attribute name
+ * @param attributeType attribute type
+ * @param curNode current YANG node
* @param isListAttribute is list attribute
* @return java attribute info.
*/
private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
- YangType<?> attributeType, YangNode curNode, boolean isListAttribute) {
+ YangType<?> attributeType, YangNode curNode,
+ boolean isListAttribute) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
newAttr.setImportInfo(importInfo);