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