Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 19 | import java.util.List; |
| 20 | import java.util.Map; |
Gaurav Agrawal | a8391d0 | 2016-06-30 13:28:14 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 27 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE; |
| 31 | import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 32 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
| 33 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 34 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.utils.UtilConstants.CASE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.utils.UtilConstants.CLEAR; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.utils.UtilConstants.COLAN; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE; |
| 52 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
| 55 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
| 56 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
| 57 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 58 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
| 59 | import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION; |
| 61 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; |
| 65 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; |
| 67 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; |
| 68 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; |
| 69 | import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING; |
| 70 | import static org.onosproject.yangutils.utils.UtilConstants.IF; |
| 71 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 72 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; |
| 73 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 77 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
| 79 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 80 | import static org.onosproject.yangutils.utils.UtilConstants.NULL; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.utils.UtilConstants.OBJ; |
| 82 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
| 83 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; |
| 84 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 85 | import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 86 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
| 87 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
| 88 | import static org.onosproject.yangutils.utils.UtilConstants.OTHER; |
| 89 | import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 90 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN; |
| 91 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; |
| 92 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; |
| 93 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; |
| 94 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 96 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
| 97 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
| 98 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 99 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 101 | import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 102 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 104 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; |
| 105 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 106 | import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 107 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 109 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 110 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 111 | import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 113 | import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 114 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
| 115 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 116 | import static org.onosproject.yangutils.utils.UtilConstants.TRY; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 117 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; |
| 118 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
| 119 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 120 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 121 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
| 122 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
| 123 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 124 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 125 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 126 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 127 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 128 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 129 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 130 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
| 131 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 132 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 133 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 134 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 135 | |
| 136 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 137 | * Represents generator for methods of generated files based on the file type. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 138 | */ |
| 139 | public final class MethodsGenerator { |
| 140 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 141 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 142 | * Creates an instance of method generator. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 143 | */ |
| 144 | private MethodsGenerator() { |
| 145 | } |
| 146 | |
| 147 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 148 | * Returns the methods strings for builder interface. |
| 149 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 150 | * @param name attribute name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 151 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 152 | * @return method string for builder interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 153 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 154 | public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) { |
| 155 | return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns getter string. |
| 160 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 161 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 162 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 163 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 164 | * @return getter string |
| 165 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 166 | public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 167 | YangPluginConfig pluginConfig) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 168 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 169 | String returnType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 170 | String attributeName = attr.getAttributeName(); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 171 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 172 | return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 173 | + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Returns setter string. |
| 178 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 179 | * @param attr attribute info |
| 180 | * @param className java class name |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 181 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 182 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 183 | * @return setter string |
| 184 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 185 | public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 186 | YangPluginConfig pluginConfig) { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 187 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 188 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 189 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 190 | JavaDocGen.JavaDocType type; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 191 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 192 | type = MANAGER_SETTER_METHOD; |
| 193 | } else { |
| 194 | type = SETTER_METHOD; |
| 195 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 196 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 197 | return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 198 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Returns constructor method string. |
| 203 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 204 | * @param name class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 205 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 206 | * @return constructor string |
| 207 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 208 | public static String getConstructorString(String name, YangPluginConfig pluginConfig) { |
| 209 | return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Returns default constructor method string. |
| 214 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 215 | * @param name class name |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 216 | * @param modifierType modifier type |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 217 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 218 | * @return default constructor string |
| 219 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 220 | public static String getDefaultConstructorString(String name, String modifierType, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 221 | YangPluginConfig pluginConfig) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 222 | return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig) |
| 223 | + getDefaultConstructor(name, modifierType) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 224 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns check not null string. |
| 229 | * |
| 230 | * @param name attribute name |
| 231 | * @return check not null string |
| 232 | */ |
| 233 | public static String getCheckNotNull(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 234 | return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name |
| 235 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Returns build method string. |
| 240 | * |
| 241 | * @param name class name |
| 242 | * @return build string |
| 243 | */ |
| 244 | public static String getBuildString(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 245 | return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Returns the getter method strings for class file. |
| 250 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 251 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 252 | * @param generatedJavaFiles for the type of java file being generated |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 253 | * @return getter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 254 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 255 | public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 256 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 257 | String attrQuaifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 258 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 259 | |
| 260 | if (!attr.isListAttr()) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 261 | return getGetter(attrQuaifiedType, attributeName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 262 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 263 | String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 264 | return getGetter(listAttr, attributeName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Returns getter for attribute. |
| 269 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 270 | * @param type return type |
| 271 | * @param name attribute name |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 272 | * @param generatedJavaFiles generated java files |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 273 | * @return getter for attribute |
| 274 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 275 | public static String getGetter(String type, String name, int generatedJavaFiles) { |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 276 | String ret = parseTypeForReturnValue(type); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 277 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 278 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 279 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
| 280 | EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION + |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 281 | RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 282 | } else { |
| 283 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name |
| 284 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
| 285 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 286 | + CLOSE_CURLY_BRACKET; |
| 287 | } |
| 288 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 289 | } |
| 290 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 291 | /*Provides string to return for type.*/ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 292 | private static String parseTypeForReturnValue(String type) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 293 | switch (type) { |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 294 | case BYTE: |
| 295 | case INT: |
| 296 | case SHORT: |
| 297 | case LONG: |
| 298 | return "0"; |
| 299 | case BOOLEAN_DATA_TYPE: |
| 300 | return FALSE; |
| 301 | default: |
| 302 | return null; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 306 | /** |
| 307 | * Returns the setter method strings for class file. |
| 308 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 309 | * @param attr attribute info |
| 310 | * @param className name of the class |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 311 | * @param generatedJavaFiles generated java files |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 312 | * @return setter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 313 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 314 | public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 315 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 316 | String attrQuaifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 317 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 318 | if (!attr.isListAttr()) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 319 | return getSetter(className, attributeName, attrQuaifiedType, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 320 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 321 | String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 322 | return getSetter(className, attributeName, listAttr, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Returns setter for attribute. |
| 327 | * |
| 328 | * @param className class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 329 | * @param name attribute name |
| 330 | * @param type return type |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 331 | * @return setter for attribute |
| 332 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 333 | private static String getSetter(String className, String name, String type, int generatedJavaFiles) { |
| 334 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 335 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 336 | + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE + |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 337 | OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + |
| 338 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 339 | } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) { |
| 340 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE |
| 341 | + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 342 | + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE |
| 343 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 344 | } else { |
| 345 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + |
| 346 | name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 347 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE |
| 348 | + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE |
| 349 | + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 350 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 354 | * Returns the setter method strings for class file. |
| 355 | * |
| 356 | * @param attr attribute info |
| 357 | * @return setter method for class |
| 358 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 359 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 360 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 361 | String attrQuaifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 362 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 363 | return getTypeDefSetter(attrQuaifiedType, attributeName); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Returns type def's setter for attribute. |
| 368 | * |
| 369 | * @param type data type |
| 370 | * @param name attribute name |
| 371 | * @return setter for type def's attribute |
| 372 | */ |
| 373 | private static String getTypeDefSetter(String type, String name) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 374 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name) |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 375 | + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 376 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE |
| 377 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Returns override string. |
| 382 | * |
| 383 | * @return override string |
| 384 | */ |
| 385 | public static String getOverRideString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 386 | return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 390 | * Returns the getter method strings for interface file. |
| 391 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 392 | * @param yangName name of the attribute |
| 393 | * @param returnType return type of attribute |
| 394 | * @param isList is list attribute |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 395 | * @param generatedJavaFiles generated java files |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 396 | * @return getter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 397 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 398 | public static String getGetterForInterface(String yangName, String returnType, boolean isList, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 399 | int generatedJavaFiles) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 400 | |
| 401 | if (!isList) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 402 | return getGetterInterfaceString(returnType, yangName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 403 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 404 | String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 405 | return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /** |
| 409 | * Returns getter for attribute in interface. |
| 410 | * |
| 411 | * @param returnType return type |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 412 | * @param yangName attribute name |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 413 | * @return getter for interface |
| 414 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 415 | private static String getGetterInterfaceString(String returnType, String yangName, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 416 | int generatedJavaFiles) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 417 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 418 | return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 419 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 420 | } else { |
| 421 | return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName |
| 422 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 423 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Returns the setter method strings for interface file. |
| 428 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 429 | * @param attrName name of the attribute |
| 430 | * @param attrType return type of attribute |
| 431 | * @param className name of the java class being generated |
| 432 | * @param isList is list attribute |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 433 | * @param generatedJavaFiles generated java files |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 434 | * @return setter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 435 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 436 | public static String getSetterForInterface(String attrName, String attrType, String className, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 437 | boolean isList, int generatedJavaFiles) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 438 | |
| 439 | if (!isList) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 440 | return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 441 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 442 | String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 443 | return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Returns setter string for interface. |
| 448 | * |
| 449 | * @param className class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 450 | * @param attrName attribute name |
| 451 | * @param attrType attribute type |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 452 | * @return setter string |
| 453 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 454 | private static String getSetterInterfaceString(String className, String attrName, String attrType, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 455 | int generatedJavaFiles) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 456 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 457 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 458 | return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 459 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 460 | } else { |
| 461 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName |
| 462 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 463 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 467 | * Returns list string. |
| 468 | * |
| 469 | * @return list string |
| 470 | */ |
| 471 | private static String getListString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 472 | return LIST + DIAMOND_OPEN_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 476 | * Returns return type for attribute. |
| 477 | * |
| 478 | * @param attr attribute info |
| 479 | * @return return type |
| 480 | */ |
| 481 | private static String getReturnType(JavaAttributeInfo attr) { |
| 482 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 483 | String returnType = EMPTY_STRING; |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 484 | if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 485 | returnType = attr.getImportInfo().getPkgInfo() + PERIOD; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 486 | } |
| 487 | returnType = returnType + attr.getImportInfo().getClassInfo(); |
| 488 | return returnType; |
| 489 | } |
| 490 | |
| 491 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 492 | * Returns the build method strings for interface file. |
| 493 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 494 | * @param yangName name of the interface |
| 495 | * @return build method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 496 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 497 | public static String getBuildForInterface(String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 498 | return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
| 499 | + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 503 | * Returns constructor string for impl class. |
| 504 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 505 | * @param yangName class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 506 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 507 | * @return constructor string |
| 508 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 509 | public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 510 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 511 | String javadoc = getConstructorString(yangName, pluginConfig); |
| 512 | String constructor = |
| 513 | FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName |
| 514 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE |
| 515 | + OPEN_CURLY_BRACKET |
| 516 | + NEW_LINE; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 517 | return javadoc + constructor; |
| 518 | } |
| 519 | |
| 520 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 521 | * Returns the constructor strings for class file. |
| 522 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 523 | * @param yangName name of the class |
| 524 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 525 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 526 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 527 | * @return constructor for class |
| 528 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 529 | public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 530 | YangPluginConfig pluginConfig) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 531 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 532 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 533 | String constructor; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 534 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 535 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 536 | constructor = |
| 537 | EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 538 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL |
| 539 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
| 540 | + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver())) |
| 541 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 542 | } else { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 543 | constructor = |
| 544 | EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 545 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL |
| 546 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD |
| 547 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + |
| 548 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 549 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 550 | return constructor; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 554 | * Returns the rpc strings for service interface. |
| 555 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 556 | * @param rpcName name of the rpc |
| 557 | * @param inputName name of input |
| 558 | * @param outputName name of output |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 559 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 560 | * @return rpc method string |
| 561 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 562 | public static String getRpcServiceMethod(String rpcName, String inputName, String outputName, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 563 | YangPluginConfig pluginConfig) { |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 564 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 565 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 566 | if (!inputName.equals(EMPTY_STRING)) { |
| 567 | inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 568 | } |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 569 | return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName |
| 570 | + CLOSE_PARENTHESIS + SEMI_COLAN; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 574 | * Returns the rpc strings for manager impl. |
| 575 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 576 | * @param rpcName name of the rpc |
| 577 | * @param inputName name of input |
| 578 | * @param outputName name of output |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 579 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 580 | * @return rpc method string |
| 581 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 582 | public static String getRpcManagerMethod(String rpcName, String inputName, String outputName, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 583 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 584 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 585 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 586 | if (!inputName.equals(EMPTY_STRING)) { |
| 587 | inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 588 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 589 | |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 590 | String method = |
| 591 | getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName |
| 592 | + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE |
| 593 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 594 | if (!outputName.contentEquals(VOID)) { |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 595 | method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN |
| 596 | + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 597 | } |
| 598 | method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 599 | |
| 600 | return method; |
| 601 | } |
| 602 | |
| 603 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 604 | * Returns the build method strings for class file. |
| 605 | * |
| 606 | * @param yangName class name |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 607 | * @return build method string for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 608 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 609 | public static String getBuild(String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 610 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 611 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE |
| 612 | + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
| 613 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Returns the Default constructor strings for class file. |
| 618 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 619 | * @param name name of the class |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 620 | * @param modifierType modifier type for default constructor |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 621 | * @return Default constructor for class |
| 622 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 623 | private static String getDefaultConstructor(String name, String modifierType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 624 | return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE |
| 625 | + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 626 | } |
| 627 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 628 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 629 | * Returns to string method's open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 630 | * |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 631 | * @return string method's open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 632 | */ |
| 633 | public static String getToStringMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 634 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
| 635 | + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 636 | + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 640 | * Returns omit null value string. |
| 641 | * |
| 642 | * @return omit null value string |
| 643 | */ |
| 644 | public static String getOmitNullValueString() { |
| 645 | return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE; |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Returns to string method's close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 650 | * |
| 651 | * @return to string method close string |
| 652 | */ |
| 653 | public static String getToStringMethodClose() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 654 | return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 655 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 659 | * Returns to string method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 660 | * |
| 661 | * @param attr attribute info |
| 662 | * @return to string method |
| 663 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 664 | public static String getToStringMethod(JavaAttributeInfo attr) { |
| 665 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 666 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 667 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
| 668 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 672 | * Returns from string method's open string. |
| 673 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 674 | * @param className name of the class |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 675 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 676 | * @return from string method's open string |
| 677 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 678 | public static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) { |
| 679 | return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE |
| 680 | + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS |
| 681 | + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE |
| 682 | + OPEN_CURLY_BRACKET + NEW_LINE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Return from string method's close string. |
| 687 | * |
| 688 | * @return from string method's close string |
| 689 | */ |
| 690 | public static String getFromStringMethodClose() { |
| 691 | return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 692 | CLOSE_CURLY_BRACKET + NEW_LINE; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Return from string method's body string. |
| 697 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 698 | * @param attr attribute info |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 699 | * @param fromStringAttributeInfo attribute info for the from string |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 700 | * wrapper type |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 701 | * @return from string method's body string |
| 702 | */ |
| 703 | public static String getFromStringMethod(JavaAttributeInfo attr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 704 | JavaAttributeInfo fromStringAttributeInfo) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 705 | |
| 706 | return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION |
| 707 | + getParsedSubString(attr, fromStringAttributeInfo) + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION |
| 708 | + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString() |
| 709 | + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Returns sub string with try statement for union's from string method. |
| 714 | * |
| 715 | * @return sub string with try statement for union's from string method |
| 716 | */ |
| 717 | public static String getTrySubString() { |
| 718 | return TRY + SPACE + OPEN_CURLY_BRACKET; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Returns sub string with return statement for union's from string method. |
| 723 | * |
| 724 | * @return sub string with return statement for union's from string method |
| 725 | */ |
| 726 | public static String getReturnOfSubString() { |
| 727 | return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Returns sub string with catch statement for union's from string method. |
| 732 | * |
| 733 | * @return sub string with catch statement for union's from string method |
| 734 | */ |
| 735 | public static String getCatchSubString() { |
| 736 | return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR |
| 737 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET; |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * Returns sub string with parsed statement for union's from string method. |
| 742 | * |
| 743 | * @param attr attribute info |
| 744 | * @return sub string with parsed statement for union's from string method |
| 745 | */ |
| 746 | private static String getParsedSubString(JavaAttributeInfo attr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 747 | JavaAttributeInfo fromStringAttributeInfo) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 748 | |
| 749 | String targetDataType = getReturnType(attr); |
| 750 | String parseFromStringMethod = getParseFromStringMethod(targetDataType, |
| 751 | fromStringAttributeInfo.getAttributeType()); |
| 752 | return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod |
| 753 | + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; |
| 754 | } |
| 755 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 756 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 757 | * Returns hash code method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 758 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 759 | * @return hash code method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 760 | */ |
| 761 | public static String getHashCodeMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 762 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING |
| 763 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 764 | + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 768 | * Returns hash code methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 769 | * |
| 770 | * @param hashcodeString hash code string |
| 771 | * @return to hash code method close string |
| 772 | */ |
| 773 | public static String getHashCodeMethodClose(String hashcodeString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 774 | hashcodeString = trimAtLast(hashcodeString, COMMA); |
| 775 | hashcodeString = trimAtLast(hashcodeString, SPACE); |
| 776 | return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 777 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 781 | * Returns hash code method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 782 | * |
| 783 | * @param attr attribute info |
| 784 | * @return hash code method |
| 785 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 786 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 787 | return attr.getAttributeName() + COMMA + SPACE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 791 | * Returns equals method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 792 | * |
| 793 | * @param className class name |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 794 | * @return equals method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 795 | */ |
| 796 | public static String getEqualsMethodOpen(String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 797 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING |
| 798 | + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 799 | + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Returns equal methods if condition string. |
| 804 | * |
| 805 | * @return if condition string |
| 806 | */ |
| 807 | private static String getEqualsMethodsCommonIfCondition() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 808 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ |
| 809 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE |
| 810 | + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Returns if condition for specific class object in equals method. |
| 815 | * |
| 816 | * @param className class name |
| 817 | * @return if condition string |
| 818 | */ |
| 819 | private static String getEqualsMethodsSpecificIfCondition(String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 820 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className |
| 821 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className |
| 822 | + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE |
| 823 | + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 827 | * Returns equals methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 828 | * |
| 829 | * @param equalMethodString equal method string |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 830 | * @return equals method close string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 831 | */ |
| 832 | public static String getEqualsMethodClose(String equalMethodString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 833 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 834 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 835 | equalMethodString = trimAtLast(equalMethodString, SPACE); |
| 836 | equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE; |
| 837 | return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 838 | + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 839 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 843 | * Returns equals method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 844 | * |
| 845 | * @param attr attribute info |
| 846 | * @return equals method |
| 847 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 848 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
| 849 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 850 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 851 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
| 852 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND |
| 853 | + AND; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Returns of method string for class. |
| 858 | * |
| 859 | * @param name class name |
| 860 | * @param attr attribute info |
| 861 | * @return of method string |
| 862 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 863 | public static String getOfMethod(String name, JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 864 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 865 | String attrQualifiedType = getReturnType(attr); |
| 866 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 867 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 868 | + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 869 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
| 870 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 871 | } |
| 872 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 873 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 874 | * Returns of method's string and java doc for special type. |
| 875 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 876 | * @param attr attribute info |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 877 | * @param generatedJavaClassName class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 878 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 879 | * @return of method's string and java doc for special type |
| 880 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 881 | public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 882 | YangPluginConfig pluginConfig) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 883 | |
| 884 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 885 | String attrName = attr.getAttributeName(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 886 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 887 | return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 888 | + getOfMethodString(attrType, generatedJavaClassName); |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * Returns of method's string. |
| 893 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 894 | * @param type data type |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 895 | * @param className class name |
| 896 | * @return of method's string |
| 897 | */ |
| 898 | private static String getOfMethodString(String type, String className) { |
| 899 | |
| 900 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS |
| 901 | + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 902 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE |
| 903 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Returns string and java doc for constructor of type class. |
| 908 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 909 | * @param attr attribute info |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 910 | * @param generatedJavaClassName class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 911 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 912 | * @return string and java doc for constructor of type class |
| 913 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 914 | public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 915 | String generatedJavaClassName, |
| 916 | YangPluginConfig pluginConfig) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 917 | |
| 918 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 919 | String attrName = attr.getAttributeName(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 920 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 921 | return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 922 | + getTypeConstructorString(attrType, attrName, generatedJavaClassName); |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * Returns type constructor string. |
| 927 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 928 | * @param type data type |
| 929 | * @param name attribute name |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 930 | * @param className class name |
| 931 | * @return type constructor string |
| 932 | */ |
| 933 | private static String getTypeConstructorString(String type, String name, String className) { |
| 934 | |
| 935 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
| 936 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 937 | + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 938 | + CLOSE_CURLY_BRACKET; |
| 939 | } |
| 940 | |
| 941 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 942 | * Returns implementation of add augmentation method of AugmentationHolder class. |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 943 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 944 | * @return implementation of add augmentation method of AugmentationHolder class |
| 945 | */ |
| 946 | public static String getAddAugmentInfoMethodImpl() { |
| 947 | String method = FOUR_SPACE_INDENTATION; |
| 948 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING |
| 949 | + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE |
| 950 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST |
| 951 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE |
| 952 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 953 | |
| 954 | return method; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Returns implementation of get augment info list method of AugmentationHolder class. |
| 959 | * |
| 960 | * @return implementation of get augment info list method of AugmentationHolder class |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 961 | */ |
| 962 | public static String getAugmentInfoListImpl() { |
| 963 | |
| 964 | String method = FOUR_SPACE_INDENTATION; |
| 965 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET |
| 966 | + AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST |
| 967 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 968 | + RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 969 | + CLOSE_CURLY_BRACKET; |
| 970 | return method; |
| 971 | } |
| 972 | |
| 973 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 974 | * Returns implementation of remove augmentation method of AugmentationHolder class. |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 975 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 976 | * @return implementation of remove augmentation method of AugmentationHolder class |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 977 | */ |
| 978 | public static String getRemoveAugmentationImpl() { |
| 979 | String method = FOUR_SPACE_INDENTATION; |
| 980 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove" |
| 981 | + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 982 | + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 983 | + CLOSE_PARENTHESIS + PERIOD + CLEAR + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 984 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 985 | return method; |
| 986 | } |
| 987 | |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 988 | /** |
| 989 | * Returns enum's constructor. |
| 990 | * |
| 991 | * @param className enum's class name |
| 992 | * @return enum's constructor |
| 993 | */ |
| 994 | public static String getEnumsConstrcutor(String className) { |
| 995 | return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE |
| 996 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL |
| 997 | + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 998 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 999 | |
| 1000 | /** |
| 1001 | * Returns of method for enum class. |
| 1002 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1003 | * @param className class name |
| 1004 | * @param attr java attribute |
| 1005 | * @param enumMap enum's sets map |
| 1006 | * @param enumList enum's sets list |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1007 | * @param pluginConfig plugin configurations |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1008 | * @return of method |
| 1009 | */ |
| 1010 | public static String getEnumsOfMethod(String className, JavaAttributeInfo attr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1011 | Map<String, Integer> enumMap, List<String> enumList, |
| 1012 | YangPluginConfig pluginConfig) { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1013 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1014 | String attrName = attr.getAttributeName(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1015 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1016 | String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE |
| 1017 | + OF + OPEN_PARENTHESIS |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1018 | + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 1019 | + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE |
| 1020 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 1021 | int value = 0; |
| 1022 | for (String str : enumList) { |
| 1023 | |
| 1024 | value = enumMap.get(str); |
| 1025 | method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1026 | + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1027 | + str + SEMI_COLAN + NEW_LINE; |
| 1028 | } |
| 1029 | method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION |
| 1030 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 1031 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 1032 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1033 | return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig) |
| 1034 | + method; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1035 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1036 | |
| 1037 | /** |
| 1038 | * Returns activate method string. |
| 1039 | * |
| 1040 | * @return activate method string |
| 1041 | */ |
| 1042 | public static String addActivateMethod() { |
| 1043 | return FOUR_SPACE_INDENTATION + ACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION |
| 1044 | + PUBLIC + SPACE + VOID + SPACE + ACTIVATE + OPEN_PARENTHESIS |
| 1045 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 1046 | + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1047 | + YANG_UTILS_TODO |
| 1048 | + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1049 | + STARTED_LOG_INFO + FOUR_SPACE_INDENTATION |
| 1050 | + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Returns deactivate method string. |
| 1055 | * |
| 1056 | * @return deactivate method string |
| 1057 | */ |
| 1058 | public static String addDeActivateMethod() { |
| 1059 | return NEW_LINE + FOUR_SPACE_INDENTATION + DEACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION |
| 1060 | + PUBLIC + SPACE + VOID + SPACE + DEACTIVATE + OPEN_PARENTHESIS |
| 1061 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1062 | + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1063 | + STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1064 | } |
| 1065 | |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1066 | /** |
| 1067 | * Returns from string method parsed string. |
| 1068 | * |
| 1069 | * @param targetDataType target data type |
| 1070 | * @param yangType YANG type |
| 1071 | * @return parsed string |
| 1072 | */ |
| 1073 | public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) { |
| 1074 | |
| 1075 | YangDataTypes type = yangType.getDataType(); |
| 1076 | |
| 1077 | switch (type) { |
| 1078 | case INT8: |
| 1079 | return BYTE_WRAPPER + PERIOD + PARSE_BYTE; |
| 1080 | case INT16: |
| 1081 | return SHORT_WRAPPER + PERIOD + PARSE_SHORT; |
| 1082 | case INT32: |
| 1083 | return INTEGER_WRAPPER + PERIOD + PARSE_INT; |
| 1084 | case INT64: |
| 1085 | return LONG_WRAPPER + PERIOD + PARSE_LONG; |
| 1086 | case UINT8: |
| 1087 | return SHORT_WRAPPER + PERIOD + PARSE_SHORT; |
| 1088 | case UINT16: |
| 1089 | return INTEGER_WRAPPER + PERIOD + PARSE_INT; |
| 1090 | case UINT32: |
| 1091 | return LONG_WRAPPER + PERIOD + PARSE_LONG; |
| 1092 | case UINT64: |
| 1093 | return NEW + SPACE + BIG_INTEGER; |
| 1094 | case STRING: |
| 1095 | return EMPTY_STRING; |
| 1096 | case EMPTY: |
| 1097 | case BOOLEAN: |
| 1098 | return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN; |
| 1099 | case DECIMAL64: |
| 1100 | case BITS: |
| 1101 | case BINARY: |
| 1102 | case UNION: |
| 1103 | case ENUMERATION: |
| 1104 | case DERIVED: |
| 1105 | return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; |
| 1106 | default: |
| 1107 | throw new TranslatorException("given data type is not supported."); |
| 1108 | } |
| 1109 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1110 | } |