ST defect fixes and review comments fixes
Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
diff --git a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 63c1fe7..821f2b3 100644
--- a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -256,6 +256,7 @@
public static final String BUILD = "build";
public static final String OBJECT = "Object";
public static final String OVERRIDE = "@Override";
+ public static final String CHILDREN = "'s children";
/**
* For collections.
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index 7181a62..271d698 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -104,7 +104,7 @@
*/
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
- insertStringInFile(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString()));
+ updateFileHandle(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString()), false);
return;
}
@@ -133,18 +133,23 @@
}
/**
- * Insert content to the generated file.
+ * Update the generated file handle.
*
* @param inputFile input file
* @param contentTobeAdded content to be appended to the file
+ * @param isClose when close of file is called.
* @throws IOException when fails to append content to the file
*/
- public static void insertStringInFile(File inputFile, String contentTobeAdded) throws IOException {
+ public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException {
FileWriter fileWriter = new FileWriter(inputFile, true);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter);
- outputPrintWriter.write(contentTobeAdded);
- outputPrintWriter.flush();
- outputPrintWriter.close();
-
+ if (!isClose) {
+ outputPrintWriter.write(contentTobeAdded);
+ outputPrintWriter.flush();
+ outputPrintWriter.close();
+ } else {
+ fileWriter.flush();
+ fileWriter.close();
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index c2f170c..72bedf9 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -71,6 +71,21 @@
SETTER,
/**
+ * For type def's setters.
+ */
+ TYPE_DEF_SETTER,
+
+ /**
+ * For type def's constructor.
+ */
+ TYPE_DEF_CONSTRUCTOR,
+
+ /**
+ * For of method.
+ */
+ OF,
+
+ /**
* For default constructor.
*/
DEFAULT_CONSTRUCTOR,
@@ -91,10 +106,11 @@
*
* @param type java doc type
* @param name name of the YangNode
- * @return javadocs
+ * @param isList is list attribute
+ * @return javadocs.
*/
- public static String getJavaDoc(JavaDocType type, String name) {
- name = JavaIdentifierSyntax.getCamelCase(name);
+ public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
+ name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name));
String javaDoc = "";
if (type.equals(JavaDocType.IMPL_CLASS)) {
javaDoc = generateForImplClass(name);
@@ -107,9 +123,15 @@
} else if (type.equals(JavaDocType.PACKAGE_INFO)) {
javaDoc = generateForPackage(name);
} else if (type.equals(JavaDocType.GETTER)) {
- javaDoc = generateForGetters(name);
+ javaDoc = generateForGetters(name, isList);
+ } else if (type.equals(JavaDocType.TYPE_DEF_SETTER)) {
+ javaDoc = generateForTypeDefSetter(name);
+ } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) {
+ javaDoc = generateForTypeDefConstructor(name);
} else if (type.equals(JavaDocType.SETTER)) {
- javaDoc = generateForSetters(name);
+ javaDoc = generateForSetters(name, isList);
+ } else if (type.equals(JavaDocType.OF)) {
+ javaDoc = generateForOf(name);
} else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
javaDoc = generateForDefaultConstructors();
} else if (type.equals(JavaDocType.BUILD)) {
@@ -124,32 +146,96 @@
* Generate javaDocs for getter method.
*
* @param attribute attribute
+ * @param isList is list attribute
* @return javaDocs
*/
- private static String generateForGetters(String attribute) {
- return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ private static String generateForGetters(String attribute, boolean isList) {
+ String getter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.JAVA_DOC_FIRST_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
- + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
- + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN;
+ if (isList) {
+ attribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE
+ + attribute;
+ }
+
+ getter = getter + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_END_LINE;
+ return getter;
}
/**
* Generates javaDocs for setter method.
*
* @param attribute attribute
+ * @param isList is list attribute
* @return javaDocs
*/
- private static String generateForSetters(String attribute) {
- return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ private static String generateForSetters(String attribute, boolean isList) {
+ String setter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.JAVA_DOC_FIRST_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
- + attribute + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
+ + attribute + UtilConstants.SPACE;
+ if (isList) {
+ attribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE
+ + attribute;
+ }
+
+ setter = setter + attribute + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT
+ attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_END_LINE;
+ return setter;
+ }
+
+ /**
+ * Generates javaDocs for of method.
+ *
+ * @param attribute attribute
+ * @return javaDocs
+ */
+ private static String generateForOf(String attribute) {
+ return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_OF + attribute
+ + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.OBJECT
+ + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE;
+ }
+
+ /**
+ * Generates javaDocs for typedef setter method.
+ *
+ * @param attribute attribute
+ * @return javaDocs
+ */
+ private static String generateForTypeDefSetter(String attribute) {
+ return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS_COMMON + attribute
+ + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
+ }
+
+ /**
+ * Generates javaDocs for typedef constructor.
+ *
+ * @param attribute attribute
+ * @return javaDocs
+ */
+ private static String generateForTypeDefConstructor(String attribute) {
+ return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_CONSTRUCTOR + attribute
+ + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
+ + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
}
/**
@@ -170,8 +256,8 @@
* @return javaDocs
*/
private static String generateForBuilderClass(String className) {
- return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC + className
- + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
+ return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC
+ + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
@@ -181,8 +267,8 @@
* @return javaDocs
*/
private static String generateForInterface(String interfaceName) {
- return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC + interfaceName
- + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
+ return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC
+ + interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
index 98e0444..7af3d77 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
@@ -38,7 +38,7 @@
*
* @param root specified directory
* @return list of java files
- * @throws NullPointerException when no files are there
+ * @throws NullPointerException when no files are there.
* @throws IOException when files get deleted while performing the
* operations
*/
@@ -67,9 +67,8 @@
* @return list of required files
* @throws IOException when files get deleted while performing the
* operations
- * @throws NullPointerException null pointer access
*/
- public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException {
+ public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException {
List<String> store = new LinkedList<>();
Stack<String> stack = new Stack<>();
stack.push(root);
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index a0aba1f..d410cfb 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -16,6 +16,8 @@
package org.onosproject.yangutils.utils.io.impl;
+import static org.slf4j.LoggerFactory.getLogger;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -29,8 +31,6 @@
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
-import static org.slf4j.LoggerFactory.getLogger;
-
/**
* Provides common utility functionalities for code generation.
*/
@@ -80,7 +80,7 @@
fileWriter = new FileWriter(packageInfo);
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
- bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo));
+ bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo, false));
bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN);
bufferedWriter.close();
} catch (IOException e) {
@@ -127,4 +127,38 @@
log.info("Source directory added to compilation root: " + source);
}
+ /**
+ * Removes extra char from the string.
+ *
+ * @param valueString string to be trimmed
+ * @param removealStirng extra chars
+ * @return new string
+ */
+ public static String trimAtLast(String valueString, String removealStirng) {
+ StringBuilder stringBuilder = new StringBuilder(valueString);
+ int index = valueString.lastIndexOf(removealStirng);
+ stringBuilder.deleteCharAt(index);
+ return stringBuilder.toString();
+ }
+
+ /**
+ * Returns new parted string.
+ *
+ * @param partString string to be parted
+ * @return parted string
+ */
+ public static String partString(String partString) {
+ String[] strArray = partString.split(UtilConstants.COMMA);
+ String newString = "";
+ for (int i = 0; i < strArray.length; i++) {
+ if (i % 4 != 0) {
+ newString = newString + strArray[i] + UtilConstants.COMMA;
+ } else {
+ newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + strArray[i]
+ + UtilConstants.COMMA;
+ }
+ }
+ return trimAtLast(newString, UtilConstants.COMMA);
+ }
+
}