Bharat saraswal
Committed by Gerrit Code Review

[ONOS-3908] Implemetation of YANG container translator.

Change-Id: I9ffcfc4b370edb801dfc90c5394cef787c77641d
Showing 23 changed files with 281 additions and 83 deletions
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -342,4 +343,16 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -336,4 +337,16 @@ public class YangCase extends YangNode implements YangLeavesHolder, YangCommonIn
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -252,6 +253,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @return the description.
*/
@Override
public String getDescription() {
return description;
}
......@@ -261,6 +263,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @param description set the description.
*/
@Override
public void setDescription(String description) {
this.description = description;
}
......@@ -270,6 +273,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @return the reference.
*/
@Override
public String getReference() {
return reference;
}
......@@ -279,6 +283,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @param reference the reference to set.
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
......@@ -288,6 +293,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @return the status.
*/
@Override
public YangStatusType getStatus() {
return status;
}
......@@ -297,6 +303,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @param status the status to set.
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
......@@ -306,6 +313,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @return returns CHOICE_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.CHOICE_DATA;
}
......@@ -315,6 +323,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -324,6 +333,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -349,6 +359,7 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
@Override
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
......@@ -357,8 +368,21 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
@Override
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -133,7 +133,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
private YangStatusType status;
/**
* package of the generated java code.
* Package of the generated java code.
*/
private String pkg;
......@@ -332,6 +332,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
*
* @return the fileHandle
*/
@Override
public CachedFileHandle getFileHandle() {
return fileHandle;
}
......@@ -341,6 +342,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
*
* @param handle the fileHandle to set
*/
@Override
public void setFileHandle(CachedFileHandle handle) {
fileHandle = handle;
}
......@@ -395,11 +397,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
pkg = pcg;
}
/**
* Generate the java code corresponding to YANG container.
*
* @throws IOException when fails to generate the source files.
*/
@Override
public void generateJavaCodeEntry() throws IOException {
YangNode parent = getParent();
......@@ -414,14 +411,33 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
throw new IOException("Failed to create the source files.");
}
setFileHandle(handle);
addLavesAttributes();
addAttributeInParent();
}
/**
* Adds current node attribute to parent file.
*
* @param pkg java file package path
*/
private void addAttributeInParent() {
if (getParent() != null) {
getParent().getFileHandle().setChildsPackage(getPackage());
getParent().getFileHandle().addAttributeInfo(null, getName(), false);
}
}
@Override
public void generateJavaCodeExit() throws IOException {
addLeavesAttributes();
addLeafListAttributes();
getFileHandle().close();
return;
}
/**
* Adds leaf attributes in generated files.
*/
private void addLavesAttributes() {
private void addLeavesAttributes() {
List<YangLeaf<?>> leaves = getListOfLeaf();
if (leaves != null) {
......@@ -442,17 +458,5 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
}
}
return;
}
/**
* Free resources used to generate code.
*
* @throws IOException when fails to generate source files.
*/
@Override
public void generateJavaCodeExit() throws IOException {
getFileHandle().close();
return;
}
}
......
......@@ -22,6 +22,7 @@ import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*
* The enumeration built-in type represents values from a set of
......@@ -79,6 +80,7 @@ public class YangEnumeration extends YangNode implements Parsable {
*
* @return returns ENUMERATION_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.ENUMERATION_DATA;
}
......@@ -88,6 +90,7 @@ public class YangEnumeration extends YangNode implements Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -97,6 +100,7 @@ public class YangEnumeration extends YangNode implements Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -140,6 +144,7 @@ public class YangEnumeration extends YangNode implements Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
@Override
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
......@@ -148,8 +153,21 @@ public class YangEnumeration extends YangNode implements Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
@Override
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -321,4 +322,16 @@ public class YangGrouping extends YangNode implements YangLeavesHolder, YangComm
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -22,6 +22,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* The "list" statement is used to define an interior data node in the
......@@ -459,4 +460,16 @@ public class YangList extends YangNode implements YangLeavesHolder, YangCommonIn
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -155,7 +155,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
private byte version;
/**
* package of the generated java code.
* Package of the generated java code.
*/
private String pkg;
......@@ -493,6 +493,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
*
* @return the fileHandle
*/
@Override
public CachedFileHandle getFileHandle() {
return fileHandle;
}
......@@ -502,6 +503,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
*
* @param handle the fileHandle to set
*/
@Override
public void setFileHandle(CachedFileHandle handle) {
fileHandle = handle;
}
......@@ -555,14 +557,20 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
throw new IOException("Failed to create the source files.");
}
setFileHandle(handle);
addLavesAttributes();
}
@Override
public void generateJavaCodeExit() throws IOException {
addLeavesAttributes();
addLeafListAttributes();
getFileHandle().close();
return;
}
/**
* Adds leaf attributes in generated files.
*/
private void addLavesAttributes() {
private void addLeavesAttributes() {
List<YangLeaf<?>> leaves = getListOfLeaf();
if (leaves != null) {
......@@ -584,15 +592,4 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
}
}
/**
* Free resources used to generate code.
*
* @throws IOException when fails to generate source files.
*/
@Override
public void generateJavaCodeExit() throws IOException {
getFileHandle().close();
return;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.translator.CodeGenerator;
/**
......@@ -253,4 +254,18 @@ public abstract class YangNode implements CodeGenerator {
*/
public abstract void setPackage(String pkg);
/**
* Get the mapped java file handler.
*
* @return the file handle.
*/
public abstract CachedFileHandle getFileHandle();
/**
* Set the mapped java file handle.
*
* @param fileHandle the file handle to set of current node.
*/
public abstract void setFileHandle(CachedFileHandle fileHandle);
}
......
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*
* Reference RFC 6020.
......@@ -491,4 +492,16 @@ public class YangSubModule extends YangNode implements YangLeavesHolder, YangDes
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -138,6 +139,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @return the description.
*/
@Override
public String getDescription() {
return description;
}
......@@ -147,6 +149,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @param description set the description.
*/
@Override
public void setDescription(String description) {
this.description = description;
}
......@@ -156,6 +159,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @return the reference.
*/
@Override
public String getReference() {
return reference;
}
......@@ -165,6 +169,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @param reference the reference to set.
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
......@@ -174,6 +179,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @return the status.
*/
@Override
public YangStatusType getStatus() {
return status;
}
......@@ -183,6 +189,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @param status the status to set.
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
......@@ -230,6 +237,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @return returns TYPEDEF_DATA
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.TYPEDEF_DATA;
}
......@@ -239,6 +247,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -248,6 +257,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -273,6 +283,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
@Override
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
......@@ -281,6 +292,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
@Override
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
......@@ -303,4 +315,16 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CachedFileHandle;
/*-
* Reference RFC 6020.
......@@ -127,6 +128,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @return the description.
*/
@Override
public String getDescription() {
return description;
}
......@@ -136,6 +138,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @param description set the description.
*/
@Override
public void setDescription(String description) {
this.description = description;
}
......@@ -145,6 +148,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @return the reference.
*/
@Override
public String getReference() {
return reference;
}
......@@ -154,6 +158,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @param reference the reference to set.
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
......@@ -163,6 +168,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @return the status.
*/
@Override
public YangStatusType getStatus() {
return status;
}
......@@ -172,6 +178,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @param status the status to set.
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
......@@ -181,6 +188,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @return returns USES_DATA.
*/
@Override
public ParsableDataType getParsableDataType() {
return ParsableDataType.USES_DATA;
}
......@@ -190,6 +198,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -199,6 +208,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
*
* @throws DataModelException a violation of data model rules.
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
......@@ -224,6 +234,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
@Override
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
......@@ -232,6 +243,7 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
@Override
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
......@@ -254,4 +266,16 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
// TODO Auto-generated method stub
}
@Override
public CachedFileHandle getFileHandle() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFileHandle(CachedFileHandle fileHandle) {
// TODO Auto-generated method stub
}
}
......
......@@ -42,4 +42,11 @@ public interface CachedFileHandle {
* @throws IOException when failes to generated java files.
*/
void close() throws IOException;
/**
* Sets child package path for import.
*
* @param pkg child's package path
*/
void setChildsPackage(String pkg);
}
......
......@@ -42,18 +42,19 @@ public final class JavaCodeGenerator {
TraversalType curTraversal = TraversalType.ROOT;
while (!(curNode == null)) {
if (curTraversal != TraversalType.PARENT) {
if (curTraversal != TraversalType.PARENT || curTraversal == TraversalType.SIBILING) {
curNode.generateJavaCodeEntry();
}
if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) {
curTraversal = TraversalType.CHILD;
curNode = curNode.getChild();
} else if (!(curNode.getNextSibling() == null)) {
} else if (curTraversal == TraversalType.PARENT && !(curNode.getNextSibling() == null)) {
curNode.generateJavaCodeExit();
curTraversal = TraversalType.SIBILING;
curNode = curNode.getNextSibling();
} else {
curTraversal = TraversalType.PARENT;
curNode.generateJavaCodeExit();
curTraversal = TraversalType.PARENT;
curNode = curNode.getParent();
}
}
......
......@@ -16,9 +16,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.SortedSet;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
......@@ -50,29 +47,15 @@ public final class JavaCodeSnippetGen {
}
/**
* reorder the import list based on the ONOS import rules.
*
* @param importInfo the set of classes/interfaces to be imported.
* @return string of import info.
*/
public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) {
/* TODO: reorder the import list based on the ONOS import rules. */
return null;
}
/**
* Get the textual java code information corresponding to the import list.
*
* @param importInfo sorted list of import info.
* @param importInfo import info.
* @return the textual java code information corresponding to the import
* list.
*/
public static String getImportText(List<ImportInfo> importInfo) {
/*
* TODO: get the textual java code information corresponding to the
* import list
*/
return null;
public static String getImportText(ImportInfo importInfo) {
return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo()
+ UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE;
}
/**
......@@ -101,9 +84,23 @@ public final class JavaCodeSnippetGen {
*/
public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) {
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
if (type != null) {
return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName
+ UtilConstants.SEMI_COLAN;
}
return UtilConstants.PRIVATE + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN;
}
/**
* Returns list attribute string.
*
* @param type attribute type
* @return list attribute string
*/
public static String getListAttribute(String type) {
return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + type + UtilConstants.DIAMOND_CLOSE_BRACKET;
}
/**
* Based on the file type and method type(s) and the YANG name of the
......
......@@ -163,4 +163,14 @@ public final class JavaIdentifierSyntax {
}
return camelCase;
}
/**
* Translate the YANG identifier name to java identifier with first letter in caps.
*
* @param yangIdentifier identifier in YANG file.
* @return corresponding java identifier
*/
public static String getCaptialCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
}
}
......
......@@ -112,6 +112,13 @@ public final class MethodsGenerator {
public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName,
GeneratedMethodTypes methodTypes, YangType<?> returnType) {
if (returnType == null) {
@SuppressWarnings("rawtypes")
YangType<?> type = new YangType();
type.setDataTypeName(yangName);
returnType = type;
}
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
/**
......@@ -177,12 +184,10 @@ public final class MethodsGenerator {
String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
+ UtilConstants.NEW_LINE;
String getterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType());
String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType());
return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString
+ UtilConstants.NEW_LINE;
}
......@@ -299,7 +304,8 @@ public final class MethodsGenerator {
private static String getGetterForClass(String yangName, YangType<?> returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
+ returnType.getDataTypeName() + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + yangName
+ JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName()) + UtilConstants.SPACE
+ UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
+ UtilConstants.RETURN + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
......@@ -316,13 +322,14 @@ public final class MethodsGenerator {
private static String getSetterForClass(String yangName, YangType<?> returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + getBuilderClassName()
+ UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
+ returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
+ UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD + yangName
+ UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
+ UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
+ UtilConstants.THIS + UtilConstants.PERIOD + yangName + UtilConstants.SPACE + UtilConstants.EQUAL
+ UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE
+ UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
}
......@@ -335,9 +342,9 @@ public final class MethodsGenerator {
*/
private static String getGetterForInterface(String yangName, YangType<?> returnType) {
returnType.setDataTypeName(returnType.getDataTypeName().replace("\"", ""));
return UtilConstants.FOUR_SPACE_INDENTATION + returnType.getDataTypeName() + UtilConstants.SPACE
+ UtilConstants.GET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
+ UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
return UtilConstants.FOUR_SPACE_INDENTATION + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
}
/**
......@@ -349,9 +356,9 @@ public final class MethodsGenerator {
*/
private static String getSetterForInterface(String yangName, YangType<?> returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.BUILDER + UtilConstants.SPACE
+ UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
+ returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SEMI_COLAN;
+ UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
}
/**
......@@ -387,7 +394,8 @@ public final class MethodsGenerator {
constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
+ UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
+ UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
+ UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX + attribute.getAttributeName()
+ UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(attribute.getAttributeName())
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE;
}
......
......@@ -129,7 +129,7 @@ public final class UtilConstants {
public static final String STATIC = "static";
public static final String FINAL = "final";
public static final String PACKAGE = "package";
public static final String IMPORT = "import";
public static final String IMPORT = "import ";
public static final String NULL = "null";
public static final String RETURN = "return";
public static final String NEW = "new";
......@@ -144,6 +144,7 @@ public final class UtilConstants {
/**
* For collections.
*/
public static final String COLLECTION_IMPORTS = "import java.util.";
public static final String ABSTRACT_COLLECTION = "AbstractCollection";
public static final String LIST = "List";
......
......@@ -62,8 +62,7 @@ public final class FileSystemUtil {
public static void createPackage(String pkg, String pkgInfo) throws IOException {
if (!doesPackageExist(new File(pkg))) {
try {
File pack = YangIoUtils
.createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
File pack = YangIoUtils.createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
YangIoUtils.addPackageInfo(pack, pkgInfo, pkg);
} catch (IOException e) {
throw new IOException("failed to create package-info file");
......
......@@ -226,8 +226,8 @@ public final class JavaDocGen {
*/
private static String generateForConstructors(String className) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_SETTERS + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
+ UtilConstants.JAVA_DOC_CONSTRUCTOR + className + UtilConstants.IMPL + UtilConstants.PERIOD
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT
+ UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className
......
......@@ -27,6 +27,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -165,7 +166,6 @@ public final class SerializedDataStore {
* @throws IOException when fails to read from the file.
* @throws ClassNotFoundException when file is missing.
*/
@SuppressWarnings("unchecked")
public static List<String> getSerializeData(SerializedDataStoreType type)
throws IOException, ClassNotFoundException {
......@@ -191,10 +191,13 @@ public final class SerializedDataStore {
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream(buffer);
try {
List<String> recoveredData = (List<String>) input.readObject();
String data = (String) input.readObject();
List<String> recoveredData = new ArrayList<>();
recoveredData.add(data);
return recoveredData;
} finally {
input.close();
file.close();
}
} catch (ClassNotFoundException ex) {
throw new ClassNotFoundException("failed to fetch the serialized data file.");
......
......@@ -27,6 +27,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Resource;
import org.onosproject.yangutils.utils.UtilConstants;
import org.apache.commons.io.FileUtils;
import static org.slf4j.LoggerFactory.getLogger;
import org.slf4j.Logger;
......@@ -102,10 +103,10 @@ public final class YangIoUtils {
File currentFile = new File(file);
currentFile.delete();
}
FileUtils.deleteDirectory(generatedDirectory);
} catch (IOException e) {
log.info("Failed to delete the generated files in " + generatedDirectory + " directory");
}
generatedDirectory.delete();
}
}
......