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