[ONOS-5096] Checkstyle issues fixed for generated code
Change-Id: I2821cde63def44a0dee916ee549e788ac4eef299
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 41cabfa..13eed0c 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -14,7 +14,7 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -24,7 +24,7 @@
</parent>
<artifactId>yangutils-maven-plugin</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.7.0-SNAPSHOT</version>
<name>onos-yang-utils-plugin</name>
<packaging>maven-plugin</packaging>
@@ -33,7 +33,7 @@
</properties>
<dependencies>
- <dependency>
+ <dependency>
<groupId>org.onosproject</groupId>
<artifactId>yangutils-datamodel</artifactId>
<version>1.7.0-SNAPSHOT</version>
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index a151f03..18913d4 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -18,22 +18,22 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
@@ -519,7 +519,6 @@
if (!(parent instanceof JavaCodeGenerator)) {
throw new TranslatorException("missing parent node to contain current node info in generated file");
}
-
if (parent instanceof YangJavaGroupingTranslator) {
/*
* In case of grouping, there is no need to add the information, it
@@ -582,7 +581,6 @@
isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
className, fileInfo.getPackage());
}
-
boolean collectionSetFlag = false;
if (curNode instanceof YangList) {
YangList yangList = (YangList) curNode;
@@ -605,16 +603,13 @@
}
}
}
-
if (isListNode && !(collectionSetFlag)) {
parentImportData.setIfListImported(true);
}
-
if (curNode instanceof YangList) {
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
((YangList) curNode).getCompilerAnnotation());
}
-
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
}
@@ -1379,7 +1374,7 @@
* @return attribute string
*/
String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
- //TODO: check if this utility needs to be called or move to the caller
+ //TODO: check if this utility needs to be called or move to the caller
String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
String attributeAccessType = PRIVATE;
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
@@ -1640,7 +1635,7 @@
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
.getJavaImportData().getImports();
if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, true, true);
+ addImportsForAugmentableClass(imports, true, true, curNode);
}
createPackage(curNode);
@@ -1669,7 +1664,7 @@
}
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, false, true);
+ addImportsForAugmentableClass(imports, false, true, curNode);
}
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
@@ -1677,9 +1672,18 @@
addImportsToStringAndHasCodeMethods(imports, true);
addArrayListImport(imports);
}
- addBitsetImport(imports);
+
+ boolean isLeavesPresent;
+ if (curNode instanceof YangLeavesHolder) {
+ YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
+ isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
+ || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
+ if (isLeavesPresent) {
+ addBitsetImport(imports);
+ }
+ }
if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, true, false);
+ addImportsForAugmentableClass(imports, true, false, curNode);
addInvocationExceptionImport(imports);
}
sortImports(imports);
@@ -1701,9 +1705,7 @@
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
-
}
-
//Close all the file handles.
freeTemporaryResources(false);
}
@@ -1741,13 +1743,18 @@
* @param imports import list
* @param operations true for adding and false for deletion
* @param isInterfaceFile if need to add in interface file
+ * @param curNode current node
*/
- private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile) {
+ private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
+ YangNode curNode) {
if (operations) {
if (!isInterfaceFile) {
imports.add(getJavaImportData().getHashMapImport());
}
- imports.add(getJavaImportData().getMapImport());
+ // Add import for hash map only if node is not a YANG choice.
+ if (!(curNode instanceof YangChoice)) {
+ imports.add(getJavaImportData().getMapImport());
+ }
} else {
if (!isInterfaceFile) {
imports.remove(getJavaImportData().getHashMapImport());
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
index 6190f5d..e6a5379 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -20,14 +20,13 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
@@ -526,6 +525,14 @@
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(imports, true);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
+
+ // In case if data type is binary, MoreObjects is not required and should be removed.
+ if (curNode instanceof YangTypeHolder) {
+ YangType yangType = ((YangTypeHolder) curNode).getTypeList().get(0);
+ if (yangType.getDataType() == YangDataTypes.BINARY) {
+ imports.remove(getJavaImportData().getImportForToString());
+ }
+ }
generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
}
/*
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index 2250a62..0d52229 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -20,10 +20,10 @@
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
@@ -346,12 +346,12 @@
" * Identify the leafs whose value are explicitly set\n" +
" * Applicable in protocol edit and query operation\n" +
" */\n" +
- " private BitSet _valueLeafFlags = new BitSet();\n" +
+ " private BitSet valueLeafFlags = new BitSet();\n" +
"\n" +
" /**\n" +
" * Identify the leafs to be selected, in a query operation\n" +
" */\n" +
- " private BitSet _selectLeafFlags = new BitSet();\n";
+ " private BitSet selectLeafFlags = new BitSet();\n";
}
/**
@@ -364,7 +364,7 @@
" * Specify the node specific operation in protocols like NETCONF.\n" +
" * Applicable in protocol edit operation, will be ignored in query operation\n" +
" */\n" +
- " private OperationType _operationType;\n" +
+ " private OperationType operationType;\n" +
"\n";
}
@@ -374,8 +374,8 @@
* @return operation type enum, leaf value set attribute and select leaf attribute for constructor
*/
static String getOperationAttributeForConstructor() {
- return " this._valueLeafFlags = builderObject.get_valueLeafFlags();\n" +
- " this._selectLeafFlags = builderObject.get_selectLeafFlags();\n";
+ return " this.valueLeafFlags = builderObject.getValueLeafFlags();\n" +
+ " this.selectLeafFlags = builderObject.getSelectLeafFlags();\n";
}
/**
@@ -384,7 +384,7 @@
* @return operation type enum, leaf value set attribute and select leaf attribute for constructor
*/
static String getOperationTypeForConstructor() {
- return " this._operationType = builderObject.get_operationType();\n";
+ return " this.operationType = builderObject.getOperationType();\n";
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index 9d0ca67..412409a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
@@ -31,19 +30,19 @@
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
@@ -171,6 +170,7 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.replaceLast;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
import static java.util.Collections.sort;
@@ -226,12 +226,12 @@
//Leaf identifier enum.
if (isLeavesPresent) {
insertDataIntoJavaFile(file, NEW_LINE + getInterfaceLeafIdEnumSignature(className) + NEW_LINE +
- trimAtLast(trimAtLast(
+ trimAtLast(replaceLast(
getDataFromTempFileHandle(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path), COMMA), NEW_LINE) + SEMI_COLAN
- + NEW_LINE + NEW_LINE + getInterfaceLeafIdEnumMethods());
+ .getBeanTempFiles(), path), COMMA, SEMI_COLAN), NEW_LINE) +
+ NEW_LINE + NEW_LINE + getInterfaceLeafIdEnumMethods());
}
//Getter methods.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 5f00ecc..431eecf 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -21,18 +21,18 @@
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
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.JavaFileInfoTranslator;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
@@ -179,6 +179,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
+import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
@@ -190,7 +191,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
@@ -469,7 +469,7 @@
//Returns value leaf flag setter.
private static String getValueLeafSetString(String name) {
- return "\n get_valueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
+ return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
}
/**
@@ -519,7 +519,7 @@
* @return getter method for interface
*/
static String getGetterForInterface(String yangName, String returnType, boolean isList,
- int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
+ int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
}
@@ -556,8 +556,8 @@
* @return setter method for interface
*/
static String getSetterForInterface(String attrName, String attrType, String className,
- boolean isList, int generatedJavaFiles,
- YangCompilerAnnotation compilerAnnotation) {
+ boolean isList, int generatedJavaFiles,
+ YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
}
@@ -958,7 +958,8 @@
getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + IS_EMPTY +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
- method = method + TWELVE_SPACE_INDENTATION + IF + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + getSmallCase(name)
+ method = method + TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD +
+ getSmallCase(name)
+ OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + "||" + SPACE +
getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + IS_EMPTY + CLOSE_PARENTHESIS +
@@ -976,7 +977,7 @@
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
FLAG + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN + NEW_LINE;
method = method + SIXTEEN_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE +
- UNDER_SCORE + getSmallCase(name)
+ TMP_VAR + getSmallCase(name)
+ SPACE + COLAN + SPACE + APP_INSTANCE + PERIOD + getSmallCase(name) + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
method = method + TWENTY_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + getSmallCase(name) + PERIOD;
@@ -988,7 +989,7 @@
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
FLAG + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN + NEW_LINE;
method = method + SIXTEEN_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + name + SPACE +
- UNDER_SCORE + getSmallCase(name)
+ TMP_VAR + getSmallCase(name)
+ SPACE + COLAN + SPACE + APP_INSTANCE + PERIOD + getSmallCase(name) + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
method = method + TWENTY_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + getSmallCase(name) + PERIOD;
@@ -998,15 +999,15 @@
} else {
method = method + EQUALS_STRING;
}
- method = method + OPEN_PARENTHESIS + UNDER_SCORE + getSmallCase(name) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ method = method + OPEN_PARENTHESIS + TMP_VAR + getSmallCase(name) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + FLAG + SPACE + EQUAL + SPACE + TRUE +
SEMI_COLAN
+ NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + BREAK + SEMI_COLAN + NEW_LINE + TWENTY_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
- method = method + SIXTEEN_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + FLAG + SPACE + EQUAL + EQUAL
- + SPACE + FALSE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWENTY_SPACE_INDENTATION
+ method = method + SIXTEEN_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + NOT + FLAG
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWENTY_SPACE_INDENTATION
+ RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
NEW_LINE;
return method + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
@@ -1036,12 +1037,12 @@
NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + PERIOD + GET_CLASS + COMMA + SPACE +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO)
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
- + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + CATCH + OPEN_PARENTHESIS
+ + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS
+ NO_SUCH_METHOD_EXCEPTION + " | " + INVOCATION_TARGET_EXCEPTION + " | " + ILLEGAL_ACCESS_EXCEPTION +
SPACE + EXCEPTION_VAR + 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 + TWELVE_SPACE_INDENTATION
- + IF + OPEN_PARENTHESIS + NOT + FILTER_CONTENT_MATCH + CLOSE_PARENTHESIS +
+ + IF + SPACE + OPEN_PARENTHESIS + NOT + FILTER_CONTENT_MATCH + 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;
@@ -1200,7 +1201,7 @@
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS + SPACE;
+ + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
}
/**
@@ -1649,7 +1650,7 @@
getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
getCapitalCase(curNodeName), returnType, parentName, false,
- GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
+ GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
methods.append(method);
}
return methods.toString();
@@ -1871,21 +1872,21 @@
static String getOperationAttributesGetters() {
return "\n" +
" /**\n" +
- " * Returns the _valueLeafFlags.\n" +
+ " * Returns the valueLeafFlags.\n" +
" *\n" +
- " * @return value of _valueLeafFlags\n" +
+ " * @return value of valueLeafFlags\n" +
" */\n" +
- " public BitSet get_valueLeafFlags() {\n" +
- " return _valueLeafFlags;\n" +
+ " public BitSet getValueLeafFlags() {\n" +
+ " return valueLeafFlags;\n" +
" }\n" +
"\n" +
" /**\n" +
- " * Returns the _selectLeafFlags.\n" +
+ " * Returns the selectLeafFlags.\n" +
" *\n" +
- " * @return value of _selectLeafFlags\n" +
+ " * @return value of selectLeafFlags\n" +
" */\n" +
- " public BitSet get_selectLeafFlags() {\n" +
- " return _selectLeafFlags;\n" +
+ " public BitSet getSelectLeafFlags() {\n" +
+ " return selectLeafFlags;\n" +
" }\n" +
"\n";
}
@@ -1897,12 +1898,12 @@
*/
static String getGetterForOperationType() {
return " /**\n" +
- " * Returns the _operationType.\n" +
+ " * Returns the operationType.\n" +
" *\n" +
- " * @return value of _operationType\n" +
+ " * @return value of operationType\n" +
" */\n" +
- " public OperationType get_operationType() {\n" +
- " return _operationType;\n" +
+ " public OperationType getOperationType() {\n" +
+ " return operationType;\n" +
" }\n";
}
@@ -1915,12 +1916,12 @@
return "\n" +
" @Override\n" +
" public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
- " return get_valueLeafFlags().get(leaf.getLeafIndex());\n" +
+ " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
" }\n" +
"\n" +
" @Override\n" +
" public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
- " return get_selectLeafFlags().get(leaf.getLeafIndex());\n" +
+ " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
" }\n";
}
@@ -1934,10 +1935,10 @@
return " /**\n" +
" * Set operation type.\n" +
" *\n" +
- " * @param _operationType operation type\n" +
+ " * @param operationType operation type\n" +
" */\n" +
- " public " + name + BUILDER + " set_operationType(OperationType _operationType) {\n" +
- " this._operationType = _operationType;\n" +
+ " public " + name + BUILDER + " setOperationType(OperationType operationType) {\n" +
+ " this.operationType = operationType;\n" +
" return this;\n" +
" }\n";
}
@@ -1957,7 +1958,7 @@
return "\n" +
" " + append + "\n" +
" public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
- " get_selectLeafFlags().set(leaf.getLeafIndex());\n" +
+ " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
" return this;\n" +
" }\n";
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 23dacfe..580b6cf 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -761,7 +761,7 @@
/**
* Static attribute for get filter leaf flags.
*/
- public static final String GET_FILTER_LEAF = "get_valueLeafFlags";
+ public static final String GET_FILTER_LEAF = "getValueLeafFlags";
/**
* Static attribute for getLeafIndex.
@@ -1398,6 +1398,21 @@
public static final String ARRAY_LIST_IMPORT = IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
/**
+ * Static attribute for temp keyword.
+ */
+ public static final String TMP_VAR = "tmp";
+
+ /**
+ * Static attribute for unused keyword.
+ */
+ public static final String UNUSED = "UNUSED";
+
+ /**
+ * Static attribute for 1 keyword.
+ */
+ public static final String ONE = "1";
+
+ /**
* Creates an instance of util constants.
*/
private UtilConstants() {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index 1c1de71..be6db1f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -28,18 +28,20 @@
import java.util.List;
import java.util.Stack;
import java.util.regex.Pattern;
-
import org.apache.commons.io.FileUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.ONE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
@@ -61,6 +63,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
+import static org.onosproject.yangutils.utils.UtilConstants.UNUSED;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
@@ -240,6 +243,29 @@
}
/**
+ * Replaces the last occurrence of a string with a given string.
+ *
+ * @param valueString string under operation
+ * @param removalString string to be replaced
+ * @param replacingString string with which replacement is to be done
+ * @return new string
+ */
+ public static String replaceLast(String valueString, String removalString, String replacingString) {
+ StringBuilder stringBuilder = new StringBuilder(valueString);
+ int index = valueString.lastIndexOf(removalString);
+ if (index != -1) {
+ stringBuilder.replace(index, index + 1, replacingString);
+ } else {
+ stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED + OPEN_PARENTHESIS + ONE +
+ CLOSE_PARENTHESIS + SEMI_COLAN);
+ }
+ return stringBuilder.toString();
+
+ // TODO remove generation of ENUM if there is no leaf node.
+ }
+
+
+ /**
* Returns the directory path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be