[ONOS-5058][ONOS-4796][ONOS-4893]compiler annotation implementation + defect fix
Change-Id: Ie317409d9ab1d36e626433558b2d51f26daaac82
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index 254ea4a..ffa7b21 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -54,6 +55,11 @@
private JavaQualifiedTypeInfoTranslator importInfo;
/**
+ * Compiler annotation attribute info.
+ */
+ private YangCompilerAnnotation compilerAnnotation;
+
+ /**
* If conflict occurs.
*/
private boolean isIntConflict;
@@ -184,7 +190,25 @@
}
/**
- * Returns true if conflict between int and uInt.
+ * Returns the compiler annotation.
+ *
+ * @return compiler annotation info
+ */
+ public YangCompilerAnnotation getCompilerAnnotation() {
+ return compilerAnnotation;
+ }
+
+ /**
+ * Sets the compiler annotation.
+ *
+ * @param compilerAnnotation the compiler annotation to set
+ */
+ public void setCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ this.compilerAnnotation = compilerAnnotation;
+ }
+
+ /**
+ * Returns true if conflict between int and uint.
*
* @return true if conflict between int and uInt
*/
@@ -247,4 +271,27 @@
return newAttr;
}
+
+ /**
+ * Returns java attribute info.
+ *
+ * @param importInfo java qualified type info
+ * @param attributeName attribute name
+ * @param attributeType attribute type
+ * @param isQualifiedAccess is the attribute a qualified access
+ * @param isListAttribute is list attribute
+ * @param compilerAnnotation compiler annotation
+ * @return java attribute info.
+ */
+ public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo,
+ String attributeName, YangType<?> attributeType,
+ boolean isQualifiedAccess, boolean isListAttribute,
+ YangCompilerAnnotation compilerAnnotation) {
+ JavaAttributeInfo newAttr = getAttributeInfoForTheData(importInfo, attributeName, attributeType,
+ isQualifiedAccess, isListAttribute);
+
+ newAttr.setCompilerAnnotation(compilerAnnotation);
+
+ return newAttr;
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index aa8b53f..7c82175 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -41,7 +41,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static java.util.Collections.sort;
/**
@@ -55,6 +57,16 @@
private boolean isListToImport;
/**
+ * Flag to denote if any queue is imported due to compiler annotation.
+ */
+ private boolean isQueueToImport;
+
+ /**
+ * Flag to denote if any set is imported due to compiler annotation.
+ */
+ private boolean isSetToImport;
+
+ /**
* Sorted set of import info, to be used to maintain the set of classes to
* be imported in the generated class.
*/
@@ -86,6 +98,42 @@
}
/**
+ * Is Queue to be imported due to compiler annotations.
+ *
+ * @return status of queue import
+ */
+ public boolean isQueueToImport() {
+ return isQueueToImport;
+ }
+
+ /**
+ * Is Set to be imported due to compiler annotations.
+ *
+ * @return status of set import
+ */
+ public boolean isSetToImport() {
+ return isSetToImport;
+ }
+
+ /**
+ * Sets the status of the queue to be imported due to compiler annotations.
+ *
+ * @param queueToImport status of queue to import
+ */
+ public void setQueueToImport(boolean queueToImport) {
+ isQueueToImport = queueToImport;
+ }
+
+ /**
+ * Sets the status of the set to be imported due to compiler annotations.
+ *
+ * @param setToImport status of set to import
+ */
+ public void setSetToImport(boolean setToImport) {
+ isSetToImport = setToImport;
+ }
+
+ /**
* Returns the set containing the imported class/interface info.
*
* @return the set containing the imported class/interface info
@@ -124,7 +172,7 @@
if (newImportInfo.getClassInfo().contentEquals(className)) {
/*
- * if the current class name is same as the attribute class name,
+ * If the current class name is same as the attribute class name,
* then the attribute must be accessed in a qualified manner.
*/
return true;
@@ -157,7 +205,7 @@
}
/*
- * import is added, so it is a member for non qualified access
+ * Import is added, so it is a member for non qualified access
*/
getImportSet().add(newImportInfo);
return false;
@@ -187,6 +235,14 @@
imports.add(getImportForList());
}
+ if (isQueueToImport()) {
+ imports.add(getImportForQueue());
+ }
+
+ if (isSetToImport()) {
+ imports.add(getImportForSet());
+ }
+
sort(imports);
return imports;
}
@@ -228,6 +284,24 @@
}
/**
+ * Returns import for queue attribute.
+ *
+ * @return import for queue attribute
+ */
+ public String getImportForQueue() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + QUEUE + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import for set attribute.
+ *
+ * @return import for set attribute
+ */
+ public String getImportForSet() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + SET + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
* Returns import string for ListenerService class.
*
* @return import string for ListenerService class
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
index 609a3d2..42c5e59 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
@@ -444,7 +444,7 @@
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventEnumTempFileHandle(),
- getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig, null) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
}
@@ -464,17 +464,26 @@
/*Adds getter method for event in event subject class.*/
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getEventSubjectGetterTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/*Adds setter method for event in event subject class.*/
private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
throws IOException {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getEventSubjectSetterTempFileHandle(),
- getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS)
+ + NEW_LINE);
}
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index 58a0e28..a151f03 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -22,10 +22,11 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
@@ -447,16 +448,12 @@
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
- /*
- * Initialize temp files to generate enum class.
- */
+ //Initialize temp files to generate enum class.
if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
- /*
- * Set temporary file handles.
- */
+ //Set temporary file handles
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
}
@@ -586,10 +583,38 @@
className, fileInfo.getPackage());
}
- if (isListNode) {
+ boolean collectionSetFlag = false;
+ if (curNode instanceof YangList) {
+ YangList yangList = (YangList) curNode;
+ if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
+ .getYangAppDataStructure() != null) {
+ switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ parentImportData.setQueueToImport(true);
+ collectionSetFlag = true;
+ break;
+ }
+ case SET: {
+ parentImportData.setSetToImport(true);
+ collectionSetFlag = true;
+ break;
+ }
+ default: {
+ // TODO : to be implemented
+ }
+ }
+ }
+ }
+
+ if (isListNode && !(collectionSetFlag)) {
parentImportData.setIfListImported(true);
}
+ if (curNode instanceof YangList) {
+ return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
+ ((YangList) curNode).getCompilerAnnotation());
+ }
+
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
}
@@ -1121,9 +1146,13 @@
getGeneratedJavaFiles()) + NEW_LINE);
}
} else {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getGetterImplTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
@@ -1136,7 +1165,7 @@
*/
private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
appendToFile(getAddToListInterfaceTempFileHandle(),
- getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
+ getAddToListMethodInterface(attr) + NEW_LINE);
}
@@ -1322,7 +1351,6 @@
*/
public String getTemporaryDataFromFileHandle(File file, String absolutePath)
throws IOException {
-
String path = getTempDirPath(absolutePath);
if (new File(path + file.getName()).exists()) {
return readAppendFile(path + file.getName(), EMPTY_STRING);
@@ -1351,9 +1379,7 @@
* @return attribute string
*/
String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
- /*
- * TODO: check if this utility needs to be called or move to the caller
- */
+ //TODO: check if this utility needs to be called or move to the caller
String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
String attributeAccessType = PRIVATE;
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
@@ -1362,10 +1388,10 @@
if (attr.isQualifiedName()) {
return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
- attributeName, attr.isListAttr(), attributeAccessType);
+ attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
} else {
return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
- attr.isListAttr(), attributeAccessType);
+ attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
}
}
@@ -1392,7 +1418,6 @@
* @param pluginConfig plugin configurations
*/
void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
-
JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
YangNode parent = getParentNodeInGenCode(curNode);
if (curNode instanceof YangCase && parent instanceof YangAugment) {
@@ -1618,30 +1643,26 @@
addImportsForAugmentableClass(imports, true, true);
}
createPackage(curNode);
- /*
- * Generate java code.
- */
+
+ //Generate java code.
if ((fileType & INTERFACE_MASK) != 0 || (fileType &
BUILDER_INTERFACE_MASK) != 0) {
- /*
- * Create interface file.
- */
+
+ //Create interface file.
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
setInterfaceJavaFileHandle(
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
- /*
- * Create builder interface file.
- */
+
+ //Create builder interface file.
if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
setBuilderInterfaceJavaFileHandle(
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
setBuilderInterfaceJavaFileHandle(
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
isAttributePresent()));
- /*
- * Append builder interface file to interface file and close it.
- */
+
+ //Append builder interface file to interface file and close it.
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
validateLineLength(getInterfaceJavaFileHandle());
}
@@ -1662,36 +1683,32 @@
addInvocationExceptionImport(imports);
}
sortImports(imports);
- /*
- * Create impl class file.
- */
+
+ //Create impl class file.
setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
setImplClassJavaFileHandle(
generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
- /*
- * Create builder class file.
- */
+
+ //Create builder class file.
if ((fileType & BUILDER_CLASS_MASK) != 0) {
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
setBuilderClassJavaFileHandle(
generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
isAttributePresent()));
- /*
- * Append impl class to builder class and close it.
- */
+
+ //Append impl class to builder class and close it.
mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
}
- /*
- * Close all the file handles.
- */
+
+ //Close all the file handles.
freeTemporaryResources(false);
}
- /*Adds import for array list.*/
+ //Adds import for array list.
private void addArrayListImport(List<String> imports) {
if (imports.contains(getJavaImportData().getImportForList())) {
imports.add(ARRAY_LIST_IMPORT);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index 29dc4ff..2250a62 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -18,6 +18,7 @@
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
@@ -55,7 +56,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
+import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR;
@@ -110,11 +113,13 @@
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @param attributeAccessType attribute access type
+ * @param compilerAnnotation compiler annotation
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefinition(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName, boolean isList,
- String attributeAccessType) {
+ String attributeAccessType,
+ YangCompilerAnnotation compilerAnnotation) {
String attributeDefinition = attributeAccessType + SPACE;
@@ -126,13 +131,43 @@
attributeDefinition = attributeDefinition + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
+ NEW_LINE;
} else {
- attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ attributeDefinition = attributeDefinition + QUEUE + DIAMOND_OPEN_BRACKET;
+ break;
+ }
+ case SET: {
+ attributeDefinition = attributeDefinition + SET + DIAMOND_OPEN_BRACKET;
+ break;
+ }
+ default: {
+ attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ }
+ }
+ } else {
+ attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ }
+
if (javaAttributeTypePkg != null) {
attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
}
- attributeDefinition = attributeDefinition + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE
- + javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
+ attributeDefinition = attributeDefinition + javaAttributeType;
+
+ if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ default: {
+ attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
+ + javaAttributeName + SEMI_COLAN + NEW_LINE;
+ }
+ }
+ } else {
+ attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
+ + javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE
+ + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
+ }
+
}
return attributeDefinition;
}
@@ -155,7 +190,7 @@
* @return string for enum's attribute
*/
public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
- return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig)
+ return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig, null)
+ EIGHT_SPACE_INDENTATION + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index 033a7d7..9d0ca67 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -936,7 +936,7 @@
insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
// Add a constructor for enum.
- insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig)
+ insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig, null)
+ getEnumsConstructor(getCapitalCase(className)) + NEW_LINE);
TempJavaEnumerationFragmentFiles enumFragFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
@@ -949,7 +949,7 @@
+ NEW_LINE);
// Add a getter method for enum.
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig)
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig, null)
+ getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
try {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index cf753f0..a1000ca 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -538,7 +538,7 @@
throws IOException {
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
}
@@ -555,7 +555,7 @@
private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
YangPluginConfig pluginConfig)
throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 372897c..5f00ecc 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -18,10 +18,10 @@
import java.util.List;
import java.util.Map;
-
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeafRef;
@@ -157,11 +157,13 @@
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.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
@@ -238,7 +240,7 @@
* @return method string for builder interface
*/
public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
- return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name);
+ return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
}
/**
@@ -251,16 +253,21 @@
*/
public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return generateForGetMethodWithAttribute(returnType)
- + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
+ + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
- return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig)
- + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
+ return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
+ + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -274,7 +281,6 @@
*/
public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attributeName = attr.getAttributeName();
JavaDocGen.JavaDocType type;
@@ -284,8 +290,13 @@
type = SETTER_METHOD;
}
- return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig)
- + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
+ return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
+ + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -296,7 +307,7 @@
* @return constructor string
*/
private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
- return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
+ return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
}
/**
@@ -309,9 +320,8 @@
*/
public static String getDefaultConstructorString(String name, String modifierType,
YangPluginConfig pluginConfig) {
- return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig)
- + getDefaultConstructor(name, modifierType)
- + NEW_LINE;
+ return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
+ + getDefaultConstructor(name, modifierType) + NEW_LINE;
}
/**
@@ -347,15 +357,14 @@
* @return getter method for class
*/
public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
-
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
if (!attr.isListAttr()) {
return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
}
- String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
- return getGetter(listAttr, attributeName, generatedJavaFiles);
+ String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
+ return getGetter(attrParam, attributeName, generatedJavaFiles);
}
/**
@@ -379,7 +388,6 @@
EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET;
}
-
}
/*Provides string to return for type.*/
@@ -407,7 +415,6 @@
* @return setter method for class
*/
public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
-
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
boolean isTypeNull = false;
@@ -417,8 +424,8 @@
if (!attr.isListAttr()) {
return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
}
- String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
- return getSetter(className, attributeName, listAttr, generatedJavaFiles, isTypeNull, true);
+ String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
+ return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
}
/**
@@ -508,15 +515,15 @@
* @param returnType return type of attribute
* @param isList is list attribute
* @param generatedJavaFiles generated java files
+ * @param compilerAnnotation compiler annotation
* @return getter method for interface
*/
static String getGetterForInterface(String yangName, String returnType, boolean isList,
- int generatedJavaFiles) {
-
+ int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
}
- String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET;
+ String listAttr = getListAttribute(returnType, compilerAnnotation);
return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
}
@@ -545,15 +552,17 @@
* @param className name of the java class being generated
* @param isList is list attribute
* @param generatedJavaFiles generated java files
+ * @param compilerAnnotation compiler annotations
* @return setter method for interface
*/
static String getSetterForInterface(String attrName, String attrType, String className,
- boolean isList, int generatedJavaFiles) {
-
+ boolean isList, int generatedJavaFiles,
+ YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
}
- String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+
+ String listAttr = getListAttribute(attrType, compilerAnnotation);
return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
}
@@ -592,7 +601,6 @@
* @return return type
*/
private static String getReturnType(JavaAttributeInfo attr) {
-
String returnType = EMPTY_STRING;
if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
@@ -621,7 +629,6 @@
* @return constructor string
*/
static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
-
String javadoc = getConstructorString(yangName, pluginConfig);
String returnType = getCapitalCase(DEFAULT) + yangName;
@@ -644,7 +651,6 @@
*/
public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String attributeName = attr.getAttributeName();
String constructor;
@@ -675,7 +681,6 @@
*/
public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
YangPluginConfig pluginConfig) {
-
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
if (!inputName.equals(EMPTY_STRING)) {
inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
@@ -695,7 +700,6 @@
*/
public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
YangPluginConfig pluginConfig) {
-
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
if (!inputName.equals(EMPTY_STRING)) {
inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
@@ -709,7 +713,6 @@
+ NEW_LINE;
}
method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
return method;
}
@@ -1084,7 +1087,7 @@
* @return from string method's open string
*/
static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
- return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
+ return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
+ STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
+ STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
@@ -1109,7 +1112,6 @@
*/
public static String getFromStringMethod(JavaAttributeInfo attr,
JavaAttributeInfo fromStringAttributeInfo) {
-
return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
+ getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION
+ getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString()
@@ -1152,7 +1154,6 @@
*/
private static String getParsedSubString(JavaAttributeInfo attr,
JavaAttributeInfo fromStringAttributeInfo) {
-
String targetDataType = getReturnType(attr);
if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
@@ -1286,7 +1287,6 @@
* @return equals method
*/
public static String getEqualsMethod(JavaAttributeInfo attr) {
-
String attributeName = attr.getAttributeName();
return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
+ attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
@@ -1301,9 +1301,7 @@
* @return of method string
*/
static String getOfMethod(String name, JavaAttributeInfo attr) {
-
String attrQualifiedType = getReturnType(attr);
-
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
+ attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE
@@ -1320,11 +1318,10 @@
*/
public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
+ getOfMethodString(attrType, generatedJavaClassName);
}
@@ -1336,7 +1333,6 @@
* @return of method's string
*/
private static String getOfMethodString(String type, String className) {
-
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS
+ type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE
@@ -1354,11 +1350,9 @@
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
String generatedJavaClassName,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
-
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
+ getTypeConstructorString(attrType, attrName, generatedJavaClassName);
}
@@ -1376,7 +1370,6 @@
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type,
boolean addFirst) {
-
String attrType = getReturnType(attr1);
String attrName1 = "";
String attrName2 = "";
@@ -1387,8 +1380,13 @@
attrName2 = attr2.getAttributeName();
}
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig)
- + getTypeConstructorString(attrType, attrName1, attrName2, generatedJavaClassName, type, addFirst);
+ String appDataStructure = null;
+ if (attr1.getCompilerAnnotation() != null) {
+ appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig,
+ appDataStructure) + getTypeConstructorString(attrType, attrName1,
+ attrName2, generatedJavaClassName, type, addFirst);
}
/**
@@ -1400,7 +1398,6 @@
* @return type constructor string
*/
private static String getTypeConstructorString(String type, String name, String className) {
-
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
@@ -1417,7 +1414,6 @@
*/
private static String getTypeConstructorString(String type, String attr1, String attr2, String className,
ValidatorTypeForUnionTypes validatorType, boolean addInt) {
-
String constructor;
constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
@@ -1501,7 +1497,7 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
- return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig)
+ return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null)
+ FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
@@ -1559,7 +1555,6 @@
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
int value;
for (String str : enumList) {
-
value = enumMap.get(str);
method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
+ SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
@@ -1569,7 +1564,7 @@
+ RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig)
+ return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig, null)
+ method;
}
@@ -1581,7 +1576,6 @@
* @return parsed string
*/
private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
-
YangDataTypes type = yangType.getDataType();
switch (type) {
@@ -1652,11 +1646,10 @@
methods.append(method);
method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
- getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig) +
+ getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
- getCapitalCase(curNodeName), returnType, parentName,
- false,
- GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
+ getCapitalCase(curNodeName), returnType, parentName, false,
+ GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
methods.append(method);
}
return methods.toString();
@@ -1968,4 +1961,30 @@
" return this;\n" +
" }\n";
}
+
+ private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) {
+ String listAttr;
+ if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ case SET: {
+ listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ case LIST: {
+ listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ default: {
+ listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ }
+ }
+ } else {
+ listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ }
+ return listAttr;
+ }
}