[ONOS-5400][ONOS-5614] identity ref support in yangtools and defect fixes.
Change-Id: Ia1f32a6772e9d468717340953cf7598c61d9f1ed
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
index 7825503..ce57463 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
@@ -73,7 +73,7 @@
*
* @return the list of key field names
*/
- private List<String> getKeyList() {
+ public List<String> getKeyList() {
return unmodifiableList(keyList);
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
index 609f4ee..b6959e9 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
@@ -25,6 +25,8 @@
LIST,
+ MAP,
+
SET;
/**
@@ -36,7 +38,7 @@
public static YangDataStructure getDataStructureType(String name) {
name = name.replace("\"", "");
for (YangDataStructure dataStructure : values()) {
- if (dataStructure.name().toLowerCase().equals(name)) {
+ if (dataStructure.name().toLowerCase().equals(name.toLowerCase())) {
return dataStructure;
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
index 4cfd430..28aceec 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
@@ -16,15 +16,15 @@
package org.onosproject.yangutils.datamodel;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-
/*
* Reference:RFC 6020.
* The "leaf" statement is used to define a leaf node in the schema
@@ -140,6 +140,7 @@
*/
private YangLeaf referredLeaf;
+ private boolean isKeyLeaf;
/**
* Creates a YANG leaf.
*/
@@ -548,4 +549,21 @@
public void setReferredLeaf(YangLeaf leaf) {
referredLeaf = leaf;
}
+ /**
+ * Returns true if its a key leaf.
+ *
+ * @return true if its a key leaf
+ */
+ public boolean isKeyLeaf() {
+ return isKeyLeaf;
+ }
+
+ /**
+ * Sets true if its a key leaf.
+ *
+ * @param keyLeaf true if its a key leaf
+ */
+ public void setKeyLeaf(boolean keyLeaf) {
+ isKeyLeaf = keyLeaf;
+ }
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
index 3c1fed0..b07949e 100644
--- a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
@@ -196,8 +196,13 @@
try {
YangNode child = augment.getChild();
List<YangNode> childNodes = new ArrayList<>();
+ List<YangNode> caseNodes = new ArrayList<>();
while (child != null) {
- childNodes.add(child);
+ if (!(child instanceof YangCase)) {
+ childNodes.add(child);
+ } else {
+ caseNodes.add(child);
+ }
child = child.getNextSibling();
}
augment.setChild(null);
@@ -217,6 +222,19 @@
//Connect each node to its correct parent again.
connectTree(map);
}
+
+ for (YangNode node : caseNodes) {
+ Map<YangNode, List<YangNode>> map = new LinkedHashMap<>();
+ node.setNextSibling(null);
+ node.setPreviousSibling(null);
+ node.setParent(null);
+ //Break the tree to from a new tree.
+ traverseAndBreak(node, map);
+ augment.addChild(node);
+ node.setParent(augment);
+ //Connect each node to its correct parent again.
+ connectTree(map);
+ }
if (augment.getListOfLeaf() != null) {
for (YangLeaf leaf : augment.getListOfLeaf()) {
YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
index d05320a..6b14095 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
@@ -99,6 +99,11 @@
public static final int GENERATE_IDENTITY_CLASS = 2048;
/**
+ * Identity key class.
+ */
+ public static final int GENERATE_KEY_CLASS = 4096;
+
+ /**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index a5a644a..db3a5e1 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -172,7 +172,7 @@
* @param isQualified if the added attribute has to be accessed in a fully
* qualified manner
*/
- private void setIsQualifiedAccess(boolean isQualified) {
+ public void setIsQualifiedAccess(boolean isQualified) {
isQualifiedName = isQualified;
}
@@ -307,12 +307,12 @@
* @param compilerAnnotation compiler annotation
* @return java attribute info.
*/
- public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo,
- String attributeName, YangType<?> attributeType,
- boolean isQualifiedAccess, boolean isListAttribute,
- YangCompilerAnnotation compilerAnnotation) {
+ static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo,
+ String attributeName, YangType<?> attributeType,
+ boolean isQualifiedAccess, boolean isListAttribute,
+ YangCompilerAnnotation compilerAnnotation) {
JavaAttributeInfo newAttr = getAttributeInfoForTheData(importInfo, attributeName, attributeType,
- isQualifiedAccess, isListAttribute);
+ isQualifiedAccess, isListAttribute);
newAttr.setCompilerAnnotation(compilerAnnotation);
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 346fba2..2f1fbd2 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -24,7 +24,6 @@
import static java.util.Collections.unmodifiableSortedSet;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
-import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
@@ -67,6 +66,11 @@
private boolean isSetToImport;
/**
+ * Flag to denote if any map is imported due to compiler annotation.
+ */
+ private boolean isMapToImport;
+
+ /**
* Sorted set of import info, to be used to maintain the set of classes to
* be imported in the generated class.
*/
@@ -109,6 +113,15 @@
}
/**
+ * Sets true if map is imported due to compiler annotations.
+ *
+ * @param mapToImport true if map is imported due to compiler annotations
+ */
+ void setMapToImport(boolean mapToImport) {
+ isMapToImport = mapToImport;
+ }
+
+ /**
* Returns the set containing the imported class/interface info.
*
* @return the set containing the imported class/interface info
@@ -207,6 +220,9 @@
if (isSetToImport) {
imports.add(getImportForSet());
}
+ if (isMapToImport) {
+ imports.add(getImportForMap());
+ }
sort(imports);
return imports;
@@ -227,7 +243,7 @@
*
* @return import for to string method
*/
- public String getImportForToString() {
+ String getImportForToString() {
return getImportString(GOOGLE_MORE_OBJECT_IMPORT_PKG,
GOOGLE_MORE_OBJECT_IMPORT_CLASS);
}
@@ -246,15 +262,6 @@
*
* @return import for to bitset method
*/
- public String getImportForToBase64() {
- return getImportString(JAVA_UTIL_PKG, BASE64);
- }
-
- /**
- * Returns import for to bitset method.
- *
- * @return import for to bitset method
- */
public String getImportForPattern() {
return getImportString(JAVA_UTIL_REGEX_PKG, PATTERN);
}
@@ -269,6 +276,15 @@
}
/**
+ * Returns import for map attribute.
+ *
+ * @return import for map attribute
+ */
+ private String getImportForMap() {
+ return getImportString(COLLECTION_IMPORTS, MAP);
+ }
+
+ /**
* Returns import for queue attribute.
*
* @return import for queue attribute
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index abd72eb..b1c45e6 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
@@ -33,15 +34,18 @@
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
@@ -77,6 +81,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateKeyClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
@@ -91,6 +96,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
@@ -108,16 +114,21 @@
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.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
+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.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.ITR_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_PKG;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.METHOD;
import static org.onosproject.yangutils.utils.UtilConstants.METHOD_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -127,11 +138,13 @@
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
+import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.REFLECT_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SET_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBTREE_FILTERED;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.YANG;
@@ -276,6 +289,11 @@
private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
/**
+ * File name for list key class file name suffix.
+ */
+ private static final String KEY_CLASS_FILE_NAME_SUFFIX = KEYS;
+
+ /**
* if type is binary.
*/
private boolean isBinary;
@@ -337,6 +355,29 @@
private File implClassJavaFileHandle;
/**
+ * Returns java file handle for key class.
+ *
+ * @return java file handle for key class
+ */
+ public File getKeyClassJavaFileHandle() {
+ return keyClassJavaFileHandle;
+ }
+
+ /**
+ * Sets java file handle for key class.
+ *
+ * @param keyClassJavaFileHandle java file handle for key class
+ */
+ public void setKeyClassJavaFileHandle(File keyClassJavaFileHandle) {
+ this.keyClassJavaFileHandle = keyClassJavaFileHandle;
+ }
+
+ /**
+ * Java file handle for impl class file.
+ */
+ private File keyClassJavaFileHandle;
+
+ /**
* Temporary file handle for attribute.
*/
private File attributesTempFileHandle;
@@ -691,23 +732,28 @@
boolean collectionSet = false;
if (curNode instanceof YangList) {
YangList yangList = (YangList) curNode;
- if (yangList.getCompilerAnnotation() != null &&
- yangList.getCompilerAnnotation()
- .getYangAppDataStructure() != null) {
- switch (yangList.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure()) {
- case QUEUE: {
+ YangDataStructure ds = getYangDataStructure(
+ yangList.getCompilerAnnotation());
+ if (ds != null) {
+ switch (ds) {
+ case QUEUE:
parentImportData.setQueueToImport(true);
collectionSet = true;
break;
- }
- case SET: {
+
+ case SET:
parentImportData.setSetToImport(true);
collectionSet = true;
break;
- }
+
+ case MAP:
+ parentImportData.setMapToImport(true);
+ collectionSet = true;
+ break;
+
default: {
- // TODO : to be implemented
+ parentImportData.setIfListImported(true);
+ collectionSet = true;
}
}
}
@@ -765,6 +811,7 @@
* @param config plugin configurations
* @param listAttribute flag indicating if list attribute
* @return JAVA attribute information
+ * @throws IOException when fails to do IO operations
*/
private static JavaAttributeInfo
getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
@@ -790,6 +837,41 @@
}
/**
+ * Returns list of java attribute for keys of list node.
+ *
+ * @param curNode current list node
+ * @return attribute list
+ * @throws IOException when fails to do IO operations
+ */
+ public static List<JavaAttributeInfo> getListOfAttributesForKey(
+ YangNode curNode) throws IOException {
+ List<String> keys = ((YangList) curNode).getKeyList();
+
+ JavaFileInfoTranslator fileInfo =
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ YangLeavesHolder holder = (YangLeavesHolder) curNode;
+ Iterator<String> keyIt = keys.iterator();
+ Iterator<YangLeaf> leafIt;
+ String key;
+ YangJavaLeafTranslator leaf;
+ TempJavaBeanFragmentFiles beanFile = getBeanFiles(curNode);
+ List<JavaAttributeInfo> attrs = new ArrayList<>();
+ while (keyIt.hasNext()) {
+ key = keyIt.next();
+ leafIt = holder.getListOfLeaf().iterator();
+ while (leafIt.hasNext()) {
+ leaf = (YangJavaLeafTranslator) leafIt.next();
+ if (key.equals(leaf.getName())) {
+ attrs.add(getAttributeOfLeafInfoContainer(
+ beanFile, leaf,
+ fileInfo.getPluginConfig(), false));
+ }
+ }
+ }
+ return attrs;
+ }
+
+ /**
* Adds bits handler attribute for bits to string method.
*
* @param attr attribute
@@ -1123,21 +1205,22 @@
throws IOException {
String getter = getGetterForClass(attr, getGeneratedJavaFiles());
String javadoc = getOverRideString();
+ YangDataStructure ds = getYangDataStructure(
+ attr.getCompilerAnnotation());
+ String annotation = null;
+ if (ds != null) {
+ annotation = ds.name();
+ }
if (attr.getAttributeName().equals(SUBTREE_FILTERED)) {
javadoc = getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
- false, null);
+ false, annotation);
}
if (javaFlagSet(BUILDER_CLASS_MASK)) {
appendToFile(getterImplTempFileHandle, javadoc + getter);
} else {
- String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure().name();
- }
appendToFile(getterImplTempFileHandle,
getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
- false, appDataStructure) + getter);
+ false, annotation) + getter);
}
}
@@ -1149,9 +1232,15 @@
*/
private void addAddToListInterface(JavaAttributeInfo attr)
throws IOException {
+ YangDataStructure ds = getYangDataStructure(
+ attr.getCompilerAnnotation());
+ String annotation = null;
+ if (ds != null) {
+ annotation = ds.name();
+ }
appendToFile(addToListInterfaceTempFileHandle,
getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
- null) + getAddToListMethodInterface(
+ annotation) + getAddToListMethodInterface(
attr, getGeneratedJavaClassName()) + NEW_LINE);
}
@@ -1383,9 +1472,17 @@
if (attr.isQualifiedName()) {
pkg = attr.getImportInfo().getPkgInfo();
}
+ String attrType = attr.getImportInfo().getClassInfo();
+ if (attr.getAttributeType() != null &&
+ attr.getAttributeType().getDataType() == IDENTITYREF) {
+ attrType = CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + SPACE + EXTEND + SPACE +
+ attrType + DIAMOND_CLOSE_BRACKET;
+ }
+
return getJavaAttributeDefinition(
- pkg, attr.getImportInfo().getClassInfo(), attrName,
- attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
+ pkg, attrType, attrName, attr.isListAttr(), attrAccessType,
+ attr.getCompilerAnnotation());
}
/**
@@ -1795,6 +1892,8 @@
addImportsForSubTreeFilterAug(imports);
}
addSubTreeImportStrings(imports);
+ } else {
+ removeCaseParentImport(curNode, imports);
}
if ((fileType & BUILDER_CLASS_MASK) != 0 ||
@@ -1838,10 +1937,33 @@
insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
validateLineLength(implClassJavaFileHandle);
}
+
+ if (curNode instanceof YangList) {
+ YangList list = (YangList) curNode;
+ YangDataStructure data = getYangDataStructure(
+ list.getCompilerAnnotation());
+ if (list.isConfig() && data == YangDataStructure.MAP) {
+ keyClassJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(
+ KEY_CLASS_FILE_NAME_SUFFIX));
+ keyClassJavaFileHandle =
+ generateKeyClassFile(keyClassJavaFileHandle, curNode);
+
+ }
+ }
//Close all the file handles.
freeTemporaryResources(false);
}
+ //Removes case's parent import.
+ private void removeCaseParentImport(YangNode node, List<String> imports) {
+ YangNode parent = node.getParent();
+ JavaFileInfo info = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ String impt = getImportString(info.getPackage(),
+ getCapitalCase(info.getJavaName()));
+ imports.remove(impt);
+ }
+
private void addImportsForSubTreeFilterAug(List<String> imports) {
if (!imports.contains(SET_IMPORT)) {
imports.add(SET_IMPORT);
@@ -2155,7 +2277,11 @@
private void addSubTreeImportStrings(List<String> imports) {
for (JavaQualifiedTypeInfoTranslator impt : subTreeImports) {
- imports.add(getImportString(impt.getPkgInfo(), impt.getClassInfo()));
+ String imp = getImportString(impt.getPkgInfo(), impt
+ .getClassInfo());
+ if (!imports.contains(imp)) {
+ imports.add(imp);
+ }
}
sortImports(imports);
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 00d7a19..6bcbb1b 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -546,7 +546,7 @@
* @param cnfg YANG to java naming conflict util
* @return import class
*/
- private static String getIdentityRefImpClass(
+ public static String getIdentityRefImpClass(
YangType type, YangToJavaNamingConflictUtil cnfg) {
YangIdentityRef ir = (YangIdentityRef) type.getDataTypeExtendedInfo();
if (ir.isInGrouping()) {
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java
index b36de60..26c9a1b 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java
@@ -16,7 +16,6 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaGrouping;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
index 9161afe..9051d17 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
@@ -35,13 +35,17 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodForIdentity;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodForIdentity;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_FILE_EXTENSION;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
/**
@@ -127,7 +131,8 @@
JavaQualifiedTypeInfoTranslator basePkgInfo =
new JavaQualifiedTypeInfoTranslator();
JavaFileInfoTranslator itsInfo = getJavaFileInfo();
- String className = getCapitalCase(itsInfo.getJavaName());
+ String name = itsInfo.getJavaName();
+ String className = getCapitalCase(name);
String path = itsInfo.getPackageFilePath();
createPackage(this);
List<String> imports = null;
@@ -158,7 +163,8 @@
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
file = validateLineLength(file);
//Add to string and from string method to class
- addStringMethodsToClass(file);
+ addStringMethodsToClass(file, name);
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
closeFile(file, false);
} catch (IOException e) {
@@ -167,8 +173,10 @@
}
}
- private void addStringMethodsToClass(File file) {
- //TODO: add implementation.
+ private void addStringMethodsToClass(File file, String className) throws IOException {
+ insertDataIntoJavaFile(file, getToStringMethodForIdentity(getName()));
+ insertDataIntoJavaFile(file, getFromStringMethodForIdentity(
+ className, getName()));
}
/**
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 9abd058..03431df 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -36,6 +36,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -47,6 +48,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithExtends;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithImpl;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultName;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefinitionWithImplements;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getErrorMsg;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getEventExtendsString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSpecificModifier;
@@ -56,6 +58,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPARABLE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
@@ -148,6 +151,8 @@
return getEventDefinition(yangName, eventName);
case GENERATE_EVENT_LISTENER_INTERFACE:
return getEventListenerDefinition(yangName);
+ case GENERATE_KEY_CLASS:
+ return getKeyClassDefinition(yangName);
case GENERATE_EVENT_SUBJECT_CLASS:
return getClassDefinition(yangName);
case GENERATE_IDENTITY_CLASS:
@@ -260,6 +265,18 @@
}
/**
+ * Returns impl file class definition.
+ *
+ * @param yangName file name
+ * @return definition
+ */
+ private static String getKeyClassDefinition(String yangName) {
+ String compareName = COMPARABLE + brackets(
+ OPEN_CLOSE_DIAMOND_WITH_VALUE, yangName, null);
+ return getDefinitionWithImplements(CLASS, yangName, PUBLIC, compareName);
+ }
+
+ /**
* Returns implementation file identity class definition.
*
* @param yangName file name
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index 4cdf2e3..56bde74 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
@@ -28,6 +29,7 @@
import static java.util.Collections.sort;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOpenCloseParaWithValue;
@@ -45,9 +47,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
@@ -156,14 +160,16 @@
attrDef.append(signatureClose());
} else {
- // Add starting definition.
- addAttrStartDef(annotation, attrDef);
-
+ StringBuilder type = new StringBuilder();
if (typePkg != null) {
- attrDef.append(typePkg).append(PERIOD);
+ type.append(typePkg).append(PERIOD);
}
- attrDef.append(attrType);
+ type.append(attrType);
+
+ // Add starting definition.
+ addAttrStartDef(annotation, attrDef, type.toString());
+
// Add ending definition.
addAttrEndDef(attrDef, attrName);
@@ -176,12 +182,13 @@
*
* @param annotation compiler annotation
* @param attrDef JAVA attribute definition
+ * @param type attr type
*/
private static void addAttrStartDef(YangCompilerAnnotation annotation,
- StringBuilder attrDef) {
- if (annotation != null &&
- annotation.getYangAppDataStructure() != null) {
- switch (annotation.getYangAppDataStructure().getDataStructure()) {
+ StringBuilder attrDef, String type) {
+ YangDataStructure ds = getYangDataStructure(annotation);
+ if (ds != null) {
+ switch (ds) {
case QUEUE: {
attrDef.append(QUEUE)
.append(DIAMOND_OPEN_BRACKET);
@@ -192,6 +199,10 @@
.append(DIAMOND_OPEN_BRACKET);
break;
}
+ case MAP:
+ attrDef.append(MAP).append(DIAMOND_OPEN_BRACKET)
+ .append(type).append(KEYS).append(COMMA);
+ break;
default: {
attrDef.append(LIST)
.append(DIAMOND_OPEN_BRACKET);
@@ -200,6 +211,7 @@
} else {
attrDef.append(LIST).append(DIAMOND_OPEN_BRACKET);
}
+ attrDef.append(type);
}
/**
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index 7bc490f..6b9f346 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -19,9 +19,9 @@
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
@@ -32,6 +32,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
@@ -41,11 +42,10 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import static java.util.Collections.sort;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
@@ -53,6 +53,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -80,10 +81,12 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
+import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getListOfAttributesForKey;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired;
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getSetValueParaForUnionClass;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
@@ -97,6 +100,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassFromString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassToString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCompareToForKeyClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfValueMethod;
@@ -105,11 +109,13 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringForEnumClass;
@@ -122,6 +128,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIsSelectLeafSet;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIsValueLeafSet;
@@ -155,6 +162,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
@@ -166,6 +174,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.UNION_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -454,6 +463,85 @@
}
/**
+ * Returns generated key class file for current list node.
+ *
+ * @param file file
+ * @param curNode current YANG node
+ * @return key class file
+ * @throws IOException when fails to write in file
+ */
+ public static File generateKeyClassFile(File file, YangNode curNode)
+ throws IOException {
+
+ JavaFileInfoTranslator fileInfo =
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String className = getCapitalCase(fileInfo.getJavaName()) + KEYS;
+ List<String> imports = new ArrayList<>();
+
+ YangNode parent = curNode.getParent();
+ JavaImportData importData = ((JavaCodeGeneratorInfo) parent)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles()
+ .getJavaImportData();
+ JavaQualifiedTypeInfoTranslator info =
+ new JavaQualifiedTypeInfoTranslator();
+ info.setClassInfo(className);
+ info.setPkgInfo(fileInfo.getPackage());
+ importData.addImportInfo(info, parent.getJavaClassNameOrBuiltInType(),
+ parent.getJavaPackage());
+ List<String> keys = ((YangList) curNode).getKeyList();
+ List<JavaAttributeInfo> attrs = getListOfAttributesForKey(curNode);
+
+ Iterator<JavaAttributeInfo> attrIt = attrs.iterator();
+ JavaAttributeInfo attr;
+ JavaQualifiedTypeInfoTranslator typeInfo;
+ while (attrIt.hasNext()) {
+ attr = attrIt.next();
+ typeInfo = attr.getImportInfo();
+ if (!typeInfo.getClassInfo().equals(className)) {
+ imports.add(getImportString(attr.getImportInfo().getPkgInfo(),
+ attr.getImportInfo().getClassInfo()));
+ } else {
+ attr.setIsQualifiedAccess(true);
+ }
+ }
+
+ initiateJavaFileGeneration(file, GENERATE_KEY_CLASS, imports, curNode,
+ className);
+ String pkg = null;
+ attrIt = attrs.iterator();
+ while (attrIt.hasNext()) {
+ attr = attrIt.next();
+ if (attr.isQualifiedName()) {
+ pkg = attr.getImportInfo().getPkgInfo();
+ }
+ insertDataIntoJavaFile(file, getJavaAttributeDefinition(
+ pkg, attr.getImportInfo().getClassInfo(),
+ attr.getAttributeName(), false, PROTECTED, null));
+ }
+ attrIt = attrs.iterator();
+ while (attrIt.hasNext()) {
+ attr = attrIt.next();
+ //add getter methods
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, attr
+ .getAttributeName(), false, null));
+ insertDataIntoJavaFile(file, getGetterForClass(
+ attr, GENERATE_KEY_CLASS));
+ insertDataIntoJavaFile(file, NEW_LINE);
+ //Add setter methods.
+ insertDataIntoJavaFile(file, getJavaDoc(MANAGER_SETTER_METHOD, attr
+ .getAttributeName(), false, null));
+ insertDataIntoJavaFile(file, getSetterForClass(
+ attr, className, GENERATE_EVENT_SUBJECT_CLASS));
+ insertDataIntoJavaFile(file, NEW_LINE);
+ }
+ insertDataIntoJavaFile(file, getCompareToForKeyClass(attrs, className));
+
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
+ return file;
+ }
+
+ /**
* Returns generated default class file for current node.
*
* @param file file
@@ -701,25 +789,12 @@
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
//From string method.
- if (type.getDataType() == DERIVED &&
- ((YangDerivedInfo) type.getDataTypeExtendedInfo())
- .getEffectiveBuiltInType()
- == IDENTITYREF) {
- yangDataTypes = IDENTITYREF;
- }
-
- if (type.getDataType() == IDENTITYREF) {
- yangDataTypes = IDENTITYREF;
- }
-
- if (yangDataTypes != IDENTITYREF) {
- methods.add(getFromStringMethodSignature(className) +
- getDataFromTempFileHandle(
- FROM_STRING_IMPL_MASK,
- javaGenInfo.getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(), path) +
- getFromStringMethodClose());
- }
+ methods.add(getFromStringMethodSignature(className) +
+ getDataFromTempFileHandle(
+ FROM_STRING_IMPL_MASK,
+ javaGenInfo.getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path) +
+ getFromStringMethodClose());
} catch (IOException e) {
throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index b48f48a..66950b5 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -54,6 +54,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_KEY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -88,7 +89,6 @@
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getNodesPackage;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_FOR_GEN_CODE;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -451,38 +451,41 @@
switch (genType) {
case INTERFACE_MASK:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, INTERFACE, curNode, className);
+ write(file, genType, INTERFACE, curNode, className, false);
+ break;
+ case GENERATE_KEY_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, DEFAULT_CLASS, curNode, className, false);
break;
case DEFAULT_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, DEFAULT_CLASS, curNode, className);
+ write(file, genType, DEFAULT_CLASS, curNode, className, true);
break;
case BUILDER_CLASS_MASK:
- write(file, genType, BUILDER_CLASS, curNode, className);
+ write(file, genType, BUILDER_CLASS, curNode, className, false);
break;
case BUILDER_INTERFACE_MASK:
- write(file, genType, BUILDER_INTERFACE, curNode, className);
+ write(file, genType, BUILDER_INTERFACE, curNode, className, false);
break;
case GENERATE_SERVICE_AND_MANAGER:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, RPC_INTERFACE, curNode, className);
+ write(file, genType, RPC_INTERFACE, curNode, className, false);
break;
case GENERATE_EVENT_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT, curNode, className);
+ write(file, genType, EVENT, curNode, className, false);
break;
case GENERATE_EVENT_LISTENER_INTERFACE:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_LISTENER, curNode, className);
+ write(file, genType, EVENT_LISTENER, curNode, className, false);
break;
case GENERATE_EVENT_SUBJECT_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
+ write(file, genType, EVENT_SUBJECT_CLASS, curNode, className, false);
break;
case GENERATE_IDENTITY_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
+ write(file, genType, EVENT_SUBJECT_CLASS, curNode, className, false);
break;
default:
break;
@@ -582,13 +585,14 @@
* @param javaDocType java doc type
* @param curNode current YANG node
* @param fileName file name
+ * @param isForClass is for default class
* @throws IOException when fails to write into a file
*/
private static void write(File file, int genType, JavaDocType javaDocType,
- YangNode curNode, String fileName)
+ YangNode curNode, String fileName, boolean isForClass)
throws IOException {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName,
- false, null));
+ isForClass, null));
insertDataIntoJavaFile(file, generateClassDefinition(genType,
fileName, curNode));
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index b0a7032..5886939 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -18,10 +18,14 @@
import org.onosproject.yangutils.datamodel.InvalidOpTypeHolder;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangAppDataStructure;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
@@ -31,9 +35,12 @@
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
@@ -77,6 +84,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getStringBuilderAttr;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getToStringCall;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getTrySubString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getTwoParaEqualsString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifAndAndCondition;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifConditionForIntInTypeDefConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifEqualEqualCondition;
@@ -108,9 +116,12 @@
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPARE_TO;
import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
+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.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
@@ -119,6 +130,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
import static org.onosproject.yangutils.utils.UtilConstants.FOR_TYPE_STRING;
@@ -137,11 +149,15 @@
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
+import static org.onosproject.yangutils.utils.UtilConstants.LINKED_HASH_MAP;
+import static org.onosproject.yangutils.utils.UtilConstants.LINKED_HASH_SET;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.NEG_ONE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
@@ -155,14 +171,17 @@
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PRIORITY_QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.PUT;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
@@ -193,11 +212,13 @@
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
@@ -256,9 +277,11 @@
String appDataStructure = null;
StringBuilder builder = new StringBuilder();
if (attr.getCompilerAnnotation() != null) {
- appDataStructure =
- attr.getCompilerAnnotation().getYangAppDataStructure()
- .getDataStructure().name();
+ YangDataStructure data = getYangDataStructure(
+ attr.getCompilerAnnotation());
+ if (data != null) {
+ appDataStructure = data.name();
+ }
}
if (genType == GENERATE_SERVICE_AND_MANAGER) {
builder.append(generateForGetMethodWithAttribute(returnType))
@@ -300,10 +323,10 @@
}
String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure =
- attr.getCompilerAnnotation().getYangAppDataStructure()
- .getDataStructure().name();
+ YangDataStructure ds = getYangDataStructure(
+ attr.getCompilerAnnotation());
+ if (ds != null) {
+ appDataStructure = ds.name();
}
builder.append(getJavaDoc(type, attributeName, attr.isListAttr(),
appDataStructure))
@@ -613,12 +636,20 @@
private static String getReturnType(JavaAttributeInfo attr) {
String returnType;
StringBuilder builder = new StringBuilder();
+
if (attr.isQualifiedName() &&
attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
builder.append(returnType);
}
returnType = attr.getImportInfo().getClassInfo();
+
+ if (attr.getAttributeType() != null &&
+ attr.getAttributeType().getDataType() == IDENTITYREF) {
+ returnType = CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + SPACE + EXTEND + SPACE +
+ returnType + DIAMOND_CLOSE_BRACKET;
+ }
builder.append(returnType);
return builder.toString();
}
@@ -981,6 +1012,14 @@
*/
public static String getEqualsMethod(JavaAttributeInfo attr) {
String attributeName = attr.getAttributeName();
+ if (attributeName.contains(OPERATION_TYPE_ATTRIBUTE)) {
+ return SIXTEEN_SPACE_INDENTATION + OBJECT_STRING + SUFFIX_S +
+ NEW_LINE + SIXTEEN_SPACE_INDENTATION +
+ PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + attributeName +
+ COMMA + NEW_LINE + SIXTEEN_SPACE_INDENTATION + SPACE + OTHER
+ + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND +
+ AND;
+ }
return SIXTEEN_SPACE_INDENTATION + OBJECT_STRING + SUFFIX_S +
PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + attributeName +
COMMA + SPACE + OTHER + PERIOD + attributeName +
@@ -994,6 +1033,7 @@
* @param className class name
* @return of method's string and java doc for special type
*/
+
public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr,
String className) {
String attrType = getReturnType(attr);
@@ -1163,8 +1203,8 @@
map.put(VALUE, OBJECT_STRING);
map.put(CLASS + OBJECT_STRING, CLASS_STRING);
builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- EMPTY_STRING, EMPTY_STRING,
- className, map, INTERFACE_TYPE));
+ null, null, className, map,
+ INTERFACE_TYPE));
return builder.toString();
}
@@ -1180,14 +1220,13 @@
map.put(VALUE, OBJECT_STRING);
map.put(CLASS + OBJECT_STRING, CLASS_STRING);
builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- EMPTY_STRING, PUBLIC,
+ null, PUBLIC,
className, map, CLASS_TYPE))
.append(methodBody(AUGMENTED_MAP_ADD, null, null,
EIGHT_SPACE_INDENTATION, null, null, false, null))
.append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
.append(signatureClose())
- .append(methodClose(FOUR_SPACE))
- .append(NEW_LINE);
+ .append(methodClose(FOUR_SPACE));
return builder.toString();
}
@@ -1467,14 +1506,48 @@
public static String getAddToListMethodInterface(JavaAttributeInfo attr,
String className) {
- return methodSignature(ADD_STRING + TO_CAPS + getCapitalCase(
- attr.getAttributeName()), EMPTY_STRING, EMPTY_STRING,
- ADD_STRING + TO_CAPS,
+ String methodName = ADD_STRING + TO_CAPS + getCapitalCase(
+ attr.getAttributeName());
+ String retType = getReturnType(attr);
+ YangDataStructure struct = getYangDataStructure(attr.getCompilerAnnotation());
+ if (struct != null) {
+ switch (struct) {
+ case MAP:
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(attr.getAttributeName() + KEYS, retType + KEYS);
+ param.put(attr.getAttributeName() + VALUE_CAPS, retType);
+ return multiAttrMethodSignature(methodName, null, null,
+ className + BUILDER, param,
+ INTERFACE_TYPE);
+ default:
+ return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
+ className + BUILDER, retType,
+ INTERFACE_TYPE);
+ }
+ }
+ return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
className + BUILDER, getReturnType(attr),
INTERFACE_TYPE);
}
/**
+ * Returns YANG data structure from java attribute.
+ *
+ * @param annotation compiler annotation
+ * @return YANG data structure from java attribute
+ */
+ public static YangDataStructure getYangDataStructure(
+ YangCompilerAnnotation annotation) {
+ if (annotation != null) {
+ YangAppDataStructure data = annotation.getYangAppDataStructure();
+ if (data != null) {
+ return data.getDataStructure();
+ }
+ }
+ return null;
+ }
+
+ /**
* Returns add to list method impl.
*
* @param attr java attribute
@@ -1485,29 +1558,92 @@
String name) {
String attrName = attr.getAttributeName();
String retString = getOverRideString();
+ String methodName = ADD_STRING + TO_CAPS + getCapitalCase(attrName);
StringBuilder builder = new StringBuilder(retString);
- builder.append(methodSignature(ADD_STRING + TO_CAPS +
- getCapitalCase(attrName),
- EMPTY_STRING, PUBLIC, ADD_STRING + TO_CAPS,
- name + BUILDER, getReturnType(attr),
- CLASS_TYPE))
- .append(getIfConditionForAddToListMethod(attrName));
- retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD + ADD_STRING +
- OPEN_PARENTHESIS + ADD_STRING + TO_CAPS + CLOSE_PARENTHESIS;
+ String retType = getReturnType(attr);
+ YangDataStructure struct = getYangDataStructure(attr.getCompilerAnnotation());
+ if (struct != null) {
+ switch (struct) {
+ case MAP:
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(attr.getAttributeName() + KEYS, retType + KEYS);
+ param.put(attr.getAttributeName() + VALUE_CAPS, retType);
+ builder.append(multiAttrMethodSignature(methodName,
+ null, PUBLIC,
+ name + BUILDER, param,
+ CLASS_TYPE))
+ .append(getIfConditionForAddToListMethod(attr));
+ retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD +
+ PUT + getOpenCloseParaWithValue(
+ attrName + KEYS + COMMA + SPACE + attrName +
+ VALUE_CAPS);
+ break;
+ default:
+ builder.append(methodSignature(methodName,
+ null, PUBLIC,
+ ADD_STRING + TO_CAPS,
+ name + BUILDER, retType,
+ CLASS_TYPE))
+ .append(getIfConditionForAddToListMethod(attr));
+ retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD + ADD_STRING +
+ OPEN_PARENTHESIS + ADD_STRING + TO_CAPS + CLOSE_PARENTHESIS;
+
+ }
+ } else {
+ builder.append(methodSignature(ADD_STRING + TO_CAPS +
+ getCapitalCase(attrName),
+ null, PUBLIC, ADD_STRING + TO_CAPS,
+ name + BUILDER, retType,
+ CLASS_TYPE))
+ .append(getIfConditionForAddToListMethod(attr));
+ retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD + ADD_STRING +
+ OPEN_PARENTHESIS + ADD_STRING + TO_CAPS + CLOSE_PARENTHESIS;
+ }
builder.append(retString)
.append(signatureClose())
.append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
.append(signatureClose())
.append(methodClose(FOUR_SPACE));
return builder.toString();
+
}
// Returns if condition for add to list method.
- static String getIfConditionForAddToListMethod(String name) {
+
+ private static String getIfConditionForAddToListMethod(JavaAttributeInfo attr) {
+ String name = attr.getAttributeName();
+ String type;
+ YangDataStructure struct = getYangDataStructure(attr.getCompilerAnnotation());
+ if (struct != null) {
+ switch (struct) {
+ case QUEUE:
+ type = PRIORITY_QUEUE;
+ break;
+
+ case LIST:
+ type = ARRAY_LIST;
+ break;
+
+ case MAP:
+ type = LINKED_HASH_MAP;
+ break;
+
+ case SET:
+ type = LINKED_HASH_SET;
+ break;
+
+ default:
+ type = ARRAY_LIST;
+ break;
+
+ }
+ } else {
+ type = ARRAY_LIST;
+ }
return getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + SPACE + EQUAL +
EQUAL + SPACE + NULL) + TWELVE_SPACE_INDENTATION +
name + SPACE + EQUAL + SPACE +
- NEW + SPACE + ARRAY_LIST + signatureClose() + methodClose(
+ NEW + SPACE + type + signatureClose() + methodClose(
EIGHT_SPACE);
}
@@ -1727,12 +1863,18 @@
return rt == null ? getToStringCall(name) :
getToStringForSpecialType(rt, name);
+ case IDENTITYREF:
+ YangIdentityRef ir = (YangIdentityRef) type
+ .getDataTypeExtendedInfo();
+ YangIdentity identity = ir.getReferredIdentity();
+ String idName = getCamelCase(identity.getName(), null);
+ return getCapitalCase(idName) + PERIOD + idName + TO_CAPS +
+ STRING_DATA_TYPE + OPEN_CLOSE_BRACKET_STRING;
case ENUMERATION:
case INSTANCE_IDENTIFIER:
case UINT64:
case DECIMAL64:
case DERIVED:
- case IDENTITYREF:
case UNION:
return getToStringCall(name);
@@ -1886,4 +2028,91 @@
return builder.toString();
}
+ /**
+ * To string method for identity.
+ *
+ * @param name name of identity
+ * @return to string method
+ */
+ public static String getToStringMethodForIdentity(String name) {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+ String returnVal = getQuotedString(name);
+ String methodName = getCamelCase(name, null) + TO_CAPS + STRING_DATA_TYPE;
+ builder.append(methodSignature(methodName, null, PUBLIC + SPACE + STATIC,
+ null, STRING_DATA_TYPE, null, CLASS_TYPE))
+ .append(getReturnString(returnVal, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ /**
+ * Returns from string method for identity class.
+ *
+ * @param name name of identity
+ * @param schemaName schema name
+ * @return from string method
+ */
+ public static String getFromStringMethodForIdentity(String name,
+ String schemaName) {
+ StringBuilder builder = new StringBuilder(NEW_LINE);
+ String caps = getCapitalCase(name);
+ String returnVal = caps + PERIOD + CLASS;
+ String cond = getTwoParaEqualsString(FROM_STRING_PARAM_NAME,
+ getQuotedString(schemaName));
+ builder.append(methodSignature(FROM_STRING_METHOD_NAME, null,
+ PUBLIC + SPACE + STATIC,
+ FROM_STRING_PARAM_NAME, CLASS_STRING,
+ STRING_DATA_TYPE, CLASS_TYPE))
+ .append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond))
+ .append(getReturnString(returnVal, TWELVE_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(EIGHT_SPACE))
+ .append(EIGHT_SPACE_INDENTATION).append(THROW_NEW)
+ .append(EXCEPTION_STRING).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ /**
+ * Returns compare to method for key class.
+ *
+ * @param attrs attribute list
+ * @param className class name
+ * @return compare to method
+ */
+ public static String getCompareToForKeyClass(
+ List<JavaAttributeInfo> attrs, String className) {
+
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ builder.append(methodSignature(COMPARE_TO, null, PUBLIC, VALUE, INT,
+ className, CLASS_TYPE));
+ String cond;
+ String attrName;
+ String para;
+ StringBuilder space = new StringBuilder();
+ List<String> spaces = new ArrayList<>();
+ int count = 1;
+ for (JavaAttributeInfo attr : attrs) {
+ attrName = attr.getAttributeName();
+ para = VALUE + PERIOD + attrName;
+ cond = getTwoParaEqualsString(attrName, para);
+ if (count == 1) {
+ space.append(EIGHT_SPACE_INDENTATION);
+ } else {
+ space.append(FOUR_SPACE_INDENTATION);
+ }
+ spaces.add(space.toString());
+ count++;
+ builder.append(getIfConditionBegin(space.toString(), cond));
+ }
+ space.append(FOUR_SPACE_INDENTATION);
+ builder.append(getReturnString(ZERO, space.toString()))
+ .append(signatureClose());
+ for (int i = spaces.size() - 1; i >= 0; i--) {
+ builder.append(spaces.get(i)).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+ }
+ builder.append(getReturnString(NEG_ONE, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
index b901b62..9311e2d 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
@@ -17,6 +17,9 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -41,7 +44,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIfConditionForAddToListMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.APPEND;
@@ -90,12 +93,14 @@
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MORE_OBJ_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -147,6 +152,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
+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.trimAtLast;
/**
@@ -329,13 +336,6 @@
signatureClose();
case DEFAULT_CONSTRUCTOR:
return EMPTY_STRING;
- case ADD_TO_LIST:
- return space + getIfConditionForAddToListMethod(paraName) +
- space + paraName +
- brackets(OPEN_CLOSE_BRACKET, null, null) + PERIOD +
- ADD_STRING + getOpenCloseParaWithValue(VALUE) +
- signatureClose() + getReturnString(
- THIS + signatureClose(), space);
case AUGMENTED_MAP_ADD:
return space + YANG_AUGMENTED_INFO_MAP +
PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
@@ -589,10 +589,9 @@
static String getListAttribute(String attrType,
YangCompilerAnnotation compilerAnnotation) {
String listAttr;
- if (compilerAnnotation != null &&
- compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure()
- .getDataStructure()) {
+ YangDataStructure ds = getYangDataStructure(compilerAnnotation);
+ if (ds != null) {
+ switch (ds) {
case QUEUE: {
listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
DIAMOND_CLOSE_BRACKET;
@@ -608,6 +607,10 @@
DIAMOND_CLOSE_BRACKET;
break;
}
+ case MAP:
+ listAttr = MAP + DIAMOND_OPEN_BRACKET + attrType + KEYS +
+ COMMA + attrType + DIAMOND_CLOSE_BRACKET;
+ break;
default: {
listAttr = getListString() + attrType +
DIAMOND_CLOSE_BRACKET;
@@ -789,9 +792,7 @@
case INSTANCE_IDENTIFIER:
case STRING:
- case IDENTITYREF:
return EMPTY_STRING;
-
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
@@ -799,6 +800,12 @@
case ENUMERATION:
return targetDataType + PERIOD + OF;
+ case IDENTITYREF:
+ YangIdentityRef ir = (YangIdentityRef) yangType
+ .getDataTypeExtendedInfo();
+ YangIdentity identity = ir.getReferredIdentity();
+ return getCapitalCase(getCamelCase(identity.getName(), null))
+ + PERIOD + FROM_STRING_METHOD_NAME;
case DERIVED:
case UNION:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
@@ -1036,6 +1043,26 @@
}
/**
+ * Returns class definition for implements.
+ *
+ * @param classType class type
+ * @param name name of class
+ * @param modifier modifier
+ * @param implClass implements class
+ * @return class definition
+ */
+ static String getDefinitionWithImplements(String classType, String name,
+ String modifier, String
+ implClass) {
+ String mod = EMPTY_STRING;
+ if (modifier != null) {
+ mod = modifier + SPACE;
+ }
+ return mod + classType + SPACE + name + SPACE + IMPLEMENTS + SPACE +
+ implClass + defCloseString();
+ }
+
+ /**
* Returns string for service class.
*
* @param name1 name of even listener class
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
index a02155b..651d4ec 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -34,6 +35,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
@@ -47,6 +49,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_SPACE;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getAppInstanceAttrString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getElseIfConditionBegin;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getEqualEqualString;
@@ -70,24 +73,34 @@
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD_FOR_FILTER;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
+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.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.ENTRY;
+import static org.onosproject.yangutils.utils.UtilConstants.ENTRY_SET;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_KEY;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
@@ -103,6 +116,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_LEAF_STF_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.RESULT;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD_SCHEMA_PARAM;
@@ -706,7 +720,8 @@
.build())).processSubtreeFiltering(appInstance.interfaces(),
true);*/
- assignment = getDummyObjectCreation(node, name, clsInfo, type, classCast, false);
+ assignment = getDummyObjectCreation(node, name, clsInfo, type,
+ classCast, false, false);
builder.append(assignment).append(SIXTEEN_SPACE_INDENTATION).append(
CLOSE_CURLY_BRACKET).append(ELSE).append(OPEN_CURLY_BRACKET)
.append(NEW_LINE);
@@ -753,10 +768,33 @@
String caps = getCapitalCase(javaAttributeInfo.getAttributeName());
String name = javaAttributeInfo.getAttributeName();
String type = javaAttributeInfo.getImportInfo().getClassInfo();
+ if (javaAttributeInfo.getAttributeType() != null && javaAttributeInfo
+ .getAttributeType().getDataType() == IDENTITYREF) {
+ type = CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + SPACE + EXTEND + SPACE +
+ type + DIAMOND_CLOSE_BRACKET;
+ }
+
+ YangDataStructure struct = getYangDataStructure
+ (javaAttributeInfo.getCompilerAnnotation());
+
+ boolean isMap = false;
+ if (struct != null && struct == YangDataStructure.MAP) {
+ isMap = true;
+ }
+
String clsInfo = DEFAULT_CAPS + type;
if (javaAttributeInfo.isQualifiedName()) {
- type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- type;
+ if (javaAttributeInfo.getAttributeType() != null && javaAttributeInfo
+ .getAttributeType().getDataType() == IDENTITYREF) {
+ type = CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + SPACE + EXTEND + SPACE +
+ javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
+ type + DIAMOND_CLOSE_BRACKET;
+ } else {
+ type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
+ type;
+ }
clsInfo = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
clsInfo;
}
@@ -767,29 +805,60 @@
if (node != null && node instanceof YangChoice) {
cast = name;
}
+ String validPass;
+ //If map is in DS then need to pass name.getValue() to processSubTree.
+ if (isMap) {
+ validPass = name + TWO + PERIOD + GET_VALUE;
+ } else {
+ validPass = name + TWO;
+ }
String resultString = cast + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
- name + "2" + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
+ validPass + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
NEW_LINE;
/*
* If select all schema child
*/
+ String forCondition;
+ String mapEntry;
+ String para;
+ //If map is there in DS the for loop should run for map entry.
+ if (!isMap) {
+ forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
+ getAppInstanceAttrString(name));
+ } else {
+ mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
+ KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
+ para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
+ forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION,
+ mapEntry, name, para);
+ }
builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION,
IS_SELECT_ALL_SCHEMA_CHILD_FLAG))
.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION,
getAppInstanceCondition(name, NOT)))
- .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
- getAppInstanceAttrString(name)));
+ .append(forCondition);
String assignment;
+ String result;
+ //If map is added then while creating dummy object need to used name
+ // .getValue() and to add the result in subTreeBuilder need to pass
+ // using key and value, key will be name.getKey() and value will be
+ // result.
+ if (isMap) {
+ result = getOpenCloseParaWithValue(name + PERIOD + GET_KEY + COMMA +
+ SPACE + RESULT);
+ } else {
+ result = getOpenCloseParaWithValue(RESULT);
+ }
if (!isLeafList) {
builder.append(TWENTY_SPACE_INDENTATION).append(type).append(SPACE)
.append(RESULT).append(signatureClose());
assignment = getDummyObjectCreation(node, name, type, clsInfo,
- classCast, true);
+ classCast, true, isMap);
builder.append(assignment);
assignment = TWENTY_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(RESULT) +
+ getCapitalCase(TO) + caps + result +
signatureClose();
builder.append(assignment);
} else {
@@ -857,8 +926,8 @@
builder.append(assignment);
assignment = TWENTY_EIGHT_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
- name + TWO) + signatureClose();
+ getCapitalCase(TO) + caps + getOpenCloseParaWithValue(name + TWO) +
+ signatureClose();
builder.append(assignment).append(TWENTY_EIGHT_SPACE_INDENTATION)
.append(BREAK).append(signatureClose())
//the content match leaf list attribute value matches
@@ -876,15 +945,36 @@
cond = getAppInstanceCondition(name, NOT) + SPACE + AND_OPERATION +
SPACE + NOT + getAppInstanceAttrString(name) +
PERIOD + IS_EMPTY;
+ //Same here for loop for map entry.
+ if (!isMap) {
+ forCondition = getForLoopString(TWENTY_SPACE_INDENTATION, type,
+ name + TWO,
+ getAppInstanceAttrString(name));
+ } else {
+ mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
+ KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
+ para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
+ forCondition = getForLoopString(TWENTY_SPACE_INDENTATION,
+ mapEntry, name + TWO, para);
+ }
+ String forCondition2;
+ //Same here for loop for map entry.
+ if (!isMap) {
+ forCondition2 = getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
+ name + OPEN_CLOSE_BRACKET_STRING);
+ } else {
+ mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
+ KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
+ para = name + OPEN_CLOSE_BRACKET_STRING + PERIOD + ENTRY_SET;
+ forCondition2 = getForLoopString(SIXTEEN_SPACE_INDENTATION,
+ mapEntry, name, para);
+ }
/*if there is any app instance entry*/
builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
cond))
//loop all the app instance(s)
- .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
- name + OPEN_CLOSE_BRACKET_STRING))
- .append(getForLoopString(TWENTY_SPACE_INDENTATION, type,
- name + TWO,
- getAppInstanceAttrString(name)));
+ .append(forCondition2)
+ .append(forCondition);
assignment = TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
@@ -893,10 +983,20 @@
cond = RESULT + SPACE + NOT + EQUAL + SPACE + NULL;
builder.append(getIfConditionBegin(TWENTY_EIGHT_SPACE_INDENTATION, cond));
+ //If map is added then while creating dummy object need to used name
+ // .getValue() and to add the result in subTreeBuilder need to pass
+ // using key and value, key will be name.getKey() and value will be
+ // result.
+ if (isMap) {
+ result = getOpenCloseParaWithValue(name + TWO + PERIOD + GET_KEY +
+ COMMA +
+ SPACE + RESULT);
+ } else {
+ result = getOpenCloseParaWithValue(RESULT);
+ }
assignment = THIRTY_TWO_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
- RESULT) + signatureClose();
+ getCapitalCase(TO) + caps + result + signatureClose();
builder.append(assignment).append(methodClose(TWENTY_EIGHT_SPACE))
//loop all the app instance(s)
.append(methodClose(TWENTY_FOUR_SPACE))
@@ -914,15 +1014,33 @@
if (isLeafList) {
builder.append(getSelectOrContainmentAssignString());
}
+
+ //need to pass name.getKey() and name.getValue() while adding to
+ // subtree builder.
+ if (!isMap) {
+ forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION, type,
+ name, getAppInstanceAttrString(name));
+ } else {
+ mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
+ KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
+ para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
+ forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION,
+ mapEntry, name, para);
+ }
cond = getAppInstanceCondition(name, NOT) + SPACE + AND_OPERATION +
SPACE + NOT + getAppInstanceAttrString(name) + PERIOD + IS_EMPTY;
builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
- .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type,
- name, getAppInstanceAttrString(name)));
+ .append(forCondition);
+ if (isMap) {
+ result = getOpenCloseParaWithValue(name + PERIOD + GET_KEY + COMMA +
+ SPACE + name + PERIOD +
+ GET_VALUE);
+ } else {
+ result = getOpenCloseParaWithValue(name);
+ }
assignment = TWENTY_FOUR_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
- name) + signatureClose();
+ getCapitalCase(TO) + caps + result + signatureClose();
builder.append(assignment).append(methodClose(TWENTY_SPACE))// Close collection Iteration loop
// close if condition
.append(methodClose(SIXTEEN_SPACE))
@@ -933,103 +1051,74 @@
}
public static String getAugmentableSubTreeFiltering() {
- return " if (yangAugmentedInfoMap.isEmpty()) {\n " +
- "Set<Map.Entry<Class<?>, Object>> augment = appInstance" +
- ".yangAugmentedInfoMap().entrySet();\n " +
- "if (augment != null && !augment.isEmpty()) {\n" +
- " " +
- "Iterator<Map.Entry<Class<?>, Object>> augItr = " +
- "augment.iterator();\n " +
- "while (augItr.hasNext()) {\n " +
- "Map.Entry<Class<?>, Object> aug = augItr.next();\n" +
- " " +
- "Class<?> augClass = aug.getKey();\n " +
- "String augClassName = augClass.getName();\n" +
- " " +
- "int index = augClassName.lastIndexOf('.');\n" +
- " " +
- "String classPackage = augClassName.substring(0, index) +\n" +
- " " +
- "\".\" + \"Default\" + augClass.getSimpleName() + \"$\"\n" +
- " " +
- "+ augClass.getSimpleName() + \"Builder\";\n" +
- " " +
- "ClassLoader classLoader = augClass.getClassLoader();\n" +
- " " +
- "try {\n " +
- "Class<?> builderClass;\n " +
- "builderClass = classLoader.loadClass(classPackage);\n" +
- " " +
- "Object builderObj = builderClass.newInstance();\n" +
- " " +
- "Method method = builderClass.getMethod(\"build\");\n" +
- " " +
- "Object defaultObj = method.invoke(builderObj);\n" +
- " " +
- "Class<?> defaultClass = defaultObj.getClass();\n" +
- " " +
- "method = defaultClass.getMethod\n" +
- " " +
- "(\"processSubtreeFiltering\", augClass,\n" +
- " " +
- "boolean.class);\n " +
- "Object result = method.invoke(defaultObj, aug.getValue(),\n" +
- " " +
- "true);\n " +
- "subTreeFilteringResultBuilder\n" +
- " " +
- ".addYangAugmentedInfo(result, augClass);\n" +
- " " +
- "} catch (ClassNotFoundException | InstantiationException\n" +
+ return " if (yangAugmentedInfoMap.isEmpty()) {\n" +
+ " Set<Map.Entry<Class<?>, Object>> augment =" +
+ " appInstance.yangAugmentedInfoMap().entrySet();\n" +
+ " if (augment != null && !augment.isEmpty()) {\n" +
+ " Iterator<Map.Entry<Class<?>, Object>> augItr =" +
+ " augment.iterator();\n" +
+ " while (augItr.hasNext()) {\n" +
+ " Map.Entry<Class<?>, Object> aug =" +
+ " augItr.next();\n" +
+ " Class<?> augClass = aug.getKey();\n" +
+ " String augClassName = augClass.getName();\n" +
+ " int index = augClassName.lastIndexOf('.');\n" +
+ " String classPackage = augClassName.substring(0, index) +\n" +
+ " \".\" + \"Default\" + augClass.getSimpleName() + \"$\"\n" +
+ " + augClass.getSimpleName() + \"Builder\";\n" +
+ " ClassLoader classLoader = augClass.getClassLoader();\n" +
+ " try {\n" +
+ " Class<?> builderClass;\n" +
+ " builderClass = classLoader.loadClass(classPackage);\n" +
+ " Object builderObj = builderClass.newInstance();\n" +
+ " Method method = builderClass.getMethod(\"build\");\n" +
+ " Object defaultObj = method.invoke(builderObj);\n" +
+ " Class<?> defaultClass = defaultObj.getClass();\n" +
+ " method = defaultClass.getMethod(" +
+ "\"processSubtreeFiltering\", augClass, boolean.class);\n" +
+ " Object result = method.invoke(" +
+ "defaultObj, aug.getValue(), true);\n" +
+ " subTreeFilteringResultBuilder." +
+ "addYangAugmentedInfo(result, augClass);\n" +
+ " } catch (ClassNotFoundException | InstantiationException\n" +
" | NoSuchMethodException |\n" +
- " " +
- "InvocationTargetException | IllegalAccessException e) {\n" +
- " e.printStackTrace();\n" +
+ " InvocationTargetException | IllegalAccessException e) {\n" +
" }\n" +
" }\n" +
" }\n" +
- " } else {\n " +
- "Set<Map.Entry<Class<?>, Object>> augment = " +
- "yangAugmentedInfoMap\n .entrySet();\n" +
- " " +
- "Iterator<Map.Entry<Class<?>, Object>> augItr = " +
- "augment.iterator();\n " +
- "while (augItr.hasNext()) {\n " +
- "Map.Entry<Class<?>, Object> aug = augItr.next();\n" +
+ " } else {\n" +
+ " Set<Map.Entry<Class<?>, Object>> augment = yangAugmentedInfoMap\n" +
+ " .entrySet();\n" +
+ " Iterator<Map.Entry<Class<?>, Object>> augItr = augment.iterator();\n" +
+ " while (augItr.hasNext()) {\n" +
+ " Map.Entry<Class<?>, Object> aug = augItr.next();\n" +
" Class<?> augClass = aug.getKey();\n" +
- " " +
- "Object appInstanceInfo = appInstance.yangAugmentedInfo(" +
- "augClass);\n if (appInstanceInfo == null) {\n" +
- " " +
- "subTreeFilteringResultBuilder.addYangAugmentedInfo\n" +
- " " +
- "(aug.getValue(), aug.getKey());\n" +
- " } else {\n " +
- "Object processSubtreeFiltering;\n try {\n" +
- " " +
- "processSubtreeFiltering = aug.getValue().getClass()\n" +
- " " +
- ".getMethod(\"processSubtreeFiltering\",\n" +
- " " +
- "aug.getKey(), boolean.class)\n" +
- " .invoke(aug.getValue(),\n" +
- " " +
- "appInstanceInfo, true);\n " +
- "if (processSubtreeFiltering != null) {\n" +
- " " +
- "subTreeFilteringResultBuilder\n " +
- " .addYangAugmentedInfo(processSubtreeFiltering, " +
- "aug.getKey());\n }\n" +
- " } catch (NoSuchMethodException | " +
- "InvocationTargetException | IllegalAccessException e) {\n" +
- " e.printStackTrace();\n" +
+ " Object appInstanceInfo = appInstance." +
+ "yangAugmentedInfo(augClass);\n" +
+ " if (appInstanceInfo == null) {\n" +
+ " subTreeFilteringResultBuilder." +
+ "addYangAugmentedInfo(aug.getValue(), aug.getKey());\n" +
+ " } else {\n" +
+ " Object processSubtreeFiltering;\n" +
+ " try {\n" +
+ " processSubtreeFiltering = " +
+ "aug.getValue().getClass()\n" +
+ " .getMethod(\"processSubtreeFiltering\"," +
+ " aug.getKey(), boolean.class)\n" +
+ " .invoke(aug.getValue(), appInstanceInfo, true);\n" +
+ " if (processSubtreeFiltering != null) {\n" +
+ " subTreeFilteringResultBuilder\n" +
+ " .addYangAugmentedInfo(" +
+ "processSubtreeFiltering, aug.getKey());\n" +
+ " }\n" +
+ " } catch (NoSuchMethodException | InvocationTargetException |\n" +
+ " IllegalAccessException e) {\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n";
}
-
private static String getSubTreeFilteredCondition(String name) {
StringBuilder builder = new StringBuilder();
String cond = SUBTREE_FILTERED + SPACE + AND_OPERATION + SPACE + name +
@@ -1083,10 +1172,15 @@
private static String getDummyObjectCreation(YangNode node, String name,
String clsInfo, String type,
- String classCast, boolean isList) {
+ String classCast, boolean isList,
+ boolean isMap) {
String para = getAppInstanceAttrString(name);
if (isList) {
- para = name;
+ if (isMap) {
+ para = name + PERIOD + GET_VALUE;
+ } else {
+ para = name;
+ }
}
if (node != null && node instanceof YangChoice) {
return getChoiceReflectionResult(name, clsInfo);
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 025c8fc..c289e77 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -228,6 +228,16 @@
public static final String PERIOD = ".";
/**
+ * Static attribute for period.
+ */
+ public static final String ENTRY = "Entry";
+
+ /**
+ * Static attribute for period.
+ */
+ public static final String ENTRY_SET = "entrySet()";
+
+ /**
* Static attribute for compare to.
*/
public static final String COMPARE_TO = "compareTo";
@@ -621,6 +631,31 @@
public static final String ADD_STRING = "add";
/**
+ * Static attribute for key syntax.
+ */
+ public static final String KEYS = "Keys";
+
+ /**
+ * Static attribute for key syntax.
+ */
+ public static final String GET_KEY = "getKey()";
+
+ /**
+ * Static attribute for key syntax.
+ */
+ public static final String GET_VALUE = "getValue()";
+
+ /**
+ * Static attribute for -1 to syntax.
+ */
+ public static final String NEG_ONE = "-1";
+
+ /**
+ * Static attribute for Comparable to syntax.
+ */
+ public static final String COMPARABLE = "Comparable";
+
+ /**
* Static attribute for string trim syntax.
*/
public static final String TRIM_STRING = "trim";
@@ -676,6 +711,11 @@
public static final String VALUE = "value";
/**
+ * Static attribute for value syntax.
+ */
+ public static final String VALUE_CAPS = "Value";
+
+ /**
* Static attribute for suffix s.
*/
public static final String SUFFIX_S = "s";
@@ -890,8 +930,23 @@
/**
* Static attribute for exception string in bits enum class.
*/
- public static final String EXCEPTION_STRING = "IllegalArgumentException(\"no" +
- " such element found in bits\");\n";
+ public static final String EXCEPTION_STRING = "IllegalArgumentException" +
+ "(\"not a valid input element\");\n";
+
+ /**
+ * Static attribute for priority queue.
+ */
+ public static final String PRIORITY_QUEUE = "java.util.PriorityQueue<>()";
+
+ /**
+ * Static attribute for linked hash set.
+ */
+ public static final String LINKED_HASH_SET = "java.util.LinkedHashSet<>()";
+
+ /**
+ * Static attribute for priority queue.
+ */
+ public static final String LINKED_HASH_MAP = "java.util.LinkedHashMap<>()";
/**
* Static attribute for "throw new ".
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index 7d36c0f..2b2a203 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -50,7 +50,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RPC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
+import static org.onosproject.yangutils.utils.UtilConstants.KEYS;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -71,9 +73,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
@@ -102,7 +106,7 @@
name = YangIoUtils.getSmallCase(name);
switch (type) {
case DEFAULT_CLASS: {
- return generateForClass(name);
+ return generateForClass(name, isList);
}
case BUILDER_CLASS: {
return generateForBuilderClass(name);
@@ -159,7 +163,7 @@
return generateForRpcService(name);
}
case RPC_MANAGER: {
- return generateForClass(name);
+ return generateForClass(name, false);
}
case EVENT: {
return generateForEvent(name);
@@ -168,10 +172,10 @@
return generateForEventListener(name);
}
case EVENT_SUBJECT_CLASS: {
- return generateForClass(name);
+ return generateForClass(name, false);
}
case ADD_TO_LIST: {
- return generateForAddToList(name);
+ return generateForAddToList(name, compilerAnnotation);
}
default: {
return generateForConstructors(name);
@@ -344,6 +348,8 @@
String setter, String compilerAnnotation, boolean isList) {
String attributeParam;
if (compilerAnnotation != null) {
+ compilerAnnotation = compilerAnnotation.toLowerCase();
+ compilerAnnotation = getCapitalCase(compilerAnnotation);
switch (compilerAnnotation) {
case QUEUE: {
attributeParam = QUEUE.toLowerCase() + SPACE + OF + SPACE;
@@ -360,6 +366,10 @@
setter = setter + attributeParam;
break;
}
+ case MAP:
+ attributeParam = MAP.toLowerCase() + SPACE + OF + SPACE;
+ setter = setter + attributeParam;
+ break;
default: {
}
@@ -420,11 +430,13 @@
/**
* Generates javaDocs for the impl class.
*
- * @param className class name
+ * @param className class name
+ * @param isForDefaultClass if javadoc is for default class
* @return javaDocs
*/
- private static String generateForClass(String className) {
- return getJavaDocForDefaultClass(className, IMPL_CLASS_JAVA_DOC, EMPTY_STRING);
+ private static String generateForClass(String className, boolean isForDefaultClass) {
+ return getJavaDocForDefaultClass(className, IMPL_CLASS_JAVA_DOC,
+ EMPTY_STRING, isForDefaultClass);
}
private static String addFlagJavaDoc() {
@@ -632,15 +644,32 @@
/**
* Returns javaDocs for add to list method.
*
- * @param attribute attribute
+ * @param attribute attribute
+ * @param annotation compile annotation
* @return javaDocs
*/
- private static String generateForAddToList(String attribute) {
- return getJavaDocStartLine(attribute, JAVA_DOC_ADD_TO_LIST) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, ADD_STRING + TO_CAPS) +
- getJavaDocReturnLine(BUILDER_OBJECT + attribute) +
- getJavaDocEndLine();
+ private static String generateForAddToList(String attribute, String annotation) {
+ StringBuilder javadoc = new StringBuilder();
+ javadoc.append(getJavaDocStartLine(attribute, JAVA_DOC_ADD_TO_LIST))
+ .append(getJavaDocEmptyAsteriskLine());
+ if (annotation != null) {
+ annotation = annotation.toLowerCase();
+ annotation = getCapitalCase(annotation);
+ switch (annotation) {
+ case MAP:
+ javadoc.append(getJavaDocParamLine(
+ attribute, attribute + KEYS)).append(getJavaDocParamLine(
+ attribute, attribute + VALUE_CAPS));
+ break;
+ default:
+ javadoc.append(getJavaDocParamLine(
+ attribute, ADD_STRING + TO_CAPS));
+ break;
+ }
+ }
+ javadoc.append(getJavaDocReturnLine(BUILDER_OBJECT + attribute))
+ .append(getJavaDocEndLine());
+ return javadoc.toString();
}
/**
@@ -673,16 +702,21 @@
/**
* Returns class javadoc.
*
- * @param name name of class
- * @param type type of javadoc
- * @param indent indentation
+ * @param name name of class
+ * @param type type of javadoc
+ * @param indent indentation
+ * @param isForDefaultClass if javadoc is generated for default class
* @return class javadoc
*/
private static String getJavaDocForDefaultClass(String name, String type,
- String indent) {
+ String indent, boolean isForDefaultClass) {
+ String append = addFlagJavaDoc();
+ if (!isForDefaultClass) {
+ append = EMPTY_STRING;
+ }
return NEW_LINE + indent + JAVA_DOC_FIRST_LINE + indent + type +
- getSmallCase(name) + PERIOD + NEW_LINE + indent
- + addFlagJavaDoc() + JAVA_DOC_END_LINE;
+ getSmallCase(name) + PERIOD + NEW_LINE + indent + append +
+ JAVA_DOC_END_LINE;
}
/**
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
index ed892b3..6167843 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
@@ -110,7 +110,7 @@
}
// Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangCompilerAnnotation>(
+ YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<>(
compilerAnnotation, (YangNode) curData, line, charPositionInLine);
addToResolutionList(resolutionInfo, ctx);
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
index d6f06ff..ed0a3a2 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -135,6 +136,16 @@
leavesHolder = (YangLeavesHolder) tmpData;
leavesHolder.addLeaf(leaf);
leaf.setContainedIn(leavesHolder);
+ if (tmpData instanceof YangList) {
+ YangList list = (YangList) tmpData;
+ if (list.isConfig()) {
+ for (String key : list.getKeyList()) {
+ if (key.equals(leaf.getName())) {
+ leaf.setKeyLeaf(true);
+ }
+ }
+ }
+ }
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_DATA,
ctx.identifier().getText(), ENTRY));
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
index c1381ca..992165b 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.antlr.v4.runtime.tree.TerminalNode;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangPatternRestriction;
import org.onosproject.yangutils.datamodel.YangStringRestriction;
@@ -27,6 +28,7 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -39,7 +41,6 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
@@ -180,10 +181,15 @@
* @return validated string
*/
private static String getValidPattern(GeneratedYangParser.PatternStatementContext ctx) {
- String userInputPattern = removeQuotesAndHandleConcat(ctx.string().getText());
- userInputPattern = userInputPattern.replaceAll("[\'\"]", EMPTY_STRING);
+ List<TerminalNode> patternList = ctx.string().STRING();
+ StringBuilder userInputPattern = new StringBuilder();
+ String compile;
+ for (TerminalNode pattern : patternList) {
+ userInputPattern.append(pattern.getText());
+ }
+ compile = userInputPattern.toString().replaceAll("[\'\"]", EMPTY_STRING);
try {
- Pattern.compile(userInputPattern);
+ Pattern.compile(compile);
} catch (PatternSyntaxException exception) {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(PATTERN_DATA) + " name " + ctx.string().getText() +
@@ -192,6 +198,6 @@
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
- return userInputPattern;
+ return compile;
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
index 4c35db6..8c7def0 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
@@ -66,6 +66,20 @@
ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
.getPatternList().listIterator();
assertThat(patternListIterator.next(), is("[a-zA-Z]"));
+
+ leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("ipv4-address"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ stringRestriction = (YangStringRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+ patternListIterator = stringRestriction.getPatternRestriction()
+ .getPatternList().listIterator();
+ assertThat(patternListIterator.next(), is(
+ "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}" +
+ "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" +
+ "(%[\\p{N}\\p{L}]+)?"));
}
/**
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java
new file mode 100644
index 0000000..f5891bf
--- /dev/null
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.plugin.manager;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for compiler annotation.
+ */
+public class CompilerAnnotationTest {
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private static final String DIR = "target/compiler/";
+ private static final String COMP = System.getProperty("user.dir") + File
+ .separator + DIR;
+
+
+ /**
+ * Checks compiler annotation translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processTranslator() throws IOException,
+ ParserException, MojoExecutionException {
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/compilerAnnotation";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(COMP);
+ deleteDirectory(DIR);
+ }
+}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
index adeb42f..683867d 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
@@ -39,12 +39,12 @@
.separator + DIR;
/**
- * Checks augment translation should not result in any exception.
+ * Checks translation should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
- public void processChoiceAugmentInterTranslator() throws IOException,
+ public void processTranslator() throws IOException,
ParserException, MojoExecutionException {
deleteDirectory(DIR);
String searchDir = "src/test/resources/identityTranslator";
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
index 45bc03d..fe46f72 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
@@ -33,8 +33,10 @@
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import java.io.File;
import java.io.IOException;
import java.util.ListIterator;
@@ -43,6 +45,8 @@
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Test cases for testing inter file linking for identity.
@@ -140,6 +144,23 @@
}
+ @Test
+ public void processTranslator() throws IOException, ParserException, MojoExecutionException {
+
+ deleteDirectory("target/identityTranslator/");
+ String searchDir = "src/test/resources/interfileidentityimport";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/identityTranslator/");
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(System.getProperty("user.dir") + File
+ .separator + "target/identityTranslator/");
+ }
+
/**
* Checks inter file feature linking with included file.
*/
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
index 501e2bc..d1cfe08 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
@@ -57,7 +57,7 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
compileCode(COMP);
- //deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
}
diff --git a/plugin/maven/src/test/resources/ValidPatternStatement.yang b/plugin/maven/src/test/resources/ValidPatternStatement.yang
index 556db31..0c93e9d 100644
--- a/plugin/maven/src/test/resources/ValidPatternStatement.yang
+++ b/plugin/maven/src/test/resources/ValidPatternStatement.yang
@@ -7,4 +7,24 @@
pattern "[a-zA-Z]";
}
}
+ leaf ipv4-address {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?';
+ }
+ description
+ "The ipv4-address type represents an IPv4 address in
+ dotted-quad notation. The IPv4 address may include a zone
+ index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format for the zone index is the numerical
+ format";
+ }
+
}
diff --git a/plugin/maven/src/test/resources/augmentTranslator/test.yang b/plugin/maven/src/test/resources/augmentTranslator/test.yang
index 20393a7..a5a0daf 100644
--- a/plugin/maven/src/test/resources/augmentTranslator/test.yang
+++ b/plugin/maven/src/test/resources/augmentTranslator/test.yang
@@ -71,6 +71,20 @@
}
}
augment /choice1 {
+ case case2 {
+ container con1 {
+ leaf in1 {
+ type int32;
+ }
+ }
+ }
+ case case3 {
+ container con2 {
+ leaf in2 {
+ type int32;
+ }
+ }
+ }
leaf-list leaf2 {
type int32;
}
diff --git a/plugin/maven/src/test/resources/compilerAnnotation/test.yang b/plugin/maven/src/test/resources/compilerAnnotation/test.yang
new file mode 100644
index 0000000..592e23f
--- /dev/null
+++ b/plugin/maven/src/test/resources/compilerAnnotation/test.yang
@@ -0,0 +1,33 @@
+module test {
+ namespace "test:test";
+ prefix test;
+ typedef type1 {
+ type string;
+ }
+ list list1 {
+ key "name sur-name";
+ leaf name {
+ type string;
+ }
+ leaf sur-name {
+ type type1;
+ }
+ choice c1 {
+ case ca1 {
+ leaf a {
+ type int32;
+ }
+ }
+ }
+ }
+ list list2 {
+ key "name sur-name";
+ leaf name {
+ type string;
+ }
+ leaf sur-name {
+ type type1;
+ }
+ }
+}
+
diff --git a/plugin/maven/src/test/resources/compilerAnnotation/test2.yang b/plugin/maven/src/test/resources/compilerAnnotation/test2.yang
new file mode 100644
index 0000000..704f724
--- /dev/null
+++ b/plugin/maven/src/test/resources/compilerAnnotation/test2.yang
@@ -0,0 +1,21 @@
+module test1 {
+ namespace "test1:test1";
+ prefix test1 ;
+
+ import test {
+ prefix test;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ ca:compiler-annotation /test:list1 {
+ ds:app-data-structure "Map";
+ }
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/identityTranslator/test.yang b/plugin/maven/src/test/resources/identityTranslator/test.yang
index b8a3193..e8c1889 100644
--- a/plugin/maven/src/test/resources/identityTranslator/test.yang
+++ b/plugin/maven/src/test/resources/identityTranslator/test.yang
@@ -1,14 +1,70 @@
-module IdentityInModule{
+module IdentityTest{
yang-version 1;
namespace http://huawei.com;
- prefix IdentityInModule;
+ prefix IdentityTest;
identity ref-address-family {
- reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+ description "ref-address-family";
}
- leaf tunnel {
+
+ identity ipv4-address-family {
+ base ref-address-family;
+ }
+
+ identity ipv6-address-family {
+ base ipv4-address-family;
+ }
+
+ typedef tunnel-type {
type identityref {
base ref-address-family;
}
}
-}
\ No newline at end of file
+ leaf tunnel1 {
+ type identityref {
+ base ipv4-address-family;
+ }
+ }
+
+ typedef type2 {
+ type identityref {
+ base ipv4-address-family;
+ }
+ }
+ typedef type3 {
+ type union {
+ type type2;
+ type identityref {
+ base ipv4-address-family;
+ }
+ }
+ }
+ leaf tunnel {
+ type union {
+ type type2;
+ type identityref {
+ base ipv6-address-family;
+ }
+ }
+ }
+ typedef ipv4-address {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?';
+ }
+ description
+ "The ipv4-address type represents an IPv4 address in
+ dotted-quad notation. The IPv4 address may include a zone
+ index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format for the zone index is the numerical
+ format";
+ }
+
+}