blob: 6270cd2dc622a19bf74f0e71f7952efe4a54ae7b [file] [log] [blame]
Bharat saraswal870c56f2016-02-20 21:57:16 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Bharat saraswal870c56f2016-02-20 21:57:16 +05303 *
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
17package org.onosproject.yangutils.translator.tojava.utils;
18
Vinod Kumar S38046502016-03-23 15:30:27 +053019import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
Bharat saraswale2d51d62016-03-23 19:40:35 +053020
21import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
22import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
Bharat saraswal2f11f652016-03-25 18:19:46 +053023import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
Bharat saraswale2d51d62016-03-23 19:40:35 +053024import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
25import static org.onosproject.yangutils.utils.UtilConstants.AND;
26import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
27import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
28import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
29import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
30import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
31import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
32import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
33import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
34import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
35import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
36import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
37import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
38import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
39import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
40import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
41import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
42import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
43import static org.onosproject.yangutils.utils.UtilConstants.HASH;
44import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
45import static org.onosproject.yangutils.utils.UtilConstants.IF;
46import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
47import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
48import static org.onosproject.yangutils.utils.UtilConstants.INT;
49import static org.onosproject.yangutils.utils.UtilConstants.LIST;
50import static org.onosproject.yangutils.utils.UtilConstants.NEW;
51import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
52import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
53import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
54import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
55import static org.onosproject.yangutils.utils.UtilConstants.OF;
56import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
57import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
58import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
59import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
60import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
61import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
62import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
63import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
64import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
65import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
66import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
67import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
68import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
69import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
70import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
71import static org.onosproject.yangutils.utils.UtilConstants.THIS;
72import static org.onosproject.yangutils.utils.UtilConstants.TO;
73import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
74import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
75import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
76import static org.onosproject.yangutils.utils.UtilConstants.VOID;
77import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
78import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
79import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
80import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
81import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
82import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
83import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
Bharat saraswal870c56f2016-02-20 21:57:16 +053084
85/**
Bharat saraswald9822e92016-04-05 15:13:44 +053086 * Represents generator for methods of generated files based on the file type.
Bharat saraswal870c56f2016-02-20 21:57:16 +053087 */
88public final class MethodsGenerator {
89
Bharat saraswal870c56f2016-02-20 21:57:16 +053090 /**
Bharat saraswald9822e92016-04-05 15:13:44 +053091 * Creates an instance of method generator.
Bharat saraswal870c56f2016-02-20 21:57:16 +053092 */
93 private MethodsGenerator() {
94 }
95
96 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +053097 * Returns the methods strings for builder interface.
98 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053099 * @param name attribute name
100 * @return method string for builder interface
Bharat saraswal870c56f2016-02-20 21:57:16 +0530101 */
102 public static String parseBuilderInterfaceBuildMethodString(String name) {
103
Bharat saraswale2d51d62016-03-23 19:40:35 +0530104 return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530105 }
106
107 /**
108 * Returns getter string.
109 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530110 * @param attr attribute info
Bharat saraswal870c56f2016-02-20 21:57:16 +0530111 * @return getter string
112 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530113 public static String getGetterString(JavaAttributeInfo attr) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530114
Vinod Kumar S38046502016-03-23 15:30:27 +0530115 String returnType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530116 String attributeName = getSmallCase(attr.getAttributeName());
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530117
Bharat saraswale2d51d62016-03-23 19:40:35 +0530118 return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr())
119 + getGetterForInterface(attributeName, returnType, attr.isListAttr());
Bharat saraswal870c56f2016-02-20 21:57:16 +0530120 }
121
122 /**
123 * Returns setter string.
124 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530125 * @param attr attribute info
126 * @param className java class name
Bharat saraswal870c56f2016-02-20 21:57:16 +0530127 * @return setter string
128 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530129 public static String getSetterString(JavaAttributeInfo attr, String className) {
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530130
Vinod Kumar S38046502016-03-23 15:30:27 +0530131 String attrType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530132 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswal870c56f2016-02-20 21:57:16 +0530133
Bharat saraswale2d51d62016-03-23 19:40:35 +0530134 return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr())
Vinod Kumar S38046502016-03-23 15:30:27 +0530135 + getSetterForInterface(attributeName, attrType, className, attr.isListAttr());
Bharat saraswal870c56f2016-02-20 21:57:16 +0530136 }
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 saraswale2d51d62016-03-23 19:40:35 +0530146 return getJavaDoc(CONSTRUCTOR, name, false);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530147 }
148
149 /**
150 * Returns default constructor method string.
151 *
Bharat saraswal870c56f2016-02-20 21:57:16 +0530152 * @param name class name
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530153 * @param modifierType modifier type
Bharat saraswal870c56f2016-02-20 21:57:16 +0530154 * @return default constructor string
155 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530156 public static String getDefaultConstructorString(String name, String modifierType) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530157
Bharat saraswale2d51d62016-03-23 19:40:35 +0530158 return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530159 }
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 S38046502016-03-23 15:30:27 +0530168 public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530169
Vinod Kumar S38046502016-03-23 15:30:27 +0530170 String attrQuaifiedType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530171 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530172
173 if (!attr.isListAttr()) {
174 return getTypeDefConstructorString(attrQuaifiedType, attributeName, className);
175 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530176 String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530177 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 saraswale2d51d62016-03-23 19:40:35 +0530190 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 saraswal2f00b4b2016-03-04 20:08:09 +0530194 }
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 S38046502016-03-23 15:30:27 +0530203
Bharat saraswale2d51d62016-03-23 19:40:35 +0530204 return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
205 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530206 }
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 saraswale2d51d62016-03-23 19:40:35 +0530216 return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name);
Bharat saraswal870c56f2016-02-20 21:57:16 +0530217 }
218
219 /**
220 * Returns the getter method strings for class file.
221 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530222 * @param attr attribute info
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530223 * @return getter method for class
Bharat saraswal870c56f2016-02-20 21:57:16 +0530224 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530225 public static String getGetterForClass(JavaAttributeInfo attr) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530226
Vinod Kumar S38046502016-03-23 15:30:27 +0530227 String attrQuaifiedType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530228 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530229
230 if (!attr.isListAttr()) {
231 return getGetter(attrQuaifiedType, attributeName);
232 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530233 String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
234 return getGetter(listAttr, attributeName);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530235 }
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 saraswal870c56f2016-02-20 21:57:16 +0530245
Bharat saraswale2d51d62016-03-23 19:40:35 +0530246 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 saraswal870c56f2016-02-20 21:57:16 +0530249 }
250
251 /**
252 * Returns the setter method strings for class file.
253 *
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530254 * @param attr attribute info
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530255 * @param className name of the class
256 * @return setter method for class
Bharat saraswal870c56f2016-02-20 21:57:16 +0530257 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530258 public static String getSetterForClass(JavaAttributeInfo attr, String className) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530259
Vinod Kumar S38046502016-03-23 15:30:27 +0530260 String attrQuaifiedType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530261 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530262 if (!attr.isListAttr()) {
263 return getSetter(className, attributeName, attrQuaifiedType);
264 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530265 String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
266 return getSetter(className, attributeName, listAttr);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530267 }
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 saraswal870c56f2016-02-20 21:57:16 +0530278
Bharat saraswale2d51d62016-03-23 19:40:35 +0530279 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 saraswal870c56f2016-02-20 21:57:16 +0530284 }
285
286 /**
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530287 * Returns the setter method strings for class file.
288 *
289 * @param attr attribute info
290 * @return setter method for class
291 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530292 public static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530293
Vinod Kumar S38046502016-03-23 15:30:27 +0530294 String attrQuaifiedType = getReturnType(attr);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530295 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswale2d51d62016-03-23 19:40:35 +0530296 return getTypeDefSetter(attrQuaifiedType, attributeName);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530297 }
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 saraswale2d51d62016-03-23 19:40:35 +0530308 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 saraswal2f00b4b2016-03-04 20:08:09 +0530312 }
313
314 /**
315 * Returns override string.
316 *
317 * @return override string
318 */
319 public static String getOverRideString() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530320
Bharat saraswale2d51d62016-03-23 19:40:35 +0530321 return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530322 }
323
324 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +0530325 * Returns the getter method strings for interface file.
326 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530327 * @param yangName name of the attribute
Bharat saraswal870c56f2016-02-20 21:57:16 +0530328 * @param returnType return type of attribute
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530329 * @param isList is list attribute
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530330 * @return getter method for interface
Bharat saraswal870c56f2016-02-20 21:57:16 +0530331 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530332 public static String getGetterForInterface(String yangName, String returnType, boolean isList) {
333
334 if (!isList) {
335 return getGetterInterfaceString(returnType, yangName);
336 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530337 String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET;
338 return getGetterInterfaceString(listAttr, yangName);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530339 }
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 saraswale2d51d62016-03-23 19:40:35 +0530350 return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName)
351 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530352 }
353
354 /**
355 * Returns the setter method strings for interface file.
356 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530357 * @param attrName name of the attribute
358 * @param attrType return type of attribute
359 * @param className name of the java class being generated
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530360 * @param isList is list attribute
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530361 * @return setter method for interface
Bharat saraswal870c56f2016-02-20 21:57:16 +0530362 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530363 public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) {
364
365 if (!isList) {
366 return getSetterInterfaceString(className, attrName, attrType);
367 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530368 String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
369 return getSetterInterfaceString(className, attrName, listAttr);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530370 }
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 saraswale2d51d62016-03-23 19:40:35 +0530382 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName)
383 + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530384 }
385
386 /**
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530387 * Returns list string.
388 *
389 * @return list string
390 */
391 private static String getListString() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530392
Bharat saraswale2d51d62016-03-23 19:40:35 +0530393 return LIST + DIAMOND_OPEN_BRACKET;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530394 }
395
396 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530397 * 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 saraswale2d51d62016-03-23 19:40:35 +0530404 String returnType = EMPTY_STRING;
Vinod Kumar S38046502016-03-23 15:30:27 +0530405 if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530406 returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
Vinod Kumar S38046502016-03-23 15:30:27 +0530407 }
408 returnType = returnType + attr.getImportInfo().getClassInfo();
409 return returnType;
410 }
411
412 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +0530413 * Returns the build method strings for interface file.
414 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530415 * @param yangName name of the interface
416 * @return build method for interface
Bharat saraswal870c56f2016-02-20 21:57:16 +0530417 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530418 public static String getBuildForInterface(String yangName) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530419
Bharat saraswale2d51d62016-03-23 19:40:35 +0530420 return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
421 + NEW_LINE;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530422 }
423
424 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530425 * 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 saraswale2d51d62016-03-23 19:40:35 +0530432 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 S38046502016-03-23 15:30:27 +0530436 return javadoc + constructor;
437 }
438
439 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +0530440 * Returns the constructor strings for class file.
441 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530442 * @param yangName name of the class
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530443 * @param attr attribute info
Bharat saraswal870c56f2016-02-20 21:57:16 +0530444 * @return constructor for class
445 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530446 public static String getConstructor(String yangName, JavaAttributeInfo attr) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530447
Bharat saraswal2f11f652016-03-25 18:19:46 +0530448 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswale2d51d62016-03-23 19:40:35 +0530449
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 saraswal870c56f2016-02-20 21:57:16 +0530454
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530455 return constructor;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530456 }
457
458 /**
459 * Returns the build method strings for class file.
460 *
461 * @param yangName class name
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530462 * @return build method string for class
Bharat saraswal870c56f2016-02-20 21:57:16 +0530463 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530464 public static String getBuild(String yangName) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530465
Bharat saraswale2d51d62016-03-23 19:40:35 +0530466 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 saraswal870c56f2016-02-20 21:57:16 +0530470 }
471
472 /**
473 * Returns the Default constructor strings for class file.
474 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530475 * @param name name of the class
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530476 * @param modifierType modifier type for default constructor
Bharat saraswal870c56f2016-02-20 21:57:16 +0530477 * @return Default constructor for class
478 */
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530479 private static String getDefaultConstructor(String name, String modifierType) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530480
Bharat saraswale2d51d62016-03-23 19:40:35 +0530481 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 saraswal870c56f2016-02-20 21:57:16 +0530483 }
484
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530485 /**
486 * Returns to string method open strings.
487 *
488 * @return to string method open string
489 */
490 public static String getToStringMethodOpen() {
491
Bharat saraswale2d51d62016-03-23 19:40:35 +0530492 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 saraswal2f00b4b2016-03-04 20:08:09 +0530495 }
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 S38046502016-03-23 15:30:27 +0530503
Bharat saraswale2d51d62016-03-23 19:40:35 +0530504 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 saraswal2f00b4b2016-03-04 20:08:09 +0530506 }
507
508 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530509 * Returns to string method for class.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530510 *
511 * @param attr attribute info
512 * @return to string method
513 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530514 public static String getToStringMethod(JavaAttributeInfo attr) {
515
Bharat saraswal2f11f652016-03-25 18:19:46 +0530516 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswale2d51d62016-03-23 19:40:35 +0530517
518 return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
519 + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530520
521 }
522
523 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530524 * Returns hash code method open strings.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530525 *
Bharat saraswald9822e92016-04-05 15:13:44 +0530526 * @return hash code method open string
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530527 */
528 public static String getHashCodeMethodOpen() {
529
Bharat saraswale2d51d62016-03-23 19:40:35 +0530530 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 saraswal2f00b4b2016-03-04 20:08:09 +0530533 }
534
535 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530536 * Returns hash code methods close string.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530537 *
538 * @param hashcodeString hash code string
539 * @return to hash code method close string
540 */
541 public static String getHashCodeMethodClose(String hashcodeString) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530542
Bharat saraswale2d51d62016-03-23 19:40:35 +0530543 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 saraswal2f00b4b2016-03-04 20:08:09 +0530547 }
548
549 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530550 * Returns hash code method for class.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530551 *
552 * @param attr attribute info
553 * @return hash code method
554 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530555 public static String getHashCodeMethod(JavaAttributeInfo attr) {
556
Bharat saraswal2f11f652016-03-25 18:19:46 +0530557 return getSmallCase(attr.getAttributeName()) + COMMA + SPACE;
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530558 }
559
560 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530561 * Returns equals method open strings.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530562 *
563 * @param className class name
Bharat saraswald9822e92016-04-05 15:13:44 +0530564 * @return equals method open string
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530565 */
566 public static String getEqualsMethodOpen(String className) {
567
Bharat saraswale2d51d62016-03-23 19:40:35 +0530568 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 saraswal2f00b4b2016-03-04 20:08:09 +0530571 }
572
573 /**
574 * Returns equal methods if condition string.
575 *
576 * @return if condition string
577 */
578 private static String getEqualsMethodsCommonIfCondition() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530579
Bharat saraswale2d51d62016-03-23 19:40:35 +0530580 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 saraswal2f00b4b2016-03-04 20:08:09 +0530583 }
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 S38046502016-03-23 15:30:27 +0530592
Bharat saraswale2d51d62016-03-23 19:40:35 +0530593 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 saraswal2f00b4b2016-03-04 20:08:09 +0530597 }
598
599 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530600 * Returns equals methods close string.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530601 *
602 * @param equalMethodString equal method string
Bharat saraswald9822e92016-04-05 15:13:44 +0530603 * @return equals method close string
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530604 */
605 public static String getEqualsMethodClose(String equalMethodString) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530606
Bharat saraswale2d51d62016-03-23 19:40:35 +0530607 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 saraswal2f00b4b2016-03-04 20:08:09 +0530614 }
615
616 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530617 * Returns equals method for class.
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530618 *
619 * @param attr attribute info
620 * @return equals method
621 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530622 public static String getEqualsMethod(JavaAttributeInfo attr) {
623
Bharat saraswal2f11f652016-03-25 18:19:46 +0530624 String attributeName = getSmallCase(attr.getAttributeName());
Bharat saraswale2d51d62016-03-23 19:40:35 +0530625
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 saraswal2f00b4b2016-03-04 20:08:09 +0530629
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 S38046502016-03-23 15:30:27 +0530639 public static String getOfMethod(String name, JavaAttributeInfo attr) {
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530640
Vinod Kumar S38046502016-03-23 15:30:27 +0530641 String attrQuaifiedType = getReturnType(attr);
Bharat saraswal2f00b4b2016-03-04 20:08:09 +0530642
Bharat saraswale2d51d62016-03-23 19:40:35 +0530643 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 saraswal2f00b4b2016-03-04 20:08:09 +0530647 }
648
Bharat saraswal870c56f2016-02-20 21:57:16 +0530649}