blob: a8162340a6ca2c2420a831d500a7406892ee6580 [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;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +053048import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils
49 .getAugmentedClassNameForDataMethods;
Bharat saraswal039f59c2016-07-14 21:57:13 +053050import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
51import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
Bharat saraswal64e7e232016-07-14 23:33:55 +053052import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_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;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530151import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530152import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530153import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
154import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530155import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
156import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
Bharat saraswal84366c52016-03-23 19:40:35 +0530157import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
158import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
159import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
Bharat saraswal250a7472016-05-12 13:16:57 +0530160import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
Bharat saraswal84366c52016-03-23 19:40:35 +0530161import static org.onosproject.yangutils.utils.UtilConstants.THIS;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530162import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530163import static org.onosproject.yangutils.utils.UtilConstants.TO;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530164import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530165import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530166import static org.onosproject.yangutils.utils.UtilConstants.TRY;
Bharat saraswal84366c52016-03-23 19:40:35 +0530167import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530168import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
169import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
170import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
171import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
172import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530173import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530174import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
Bharat saraswal84366c52016-03-23 19:40:35 +0530175import static org.onosproject.yangutils.utils.UtilConstants.VOID;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530176import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530177import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530178import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
Bharat saraswal84366c52016-03-23 19:40:35 +0530179import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
180import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
181import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530182import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530183import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530184import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530185import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530186import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530187import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530188import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530189import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530190import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530191import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530192import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530193import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530194import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
195import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
196import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
Bharat saraswal84366c52016-03-23 19:40:35 +0530197import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
Bharat saraswal97459962016-02-20 21:57:16 +0530198
199/**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530200 * Represents generator for methods of generated files based on the file type.
Bharat saraswal97459962016-02-20 21:57:16 +0530201 */
202public final class MethodsGenerator {
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530203 private static final String BITS_STRING_ARRAY_VAR = "bitsTemp";
204 private static final String BIT_TEMP_VAR = "bitTemp";
Bharat saraswal97459962016-02-20 21:57:16 +0530205
Bharat saraswal97459962016-02-20 21:57:16 +0530206 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530207 * Creates an instance of method generator.
Bharat saraswal97459962016-02-20 21:57:16 +0530208 */
209 private MethodsGenerator() {
210 }
211
212 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530213 * Returns the methods strings for builder interface.
214 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530215 * @param name attribute name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530216 * @param pluginConfig plugin configurations
Vinod Kumar S08710982016-03-03 19:55:30 +0530217 * @return method string for builder interface
Bharat saraswal97459962016-02-20 21:57:16 +0530218 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530219 public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530220 return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
Bharat saraswal97459962016-02-20 21:57:16 +0530221 }
222
223 /**
224 * Returns getter string.
225 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530226 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530227 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530228 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530229 * @return getter string
230 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530231 public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530232 YangPluginConfig pluginConfig) {
233
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530234 String returnType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530235 String attributeName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +0530236 String appDataStructure = null;
237 if (attr.getCompilerAnnotation() != null) {
238 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
239 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530240 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
241 return generateForGetMethodWithAttribute(returnType)
Vidyashree Ramab3670472016-08-06 15:49:56 +0530242 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
243 attr.getCompilerAnnotation());
Bharat saraswal8beac342016-08-04 02:00:03 +0530244 }
Vinod Kumar S08710982016-03-03 19:55:30 +0530245
Vidyashree Ramab3670472016-08-06 15:49:56 +0530246 return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
247 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
248 attr.getCompilerAnnotation());
Bharat saraswal97459962016-02-20 21:57:16 +0530249 }
250
251 /**
252 * Returns setter string.
253 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530254 * @param attr attribute info
255 * @param className java class name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530256 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530257 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530258 * @return setter string
259 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530260 public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530261 YangPluginConfig pluginConfig) {
262
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530263 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530264 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530265 JavaDocGen.JavaDocType type;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530266 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530267 type = MANAGER_SETTER_METHOD;
268 } else {
269 type = SETTER_METHOD;
270 }
Bharat saraswal97459962016-02-20 21:57:16 +0530271
Vidyashree Ramab3670472016-08-06 15:49:56 +0530272 String appDataStructure = null;
273 if (attr.getCompilerAnnotation() != null) {
274 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
275 }
276 return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
277 + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles,
278 attr.getCompilerAnnotation());
Bharat saraswal97459962016-02-20 21:57:16 +0530279 }
280
281 /**
282 * Returns constructor method string.
283 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530284 * @param name class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530285 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530286 * @return constructor string
287 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530288 private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530289 return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
Bharat saraswal97459962016-02-20 21:57:16 +0530290 }
291
292 /**
293 * Returns default constructor method string.
294 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530295 * @param name class name
Bharat saraswal022dae92016-03-04 20:08:09 +0530296 * @param modifierType modifier type
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530297 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530298 * @return default constructor string
299 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530300 public static String getDefaultConstructorString(String name, String modifierType,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530301 YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530302 return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
303 + getDefaultConstructor(name, modifierType) + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530304 }
305
306 /**
307 * Returns check not null string.
308 *
309 * @param name attribute name
310 * @return check not null string
311 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530312 static String getCheckNotNull(String name) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530313 return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
314 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530315 }
316
317 /**
318 * Returns build method string.
319 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530320 * @param name class name
321 * @param isRootNode if root node
Bharat saraswal97459962016-02-20 21:57:16 +0530322 * @return build string
323 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530324 public static String getBuildString(String name, boolean isRootNode) {
325 if (isRootNode) {
326 return NEW_LINE + getBuild(name, true);
327 }
328 return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name, false);
Bharat saraswal97459962016-02-20 21:57:16 +0530329 }
330
331 /**
332 * Returns the getter method strings for class file.
333 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530334 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530335 * @param generatedJavaFiles for the type of java file being generated
Vinod Kumar S08710982016-03-03 19:55:30 +0530336 * @return getter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530337 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530338 public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530339
Bharat saraswal8beac342016-08-04 02:00:03 +0530340 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530341 String attributeName = attr.getAttributeName();
Bharat saraswal022dae92016-03-04 20:08:09 +0530342
343 if (!attr.isListAttr()) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530344 return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530345 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530346 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
347 return getGetter(attrParam, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530348 }
349
350 /**
351 * Returns getter for attribute.
352 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530353 * @param type return type
354 * @param name attribute name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530355 * @param generatedJavaFiles generated java files
Bharat saraswal022dae92016-03-04 20:08:09 +0530356 * @return getter for attribute
357 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530358 static String getGetter(String type, String name, int generatedJavaFiles) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530359 String ret = parseTypeForReturnValue(type);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530360 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530361 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530362 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
363 EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530364 RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530365 } else {
366 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
367 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
368 EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
369 + CLOSE_CURLY_BRACKET;
370 }
Bharat saraswal97459962016-02-20 21:57:16 +0530371 }
372
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530373 /*Provides string to return for type.*/
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530374 private static String parseTypeForReturnValue(String type) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530375 switch (type) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530376 case BYTE:
377 case INT:
378 case SHORT:
379 case LONG:
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530380 case DOUBLE:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530381 return "0";
382 case BOOLEAN_DATA_TYPE:
383 return FALSE;
384 default:
385 return null;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530386 }
387 }
388
Bharat saraswal97459962016-02-20 21:57:16 +0530389 /**
390 * Returns the setter method strings for class file.
391 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530392 * @param attr attribute info
393 * @param className name of the class
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530394 * @param generatedJavaFiles generated java files
Vinod Kumar S08710982016-03-03 19:55:30 +0530395 * @return setter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530396 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530397 public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530398 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530399 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530400 boolean isTypeNull = false;
401 if (attr.getAttributeType() == null) {
402 isTypeNull = true;
Bharat saraswal022dae92016-03-04 20:08:09 +0530403 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530404 if (!attr.isListAttr()) {
405 return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
406 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530407 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
408 return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
Bharat saraswal022dae92016-03-04 20:08:09 +0530409 }
410
411 /**
412 * Returns setter for attribute.
413 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530414 * @param className class name
415 * @param name attribute name
416 * @param type return type
417 * @param isTypeNull if attribute type is null
418 * @param isList true if leaf-list
Bharat saraswal022dae92016-03-04 20:08:09 +0530419 * @return setter for attribute
420 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530421 private static String getSetter(String className, String name, String type, int generatedJavaFiles,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530422 boolean isTypeNull, boolean isList) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530423 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530424 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
janani b703cfe42016-05-17 13:12:22 +0530425 + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530426 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
427 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530428 } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
429 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE
430 + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
431 + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
432 + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530433 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +0530434 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530435 name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
Bharat saraswal8beac342016-08-04 02:00:03 +0530436 + OPEN_CURLY_BRACKET;
437 if (!isTypeNull && !isList) {
438 method = method + getValueLeafSetString(name);
439 } else {
440 method = method + EMPTY_STRING;
441 }
442 return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS +
443 PERIOD + name + SPACE
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530444 + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
445 + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530446 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530447
448 }
449
450 //Returns value leaf flag setter.
451 private static String getValueLeafSetString(String name) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530452 return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
Bharat saraswal97459962016-02-20 21:57:16 +0530453 }
454
455 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530456 * Returns the setter method strings for class file.
457 *
458 * @param attr attribute info
459 * @return setter method for class
460 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530461 static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530462
Bharat saraswal8beac342016-08-04 02:00:03 +0530463 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530464 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530465 return getTypeDefSetter(attrQualifiedType, attributeName);
Bharat saraswal022dae92016-03-04 20:08:09 +0530466 }
467
468 /**
469 * Returns type def's setter for attribute.
470 *
471 * @param type data type
472 * @param name attribute name
473 * @return setter for type def's attribute
474 */
475 private static String getTypeDefSetter(String type, String name) {
janani b703cfe42016-05-17 13:12:22 +0530476 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name)
Bharat saraswal84366c52016-03-23 19:40:35 +0530477 + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +0530478 + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN +
479 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530480 }
481
482 /**
483 * Returns override string.
484 *
485 * @return override string
486 */
487 public static String getOverRideString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530488 return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530489 }
490
491 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530492 * Returns the getter method strings for interface file.
493 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530494 * @param yangName name of the attribute
495 * @param returnType return type of attribute
496 * @param isList is list attribute
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530497 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530498 * @param compilerAnnotation compiler annotation
Vinod Kumar S08710982016-03-03 19:55:30 +0530499 * @return getter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530500 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530501 static String getGetterForInterface(String yangName, String returnType, boolean isList,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530502 int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530503 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530504 return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530505 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530506 String listAttr = getListAttribute(returnType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530507 return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530508 }
509
510 /**
511 * Returns getter for attribute in interface.
512 *
513 * @param returnType return type
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530514 * @param yangName attribute name
Bharat saraswal022dae92016-03-04 20:08:09 +0530515 * @return getter for interface
516 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530517 private static String getGetterInterfaceString(String returnType, String yangName,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530518 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530519 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530520 return getGetMethodWithArgument(returnType, yangName);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530521 } else {
522 return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
523 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
524 }
Bharat saraswal97459962016-02-20 21:57:16 +0530525 }
526
527 /**
528 * Returns the setter method strings for interface file.
529 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530530 * @param attrName name of the attribute
531 * @param attrType return type of attribute
532 * @param className name of the java class being generated
533 * @param isList is list attribute
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530534 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530535 * @param compilerAnnotation compiler annotations
Vinod Kumar S08710982016-03-03 19:55:30 +0530536 * @return setter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530537 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530538 static String getSetterForInterface(String attrName, String attrType, String className,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530539 boolean isList, int generatedJavaFiles,
540 YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530541 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530542 return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530543 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530544
545 String listAttr = getListAttribute(attrType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530546 return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530547 }
548
549 /**
550 * Returns setter string for interface.
551 *
552 * @param className class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530553 * @param attrName attribute name
554 * @param attrType attribute type
Bharat saraswal022dae92016-03-04 20:08:09 +0530555 * @return setter string
556 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530557 private static String getSetterInterfaceString(String className, String attrName, String attrType,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530558 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530559 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530560 return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530561 + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
562 } else {
563 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
564 + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
565 }
Bharat saraswal97459962016-02-20 21:57:16 +0530566 }
567
568 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530569 * Returns list string.
570 *
571 * @return list string
572 */
573 private static String getListString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530574 return LIST + DIAMOND_OPEN_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530575 }
576
577 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530578 * Returns return type for attribute.
579 *
580 * @param attr attribute info
581 * @return return type
582 */
583 private static String getReturnType(JavaAttributeInfo attr) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530584 String returnType = EMPTY_STRING;
Vidyashree Rama13960652016-04-26 15:06:06 +0530585 if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530586 returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530587 }
588 returnType = returnType + attr.getImportInfo().getClassInfo();
589 return returnType;
590 }
591
592 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530593 * Returns the build method strings for interface file.
594 *
Vinod Kumar S08710982016-03-03 19:55:30 +0530595 * @param yangName name of the interface
596 * @return build method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530597 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530598 static String getBuildForInterface(String yangName) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530599 return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
600 + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530601 }
602
603 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530604 * Returns constructor string for impl class.
605 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530606 * @param yangName class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530607 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +0530608 * @param isRootNode if root node
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530609 * @return constructor string
610 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530611 static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530612 String javadoc = getConstructorString(yangName, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +0530613
614 String returnType = getCapitalCase(DEFAULT) + yangName;
615 if (isRootNode) {
616 returnType = yangName + OP_PARAM;
617 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530618 String constructor = FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
Bharat saraswald14cbe82016-07-14 13:26:18 +0530619 OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
620 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530621 return javadoc + constructor;
622 }
623
624 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530625 * Returns the constructor strings for class file.
626 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530627 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530628 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530629 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530630 * @return constructor for class
631 */
Bharat saraswald14cbe82016-07-14 13:26:18 +0530632 public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530633 YangPluginConfig pluginConfig) {
634
janani b703cfe42016-05-17 13:12:22 +0530635 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530636 String constructor;
Bharat saraswal84366c52016-03-23 19:40:35 +0530637
Bharat saraswal64e7e232016-07-14 23:33:55 +0530638 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530639 constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
640 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
641 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
642 + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
643 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530644 } else {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530645 constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
646 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
647 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
648 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
649 OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530650 }
Bharat saraswal022dae92016-03-04 20:08:09 +0530651 return constructor;
Bharat saraswal97459962016-02-20 21:57:16 +0530652 }
653
654 /**
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530655 * Returns the rpc strings for service interface.
656 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530657 * @param rpcName name of the rpc
658 * @param inputName name of input
659 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530660 * @param pluginConfig plugin configurations
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530661 * @return rpc method string
662 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530663 public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530664 YangPluginConfig pluginConfig) {
665
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530666 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530667 if (!inputName.equals(EMPTY_STRING)) {
668 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530669 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530670 return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
671 + CLOSE_PARENTHESIS + SEMI_COLAN;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530672 }
673
674 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530675 * Returns the rpc strings for manager impl.
676 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530677 * @param rpcName name of the rpc
678 * @param inputName name of input
679 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530680 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530681 * @return rpc method string
682 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530683 public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530684 YangPluginConfig pluginConfig) {
685
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530686 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530687 if (!inputName.equals(EMPTY_STRING)) {
688 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530689 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530690
Bharat saraswald14cbe82016-07-14 13:26:18 +0530691 String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
692 + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
693 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530694 if (!outputName.contentEquals(VOID)) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530695 method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
696 + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530697 }
698 method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530699
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530700 return method;
701 }
702
703 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530704 * Returns the build method strings for class file.
705 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530706 * @param yangName class name
707 * @param isRootNode if root node
Vinod Kumar S08710982016-03-03 19:55:30 +0530708 * @return build method string for class
Bharat saraswal97459962016-02-20 21:57:16 +0530709 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530710 static String getBuild(String yangName, boolean isRootNode) {
711 String type = getCapitalCase(DEFAULT) + yangName;
712 if (isRootNode) {
713 type = yangName + OP_PARAM;
714 }
715 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS +
716 CLOSE_PARENTHESIS
Bharat saraswald14cbe82016-07-14 13:26:18 +0530717 + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
Bharat saraswal8beac342016-08-04 02:00:03 +0530718 type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
Bharat saraswald14cbe82016-07-14 13:26:18 +0530719 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal97459962016-02-20 21:57:16 +0530720 }
721
722 /**
723 * Returns the Default constructor strings for class file.
724 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530725 * @param name name of the class
Bharat saraswal022dae92016-03-04 20:08:09 +0530726 * @param modifierType modifier type for default constructor
Bharat saraswal97459962016-02-20 21:57:16 +0530727 * @return Default constructor for class
728 */
Bharat saraswal022dae92016-03-04 20:08:09 +0530729 private static String getDefaultConstructor(String name, String modifierType) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530730 return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
731 + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal97459962016-02-20 21:57:16 +0530732 }
733
Bharat saraswal022dae92016-03-04 20:08:09 +0530734 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530735 * Returns to string method's open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530736 *
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530737 * @return string method's open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530738 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530739 static String getToStringMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530740 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO
741 + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
742 + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530743 }
744
745 /**
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530746 * Returns whether the data type is of primitive data type.
747 *
748 * @param dataType data type to be checked
749 * @return true, if data type can have primitive data type, false otherwise
750 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530751 static boolean isPrimitiveDataType(YangDataTypes dataType) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530752 return dataType == INT8
753 || dataType == INT16
754 || dataType == INT32
755 || dataType == INT64
756 || dataType == UINT8
757 || dataType == UINT16
758 || dataType == UINT32
759 || dataType == UINT64
760 || dataType == DECIMAL64
Bharat saraswal039f59c2016-07-14 21:57:13 +0530761 || dataType == BOOLEAN
762 || dataType == EMPTY;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530763
764 }
765
Bharat saraswal64e7e232016-07-14 23:33:55 +0530766
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530767 static String getIfConditionBegin(String indentation, String condition) {
768 return indentation + IF + SPACE + OPEN_PARENTHESIS + condition + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
Bharat saraswal8beac342016-08-04 02:00:03 +0530769 + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530770 }
771
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530772 static String getElseIfConditionBegin(String indentation, String condition) {
773 return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + getIfConditionBegin("", condition);
774 }
775
776 static String getBlockEnd(String indentation) {
777 return indentation + CLOSE_CURLY_BRACKET + NEW_LINE;
778 }
779
780 static String getCollectionIteratorForLoopBegin(String indentation, String loopVar, String collection) {
781 return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE + COLAN + SPACE + collection
782 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530783 }
784
Bharat saraswal039f59c2016-07-14 21:57:13 +0530785 /*
Bharat saraswal8beac342016-08-04 02:00:03 +0530786 * Returns omit null value string.
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530787 *
788 * @return omit null value string
789 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530790 static String getOmitNullValueString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530791 return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
792 }
793
794 /**
795 * Returns to string method's close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530796 *
797 * @return to string method close string
798 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530799 static String getToStringMethodClose() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530800 return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
801 + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530802 }
803
804 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530805 * Returns to string method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530806 *
807 * @param attr attribute info
808 * @return to string method
809 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530810 public static String getToStringMethod(JavaAttributeInfo attr) {
811
janani b703cfe42016-05-17 13:12:22 +0530812 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +0530813 return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
814 + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530815 }
816
817 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530818 * Returns from string method's open string.
819 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530820 * @param className name of the class
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530821 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530822 * @return from string method's open string
823 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530824 static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530825 return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530826 + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
827 + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
828 + OPEN_CURLY_BRACKET + NEW_LINE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530829 }
830
831 /**
832 * Return from string method's close string.
833 *
834 * @return from string method's close string
835 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530836 static String getFromStringMethodClose() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530837 return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
838 CLOSE_CURLY_BRACKET + NEW_LINE;
839 }
840
841 /**
842 * Return from string method's body string.
843 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530844 * @param attr attribute info
Bharat saraswal039f59c2016-07-14 21:57:13 +0530845 * @param fromStringAttributeInfo attribute info for the from string wrapper type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530846 * @return from string method's body string
847 */
848 public static String getFromStringMethod(JavaAttributeInfo attr,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530849 JavaAttributeInfo fromStringAttributeInfo) {
850
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530851 return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
Mahesh Poojary S6986df32016-07-19 10:58:07 +0530852 + getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530853 + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString()
854 + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
855 }
856
857 /**
858 * Returns sub string with try statement for union's from string method.
859 *
860 * @return sub string with try statement for union's from string method
861 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530862 private static String getTrySubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530863 return TRY + SPACE + OPEN_CURLY_BRACKET;
864 }
865
866 /**
867 * Returns sub string with return statement for union's from string method.
868 *
869 * @return sub string with return statement for union's from string method
870 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530871 private static String getReturnOfSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530872 return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN;
873 }
874
875 /**
876 * Returns sub string with catch statement for union's from string method.
877 *
878 * @return sub string with catch statement for union's from string method
879 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530880 private static String getCatchSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530881 return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR
882 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
883 }
884
885 /**
886 * Returns sub string with parsed statement for union's from string method.
887 *
888 * @param attr attribute info
889 * @return sub string with parsed statement for union's from string method
890 */
891 private static String getParsedSubString(JavaAttributeInfo attr,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530892 JavaAttributeInfo fromStringAttributeInfo) {
893
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530894 String targetDataType = getReturnType(attr);
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530895 if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
896 String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
897 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
898 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
899 + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE
900 + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
901 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
902 + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE
903 + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
904 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
905 + PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
906 lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR
907 + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS
908 + QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
909 lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
910 + BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE
911 + OPEN_CURLY_BRACKET + NEW_LINE;
912 lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD
913 + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
914 lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS
915 + INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS
916 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
917 lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
918 return lines;
919 } else if (attr.getAttributeType().getDataType() == BINARY) {
920 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD
921 + GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS
922 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530923 } else {
924 String parseFromStringMethod = getParseFromStringMethod(targetDataType,
Bharat saraswal039f59c2016-07-14 21:57:13 +0530925 fromStringAttributeInfo.getAttributeType());
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530926 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530927 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530928 }
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530929 }
930
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530931 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530932 * Returns hash code method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530933 *
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530934 * @return hash code method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530935 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530936 static String getHashCodeMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530937 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
Bharat saraswal8beac342016-08-04 02:00:03 +0530938 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
939 EIGHT_SPACE_INDENTATION
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530940 + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530941 }
942
943 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530944 * Returns hash code methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530945 *
946 * @param hashcodeString hash code string
947 * @return to hash code method close string
948 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530949 static String getHashCodeMethodClose(String hashcodeString) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530950 hashcodeString = trimAtLast(hashcodeString, COMMA);
951 hashcodeString = trimAtLast(hashcodeString, SPACE);
Bharat saraswal8beac342016-08-04 02:00:03 +0530952 return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
953 CLOSE_CURLY_BRACKET
Bharat saraswal84366c52016-03-23 19:40:35 +0530954 + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530955 }
956
957 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530958 * Returns hash code method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530959 *
960 * @param attr attribute info
961 * @return hash code method
962 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530963 public static String getHashCodeMethod(JavaAttributeInfo attr) {
janani b703cfe42016-05-17 13:12:22 +0530964 return attr.getAttributeName() + COMMA + SPACE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530965 }
966
967 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530968 * Returns equals method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530969 *
970 * @param className class name
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530971 * @return equals method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530972 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530973 static String getEqualsMethodOpen(String className) {
974 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE +
975 EQUALS_STRING
Bharat saraswal84366c52016-03-23 19:40:35 +0530976 + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
977 + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
Bharat saraswal022dae92016-03-04 20:08:09 +0530978 }
979
980 /**
981 * Returns equal methods if condition string.
982 *
983 * @return if condition string
984 */
985 private static String getEqualsMethodsCommonIfCondition() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530986 return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ
987 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE
988 + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530989 }
990
991 /**
992 * Returns if condition for specific class object in equals method.
993 *
994 * @param className class name
995 * @return if condition string
996 */
997 private static String getEqualsMethodsSpecificIfCondition(String className) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530998 return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className
999 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className
1000 + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE
1001 + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301002 }
1003
1004 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301005 * Returns equals methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +05301006 *
1007 * @param equalMethodString equal method string
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301008 * @return equals method close string
Bharat saraswal022dae92016-03-04 20:08:09 +05301009 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301010 static String getEqualsMethodClose(String equalMethodString) {
Bharat saraswal84366c52016-03-23 19:40:35 +05301011 equalMethodString = trimAtLast(equalMethodString, AND);
1012 equalMethodString = trimAtLast(equalMethodString, AND);
1013 equalMethodString = trimAtLast(equalMethodString, SPACE);
1014 equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
1015 return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
1016 + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1017 + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301018 }
1019
1020 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301021 * Returns equals method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +05301022 *
1023 * @param attr attribute info
1024 * @return equals method
1025 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +05301026 public static String getEqualsMethod(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301027
janani b703cfe42016-05-17 13:12:22 +05301028 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +05301029 return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
1030 + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
1031 + AND;
Bharat saraswal022dae92016-03-04 20:08:09 +05301032 }
1033
1034 /**
1035 * Returns of method string for class.
1036 *
1037 * @param name class name
1038 * @param attr attribute info
1039 * @return of method string
1040 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301041 static String getOfMethod(String name, JavaAttributeInfo attr) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301042 String attrQualifiedType = getReturnType(attr);
Bharat saraswal84366c52016-03-23 19:40:35 +05301043 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301044 + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal84366c52016-03-23 19:40:35 +05301045 + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE
1046 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301047 }
1048
Bharat saraswale2bc60d2016-04-16 02:28:25 +05301049 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301050 * Returns of method's string and java doc for special type.
1051 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301052 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301053 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301054 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301055 * @return of method's string and java doc for special type
1056 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301057 public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301058 YangPluginConfig pluginConfig) {
1059
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301060 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301061 String attrName = attr.getAttributeName();
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301062
Vidyashree Ramab3670472016-08-06 15:49:56 +05301063 return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301064 + getOfMethodString(attrType, generatedJavaClassName);
1065 }
1066
1067 /**
1068 * Returns of method's string.
1069 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301070 * @param type data type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301071 * @param className class name
1072 * @return of method's string
1073 */
1074 private static String getOfMethodString(String type, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301075 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS
1076 + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
1077 + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE
1078 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1079 }
1080
1081 /**
1082 * Returns string and java doc for constructor of type class.
1083 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301084 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301085 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301086 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301087 * @return string and java doc for constructor of type class
1088 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301089 public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301090 String generatedJavaClassName,
1091 YangPluginConfig pluginConfig) {
1092
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301093 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301094 String attrName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301095 return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301096 + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
1097 }
1098
1099 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301100 * Returns string and java doc for constructor of type class.
1101 *
1102 * @param attr1 first attribute info
1103 * @param attr2 second attribute info
1104 * @param generatedJavaClassName class name
1105 * @param pluginConfig plugin config
1106 * @param type conflict validate type
Bharat saraswal8beac342016-08-04 02:00:03 +05301107 * @param addFirst whether int came first or uInt came first
Bharat saraswal64e7e232016-07-14 23:33:55 +05301108 * @return string and java doc for constructor of type class
1109 */
1110 public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
1111 attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301112 boolean addFirst) {
1113
Bharat saraswal64e7e232016-07-14 23:33:55 +05301114 String attrType = getReturnType(attr1);
1115 String attrName1 = "";
1116 String attrName2 = "";
1117 if (attr1 != null) {
1118 attrName1 = attr1.getAttributeName();
1119 }
1120 if (attr2 != null) {
1121 attrName2 = attr2.getAttributeName();
1122 }
1123
Vidyashree Ramab3670472016-08-06 15:49:56 +05301124 String appDataStructure = null;
1125 if (attr1.getCompilerAnnotation() != null) {
1126 appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1127 }
1128 return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig,
1129 appDataStructure) + getTypeConstructorString(attrType, attrName1,
1130 attrName2, generatedJavaClassName, type, addFirst);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301131 }
1132
1133 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301134 * Returns type constructor string.
1135 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301136 * @param type data type
1137 * @param name attribute name
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301138 * @param className class name
1139 * @return type constructor string
1140 */
1141 private static String getTypeConstructorString(String type, String name, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301142 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
1143 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
1144 + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
1145 + CLOSE_CURLY_BRACKET;
1146 }
1147
1148 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301149 * Returns type constructor string.
1150 *
1151 * @param type data type
1152 * @param attr1 attribute attr1
1153 * @param className class attr1
1154 * @return type constructor string
1155 */
1156 private static String getTypeConstructorString(String type, String attr1, String attr2, String className,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301157 ValidatorTypeForUnionTypes validatorType, boolean addInt) {
1158
Bharat saraswal64e7e232016-07-14 23:33:55 +05301159 String constructor;
1160 constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
1161 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1162
1163 String name1;
1164 String name2;
1165 if (addInt) {
1166 name1 = attr1;
1167 name2 = attr2;
1168 } else {
1169 name1 = attr2;
1170 name2 = attr1;
1171 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301172 constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
Bharat saraswal64e7e232016-07-14 23:33:55 +05301173 TWELVE_SPACE_INDENTATION + THIS + PERIOD
1174 + name1 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
1175 + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION
1176 + THIS + PERIOD
1177 + name2 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
1178 + CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION
1179 + CLOSE_CURLY_BRACKET;
1180
1181 return constructor;
1182 }
1183
1184 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301185 * Returns interface of add augmentation.
1186 *
1187 * @return interface of add augmentation
1188 */
1189 static String getAddAugmentInfoMethodInterface() {
1190 return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID + SPACE +
1191 ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
1192 SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1193 }
1194
1195 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301196 * Returns implementation of add augmentation.
1197 *
1198 * @return implementation of add augmentation
1199 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301200 static String getAddAugmentInfoMethodImpl() {
Bharat saraswal8beac342016-08-04 02:00:03 +05301201 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
1202 ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301203 SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
1204 NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
1205 OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301206 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1207 CLOSE_CURLY_BRACKET + NEW_LINE;
1208 }
1209
1210 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301211 * Returns interface of get YANG augment info.
Bharat saraswalaf413b82016-07-14 15:18:20 +05301212 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301213 * @return interface of get YANG augment info
Bharat saraswalaf413b82016-07-14 15:18:20 +05301214 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301215 static String getYangAugmentInfoInterface() {
1216 return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + OBJECT_STRING + SPACE +
1217 getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
1218 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1219 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301220
Bharat saraswal8beac342016-08-04 02:00:03 +05301221 /**
1222 * Returns implementation of get YANG augment info.
1223 *
1224 * @return implementation of get YANG augment info
1225 */
1226 static String getYangAugmentInfoImpl() {
1227 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
1228 OBJECT_STRING + SPACE +
1229 getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301230 CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
1231 RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
1232 OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1233 CLOSE_CURLY_BRACKET + NEW_LINE;
1234 }
1235
1236 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301237 * Returns implementation of get YANG augment info.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301238 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301239 * @return implementation of get YANG augment info
Bharat saraswal039f59c2016-07-14 21:57:13 +05301240 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301241 static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301242 return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null)
Bharat saraswal8beac342016-08-04 02:00:03 +05301243 + FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
1244 QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
1245 SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
1246 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1247 }
1248
1249 /**
1250 * Returns implementation of get YANG augment info.
1251 *
1252 * @return implementation of get YANG augment info
1253 */
1254 static String getYangAugmentInfoMapImpl() {
1255 return getOverRideString()
Bharat saraswal039f59c2016-07-14 21:57:13 +05301256 + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
1257 MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
Bharat saraswal8beac342016-08-04 02:00:03 +05301258 DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
1259 getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301260 CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
1261 RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE
1262 + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1263 }
1264
1265 /**
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301266 * Returns enum's constructor.
1267 *
1268 * @param className enum's class name
1269 * @return enum's constructor
1270 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301271 static String getEnumsConstructor(String className) {
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301272 return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
1273 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
1274 + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1275 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301276
1277 /**
1278 * Returns of method for enum class.
1279 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301280 * @param className class name
1281 * @param attr java attribute
1282 * @param enumMap enum's sets map
1283 * @param enumList enum's sets list
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301284 * @param pluginConfig plugin configurations
Bharat saraswal250a7472016-05-12 13:16:57 +05301285 * @return of method
1286 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301287 static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301288 Map<String, Integer> enumMap, List<String> enumList,
1289 YangPluginConfig pluginConfig) {
Bharat saraswal250a7472016-05-12 13:16:57 +05301290 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301291 String attrName = attr.getAttributeName();
Bharat saraswal250a7472016-05-12 13:16:57 +05301292
janani b703cfe42016-05-17 13:12:22 +05301293 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE
1294 + OF + OPEN_PARENTHESIS
Bharat saraswal250a7472016-05-12 13:16:57 +05301295 + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
1296 + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
1297 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +05301298 int value;
Bharat saraswal250a7472016-05-12 13:16:57 +05301299 for (String str : enumList) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301300
Bharat saraswal250a7472016-05-12 13:16:57 +05301301 value = enumMap.get(str);
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301302 method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
janani b703cfe42016-05-17 13:12:22 +05301303 + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
Bharat saraswal250a7472016-05-12 13:16:57 +05301304 + str + SEMI_COLAN + NEW_LINE;
1305 }
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301306 method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
Bharat saraswal250a7472016-05-12 13:16:57 +05301307 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1308 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1309
Vidyashree Ramab3670472016-08-06 15:49:56 +05301310 return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig, null)
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301311 + method;
Bharat saraswal250a7472016-05-12 13:16:57 +05301312 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301313
1314 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301315 * Returns from string method parsed string.
1316 *
1317 * @param targetDataType target data type
1318 * @param yangType YANG type
1319 * @return parsed string
1320 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301321 private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301322 YangDataTypes type = yangType.getDataType();
1323
1324 switch (type) {
1325 case INT8:
1326 return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
1327 case INT16:
1328 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
1329 case INT32:
1330 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
1331 case INT64:
1332 return LONG_WRAPPER + PERIOD + PARSE_LONG;
1333 case UINT8:
1334 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
1335 case UINT16:
1336 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
1337 case UINT32:
1338 return LONG_WRAPPER + PERIOD + PARSE_LONG;
1339 case UINT64:
1340 return NEW + SPACE + BIG_INTEGER;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +05301341 case DECIMAL64:
1342 return NEW + SPACE + BIG_DECIMAL;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301343 case STRING:
Shankara-Huaweib7564772016-08-02 18:13:13 +05301344 case IDENTITYREF:
1345 return EMPTY_STRING;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301346 case EMPTY:
1347 case BOOLEAN:
1348 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301349 case BITS:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301350 case UNION:
1351 case ENUMERATION:
1352 case DERIVED:
1353 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
1354 default:
1355 throw new TranslatorException("given data type is not supported.");
1356 }
1357 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301358
1359 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301360 * Returns augmented data getter and setter methods for service class.
1361 *
1362 * @param parent parent node
1363 * @return augmented data getter and setter methods for service class
1364 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301365 static String getAugmentsDataMethodForService(YangNode parent) {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301366 List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
1367 YangNode augmentedNode;
1368 String curNodeName;
1369 String method;
1370 StringBuilder methods = new StringBuilder();
1371 String parentName;
1372 String returnType;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301373 YangNode methodNode;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301374 YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
1375 for (YangAtomicPath nodeId : targets) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301376 augmentedNode = nodeId.getResolvedNode().getParent();
Bharat saraswal64e7e232016-07-14 23:33:55 +05301377 methodNode = nodeId.getResolvedNode();
1378 if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) {
1379 curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +05301380 } else {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301381 curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig
Bharat saraswalaf413b82016-07-14 15:18:20 +05301382 .getConflictResolver()));
1383 }
1384 returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301385 parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +05301386 method = generateForGetMethodWithAttribute(returnType)
1387 + getGetMethodWithArgument(returnType, AUGMENTED + parentName
1388 + getCapitalCase(curNodeName)) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301389 methods.append(method);
1390
1391 method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
Vidyashree Ramab3670472016-08-06 15:49:56 +05301392 getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301393 getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
Vidyashree Ramab3670472016-08-06 15:49:56 +05301394 getCapitalCase(curNodeName), returnType, parentName, false,
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301395 GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301396 methods.append(method);
1397 }
1398 return methods.toString();
1399 }
1400
1401 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301402 * Returns validator method for range in union class.
1403 *
1404 * @param type type
1405 * @return validator method for range in union class
1406 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301407 static String getRangeValidatorMethodForUnion(String type) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301408 String newType;
1409 if (type.contentEquals(BIG_INTEGER)) {
1410 newType = LONG;
1411 } else {
1412 newType = INT;
1413 }
1414 String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
1415 SPACE +
1416 VALIDATE_RANGE +
1417 OPEN_PARENTHESIS
1418 + type + SPACE + MIN_RANGE + COMMA + SPACE + type + SPACE + MAX_RANGE + COMMA + SPACE +
1419 newType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1420 if (type.contentEquals(BIG_INTEGER)) {
1421 method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE + getSmallCase(BIG_INTEGER)
1422 + SPACE + EQUAL + SPACE + NEW + SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
1423 QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
1424 EIGHT_SPACE_INDENTATION + RETURN + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo"
1425 + OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SPACE + AND +
1426 AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
1427 CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SEMI_COLAN + NEW_LINE;
1428 } else {
1429 method = method + EIGHT_SPACE_INDENTATION
1430 + RETURN + SPACE + VALUE + SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE + SPACE + AND +
1431 AND + SPACE + VALUE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE + SEMI_COLAN + NEW_LINE;
1432 }
1433 return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1434 }
1435
1436 /**
1437 * Returns if condition string for typedef constructor.
1438 *
1439 * @param type type of conflict
1440 * @param addFirst true int/long need to be added first
1441 * @return if condition string for typedef constructor
1442 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301443 private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301444 String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS;
1445
1446 if (type == INT_TYPE_CONFLICT) {
1447 if (addFirst) {
1448 condition = condition + INT_MIN_RANGE + COMMA + SPACE + INT_MAX_RANGE + COMMA + SPACE + VALUE;
1449 } else {
1450 condition = condition + UINT_MIN_RANGE + COMMA + SPACE + UINT_MAX_RANGE + COMMA + SPACE + VALUE;
1451 }
1452 } else {
1453 if (addFirst) {
1454 condition = condition + LONG_MIN_RANGE + COMMA + SPACE + LONG_MAX_RANGE + COMMA + SPACE + VALUE;
1455 } else {
1456 condition = condition + ULONG_MIN_RANGE + COMMA + SPACE + ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
1457 }
1458 }
1459 return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1460 }
1461
Bharat saraswal8beac342016-08-04 02:00:03 +05301462 //Get method with arguments.
1463 private static String getGetMethodWithArgument(String returnType, String yangName) {
1464 return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
1465 + OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS +
1466 SEMI_COLAN;
1467 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301468
Bharat saraswal8beac342016-08-04 02:00:03 +05301469 /**
1470 * Returns add to list method interface.
1471 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301472 * @param attr java attribute
1473 * @param className name of the class
Bharat saraswal8beac342016-08-04 02:00:03 +05301474 * @return add to list method interface
1475 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301476 public static String getAddToListMethodInterface(JavaAttributeInfo attr, String className) {
1477 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + ADD_STRING + getCapitalCase(TO) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301478 getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE +
1479 VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
1480 }
1481
1482 /**
1483 * Returns add to list method impl.
1484 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301485 * @param attr java attribute
1486 * @param generatedJavaClassName class name
1487 * @param isRoot is root
Bharat saraswal8beac342016-08-04 02:00:03 +05301488 * @return add to list method impl
1489 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301490 public static String getAddToListMethodImpl(JavaAttributeInfo attr, String generatedJavaClassName, boolean isRoot) {
1491 String retString = "";
1492 if (!isRoot) {
1493 retString = getOverRideString();
1494 }
1495 return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + generatedJavaClassName + BUILDER + SPACE +
1496 ADD_STRING +
Bharat saraswal8beac342016-08-04 02:00:03 +05301497 getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
1498 getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
1499 + NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
1500 + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301501 NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN +
Bharat saraswal8beac342016-08-04 02:00:03 +05301502 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1503 }
1504
1505 /**
1506 * Returns builder method for class.
1507 *
1508 * @param name name of class
1509 * @return builder method for class
1510 */
1511 static String builderMethod(String name) {
1512 return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
1513 + name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
1514 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name +
1515 BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1516 CLOSE_CURLY_BRACKET;
1517 }
1518
1519 /**
1520 * Returns is filter content match interface.
1521 *
1522 * @param name name of node
1523 * @return is filter content match interface
1524 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301525 static String processSubtreeFilteringInterface(String name) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301526 String method = " /**\n" +
1527 " * Checks if the passed " + name + " maps the content match query condition.\n" +
1528 " *\n" +
1529 " * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" +
1530 " for" +
1531 " content match\n" +
1532 " * @return match result\n" +
1533 " */\n";
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301534 return method + FOUR_SPACE_INDENTATION + name + SPACE + PROCESS_SUBTREE_FILTERING +
1535 OPEN_PARENTHESIS
1536 + name + SPACE + getSmallCase(name) + COMMA + SPACE + BOOLEAN_DATA_TYPE + SPACE +
1537 "isSelectAllSchemaChild" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +05301538 }
1539
1540 /**
1541 * Returns is value set interface.
1542 *
1543 * @return is value set interface
1544 */
1545 static String isLeafValueSetInterface() {
1546 String method = " /**\n" +
1547 " * Checks if the leaf value is set.\n" +
1548 " *\n" +
1549 " * @param leaf leaf whose value status needs to checked\n" +
1550 " * @return result of leaf value set in object\n" +
1551 " */\n";
1552 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS
1553 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1554 }
1555
1556 /**
1557 * Returns is select leaf set interface.
1558 *
1559 * @return is select leaf set interface
1560 */
1561 static String isSelectLeafSetInterface() {
1562 String method = " /**\n" +
1563 " * Checks if the leaf is set to be a selected leaf.\n" +
1564 " *\n" +
1565 " * @param leaf if leaf needs to be selected\n" +
1566 " * @return result of leaf value set in object\n" +
1567 " */\n";
1568 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS
1569 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1570 }
1571
1572 /**
1573 * Returns set select leaf set interface.
1574 *
1575 * @param name node name
1576 * @return set select leaf set interface
1577 */
1578 static String setSelectLeafSetInterface(String name) {
1579 String method = " /**\n" +
1580 " * Set a leaf to be selected.\n" +
1581 " *\n" +
1582 " * @param leaf leaf needs to be selected\n" +
1583 " */\n";
1584 return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS
1585 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1586 }
1587
1588 /**
1589 * Returns leaf identifier interface enum signature.
1590 *
1591 * @param name name of node
1592 * @return leaf identifier interface enum signature
1593 */
1594 static String getInterfaceLeafIdEnumSignature(String name) {
1595 String start = " /**\n" +
1596 " * Identify the leaf of " + name + PERIOD + NEW_LINE +
1597 " */\n";
1598 return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE +
1599 OPEN_CURLY_BRACKET + NEW_LINE;
1600 }
1601
1602 /**
1603 * Returns interface leaf identifier enum method.
1604 *
1605 * @return interface leaf identifier enum method
1606 */
1607 static String getInterfaceLeafIdEnumMethods() {
1608 return " private int leafIndex;\n" +
1609 "\n" +
1610 " public int getLeafIndex() {\n" +
1611 " return leafIndex;\n" +
1612 " }\n" +
1613 "\n" +
1614 " LeafIdentifier(int value) {\n" +
1615 " this.leafIndex = value;\n" +
1616 " }\n" +
1617 " }\n";
1618 }
1619
1620 /**
1621 * Returns getter methods for operation attributes.
1622 *
1623 * @return getter methods for operation attributes
1624 */
1625 static String getOperationAttributesGetters() {
1626 return "\n" +
1627 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301628 " * Returns the valueLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301629 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301630 " * @return value of valueLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301631 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301632 " public BitSet getValueLeafFlags() {\n" +
1633 " return valueLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301634 " }\n" +
1635 "\n" +
1636 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301637 " * Returns the selectLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301638 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301639 " * @return value of selectLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301640 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301641 " public BitSet getSelectLeafFlags() {\n" +
1642 " return selectLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301643 " }\n" +
1644 "\n";
1645 }
1646
1647 /**
1648 * Returns getter for operation type.
1649 *
1650 * @return getter for operation type
1651 */
1652 static String getGetterForOperationType() {
1653 return " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301654 " * Returns the operationType.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301655 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301656 " * @return value of operationType\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301657 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301658 " public OperationType getOperationType() {\n" +
1659 " return operationType;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301660 " }\n";
1661 }
1662
1663 /**
1664 * Returns getters for value and select leaf.
1665 *
1666 * @return getters for value and select leaf
1667 */
1668 static String getGettersForValueAndSelectLeaf() {
1669 return "\n" +
1670 " @Override\n" +
1671 " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301672 " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301673 " }\n" +
1674 "\n" +
1675 " @Override\n" +
1676 " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301677 " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301678 " }\n";
1679 }
1680
1681 /**
1682 * Returns setter for operation type.
1683 *
1684 * @param name name of node
1685 * @return setter for operation type
1686 */
1687 static String getSetterForOperationType(String name) {
1688 return " /**\n" +
1689 " * Set operation type.\n" +
1690 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301691 " * @param operationType operation type\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301692 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301693 " public " + name + BUILDER + " setOperationType(OperationType operationType) {\n" +
1694 " this.operationType = operationType;\n" +
Bharat saraswale304c252016-08-16 20:56:20 +05301695 " return this;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301696 " }\n";
1697 }
1698
1699 /**
1700 * Returns setter for select leaf.
1701 *
1702 * @param name name of node
1703 * @param isRootNode if root node
1704 * @return setter for select leaf
1705 */
1706 static String getSetterForSelectLeaf(String name, boolean isRootNode) {
1707 String append = OVERRIDE;
1708 if (isRootNode) {
1709 append = EMPTY_STRING;
1710 }
1711 return "\n" +
1712 " " + append + "\n" +
1713 " public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301714 " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301715 " return this;\n" +
1716 " }\n";
1717 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301718
1719 private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) {
1720 String listAttr;
1721 if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
1722 switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
1723 case QUEUE: {
1724 listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1725 break;
1726 }
1727 case SET: {
1728 listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1729 break;
1730 }
1731 case LIST: {
1732 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1733 break;
1734 }
1735 default: {
1736 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1737 }
1738 }
1739 } else {
1740 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1741 }
1742 return listAttr;
1743 }
Bharat saraswal97459962016-02-20 21:57:16 +05301744}