blob: 9dfbf807a1bc0b311f32aa85f81090ed943448cd [file] [log] [blame]
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.yangutils.translator.tojava.utils;
18
19import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
20import org.onosproject.yangutils.datamodel.YangType;
21import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
22import org.onosproject.yangutils.translator.exception.TranslatorException;
23
24import java.util.Map;
25
26import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
27import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
28import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
29import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
30import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
31import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
32import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
33import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
34import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
35import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
36import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
37import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
38import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
39import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
40import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
41import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIfConditionForAddToListMethod;
42import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
43import static org.onosproject.yangutils.utils.UtilConstants.AND;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053044import static org.onosproject.yangutils.utils.UtilConstants.APPEND;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053045import static org.onosproject.yangutils.utils.UtilConstants.AT;
46import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
47import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053048import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053049import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
50import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
51import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
52import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
53import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
54import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
55import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
56import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
57import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
58import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
59import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
60import static org.onosproject.yangutils.utils.UtilConstants.COLON;
61import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
62import static org.onosproject.yangutils.utils.UtilConstants.COMPARE_TO;
63import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
64import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
65import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
66import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
67import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
68import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
69import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
70import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
71import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
72import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
73import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
74import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
75import static org.onosproject.yangutils.utils.UtilConstants.FOR;
76import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
77import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
78import static org.onosproject.yangutils.utils.UtilConstants.GET;
Bharat saraswal94844d62016-10-13 13:28:03 +053079import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053080import static org.onosproject.yangutils.utils.UtilConstants.IF;
81import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
82import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
83import static org.onosproject.yangutils.utils.UtilConstants.IN;
84import static org.onosproject.yangutils.utils.UtilConstants.INT;
85import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
86import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
87import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
88import static org.onosproject.yangutils.utils.UtilConstants.LIST;
89import static org.onosproject.yangutils.utils.UtilConstants.LONG;
90import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
91import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
92import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053093import static org.onosproject.yangutils.utils.UtilConstants.MORE_OBJ_ATTR;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053094import static org.onosproject.yangutils.utils.UtilConstants.NEW;
95import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
96import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
97import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
98import static org.onosproject.yangutils.utils.UtilConstants.OF;
99import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530100import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530101import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
102import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
103import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
104import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
105import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
106import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
107import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
108import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530109import static org.onosproject.yangutils.utils.UtilConstants.PATTERN;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530110import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
111import static org.onosproject.yangutils.utils.UtilConstants.PUT;
112import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
113import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530114import static org.onosproject.yangutils.utils.UtilConstants.QUOTE_STRING;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530115import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
116import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
117import static org.onosproject.yangutils.utils.UtilConstants.SET;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530118import static org.onosproject.yangutils.utils.UtilConstants.SET_VALUE_PARA;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530119import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
120import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
121import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
122import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
123import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
124import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530125import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER;
126import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER_VAR;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530127import static org.onosproject.yangutils.utils.UtilConstants.THIS;
128import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
Bharat saraswal94844d62016-10-13 13:28:03 +0530129import static org.onosproject.yangutils.utils.UtilConstants.TO_STRING_METHOD;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530130import static org.onosproject.yangutils.utils.UtilConstants.TRY;
131import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
132import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
133import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
134import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
135import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
136import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
137import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
138import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
139import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
140import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
Bharat saraswal94844d62016-10-13 13:28:03 +0530141import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530142import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
143import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
144import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
145
146/**
147 * Represents string generator for translator.
148 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530149public final class StringGenerator {
150
151 private StringGenerator() {
152 }
153
154 /**
155 * Returns compare to string.
156 *
157 * @return compare to string
158 */
159 static String getCompareToString() {
160 return PERIOD + COMPARE_TO;
161 }
162
163 /**
164 * Returns lesser than and equals condition.
165 *
166 * @return lesser than and equals condition
167 */
168 static String getLesserThanCondition() {
169 return SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE;
170 }
171
172 /**
173 * Returns greater than and equals condition.
174 *
175 * @return greater than and equals condition
176 */
177 static String getGreaterThanCondition() {
178 return SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE;
179 }
180
181 /**
182 * Returns && conditional string.
183 *
184 * @param cond1 condition one
185 * @param cond2 condition two
186 * @return && conditional string
187 */
188 static String ifAndAndCondition(String cond1, String cond2) {
189 return cond1 + SPACE + AND + AND + SPACE + cond2;
190 }
191
192 /**
193 * Returns equal equal conditional string.
194 *
195 * @param cond1 condition one
196 * @param cond2 condition two
197 * @return equal equal conditional string
198 */
199 static String ifEqualEqualCondition(String cond1, String cond2) {
200 return cond1 + SPACE + EQUAL + EQUAL + SPACE + cond2;
201 }
202
203 /**
204 * Returns new instance string.
205 *
206 * @param returnType return type
207 * @param varName variable name
208 * @param space spaces
209 * @param value value
210 * @return new instance string
211 */
212 static String getNewInstance(String returnType, String varName,
213 String space, String value) {
214 return space + returnType + SPACE + varName + SPACE + EQUAL + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530215 NEW + SPACE + returnType + brackets(
216 OPEN_CLOSE_BRACKET_WITH_VALUE, value, null) + signatureClose();
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530217 }
218
219 /**
220 * Returns return string.
221 *
222 * @param value value to be returned
223 * @param space spaces
224 * @return return string
225 */
226 static String getReturnString(String value, String space) {
227 return space + RETURN + SPACE + value;
228 }
229
230 /**
231 * Returns new line string with spaces.
232 *
233 * @param space spaces
234 * @return new line string with spaces
235 */
236 static String getNewLineAndSpace(String space) {
237 return NEW_LINE + space;
238 }
239
240 /**
241 * Returns method close string.
242 *
243 * @param type indentation type
244 * @return method close string
245 */
Bharat saraswal94844d62016-10-13 13:28:03 +0530246 public static String methodClose(IndentationType type) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530247 switch (type) {
248 case EIGHT_SPACE:
249 return EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
250 NEW_LINE;
251 case TWELVE_SPACE:
252 return TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
253 NEW_LINE;
254 case SIXTEEN_SPACE:
255 return SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
256 NEW_LINE;
257 case TWENTY_SPACE:
258 return TWENTY_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
259 NEW_LINE;
260 case TWENTY_EIGHT_SPACE:
261 return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
262 NEW_LINE;
263 case TWENTY_FOUR_SPACE:
264 return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
265 NEW_LINE;
266 default:
267 return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
268 NEW_LINE;
269 }
270 }
271
272 /**
273 * Returns body of the method.
274 *
275 * @param type type of method body
276 * @param paraName parameter name
277 * @param methodName method name
278 * @param space space to be given before body
279 * @param prefix prefix for internal method
280 * @param paramType parameter type
281 * @param isBuilderSetter is for builder setter
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530282 * @param setterVal value to set in setter
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530283 * @return body of the method
284 */
285 static String methodBody(MethodBodyTypes type, String paraName,
286 String methodName,
287 String space, String prefix,
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530288 String paramType, boolean isBuilderSetter, String setterVal) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530289 StringBuilder builder = new StringBuilder();
290 String body;
Bharat saraswal94844d62016-10-13 13:28:03 +0530291 String cond;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530292 switch (type) {
293 case GETTER:
294 return getReturnString(paraName, space);
295 case SETTER:
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530296 if (setterVal == null) {
297 setterVal = paraName;
298 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530299 body = space + THIS + PERIOD + paraName + SPACE + EQUAL + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530300 setterVal + signatureClose();
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530301 builder.append(body);
302 if (isBuilderSetter) {
303 body = getReturnString(THIS + signatureClose(), space);
304 builder.append(body);
305 }
306 return builder.toString();
307 case BUILD:
308 return getReturnString(
309 NEW + SPACE + paraName + brackets(
310 OPEN_CLOSE_BRACKET_WITH_VALUE, THIS, null) +
311 signatureClose(), space);
312 case CONSTRUCTOR:
313 return space + THIS + PERIOD + paraName + SPACE +
314 EQUAL + SPACE + BUILDER_LOWER_CASE + OBJECT + PERIOD +
315 prefix + methodName +
316 brackets(OPEN_CLOSE_BRACKET, null, null) +
317 signatureClose();
318 case DEFAULT_CONSTRUCTOR:
319 return EMPTY_STRING;
320 case ADD_TO_LIST:
321 return space + getIfConditionForAddToListMethod(paraName) +
322 space + paraName +
323 brackets(OPEN_CLOSE_BRACKET, null, null) + PERIOD +
324 ADD_STRING +
325 brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null) +
326 signatureClose() + getReturnString(
327 THIS + signatureClose(), space);
328 case AUGMENTED_MAP_ADD:
Bharat saraswal94844d62016-10-13 13:28:03 +0530329 return space + YANG_AUGMENTED_INFO_MAP +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530330 PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
331 OBJECT_STRING + COMMA + SPACE + VALUE +
332 CLOSE_PARENTHESIS + signatureClose();
333 case AUGMENTED_MAP_GET_VALUE:
334 return getReturnString(
Bharat saraswal94844d62016-10-13 13:28:03 +0530335 YANG_AUGMENTED_INFO_MAP + PERIOD + GET +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530336 brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, CLASS +
337 OBJECT_STRING, null) + signatureClose(),
338 space);
339 case AUGMENTED_MAP_GETTER:
Bharat saraswal94844d62016-10-13 13:28:03 +0530340 return getReturnString(YANG_AUGMENTED_INFO_MAP +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530341 signatureClose(), space);
342 case MANAGER_METHODS:
343 body = space + YANG_UTILS_TODO + NEW_LINE;
344 builder.append(body);
345 if (paramType != null) {
346 body = getReturnString(parseTypeForReturnValue(paramType),
347 space);
348 builder.append(body)
349 .append(signatureClose());
350 }
351 return builder.toString();
352 case OF_METHOD:
353 return getReturnString(
354 NEW + SPACE + paraName + brackets(
355 OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null)
356 + signatureClose(), space);
357 case TO_STRING:
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530358 return getToStringMethodsAddString(space, paraName) + paraName +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530359 CLOSE_PARENTHESIS;
360 case EQUALS_METHOD:
361 default:
362 return null;
363 }
364 }
365
366 /**
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530367 * Returns to string method's add string.
368 *
369 * @param space indentation
370 * @param paraName parameter name
371 * @return to string method's add string
372 */
373 static String getToStringMethodsAddString(String space, String paraName) {
374 return space + PERIOD + ADD_STRING + OPEN_PARENTHESIS +
375 getQuotedString(paraName) + COMMA + SPACE;
376 }
377
378 /**
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530379 * Returns end of line.
380 *
381 * @return end of line
382 */
383 static String signatureClose() {
384 return SEMI_COLON + NEW_LINE;
385 }
386
387 /**
388 * Returns method signature close for method class type.
389 *
390 * @param type method class type
391 * @return method signature close for method class type
392 */
393 static String methodSignatureClose(MethodClassTypes type) {
394 switch (type) {
395 case INTERFACE_TYPE:
396 return signatureClose();
397 case CLASS_TYPE:
398 return SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
399 default:
400 return null;
401 }
402 }
403
404 /**
405 * Returns method param.
406 *
407 * @param type type of param
408 * @param name name of param
409 * @return method param
410 */
411 private static String methodParam(String type, String name) {
412 return type + SPACE + name;
413 }
414
415 /**
416 * Returns comma followed by a space.
417 *
418 * @return comma followed by a space
419 */
420 private static String commaWithSpace() {
421 return COMMA + SPACE;
422 }
423
424 /**
425 * Returns bracket string for the given type.
426 *
427 * @param type bracket type
428 * @param value value to be added in brackets
429 * @param returnType returns type to be added for value
430 * @return bracket for the given type.
431 */
432 static String brackets(BracketType type, String value,
433 String returnType) {
434 String ret = EMPTY_STRING;
435 switch (type) {
436 case OPEN_CLOSE_BRACKET:
437 return OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
438 case OPEN_CLOSE_BRACKET_WITH_VALUE:
439 return OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS;
440 case OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE:
441 if (returnType != null) {
442 ret = returnType + SPACE;
443 }
444 return OPEN_PARENTHESIS + ret + value +
445 CLOSE_PARENTHESIS;
446 case OPEN_BRACKET_WITH_VALUE:
447 ret = EMPTY_STRING;
448 if (returnType != null) {
449 ret = returnType + SPACE;
450 }
451 return OPEN_PARENTHESIS + ret + value +
452 COMMA;
453 case CLOSE_BRACKET_WITH_VALUE:
454 ret = EMPTY_STRING;
455 if (returnType != null) {
456 ret = returnType + SPACE;
457 }
458 return SPACE + ret + value +
459 CLOSE_PARENTHESIS;
460 case OPEN_CLOSE_DIAMOND:
461 return DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET;
462 case OPEN_CLOSE_DIAMOND_WITH_VALUE:
463 return DIAMOND_OPEN_BRACKET + value + DIAMOND_CLOSE_BRACKET;
464 default:
465 return null;
466 }
467 }
468
469 /**
470 * Returns method signature for multi attribute methods.
471 *
472 * @param methodName method name
473 * @param prefix prefix for method
474 * @param modifier modifier for method
475 * @param methodReturnType method's return type
476 * @param params parameters
477 * @param type type of method
478 * @return method signature for multi attribute methods
479 */
480 static String multiAttrMethodSignature(String methodName, String
481 prefix, String modifier, String methodReturnType,
482 Map<String, String> params,
483 MethodClassTypes type) {
484 StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
485 String method = EMPTY_STRING;
486 if (modifier != null) {
487 method = modifier + SPACE;
488 }
489 methodBuilder.append(method);
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530490 if (prefix == null) {
491 prefix = EMPTY_STRING;
492 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530493 if (methodReturnType != null) {
494 method = methodReturnType + SPACE + prefix + methodName;
495 } else {
496 method = prefix + methodName;
497 }
498 //Append method beginning.
499 methodBuilder.append(method)
500 .append(OPEN_PARENTHESIS);
501 for (Map.Entry<String, String> param : params.entrySet()) {
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530502 methodBuilder.append(methodParam(param.getValue(), param.getKey()));
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530503 methodBuilder.append(commaWithSpace());
504 }
505 String para = methodBuilder.toString();
506 String[] array = {SPACE, COMMA};
507 para = trimAtLast(para, array);
508 methodBuilder = new StringBuilder(para)
509 .append(CLOSE_PARENTHESIS)
510 .append(methodSignatureClose(type));
511
512 return methodBuilder.toString();
513 }
514
515 /**
516 * Returns method signature for interface and implementation classes.
517 *
518 * @param methodName name of the method
519 * @param prefix prefix which needs to be added for method
520 * @param modifier modifier which needs to be added for method
521 * @param paraVal value which needs to be added as parameter
522 * @param methodReturnType returns type to be added for method
523 * @param paraReturnType return type to be added for parameter
524 * @param type method class type
525 * @return method signature for interface and implementation classes
526 */
527 static String methodSignature(
528 String methodName, String prefix, String modifier, String paraVal,
529 String methodReturnType, String paraReturnType,
530 MethodClassTypes type) {
531 StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
532 String method = EMPTY_STRING;
533 if (modifier != null) {
534 method = modifier + SPACE;
535 }
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530536 if (prefix == null) {
537 prefix = EMPTY_STRING;
538 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530539 methodBuilder.append(method);
540 if (methodReturnType != null) {
541 method = methodReturnType + SPACE + prefix + methodName;
542 } else {
543 method = prefix + methodName;
544 }
545 //Append method beginning.
546 methodBuilder.append(method);
547
548 if (paraVal != null) {
549 methodBuilder.append(brackets(
550 OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE,
551 paraVal, paraReturnType));
552 } else {
553 methodBuilder.append(brackets(OPEN_CLOSE_BRACKET, null,
554 null));
555 }
556
557 methodBuilder.append(methodSignatureClose(type));
558
559 return methodBuilder.toString();
560 }
561
562 /**
563 * Returns list attribute.
564 *
565 * @param attrType attribute type
566 * @param compilerAnnotation compiler annotations
567 * @return list attribute
568 */
569
570 static String getListAttribute(String attrType,
571 YangCompilerAnnotation compilerAnnotation) {
572 String listAttr;
573 if (compilerAnnotation != null &&
574 compilerAnnotation.getYangAppDataStructure() != null) {
575 switch (compilerAnnotation.getYangAppDataStructure()
576 .getDataStructure()) {
577 case QUEUE: {
578 listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
579 DIAMOND_CLOSE_BRACKET;
580 break;
581 }
582 case SET: {
583 listAttr = SET + DIAMOND_OPEN_BRACKET + attrType +
584 DIAMOND_CLOSE_BRACKET;
585 break;
586 }
587 case LIST: {
588 listAttr = getListString() + attrType +
589 DIAMOND_CLOSE_BRACKET;
590 break;
591 }
592 default: {
593 listAttr = getListString() + attrType +
594 DIAMOND_CLOSE_BRACKET;
595 }
596 }
597 } else {
598 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
599 }
600 return listAttr;
601 }
602
603 /**
604 * Returns getters for value and select leaf.
605 *
606 * @return getters for value and select leaf
607 */
Bharat saraswal94844d62016-10-13 13:28:03 +0530608 static String getIsValueLeafSet() {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530609 return "\n" +
610 " @Override\n" +
611 " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
Bharat saraswal94844d62016-10-13 13:28:03 +0530612 " return valueLeafFlags.get(leaf.getLeafIndex());\n" +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530613 " }\n" +
Bharat saraswal94844d62016-10-13 13:28:03 +0530614 "\n";
615 }
616
617 /**
618 * Returns is select leaf set.
619 *
620 * @return is select leaf set
621 */
622 static String getIsSelectLeafSet() {
623 return " @Override\n" +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530624 " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
Bharat saraswal94844d62016-10-13 13:28:03 +0530625 " return selectLeafFlags.get(leaf.getLeafIndex());\n" +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530626 " }\n";
627 }
628
629 /**
630 * Returns getter methods for operation attributes.
631 *
632 * @return getter methods for operation attributes
633 */
Bharat saraswal94844d62016-10-13 13:28:03 +0530634 static String getValueLeafGetters() {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530635 return "\n" +
636 " /**\n" +
637 " * Returns the valueLeafFlags.\n" +
638 " *\n" +
639 " * @return value of valueLeafFlags\n" +
640 " */\n" +
641 " public BitSet getValueLeafFlags() {\n" +
642 " return valueLeafFlags;\n" +
643 " }\n" +
Bharat saraswal94844d62016-10-13 13:28:03 +0530644 "\n";
645 }
646
647 /**
648 * Returns getter methods for operation attributes.
649 *
650 * @return getter methods for operation attributes
651 */
652 static String getSelectLeafGetters() {
653 return " /**\n" +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530654 " * Returns the selectLeafFlags.\n" +
655 " *\n" +
656 " * @return value of selectLeafFlags\n" +
657 " */\n" +
658 " public BitSet getSelectLeafFlags() {\n" +
659 " return selectLeafFlags;\n" +
660 " }\n" +
661 "\n";
662 }
663
664 /**
665 * Returns interface leaf identifier enum method.
666 *
667 * @return interface leaf identifier enum method
668 */
669 static String getInterfaceLeafIdEnumMethods() {
670 return "\n\n private int leafIndex;\n" +
671 "\n" +
672 " public int getLeafIndex() {\n" +
673 " return leafIndex;\n" +
674 " }\n" +
675 "\n" +
676 " LeafIdentifier(int value) {\n" +
677 " this.leafIndex = value;\n" +
678 " }\n" +
679 " }\n";
680 }
681
682 /**
683 * Returns if condition string for typedef constructor.
684 *
685 * @param type type of conflict
686 * @param addFirst true int/long need to be added first
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530687 * @param val value to set
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530688 * @return if condition string for typedef constructor
689 */
690 static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type,
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530691 boolean addFirst, String val) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530692 String condition =
693 EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
694 VALIDATE_RANGE + OPEN_PARENTHESIS;
695
696 switch (type) {
697 case INT_TYPE_CONFLICT:
698 if (addFirst) {
699 condition = condition + INT_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530700 INT_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530701 } else {
702 condition = condition + UINT_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530703 UINT_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530704 }
705 break;
706 case LONG_TYPE_CONFLICT:
707 if (addFirst) {
708 condition = condition + LONG_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530709 LONG_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530710 } else {
711 condition = condition + ULONG_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530712 ULONG_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530713 }
714 break;
715 case SHORT_TYPE_CONFLICT:
716 if (addFirst) {
717 condition = condition + SHORT_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530718 SHORT_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530719 } else {
720 condition = condition + UINT8_MIN_RANGE + COMMA + SPACE +
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530721 UINT8_MAX_RANGE + COMMA + SPACE + val;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530722 }
723 break;
724 default:
725 return null;
726 }
727
728 return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
729 OPEN_CURLY_BRACKET + NEW_LINE;
730 }
731
732 /**
733 * Returns from string method parsed string.
734 *
735 * @param targetDataType target data type
736 * @param yangType YANG type
737 * @return parsed string
738 */
739 static String getParseFromStringMethod(String targetDataType,
740 YangType<?> yangType) {
741 YangDataTypes type = yangType.getDataType();
742
743 switch (type) {
744 case INT8:
745 return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
746 case INT16:
747 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
748 case INT32:
749 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
750 case INT64:
751 return LONG_WRAPPER + PERIOD + PARSE_LONG;
752 case UINT8:
753 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
754 case UINT16:
755 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
756 case UINT32:
757 return LONG_WRAPPER + PERIOD + PARSE_LONG;
758 case UINT64:
759 return NEW + SPACE + BIG_INTEGER;
760 case DECIMAL64:
761 return NEW + SPACE + BIG_DECIMAL;
762 case STRING:
763 case IDENTITYREF:
764 return EMPTY_STRING;
765 case EMPTY:
766 case BOOLEAN:
767 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530768 case ENUMERATION:
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530769 return targetDataType + PERIOD + OF;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530770 case DERIVED:
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530771 case UNION:
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530772 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
773 default:
774 throw new TranslatorException("given data type is not " +
775 "supported. " +
776 yangType.getDataTypeName() +
777 " in " +
778 yangType.getLineNumber() +
779 " at " +
780 yangType.getCharPosition() +
781 " in " +
782 yangType.getFileName());
783 }
784 }
785
786 /**
787 * Returns sub string with catch statement for union's from string method.
788 *
789 * @return sub string with catch statement for union's from string method
790 */
791 static String getCatchSubString() {
792 return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE +
793 brackets(OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE, EXCEPTION_VAR,
794 EXCEPTION) + SPACE + OPEN_CURLY_BRACKET;
795 }
796
797 /**
798 * Returns sub string with return statement for union's from string method.
799 *
800 * @return sub string with return statement for union's from string method
801 */
802 static String getReturnOfSubString() {
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530803 return getReturnString(OF, TWELVE_SPACE_INDENTATION) +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530804 brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, TMP_VAL, null) +
805 signatureClose();
806 }
807
808 /**
809 * Returns sub string with try statement for union's from string method.
810 *
811 * @return sub string with try statement for union's from string method
812 */
813 static String getTrySubString() {
814 return TRY + SPACE + OPEN_CURLY_BRACKET;
815 }
816
817 /*
818 * Returns omit null value string.
819 *
820 * @return omit null value string
821 */
822 static String getOmitNullValueString() {
823 return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING +
824 NEW_LINE;
825 }
826
827 /**
828 * Returns collection's iterator method.
829 *
830 * @param indentation indentation
831 * @param loopVar loop variable
832 * @param collection collection
833 * @return collection's iterator method
834 */
835 static String getCollectionIteratorForLoopBegin(String indentation,
836 String loopVar,
837 String collection) {
838 return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE +
839 COLON + SPACE + collection + CLOSE_PARENTHESIS + SPACE +
840 OPEN_CURLY_BRACKET + NEW_LINE;
841 }
842
843 /**
844 * Returns if else condition's signature.
845 *
846 * @param indentation indentation
847 * @param condition conditions
848 * @return if else condition's signature
849 */
850 static String getElseIfConditionBegin(String indentation,
851 String condition) {
852 return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
853 getIfConditionBegin(EMPTY_STRING, condition);
854 }
855
856 /**
857 * Returns if condition's signature.
858 *
859 * @param indentation indentation
860 * @param condition conditions
861 * @return if condition's signature
862 */
863 static String getIfConditionBegin(String indentation, String condition) {
864 return indentation + IF + SPACE + brackets(
865 OPEN_CLOSE_BRACKET_WITH_VALUE, condition, EMPTY_STRING) +
866 methodSignatureClose(CLASS_TYPE);
867 }
868
869 /**
870 * Returns whether the data type is of primitive data type.
871 *
872 * @param dataType data type to be checked
873 * @return true, if data type can have primitive data type, false otherwise
874 */
875 static boolean isPrimitiveDataType(YangDataTypes dataType) {
876 return dataType == INT8 ||
877 dataType == INT16 ||
878 dataType == INT32 ||
879 dataType == INT64 ||
880 dataType == UINT8 ||
881 dataType == UINT16 ||
882 dataType == UINT32 ||
883 dataType == UINT64 ||
884 dataType == DECIMAL64 ||
885 dataType == BOOLEAN ||
886 dataType == EMPTY;
887 }
888
889 /**
890 * Returns list string.
891 *
892 * @return list string
893 */
894 private static String getListString() {
895 return LIST + DIAMOND_OPEN_BRACKET;
896 }
897
898 /**
899 * Returns override string.
900 *
901 * @return override string
902 */
903 public static String getOverRideString() {
904 return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
905 }
906
907 /**
908 * Returns value leaf flag setter.
909 *
910 * @param name name of leaf
911 * @return value leaf flag setter
912 */
913 static String getValueLeafSetString(String name) {
Bharat saraswal94844d62016-10-13 13:28:03 +0530914 return " valueLeafFlags.set(LeafIdentifier." +
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530915 name.toUpperCase() + ".getLeafIndex());\n";
916 }
917
918 /*Provides string to return for type.*/
919 private static String parseTypeForReturnValue(String type) {
920 switch (type) {
921 case BYTE:
922 case INT:
923 case SHORT:
924 case LONG:
925 case DOUBLE:
926 return ZERO;
927 case BOOLEAN_DATA_TYPE:
928 return FALSE;
929 default:
930 return null;
931 }
932 }
933
934 /**
935 * Returns check not null string.
936 *
937 * @param name attribute name
938 * @return check not null string
939 */
940 static String getCheckNotNull(String name) {
941 return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING +
942 OPEN_PARENTHESIS + name + COMMA + SPACE + name +
943 CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
944 }
945
946 /**
947 * Returns definition close string.
948 *
949 * @return definition close string
950 */
951 private static String defCloseString() {
Bharat saraswal94844d62016-10-13 13:28:03 +0530952 return SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530953 }
954
955 /**
956 * Returns default class definition for java file when extends a
957 * interface.
958 *
959 * @param classType class type
960 * @param name name of class
961 * @param modifier modifier for class
962 * @param extend extends class name
963 * @return class definition
964 */
965 static String getDefaultDefinitionWithExtends(String classType,
966 String name, String
967 modifier,
968 String extend) {
969 String mod = EMPTY_STRING;
970 if (modifier != null) {
971 mod = modifier + SPACE;
972 }
973 return mod + classType + SPACE + name + SPACE + EXTEND + SPACE
974 + extend + defCloseString();
975 }
976
977 /**
978 * Returns default class definition for java file when implements a
979 * interface.
980 *
981 * @param classType class type
982 * @param name name of class
983 * @param modifier modifier for class
984 * @param impl implements class name
985 * @return class definition
986 */
987 static String getDefaultDefinitionWithImpl(String classType,
988 String name, String
989 modifier,
990 String impl) {
991 String mod = EMPTY_STRING;
992 if (modifier != null) {
993 mod = modifier + SPACE;
994 }
995 return mod + classType + SPACE + name + SPACE + IMPLEMENTS +
996 SPACE + impl + defCloseString();
997 }
998
999 /**
1000 * Returns default class definition for java file.
1001 *
1002 * @param classType class type
1003 * @param name name of class
1004 * @param modifier modifier for class
1005 * @return class definition
1006 */
1007 static String getDefaultDefinition(String classType,
1008 String name, String modifier) {
1009 String mod = EMPTY_STRING;
1010 if (modifier != null) {
1011 mod = modifier + SPACE;
1012 }
1013 return mod + classType + SPACE + name + defCloseString();
1014 }
1015
1016 /**
1017 * Returns string for service class.
1018 *
1019 * @param name1 name of even listener class
1020 * @param name2 name of even class
1021 * @return listener service string for service class
1022 */
1023 static String getEventExtendsString(String name1, String type,
1024 String name2) {
1025 StringBuilder builder = new StringBuilder();
1026 builder.append(type).append(DIAMOND_OPEN_BRACKET).append(name1)
1027 .append(COMMA).append(SPACE).append(name2).append
1028 (DIAMOND_CLOSE_BRACKET);
1029 return builder.toString();
1030 }
1031
1032 /**
1033 * Returns import string.
1034 *
1035 * @param pkg package
1036 * @param cls class
1037 * @return import string
1038 */
1039 public static String getImportString(String pkg, String cls) {
1040 StringBuilder builder = new StringBuilder()
1041 .append(IMPORT).append(pkg).append(PERIOD).append(cls)
1042 .append(signatureClose());
1043 return builder.toString();
1044 }
1045
1046 /**
1047 * Returns static modifier string.
1048 *
1049 * @param modifier modifier
1050 * @return static modifier string
1051 */
1052 static String getSpecificModifier(String modifier, String keyWord) {
1053 return new StringBuilder(modifier).append(SPACE).append(keyWord)
1054 .toString();
1055 }
1056
1057 /**
1058 * Returns builder string for class definition.
1059 *
1060 * @param yangName class name
1061 * @return builder string for class definition
1062 */
1063 static String getBuilderImplStringClassDef(String yangName) {
1064 return new StringBuilder(yangName).append(PERIOD).append(yangName)
1065 .append(BUILDER).toString();
1066 }
1067
1068 /**
1069 * Returns default name string.
1070 *
1071 * @param yangName class name
1072 * @return default name string
1073 */
1074 static String getDefaultName(String yangName) {
1075 return new StringBuilder(DEFAULT_CAPS).append(yangName).toString();
1076 }
1077
1078 /**
1079 * Returns suffixed name string.
1080 *
1081 * @param yangName class name
1082 * @param suffix suffix to append to name
1083 * @return suffixed name string
1084 */
1085 static String getSuffixedName(String yangName, String suffix) {
1086 return new StringBuilder(yangName).append(suffix).toString();
1087 }
1088
1089 /**
1090 * Returns error msg string.
1091 *
1092 * @param msg message
1093 * @param name name of node
1094 * @param line line number
1095 * @param position char position
1096 * @param fileName file name
1097 * @return error message string
1098 */
1099 static String getErrorMsg(String msg, String name, int line, int position,
1100 String fileName) {
1101 return new StringBuilder().append(msg).append(name).append(IN)
1102 .append(line).append(AT).append(position).append(IN)
1103 .append(fileName).toString();
1104 }
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301105
1106 /**
1107 * Returns string builder attribute string;
1108 *
1109 * @param init first param to be appended to string builder
1110 * @param space indentation space
1111 * @return string builder attribute
1112 */
1113 static String getStringBuilderAttr(String init, String space) {
1114 StringBuilder builder = new StringBuilder(space);
1115 builder.append(STRING_BUILDER).append(SPACE).append(STRING_BUILDER_VAR)
1116 .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
1117 .append(SPACE).append(STRING_BUILDER).append(
1118 brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, getQuotedString(init), null))
1119 .append(signatureClose());
1120 return builder.toString();
1121 }
1122
1123 /**
1124 * Returns quoted string.
1125 *
1126 * @param name name to be quoted
1127 * @return quoted string
1128 */
1129 static String getQuotedString(String name) {
1130 return QUOTES + name + QUOTES;
1131 }
1132
1133 /**
1134 * Returns string builder's append string.
1135 *
1136 * @param append data to be append
1137 * @param space indentation
1138 * @return string builder's append string
1139 */
1140 static String getStringBuilderAppendString(String append, String space) {
1141 return space + STRING_BUILDER_VAR + PERIOD + APPEND + OPEN_PARENTHESIS +
1142 append + CLOSE_PARENTHESIS + signatureClose();
1143 }
1144
1145 /**
1146 * Returns pattern quote string.
1147 *
1148 * @param type type for pattern is needed
1149 * @return pattern quote string
1150 */
1151 static String getPatternQuoteString(String type) {
1152 return PATTERN + PERIOD + QUOTE_STRING + brackets(
1153 OPEN_CLOSE_BRACKET_WITH_VALUE, getQuotedString(type), null);
1154 }
1155
1156 /**
1157 * Returns bitset attribute.
1158 *
1159 * @param indentation indentation
1160 * @return bitset attribute
1161 */
1162 static String getBitSetAttr(String indentation) {
1163 StringBuilder builder = new StringBuilder(indentation);
1164 return builder.append(BITSET).append(SPACE).append(TMP_VAL)
1165 .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
1166 .append(SPACE).append(BITSET).append(OPEN_CLOSE_BRACKET_STRING)
1167 .append(signatureClose()).toString();
1168 }
1169
1170 /**
1171 * Returns for loop string
1172 *
1173 * @param space indentation
1174 * @param type data type
1175 * @param var variable
1176 * @param data data variable/collection
1177 * @return for loop string
1178 */
1179 static String getForLoopString(String space, String type, String var,
1180 String data) {
1181 return space + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE + var +
1182 SPACE + COLON + SPACE + data + CLOSE_PARENTHESIS +
1183 methodSignatureClose(CLASS_TYPE);
1184 }
1185
1186 /**
1187 * Returns set value parameter's get string for union to string method.
1188 *
1189 * @param count count of type
1190 * @return get string
1191 */
1192 static String getSetValueParaCondition(int count) {
1193 return SET_VALUE_PARA + PERIOD + GET + brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
1194 count + EMPTY_STRING, null);
1195 }
1196
1197 /**
1198 * Returns more object attr for union to string method.
1199 *
Bharat saraswal94844d62016-10-13 13:28:03 +05301200 * @param name name of generate class
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301201 * @return more object attr for union to string method
1202 */
Bharat saraswal94844d62016-10-13 13:28:03 +05301203 static String getMoreObjectAttr(String name) {
1204 String cls = name + PERIOD + CLASS;
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301205 StringBuilder attr = new StringBuilder(EIGHT_SPACE_INDENTATION);
1206 String[] array = {NEW_LINE};
Bharat saraswal94844d62016-10-13 13:28:03 +05301207 attr.append(MORE_OBJ_ATTR).append(GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING)
1208 .append(brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, cls, null))
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301209 .append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(trimAtLast(
1210 getOmitNullValueString(), array)).append(signatureClose());
1211 return attr.toString();
1212 }
Bharat saraswal94844d62016-10-13 13:28:03 +05301213
1214 /**
1215 * Returns to string call.
1216 *
1217 * @param name name of attribute
1218 * @return to string call for attribute
1219 */
1220 static String getToStringCall(String name) {
1221 return name + PERIOD +
1222 TO_STRING_METHOD + OPEN_CLOSE_BRACKET_STRING;
1223 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301224}