[ONOS-5003][ONOS-5004][ONOS-5005]Generated Code modification for YangUtils+added interface for augmentation method and other api changes.
Change-Id: I954b9c99e182f21d01fcc5cd76fbac7d61a6c3aa
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 2312ba7..21f2723 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -107,6 +107,11 @@
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
/**
+ * JavaDocs's description for add to list method.
+ */
+ public static final String JAVA_DOC_ADD_TO_LIST = " * Adds to the list of ";
+
+ /**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_MANAGER_SETTERS = " * Sets the value to attribute ";
@@ -187,11 +192,6 @@
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";
@@ -217,16 +217,16 @@
public static final String PERIOD = ".";
/**
+ * Static attribute for period.
+ */
+ public static final String INVOKE = "invoke";
+
+ /**
* Static attribute for parse byte.
*/
public static final String PARSE_BYTE = "parseByte";
/**
- * Static attribute for get bytes.
- */
- public static final String GET_BYTES = "getBytes";
-
- /**
* Static attribute for parse boolean.
*/
public static final String PARSE_BOOLEAN = "parseBoolean";
@@ -694,11 +694,6 @@
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";
@@ -749,6 +744,16 @@
public static final String GET_METHOD_PREFIX = "get";
/**
+ * Static attribute for getter method prefix.
+ */
+ public static final String GET_METHOD = "getMethod";
+
+ /**
+ * Static attribute for getter method prefix.
+ */
+ public static final String GET_CLASS = "getClass()";
+
+ /**
* Static attribute for setter method prefix.
*/
public static final String SET_METHOD_PREFIX = "set";
@@ -756,57 +761,18 @@
/**
* Static attribute for get filter leaf flags.
*/
- public static final String GET_FILTER_LEAF = "getFilterLeafFlags";
+ public static final String GET_FILTER_LEAF = "get_valueLeafFlags";
/**
- * Static attribute for get filter leaf list flags.
+ * Static attribute for getLeafIndex.
*/
- public static final String GET_FILTER_LEAF_LIST = "getFilterLeafListFlags";
+ public static final String GET_LEAF_INDEX = "getLeafIndex()";
/**
- * Static attribute for filter leaf flags.
+ * Static attribute for op param.
*/
- public static final String FILTER_LEAF = "filterLeafFlags";
+ public static final String OP_PARAM = "OpParam";
- /**
- * 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.
@@ -814,6 +780,41 @@
public static final String FILTER_CONTENT_MATCH = "isFilterContentMatch";
/**
+ * Static attribute for flag prefix.
+ */
+ public static final String FLAG = "flag";
+
+ /**
+ * Static attribute for break prefix.
+ */
+ public static final String BREAK = "break";
+
+ /**
+ * Static attribute for break prefix.
+ */
+ public static final String IS_EMPTY = "isEmpty()";
+
+ /**
+ * Static attribute for is isLeafValueSet method prefix.
+ */
+ public static final String VALUE_LEAF_SET = "isLeafValueSet";
+
+ /**
+ * Static attribute for is isSelectLeaf method prefix.
+ */
+ public static final String IS_SELECT_LEAF = "isSelectLeaf";
+
+ /**
+ * Static attribute for is selectLeaf method prefix.
+ */
+ public static final String SET_SELECT_LEAF = "selectLeaf";
+
+ /**
+ * Static attribute for is LeafIdentifier enum prefix.
+ */
+ public static final String LEAF_IDENTIFIER = "LeafIdentifier";
+
+ /**
* Static attribute for four space indentation.
*/
public static final String FOUR_SPACE_INDENTATION = " ";
@@ -834,36 +835,6 @@
public static final String CATCH = "catch";
/**
- * Static attribute for super syntax.
- */
- 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;
@@ -879,6 +850,16 @@
public static final String SIXTEEN_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
/**
+ * Static attribute for twenty space indentation.
+ */
+ public static final String TWENTY_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + SIXTEEN_SPACE_INDENTATION;
+
+ /**
+ * Static attribute for twenty four space indentation.
+ */
+ public static final String TWENTY_FOUR_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + SIXTEEN_SPACE_INDENTATION;
+
+ /**
* Static attribute for generated code path.
*/
public static final String YANG_GEN_DIR = "src/main/java/";
@@ -899,7 +880,7 @@
public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
/**
- * Static attribute for YANG version perifx.
+ * Static attribute for YANG version prefix.
*/
public static final String VERSION_PREFIX = "v";
@@ -1014,7 +995,7 @@
public static final String LONG_WRAPPER = "Long";
/**
- * Static varibale for question mark.
+ * Static variable for question mark.
*/
public static final String QUESTION_MARK = "?";
@@ -1022,11 +1003,11 @@
* List of keywords in java, this is used for checking if the input does not contain these keywords.
*/
public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
- "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", "package", "synchronized",
- "boolean", "do", "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte",
- "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch",
- "extends", "int", "short", "try", "char", "final", "interface", "static", "void", "class", "finally",
- "long", "strictfp", "volatile", "const", "float", "native", "super", "while");
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if",
+ "implements", "import", "instanceof", "enum", "int", "interface", "long", "native", "new", "null",
+ "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
+ "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
/**
* Static attribute for regex for all the special characters.
@@ -1199,11 +1180,6 @@
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
- * Static attribute for impl syntax.
- */
- public static final String IMPL = "Impl";
-
- /**
* Static attribute for build method syntax.
*/
public static final String BUILD = "build";
@@ -1275,21 +1251,6 @@
public static final String JAVA_UTIL_IMPORT_BASE64_CLASS = "Base64;\n";
/**
- * Static attribute for AugmentedInfo class import package.
- */
- public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel";
-
- /**
- * Static attribute for AugmentedInfo class import class.
- */
- public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS = "YangAugmentedInfo;\n";
-
- /**
- * Static attribute for augmentation class.
- */
- public static final String AUGMENTED_INFO = "AugmentedInfo";
-
- /**
* Static attribute for AugmentedInfo class.
*/
public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
@@ -1305,104 +1266,11 @@
public static final String LIST = "List";
/**
- * Comment to be added for autogenerated impl methods.
+ * Comment to be added for auto generated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
- * Static attribute for activate annotation.
- */
- public static final String ACTIVATE_ANNOTATION = "@Activate\n";
-
- /**
- * Static attribute for activate.
- */
- public static final String ACTIVATE = "activate";
-
- /**
- * Static attribute for activate annotation import.
- */
- public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n";
-
- /**
- * Static attribute for deactivate annotation.
- */
- public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n";
-
- /**
- * Static attribute for deactivate.
- */
- public static final String DEACTIVATE = "deactivate";
-
- /**
- * Static attribute for deactivate annotation import.
- */
- public static final String DEACTIVATE_ANNOTATION_IMPORT =
- "import org.apache.felix.scr.annotations.Deactivate;\n";
-
- /**
- * Static attribute for component annotation.
- */
- public static final String COMPONENT_ANNOTATION = "@Component";
-
- /**
- * Static attribute for component.
- */
- public static final String COMPONENT = "Component";
-
- /**
- * Static attribute for immediate.
- */
- public static final String IMMEDIATE = "immediate";
-
- /**
- * Static attribute for component annotation import.
- */
- public static final String COMPONENT_ANNOTATION_IMPORT =
- "import org.apache.felix.scr.annotations.Component;\n";
-
- /**
- * Static attribute for service annotation.
- */
- public static final String SERVICE_ANNOTATION = "@Service\n";
-
- /**
- * Static attribute for service annotation import.
- */
- public static final String SERVICE_ANNOTATION_IMPORT =
- "import org.apache.felix.scr.annotations.Service;\n";
-
- /**
- * Static attribute for logger factory import.
- */
- public static final String LOGGER_FACTORY_IMPORT =
- "import static org.slf4j.LoggerFactory.getLogger;\n";
-
- /**
- * Static attribute for logger import.
- */
- public static final String LOGGER_IMPORT =
- "import org.slf4j.Logger;\n";
-
- /**
- * Static attribute for logger statement.
- */
- public static final String LOGGER_STATEMENT =
- "\n private final Logger log = getLogger(getClass());\n";
-
- /**
- * Static attribute for logger statement for started.
- */
- public static final String STARTED_LOG_INFO =
- "log.info(\"Started\");\n";
-
- /**
- * Static attribute for logger statement for stopped.
- */
- public static final String STOPPED_LOG_INFO =
- "log.info(\"Stopped\");\n";
-
- /**
* Static attribute for AbstractEvent.
*/
public static final String ABSTRACT_EVENT = "AbstractEvent";
@@ -1470,16 +1338,6 @@
+ "identity for given base";
/**
- * Static attribute for reference.
- */
- public static final String REFERENCE = "Reference";
-
- /**
- * Static attribute for ReferenceCardinality.
- */
- public static final String REFERENCE_CARDINALITY = "ReferenceCardinality";
-
- /**
* Static attribute for jar.
*/
public static final String JAR = "jar";
@@ -1495,31 +1353,34 @@
public static final String YANG_AUGMENTED_OP_PARAM_INFO = "YangAugmentedOpParamInfo";
/**
- * Static attribute for YangAugmentedOpParamInfo.
+ * Static attribute for NoSuchMethodException.
*/
- public static final String YANG_AUGMENTED_OP_PARAM_INFO_CLASS = "YangAugmentedOpParamInfo;\n";
+ public static final String NO_SUCH_METHOD_EXCEPTION = "NoSuchMethodException";
/**
- * Static attribute for IllegalArgumentException.
+ * Static attribute for InvocationTargetException.
*/
- public static final String ILLEGAL_ARGUMENT_EXCEPTION = "IllegalArgumentException";
+ public static final String INVOCATION_TARGET_EXCEPTION = "InvocationTargetException";
/**
- * Static attribute for IllegalArgumentException.
+ * Static attribute for InvocationTargetException.
*/
- public static final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "\"provided augmented info is invalid for content " +
- "match.\"";
+ public static final String INVOCATION_TARGET_EXCEPTION_IMPORT = "import" +
+ " java.lang.reflect.InvocationTargetException;\n";
+ /**
+ * Static attribute for IllegalAccessException.
+ */
+ public static final String ILLEGAL_ACCESS_EXCEPTION = "IllegalAccessException";
/**
- * Static attribute for throw.
+ * Static attribute for arrayList.
*/
- public static final String THROW = "throw";
+ public static final String ARRAY_LIST = "ArrayList<>()";
/**
- * Static attribute for baseClass().
+ * Static attribute for arrayList import.
*/
- public static final String BASE_CLASS = "BaseClass()";
-
+ public static final String ARRAY_LIST_IMPORT = IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
/**
* Creates an instance of util constants.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index fae08ed..1b58c0f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -44,16 +44,13 @@
}
/**
- * Reads the contents from source file and append its contents to append
- * file.
+ * Reads the contents from source file and append its contents to append file.
*
- * @param toAppend destination file in which the contents of source file is
- * appended
- * @param srcFile source file from which data is read and added to to append
- * file
+ * @param toAppend destination file in which the contents of source file is appended
+ * @param srcFile source file from which data is read and added to to append file
* @throws IOException any IO errors
*/
- public static void appendFileContents(File toAppend, File srcFile)
+ static void appendFileContents(File toAppend, File srcFile)
throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
}
@@ -76,14 +73,21 @@
String line = bufferReader.readLine();
while (line != null) {
- if (line.equals(SPACE) || line.equals(EMPTY_STRING) || line.equals(EIGHT_SPACE_INDENTATION)
- || line.equals(MULTIPLE_NEW_LINE)) {
- stringBuilder.append(NEW_LINE);
- } else if (line.equals(FOUR_SPACE_INDENTATION)) {
- stringBuilder.append(EMPTY_STRING);
- } else {
- stringBuilder.append(spaces + line);
- stringBuilder.append(NEW_LINE);
+ switch (line) {
+ case SPACE:
+ case EMPTY_STRING:
+ case EIGHT_SPACE_INDENTATION:
+ case MULTIPLE_NEW_LINE:
+ stringBuilder.append(NEW_LINE);
+ break;
+ case FOUR_SPACE_INDENTATION:
+ stringBuilder.append(EMPTY_STRING);
+ break;
+ default:
+ String append = spaces + line;
+ stringBuilder.append(append);
+ stringBuilder.append(NEW_LINE);
+ break;
}
line = bufferReader.readLine();
}
@@ -100,10 +104,10 @@
* @param inputFile input file
* @param contentTobeAdded content to be appended to the file
* @param isClose when close of file is called.
- * @throws IOException if the named file exists but is a directory rather than a regular file,
- * does not exist but cannot be created, or cannot be opened for any other reason
+ * @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but
+ * cannot be created, or cannot be opened for any other reason
*/
- public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
+ static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
List<FileWriter> fileWriterStore = new ArrayList<>();
@@ -119,7 +123,6 @@
for (FileWriter curWriter : fileWriterStore) {
curWriter.flush();
curWriter.close();
- curWriter = null;
}
}
}
@@ -137,7 +140,10 @@
if (file != null) {
updateFileHandle(file, null, true);
if (toBeDeleted) {
- file.delete();
+ boolean deleted = file.delete();
+ if (!deleted) {
+ throw new IOException("Failed to delete temporary file " + file.getName());
+ }
}
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index a674f17..3b47386 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -19,17 +19,12 @@
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
-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;
+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.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
@@ -38,15 +33,17 @@
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_ADD_TO_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
@@ -57,11 +54,14 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
+import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
+import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
@@ -71,6 +71,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
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.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
@@ -92,7 +93,7 @@
* @param name name of the YangNode
* @param isList is list attribute
* @param pluginConfig plugin configurations
- * @return javadocs.
+ * @return javaDocs.
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
@@ -167,6 +168,9 @@
case EVENT_SUBJECT_CLASS: {
return generateForClass(name);
}
+ case ADD_TO_LIST: {
+ return generateForAddToList(name);
+ }
default: {
return generateForConstructors(name);
}
@@ -180,8 +184,8 @@
* @return javaDocs
*/
private static String generateForEnumAttr(String name) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
- + name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return EIGHT_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + EIGHT_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
+ + name + PERIOD + NEW_LINE + EIGHT_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
@@ -438,11 +442,11 @@
/**
* Generates javaDoc for the builder interface.
*
- * @param builderforName builder for name
+ * @param builderForName builder for name
* @return javaDocs
*/
- private static String generateForBuilderInterface(String builderforName) {
- return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE
+ private static String generateForBuilderInterface(String builderForName) {
+ return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderForName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
@@ -480,7 +484,7 @@
*/
private static String generateForConstructors(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
- + className + IMPL + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ + className + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT
+ className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
@@ -504,7 +508,7 @@
* @param attribute attribute string
* @return javaDocs for type constructor
*/
- public static String generateForTypeConstructor(String attribute) {
+ private static String generateForTypeConstructor(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
@@ -557,6 +561,52 @@
}
/**
+ * Generates javaDocs for type constructor.
+ *
+ * @param attribute attribute string
+ * @return javaDocs for type constructor
+ */
+ public static String generateForGetMethodWithAttribute(String attribute) {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_GETTERS
+ + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_PARAM + attribute + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ }
+
+ /**
+ * Returns javaDocs for add to list method.
+ *
+ * @param attribute attribute
+ * @return javaDocs
+ */
+ private static String generateForAddToList(String attribute) {
+ String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_ADD_TO_LIST + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE;
+ javadoc = javadoc + VALUE + SPACE + OF + SPACE;
+ javadoc = javadoc + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return javadoc;
+ }
+
+ /**
+ * Generates for builder method.
+ *
+ * @param attribute attribute
+ * @return javaDocs
+ */
+ public static String generateForBuilderMethod(String attribute) {
+
+ String javadoc = FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_GETTERS + attribute + BUILDER + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
+ + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
+ javadoc = javadoc + VALUE + SPACE + OF + SPACE;
+ javadoc = javadoc + attribute + BUILDER + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return javadoc;
+ }
+
+
+ /**
* JavaDocs types.
*/
public enum JavaDocType {
@@ -679,6 +729,12 @@
/**
* For operation builder.
*/
- OPERATION_BUILDER_CLASS
+ OPERATION_BUILDER_CLASS,
+
+ /**
+ * For add to list.
+ */
+ ADD_TO_LIST,
}
+
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
index ff2e3e7..b5f5fca 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
@@ -27,8 +27,8 @@
*/
public final class YangFileScanner {
- private static final String JAVA_FILE_EXTENTION = ".java";
- private static final String YANG_FILE_EXTENTION = ".yang";
+ private static final String JAVA_FILE_EXTENSION = ".java";
+ private static final String YANG_FILE_EXTENSION = ".yang";
/**
* Creates an instance of YANG file scanner.
@@ -45,9 +45,8 @@
* @throws IOException when files get deleted while performing the
* operations
*/
- public static List<String> getJavaFiles(String root) throws IOException {
-
- return getFiles(root, JAVA_FILE_EXTENTION);
+ static List<String> getJavaFiles(String root) throws IOException {
+ return getFiles(root, JAVA_FILE_EXTENSION);
}
/**
@@ -60,8 +59,7 @@
* operations
*/
public static List<String> getYangFiles(String root) throws IOException {
-
- return getFiles(root, YANG_FILE_EXTENTION);
+ return getFiles(root, YANG_FILE_EXTENSION);
}
/**
@@ -73,22 +71,22 @@
* @throws NullPointerException when no file is there
* @throws IOException when files get deleted while performing the operations
*/
- public static List<String> getFiles(String root, String extension) throws IOException {
+ private static List<String> getFiles(String root, String extension) throws IOException {
List<String> store = new LinkedList<>();
Stack<String> stack = new Stack<>();
stack.push(root);
File file;
- File[] filelist;
+ File[] fileList;
try {
while (!stack.empty()) {
root = stack.pop();
file = new File(root);
- filelist = file.listFiles();
- if ((filelist == null) || (filelist.length == 0)) {
+ fileList = file.listFiles();
+ if ((fileList == null) || (fileList.length == 0)) {
continue;
}
- for (File current : filelist) {
+ for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
} else {
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 0c6b51e..7b91ae9 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
@@ -62,6 +62,7 @@
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.YANG_AUTO_PREFIX;
+import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
@@ -87,10 +88,16 @@
*
* @param path directory path
* @return directory structure
+ * @throws IOException when fails to do IO operations
*/
- public static File createDirectories(String path) {
+ public static File createDirectories(String path) throws IOException {
File generatedDir = new File(path);
- generatedDir.mkdirs();
+ if (!generatedDir.exists()) {
+ boolean isGenerated = generatedDir.mkdirs();
+ if (!isGenerated) {
+ throw new IOException("failed to generated directory " + path);
+ }
+ }
return generatedDir;
}
@@ -113,22 +120,26 @@
try {
File packageInfo = new File(path + SLASH + "package-info.java");
- packageInfo.createNewFile();
-
+ if (!packageInfo.exists()) {
+ boolean isGenerated = packageInfo.createNewFile();
+ if (!isGenerated) {
+ throw new IOException("failed to generated package-info " + path);
+ }
+ }
FileWriter fileWriter = new FileWriter(packageInfo);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
- bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
+ bufferedWriter.write(getCopyrightHeader());
bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig));
String pkg = PACKAGE + SPACE + pack + SEMI_COLAN;
if (pkg.length() > LINE_SIZE) {
- pkg = whenDelimiterIsPersent(pkg, LINE_SIZE);
+ pkg = whenDelimiterIsPresent(pkg, LINE_SIZE);
}
bufferedWriter.write(pkg);
bufferedWriter.close();
fileWriter.close();
} catch (IOException e) {
- throw new IOException("Exception occured while creating package info file.");
+ throw new IOException("Exception occurred while creating package info file.");
}
}
@@ -192,11 +203,11 @@
while (!stack.empty()) {
root = stack.pop();
File file = new File(root);
- File[] filelist = file.listFiles();
- if (filelist == null || filelist.length == 0) {
+ File[] fileList = file.listFiles();
+ if (fileList == null || fileList.length == 0) {
continue;
}
- for (File current : filelist) {
+ for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
if (current.getName().endsWith("-Temp")) {
@@ -215,12 +226,12 @@
* Removes extra char from the string.
*
* @param valueString string to be trimmed
- * @param removalStirng extra chars
+ * @param removalString extra chars
* @return new string
*/
- public static String trimAtLast(String valueString, String removalStirng) {
+ public static String trimAtLast(String valueString, String removalString) {
StringBuilder stringBuilder = new StringBuilder(valueString);
- int index = valueString.lastIndexOf(removalStirng);
+ int index = valueString.lastIndexOf(removalString);
if (index != -1) {
stringBuilder.deleteCharAt(index);
}
@@ -302,9 +313,9 @@
*/
public static File validateLineLength(File dataFile)
throws IOException {
- File tempFile = dataFile;
FileReader fileReader = new FileReader(dataFile);
BufferedReader bufferReader = new BufferedReader(fileReader);
+ String append;
try {
StringBuilder stringBuilder = new StringBuilder();
String line = bufferReader.readLine();
@@ -312,20 +323,21 @@
while (line != null) {
if (line.length() > LINE_SIZE) {
if (line.contains(PERIOD)) {
- line = whenDelimiterIsPersent(line, LINE_SIZE);
+ line = whenDelimiterIsPresent(line, LINE_SIZE);
} else if (line.contains(SPACE)) {
line = whenSpaceIsPresent(line, LINE_SIZE);
}
stringBuilder.append(line);
} else {
- stringBuilder.append(line + NEW_LINE);
+ append = line + NEW_LINE;
+ stringBuilder.append(append);
}
line = bufferReader.readLine();
}
- FileWriter writer = new FileWriter(tempFile);
+ FileWriter writer = new FileWriter(dataFile);
writer.write(stringBuilder.toString());
writer.close();
- return tempFile;
+ return dataFile;
} finally {
fileReader.close();
bufferReader.close();
@@ -333,14 +345,15 @@
}
/* When delimiters are present in the given line. */
- private static String whenDelimiterIsPersent(String line, int lineSize) {
+ private static String whenDelimiterIsPresent(String line, int lineSize) {
StringBuilder stringBuilder = new StringBuilder();
-
+ String append;
if (line.length() > lineSize) {
String[] strArray = line.split(Pattern.quote(PERIOD));
stringBuilder = updateString(strArray, stringBuilder, PERIOD, lineSize);
} else {
- stringBuilder.append(line + NEW_LINE);
+ append = line + NEW_LINE;
+ stringBuilder.append(append);
}
String[] strArray = stringBuilder.toString().split(NEW_LINE);
StringBuilder tempBuilder = new StringBuilder();
@@ -353,7 +366,8 @@
tempBuilder.append(whenSpaceIsPresent(str, SUB_LINE_SIZE));
}
} else {
- tempBuilder.append(str + NEW_LINE);
+ append = str + NEW_LINE;
+ tempBuilder.append(append);
}
}
return tempBuilder.toString();
@@ -363,11 +377,13 @@
/* When spaces are present in the given line. */
private static String whenSpaceIsPresent(String line, int lineSize) {
StringBuilder stringBuilder = new StringBuilder();
+ String append;
if (line.length() > lineSize) {
String[] strArray = line.split(SPACE);
stringBuilder = updateString(strArray, stringBuilder, SPACE, lineSize);
} else {
- stringBuilder.append(line + NEW_LINE);
+ append = line + NEW_LINE;
+ stringBuilder.append(append);
}
String[] strArray = stringBuilder.toString().split(NEW_LINE);
@@ -379,7 +395,8 @@
tempBuilder = updateString(strArr, tempBuilder, SPACE, SUB_LINE_SIZE);
}
} else {
- tempBuilder.append(str + NEW_LINE);
+ append = str + NEW_LINE;
+ tempBuilder.append(append);
}
}
return tempBuilder.toString();
@@ -390,28 +407,34 @@
int lineSize) {
StringBuilder tempBuilder = new StringBuilder();
+ String append;
for (String str : strArray) {
- tempBuilder.append(str + string);
+ append = str + string;
+ tempBuilder.append(append);
if (tempBuilder.length() > lineSize) {
String tempString = stringBuilder.toString();
stringBuilder.delete(ZERO, stringBuilder.length());
tempString = trimAtLast(tempString, string);
stringBuilder.append(tempString);
if (string.equals(PERIOD)) {
- stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string);
+ append = NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string;
+ stringBuilder.append(append);
} else {
- stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + str + string);
+ append = NEW_LINE + TWELVE_SPACE_INDENTATION + str + string;
+ stringBuilder.append(append);
}
tempBuilder.delete(ZERO, tempBuilder.length());
tempBuilder.append(TWELVE_SPACE_INDENTATION);
} else {
- stringBuilder.append(str + string);
+ append = str + string;
+ stringBuilder.append(append);
}
}
String tempString = stringBuilder.toString();
tempString = trimAtLast(tempString, string);
stringBuilder.delete(ZERO, stringBuilder.length());
- stringBuilder.append(tempString + NEW_LINE);
+ append = tempString + NEW_LINE;
+ stringBuilder.append(append);
return stringBuilder;
}
@@ -464,7 +487,7 @@
* @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
* @return string without consecutive capital case
*/
- public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
+ private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
if (k + 1 < consecCapitalCaseRemover.length()) {
@@ -487,7 +510,7 @@
* @param conflictResolver object of YANG to java naming conflict util
* @return prefixed camel case string
*/
- public static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
+ private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
String prefix = getPrefixForIdentifier(conflictResolver);
if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
@@ -508,7 +531,7 @@
* @param conflictResolver object of YANG to java naming conflict util
* @return camel case rule checked string
*/
- public static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
+ private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
String ruleChecker = stringArray[0].toLowerCase();
int i;
@@ -551,8 +574,8 @@
* @param conflictResolver object of YANG to java naming conflict util
* @return camel cased string
*/
- public static String upperCaseConflictResolver(String[] stringArray,
- YangToJavaNamingConflictUtil conflictResolver) {
+ private static String upperCaseConflictResolver(String[] stringArray,
+ YangToJavaNamingConflictUtil conflictResolver) {
for (int l = 0; l < stringArray.length; l++) {
String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
@@ -579,7 +602,7 @@
}
stringArray[l] = strBuilder.toString();
}
- List<String> result = new ArrayList<String>();
+ List<String> result = new ArrayList<>();
for (String element : stringArray) {
String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
for (String letter : capitalCaseSplitArray) {
@@ -625,10 +648,8 @@
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
String[] strArray = yangIdentifier.split(COLAN);
if (strArray[0].isEmpty()) {
- List<String> stringArrangement = new ArrayList<String>();
- for (int i = 1; i < strArray.length; i++) {
- stringArrangement.add(strArray[i]);
- }
+ List<String> stringArrangement = new ArrayList<>();
+ stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
return upperCaseConflictResolver(strArray, conflictResolver);
@@ -651,10 +672,8 @@
String[] strArray = prefixForIdentifier.split(COLAN);
try {
if (strArray[0].isEmpty()) {
- List<String> stringArrangement = new ArrayList<String>();
- for (int i = 1; i < strArray.length; i++) {
- stringArrangement.add(strArray[i]);
- }
+ List<String> stringArrangement = new ArrayList<>();
+ stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
prefixForIdentifier = strArray[0];