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; |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 21 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangCompilerAnnotation; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangType; |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.utils.io.YangPluginConfig; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 32 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 33 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY; |
| 34 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS; |
| 35 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16; |
| 39 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32; |
| 40 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64; |
| 45 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods; |
| 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.utils.UtilConstants.ADD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
| 55 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 56 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.utils.UtilConstants.BASE64; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 58 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.utils.UtilConstants.CASE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 67 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 68 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
| 70 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 71 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
| 72 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.utils.UtilConstants.COLAN; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.utils.UtilConstants.COLON; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.utils.UtilConstants.DECODE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 77 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
| 79 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 80 | import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.utils.UtilConstants.ELSE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 83 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 85 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
| 86 | import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 87 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION; |
| 88 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 90 | import static org.onosproject.yangutils.utils.UtilConstants.FOR; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 91 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; |
| 93 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 94 | import static org.onosproject.yangutils.utils.UtilConstants.GET; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; |
| 97 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; |
| 98 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; |
| 99 | import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING; |
| 100 | import static org.onosproject.yangutils.utils.UtilConstants.IF; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 101 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; |
| 102 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 104 | import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE; |
| 105 | import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 106 | import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF; |
| 107 | import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 109 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 110 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE; |
| 111 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 113 | import static org.onosproject.yangutils.utils.UtilConstants.MAP; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 114 | import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE; |
| 115 | import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 116 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
| 117 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 118 | import static org.onosproject.yangutils.utils.UtilConstants.NULL; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 119 | import static org.onosproject.yangutils.utils.UtilConstants.OBJ; |
| 120 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
| 121 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; |
| 122 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 123 | import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 124 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
| 125 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 126 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 127 | import static org.onosproject.yangutils.utils.UtilConstants.OTHER; |
| 128 | import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 129 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN; |
| 130 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; |
| 131 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; |
| 132 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; |
| 133 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 134 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 135 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 136 | import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING; |
| 137 | import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 138 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 139 | import static org.onosproject.yangutils.utils.UtilConstants.PUT; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 140 | import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK; |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 141 | import static org.onosproject.yangutils.utils.UtilConstants.QUEUE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 142 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 143 | import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 144 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 145 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 146 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 147 | import static org.onosproject.yangutils.utils.UtilConstants.SET; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 148 | import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 149 | import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 150 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 151 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE; |
| 152 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 153 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 154 | import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 155 | import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; |
| 156 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 157 | import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING; |
| 158 | import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 159 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
| 160 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 161 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 162 | import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 163 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 164 | import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 165 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 166 | import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 167 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 168 | import static org.onosproject.yangutils.utils.UtilConstants.TRY; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 169 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 170 | import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE; |
| 171 | import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 172 | import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE; |
| 173 | import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE; |
| 174 | import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE; |
| 175 | import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE; |
| 176 | import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 177 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 178 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 179 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 180 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 181 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 182 | import static org.onosproject.yangutils.utils.UtilConstants.ZERO; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 183 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
| 184 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
| 185 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 186 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 187 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 188 | 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] | 189 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 190 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 191 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 192 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 193 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 194 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 195 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 196 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 197 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 198 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 199 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 200 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 201 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 202 | |
| 203 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 204 | * Represents generator for methods of generated files based on the file type. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 205 | */ |
| 206 | public final class MethodsGenerator { |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 207 | private static final String BITS_STRING_ARRAY_VAR = "bitsTemp"; |
| 208 | private static final String BIT_TEMP_VAR = "bitTemp"; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 209 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 210 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 211 | * Creates an instance of method generator. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 212 | */ |
| 213 | private MethodsGenerator() { |
| 214 | } |
| 215 | |
| 216 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 217 | * Returns the methods strings for builder interface. |
| 218 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 219 | * @param name attribute name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 220 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 221 | * @return method string for builder interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 222 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 223 | public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 224 | return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns getter string. |
| 229 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 230 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 231 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 232 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 233 | * @return getter string |
| 234 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 235 | public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 236 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 237 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 238 | String returnType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 239 | String attributeName = attr.getAttributeName(); |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 240 | String appDataStructure = null; |
| 241 | if (attr.getCompilerAnnotation() != null) { |
| 242 | appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name(); |
| 243 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 244 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
| 245 | return generateForGetMethodWithAttribute(returnType) |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 246 | + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles, |
| 247 | attr.getCompilerAnnotation()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 248 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 249 | |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 250 | return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure) |
| 251 | + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles, |
| 252 | attr.getCompilerAnnotation()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Returns setter string. |
| 257 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 258 | * @param attr attribute info |
| 259 | * @param className java class name |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 260 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 261 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 262 | * @return setter string |
| 263 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 264 | public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 265 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 266 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 267 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 268 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 269 | JavaDocGen.JavaDocType type; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 270 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 271 | type = MANAGER_SETTER_METHOD; |
| 272 | } else { |
| 273 | type = SETTER_METHOD; |
| 274 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 275 | |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 276 | String appDataStructure = null; |
| 277 | if (attr.getCompilerAnnotation() != null) { |
| 278 | appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name(); |
| 279 | } |
| 280 | return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure) |
| 281 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles, |
| 282 | attr.getCompilerAnnotation()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Returns constructor method string. |
| 287 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 288 | * @param name class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 289 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 290 | * @return constructor string |
| 291 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 292 | private static String getConstructorString(String name, YangPluginConfig pluginConfig) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 293 | return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Returns default constructor method string. |
| 298 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 299 | * @param name class name |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 300 | * @param modifierType modifier type |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 301 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 302 | * @return default constructor string |
| 303 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 304 | public static String getDefaultConstructorString(String name, String modifierType, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 305 | YangPluginConfig pluginConfig) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 306 | return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null) |
| 307 | + getDefaultConstructor(name, modifierType) + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Returns check not null string. |
| 312 | * |
| 313 | * @param name attribute name |
| 314 | * @return check not null string |
| 315 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 316 | static String getCheckNotNull(String name) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 317 | return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name |
| 318 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Returns build method string. |
| 323 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 324 | * @param name class name |
| 325 | * @param isRootNode if root node |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 326 | * @return build string |
| 327 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 328 | public static String getBuildString(String name, boolean isRootNode) { |
| 329 | if (isRootNode) { |
| 330 | return NEW_LINE + getBuild(name, true); |
| 331 | } |
| 332 | return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name, false); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Returns the getter method strings for class file. |
| 337 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 338 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 339 | * @param generatedJavaFiles for the type of java file being generated |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 340 | * @return getter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 341 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 342 | public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 343 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 344 | String attrQualifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 345 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 346 | |
| 347 | if (!attr.isListAttr()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 348 | return getGetter(attrQualifiedType, attributeName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 349 | } |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 350 | String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation()); |
| 351 | return getGetter(attrParam, attributeName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Returns getter for attribute. |
| 356 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 357 | * @param type return type |
| 358 | * @param name attribute name |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 359 | * @param generatedJavaFiles generated java files |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 360 | * @return getter for attribute |
| 361 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 362 | static String getGetter(String type, String name, int generatedJavaFiles) { |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 363 | String ret = parseTypeForReturnValue(type); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 364 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 365 | 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] | 366 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
| 367 | EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION + |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 368 | 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] | 369 | } else { |
| 370 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name |
| 371 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
| 372 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 373 | + CLOSE_CURLY_BRACKET; |
| 374 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 375 | } |
| 376 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 377 | /*Provides string to return for type.*/ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 378 | private static String parseTypeForReturnValue(String type) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 379 | switch (type) { |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 380 | case BYTE: |
| 381 | case INT: |
| 382 | case SHORT: |
| 383 | case LONG: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 384 | case DOUBLE: |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 385 | return "0"; |
| 386 | case BOOLEAN_DATA_TYPE: |
| 387 | return FALSE; |
| 388 | default: |
| 389 | return null; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 393 | /** |
| 394 | * Returns the setter method strings for class file. |
| 395 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 396 | * @param attr attribute info |
| 397 | * @param className name of the class |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 398 | * @param generatedJavaFiles generated java files |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 399 | * @return setter method for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 400 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 401 | public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 402 | String attrQualifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 403 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 404 | boolean isTypeNull = false; |
| 405 | if (attr.getAttributeType() == null) { |
| 406 | isTypeNull = true; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 407 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 408 | if (!attr.isListAttr()) { |
| 409 | return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false); |
| 410 | } |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 411 | String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation()); |
| 412 | return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Returns setter for attribute. |
| 417 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 418 | * @param className class name |
| 419 | * @param name attribute name |
| 420 | * @param type return type |
| 421 | * @param isTypeNull if attribute type is null |
| 422 | * @param isList true if leaf-list |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 423 | * @return setter for attribute |
| 424 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 425 | private static String getSetter(String className, String name, String type, int generatedJavaFiles, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 426 | boolean isTypeNull, boolean isList) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 427 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 428 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 429 | + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE + |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 430 | OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + |
| 431 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 432 | } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) { |
| 433 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE |
| 434 | + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 435 | + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE |
| 436 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 437 | } else { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 438 | String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 439 | name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 440 | + OPEN_CURLY_BRACKET; |
| 441 | if (!isTypeNull && !isList) { |
| 442 | method = method + getValueLeafSetString(name); |
| 443 | } else { |
| 444 | method = method + EMPTY_STRING; |
| 445 | } |
| 446 | return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + |
| 447 | PERIOD + name + SPACE |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 448 | + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE |
| 449 | + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 450 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 451 | |
| 452 | } |
| 453 | |
| 454 | //Returns value leaf flag setter. |
| 455 | private static String getValueLeafSetString(String name) { |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 456 | return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());"; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 460 | * Returns the setter method strings for class file. |
| 461 | * |
| 462 | * @param attr attribute info |
| 463 | * @return setter method for class |
| 464 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 465 | static String getSetterForTypeDefClass(JavaAttributeInfo attr) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 466 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 467 | String attrQualifiedType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 468 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 469 | return getTypeDefSetter(attrQualifiedType, attributeName); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Returns type def's setter for attribute. |
| 474 | * |
| 475 | * @param type data type |
| 476 | * @param name attribute name |
| 477 | * @return setter for type def's attribute |
| 478 | */ |
| 479 | private static String getTypeDefSetter(String type, String name) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 480 | 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] | 481 | + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 482 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + |
| 483 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Returns override string. |
| 488 | * |
| 489 | * @return override string |
| 490 | */ |
| 491 | public static String getOverRideString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 492 | return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 496 | * Returns the getter method strings for interface file. |
| 497 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 498 | * @param yangName name of the attribute |
| 499 | * @param returnType return type of attribute |
| 500 | * @param isList is list attribute |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 501 | * @param generatedJavaFiles generated java files |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 502 | * @param compilerAnnotation compiler annotation |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 503 | * @return getter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 504 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 505 | static String getGetterForInterface(String yangName, String returnType, boolean isList, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 506 | int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 507 | if (!isList) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 508 | return getGetterInterfaceString(returnType, yangName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 509 | } |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 510 | String listAttr = getListAttribute(returnType, compilerAnnotation); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 511 | return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Returns getter for attribute in interface. |
| 516 | * |
| 517 | * @param returnType return type |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 518 | * @param yangName attribute name |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 519 | * @return getter for interface |
| 520 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 521 | private static String getGetterInterfaceString(String returnType, String yangName, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 522 | int generatedJavaFiles) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 523 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 524 | return getGetMethodWithArgument(returnType, yangName); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 525 | } else { |
| 526 | return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName |
| 527 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 528 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Returns the setter method strings for interface file. |
| 533 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 534 | * @param attrName name of the attribute |
| 535 | * @param attrType return type of attribute |
| 536 | * @param className name of the java class being generated |
| 537 | * @param isList is list attribute |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 538 | * @param generatedJavaFiles generated java files |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 539 | * @param compilerAnnotation compiler annotations |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 540 | * @return setter method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 541 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 542 | static String getSetterForInterface(String attrName, String attrType, String className, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 543 | boolean isList, int generatedJavaFiles, |
| 544 | YangCompilerAnnotation compilerAnnotation) { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 545 | if (!isList) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 546 | return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 547 | } |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 548 | |
| 549 | String listAttr = getListAttribute(attrType, compilerAnnotation); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 550 | return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Returns setter string for interface. |
| 555 | * |
| 556 | * @param className class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 557 | * @param attrName attribute name |
| 558 | * @param attrType attribute type |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 559 | * @return setter string |
| 560 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 561 | private static String getSetterInterfaceString(String className, String attrName, String attrType, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 562 | int generatedJavaFiles) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 563 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 564 | return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName) |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 565 | + OPEN_PARENTHESIS + attrType + OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 566 | } else { |
| 567 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName |
| 568 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 569 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 573 | * Returns list string. |
| 574 | * |
| 575 | * @return list string |
| 576 | */ |
| 577 | private static String getListString() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 578 | return LIST + DIAMOND_OPEN_BRACKET; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 582 | * Returns return type for attribute. |
| 583 | * |
| 584 | * @param attr attribute info |
| 585 | * @return return type |
| 586 | */ |
| 587 | private static String getReturnType(JavaAttributeInfo attr) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 588 | String returnType = EMPTY_STRING; |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 589 | if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 590 | returnType = attr.getImportInfo().getPkgInfo() + PERIOD; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 591 | } |
| 592 | returnType = returnType + attr.getImportInfo().getClassInfo(); |
| 593 | return returnType; |
| 594 | } |
| 595 | |
| 596 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 597 | * Returns the build method strings for interface file. |
| 598 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 599 | * @param yangName name of the interface |
| 600 | * @return build method for interface |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 601 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 602 | static String getBuildForInterface(String yangName) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 603 | return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
| 604 | + NEW_LINE; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /** |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 608 | * Returns constructor string for impl class. |
| 609 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 610 | * @param yangName class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 611 | * @param pluginConfig plugin configurations |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 612 | * @param isRootNode if root node |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 613 | * @return constructor string |
| 614 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 615 | static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 616 | String javadoc = getConstructorString(yangName, pluginConfig); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 617 | |
| 618 | String returnType = getCapitalCase(DEFAULT) + yangName; |
| 619 | if (isRootNode) { |
| 620 | returnType = yangName + OP_PARAM; |
| 621 | } |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 622 | String constructor = FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType + |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 623 | OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT |
| 624 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 625 | return javadoc + constructor; |
| 626 | } |
| 627 | |
| 628 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 629 | * Returns the constructor strings for class file. |
| 630 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 631 | * @param attr attribute info |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 632 | * @param generatedJavaFiles generated java files |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 633 | * @param pluginConfig plugin configurations |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 634 | * @return constructor for class |
| 635 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 636 | public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 637 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 638 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 639 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 640 | String constructor; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 641 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 642 | if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 643 | constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 644 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL |
| 645 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
| 646 | + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver())) |
| 647 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 648 | } else { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 649 | constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 650 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL |
| 651 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD |
| 652 | + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + |
| 653 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 654 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 655 | return constructor; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 659 | * Returns the rpc strings for service interface. |
| 660 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 661 | * @param rpcName name of the rpc |
| 662 | * @param inputName name of input |
| 663 | * @param outputName name of output |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 664 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 665 | * @return rpc method string |
| 666 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 667 | public static String getRpcServiceMethod(String rpcName, String inputName, String outputName, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 668 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 669 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 670 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 671 | if (!inputName.equals(EMPTY_STRING)) { |
| 672 | inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 673 | } |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 674 | return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName |
| 675 | + CLOSE_PARENTHESIS + SEMI_COLAN; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 679 | * Returns the rpc strings for manager impl. |
| 680 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 681 | * @param rpcName name of the rpc |
| 682 | * @param inputName name of input |
| 683 | * @param outputName name of output |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 684 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 685 | * @return rpc method string |
| 686 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 687 | public static String getRpcManagerMethod(String rpcName, String inputName, String outputName, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 688 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 689 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 690 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 691 | if (!inputName.equals(EMPTY_STRING)) { |
| 692 | inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 693 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 694 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 695 | String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName |
| 696 | + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE |
| 697 | + 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] | 698 | if (!outputName.contentEquals(VOID)) { |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 699 | method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN |
| 700 | + NEW_LINE; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 701 | } |
| 702 | method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 703 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 704 | return method; |
| 705 | } |
| 706 | |
| 707 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 708 | * Returns the build method strings for class file. |
| 709 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 710 | * @param yangName class name |
| 711 | * @param isRootNode if root node |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 712 | * @return build method string for class |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 713 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 714 | static String getBuild(String yangName, boolean isRootNode) { |
| 715 | String type = getCapitalCase(DEFAULT) + yangName; |
| 716 | if (isRootNode) { |
| 717 | type = yangName + OP_PARAM; |
| 718 | } |
| 719 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + |
| 720 | CLOSE_PARENTHESIS |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 721 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 722 | type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 723 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Returns the Default constructor strings for class file. |
| 728 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 729 | * @param name name of the class |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 730 | * @param modifierType modifier type for default constructor |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 731 | * @return Default constructor for class |
| 732 | */ |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 733 | private static String getDefaultConstructor(String name, String modifierType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 734 | return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE |
| 735 | + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 736 | } |
| 737 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 738 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 739 | * Returns to string method's open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 740 | * |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 741 | * @return string method's open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 742 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 743 | static String getToStringMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 744 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
| 745 | + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 746 | + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /** |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 750 | * Returns whether the data type is of primitive data type. |
| 751 | * |
| 752 | * @param dataType data type to be checked |
| 753 | * @return true, if data type can have primitive data type, false otherwise |
| 754 | */ |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 755 | static boolean isPrimitiveDataType(YangDataTypes dataType) { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 756 | return dataType == INT8 |
| 757 | || dataType == INT16 |
| 758 | || dataType == INT32 |
| 759 | || dataType == INT64 |
| 760 | || dataType == UINT8 |
| 761 | || dataType == UINT16 |
| 762 | || dataType == UINT32 |
| 763 | || dataType == UINT64 |
| 764 | || dataType == DECIMAL64 |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 765 | || dataType == BOOLEAN |
| 766 | || dataType == EMPTY; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 767 | |
| 768 | } |
| 769 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 770 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 771 | static String getIfConditionBegin(String indentation, String condition) { |
| 772 | return indentation + IF + SPACE + OPEN_PARENTHESIS + condition + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 773 | + NEW_LINE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 774 | } |
| 775 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 776 | static String getElseIfConditionBegin(String indentation, String condition) { |
| 777 | return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + getIfConditionBegin("", condition); |
| 778 | } |
| 779 | |
| 780 | static String getBlockEnd(String indentation) { |
| 781 | return indentation + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 782 | } |
| 783 | |
| 784 | static String getCollectionIteratorForLoopBegin(String indentation, String loopVar, String collection) { |
| 785 | return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE + COLAN + SPACE + collection |
| 786 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 787 | } |
| 788 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 789 | /* |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 790 | * Returns omit null value string. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 791 | * |
| 792 | * @return omit null value string |
| 793 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 794 | static String getOmitNullValueString() { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 795 | return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE; |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Returns to string method's close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 800 | * |
| 801 | * @return to string method close string |
| 802 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 803 | static String getToStringMethodClose() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 804 | return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 805 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 809 | * Returns to string method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 810 | * |
| 811 | * @param attr attribute info |
| 812 | * @return to string method |
| 813 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 814 | public static String getToStringMethod(JavaAttributeInfo attr) { |
| 815 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 816 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 817 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
| 818 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 822 | * Returns from string method's open string. |
| 823 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 824 | * @param className name of the class |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 825 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 826 | * @return from string method's open string |
| 827 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 828 | static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 829 | return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 830 | + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS |
| 831 | + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE |
| 832 | + OPEN_CURLY_BRACKET + NEW_LINE; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /** |
| 836 | * Return from string method's close string. |
| 837 | * |
| 838 | * @return from string method's close string |
| 839 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 840 | static String getFromStringMethodClose() { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 841 | return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 842 | CLOSE_CURLY_BRACKET + NEW_LINE; |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * Return from string method's body string. |
| 847 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 848 | * @param attr attribute info |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 849 | * @param fromStringAttributeInfo attribute info for the from string wrapper type |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 850 | * @return from string method's body string |
| 851 | */ |
| 852 | public static String getFromStringMethod(JavaAttributeInfo attr, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 853 | JavaAttributeInfo fromStringAttributeInfo) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 854 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 855 | return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION |
Mahesh Poojary S | 6986df3 | 2016-07-19 10:58:07 +0530 | [diff] [blame] | 856 | + getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 857 | + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString() |
| 858 | + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Returns sub string with try statement for union's from string method. |
| 863 | * |
| 864 | * @return sub string with try statement for union's from string method |
| 865 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 866 | private static String getTrySubString() { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 867 | return TRY + SPACE + OPEN_CURLY_BRACKET; |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Returns sub string with return statement for union's from string method. |
| 872 | * |
| 873 | * @return sub string with return statement for union's from string method |
| 874 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 875 | private static String getReturnOfSubString() { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 876 | return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Returns sub string with catch statement for union's from string method. |
| 881 | * |
| 882 | * @return sub string with catch statement for union's from string method |
| 883 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 884 | private static String getCatchSubString() { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 885 | return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR |
| 886 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Returns sub string with parsed statement for union's from string method. |
| 891 | * |
| 892 | * @param attr attribute info |
| 893 | * @return sub string with parsed statement for union's from string method |
| 894 | */ |
| 895 | private static String getParsedSubString(JavaAttributeInfo attr, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 896 | JavaAttributeInfo fromStringAttributeInfo) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 897 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 898 | String targetDataType = getReturnType(attr); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 899 | if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) { |
| 900 | String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType |
| 901 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 902 | lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME |
| 903 | + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE |
| 904 | + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 905 | lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME |
| 906 | + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE |
| 907 | + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 908 | lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME |
| 909 | + PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 910 | lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR |
| 911 | + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS |
| 912 | + QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 913 | lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE |
| 914 | + BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE |
| 915 | + OPEN_CURLY_BRACKET + NEW_LINE; |
| 916 | lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD |
| 917 | + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 918 | lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS |
| 919 | + INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS |
| 920 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 921 | lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 922 | return lines; |
| 923 | } else if (attr.getAttributeType().getDataType() == BINARY) { |
| 924 | return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD |
| 925 | + GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS |
| 926 | + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 927 | } else { |
| 928 | String parseFromStringMethod = getParseFromStringMethod(targetDataType, |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 929 | fromStringAttributeInfo.getAttributeType()); |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 930 | return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 931 | + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 932 | } |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 933 | } |
| 934 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 935 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 936 | * Returns hash code method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 937 | * |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 938 | * @return hash code method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 939 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 940 | static String getHashCodeMethodOpen() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 941 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 942 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
| 943 | EIGHT_SPACE_INDENTATION |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 944 | + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 948 | * Returns hash code methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 949 | * |
| 950 | * @param hashcodeString hash code string |
| 951 | * @return to hash code method close string |
| 952 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 953 | static String getHashCodeMethodClose(String hashcodeString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 954 | hashcodeString = trimAtLast(hashcodeString, COMMA); |
| 955 | hashcodeString = trimAtLast(hashcodeString, SPACE); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 956 | return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 957 | CLOSE_CURLY_BRACKET |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 958 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 962 | * Returns hash code method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 963 | * |
| 964 | * @param attr attribute info |
| 965 | * @return hash code method |
| 966 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 967 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 968 | return attr.getAttributeName() + COMMA + SPACE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 972 | * Returns equals method open strings. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 973 | * |
| 974 | * @param className class name |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 975 | * @return equals method open string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 976 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 977 | static String getEqualsMethodOpen(String className) { |
| 978 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + |
| 979 | EQUALS_STRING |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 980 | + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 981 | + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /** |
| 985 | * Returns equal methods if condition string. |
| 986 | * |
| 987 | * @return if condition string |
| 988 | */ |
| 989 | private static String getEqualsMethodsCommonIfCondition() { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 990 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ |
| 991 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE |
| 992 | + 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] | 993 | } |
| 994 | |
| 995 | /** |
| 996 | * Returns if condition for specific class object in equals method. |
| 997 | * |
| 998 | * @param className class name |
| 999 | * @return if condition string |
| 1000 | */ |
| 1001 | private static String getEqualsMethodsSpecificIfCondition(String className) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1002 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className |
| 1003 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className |
| 1004 | + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE |
| 1005 | + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1009 | * Returns equals methods close string. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1010 | * |
| 1011 | * @param equalMethodString equal method string |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1012 | * @return equals method close string |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1013 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1014 | static String getEqualsMethodClose(String equalMethodString) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1015 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 1016 | equalMethodString = trimAtLast(equalMethodString, AND); |
| 1017 | equalMethodString = trimAtLast(equalMethodString, SPACE); |
| 1018 | equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE; |
| 1019 | return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1020 | + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 1021 | + NEW_LINE; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1025 | * Returns equals method for class. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1026 | * |
| 1027 | * @param attr attribute info |
| 1028 | * @return equals method |
| 1029 | */ |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1030 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1031 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1032 | String attributeName = attr.getAttributeName(); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1033 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
| 1034 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND |
| 1035 | + AND; |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Returns of method string for class. |
| 1040 | * |
| 1041 | * @param name class name |
| 1042 | * @param attr attribute info |
| 1043 | * @return of method string |
| 1044 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1045 | static String getOfMethod(String name, JavaAttributeInfo attr) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1046 | String attrQualifiedType = getReturnType(attr); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1047 | 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] | 1048 | + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1049 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
| 1050 | + 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] | 1051 | } |
| 1052 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1053 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1054 | * Returns of method's string and java doc for special type. |
| 1055 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1056 | * @param attr attribute info |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1057 | * @param generatedJavaClassName class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1058 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1059 | * @return of method's string and java doc for special type |
| 1060 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1061 | public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1062 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1063 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1064 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1065 | String attrName = attr.getAttributeName(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1066 | |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1067 | return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1068 | + getOfMethodString(attrType, generatedJavaClassName); |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * Returns of method's string. |
| 1073 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1074 | * @param type data type |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1075 | * @param className class name |
| 1076 | * @return of method's string |
| 1077 | */ |
| 1078 | private static String getOfMethodString(String type, String className) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1079 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS |
| 1080 | + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 1081 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE |
| 1082 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Returns string and java doc for constructor of type class. |
| 1087 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1088 | * @param attr attribute info |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1089 | * @param generatedJavaClassName class name |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1090 | * @param pluginConfig plugin configurations |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1091 | * @return string and java doc for constructor of type class |
| 1092 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1093 | public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1094 | String generatedJavaClassName, |
| 1095 | YangPluginConfig pluginConfig) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1096 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1097 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1098 | String attrName = attr.getAttributeName(); |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1099 | return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null) |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1100 | + getTypeConstructorString(attrType, attrName, generatedJavaClassName); |
| 1101 | } |
| 1102 | |
| 1103 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1104 | * Returns string and java doc for constructor of type class. |
| 1105 | * |
| 1106 | * @param attr1 first attribute info |
| 1107 | * @param attr2 second attribute info |
| 1108 | * @param generatedJavaClassName class name |
| 1109 | * @param pluginConfig plugin config |
| 1110 | * @param type conflict validate type |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1111 | * @param addFirst whether int came first or uInt came first |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1112 | * @return string and java doc for constructor of type class |
| 1113 | */ |
| 1114 | public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo |
| 1115 | attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1116 | boolean addFirst) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1117 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1118 | String attrType = getReturnType(attr1); |
| 1119 | String attrName1 = ""; |
| 1120 | String attrName2 = ""; |
| 1121 | if (attr1 != null) { |
| 1122 | attrName1 = attr1.getAttributeName(); |
| 1123 | } |
| 1124 | if (attr2 != null) { |
| 1125 | attrName2 = attr2.getAttributeName(); |
| 1126 | } |
| 1127 | |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1128 | String appDataStructure = null; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1129 | if (attr1 != null && attr1.getCompilerAnnotation() != null) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1130 | appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name(); |
| 1131 | } |
| 1132 | return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig, |
| 1133 | appDataStructure) + getTypeConstructorString(attrType, attrName1, |
| 1134 | attrName2, generatedJavaClassName, type, addFirst); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1138 | * Returns type constructor string. |
| 1139 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1140 | * @param type data type |
| 1141 | * @param name attribute name |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1142 | * @param className class name |
| 1143 | * @return type constructor string |
| 1144 | */ |
| 1145 | private static String getTypeConstructorString(String type, String name, String className) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1146 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
| 1147 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
| 1148 | + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
| 1149 | + CLOSE_CURLY_BRACKET; |
| 1150 | } |
| 1151 | |
| 1152 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1153 | * Returns type constructor string. |
| 1154 | * |
| 1155 | * @param type data type |
| 1156 | * @param attr1 attribute attr1 |
| 1157 | * @param className class attr1 |
| 1158 | * @return type constructor string |
| 1159 | */ |
| 1160 | private static String getTypeConstructorString(String type, String attr1, String attr2, String className, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1161 | ValidatorTypeForUnionTypes validatorType, boolean addInt) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1162 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1163 | String constructor; |
| 1164 | constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
| 1165 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 1166 | |
| 1167 | String name1; |
| 1168 | String name2; |
| 1169 | if (addInt) { |
| 1170 | name1 = attr1; |
| 1171 | name2 = attr2; |
| 1172 | } else { |
| 1173 | name1 = attr2; |
| 1174 | name2 = attr1; |
| 1175 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1176 | constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) + |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1177 | TWELVE_SPACE_INDENTATION + THIS + PERIOD |
| 1178 | + name1 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1179 | + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION |
| 1180 | + THIS + PERIOD |
| 1181 | + name2 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 1182 | + CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION |
| 1183 | + CLOSE_CURLY_BRACKET; |
| 1184 | |
| 1185 | return constructor; |
| 1186 | } |
| 1187 | |
| 1188 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1189 | * Returns interface of add augmentation. |
| 1190 | * |
| 1191 | * @return interface of add augmentation |
| 1192 | */ |
| 1193 | static String getAddAugmentInfoMethodInterface() { |
| 1194 | return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID + SPACE + |
| 1195 | ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA + |
| 1196 | SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1200 | * Returns implementation of add augmentation. |
| 1201 | * |
| 1202 | * @return implementation of add augmentation |
| 1203 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1204 | static String getAddAugmentInfoMethodImpl() { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1205 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + |
| 1206 | ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA + |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1207 | SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + |
| 1208 | NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT + |
| 1209 | OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE + |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1210 | CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 1211 | CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1215 | * Returns interface of get YANG augment info. |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1216 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1217 | * @return interface of get YANG augment info |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1218 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1219 | static String getYangAugmentInfoInterface() { |
| 1220 | return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + OBJECT_STRING + SPACE + |
| 1221 | getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + |
| 1222 | CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1223 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1224 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1225 | /** |
| 1226 | * Returns implementation of get YANG augment info. |
| 1227 | * |
| 1228 | * @return implementation of get YANG augment info |
| 1229 | */ |
| 1230 | static String getYangAugmentInfoImpl() { |
| 1231 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + |
| 1232 | OBJECT_STRING + SPACE + |
| 1233 | getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1234 | CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + |
| 1235 | RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS + |
| 1236 | OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 1237 | CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1241 | * Returns implementation of get YANG augment info. |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1242 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1243 | * @return implementation of get YANG augment info |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1244 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1245 | static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) { |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1246 | return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null) |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1247 | + FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + |
| 1248 | QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + |
| 1249 | SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS + |
| 1250 | CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Returns implementation of get YANG augment info. |
| 1255 | * |
| 1256 | * @return implementation of get YANG augment info |
| 1257 | */ |
| 1258 | static String getYangAugmentInfoMapImpl() { |
| 1259 | return getOverRideString() |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1260 | + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + |
| 1261 | MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1262 | DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE + |
| 1263 | getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS + |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1264 | CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + |
| 1265 | RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE |
| 1266 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1270 | * Returns enum's constructor. |
| 1271 | * |
| 1272 | * @param className enum's class name |
| 1273 | * @return enum's constructor |
| 1274 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1275 | static String getEnumsConstructor(String className) { |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1276 | return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE |
| 1277 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL |
| 1278 | + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 1279 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1280 | |
| 1281 | /** |
| 1282 | * Returns of method for enum class. |
| 1283 | * |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1284 | * @param className class name |
| 1285 | * @param attr java attribute |
| 1286 | * @param enumMap enum's sets map |
| 1287 | * @param enumList enum's sets list |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1288 | * @param pluginConfig plugin configurations |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1289 | * @return of method |
| 1290 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1291 | static String getEnumsOfMethod(String className, JavaAttributeInfo attr, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1292 | Map<String, Integer> enumMap, List<String> enumList, |
| 1293 | YangPluginConfig pluginConfig) { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1294 | String attrType = getReturnType(attr); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1295 | String attrName = attr.getAttributeName(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1296 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1297 | String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE |
| 1298 | + OF + OPEN_PARENTHESIS |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1299 | + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
| 1300 | + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE |
| 1301 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1302 | int value; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1303 | for (String str : enumList) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1304 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1305 | value = enumMap.get(str); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 1306 | method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1307 | + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1308 | + str + SEMI_COLAN + NEW_LINE; |
| 1309 | } |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 1310 | method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1311 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 1312 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 1313 | |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1314 | return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig, null) |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1315 | + method; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1316 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1317 | |
| 1318 | /** |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1319 | * Returns from string method parsed string. |
| 1320 | * |
| 1321 | * @param targetDataType target data type |
| 1322 | * @param yangType YANG type |
| 1323 | * @return parsed string |
| 1324 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1325 | private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) { |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1326 | YangDataTypes type = yangType.getDataType(); |
| 1327 | |
| 1328 | switch (type) { |
| 1329 | case INT8: |
| 1330 | return BYTE_WRAPPER + PERIOD + PARSE_BYTE; |
| 1331 | case INT16: |
| 1332 | return SHORT_WRAPPER + PERIOD + PARSE_SHORT; |
| 1333 | case INT32: |
| 1334 | return INTEGER_WRAPPER + PERIOD + PARSE_INT; |
| 1335 | case INT64: |
| 1336 | return LONG_WRAPPER + PERIOD + PARSE_LONG; |
| 1337 | case UINT8: |
| 1338 | return SHORT_WRAPPER + PERIOD + PARSE_SHORT; |
| 1339 | case UINT16: |
| 1340 | return INTEGER_WRAPPER + PERIOD + PARSE_INT; |
| 1341 | case UINT32: |
| 1342 | return LONG_WRAPPER + PERIOD + PARSE_LONG; |
| 1343 | case UINT64: |
| 1344 | return NEW + SPACE + BIG_INTEGER; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 1345 | case DECIMAL64: |
| 1346 | return NEW + SPACE + BIG_DECIMAL; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1347 | case STRING: |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1348 | case IDENTITYREF: |
| 1349 | return EMPTY_STRING; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1350 | case EMPTY: |
| 1351 | case BOOLEAN: |
| 1352 | return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1353 | case BITS: |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1354 | case UNION: |
| 1355 | case ENUMERATION: |
| 1356 | case DERIVED: |
| 1357 | return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; |
| 1358 | default: |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 1359 | throw new TranslatorException("given data type is not supported. " + |
| 1360 | yangType.getDataTypeName() + " in " + |
| 1361 | yangType.getLineNumber() + " at " + |
| 1362 | yangType.getCharPosition() |
| 1363 | + " in " + yangType.getFileName()); |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 1364 | } |
| 1365 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1366 | |
| 1367 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1368 | * Returns augmented data getter and setter methods for service class. |
| 1369 | * |
| 1370 | * @param parent parent node |
| 1371 | * @return augmented data getter and setter methods for service class |
| 1372 | */ |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1373 | static String getAugmentsDataMethodForService(YangNode parent) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1374 | List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent); |
| 1375 | YangNode augmentedNode; |
| 1376 | String curNodeName; |
| 1377 | String method; |
| 1378 | StringBuilder methods = new StringBuilder(); |
| 1379 | String parentName; |
| 1380 | String returnType; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1381 | YangNode methodNode; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1382 | YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(); |
| 1383 | for (YangAtomicPath nodeId : targets) { |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1384 | augmentedNode = nodeId.getResolvedNode().getParent(); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1385 | methodNode = nodeId.getResolvedNode(); |
| 1386 | if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) { |
| 1387 | curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1388 | } else { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1389 | curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1390 | .getConflictResolver())); |
| 1391 | } |
| 1392 | returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1393 | parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1394 | method = generateForGetMethodWithAttribute(returnType) |
| 1395 | + getGetMethodWithArgument(returnType, AUGMENTED + parentName |
| 1396 | + getCapitalCase(curNodeName)) + NEW_LINE; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1397 | methods.append(method); |
| 1398 | |
| 1399 | method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED + |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1400 | getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) + |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1401 | getSetterForInterface(getSmallCase(AUGMENTED) + parentName + |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1402 | getCapitalCase(curNodeName), returnType, parentName, false, |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1403 | GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1404 | methods.append(method); |
| 1405 | } |
| 1406 | return methods.toString(); |
| 1407 | } |
| 1408 | |
| 1409 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1410 | * Returns validator method for range in union class. |
| 1411 | * |
| 1412 | * @param type type |
| 1413 | * @return validator method for range in union class |
| 1414 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1415 | static String getRangeValidatorMethodForUnion(String type) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1416 | String newType; |
| 1417 | if (type.contentEquals(BIG_INTEGER)) { |
| 1418 | newType = LONG; |
| 1419 | } else { |
| 1420 | newType = INT; |
| 1421 | } |
| 1422 | String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE + |
| 1423 | SPACE + |
| 1424 | VALIDATE_RANGE + |
| 1425 | OPEN_PARENTHESIS |
| 1426 | + type + SPACE + MIN_RANGE + COMMA + SPACE + type + SPACE + MAX_RANGE + COMMA + SPACE + |
| 1427 | newType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 1428 | if (type.contentEquals(BIG_INTEGER)) { |
| 1429 | method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE + getSmallCase(BIG_INTEGER) |
| 1430 | + SPACE + EQUAL + SPACE + NEW + SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE + |
| 1431 | QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + |
| 1432 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" |
| 1433 | + OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SPACE + AND + |
| 1434 | AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" + OPEN_PARENTHESIS + MAX_RANGE + |
| 1435 | CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SEMI_COLAN + NEW_LINE; |
| 1436 | } else { |
| 1437 | method = method + EIGHT_SPACE_INDENTATION |
| 1438 | + RETURN + SPACE + VALUE + SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE + SPACE + AND + |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 1439 | AND + SPACE + VALUE + SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE + SEMI_COLAN + |
| 1440 | NEW_LINE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1441 | } |
| 1442 | return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 1443 | } |
| 1444 | |
| 1445 | /** |
| 1446 | * Returns if condition string for typedef constructor. |
| 1447 | * |
| 1448 | * @param type type of conflict |
| 1449 | * @param addFirst true int/long need to be added first |
| 1450 | * @return if condition string for typedef constructor |
| 1451 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1452 | private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1453 | String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS; |
| 1454 | |
| 1455 | if (type == INT_TYPE_CONFLICT) { |
| 1456 | if (addFirst) { |
| 1457 | condition = condition + INT_MIN_RANGE + COMMA + SPACE + INT_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1458 | } else { |
| 1459 | condition = condition + UINT_MIN_RANGE + COMMA + SPACE + UINT_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1460 | } |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1461 | } else if (type == SHORT_TYPE_CONFLICT) { |
| 1462 | if (addFirst) { |
| 1463 | condition = condition + SHORT_MIN_RANGE + COMMA + SPACE + SHORT_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1464 | } else { |
| 1465 | condition = condition + UINT8_MIN_RANGE + COMMA + SPACE + UINT8_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1466 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1467 | } else { |
| 1468 | if (addFirst) { |
| 1469 | condition = condition + LONG_MIN_RANGE + COMMA + SPACE + LONG_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1470 | } else { |
| 1471 | condition = condition + ULONG_MIN_RANGE + COMMA + SPACE + ULONG_MAX_RANGE + COMMA + SPACE + VALUE; |
| 1472 | } |
| 1473 | } |
| 1474 | return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 1475 | } |
| 1476 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1477 | //Get method with arguments. |
| 1478 | private static String getGetMethodWithArgument(String returnType, String yangName) { |
| 1479 | return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName) |
| 1480 | + OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS + |
| 1481 | SEMI_COLAN; |
| 1482 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1483 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1484 | /** |
| 1485 | * Returns add to list method interface. |
| 1486 | * |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1487 | * @param attr java attribute |
| 1488 | * @param className name of the class |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1489 | * @return add to list method interface |
| 1490 | */ |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1491 | public static String getAddToListMethodInterface(JavaAttributeInfo attr, String className) { |
| 1492 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + ADD_STRING + getCapitalCase(TO) + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1493 | getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE + |
| 1494 | VALUE + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * Returns add to list method impl. |
| 1499 | * |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1500 | * @param attr java attribute |
| 1501 | * @param generatedJavaClassName class name |
| 1502 | * @param isRoot is root |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1503 | * @return add to list method impl |
| 1504 | */ |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1505 | public static String getAddToListMethodImpl(JavaAttributeInfo attr, String generatedJavaClassName, boolean isRoot) { |
| 1506 | String retString = ""; |
| 1507 | if (!isRoot) { |
| 1508 | retString = getOverRideString(); |
| 1509 | } |
| 1510 | return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + generatedJavaClassName + BUILDER + SPACE + |
| 1511 | ADD_STRING + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1512 | getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + |
| 1513 | getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
| 1514 | + NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 1515 | + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1516 | NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1517 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 1518 | } |
| 1519 | |
| 1520 | /** |
| 1521 | * Returns builder method for class. |
| 1522 | * |
| 1523 | * @param name name of class |
| 1524 | * @return builder method for class |
| 1525 | */ |
| 1526 | static String builderMethod(String name) { |
| 1527 | return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE |
| 1528 | + name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + |
| 1529 | OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + |
| 1530 | BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + |
| 1531 | CLOSE_CURLY_BRACKET; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * Returns is filter content match interface. |
| 1536 | * |
| 1537 | * @param name name of node |
| 1538 | * @return is filter content match interface |
| 1539 | */ |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1540 | static String processSubtreeFilteringInterface(String name) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1541 | String method = " /**\n" + |
| 1542 | " * Checks if the passed " + name + " maps the content match query condition.\n" + |
| 1543 | " *\n" + |
| 1544 | " * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" + |
| 1545 | " for" + |
| 1546 | " content match\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1547 | " * @param isSelectAllSchemaChild is select all schema child\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1548 | " * @return match result\n" + |
| 1549 | " */\n"; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1550 | return method + FOUR_SPACE_INDENTATION + name + SPACE + PROCESS_SUBTREE_FILTERING + |
| 1551 | OPEN_PARENTHESIS |
| 1552 | + name + SPACE + getSmallCase(name) + COMMA + SPACE + BOOLEAN_DATA_TYPE + SPACE + |
| 1553 | "isSelectAllSchemaChild" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * Returns is value set interface. |
| 1558 | * |
| 1559 | * @return is value set interface |
| 1560 | */ |
| 1561 | static String isLeafValueSetInterface() { |
| 1562 | String method = " /**\n" + |
| 1563 | " * Checks if the leaf value is set.\n" + |
| 1564 | " *\n" + |
| 1565 | " * @param leaf leaf whose value status needs to checked\n" + |
| 1566 | " * @return result of leaf value set in object\n" + |
| 1567 | " */\n"; |
| 1568 | return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS |
| 1569 | + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Returns is select leaf set interface. |
| 1574 | * |
| 1575 | * @return is select leaf set interface |
| 1576 | */ |
| 1577 | static String isSelectLeafSetInterface() { |
| 1578 | String method = " /**\n" + |
| 1579 | " * Checks if the leaf is set to be a selected leaf.\n" + |
| 1580 | " *\n" + |
| 1581 | " * @param leaf if leaf needs to be selected\n" + |
| 1582 | " * @return result of leaf value set in object\n" + |
| 1583 | " */\n"; |
| 1584 | return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS |
| 1585 | + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * Returns set select leaf set interface. |
| 1590 | * |
| 1591 | * @param name node name |
| 1592 | * @return set select leaf set interface |
| 1593 | */ |
| 1594 | static String setSelectLeafSetInterface(String name) { |
| 1595 | String method = " /**\n" + |
| 1596 | " * Set a leaf to be selected.\n" + |
| 1597 | " *\n" + |
| 1598 | " * @param leaf leaf needs to be selected\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1599 | " * @return builder object for select leaf\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1600 | " */\n"; |
| 1601 | return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS |
| 1602 | + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * Returns leaf identifier interface enum signature. |
| 1607 | * |
| 1608 | * @param name name of node |
| 1609 | * @return leaf identifier interface enum signature |
| 1610 | */ |
| 1611 | static String getInterfaceLeafIdEnumSignature(String name) { |
| 1612 | String start = " /**\n" + |
| 1613 | " * Identify the leaf of " + name + PERIOD + NEW_LINE + |
| 1614 | " */\n"; |
| 1615 | return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE + |
| 1616 | OPEN_CURLY_BRACKET + NEW_LINE; |
| 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * Returns interface leaf identifier enum method. |
| 1621 | * |
| 1622 | * @return interface leaf identifier enum method |
| 1623 | */ |
| 1624 | static String getInterfaceLeafIdEnumMethods() { |
| 1625 | return " private int leafIndex;\n" + |
| 1626 | "\n" + |
| 1627 | " public int getLeafIndex() {\n" + |
| 1628 | " return leafIndex;\n" + |
| 1629 | " }\n" + |
| 1630 | "\n" + |
| 1631 | " LeafIdentifier(int value) {\n" + |
| 1632 | " this.leafIndex = value;\n" + |
| 1633 | " }\n" + |
| 1634 | " }\n"; |
| 1635 | } |
| 1636 | |
| 1637 | /** |
| 1638 | * Returns getter methods for operation attributes. |
| 1639 | * |
| 1640 | * @return getter methods for operation attributes |
| 1641 | */ |
| 1642 | static String getOperationAttributesGetters() { |
| 1643 | return "\n" + |
| 1644 | " /**\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1645 | " * Returns the valueLeafFlags.\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1646 | " *\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1647 | " * @return value of valueLeafFlags\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1648 | " */\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1649 | " public BitSet getValueLeafFlags() {\n" + |
| 1650 | " return valueLeafFlags;\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1651 | " }\n" + |
| 1652 | "\n" + |
| 1653 | " /**\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1654 | " * Returns the selectLeafFlags.\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1655 | " *\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1656 | " * @return value of selectLeafFlags\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1657 | " */\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1658 | " public BitSet getSelectLeafFlags() {\n" + |
| 1659 | " return selectLeafFlags;\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1660 | " }\n" + |
| 1661 | "\n"; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
| 1665 | * Returns getter for operation type. |
| 1666 | * |
| 1667 | * @return getter for operation type |
| 1668 | */ |
| 1669 | static String getGetterForOperationType() { |
| 1670 | return " /**\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1671 | " * Returns the onosYangNodeOperationType.\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1672 | " *\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1673 | " * @return value of onosYangNodeOperationType\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1674 | " */\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1675 | " public OnosYangNodeOperationType onosYangNodeOperationType() {\n" + |
| 1676 | " return onosYangNodeOperationType;\n" + |
| 1677 | " }\n\n"; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * Returns getters for value and select leaf. |
| 1682 | * |
| 1683 | * @return getters for value and select leaf |
| 1684 | */ |
| 1685 | static String getGettersForValueAndSelectLeaf() { |
| 1686 | return "\n" + |
| 1687 | " @Override\n" + |
| 1688 | " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1689 | " return getValueLeafFlags().get(leaf.getLeafIndex());\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1690 | " }\n" + |
| 1691 | "\n" + |
| 1692 | " @Override\n" + |
| 1693 | " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1694 | " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1695 | " }\n"; |
| 1696 | } |
| 1697 | |
| 1698 | /** |
| 1699 | * Returns setter for operation type. |
| 1700 | * |
| 1701 | * @param name name of node |
| 1702 | * @return setter for operation type |
| 1703 | */ |
| 1704 | static String getSetterForOperationType(String name) { |
| 1705 | return " /**\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1706 | " * Set node operation type.\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1707 | " *\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1708 | " * @param onosYangNodeOperationType node operation type\n" + |
| 1709 | " * @return builder object for node operation type\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1710 | " */\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1711 | " public " + name + BUILDER + " onosYangNodeOperationType(OnosYangNodeOperationType " + |
| 1712 | "onosYangNodeOperationType) {\n" + |
| 1713 | " this.onosYangNodeOperationType = onosYangNodeOperationType;\n" + |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 1714 | " return this;\n" + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1715 | " }\n\n"; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | /** |
| 1719 | * Returns setter for select leaf. |
| 1720 | * |
| 1721 | * @param name name of node |
| 1722 | * @param isRootNode if root node |
| 1723 | * @return setter for select leaf |
| 1724 | */ |
| 1725 | static String getSetterForSelectLeaf(String name, boolean isRootNode) { |
| 1726 | String append = OVERRIDE; |
| 1727 | if (isRootNode) { |
| 1728 | append = EMPTY_STRING; |
| 1729 | } |
| 1730 | return "\n" + |
| 1731 | " " + append + "\n" + |
| 1732 | " public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" + |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 1733 | " getSelectLeafFlags().set(leaf.getLeafIndex());\n" + |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1734 | " return this;\n" + |
| 1735 | " }\n"; |
| 1736 | } |
Vidyashree Rama | b367047 | 2016-08-06 15:49:56 +0530 | [diff] [blame] | 1737 | |
| 1738 | private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) { |
| 1739 | String listAttr; |
| 1740 | if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) { |
| 1741 | switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) { |
| 1742 | case QUEUE: { |
| 1743 | listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET; |
| 1744 | break; |
| 1745 | } |
| 1746 | case SET: { |
| 1747 | listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET; |
| 1748 | break; |
| 1749 | } |
| 1750 | case LIST: { |
| 1751 | listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
| 1752 | break; |
| 1753 | } |
| 1754 | default: { |
| 1755 | listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
| 1756 | } |
| 1757 | } |
| 1758 | } else { |
| 1759 | listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
| 1760 | } |
| 1761 | return listAttr; |
| 1762 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1763 | } |