Shankara-Huawei
Committed by Gerrit Code Review

[ONOS-4831] Implement op param class for apps

Change-Id: I88aee8a3009de84649c959e21ce83e3bbbf63c18
Showing 16 changed files with 1097 additions and 46 deletions
......@@ -150,6 +150,12 @@ public class YangUtilManager
@Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
private List<ArtifactRepository> remoteRepository;
/**
* Code generation is for nbi or sbi.
*/
@Parameter(property = "generateJavaFileForsbi", defaultValue = "nbi")
private String generateJavaFileForsbi;
@Override
public void execute()
throws MojoExecutionException, MojoFailureException {
......@@ -177,6 +183,7 @@ public class YangUtilManager
yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
yangPlugin.setCodeGenerateForsbi(generateJavaFileForsbi.toLowerCase());
/*
* Obtain the YANG files at a path mentioned in plugin and creates
* YANG file information set.
......
......@@ -44,8 +44,7 @@ public final class GeneratedJavaFileType {
/**
* Interface and class file.
*/
public static final int GENERATE_INTERFACE_WITH_BUILDER = INTERFACE_MASK
| BUILDER_INTERFACE_MASK | BUILDER_CLASS_MASK | IMPL_CLASS_MASK;
public static final int GENERATE_INTERFACE_WITH_BUILDER = 8207;
/**
* Java interface corresponding to rpc.
......@@ -94,6 +93,16 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_IDENTITY_CLASS = 2048;
/**
* Operation class file.
*/
public static final int OPERATION_CLASS_MASK = 4096;
/**
* Operation class builder file.
*/
public static final int OPERATION_BUILDER_CLASS_MASK = 8192;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -32,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
......@@ -209,6 +210,15 @@ public class JavaImportData {
}
/**
* Returns import for to bitset method.
*
* @return import for to bitset method
*/
public String getImportForToBitSet() {
return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + BITSET + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import for list attribute.
*
* @return import for list attribute
......
......@@ -47,6 +47,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
......@@ -69,6 +70,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamImplClassFile;
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.getAugmentedConstructor;
......@@ -102,6 +105,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
......@@ -246,11 +252,39 @@ public class TempJavaFragmentFiles {
private File builderClassJavaFileHandle;
/**
* Retrieves the temporary file handle of op param builder class.
*
* @return op param builder temporary file handle
*/
public File getBuilderOpParmClassJavaFileHandle() {
return builderOpParmClassJavaFileHandle;
}
/**
* Sets the java file handle for op param builder class.
*
* @param builderOpParmClassJavaFileHandle java file handle
*/
public void setBuilderOpParmClassJavaFileHandle(File builderOpParmClassJavaFileHandle) {
this.builderOpParmClassJavaFileHandle = builderOpParmClassJavaFileHandle;
}
/**
* Java file handle for builder op param class file.
*/
private File builderOpParmClassJavaFileHandle;
/**
* Java file handle for impl class file.
*/
private File implClassJavaFileHandle;
/**
* Java file handle for op param class file.
*/
private File opParamClassJavaFileHandle;
/**
* Temporary file handle for attribute.
*/
private File attributesTempFileHandle;
......@@ -1192,13 +1226,17 @@ public class TempJavaFragmentFiles {
* 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) {
attributeAccessType = PROTECTED;
}
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
attributeName, attr.isListAttr());
attributeName, attr.isListAttr(), attributeAccessType);
} else {
return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
attr.isListAttr());
attr.isListAttr(), attributeAccessType);
}
}
......@@ -1260,7 +1298,7 @@ public class TempJavaFragmentFiles {
if (!(leaf instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf does not have java information");
}
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(leaf, yangPluginConfig),
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
yangPluginConfig);
}
}
......@@ -1269,12 +1307,13 @@ public class TempJavaFragmentFiles {
/**
* Returns java attribute for leaf.
*
* @param tempJavaFragmentFiles temporary generated file
* @param leaf YANG leaf
* @param yangPluginConfig plugin configurations
* @return java attribute for leaf
*/
private JavaAttributeInfo getJavaAttributeOfLeaf(YangLeaf leaf,
YangPluginConfig yangPluginConfig) {
public static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
YangPluginConfig yangPluginConfig) {
JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
javaLeaf.updateJavaQualifiedInfo();
......@@ -1282,7 +1321,7 @@ public class TempJavaFragmentFiles {
javaLeaf.getJavaQualifiedInfo(),
javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
false);
}
......@@ -1300,7 +1339,7 @@ public class TempJavaFragmentFiles {
if (!(leafList instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf-list does not have java information");
}
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(leafList, yangPluginConfig),
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this, leafList, yangPluginConfig),
yangPluginConfig);
}
}
......@@ -1309,25 +1348,28 @@ public class TempJavaFragmentFiles {
/**
* Returns java attribute for leaf-list.
*
* @param tempJavaFragmentFiles temporary generated file
* @param leafList YANG leaf-list
* @param yangPluginConfig plugin configurations
* @return java attribute for leaf-list
*/
private JavaAttributeInfo getJavaAttributeOfLeafList(YangLeafList leafList, YangPluginConfig yangPluginConfig) {
public static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
YangLeafList leafList, YangPluginConfig yangPluginConfig) {
JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
javaLeaf.updateJavaQualifiedInfo();
getJavaImportData().setIfListImported(true);
tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
return getAttributeInfoForTheData(
javaLeaf.getJavaQualifiedInfo(),
javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
true);
}
/**
* Adds all the leaves in the current data model node as part of the generated temporary file.
* Adds all the leaves in the current data model node as part of the
* generated temporary file.
*
* @param curNode java file info of the generated file
* @param yangPluginConfig plugin config
......@@ -1419,6 +1461,24 @@ public class TempJavaFragmentFiles {
}
/**
* Returns op param java class name.
*
* @return op param java class name
*/
String getOpParamImplClassName() {
return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION;
}
/**
* Returns op param builder java class name.
*
* @return op param builder java class name
*/
String getOpParamBuilderImplClassName() {
return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION + BUILDER;
}
/**
* Returns the directory path.
*
* @return directory path
......@@ -1494,7 +1554,7 @@ public class TempJavaFragmentFiles {
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(imports);
addImportsToStringAndHasCodeMethods(imports, true);
}
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports);
......@@ -1522,6 +1582,39 @@ public class TempJavaFragmentFiles {
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
if (!(curNode instanceof YangModule)) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(imports, false);
}
addBitsetImport(imports, true);
/*
* Create impl class file.
*/
setOpParamClassJavaFileHandle(getJavaFileHandle(getOpParamImplClassName()));
setOpParamClassJavaFileHandle(
generateOpParamImplClassFile(getOpParamClassJavaFileHandle(), curNode,
isAttributePresent(), imports));
/*
* Create builder class file.
*/
if ((fileType & BUILDER_CLASS_MASK) != 0) {
setBuilderOpParmClassJavaFileHandle(getJavaFileHandle(getOpParamBuilderImplClassName()));
setBuilderOpParmClassJavaFileHandle(
generateOpParamBuilderClassFile(getBuilderOpParmClassJavaFileHandle(), curNode,
isAttributePresent()));
/*
* Append impl class to builder class and close it.
*/
mergeJavaFiles(getBuilderOpParmClassJavaFileHandle(), getOpParamClassJavaFileHandle());
validateLineLength(getOpParamClassJavaFileHandle());
addBitsetImport(imports, false);
}
insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose());
}
}
/*
* Close all the file handles.
......@@ -1547,15 +1640,15 @@ public class TempJavaFragmentFiles {
YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
if (holder.getListOfLeaf() != null) {
for (YangLeaf leaf : holder.getListOfLeaf()) {
addAugmentConstructor(getJavaAttributeOfLeaf(leaf,
pluginConfig), pluginConfig);
addAugmentConstructor(getJavaAttributeOfLeaf(this, leaf,
pluginConfig), pluginConfig);
}
}
if (holder.getListOfLeafList() != null) {
for (YangLeafList leafList : holder.getListOfLeafList()) {
addAugmentConstructor(getJavaAttributeOfLeafList(leafList,
pluginConfig), pluginConfig);
addAugmentConstructor(getJavaAttributeOfLeafList(this, leafList,
pluginConfig), pluginConfig);
}
}
......@@ -1579,10 +1672,30 @@ public class TempJavaFragmentFiles {
* Adds imports for ToString and HashCodeMethod.
*
* @param imports import list
* @param operation add or remove
*/
public void addImportsToStringAndHasCodeMethods(List<String> imports) {
imports.add(getJavaImportData().getImportForHashAndEquals());
imports.add(getJavaImportData().getImportForToString());
public void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
if (operation) {
imports.add(getJavaImportData().getImportForHashAndEquals());
imports.add(getJavaImportData().getImportForToString());
} else {
imports.remove(getJavaImportData().getImportForHashAndEquals());
imports.remove(getJavaImportData().getImportForToString());
}
}
/**
* Adds imports for bitset method.
*
* @param imports import list
* @param operation add or remove
*/
public void addBitsetImport(List<String> imports, boolean operation) {
if (operation) {
imports.add(getJavaImportData().getImportForToBitSet());
} else {
imports.remove(getJavaImportData().getImportForToBitSet());
}
}
......@@ -1653,6 +1766,9 @@ public class TempJavaFragmentFiles {
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
closeFile(getBuilderClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & OPERATION_BUILDER_CLASS_MASK) != 0) {
closeFile(getBuilderOpParmClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
closeFile(getBuilderInterfaceJavaFileHandle(), true);
}
......@@ -1700,4 +1816,21 @@ public class TempJavaFragmentFiles {
getJavaFileInfo().getPackage());
}
/**
* Returns java file handle for op param class file.
*
* @return java file handle for op param class file
*/
public File getOpParamClassJavaFileHandle() {
return opParamClassJavaFileHandle;
}
/**
* Sets the java file handle for op param class file.
*
* @param opParamClassJavaFileHandle java file handle
*/
public void setOpParamClassJavaFileHandle(File opParamClassJavaFileHandle) {
this.opParamClassJavaFileHandle = opParamClassJavaFileHandle;
}
}
......
......@@ -332,7 +332,7 @@ public class TempJavaTypeFragmentFiles
* Creates type def class file.
*/
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(imports);
addImportsToStringAndHasCodeMethods(imports, true);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
}
......@@ -340,7 +340,7 @@ public class TempJavaTypeFragmentFiles
* Creates type class file.
*/
if ((fileType & GENERATE_UNION_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(imports);
addImportsToStringAndHasCodeMethods(imports, true);
setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
}
......
......@@ -39,6 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isM
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
/**
* Represents module information extended to support java code generation.
......@@ -159,10 +160,13 @@ public class YangJavaModule
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......
......@@ -40,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -127,8 +128,7 @@ public class YangJavaSubModule
/**
* Returns the name space of the module to which the sub module belongs to.
*
* @param belongsToInfo Information of the module to which the sub module
* belongs
* @param belongsToInfo Information of the module to which the sub module belongs
* @return the name space string of the module.
*/
public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
......@@ -136,8 +136,7 @@ public class YangJavaSubModule
}
/**
* Prepares the information for java code generation corresponding to YANG
* submodule info.
* Prepares the information for java code generation corresponding to YANG submodule info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to translate
......@@ -171,9 +170,11 @@ public class YangJavaSubModule
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......
......@@ -38,11 +38,14 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
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.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
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;
......@@ -123,8 +126,12 @@ public final class ClassDefinitionGenerator {
return getInterfaceDefinition(yangName, curNode);
case BUILDER_CLASS_MASK:
return getBuilderClassDefinition(yangName, curNode);
case OPERATION_BUILDER_CLASS_MASK:
return getOpParamBuilderClassDefinition(yangName, curNode);
case IMPL_CLASS_MASK:
return getImplClassDefinition(yangName, curNode);
case OPERATION_CLASS_MASK:
return getOperClassDefinition(yangName, curNode);
case BUILDER_INTERFACE_MASK:
return getBuilderInterfaceDefinition(yangName, curNode);
case GENERATE_SERVICE_AND_MANAGER:
......@@ -205,6 +212,26 @@ public final class ClassDefinitionGenerator {
}
/**
* Returns operation param builder file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @return definition returns operation param builder file class definition
*/
private static String getOpParamBuilderClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_BUILDER_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + BUILDER + SPACE + EXTEND +
SPACE + getCapitalCase(DEFAULT) + yangName + PERIOD + yangName + BUILDER + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns impl file class definition.
*
* @param yangName file name
......@@ -223,6 +250,26 @@ public final class ClassDefinitionGenerator {
}
/**
* Returns operation param file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @return definition returns operation param file class definition
*/
private static String getOperClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns impl file class definition.
*
* @param yangName file name
......@@ -413,6 +460,19 @@ public final class ClassDefinitionGenerator {
return def + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case OPERATION_CLASS_MASK:
def = def + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (!info.getClassInfo().contains(BUILDER)
&& info.getClassInfo().contains(OPERATION)) {
def = getDefinitionString(def, info, holder);
}
}
def = trimAtLast(def, COMMA);
return def + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
default:
return null;
}
......
......@@ -105,16 +105,17 @@ public final class JavaCodeSnippetGen {
/**
* Returns the textual java code for attribute definition in class.
*
* @param javaAttributeTypePkg Package of the attribute type
* @param javaAttributeType java attribute type
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @return the textual java code for attribute definition in class
* @param javaAttributeTypePkg Package of the attribute type
* @param javaAttributeType java attribute type
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @param attributeAccessType attribute access type
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName, boolean isList) {
String javaAttributeName, boolean isList, String attributeAccessType) {
String attributeDefination = PRIVATE + SPACE;
String attributeDefination = attributeAccessType + SPACE;
if (!isList) {
if (javaAttributeTypePkg != null) {
......
......@@ -22,6 +22,9 @@ import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
......@@ -44,6 +47,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
......@@ -91,11 +96,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
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.getOmitNullValueString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypegetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeafList;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
......@@ -118,6 +133,27 @@ import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
import static org.onosproject.yangutils.utils.UtilConstants.CREATE;
import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
......@@ -328,6 +364,119 @@ public final class JavaFileGenerator {
}
/**
* Returns generated op param builder class file for current node.
* @param file file handle
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateOpParamBuilderClassFile(File file, YangNode curNode,
boolean isAttrPresent) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
initiateJavaFileGeneration(file, OPERATION_BUILDER_CLASS_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
/**
* Add attribute strings.
*/
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
}
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
/**
* Setter methods.
*/
methods.add(getSetterForLeaf(className, curNode, pluginConfig));
methods.add(getSetterForLeafList(className, curNode, pluginConfig));
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
methods.add(getToStringLeafgetter());
methods.add(getToStringSelectLeafgetter());
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
methods.add(getToStringLeafListgetter());
methods.add(getToStringSelectLeafListgetter());
}
}
methods.add(getOperationTypegetter());
methods.add(getOperationTypeSetter());
insertDataIntoJavaFile(file, NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder class file generation");
}
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
/**
* Add methods in builder class.
*/
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
return validateLineLength(file);
}
/**
* Returns generated manager class file for current node.
*
* @param file file
......@@ -513,6 +662,160 @@ public final class JavaFileGenerator {
}
/**
* Returns generated op param class file for current node.
*
* @param file file handle
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @param imports import list
* @return returns generated op param class file for current node
* @throws IOException when fails to write in file
*/
public static File generateOpParamImplClassFile(File file, YangNode curNode,
boolean isAttrPresent, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
/**
* Add attribute strings.
*/
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC +
SPACE + ENUM + SPACE + OPERATION_ENUM + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + EIGHT_SPACE_INDENTATION + MERGE +
NEW_LINE + EIGHT_SPACE_INDENTATION + REPLACE +
NEW_LINE + EIGHT_SPACE_INDENTATION + CREATE +
NEW_LINE + EIGHT_SPACE_INDENTATION + DELETE +
NEW_LINE + EIGHT_SPACE_INDENTATION + REMOVE +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
/**
* Add attribute strings.
*/
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
}
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
methods.add(getToStringLeafgetter());
methods.add(getToStringSelectLeafgetter());
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
methods.add(getToStringLeafListgetter());
methods.add(getToStringSelectLeafListgetter());
}
}
methods.add(getOperationTypegetter());
methods.add(getisFilterContentMatch(className, curNode, pluginConfig));
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
String constructor = getOpParamConstructorStart(className, pluginConfig);
constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS
+ BUILDER.toLowerCase() + OBJECT
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
String filterLeaf = "";
String filterLeafList = "";
if (leaves != null && !leaves.isEmpty()) {
filterLeaf = EIGHT_SPACE_INDENTATION + FILTER_LEAF + SPACE + EQUAL + SPACE
+ BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
filterLeafList = EIGHT_SPACE_INDENTATION + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE
+ BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
constructor = constructor + filterLeaf + filterLeafList;
}
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
/**
* Add methods in impl class.
*/
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return validateLineLength(file);
}
/**
* Generates class file for type def.
*
* @param file generated file
......
......@@ -55,6 +55,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
......@@ -95,6 +97,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENU
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OPERATION_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
......@@ -371,9 +374,16 @@ public final class JavaFileGeneratorUtils {
appendHeaderContents(file, pkgString, importsList);
write(file, genType, IMPL_CLASS, curNode, className);
break;
case OPERATION_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, genType, OPERATION_CLASS, curNode, className);
break;
case BUILDER_CLASS_MASK:
write(file, genType, BUILDER_CLASS, curNode, className);
break;
case OPERATION_BUILDER_CLASS_MASK:
write(file, genType, BUILDER_CLASS, curNode, className);
break;
case BUILDER_INTERFACE_MASK:
write(file, genType, BUILDER_INTERFACE, curNode, className);
break;
......
......@@ -19,6 +19,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
......@@ -27,15 +30,29 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
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.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getResolvedAugmentsForManager;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeaf;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeafList;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
......@@ -134,6 +151,25 @@ import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
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_UTILS_TODO;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.GET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.RECEIVED_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH;
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
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;
......@@ -537,6 +573,21 @@ public final class MethodsGenerator {
}
/**
* Returns constructor string for op param class.
*
* @param yangName class name
* @param pluginConfig plugin configurations
* @return constructor string
*/
public static String getOpParamConstructorStart(String yangName, YangPluginConfig pluginConfig) {
String javadoc = getConstructorString(yangName, pluginConfig);
String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + OPERATION +
OPEN_PARENTHESIS + yangName + OPERATION + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
/**
* Returns the constructor strings for class file.
*
* @param attr attribute info
......@@ -652,6 +703,278 @@ public final class MethodsGenerator {
}
/**
* Returns to string leaf for get method.
*
* @return string leaf for get method
*/
public static String getToStringLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string select leaf for get method.
*
* @return select leaf string for get method
*/
public static String getToStringSelectLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string leaf list for get method.
*
* @return string leaf list for get method
*/
public static String getToStringLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string select leaf list for get.
*
* @return select leaf list list for get
*/
public static String getToStringSelectLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string operation type for get method.
*
* @return operation type for get method
*/
public static String getOperationTypegetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + OPERATION_ENUM
+ SPACE + GET_OPERATION_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
+ OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string operation type for set.
*
* @return operation type set method
*/
public static String getOperationTypeSetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_OPERATION_TYPE
+ OPEN_PARENTHESIS + OPERATION_ENUM + SPACE + getSmallCase(OPERATION_ENUM) + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ OP_PARAM_TYPE + SPACE + EQUAL + SPACE + getSmallCase(OPERATION_ENUM) + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns string for leaf set method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf set method
*/
public static String getSetterForLeaf(String className, YangNode curnode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
if (leaves != null && !leaves.isEmpty()) {
for (YangLeaf leaf : leaves) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf, pluginConfig);
String attrQuaifiedType = getReturnType(javaAttributeInfo);
String attributeName = javaAttributeInfo.getAttributeName();
filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
+ attributeName + OPEN_PARENTHESIS + attrQuaifiedType
+ SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
+ RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
+ GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
numleaf++;
}
}
}
return filterMethod;
}
/**
* Returns string for leaf list set method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf list set method
*/
public static String getSetterForLeafList(String className, YangNode curnode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = getReturnType(javaAttributeInfo);
if (javaAttributeInfo.isListAttr()) {
attrQuaifiedType = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
}
filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
+ attributeName + OPEN_PARENTHESIS + attrQuaifiedType
+ SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
+ RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
+ GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
numleaf++;
}
}
}
return filterMethod;
}
/**
* Returns whether the data type is of primitive data type.
*
* @param dataType data type to be checked
* @return true, if data type can have primitive data type, false otherwise
*/
public static boolean isPrimitiveDataType(YangDataTypes dataType) {
return dataType == INT8
|| dataType == INT16
|| dataType == INT32
|| dataType == INT64
|| dataType == UINT8
|| dataType == UINT16
|| dataType == UINT32
|| dataType == UINT64
|| dataType == DECIMAL64
|| dataType == BOOLEAN;
}
/**
* Returns string for is filter content match method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for is filter content match method
*/
public static String getisFilterContentMatch(String className, YangNode curnode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null || listOfLeafList != null) {
filterMethod = NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
+ SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(DEFAULT)
+ getCapitalCase(className) + SPACE + APP_INSTANCE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
if (leaves != null) {
for (YangLeaf leaf : leaves) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf,
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = "";
if (isPrimitiveDataType(leaf.getDataType().getDataType())) {
attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + NOT + EQUAL + SPACE + attributeName + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS;
} else {
attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + OR_OPERATION + SPACE + OPEN_PARENTHESIS
+ NOT + OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS;
}
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
+ GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
+ OPEN_PARENTHESIS + attrQuaifiedType + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
+ SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
numleaf++;
}
}
if (listOfLeafList != null) {
numleaf = 1;
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = "";
if (isPrimitiveDataType(leafList.getDataType().getDataType())) {
attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + NOT + EQUAL + SPACE + attributeName + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS;
} else {
attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + EQUAL + EQUAL + SPACE + NULL + OR_OPERATION + OPEN_PARENTHESIS + NOT
+ OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
}
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
+ GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
+ OPEN_PARENTHESIS + attrQuaifiedType + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
+ SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
numleaf++;
}
}
if (leaves != null || listOfLeafList != null) {
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
}
return filterMethod;
}
/**
* Returns omit null value string.
*
* @return omit null value string
......
......@@ -47,6 +47,11 @@ public final class UtilConstants {
public static final String EVENT_JAVA_DOC = " * Represents event implementation of ";
/**
* JavaDocs for op param class.
*/
public static final String OP_PARAM_JAVA_DOC = " * Represents operation parameter implementation of ";
/**
* JavaDocs for event listener.
*/
public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
......@@ -167,6 +172,21 @@ public final class UtilConstants {
public static final String DEFAULT = "default";
/**
* Static attribute for op param class.
*/
public static final String OPERATION = "OpParam";
/**
* Static attribute for operation type.
*/
public static final String OPERATION_ENUM = "OperationType";
/**
* Static attribute for java code generation for sbi.
*/
public static final String SBI = "sbi";
/**
* Static attribute for multiple new line.
*/
public static final String MULTIPLE_NEW_LINE = "\n\n";
......@@ -512,6 +532,11 @@ public final class UtilConstants {
public static final String OPEN_PARENTHESIS = "(";
/**
* Static attribute for received syntax.
*/
public static final String RECEIVED_OBJECT = "recv";
/**
* Static attribute for switch syntax.
*/
public static final String SWITCH = "switch";
......@@ -562,11 +587,76 @@ public final class UtilConstants {
public static final String SET_METHOD_PREFIX = "set";
/**
* Static attribute for get filter leaf flags.
*/
public static final String GET_FILTER_LEAF = "getFilterLeafFlags";
/**
* Static attribute for get filter leaf list flags.
*/
public static final String GET_FILTER_LEAF_LIST = "getFilterLeafListFlags";
/**
* Static attribute for filter leaf flags.
*/
public static final String FILTER_LEAF = "filterLeafFlags";
/**
* Static attribute for filter leaf list flags.
*/
public static final String FILTER_LEAF_LIST = "filterLeafListFlags";
/**
* Static attribute for get select leaf flags.
*/
public static final String GET_SELECT_LEAF = "getSelectLeafFlags";
/**
* Static attribute for get select leaf list flags.
*/
public static final String GET_SELECT_LEAF_LIST = "getSelectLeafListFlags";
/**
* Static attribute for get operation type.
*/
public static final String GET_OPERATION_TYPE = "getOpertionType";
/**
* Static attribute for set operation type.
*/
public static final String SET_OPERATION_TYPE = "setOpertionType";
/**
* Static attribute for select leaf flags.
*/
public static final String SELECT_LEAF = "selectLeafFlags";
/**
* Static attribute for select leaf list flags.
*/
public static final String SELECT_LEAF_LIST = "selectLeafListFlags";
/**
* Static attribute for op param type.
*/
public static final String OP_PARAM_TYPE = "opParamType";
/**
* Static attribute for is filter content match method prefix.
*/
public static final String FILTER_CONTENT_MATCH = "isFilterContentMatch";
/**
* Static attribute for four space indentation.
*/
public static final String FOUR_SPACE_INDENTATION = " ";
/**
* Static attribute for not syntax.
*/
public static final String NOT = "!";
/**
* Static attribute for try syntax.
*/
public static final String TRY = "try";
......@@ -582,6 +672,31 @@ public final class UtilConstants {
public static final String SUPER = "super";
/**
* Static attribute for merge syntax.
*/
public static final String MERGE = "MERGE,";
/**
* Static attribute for replace syntax.
*/
public static final String REPLACE = "REPLACE,";
/**
* Static attribute for create syntax.
*/
public static final String CREATE = "CREATE,";
/**
* Static attribute for delete syntax.
*/
public static final String DELETE = "DELETE,";
/**
* Static attribute for remove syntax.
*/
public static final String REMOVE = "REMOVE";
/**
* Static attribute for eight space indentation.
*/
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
......@@ -637,6 +752,11 @@ public final class UtilConstants {
public static final String ABSTRACT = "abstract";
/**
* Static attribute for protected modifier.
*/
public static final String PROTECTED = "protected";
/**
* Void java type.
*/
public static final String VOID = "void";
......@@ -927,6 +1047,11 @@ public final class UtilConstants {
public static final String OBJECT = "Object";
/**
* Static attribute for app instance.
*/
public static final String APP_INSTANCE = "appInstance";
/**
* Static attribute for override annotation.
*/
public static final String OVERRIDE = "@Override";
......@@ -968,6 +1093,11 @@ public final class UtilConstants {
public static final String JAVA_UTIL_OBJECTS_IMPORT_PKG = "java.util";
/**
* Static attribute for bitset.
*/
public static final String BITSET = "BitSet";
/**
* Static attribute for java utilities objects import class.
*/
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
......@@ -1111,6 +1241,11 @@ public final class UtilConstants {
public static final String EVENT_LISTENER = "EventListener";
/**
* Static attribute for or operator.
*/
public static final String OR_OPERATION = "||";
/**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
......
......@@ -20,6 +20,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
......@@ -97,6 +98,12 @@ public final class JavaDocGen {
case BUILDER_CLASS: {
return generateForBuilderClass(name);
}
case OPERATION_CLASS: {
return generateForOpParamClass(name);
}
case OPERATION_BUILDER_CLASS: {
return generateForOpParamClass(name);
}
case INTERFACE: {
return generateForInterface(name);
}
......@@ -401,6 +408,17 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for the op param class.
*
* @param className class name
* @return javaDocs
*/
private static String generateForOpParamClass(String className) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + OP_PARAM_JAVA_DOC + className + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
/**
* Generates javaDoc for the interface.
*
* @param interfaceName interface name
......@@ -623,6 +641,16 @@ public final class JavaDocGen {
/**
* For event subject.
*/
EVENT_SUBJECT_CLASS
EVENT_SUBJECT_CLASS,
/**
* For operation.
*/
OPERATION_CLASS,
/**
* For operation builder.
*/
OPERATION_BUILDER_CLASS
}
}
......
......@@ -43,6 +43,29 @@ public final class YangPluginConfig {
}
/**
* Java code generation is for sbi.
*/
private String codeGenerateForsbi;
/**
* Returns the string for code generation.
*
* @return returns the string for code generation.
*/
public String getCodeGenerateForsbi() {
return codeGenerateForsbi;
}
/**
* Sets the string sbi or nbi for code generation.
*
* @par code generation is for sbi
*/
public void setCodeGenerateForsbi(String codeGenerateForsbi) {
this.codeGenerateForsbi = codeGenerateForsbi;
}
/**
* Sets the path of the java code where it has to be generated.
*
* @param codeGenDir path of the directory
......
......@@ -102,20 +102,24 @@ public class JavaCodeSnippetGenTest {
@Test
public void testForJavaAttributeInfo() {
String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, false);
String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithoutTypePkg.equals(
PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, false);
String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD
+ STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, true);
String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListPkg.equals(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, true);
String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListWithoutPkg.equals(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE
+ YANG_NAME + SEMI_COLAN + NEW_LINE)));
......