Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 20 | |
| 21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 24 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
| 25 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame^] | 26 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
| 27 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
| 29 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
| 30 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 31 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
| 32 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
| 33 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
| 34 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
| 36 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
| 37 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
| 38 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 39 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; |
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 43 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; |
| 44 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; |
| 45 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; |
| 46 | import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.IF; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 49 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; |
| 50 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 51 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
| 52 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
| 53 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 54 | import static org.onosproject.yangutils.utils.UtilConstants.OBJ; |
| 55 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
| 56 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; |
| 57 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
| 58 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
| 59 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
| 60 | import static org.onosproject.yangutils.utils.UtilConstants.OTHER; |
| 61 | import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE; |
| 62 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
| 64 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
| 65 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
| 66 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 67 | import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; |
| 68 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; |
| 69 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 70 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
| 71 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 72 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
| 73 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
| 74 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
| 75 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
| 76 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; |
| 77 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
| 78 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
| 79 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
| 80 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
| 81 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
| 82 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
| 83 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 84 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
| 85 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 86 | |
| 87 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 88 | * Represents generator for methods of generated files based on the file type. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 89 | */ |
| 90 | public final class MethodsGenerator { |
| 91 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 92 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 93 | * Creates an instance of method generator. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 94 | */ |
| 95 | private MethodsGenerator() { |
| 96 | } |
| 97 | |
| 98 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 99 | * Returns the methods strings for builder interface. |
| 100 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 101 | * @param name attribute name |
| 102 | * @return method string for builder interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 103 | */ |
| 104 | public static String parseBuilderInterfaceBuildMethodString(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 105 | return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns getter string. |
| 110 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 111 | * @param attr attribute info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 112 | * @return getter string |
| 113 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 114 | public static String getGetterString(JavaAttributeInfo attr) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 115 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 116 | String returnType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 117 | String attributeName = getSmallCase(attr.getAttributeName()); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 118 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 119 | return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) |
| 120 | + getGetterForInterface(attributeName, returnType, attr.isListAttr()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Returns setter string. |
| 125 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 126 | * @param attr attribute info |
| 127 | * @param className java class name |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 128 | * @return setter string |
| 129 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 130 | public static String getSetterString(JavaAttributeInfo attr, String className) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 131 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 132 | String attrType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 133 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 134 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 135 | return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr()) |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 136 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Returns constructor method string. |
| 141 | * |
| 142 | * @param name class name |
| 143 | * @return constructor string |
| 144 | */ |
| 145 | public static String getConstructorString(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 146 | return getJavaDoc(CONSTRUCTOR, name, false); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns default constructor method string. |
| 151 | * |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 152 | * @param name class name |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 153 | * @param modifierType modifier type |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 154 | * @return default constructor string |
| 155 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 156 | public static String getDefaultConstructorString(String name, String modifierType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 157 | return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Returns default constructor method string. |
| 162 | * |
| 163 | * @param attr attribute info |
| 164 | * @param className class name |
| 165 | * @return default constructor string |
| 166 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 167 | public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 168 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 169 | String attrQuaifiedType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 170 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 171 | |
| 172 | if (!attr.isListAttr()) { |
| 173 | return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); |
| 174 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 175 | String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 176 | return getTypeDefConstructorString(listAttr, attributeName, className); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns type def's constructor for attribute. |
| 181 | * |
| 182 | * @param type data type |
| 183 | * @param name attribute name |
| 184 | * @param className class name |
| 185 | * @return setter for type def's attribute |
| 186 | */ |
| 187 | private static String getTypeDefConstructorString(String type, String name, String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 188 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
| 189 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 190 | + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 191 | + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns check not null string. |
| 196 | * |
| 197 | * @param name attribute name |
| 198 | * @return check not null string |
| 199 | */ |
| 200 | public static String getCheckNotNull(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 201 | return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name |
| 202 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Returns build method string. |
| 207 | * |
| 208 | * @param name class name |
| 209 | * @return build string |
| 210 | */ |
| 211 | public static String getBuildString(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 212 | return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Returns the getter method strings for class file. |
| 217 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 218 | * @param attr attribute info |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 219 | * @return getter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 220 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 221 | public static String getGetterForClass(JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 222 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 223 | String attrQuaifiedType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 224 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 225 | |
| 226 | if (!attr.isListAttr()) { |
| 227 | return getGetter(attrQuaifiedType, attributeName); |
| 228 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 229 | String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
| 230 | return getGetter(listAttr, attributeName); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Returns getter for attribute. |
| 235 | * |
| 236 | * @param type return type |
| 237 | * @param name attribute name |
| 238 | * @return getter for attribute |
| 239 | */ |
| 240 | private static String getGetter(String type, String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 241 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) |
| 242 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 243 | + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Returns the setter method strings for class file. |
| 248 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 249 | * @param attr attribute info |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 250 | * @param className name of the class |
| 251 | * @return setter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 252 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 253 | public static String getSetterForClass(JavaAttributeInfo attr, String className) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 254 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 255 | String attrQuaifiedType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 256 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 257 | if (!attr.isListAttr()) { |
| 258 | return getSetter(className, attributeName, attrQuaifiedType); |
| 259 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 260 | String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
| 261 | return getSetter(className, attributeName, listAttr); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Returns setter for attribute. |
| 266 | * |
| 267 | * @param className class name |
| 268 | * @param name attribute name |
| 269 | * @param type return type |
| 270 | * @return setter for attribute |
| 271 | */ |
| 272 | private static String getSetter(String className, String name, String type) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 273 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX |
| 274 | + getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
| 275 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE |
| 276 | + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN |
| 277 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 281 | * Returns the setter method strings for class file. |
| 282 | * |
| 283 | * @param attr attribute info |
| 284 | * @return setter method for class |
| 285 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 286 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 287 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 288 | String attrQuaifiedType = getReturnType(attr); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 289 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 290 | return getTypeDefSetter(attrQuaifiedType, attributeName); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Returns type def's setter for attribute. |
| 295 | * |
| 296 | * @param type data type |
| 297 | * @param name attribute name |
| 298 | * @return setter for type def's attribute |
| 299 | */ |
| 300 | private static String getTypeDefSetter(String type, String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 301 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(name) |
| 302 | + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 303 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE |
| 304 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Returns override string. |
| 309 | * |
| 310 | * @return override string |
| 311 | */ |
| 312 | public static String getOverRideString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 313 | return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 317 | * Returns the getter method strings for interface file. |
| 318 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 319 | * @param yangName name of the attribute |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 320 | * @param returnType return type of attribute |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 321 | * @param isList is list attribute |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 322 | * @return getter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 323 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 324 | public static String getGetterForInterface(String yangName, String returnType, boolean isList) { |
| 325 | |
| 326 | if (!isList) { |
| 327 | return getGetterInterfaceString(returnType, yangName); |
| 328 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 329 | String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET; |
| 330 | return getGetterInterfaceString(listAttr, yangName); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Returns getter for attribute in interface. |
| 335 | * |
| 336 | * @param returnType return type |
| 337 | * @param yangName attribute name |
| 338 | * @return getter for interface |
| 339 | */ |
| 340 | private static String getGetterInterfaceString(String returnType, String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 341 | return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName) |
| 342 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Returns the setter method strings for interface file. |
| 347 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 348 | * @param attrName name of the attribute |
| 349 | * @param attrType return type of attribute |
| 350 | * @param className name of the java class being generated |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 351 | * @param isList is list attribute |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 352 | * @return setter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 353 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 354 | public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) { |
| 355 | |
| 356 | if (!isList) { |
| 357 | return getSetterInterfaceString(className, attrName, attrType); |
| 358 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 359 | String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
| 360 | return getSetterInterfaceString(className, attrName, listAttr); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Returns setter string for interface. |
| 365 | * |
| 366 | * @param className class name |
| 367 | * @param attrName attribute name |
| 368 | * @param attrType attribute type |
| 369 | * @return setter string |
| 370 | */ |
| 371 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 372 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName) |
| 373 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 377 | * Returns list string. |
| 378 | * |
| 379 | * @return list string |
| 380 | */ |
| 381 | private static String getListString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 382 | return LIST + DIAMOND_OPEN_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 386 | * Returns return type for attribute. |
| 387 | * |
| 388 | * @param attr attribute info |
| 389 | * @return return type |
| 390 | */ |
| 391 | private static String getReturnType(JavaAttributeInfo attr) { |
| 392 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 393 | String returnType = EMPTY_STRING; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 394 | if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 395 | returnType = attr.getImportInfo().getPkgInfo() + PERIOD; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 396 | } |
| 397 | returnType = returnType + attr.getImportInfo().getClassInfo(); |
| 398 | return returnType; |
| 399 | } |
| 400 | |
| 401 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 402 | * Returns the build method strings for interface file. |
| 403 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 404 | * @param yangName name of the interface |
| 405 | * @return build method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 406 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 407 | public static String getBuildForInterface(String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 408 | return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
| 409 | + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 413 | * Returns constructor string for impl class. |
| 414 | * |
| 415 | * @param yangName class name |
| 416 | * @return constructor string |
| 417 | */ |
| 418 | public static String getConstructorStart(String yangName) { |
| 419 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 420 | String javadoc = getConstructorString(yangName); |
| 421 | String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName |
| 422 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 423 | + NEW_LINE; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 424 | return javadoc + constructor; |
| 425 | } |
| 426 | |
| 427 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 428 | * Returns the constructor strings for class file. |
| 429 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 430 | * @param yangName name of the class |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 431 | * @param attr attribute info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 432 | * @return constructor for class |
| 433 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 434 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 435 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 436 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 437 | |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 438 | String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 439 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 440 | + getCaptialCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 441 | + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 442 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 443 | return constructor; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Returns the build method strings for class file. |
| 448 | * |
| 449 | * @param yangName class name |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 450 | * @return build method string for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 451 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 452 | public static String getBuild(String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 453 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 454 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE |
| 455 | + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
| 456 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Returns the Default constructor strings for class file. |
| 461 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 462 | * @param name name of the class |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 463 | * @param modifierType modifier type for default constructor |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 464 | * @return Default constructor for class |
| 465 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 466 | private static String getDefaultConstructor(String name, String modifierType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 467 | return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE |
| 468 | + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 469 | } |
| 470 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 471 | /** |
| 472 | * Returns to string method open strings. |
| 473 | * |
| 474 | * @return to string method open string |
| 475 | */ |
| 476 | public static String getToStringMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 477 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
| 478 | + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 479 | + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Returns to string methods close string. |
| 484 | * |
| 485 | * @return to string method close string |
| 486 | */ |
| 487 | public static String getToStringMethodClose() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 488 | return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 489 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 493 | * Returns to string method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 494 | * |
| 495 | * @param attr attribute info |
| 496 | * @return to string method |
| 497 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 498 | public static String getToStringMethod(JavaAttributeInfo attr) { |
| 499 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 500 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 501 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
| 502 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 506 | * Returns hash code method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 507 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 508 | * @return hash code method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 509 | */ |
| 510 | public static String getHashCodeMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 511 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING |
| 512 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 513 | + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 517 | * Returns hash code methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 518 | * |
| 519 | * @param hashcodeString hash code string |
| 520 | * @return to hash code method close string |
| 521 | */ |
| 522 | public static String getHashCodeMethodClose(String hashcodeString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 523 | hashcodeString = trimAtLast(hashcodeString, COMMA); |
| 524 | hashcodeString = trimAtLast(hashcodeString, SPACE); |
| 525 | return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 526 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 530 | * Returns hash code method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 531 | * |
| 532 | * @param attr attribute info |
| 533 | * @return hash code method |
| 534 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 535 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 536 | return getSmallCase(attr.getAttributeName()) + COMMA + SPACE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 540 | * Returns equals method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 541 | * |
| 542 | * @param className class name |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 543 | * @return equals method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 544 | */ |
| 545 | public static String getEqualsMethodOpen(String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 546 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING |
| 547 | + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 548 | + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Returns equal methods if condition string. |
| 553 | * |
| 554 | * @return if condition string |
| 555 | */ |
| 556 | private static String getEqualsMethodsCommonIfCondition() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 557 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ |
| 558 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE |
| 559 | + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Returns if condition for specific class object in equals method. |
| 564 | * |
| 565 | * @param className class name |
| 566 | * @return if condition string |
| 567 | */ |
| 568 | private static String getEqualsMethodsSpecificIfCondition(String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 569 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className |
| 570 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className |
| 571 | + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE |
| 572 | + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 576 | * Returns equals methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 577 | * |
| 578 | * @param equalMethodString equal method string |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 579 | * @return equals method close string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 580 | */ |
| 581 | public static String getEqualsMethodClose(String equalMethodString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 582 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 583 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 584 | equalMethodString = trimAtLast(equalMethodString, SPACE); |
| 585 | equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE; |
| 586 | return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 587 | + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 588 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 592 | * Returns equals method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 593 | * |
| 594 | * @param attr attribute info |
| 595 | * @return equals method |
| 596 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 597 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
| 598 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 599 | String attributeName = getSmallCase(attr.getAttributeName()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 600 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
| 601 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND |
| 602 | + AND; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Returns of method string for class. |
| 607 | * |
| 608 | * @param name class name |
| 609 | * @param attr attribute info |
| 610 | * @return of method string |
| 611 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 612 | public static String getOfMethod(String name, JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 613 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 614 | String attrQuaifiedType = getReturnType(attr); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 615 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS |
| 616 | + attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 617 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
| 618 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 619 | } |
| 620 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame^] | 621 | /** |
| 622 | * Returns implementation of add augmentation method of HasAugmentation class. |
| 623 | * |
| 624 | * @return implementation of add augmentation method of HasAugmentation class |
| 625 | */ |
| 626 | public static String getAddAugmentInfoMethodImpl() { |
| 627 | String method = FOUR_SPACE_INDENTATION; |
| 628 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING |
| 629 | + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE |
| 630 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST |
| 631 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE |
| 632 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 633 | |
| 634 | return method; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Returns implementation of get augment info list method of HasAugmentation class. |
| 639 | * |
| 640 | * @return implementation of get augment info list method of HasAugmentation class |
| 641 | */ |
| 642 | public static String getAugmentInfoListImpl() { |
| 643 | |
| 644 | String method = FOUR_SPACE_INDENTATION; |
| 645 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET |
| 646 | + AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST |
| 647 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 648 | + RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 649 | + CLOSE_CURLY_BRACKET; |
| 650 | return method; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Returns implementation of remove augmentation method of HasAugmentation class. |
| 655 | * |
| 656 | * @return implementation of remove augmentation method of HasAugmentation class |
| 657 | */ |
| 658 | public static String getRemoveAugmentationImpl() { |
| 659 | String method = FOUR_SPACE_INDENTATION; |
| 660 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove" |
| 661 | + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 662 | + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS |
| 663 | + CLOSE_PARENTHESIS + PERIOD + "clear" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
| 664 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 665 | return method; |
| 666 | } |
| 667 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 668 | } |