blob: 0ab080e656ce7b04ca7166e78fc85113cbc014c0 [file] [log] [blame]
Bharat saraswal97459962016-02-20 21:57:16 +05301/*
Brian O'Connor0f7908b2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Bharat saraswal97459962016-02-20 21:57:16 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.translator.tojava.utils;
18
Bharat saraswal250a7472016-05-12 13:16:57 +053019import java.util.List;
20import java.util.Map;
Bharat saraswale304c252016-08-16 20:56:20 +053021
Bharat saraswal039f59c2016-07-14 21:57:13 +053022import org.onosproject.yangutils.datamodel.YangAtomicPath;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053023import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
Bharat saraswalaf413b82016-07-14 15:18:20 +053024import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053025import org.onosproject.yangutils.datamodel.YangType;
janani b0e4e8ae2016-07-13 21:06:41 +053026import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053027import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053028import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
Bharat saraswal039f59c2016-07-14 21:57:13 +053029import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053030import org.onosproject.yangutils.utils.io.YangPluginConfig;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053031import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
Bharat saraswal84366c52016-03-23 19:40:35 +053032
Bharat saraswal039f59c2016-07-14 21:57:13 +053033import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
34import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
35import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053036import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
Bharat saraswal039f59c2016-07-14 21:57:13 +053037import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053038import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
39import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
40import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
Bharat saraswal039f59c2016-07-14 21:57:13 +053041import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053042import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053043import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
Bharat saraswal039f59c2016-07-14 21:57:13 +053044import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
45import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053048import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
Bharat saraswal039f59c2016-07-14 21:57:13 +053049import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
50import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
Bharat saraswal64e7e232016-07-14 23:33:55 +053051import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053052import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT;
Bharat saraswal64e7e232016-07-14 23:33:55 +053053import static org.onosproject.yangutils.utils.UtilConstants.ADD;
Bharat saraswal84366c52016-03-23 19:40:35 +053054import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
55import static org.onosproject.yangutils.utils.UtilConstants.AND;
Bharat saraswalaf413b82016-07-14 15:18:20 +053056import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053057import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +053058import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
Bharat saraswald14cbe82016-07-14 13:26:18 +053059import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
Bharat saraswal84366c52016-03-23 19:40:35 +053060import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053061import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
Bharat saraswal84366c52016-03-23 19:40:35 +053062import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
63import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053064import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053065import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
Bharat saraswal250a7472016-05-12 13:16:57 +053066import static org.onosproject.yangutils.utils.UtilConstants.CASE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053067import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
Bharat saraswal84366c52016-03-23 19:40:35 +053068import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
Bharat saraswalaf413b82016-07-14 15:18:20 +053069import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
70import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +053071import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
72import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
Bharat saraswal039f59c2016-07-14 21:57:13 +053073import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053074import static org.onosproject.yangutils.utils.UtilConstants.COLON;
Bharat saraswal84366c52016-03-23 19:40:35 +053075import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053076import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
Bharat saraswal250a7472016-05-12 13:16:57 +053077import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Bharat saraswal84366c52016-03-23 19:40:35 +053078import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
79import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +053080import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
Bharat saraswal84366c52016-03-23 19:40:35 +053081import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
Bharat saraswal64e7e232016-07-14 23:33:55 +053082import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
Bharat saraswal84366c52016-03-23 19:40:35 +053083import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
Bharat saraswal8beac342016-08-04 02:00:03 +053084import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
Bharat saraswal84366c52016-03-23 19:40:35 +053085import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
86import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053087import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
88import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
Bharat saraswal84366c52016-03-23 19:40:35 +053089import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053090import static org.onosproject.yangutils.utils.UtilConstants.FOR;
Bharat saraswal84366c52016-03-23 19:40:35 +053091import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053092import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
93import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
Bharat saraswalaf413b82016-07-14 15:18:20 +053094import static org.onosproject.yangutils.utils.UtilConstants.GET;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053095import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
Bharat saraswal84366c52016-03-23 19:40:35 +053096import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
97import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
98import static org.onosproject.yangutils.utils.UtilConstants.HASH;
99import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
100import static org.onosproject.yangutils.utils.UtilConstants.IF;
Bharat saraswal84366c52016-03-23 19:40:35 +0530101import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
102import static org.onosproject.yangutils.utils.UtilConstants.INT;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530103import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530104import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
105import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530106import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
107import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
Bharat saraswal84366c52016-03-23 19:40:35 +0530108import static org.onosproject.yangutils.utils.UtilConstants.LIST;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530109import static org.onosproject.yangutils.utils.UtilConstants.LONG;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530110import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
111import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530112import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530113import static org.onosproject.yangutils.utils.UtilConstants.MAP;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530114import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
115import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530116import static org.onosproject.yangutils.utils.UtilConstants.NEW;
117import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530118import static org.onosproject.yangutils.utils.UtilConstants.NULL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530119import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
120import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
121import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
122import static org.onosproject.yangutils.utils.UtilConstants.OF;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530123import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530124import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
125import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
Bharat saraswal8beac342016-08-04 02:00:03 +0530126import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Bharat saraswal84366c52016-03-23 19:40:35 +0530127import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
128import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530129import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
130import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
131import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
132import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
133import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
Bharat saraswal84366c52016-03-23 19:40:35 +0530134import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530135import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530136import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
137import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
Bharat saraswal84366c52016-03-23 19:40:35 +0530138import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530139import static org.onosproject.yangutils.utils.UtilConstants.PUT;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530140import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530141import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530142import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530143import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530144import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530145import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
Bharat saraswal84366c52016-03-23 19:40:35 +0530146import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530147import static org.onosproject.yangutils.utils.UtilConstants.SET;
Bharat saraswal84366c52016-03-23 19:40:35 +0530148import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
Bharat saraswal8beac342016-08-04 02:00:03 +0530149import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530150import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530151import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
152import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530153import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530154import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530155import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
156import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530157import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
158import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
Bharat saraswal84366c52016-03-23 19:40:35 +0530159import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
160import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
161import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
Bharat saraswal250a7472016-05-12 13:16:57 +0530162import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
Bharat saraswal84366c52016-03-23 19:40:35 +0530163import static org.onosproject.yangutils.utils.UtilConstants.THIS;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530164import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530165import static org.onosproject.yangutils.utils.UtilConstants.TO;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530166import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530167import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530168import static org.onosproject.yangutils.utils.UtilConstants.TRY;
Bharat saraswal84366c52016-03-23 19:40:35 +0530169import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530170import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
171import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530172import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
173import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
174import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
175import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
176import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530177import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530178import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
Bharat saraswal84366c52016-03-23 19:40:35 +0530179import static org.onosproject.yangutils.utils.UtilConstants.VOID;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530180import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530181import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530182import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
Bharat saraswal84366c52016-03-23 19:40:35 +0530183import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
184import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
185import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530186import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530187import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530188import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530189import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530190import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530191import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530192import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530193import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530194import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530195import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530196import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530197import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530198import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
199import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
200import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
Bharat saraswal84366c52016-03-23 19:40:35 +0530201import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
Bharat saraswal97459962016-02-20 21:57:16 +0530202
203/**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530204 * Represents generator for methods of generated files based on the file type.
Bharat saraswal97459962016-02-20 21:57:16 +0530205 */
206public final class MethodsGenerator {
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530207 private static final String BITS_STRING_ARRAY_VAR = "bitsTemp";
208 private static final String BIT_TEMP_VAR = "bitTemp";
Bharat saraswal97459962016-02-20 21:57:16 +0530209
Bharat saraswal97459962016-02-20 21:57:16 +0530210 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530211 * Creates an instance of method generator.
Bharat saraswal97459962016-02-20 21:57:16 +0530212 */
213 private MethodsGenerator() {
214 }
215
216 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530217 * Returns the methods strings for builder interface.
218 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530219 * @param name attribute name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530220 * @param pluginConfig plugin configurations
Vinod Kumar S08710982016-03-03 19:55:30 +0530221 * @return method string for builder interface
Bharat saraswal97459962016-02-20 21:57:16 +0530222 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530223 public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530224 return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
Bharat saraswal97459962016-02-20 21:57:16 +0530225 }
226
227 /**
228 * Returns getter string.
229 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530230 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530231 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530232 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530233 * @return getter string
234 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530235 public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530236 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530237
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530238 String returnType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530239 String attributeName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +0530240 String appDataStructure = null;
241 if (attr.getCompilerAnnotation() != null) {
242 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
243 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530244 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
245 return generateForGetMethodWithAttribute(returnType)
Vidyashree Ramab3670472016-08-06 15:49:56 +0530246 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
247 attr.getCompilerAnnotation());
Bharat saraswal8beac342016-08-04 02:00:03 +0530248 }
Vinod Kumar S08710982016-03-03 19:55:30 +0530249
Vidyashree Ramab3670472016-08-06 15:49:56 +0530250 return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
251 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
252 attr.getCompilerAnnotation());
Bharat saraswal97459962016-02-20 21:57:16 +0530253 }
254
255 /**
256 * Returns setter string.
257 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530258 * @param attr attribute info
259 * @param className java class name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530260 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530261 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530262 * @return setter string
263 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530264 public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530265 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530266
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530267 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530268 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530269 JavaDocGen.JavaDocType type;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530270 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530271 type = MANAGER_SETTER_METHOD;
272 } else {
273 type = SETTER_METHOD;
274 }
Bharat saraswal97459962016-02-20 21:57:16 +0530275
Vidyashree Ramab3670472016-08-06 15:49:56 +0530276 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 saraswal97459962016-02-20 21:57:16 +0530283 }
284
285 /**
286 * Returns constructor method string.
287 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530288 * @param name class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530289 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530290 * @return constructor string
291 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530292 private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530293 return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
Bharat saraswal97459962016-02-20 21:57:16 +0530294 }
295
296 /**
297 * Returns default constructor method string.
298 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530299 * @param name class name
Bharat saraswal022dae92016-03-04 20:08:09 +0530300 * @param modifierType modifier type
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530301 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530302 * @return default constructor string
303 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530304 public static String getDefaultConstructorString(String name, String modifierType,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530305 YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530306 return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
307 + getDefaultConstructor(name, modifierType) + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530308 }
309
310 /**
311 * Returns check not null string.
312 *
313 * @param name attribute name
314 * @return check not null string
315 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530316 static String getCheckNotNull(String name) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530317 return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
318 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530319 }
320
321 /**
322 * Returns build method string.
323 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530324 * @param name class name
325 * @param isRootNode if root node
Bharat saraswal97459962016-02-20 21:57:16 +0530326 * @return build string
327 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530328 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 saraswal97459962016-02-20 21:57:16 +0530333 }
334
335 /**
336 * Returns the getter method strings for class file.
337 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530338 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530339 * @param generatedJavaFiles for the type of java file being generated
Vinod Kumar S08710982016-03-03 19:55:30 +0530340 * @return getter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530341 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530342 public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530343
Bharat saraswal8beac342016-08-04 02:00:03 +0530344 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530345 String attributeName = attr.getAttributeName();
Bharat saraswal022dae92016-03-04 20:08:09 +0530346
347 if (!attr.isListAttr()) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530348 return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530349 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530350 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
351 return getGetter(attrParam, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530352 }
353
354 /**
355 * Returns getter for attribute.
356 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530357 * @param type return type
358 * @param name attribute name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530359 * @param generatedJavaFiles generated java files
Bharat saraswal022dae92016-03-04 20:08:09 +0530360 * @return getter for attribute
361 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530362 static String getGetter(String type, String name, int generatedJavaFiles) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530363 String ret = parseTypeForReturnValue(type);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530364 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530365 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530366 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
367 EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530368 RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530369 } 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 saraswal97459962016-02-20 21:57:16 +0530375 }
376
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530377 /*Provides string to return for type.*/
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530378 private static String parseTypeForReturnValue(String type) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530379 switch (type) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530380 case BYTE:
381 case INT:
382 case SHORT:
383 case LONG:
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530384 case DOUBLE:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530385 return "0";
386 case BOOLEAN_DATA_TYPE:
387 return FALSE;
388 default:
389 return null;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530390 }
391 }
392
Bharat saraswal97459962016-02-20 21:57:16 +0530393 /**
394 * Returns the setter method strings for class file.
395 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530396 * @param attr attribute info
397 * @param className name of the class
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530398 * @param generatedJavaFiles generated java files
Vinod Kumar S08710982016-03-03 19:55:30 +0530399 * @return setter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530400 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530401 public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530402 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530403 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530404 boolean isTypeNull = false;
405 if (attr.getAttributeType() == null) {
406 isTypeNull = true;
Bharat saraswal022dae92016-03-04 20:08:09 +0530407 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530408 if (!attr.isListAttr()) {
409 return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
410 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530411 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
412 return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
Bharat saraswal022dae92016-03-04 20:08:09 +0530413 }
414
415 /**
416 * Returns setter for attribute.
417 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530418 * @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 saraswal022dae92016-03-04 20:08:09 +0530423 * @return setter for attribute
424 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530425 private static String getSetter(String className, String name, String type, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530426 boolean isTypeNull, boolean isList) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530427 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530428 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
janani b703cfe42016-05-17 13:12:22 +0530429 + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530430 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
431 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530432 } 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-Huawei6266db32016-05-10 17:58:57 +0530437 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +0530438 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530439 name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
Bharat saraswal8beac342016-08-04 02:00:03 +0530440 + 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 saraswal715d3fc2016-05-17 19:59:16 +0530448 + 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-Huawei6266db32016-05-10 17:58:57 +0530450 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530451
452 }
453
454 //Returns value leaf flag setter.
455 private static String getValueLeafSetString(String name) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530456 return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
Bharat saraswal97459962016-02-20 21:57:16 +0530457 }
458
459 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530460 * Returns the setter method strings for class file.
461 *
462 * @param attr attribute info
463 * @return setter method for class
464 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530465 static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530466
Bharat saraswal8beac342016-08-04 02:00:03 +0530467 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530468 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530469 return getTypeDefSetter(attrQualifiedType, attributeName);
Bharat saraswal022dae92016-03-04 20:08:09 +0530470 }
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 b703cfe42016-05-17 13:12:22 +0530480 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name)
Bharat saraswal84366c52016-03-23 19:40:35 +0530481 + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +0530482 + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN +
483 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530484 }
485
486 /**
487 * Returns override string.
488 *
489 * @return override string
490 */
491 public static String getOverRideString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530492 return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530493 }
494
495 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530496 * Returns the getter method strings for interface file.
497 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530498 * @param yangName name of the attribute
499 * @param returnType return type of attribute
500 * @param isList is list attribute
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530501 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530502 * @param compilerAnnotation compiler annotation
Vinod Kumar S08710982016-03-03 19:55:30 +0530503 * @return getter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530504 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530505 static String getGetterForInterface(String yangName, String returnType, boolean isList,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530506 int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530507 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530508 return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530509 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530510 String listAttr = getListAttribute(returnType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530511 return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530512 }
513
514 /**
515 * Returns getter for attribute in interface.
516 *
517 * @param returnType return type
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530518 * @param yangName attribute name
Bharat saraswal022dae92016-03-04 20:08:09 +0530519 * @return getter for interface
520 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530521 private static String getGetterInterfaceString(String returnType, String yangName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530522 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530523 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530524 return getGetMethodWithArgument(returnType, yangName);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530525 } else {
526 return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
527 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
528 }
Bharat saraswal97459962016-02-20 21:57:16 +0530529 }
530
531 /**
532 * Returns the setter method strings for interface file.
533 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530534 * @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-Huawei6266db32016-05-10 17:58:57 +0530538 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530539 * @param compilerAnnotation compiler annotations
Vinod Kumar S08710982016-03-03 19:55:30 +0530540 * @return setter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530541 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530542 static String getSetterForInterface(String attrName, String attrType, String className,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530543 boolean isList, int generatedJavaFiles,
544 YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530545 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530546 return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530547 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530548
549 String listAttr = getListAttribute(attrType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530550 return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530551 }
552
553 /**
554 * Returns setter string for interface.
555 *
556 * @param className class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530557 * @param attrName attribute name
558 * @param attrType attribute type
Bharat saraswal022dae92016-03-04 20:08:09 +0530559 * @return setter string
560 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530561 private static String getSetterInterfaceString(String className, String attrName, String attrType,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530562 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530563 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530564 return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530565 + OPEN_PARENTHESIS + attrType + OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530566 } else {
567 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
568 + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
569 }
Bharat saraswal97459962016-02-20 21:57:16 +0530570 }
571
572 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530573 * Returns list string.
574 *
575 * @return list string
576 */
577 private static String getListString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530578 return LIST + DIAMOND_OPEN_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530579 }
580
581 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530582 * Returns return type for attribute.
583 *
584 * @param attr attribute info
585 * @return return type
586 */
587 private static String getReturnType(JavaAttributeInfo attr) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530588 String returnType = EMPTY_STRING;
Vidyashree Rama13960652016-04-26 15:06:06 +0530589 if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530590 returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530591 }
592 returnType = returnType + attr.getImportInfo().getClassInfo();
593 return returnType;
594 }
595
596 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530597 * Returns the build method strings for interface file.
598 *
Vinod Kumar S08710982016-03-03 19:55:30 +0530599 * @param yangName name of the interface
600 * @return build method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530601 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530602 static String getBuildForInterface(String yangName) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530603 return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
604 + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530605 }
606
607 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530608 * Returns constructor string for impl class.
609 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530610 * @param yangName class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530611 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +0530612 * @param isRootNode if root node
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530613 * @return constructor string
614 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530615 static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530616 String javadoc = getConstructorString(yangName, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +0530617
618 String returnType = getCapitalCase(DEFAULT) + yangName;
619 if (isRootNode) {
620 returnType = yangName + OP_PARAM;
621 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530622 String constructor = FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
Bharat saraswald14cbe82016-07-14 13:26:18 +0530623 OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
624 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530625 return javadoc + constructor;
626 }
627
628 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530629 * Returns the constructor strings for class file.
630 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530631 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530632 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530633 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530634 * @return constructor for class
635 */
Bharat saraswald14cbe82016-07-14 13:26:18 +0530636 public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530637 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530638
janani b703cfe42016-05-17 13:12:22 +0530639 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530640 String constructor;
Bharat saraswal84366c52016-03-23 19:40:35 +0530641
Bharat saraswal64e7e232016-07-14 23:33:55 +0530642 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530643 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-Huawei6266db32016-05-10 17:58:57 +0530648 } else {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530649 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-Huawei6266db32016-05-10 17:58:57 +0530654 }
Bharat saraswal022dae92016-03-04 20:08:09 +0530655 return constructor;
Bharat saraswal97459962016-02-20 21:57:16 +0530656 }
657
658 /**
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530659 * Returns the rpc strings for service interface.
660 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530661 * @param rpcName name of the rpc
662 * @param inputName name of input
663 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530664 * @param pluginConfig plugin configurations
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530665 * @return rpc method string
666 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530667 public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530668 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530669
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530670 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530671 if (!inputName.equals(EMPTY_STRING)) {
672 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530673 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530674 return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
675 + CLOSE_PARENTHESIS + SEMI_COLAN;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530676 }
677
678 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530679 * Returns the rpc strings for manager impl.
680 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530681 * @param rpcName name of the rpc
682 * @param inputName name of input
683 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530684 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530685 * @return rpc method string
686 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530687 public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530688 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530689
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530690 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530691 if (!inputName.equals(EMPTY_STRING)) {
692 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530693 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530694
Bharat saraswald14cbe82016-07-14 13:26:18 +0530695 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-Huawei6266db32016-05-10 17:58:57 +0530698 if (!outputName.contentEquals(VOID)) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530699 method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
700 + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530701 }
702 method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530703
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530704 return method;
705 }
706
707 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530708 * Returns the build method strings for class file.
709 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530710 * @param yangName class name
711 * @param isRootNode if root node
Vinod Kumar S08710982016-03-03 19:55:30 +0530712 * @return build method string for class
Bharat saraswal97459962016-02-20 21:57:16 +0530713 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530714 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 saraswald14cbe82016-07-14 13:26:18 +0530721 + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
Bharat saraswal8beac342016-08-04 02:00:03 +0530722 type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
Bharat saraswald14cbe82016-07-14 13:26:18 +0530723 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal97459962016-02-20 21:57:16 +0530724 }
725
726 /**
727 * Returns the Default constructor strings for class file.
728 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530729 * @param name name of the class
Bharat saraswal022dae92016-03-04 20:08:09 +0530730 * @param modifierType modifier type for default constructor
Bharat saraswal97459962016-02-20 21:57:16 +0530731 * @return Default constructor for class
732 */
Bharat saraswal022dae92016-03-04 20:08:09 +0530733 private static String getDefaultConstructor(String name, String modifierType) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530734 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 saraswal97459962016-02-20 21:57:16 +0530736 }
737
Bharat saraswal022dae92016-03-04 20:08:09 +0530738 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530739 * Returns to string method's open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530740 *
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530741 * @return string method's open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530742 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530743 static String getToStringMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530744 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 saraswal022dae92016-03-04 20:08:09 +0530747 }
748
749 /**
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530750 * 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-Huawei9a91b482016-08-19 23:22:59 +0530755 static boolean isPrimitiveDataType(YangDataTypes dataType) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530756 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 saraswal039f59c2016-07-14 21:57:13 +0530765 || dataType == BOOLEAN
766 || dataType == EMPTY;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530767
768 }
769
Bharat saraswal64e7e232016-07-14 23:33:55 +0530770
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530771 static String getIfConditionBegin(String indentation, String condition) {
772 return indentation + IF + SPACE + OPEN_PARENTHESIS + condition + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
Bharat saraswal8beac342016-08-04 02:00:03 +0530773 + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530774 }
775
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530776 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 saraswal039f59c2016-07-14 21:57:13 +0530787 }
788
Bharat saraswal039f59c2016-07-14 21:57:13 +0530789 /*
Bharat saraswal8beac342016-08-04 02:00:03 +0530790 * Returns omit null value string.
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530791 *
792 * @return omit null value string
793 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530794 static String getOmitNullValueString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530795 return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
796 }
797
798 /**
799 * Returns to string method's close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530800 *
801 * @return to string method close string
802 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530803 static String getToStringMethodClose() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530804 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 saraswal022dae92016-03-04 20:08:09 +0530806 }
807
808 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530809 * Returns to string method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530810 *
811 * @param attr attribute info
812 * @return to string method
813 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530814 public static String getToStringMethod(JavaAttributeInfo attr) {
815
janani b703cfe42016-05-17 13:12:22 +0530816 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +0530817 return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
818 + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530819 }
820
821 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530822 * Returns from string method's open string.
823 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530824 * @param className name of the class
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530825 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530826 * @return from string method's open string
827 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530828 static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530829 return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530830 + 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 Agrawal97a5e1c2016-04-18 18:53:11 +0530833 }
834
835 /**
836 * Return from string method's close string.
837 *
838 * @return from string method's close string
839 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530840 static String getFromStringMethodClose() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530841 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 Agrawalbfce9342016-06-15 13:58:01 +0530848 * @param attr attribute info
Bharat saraswal039f59c2016-07-14 21:57:13 +0530849 * @param fromStringAttributeInfo attribute info for the from string wrapper type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530850 * @return from string method's body string
851 */
852 public static String getFromStringMethod(JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530853 JavaAttributeInfo fromStringAttributeInfo) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530854
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530855 return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
Mahesh Poojary S6986df32016-07-19 10:58:07 +0530856 + getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530857 + 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 saraswal8beac342016-08-04 02:00:03 +0530866 private static String getTrySubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530867 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 saraswal8beac342016-08-04 02:00:03 +0530875 private static String getReturnOfSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530876 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 saraswal8beac342016-08-04 02:00:03 +0530884 private static String getCatchSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530885 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 saraswal2da23bf2016-08-25 15:28:39 +0530896 JavaAttributeInfo fromStringAttributeInfo) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530897
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530898 String targetDataType = getReturnType(attr);
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530899 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 Huawei2cd44332016-07-14 12:38:17 +0530927 } else {
928 String parseFromStringMethod = getParseFromStringMethod(targetDataType,
Bharat saraswal039f59c2016-07-14 21:57:13 +0530929 fromStringAttributeInfo.getAttributeType());
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530930 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530931 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530932 }
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530933 }
934
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530935 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530936 * Returns hash code method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530937 *
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530938 * @return hash code method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530939 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530940 static String getHashCodeMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530941 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
Bharat saraswal8beac342016-08-04 02:00:03 +0530942 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
943 EIGHT_SPACE_INDENTATION
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530944 + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530945 }
946
947 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530948 * Returns hash code methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530949 *
950 * @param hashcodeString hash code string
951 * @return to hash code method close string
952 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530953 static String getHashCodeMethodClose(String hashcodeString) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530954 hashcodeString = trimAtLast(hashcodeString, COMMA);
955 hashcodeString = trimAtLast(hashcodeString, SPACE);
Bharat saraswal8beac342016-08-04 02:00:03 +0530956 return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
957 CLOSE_CURLY_BRACKET
Bharat saraswal84366c52016-03-23 19:40:35 +0530958 + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530959 }
960
961 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530962 * Returns hash code method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530963 *
964 * @param attr attribute info
965 * @return hash code method
966 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530967 public static String getHashCodeMethod(JavaAttributeInfo attr) {
janani b703cfe42016-05-17 13:12:22 +0530968 return attr.getAttributeName() + COMMA + SPACE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530969 }
970
971 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530972 * Returns equals method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530973 *
974 * @param className class name
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530975 * @return equals method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530976 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530977 static String getEqualsMethodOpen(String className) {
978 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE +
979 EQUALS_STRING
Bharat saraswal84366c52016-03-23 19:40:35 +0530980 + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
981 + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
Bharat saraswal022dae92016-03-04 20:08:09 +0530982 }
983
984 /**
985 * Returns equal methods if condition string.
986 *
987 * @return if condition string
988 */
989 private static String getEqualsMethodsCommonIfCondition() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530990 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 saraswal022dae92016-03-04 20:08:09 +0530993 }
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 saraswal84366c52016-03-23 19:40:35 +05301002 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 saraswal022dae92016-03-04 20:08:09 +05301006 }
1007
1008 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301009 * Returns equals methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +05301010 *
1011 * @param equalMethodString equal method string
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301012 * @return equals method close string
Bharat saraswal022dae92016-03-04 20:08:09 +05301013 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301014 static String getEqualsMethodClose(String equalMethodString) {
Bharat saraswal84366c52016-03-23 19:40:35 +05301015 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 saraswal022dae92016-03-04 20:08:09 +05301022 }
1023
1024 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301025 * Returns equals method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +05301026 *
1027 * @param attr attribute info
1028 * @return equals method
1029 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +05301030 public static String getEqualsMethod(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301031
janani b703cfe42016-05-17 13:12:22 +05301032 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +05301033 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 saraswal022dae92016-03-04 20:08:09 +05301036 }
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 saraswal8beac342016-08-04 02:00:03 +05301045 static String getOfMethod(String name, JavaAttributeInfo attr) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301046 String attrQualifiedType = getReturnType(attr);
Bharat saraswal84366c52016-03-23 19:40:35 +05301047 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301048 + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal84366c52016-03-23 19:40:35 +05301049 + 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 saraswal022dae92016-03-04 20:08:09 +05301051 }
1052
Bharat saraswale2bc60d2016-04-16 02:28:25 +05301053 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301054 * Returns of method's string and java doc for special type.
1055 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301056 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301057 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301058 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301059 * @return of method's string and java doc for special type
1060 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301061 public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301062 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301063
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301064 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301065 String attrName = attr.getAttributeName();
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301066
Vidyashree Ramab3670472016-08-06 15:49:56 +05301067 return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301068 + getOfMethodString(attrType, generatedJavaClassName);
1069 }
1070
1071 /**
1072 * Returns of method's string.
1073 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301074 * @param type data type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301075 * @param className class name
1076 * @return of method's string
1077 */
1078 private static String getOfMethodString(String type, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301079 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 Agrawalbfce9342016-06-15 13:58:01 +05301088 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301089 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301090 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301091 * @return string and java doc for constructor of type class
1092 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301093 public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301094 String generatedJavaClassName,
1095 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301096
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301097 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301098 String attrName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301099 return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301100 + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
1101 }
1102
1103 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301104 * 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 saraswal8beac342016-08-04 02:00:03 +05301111 * @param addFirst whether int came first or uInt came first
Bharat saraswal64e7e232016-07-14 23:33:55 +05301112 * @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 saraswal2da23bf2016-08-25 15:28:39 +05301116 boolean addFirst) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301117
Bharat saraswal64e7e232016-07-14 23:33:55 +05301118 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 Ramab3670472016-08-06 15:49:56 +05301128 String appDataStructure = null;
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301129 if (attr1 != null && attr1.getCompilerAnnotation() != null) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301130 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 saraswal64e7e232016-07-14 23:33:55 +05301135 }
1136
1137 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301138 * Returns type constructor string.
1139 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301140 * @param type data type
1141 * @param name attribute name
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301142 * @param className class name
1143 * @return type constructor string
1144 */
1145 private static String getTypeConstructorString(String type, String name, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301146 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 saraswal64e7e232016-07-14 23:33:55 +05301153 * 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 saraswal2da23bf2016-08-25 15:28:39 +05301161 ValidatorTypeForUnionTypes validatorType, boolean addInt) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301162
Bharat saraswal64e7e232016-07-14 23:33:55 +05301163 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 saraswal8beac342016-08-04 02:00:03 +05301176 constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
Bharat saraswal64e7e232016-07-14 23:33:55 +05301177 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 saraswal8beac342016-08-04 02:00:03 +05301189 * 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 saraswalaf413b82016-07-14 15:18:20 +05301200 * Returns implementation of add augmentation.
1201 *
1202 * @return implementation of add augmentation
1203 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301204 static String getAddAugmentInfoMethodImpl() {
Bharat saraswal8beac342016-08-04 02:00:03 +05301205 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
1206 ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301207 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 saraswalaf413b82016-07-14 15:18:20 +05301210 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1211 CLOSE_CURLY_BRACKET + NEW_LINE;
1212 }
1213
1214 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301215 * Returns interface of get YANG augment info.
Bharat saraswalaf413b82016-07-14 15:18:20 +05301216 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301217 * @return interface of get YANG augment info
Bharat saraswalaf413b82016-07-14 15:18:20 +05301218 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301219 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 saraswalaf413b82016-07-14 15:18:20 +05301224
Bharat saraswal8beac342016-08-04 02:00:03 +05301225 /**
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 saraswalaf413b82016-07-14 15:18:20 +05301234 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 saraswal8beac342016-08-04 02:00:03 +05301241 * Returns implementation of get YANG augment info.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301242 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301243 * @return implementation of get YANG augment info
Bharat saraswal039f59c2016-07-14 21:57:13 +05301244 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301245 static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301246 return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null)
Bharat saraswal8beac342016-08-04 02:00:03 +05301247 + 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 saraswal039f59c2016-07-14 21:57:13 +05301260 + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
1261 MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
Bharat saraswal8beac342016-08-04 02:00:03 +05301262 DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
1263 getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301264 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 saraswal68fa0d12016-04-19 01:00:16 +05301270 * Returns enum's constructor.
1271 *
1272 * @param className enum's class name
1273 * @return enum's constructor
1274 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301275 static String getEnumsConstructor(String className) {
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301276 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 saraswal250a7472016-05-12 13:16:57 +05301280
1281 /**
1282 * Returns of method for enum class.
1283 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301284 * @param className class name
1285 * @param attr java attribute
1286 * @param enumMap enum's sets map
1287 * @param enumList enum's sets list
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301288 * @param pluginConfig plugin configurations
Bharat saraswal250a7472016-05-12 13:16:57 +05301289 * @return of method
1290 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301291 static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301292 Map<String, Integer> enumMap, List<String> enumList,
1293 YangPluginConfig pluginConfig) {
Bharat saraswal250a7472016-05-12 13:16:57 +05301294 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301295 String attrName = attr.getAttributeName();
Bharat saraswal250a7472016-05-12 13:16:57 +05301296
janani b703cfe42016-05-17 13:12:22 +05301297 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE
1298 + OF + OPEN_PARENTHESIS
Bharat saraswal250a7472016-05-12 13:16:57 +05301299 + 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 saraswal8beac342016-08-04 02:00:03 +05301302 int value;
Bharat saraswal250a7472016-05-12 13:16:57 +05301303 for (String str : enumList) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301304
Bharat saraswal250a7472016-05-12 13:16:57 +05301305 value = enumMap.get(str);
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301306 method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
janani b703cfe42016-05-17 13:12:22 +05301307 + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
Bharat saraswal250a7472016-05-12 13:16:57 +05301308 + str + SEMI_COLAN + NEW_LINE;
1309 }
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301310 method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
Bharat saraswal250a7472016-05-12 13:16:57 +05301311 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1312 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1313
Vidyashree Ramab3670472016-08-06 15:49:56 +05301314 return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig, null)
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301315 + method;
Bharat saraswal250a7472016-05-12 13:16:57 +05301316 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301317
1318 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301319 * Returns from string method parsed string.
1320 *
1321 * @param targetDataType target data type
1322 * @param yangType YANG type
1323 * @return parsed string
1324 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301325 private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301326 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 Huawei2cd44332016-07-14 12:38:17 +05301345 case DECIMAL64:
1346 return NEW + SPACE + BIG_DECIMAL;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301347 case STRING:
Shankara-Huaweib7564772016-08-02 18:13:13 +05301348 case IDENTITYREF:
1349 return EMPTY_STRING;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301350 case EMPTY:
1351 case BOOLEAN:
1352 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301353 case BITS:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301354 case UNION:
1355 case ENUMERATION:
1356 case DERIVED:
1357 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
1358 default:
1359 throw new TranslatorException("given data type is not supported.");
1360 }
1361 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301362
1363 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301364 * Returns augmented data getter and setter methods for service class.
1365 *
1366 * @param parent parent node
1367 * @return augmented data getter and setter methods for service class
1368 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301369 static String getAugmentsDataMethodForService(YangNode parent) {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301370 List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
1371 YangNode augmentedNode;
1372 String curNodeName;
1373 String method;
1374 StringBuilder methods = new StringBuilder();
1375 String parentName;
1376 String returnType;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301377 YangNode methodNode;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301378 YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
1379 for (YangAtomicPath nodeId : targets) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301380 augmentedNode = nodeId.getResolvedNode().getParent();
Bharat saraswal64e7e232016-07-14 23:33:55 +05301381 methodNode = nodeId.getResolvedNode();
1382 if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) {
1383 curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +05301384 } else {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301385 curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig
Bharat saraswalaf413b82016-07-14 15:18:20 +05301386 .getConflictResolver()));
1387 }
1388 returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301389 parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +05301390 method = generateForGetMethodWithAttribute(returnType)
1391 + getGetMethodWithArgument(returnType, AUGMENTED + parentName
1392 + getCapitalCase(curNodeName)) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301393 methods.append(method);
1394
1395 method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
Vidyashree Ramab3670472016-08-06 15:49:56 +05301396 getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301397 getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
Vidyashree Ramab3670472016-08-06 15:49:56 +05301398 getCapitalCase(curNodeName), returnType, parentName, false,
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301399 GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301400 methods.append(method);
1401 }
1402 return methods.toString();
1403 }
1404
1405 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301406 * Returns validator method for range in union class.
1407 *
1408 * @param type type
1409 * @return validator method for range in union class
1410 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301411 static String getRangeValidatorMethodForUnion(String type) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301412 String newType;
1413 if (type.contentEquals(BIG_INTEGER)) {
1414 newType = LONG;
1415 } else {
1416 newType = INT;
1417 }
1418 String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
1419 SPACE +
1420 VALIDATE_RANGE +
1421 OPEN_PARENTHESIS
1422 + type + SPACE + MIN_RANGE + COMMA + SPACE + type + SPACE + MAX_RANGE + COMMA + SPACE +
1423 newType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1424 if (type.contentEquals(BIG_INTEGER)) {
1425 method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE + getSmallCase(BIG_INTEGER)
1426 + SPACE + EQUAL + SPACE + NEW + SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
1427 QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
1428 EIGHT_SPACE_INDENTATION + RETURN + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo"
1429 + OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SPACE + AND +
1430 AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
1431 CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SEMI_COLAN + NEW_LINE;
1432 } else {
1433 method = method + EIGHT_SPACE_INDENTATION
1434 + RETURN + SPACE + VALUE + SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE + SPACE + AND +
1435 AND + SPACE + VALUE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE + SEMI_COLAN + NEW_LINE;
1436 }
1437 return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1438 }
1439
1440 /**
1441 * Returns if condition string for typedef constructor.
1442 *
1443 * @param type type of conflict
1444 * @param addFirst true int/long need to be added first
1445 * @return if condition string for typedef constructor
1446 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301447 private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301448 String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS;
1449
1450 if (type == INT_TYPE_CONFLICT) {
1451 if (addFirst) {
1452 condition = condition + INT_MIN_RANGE + COMMA + SPACE + INT_MAX_RANGE + COMMA + SPACE + VALUE;
1453 } else {
1454 condition = condition + UINT_MIN_RANGE + COMMA + SPACE + UINT_MAX_RANGE + COMMA + SPACE + VALUE;
1455 }
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301456 } else if (type == SHORT_TYPE_CONFLICT) {
1457 if (addFirst) {
1458 condition = condition + SHORT_MIN_RANGE + COMMA + SPACE + SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
1459 } else {
1460 condition = condition + UINT8_MIN_RANGE + COMMA + SPACE + UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
1461 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301462 } else {
1463 if (addFirst) {
1464 condition = condition + LONG_MIN_RANGE + COMMA + SPACE + LONG_MAX_RANGE + COMMA + SPACE + VALUE;
1465 } else {
1466 condition = condition + ULONG_MIN_RANGE + COMMA + SPACE + ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
1467 }
1468 }
1469 return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1470 }
1471
Bharat saraswal8beac342016-08-04 02:00:03 +05301472 //Get method with arguments.
1473 private static String getGetMethodWithArgument(String returnType, String yangName) {
1474 return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
1475 + OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS +
1476 SEMI_COLAN;
1477 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301478
Bharat saraswal8beac342016-08-04 02:00:03 +05301479 /**
1480 * Returns add to list method interface.
1481 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301482 * @param attr java attribute
1483 * @param className name of the class
Bharat saraswal8beac342016-08-04 02:00:03 +05301484 * @return add to list method interface
1485 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301486 public static String getAddToListMethodInterface(JavaAttributeInfo attr, String className) {
1487 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + ADD_STRING + getCapitalCase(TO) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301488 getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE +
1489 VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
1490 }
1491
1492 /**
1493 * Returns add to list method impl.
1494 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301495 * @param attr java attribute
1496 * @param generatedJavaClassName class name
1497 * @param isRoot is root
Bharat saraswal8beac342016-08-04 02:00:03 +05301498 * @return add to list method impl
1499 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301500 public static String getAddToListMethodImpl(JavaAttributeInfo attr, String generatedJavaClassName, boolean isRoot) {
1501 String retString = "";
1502 if (!isRoot) {
1503 retString = getOverRideString();
1504 }
1505 return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + generatedJavaClassName + BUILDER + SPACE +
1506 ADD_STRING +
Bharat saraswal8beac342016-08-04 02:00:03 +05301507 getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
1508 getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
1509 + NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
1510 + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301511 NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN +
Bharat saraswal8beac342016-08-04 02:00:03 +05301512 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1513 }
1514
1515 /**
1516 * Returns builder method for class.
1517 *
1518 * @param name name of class
1519 * @return builder method for class
1520 */
1521 static String builderMethod(String name) {
1522 return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
1523 + name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
1524 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name +
1525 BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1526 CLOSE_CURLY_BRACKET;
1527 }
1528
1529 /**
1530 * Returns is filter content match interface.
1531 *
1532 * @param name name of node
1533 * @return is filter content match interface
1534 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301535 static String processSubtreeFilteringInterface(String name) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301536 String method = " /**\n" +
1537 " * Checks if the passed " + name + " maps the content match query condition.\n" +
1538 " *\n" +
1539 " * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" +
1540 " for" +
1541 " content match\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301542 " * @param isSelectAllSchemaChild is select all schema child\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301543 " * @return match result\n" +
1544 " */\n";
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301545 return method + FOUR_SPACE_INDENTATION + name + SPACE + PROCESS_SUBTREE_FILTERING +
1546 OPEN_PARENTHESIS
1547 + name + SPACE + getSmallCase(name) + COMMA + SPACE + BOOLEAN_DATA_TYPE + SPACE +
1548 "isSelectAllSchemaChild" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +05301549 }
1550
1551 /**
1552 * Returns is value set interface.
1553 *
1554 * @return is value set interface
1555 */
1556 static String isLeafValueSetInterface() {
1557 String method = " /**\n" +
1558 " * Checks if the leaf value is set.\n" +
1559 " *\n" +
1560 " * @param leaf leaf whose value status needs to checked\n" +
1561 " * @return result of leaf value set in object\n" +
1562 " */\n";
1563 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS
1564 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1565 }
1566
1567 /**
1568 * Returns is select leaf set interface.
1569 *
1570 * @return is select leaf set interface
1571 */
1572 static String isSelectLeafSetInterface() {
1573 String method = " /**\n" +
1574 " * Checks if the leaf is set to be a selected leaf.\n" +
1575 " *\n" +
1576 " * @param leaf if leaf needs to be selected\n" +
1577 " * @return result of leaf value set in object\n" +
1578 " */\n";
1579 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS
1580 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1581 }
1582
1583 /**
1584 * Returns set select leaf set interface.
1585 *
1586 * @param name node name
1587 * @return set select leaf set interface
1588 */
1589 static String setSelectLeafSetInterface(String name) {
1590 String method = " /**\n" +
1591 " * Set a leaf to be selected.\n" +
1592 " *\n" +
1593 " * @param leaf leaf needs to be selected\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301594 " * @return builder object for select leaf\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301595 " */\n";
1596 return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS
1597 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1598 }
1599
1600 /**
1601 * Returns leaf identifier interface enum signature.
1602 *
1603 * @param name name of node
1604 * @return leaf identifier interface enum signature
1605 */
1606 static String getInterfaceLeafIdEnumSignature(String name) {
1607 String start = " /**\n" +
1608 " * Identify the leaf of " + name + PERIOD + NEW_LINE +
1609 " */\n";
1610 return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE +
1611 OPEN_CURLY_BRACKET + NEW_LINE;
1612 }
1613
1614 /**
1615 * Returns interface leaf identifier enum method.
1616 *
1617 * @return interface leaf identifier enum method
1618 */
1619 static String getInterfaceLeafIdEnumMethods() {
1620 return " private int leafIndex;\n" +
1621 "\n" +
1622 " public int getLeafIndex() {\n" +
1623 " return leafIndex;\n" +
1624 " }\n" +
1625 "\n" +
1626 " LeafIdentifier(int value) {\n" +
1627 " this.leafIndex = value;\n" +
1628 " }\n" +
1629 " }\n";
1630 }
1631
1632 /**
1633 * Returns getter methods for operation attributes.
1634 *
1635 * @return getter methods for operation attributes
1636 */
1637 static String getOperationAttributesGetters() {
1638 return "\n" +
1639 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301640 " * Returns the valueLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301641 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301642 " * @return value of valueLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301643 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301644 " public BitSet getValueLeafFlags() {\n" +
1645 " return valueLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301646 " }\n" +
1647 "\n" +
1648 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301649 " * Returns the selectLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301650 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301651 " * @return value of selectLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301652 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301653 " public BitSet getSelectLeafFlags() {\n" +
1654 " return selectLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301655 " }\n" +
1656 "\n";
1657 }
1658
1659 /**
1660 * Returns getter for operation type.
1661 *
1662 * @return getter for operation type
1663 */
1664 static String getGetterForOperationType() {
1665 return " /**\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301666 " * Returns the onosYangNodeOperationType.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301667 " *\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301668 " * @return value of onosYangNodeOperationType\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301669 " */\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301670 " public OnosYangNodeOperationType onosYangNodeOperationType() {\n" +
1671 " return onosYangNodeOperationType;\n" +
1672 " }\n\n";
Bharat saraswal8beac342016-08-04 02:00:03 +05301673 }
1674
1675 /**
1676 * Returns getters for value and select leaf.
1677 *
1678 * @return getters for value and select leaf
1679 */
1680 static String getGettersForValueAndSelectLeaf() {
1681 return "\n" +
1682 " @Override\n" +
1683 " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301684 " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301685 " }\n" +
1686 "\n" +
1687 " @Override\n" +
1688 " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301689 " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301690 " }\n";
1691 }
1692
1693 /**
1694 * Returns setter for operation type.
1695 *
1696 * @param name name of node
1697 * @return setter for operation type
1698 */
1699 static String getSetterForOperationType(String name) {
1700 return " /**\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301701 " * Set node operation type.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301702 " *\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301703 " * @param onosYangNodeOperationType node operation type\n" +
1704 " * @return builder object for node operation type\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301705 " */\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301706 " public " + name + BUILDER + " onosYangNodeOperationType(OnosYangNodeOperationType " +
1707 "onosYangNodeOperationType) {\n" +
1708 " this.onosYangNodeOperationType = onosYangNodeOperationType;\n" +
Bharat saraswale304c252016-08-16 20:56:20 +05301709 " return this;\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301710 " }\n\n";
Bharat saraswal8beac342016-08-04 02:00:03 +05301711 }
1712
1713 /**
1714 * Returns setter for select leaf.
1715 *
1716 * @param name name of node
1717 * @param isRootNode if root node
1718 * @return setter for select leaf
1719 */
1720 static String getSetterForSelectLeaf(String name, boolean isRootNode) {
1721 String append = OVERRIDE;
1722 if (isRootNode) {
1723 append = EMPTY_STRING;
1724 }
1725 return "\n" +
1726 " " + append + "\n" +
1727 " public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301728 " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301729 " return this;\n" +
1730 " }\n";
1731 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301732
1733 private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) {
1734 String listAttr;
1735 if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
1736 switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
1737 case QUEUE: {
1738 listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1739 break;
1740 }
1741 case SET: {
1742 listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1743 break;
1744 }
1745 case LIST: {
1746 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1747 break;
1748 }
1749 default: {
1750 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1751 }
1752 }
1753 } else {
1754 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1755 }
1756 return listAttr;
1757 }
Bharat saraswal97459962016-02-20 21:57:16 +05301758}