blob: 5b380968f4bbdbfd2660713434c435caa42463f4 [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;
Bharat saraswale304c252016-08-16 20:56:20 +053020
Bharat saraswal039f59c2016-07-14 21:57:13 +053021import org.onosproject.yangutils.datamodel.YangAtomicPath;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053022import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
Bharat saraswal748fc3c2016-09-06 16:38:20 +053023import org.onosproject.yangutils.datamodel.YangEnum;
24import org.onosproject.yangutils.datamodel.YangEnumeration;
Bharat saraswalaf413b82016-07-14 15:18:20 +053025import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053026import org.onosproject.yangutils.datamodel.YangType;
janani b0e4e8ae2016-07-13 21:06:41 +053027import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053028import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053029import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
Bharat saraswal039f59c2016-07-14 21:57:13 +053030import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053031import org.onosproject.yangutils.utils.io.YangPluginConfig;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053032import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
Bharat saraswal84366c52016-03-23 19:40:35 +053033
Bharat saraswal039f59c2016-07-14 21:57:13 +053034import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
35import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
36import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053037import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
Bharat saraswal039f59c2016-07-14 21:57:13 +053038import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053039import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
40import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
41import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
Bharat saraswal039f59c2016-07-14 21:57:13 +053042import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053043import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
Shankara-Huaweia1039e52016-07-14 16:53:09 +053044import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
Bharat saraswal039f59c2016-07-14 21:57:13 +053045import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
46import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
Bharat saraswal748fc3c2016-09-06 16:38:20 +053049import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils
50 .getAugmentedClassNameForDataMethods;
Bharat saraswal039f59c2016-07-14 21:57:13 +053051import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
52import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
Bharat saraswal748fc3c2016-09-06 16:38:20 +053053import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
Bharat saraswal64e7e232016-07-14 23:33:55 +053054import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053055import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT;
Bharat saraswal64e7e232016-07-14 23:33:55 +053056import static org.onosproject.yangutils.utils.UtilConstants.ADD;
Bharat saraswal84366c52016-03-23 19:40:35 +053057import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
58import static org.onosproject.yangutils.utils.UtilConstants.AND;
Bharat saraswalaf413b82016-07-14 15:18:20 +053059import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053060import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +053061import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
Bharat saraswald14cbe82016-07-14 13:26:18 +053062import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
Bharat saraswal84366c52016-03-23 19:40:35 +053063import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053064import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
Bharat saraswal84366c52016-03-23 19:40:35 +053065import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
66import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053067import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053068import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
Bharat saraswal250a7472016-05-12 13:16:57 +053069import static org.onosproject.yangutils.utils.UtilConstants.CASE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053070import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
Bharat saraswal84366c52016-03-23 19:40:35 +053071import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
Bharat saraswalaf413b82016-07-14 15:18:20 +053072import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
73import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +053074import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
75import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
Bharat saraswal039f59c2016-07-14 21:57:13 +053076import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053077import static org.onosproject.yangutils.utils.UtilConstants.COLON;
Bharat saraswal84366c52016-03-23 19:40:35 +053078import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053079import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
Bharat saraswal250a7472016-05-12 13:16:57 +053080import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Bharat saraswal84366c52016-03-23 19:40:35 +053081import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
82import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +053083import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
Bharat saraswal84366c52016-03-23 19:40:35 +053084import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
Bharat saraswal64e7e232016-07-14 23:33:55 +053085import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
Bharat saraswal84366c52016-03-23 19:40:35 +053086import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
Bharat saraswal8beac342016-08-04 02:00:03 +053087import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
Bharat saraswal84366c52016-03-23 19:40:35 +053088import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
89import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053090import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
91import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
Bharat saraswal84366c52016-03-23 19:40:35 +053092import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053093import static org.onosproject.yangutils.utils.UtilConstants.FOR;
Bharat saraswal84366c52016-03-23 19:40:35 +053094import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +053095import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
96import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
Bharat saraswalaf413b82016-07-14 15:18:20 +053097import static org.onosproject.yangutils.utils.UtilConstants.GET;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +053098import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
Bharat saraswal84366c52016-03-23 19:40:35 +053099import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
100import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
101import static org.onosproject.yangutils.utils.UtilConstants.HASH;
102import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
103import static org.onosproject.yangutils.utils.UtilConstants.IF;
Bharat saraswal84366c52016-03-23 19:40:35 +0530104import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
105import static org.onosproject.yangutils.utils.UtilConstants.INT;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530106import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530107import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
108import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530109import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
110import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
Bharat saraswal84366c52016-03-23 19:40:35 +0530111import static org.onosproject.yangutils.utils.UtilConstants.LIST;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530112import static org.onosproject.yangutils.utils.UtilConstants.LONG;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530113import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
114import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530115import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530116import static org.onosproject.yangutils.utils.UtilConstants.MAP;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530117import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
118import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530119import static org.onosproject.yangutils.utils.UtilConstants.NEW;
120import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530121import static org.onosproject.yangutils.utils.UtilConstants.NULL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530122import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
123import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
124import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
125import static org.onosproject.yangutils.utils.UtilConstants.OF;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530126import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530127import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
128import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
Bharat saraswal8beac342016-08-04 02:00:03 +0530129import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Bharat saraswal84366c52016-03-23 19:40:35 +0530130import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
131import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530132import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
133import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
134import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
135import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
136import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
Bharat saraswal84366c52016-03-23 19:40:35 +0530137import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530138import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530139import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
140import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
Bharat saraswal84366c52016-03-23 19:40:35 +0530141import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530142import static org.onosproject.yangutils.utils.UtilConstants.PUT;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530143import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530144import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530145import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530146import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530147import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530148import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530149import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
Bharat saraswal84366c52016-03-23 19:40:35 +0530150import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530151import static org.onosproject.yangutils.utils.UtilConstants.SET;
Bharat saraswal84366c52016-03-23 19:40:35 +0530152import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
Bharat saraswal8beac342016-08-04 02:00:03 +0530153import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530154import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530155import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
156import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530157import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530158import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530159import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
160import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530161import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
162import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
Bharat saraswal84366c52016-03-23 19:40:35 +0530163import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
164import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530165import static org.onosproject.yangutils.utils.UtilConstants.STR_VAL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530166import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
Bharat saraswal250a7472016-05-12 13:16:57 +0530167import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
Bharat saraswal84366c52016-03-23 19:40:35 +0530168import static org.onosproject.yangutils.utils.UtilConstants.THIS;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530169import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
Bharat saraswal84366c52016-03-23 19:40:35 +0530170import static org.onosproject.yangutils.utils.UtilConstants.TO;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530171import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
Bharat saraswal84366c52016-03-23 19:40:35 +0530172import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530173import static org.onosproject.yangutils.utils.UtilConstants.TRY;
Bharat saraswal84366c52016-03-23 19:40:35 +0530174import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530175import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
176import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530177import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
178import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
179import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
180import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
181import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
Bharat saraswal84366c52016-03-23 19:40:35 +0530182import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530183import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
Bharat saraswal84366c52016-03-23 19:40:35 +0530184import static org.onosproject.yangutils.utils.UtilConstants.VOID;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530185import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530186import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530187import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
Bharat saraswal84366c52016-03-23 19:40:35 +0530188import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
189import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
190import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530191import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530192import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530193import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530194import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
Bharat saraswal84366c52016-03-23 19:40:35 +0530195import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530196import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530197import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530198import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530199import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
Bharat saraswal8beac342016-08-04 02:00:03 +0530200import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530201import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530202import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530203import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
204import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
205import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
Bharat saraswal84366c52016-03-23 19:40:35 +0530206import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
Bharat saraswal97459962016-02-20 21:57:16 +0530207
208/**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530209 * Represents generator for methods of generated files based on the file type.
Bharat saraswal97459962016-02-20 21:57:16 +0530210 */
211public final class MethodsGenerator {
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530212 private static final String BITS_STRING_ARRAY_VAR = "bitsTemp";
213 private static final String BIT_TEMP_VAR = "bitTemp";
Bharat saraswal97459962016-02-20 21:57:16 +0530214
Bharat saraswal97459962016-02-20 21:57:16 +0530215 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530216 * Creates an instance of method generator.
Bharat saraswal97459962016-02-20 21:57:16 +0530217 */
218 private MethodsGenerator() {
219 }
220
221 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530222 * Returns the methods strings for builder interface.
223 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530224 * @param name attribute name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530225 * @param pluginConfig plugin configurations
Vinod Kumar S08710982016-03-03 19:55:30 +0530226 * @return method string for builder interface
Bharat saraswal97459962016-02-20 21:57:16 +0530227 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530228 public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530229 return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
Bharat saraswal97459962016-02-20 21:57:16 +0530230 }
231
232 /**
233 * Returns getter string.
234 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530235 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530236 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530237 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530238 * @return getter string
239 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530240 public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530241 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530242
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530243 String returnType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530244 String attributeName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +0530245 String appDataStructure = null;
246 if (attr.getCompilerAnnotation() != null) {
247 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
248 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530249 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
250 return generateForGetMethodWithAttribute(returnType)
Vidyashree Ramab3670472016-08-06 15:49:56 +0530251 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530252 attr.getCompilerAnnotation());
Bharat saraswal8beac342016-08-04 02:00:03 +0530253 }
Vinod Kumar S08710982016-03-03 19:55:30 +0530254
Vidyashree Ramab3670472016-08-06 15:49:56 +0530255 return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
256 + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530257 attr.getCompilerAnnotation());
Bharat saraswal97459962016-02-20 21:57:16 +0530258 }
259
260 /**
261 * Returns setter string.
262 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530263 * @param attr attribute info
264 * @param className java class name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530265 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530266 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530267 * @return setter string
268 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530269 public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530270 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530271
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530272 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530273 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530274 JavaDocGen.JavaDocType type;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530275 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530276 type = MANAGER_SETTER_METHOD;
277 } else {
278 type = SETTER_METHOD;
279 }
Bharat saraswal97459962016-02-20 21:57:16 +0530280
Vidyashree Ramab3670472016-08-06 15:49:56 +0530281 String appDataStructure = null;
282 if (attr.getCompilerAnnotation() != null) {
283 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
284 }
285 return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
286 + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles,
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530287 attr.getCompilerAnnotation());
Bharat saraswal97459962016-02-20 21:57:16 +0530288 }
289
290 /**
291 * Returns constructor method string.
292 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530293 * @param name class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530294 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530295 * @return constructor string
296 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530297 private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530298 return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
Bharat saraswal97459962016-02-20 21:57:16 +0530299 }
300
301 /**
302 * Returns default constructor method string.
303 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530304 * @param name class name
Bharat saraswal022dae92016-03-04 20:08:09 +0530305 * @param modifierType modifier type
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530306 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530307 * @return default constructor string
308 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530309 public static String getDefaultConstructorString(String name, String modifierType,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530310 YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530311 return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
312 + getDefaultConstructor(name, modifierType) + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530313 }
314
315 /**
316 * Returns check not null string.
317 *
318 * @param name attribute name
319 * @return check not null string
320 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530321 static String getCheckNotNull(String name) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530322 return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
323 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530324 }
325
326 /**
327 * Returns build method string.
328 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530329 * @param name class name
330 * @param isRootNode if root node
Bharat saraswal97459962016-02-20 21:57:16 +0530331 * @return build string
332 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530333 public static String getBuildString(String name, boolean isRootNode) {
334 if (isRootNode) {
335 return NEW_LINE + getBuild(name, true);
336 }
337 return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name, false);
Bharat saraswal97459962016-02-20 21:57:16 +0530338 }
339
340 /**
341 * Returns the getter method strings for class file.
342 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530343 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530344 * @param generatedJavaFiles for the type of java file being generated
Vinod Kumar S08710982016-03-03 19:55:30 +0530345 * @return getter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530346 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530347 public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530348
Bharat saraswal8beac342016-08-04 02:00:03 +0530349 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530350 String attributeName = attr.getAttributeName();
Bharat saraswal022dae92016-03-04 20:08:09 +0530351
352 if (!attr.isListAttr()) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530353 return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530354 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530355 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
356 return getGetter(attrParam, attributeName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530357 }
358
359 /**
360 * Returns getter for attribute.
361 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530362 * @param type return type
363 * @param name attribute name
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530364 * @param generatedJavaFiles generated java files
Bharat saraswal022dae92016-03-04 20:08:09 +0530365 * @return getter for attribute
366 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530367 static String getGetter(String type, String name, int generatedJavaFiles) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530368 String ret = parseTypeForReturnValue(type);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530369 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530370 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530371 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
372 EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530373 RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530374 } else {
375 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
376 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
377 EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
378 + CLOSE_CURLY_BRACKET;
379 }
Bharat saraswal97459962016-02-20 21:57:16 +0530380 }
381
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530382 /*Provides string to return for type.*/
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530383 private static String parseTypeForReturnValue(String type) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530384 switch (type) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530385 case BYTE:
386 case INT:
387 case SHORT:
388 case LONG:
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530389 case DOUBLE:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530390 return "0";
391 case BOOLEAN_DATA_TYPE:
392 return FALSE;
393 default:
394 return null;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530395 }
396 }
397
Bharat saraswal97459962016-02-20 21:57:16 +0530398 /**
399 * Returns the setter method strings for class file.
400 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530401 * @param attr attribute info
402 * @param className name of the class
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530403 * @param generatedJavaFiles generated java files
Vinod Kumar S08710982016-03-03 19:55:30 +0530404 * @return setter method for class
Bharat saraswal97459962016-02-20 21:57:16 +0530405 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530406 public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530407 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530408 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530409 boolean isTypeNull = false;
410 if (attr.getAttributeType() == null) {
411 isTypeNull = true;
Bharat saraswal022dae92016-03-04 20:08:09 +0530412 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530413 if (!attr.isListAttr()) {
414 return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
415 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530416 String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
417 return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
Bharat saraswal022dae92016-03-04 20:08:09 +0530418 }
419
420 /**
421 * Returns setter for attribute.
422 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530423 * @param className class name
424 * @param name attribute name
425 * @param type return type
426 * @param isTypeNull if attribute type is null
427 * @param isList true if leaf-list
Bharat saraswal022dae92016-03-04 20:08:09 +0530428 * @return setter for attribute
429 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530430 private static String getSetter(String className, String name, String type, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530431 boolean isTypeNull, boolean isList) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530432 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530433 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
janani b703cfe42016-05-17 13:12:22 +0530434 + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530435 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
436 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530437 } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
438 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE
439 + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
440 + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
441 + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530442 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +0530443 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530444 name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
Bharat saraswal8beac342016-08-04 02:00:03 +0530445 + OPEN_CURLY_BRACKET;
446 if (!isTypeNull && !isList) {
447 method = method + getValueLeafSetString(name);
448 } else {
449 method = method + EMPTY_STRING;
450 }
451 return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS +
452 PERIOD + name + SPACE
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530453 + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
454 + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530455 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530456
457 }
458
459 //Returns value leaf flag setter.
460 private static String getValueLeafSetString(String name) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530461 return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
Bharat saraswal97459962016-02-20 21:57:16 +0530462 }
463
464 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530465 * Returns the setter method strings for class file.
466 *
467 * @param attr attribute info
468 * @return setter method for class
469 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530470 static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530471
Bharat saraswal8beac342016-08-04 02:00:03 +0530472 String attrQualifiedType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +0530473 String attributeName = attr.getAttributeName();
Bharat saraswal8beac342016-08-04 02:00:03 +0530474 return getTypeDefSetter(attrQualifiedType, attributeName);
Bharat saraswal022dae92016-03-04 20:08:09 +0530475 }
476
477 /**
478 * Returns type def's setter for attribute.
479 *
480 * @param type data type
481 * @param name attribute name
482 * @return setter for type def's attribute
483 */
484 private static String getTypeDefSetter(String type, String name) {
janani b703cfe42016-05-17 13:12:22 +0530485 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name)
Bharat saraswal84366c52016-03-23 19:40:35 +0530486 + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +0530487 + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN +
488 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530489 }
490
491 /**
492 * Returns override string.
493 *
494 * @return override string
495 */
496 public static String getOverRideString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530497 return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530498 }
499
500 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530501 * Returns the getter method strings for interface file.
502 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530503 * @param yangName name of the attribute
504 * @param returnType return type of attribute
505 * @param isList is list attribute
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530506 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530507 * @param compilerAnnotation compiler annotation
Vinod Kumar S08710982016-03-03 19:55:30 +0530508 * @return getter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530509 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530510 static String getGetterForInterface(String yangName, String returnType, boolean isList,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530511 int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530512 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530513 return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530514 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530515 String listAttr = getListAttribute(returnType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530516 return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530517 }
518
519 /**
520 * Returns getter for attribute in interface.
521 *
522 * @param returnType return type
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530523 * @param yangName attribute name
Bharat saraswal022dae92016-03-04 20:08:09 +0530524 * @return getter for interface
525 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530526 private static String getGetterInterfaceString(String returnType, String yangName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530527 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530528 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530529 return getGetMethodWithArgument(returnType, yangName);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530530 } else {
531 return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
532 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
533 }
Bharat saraswal97459962016-02-20 21:57:16 +0530534 }
535
536 /**
537 * Returns the setter method strings for interface file.
538 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530539 * @param attrName name of the attribute
540 * @param attrType return type of attribute
541 * @param className name of the java class being generated
542 * @param isList is list attribute
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530543 * @param generatedJavaFiles generated java files
Vidyashree Ramab3670472016-08-06 15:49:56 +0530544 * @param compilerAnnotation compiler annotations
Vinod Kumar S08710982016-03-03 19:55:30 +0530545 * @return setter method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530546 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530547 static String getSetterForInterface(String attrName, String attrType, String className,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530548 boolean isList, int generatedJavaFiles,
549 YangCompilerAnnotation compilerAnnotation) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530550 if (!isList) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530551 return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530552 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530553
554 String listAttr = getListAttribute(attrType, compilerAnnotation);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530555 return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
Bharat saraswal022dae92016-03-04 20:08:09 +0530556 }
557
558 /**
559 * Returns setter string for interface.
560 *
561 * @param className class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530562 * @param attrName attribute name
563 * @param attrType attribute type
Bharat saraswal022dae92016-03-04 20:08:09 +0530564 * @return setter string
565 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530566 private static String getSetterInterfaceString(String className, String attrName, String attrType,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530567 int generatedJavaFiles) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530568 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
janani b703cfe42016-05-17 13:12:22 +0530569 return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530570 + OPEN_PARENTHESIS + attrType + OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530571 } else {
572 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
573 + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
574 }
Bharat saraswal97459962016-02-20 21:57:16 +0530575 }
576
577 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530578 * Returns list string.
579 *
580 * @return list string
581 */
582 private static String getListString() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530583 return LIST + DIAMOND_OPEN_BRACKET;
Bharat saraswal022dae92016-03-04 20:08:09 +0530584 }
585
586 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530587 * Returns return type for attribute.
588 *
589 * @param attr attribute info
590 * @return return type
591 */
592 private static String getReturnType(JavaAttributeInfo attr) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530593 String returnType = EMPTY_STRING;
Vidyashree Rama13960652016-04-26 15:06:06 +0530594 if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530595 returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530596 }
597 returnType = returnType + attr.getImportInfo().getClassInfo();
598 return returnType;
599 }
600
601 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530602 * Returns the build method strings for interface file.
603 *
Vinod Kumar S08710982016-03-03 19:55:30 +0530604 * @param yangName name of the interface
605 * @return build method for interface
Bharat saraswal97459962016-02-20 21:57:16 +0530606 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530607 static String getBuildForInterface(String yangName) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530608 return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
609 + NEW_LINE;
Bharat saraswal97459962016-02-20 21:57:16 +0530610 }
611
612 /**
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530613 * Returns constructor string for impl class.
614 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530615 * @param yangName class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530616 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +0530617 * @param isRootNode if root node
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530618 * @return constructor string
619 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530620 static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530621 String javadoc = getConstructorString(yangName, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +0530622
623 String returnType = getCapitalCase(DEFAULT) + yangName;
624 if (isRootNode) {
625 returnType = yangName + OP_PARAM;
626 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530627 String constructor = FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
Bharat saraswald14cbe82016-07-14 13:26:18 +0530628 OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
629 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530630 return javadoc + constructor;
631 }
632
633 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530634 * Returns the constructor strings for class file.
635 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530636 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530637 * @param generatedJavaFiles generated java files
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530638 * @param pluginConfig plugin configurations
Bharat saraswal97459962016-02-20 21:57:16 +0530639 * @return constructor for class
640 */
Bharat saraswald14cbe82016-07-14 13:26:18 +0530641 public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530642 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530643
janani b703cfe42016-05-17 13:12:22 +0530644 String attributeName = attr.getAttributeName();
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530645 String constructor;
Bharat saraswal84366c52016-03-23 19:40:35 +0530646
Bharat saraswal64e7e232016-07-14 23:33:55 +0530647 if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530648 constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
649 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
650 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
651 + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
652 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530653 } else {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530654 constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
655 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
656 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
657 + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
658 OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530659 }
Bharat saraswal022dae92016-03-04 20:08:09 +0530660 return constructor;
Bharat saraswal97459962016-02-20 21:57:16 +0530661 }
662
663 /**
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530664 * Returns the rpc strings for service interface.
665 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530666 * @param rpcName name of the rpc
667 * @param inputName name of input
668 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530669 * @param pluginConfig plugin configurations
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530670 * @return rpc method string
671 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530672 public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530673 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530674
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530675 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530676 if (!inputName.equals(EMPTY_STRING)) {
677 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530678 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530679 return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
680 + CLOSE_PARENTHESIS + SEMI_COLAN;
Gaurav Agrawal02a60de2016-04-20 15:49:17 +0530681 }
682
683 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530684 * Returns the rpc strings for manager impl.
685 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530686 * @param rpcName name of the rpc
687 * @param inputName name of input
688 * @param outputName name of output
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530689 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530690 * @return rpc method string
691 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530692 public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530693 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530694
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530695 rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530696 if (!inputName.equals(EMPTY_STRING)) {
697 inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
Bharat saraswal250a7472016-05-12 13:16:57 +0530698 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530699
Bharat saraswald14cbe82016-07-14 13:26:18 +0530700 String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
701 + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
702 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530703 if (!outputName.contentEquals(VOID)) {
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530704 method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
705 + NEW_LINE;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530706 }
707 method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530708
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530709 return method;
710 }
711
712 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530713 * Returns the build method strings for class file.
714 *
Bharat saraswal8beac342016-08-04 02:00:03 +0530715 * @param yangName class name
716 * @param isRootNode if root node
Vinod Kumar S08710982016-03-03 19:55:30 +0530717 * @return build method string for class
Bharat saraswal97459962016-02-20 21:57:16 +0530718 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530719 static String getBuild(String yangName, boolean isRootNode) {
720 String type = getCapitalCase(DEFAULT) + yangName;
721 if (isRootNode) {
722 type = yangName + OP_PARAM;
723 }
724 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS +
725 CLOSE_PARENTHESIS
Bharat saraswald14cbe82016-07-14 13:26:18 +0530726 + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
Bharat saraswal8beac342016-08-04 02:00:03 +0530727 type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
Bharat saraswald14cbe82016-07-14 13:26:18 +0530728 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal97459962016-02-20 21:57:16 +0530729 }
730
731 /**
732 * Returns the Default constructor strings for class file.
733 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530734 * @param name name of the class
Bharat saraswal022dae92016-03-04 20:08:09 +0530735 * @param modifierType modifier type for default constructor
Bharat saraswal97459962016-02-20 21:57:16 +0530736 * @return Default constructor for class
737 */
Bharat saraswal022dae92016-03-04 20:08:09 +0530738 private static String getDefaultConstructor(String name, String modifierType) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530739 return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
740 + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal97459962016-02-20 21:57:16 +0530741 }
742
Bharat saraswal022dae92016-03-04 20:08:09 +0530743 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530744 * Returns to string method's open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530745 *
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530746 * @return string method's open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530747 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530748 static String getToStringMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530749 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO
750 + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
751 + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530752 }
753
754 /**
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530755 * Returns whether the data type is of primitive data type.
756 *
757 * @param dataType data type to be checked
758 * @return true, if data type can have primitive data type, false otherwise
759 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530760 static boolean isPrimitiveDataType(YangDataTypes dataType) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +0530761 return dataType == INT8
762 || dataType == INT16
763 || dataType == INT32
764 || dataType == INT64
765 || dataType == UINT8
766 || dataType == UINT16
767 || dataType == UINT32
768 || dataType == UINT64
769 || dataType == DECIMAL64
Bharat saraswal039f59c2016-07-14 21:57:13 +0530770 || dataType == BOOLEAN
771 || dataType == EMPTY;
Bharat saraswal64e7e232016-07-14 23:33:55 +0530772
773 }
774
Bharat saraswal64e7e232016-07-14 23:33:55 +0530775
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530776 static String getIfConditionBegin(String indentation, String condition) {
777 return indentation + IF + SPACE + OPEN_PARENTHESIS + condition + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
Bharat saraswal8beac342016-08-04 02:00:03 +0530778 + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530779 }
780
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530781 static String getElseIfConditionBegin(String indentation, String condition) {
782 return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + getIfConditionBegin("", condition);
783 }
784
785 static String getBlockEnd(String indentation) {
786 return indentation + CLOSE_CURLY_BRACKET + NEW_LINE;
787 }
788
789 static String getCollectionIteratorForLoopBegin(String indentation, String loopVar, String collection) {
790 return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE + COLAN + SPACE + collection
791 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530792 }
793
Bharat saraswal039f59c2016-07-14 21:57:13 +0530794 /*
Bharat saraswal8beac342016-08-04 02:00:03 +0530795 * Returns omit null value string.
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530796 *
797 * @return omit null value string
798 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530799 static String getOmitNullValueString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530800 return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
801 }
802
803 /**
804 * Returns to string method's close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530805 *
806 * @return to string method close string
807 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530808 static String getToStringMethodClose() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530809 return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
810 + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530811 }
812
813 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530814 * Returns to string method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530815 *
816 * @param attr attribute info
817 * @return to string method
818 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530819 public static String getToStringMethod(JavaAttributeInfo attr) {
820
janani b703cfe42016-05-17 13:12:22 +0530821 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +0530822 return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
823 + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530824 }
825
826 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530827 * Returns from string method's open string.
828 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530829 * @param className name of the class
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530830 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530831 * @return from string method's open string
832 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530833 static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530834 return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530835 + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
836 + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
837 + OPEN_CURLY_BRACKET + NEW_LINE;
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530838 }
839
840 /**
841 * Return from string method's close string.
842 *
843 * @return from string method's close string
844 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530845 static String getFromStringMethodClose() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530846 return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
847 CLOSE_CURLY_BRACKET + NEW_LINE;
848 }
849
850 /**
851 * Return from string method's body string.
852 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530853 * @param attr attribute info
Bharat saraswal039f59c2016-07-14 21:57:13 +0530854 * @param fromStringAttributeInfo attribute info for the from string wrapper type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530855 * @return from string method's body string
856 */
857 public static String getFromStringMethod(JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530858 JavaAttributeInfo fromStringAttributeInfo) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530859
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530860 return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
Mahesh Poojary S6986df32016-07-19 10:58:07 +0530861 + getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530862 + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString()
863 + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
864 }
865
866 /**
867 * Returns sub string with try statement for union's from string method.
868 *
869 * @return sub string with try statement for union's from string method
870 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530871 private static String getTrySubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530872 return TRY + SPACE + OPEN_CURLY_BRACKET;
873 }
874
875 /**
876 * Returns sub string with return statement for union's from string method.
877 *
878 * @return sub string with return statement for union's from string method
879 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530880 private static String getReturnOfSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530881 return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN;
882 }
883
884 /**
885 * Returns sub string with catch statement for union's from string method.
886 *
887 * @return sub string with catch statement for union's from string method
888 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530889 private static String getCatchSubString() {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530890 return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR
891 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
892 }
893
894 /**
895 * Returns sub string with parsed statement for union's from string method.
896 *
897 * @param attr attribute info
898 * @return sub string with parsed statement for union's from string method
899 */
900 private static String getParsedSubString(JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530901 JavaAttributeInfo fromStringAttributeInfo) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530902
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530903 String targetDataType = getReturnType(attr);
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530904 if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
905 String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
906 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
907 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
908 + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE
909 + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
910 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
911 + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE
912 + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
913 lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
914 + PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
915 lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR
916 + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS
917 + QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
918 lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
919 + BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE
920 + OPEN_CURLY_BRACKET + NEW_LINE;
921 lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD
922 + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
923 lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS
924 + INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS
925 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
926 lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
927 return lines;
928 } else if (attr.getAttributeType().getDataType() == BINARY) {
929 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD
930 + GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS
931 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530932 } else {
933 String parseFromStringMethod = getParseFromStringMethod(targetDataType,
Bharat saraswal748fc3c2016-09-06 16:38:20 +0530934 fromStringAttributeInfo.getAttributeType());
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530935 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +0530936 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +0530937 }
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530938 }
939
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +0530940 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530941 * Returns hash code method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530942 *
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530943 * @return hash code method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530944 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530945 static String getHashCodeMethodOpen() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530946 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
Bharat saraswal8beac342016-08-04 02:00:03 +0530947 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
948 EIGHT_SPACE_INDENTATION
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530949 + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
Bharat saraswal022dae92016-03-04 20:08:09 +0530950 }
951
952 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530953 * Returns hash code methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +0530954 *
955 * @param hashcodeString hash code string
956 * @return to hash code method close string
957 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530958 static String getHashCodeMethodClose(String hashcodeString) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530959 hashcodeString = trimAtLast(hashcodeString, COMMA);
960 hashcodeString = trimAtLast(hashcodeString, SPACE);
Bharat saraswal8beac342016-08-04 02:00:03 +0530961 return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
962 CLOSE_CURLY_BRACKET
Bharat saraswal84366c52016-03-23 19:40:35 +0530963 + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530964 }
965
966 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530967 * Returns hash code method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +0530968 *
969 * @param attr attribute info
970 * @return hash code method
971 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530972 public static String getHashCodeMethod(JavaAttributeInfo attr) {
janani b703cfe42016-05-17 13:12:22 +0530973 return attr.getAttributeName() + COMMA + SPACE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530974 }
975
976 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530977 * Returns equals method open strings.
Bharat saraswal022dae92016-03-04 20:08:09 +0530978 *
979 * @param className class name
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530980 * @return equals method open string
Bharat saraswal022dae92016-03-04 20:08:09 +0530981 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530982 static String getEqualsMethodOpen(String className) {
983 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE +
984 EQUALS_STRING
Bharat saraswal84366c52016-03-23 19:40:35 +0530985 + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
986 + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
Bharat saraswal022dae92016-03-04 20:08:09 +0530987 }
988
989 /**
990 * Returns equal methods if condition string.
991 *
992 * @return if condition string
993 */
994 private static String getEqualsMethodsCommonIfCondition() {
Bharat saraswal84366c52016-03-23 19:40:35 +0530995 return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ
996 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE
997 + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +0530998 }
999
1000 /**
1001 * Returns if condition for specific class object in equals method.
1002 *
1003 * @param className class name
1004 * @return if condition string
1005 */
1006 private static String getEqualsMethodsSpecificIfCondition(String className) {
Bharat saraswal84366c52016-03-23 19:40:35 +05301007 return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className
1008 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className
1009 + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE
1010 + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301011 }
1012
1013 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301014 * Returns equals methods close string.
Bharat saraswal022dae92016-03-04 20:08:09 +05301015 *
1016 * @param equalMethodString equal method string
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301017 * @return equals method close string
Bharat saraswal022dae92016-03-04 20:08:09 +05301018 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301019 static String getEqualsMethodClose(String equalMethodString) {
Bharat saraswal84366c52016-03-23 19:40:35 +05301020 equalMethodString = trimAtLast(equalMethodString, AND);
1021 equalMethodString = trimAtLast(equalMethodString, AND);
1022 equalMethodString = trimAtLast(equalMethodString, SPACE);
1023 equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
1024 return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
1025 + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1026 + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301027 }
1028
1029 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +05301030 * Returns equals method for class.
Bharat saraswal022dae92016-03-04 20:08:09 +05301031 *
1032 * @param attr attribute info
1033 * @return equals method
1034 */
Vinod Kumar S9f26ae52016-03-23 15:30:27 +05301035 public static String getEqualsMethod(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301036
janani b703cfe42016-05-17 13:12:22 +05301037 String attributeName = attr.getAttributeName();
Bharat saraswal84366c52016-03-23 19:40:35 +05301038 return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
1039 + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
1040 + AND;
Bharat saraswal022dae92016-03-04 20:08:09 +05301041 }
1042
1043 /**
1044 * Returns of method string for class.
1045 *
1046 * @param name class name
1047 * @param attr attribute info
1048 * @return of method string
1049 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301050 static String getOfMethod(String name, JavaAttributeInfo attr) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301051 String attrQualifiedType = getReturnType(attr);
Bharat saraswal84366c52016-03-23 19:40:35 +05301052 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301053 + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal84366c52016-03-23 19:40:35 +05301054 + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE
1055 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
Bharat saraswal022dae92016-03-04 20:08:09 +05301056 }
1057
Bharat saraswale2bc60d2016-04-16 02:28:25 +05301058 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301059 * Returns of method's string and java doc for special type.
1060 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301061 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301062 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301063 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301064 * @return of method's string and java doc for special type
1065 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301066 public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301067 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301068
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301069 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301070 String attrName = attr.getAttributeName();
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301071
Vidyashree Ramab3670472016-08-06 15:49:56 +05301072 return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301073 + getOfMethodString(attrType, generatedJavaClassName);
1074 }
1075
1076 /**
1077 * Returns of method's string.
1078 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301079 * @param type data type
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301080 * @param className class name
1081 * @return of method's string
1082 */
1083 private static String getOfMethodString(String type, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301084 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS
1085 + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
1086 + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE
1087 + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1088 }
1089
1090 /**
1091 * Returns string and java doc for constructor of type class.
1092 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301093 * @param attr attribute info
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301094 * @param generatedJavaClassName class name
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301095 * @param pluginConfig plugin configurations
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301096 * @return string and java doc for constructor of type class
1097 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301098 public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301099 String generatedJavaClassName,
1100 YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301101
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301102 String attrType = getReturnType(attr);
janani b703cfe42016-05-17 13:12:22 +05301103 String attrName = attr.getAttributeName();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301104 return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301105 + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
1106 }
1107
1108 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301109 * Returns string and java doc for constructor of type class.
1110 *
1111 * @param attr1 first attribute info
1112 * @param attr2 second attribute info
1113 * @param generatedJavaClassName class name
1114 * @param pluginConfig plugin config
1115 * @param type conflict validate type
Bharat saraswal8beac342016-08-04 02:00:03 +05301116 * @param addFirst whether int came first or uInt came first
Bharat saraswal64e7e232016-07-14 23:33:55 +05301117 * @return string and java doc for constructor of type class
1118 */
1119 public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
1120 attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301121 boolean addFirst) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301122
Bharat saraswal64e7e232016-07-14 23:33:55 +05301123 String attrType = getReturnType(attr1);
1124 String attrName1 = "";
1125 String attrName2 = "";
1126 if (attr1 != null) {
1127 attrName1 = attr1.getAttributeName();
1128 }
1129 if (attr2 != null) {
1130 attrName2 = attr2.getAttributeName();
1131 }
1132
Vidyashree Ramab3670472016-08-06 15:49:56 +05301133 String appDataStructure = null;
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301134 if (attr1 != null && attr1.getCompilerAnnotation() != null) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301135 appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1136 }
1137 return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig,
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301138 appDataStructure) + getTypeConstructorString(attrType, attrName1,
1139 attrName2, generatedJavaClassName, type,
1140 addFirst);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301141 }
1142
1143 /**
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301144 * Returns type constructor string.
1145 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301146 * @param type data type
1147 * @param name attribute name
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301148 * @param className class name
1149 * @return type constructor string
1150 */
1151 private static String getTypeConstructorString(String type, String name, String className) {
Gaurav Agrawal97a5e1c2016-04-18 18:53:11 +05301152 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
1153 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
1154 + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
1155 + CLOSE_CURLY_BRACKET;
1156 }
1157
1158 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301159 * Returns type constructor string.
1160 *
1161 * @param type data type
1162 * @param attr1 attribute attr1
1163 * @param className class attr1
1164 * @return type constructor string
1165 */
1166 private static String getTypeConstructorString(String type, String attr1, String attr2, String className,
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301167 ValidatorTypeForUnionTypes validatorType, boolean addInt) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301168
Bharat saraswal64e7e232016-07-14 23:33:55 +05301169 String constructor;
1170 constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
1171 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1172
1173 String name1;
1174 String name2;
1175 if (addInt) {
1176 name1 = attr1;
1177 name2 = attr2;
1178 } else {
1179 name1 = attr2;
1180 name2 = attr1;
1181 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301182 constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
Bharat saraswal64e7e232016-07-14 23:33:55 +05301183 TWELVE_SPACE_INDENTATION + THIS + PERIOD
1184 + name1 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
1185 + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION
1186 + THIS + PERIOD
1187 + name2 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
1188 + CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION
1189 + CLOSE_CURLY_BRACKET;
1190
1191 return constructor;
1192 }
1193
1194 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301195 * Returns interface of add augmentation.
1196 *
1197 * @return interface of add augmentation
1198 */
1199 static String getAddAugmentInfoMethodInterface() {
1200 return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID + SPACE +
1201 ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
1202 SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1203 }
1204
1205 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301206 * Returns implementation of add augmentation.
1207 *
1208 * @return implementation of add augmentation
1209 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301210 static String getAddAugmentInfoMethodImpl() {
Bharat saraswal8beac342016-08-04 02:00:03 +05301211 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
1212 ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301213 SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
1214 NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
1215 OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301216 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1217 CLOSE_CURLY_BRACKET + NEW_LINE;
1218 }
1219
1220 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301221 * Returns interface of get YANG augment info.
Bharat saraswalaf413b82016-07-14 15:18:20 +05301222 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301223 * @return interface of get YANG augment info
Bharat saraswalaf413b82016-07-14 15:18:20 +05301224 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301225 static String getYangAugmentInfoInterface() {
1226 return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + OBJECT_STRING + SPACE +
1227 getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
1228 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1229 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301230
Bharat saraswal8beac342016-08-04 02:00:03 +05301231 /**
1232 * Returns implementation of get YANG augment info.
1233 *
1234 * @return implementation of get YANG augment info
1235 */
1236 static String getYangAugmentInfoImpl() {
1237 return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
1238 OBJECT_STRING + SPACE +
1239 getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301240 CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
1241 RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
1242 OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1243 CLOSE_CURLY_BRACKET + NEW_LINE;
1244 }
1245
1246 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301247 * Returns implementation of get YANG augment info.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301248 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301249 * @return implementation of get YANG augment info
Bharat saraswal039f59c2016-07-14 21:57:13 +05301250 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301251 static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301252 return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null)
Bharat saraswal8beac342016-08-04 02:00:03 +05301253 + FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
1254 QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
1255 SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
1256 CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1257 }
1258
1259 /**
1260 * Returns implementation of get YANG augment info.
1261 *
1262 * @return implementation of get YANG augment info
1263 */
1264 static String getYangAugmentInfoMapImpl() {
1265 return getOverRideString()
Bharat saraswal039f59c2016-07-14 21:57:13 +05301266 + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
1267 MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
Bharat saraswal8beac342016-08-04 02:00:03 +05301268 DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
1269 getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
Bharat saraswal039f59c2016-07-14 21:57:13 +05301270 CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
1271 RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE
1272 + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1273 }
1274
1275 /**
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301276 * Returns enum's constructor.
1277 *
1278 * @param className enum's class name
1279 * @return enum's constructor
1280 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301281 static String getEnumsConstructor(String className) {
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301282 return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE +
1283 COMMA + SPACE + STRING_DATA_TYPE + SPACE + STR_VAL + CLOSE_PARENTHESIS + SPACE
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301284 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301285 + SPACE + VALUE + SEMI_COLAN + NEW_LINE
1286 + EIGHT_SPACE_INDENTATION + SCHEMA_NAME + SPACE + EQUAL
1287 + SPACE + STR_VAL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
Bharat saraswal68fa0d12016-04-19 01:00:16 +05301288 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301289
1290 /**
1291 * Returns of method for enum class.
1292 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301293 * @param className class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301294 * @param pluginConfig plugin configurations
Bharat saraswal250a7472016-05-12 13:16:57 +05301295 * @return of method
1296 */
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301297 static String getEnumsOfValueMethod(String className, YangEnumeration enumeration,
1298 YangPluginConfig pluginConfig) {
Bharat saraswal250a7472016-05-12 13:16:57 +05301299
janani b703cfe42016-05-17 13:12:22 +05301300 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE
1301 + OF + OPEN_PARENTHESIS
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301302 + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
Bharat saraswal250a7472016-05-12 13:16:57 +05301303 + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
1304 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +05301305 int value;
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301306 String str;
1307 for (YangEnum yangEnum : enumeration.getEnumSet()) {
1308 value = yangEnum.getValue();
1309 str = getEnumJavaAttribute(yangEnum.getNamedValue()).toUpperCase();
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301310 method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
janani b703cfe42016-05-17 13:12:22 +05301311 + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
Bharat saraswal250a7472016-05-12 13:16:57 +05301312 + str + SEMI_COLAN + NEW_LINE;
1313 }
Mahesh Poojary Huawei41547ad2016-07-14 17:49:50 +05301314 method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
Bharat saraswal250a7472016-05-12 13:16:57 +05301315 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1316 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1317
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301318 return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for value", false, pluginConfig, null)
1319 + method;
1320 }
1321
1322 /**
1323 * Returns of method with string value for enum class.
1324 *
1325 * @param enumName enum class name
1326 * @return of method with string value for enum class
1327 */
1328 static String getEnumValueOfSchemaNameMethod(String enumName,
1329 YangPluginConfig pluginConfig,
1330 YangEnumeration enumeration) {
1331
1332 String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(enumName) + SPACE
1333 + OF + OPEN_PARENTHESIS
1334 + STRING_DATA_TYPE + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
1335 + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
1336 + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1337 String value;
1338 for (YangEnum yangEnum : enumeration.getEnumSet()) {
1339
1340 value = getEnumJavaAttribute(yangEnum.getNamedValue()).toUpperCase();
1341 method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + QUOTES +
1342 yangEnum.getNamedValue() + QUOTES + COLON + NEW_LINE
1343 + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(enumName) + PERIOD
1344 + value + SEMI_COLAN + NEW_LINE;
1345 }
1346 method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
1347 + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
1348 + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1349
1350 return getJavaDoc(OF_METHOD, getCapitalCase(enumName) + " for " + SCHEMA_NAME, false, pluginConfig, null)
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301351 + method;
Bharat saraswal250a7472016-05-12 13:16:57 +05301352 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301353
1354 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301355 * Returns from string method parsed string.
1356 *
1357 * @param targetDataType target data type
1358 * @param yangType YANG type
1359 * @return parsed string
1360 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301361 private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301362 YangDataTypes type = yangType.getDataType();
1363
1364 switch (type) {
1365 case INT8:
1366 return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
1367 case INT16:
1368 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
1369 case INT32:
1370 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
1371 case INT64:
1372 return LONG_WRAPPER + PERIOD + PARSE_LONG;
1373 case UINT8:
1374 return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
1375 case UINT16:
1376 return INTEGER_WRAPPER + PERIOD + PARSE_INT;
1377 case UINT32:
1378 return LONG_WRAPPER + PERIOD + PARSE_LONG;
1379 case UINT64:
1380 return NEW + SPACE + BIG_INTEGER;
Mahesh Poojary Huawei2cd44332016-07-14 12:38:17 +05301381 case DECIMAL64:
1382 return NEW + SPACE + BIG_DECIMAL;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301383 case STRING:
Shankara-Huaweib7564772016-08-02 18:13:13 +05301384 case IDENTITYREF:
1385 return EMPTY_STRING;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301386 case EMPTY:
1387 case BOOLEAN:
1388 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301389 case BITS:
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301390 case UNION:
1391 case ENUMERATION:
1392 case DERIVED:
1393 return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
1394 default:
Bharat saraswale3175d32016-08-31 17:50:11 +05301395 throw new TranslatorException("given data type is not supported. " +
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301396 yangType.getDataTypeName() + " in " +
1397 yangType.getLineNumber() + " at " +
1398 yangType.getCharPosition()
1399 + " in " + yangType.getFileName());
Gaurav Agrawalbfce9342016-06-15 13:58:01 +05301400 }
1401 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301402
1403 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301404 * Returns augmented data getter and setter methods for service class.
1405 *
1406 * @param parent parent node
1407 * @return augmented data getter and setter methods for service class
1408 */
Bharat saraswal039f59c2016-07-14 21:57:13 +05301409 static String getAugmentsDataMethodForService(YangNode parent) {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301410 List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
1411 YangNode augmentedNode;
1412 String curNodeName;
1413 String method;
1414 StringBuilder methods = new StringBuilder();
1415 String parentName;
1416 String returnType;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301417 YangNode methodNode;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301418 YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
1419 for (YangAtomicPath nodeId : targets) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301420 augmentedNode = nodeId.getResolvedNode().getParent();
Bharat saraswal64e7e232016-07-14 23:33:55 +05301421 methodNode = nodeId.getResolvedNode();
1422 if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) {
1423 curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +05301424 } else {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301425 curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig
Bharat saraswalaf413b82016-07-14 15:18:20 +05301426 .getConflictResolver()));
1427 }
1428 returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301429 parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +05301430 method = generateForGetMethodWithAttribute(returnType)
1431 + getGetMethodWithArgument(returnType, AUGMENTED + parentName
1432 + getCapitalCase(curNodeName)) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301433 methods.append(method);
1434
1435 method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
Vidyashree Ramab3670472016-08-06 15:49:56 +05301436 getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
Bharat saraswalaf413b82016-07-14 15:18:20 +05301437 getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301438 getCapitalCase(curNodeName), returnType, parentName, false,
1439 GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
Bharat saraswalaf413b82016-07-14 15:18:20 +05301440 methods.append(method);
1441 }
1442 return methods.toString();
1443 }
1444
1445 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301446 * Returns validator method for range in union class.
1447 *
1448 * @param type type
1449 * @return validator method for range in union class
1450 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301451 static String getRangeValidatorMethodForUnion(String type) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301452 String newType;
1453 if (type.contentEquals(BIG_INTEGER)) {
1454 newType = LONG;
1455 } else {
1456 newType = INT;
1457 }
1458 String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
1459 SPACE +
1460 VALIDATE_RANGE +
1461 OPEN_PARENTHESIS
1462 + type + SPACE + MIN_RANGE + COMMA + SPACE + type + SPACE + MAX_RANGE + COMMA + SPACE +
1463 newType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1464 if (type.contentEquals(BIG_INTEGER)) {
1465 method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE + getSmallCase(BIG_INTEGER)
1466 + SPACE + EQUAL + SPACE + NEW + SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
1467 QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
1468 EIGHT_SPACE_INDENTATION + RETURN + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo"
1469 + OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SPACE + AND +
1470 AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
1471 CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SEMI_COLAN + NEW_LINE;
1472 } else {
1473 method = method + EIGHT_SPACE_INDENTATION
1474 + RETURN + SPACE + VALUE + SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE + SPACE + AND +
Bharat saraswale3175d32016-08-31 17:50:11 +05301475 AND + SPACE + VALUE + SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE + SEMI_COLAN +
1476 NEW_LINE;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301477 }
1478 return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
1479 }
1480
1481 /**
1482 * Returns if condition string for typedef constructor.
1483 *
1484 * @param type type of conflict
1485 * @param addFirst true int/long need to be added first
1486 * @return if condition string for typedef constructor
1487 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301488 private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301489 String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS;
1490
1491 if (type == INT_TYPE_CONFLICT) {
1492 if (addFirst) {
1493 condition = condition + INT_MIN_RANGE + COMMA + SPACE + INT_MAX_RANGE + COMMA + SPACE + VALUE;
1494 } else {
1495 condition = condition + UINT_MIN_RANGE + COMMA + SPACE + UINT_MAX_RANGE + COMMA + SPACE + VALUE;
1496 }
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301497 } else if (type == SHORT_TYPE_CONFLICT) {
1498 if (addFirst) {
1499 condition = condition + SHORT_MIN_RANGE + COMMA + SPACE + SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
1500 } else {
1501 condition = condition + UINT8_MIN_RANGE + COMMA + SPACE + UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
1502 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301503 } else {
1504 if (addFirst) {
1505 condition = condition + LONG_MIN_RANGE + COMMA + SPACE + LONG_MAX_RANGE + COMMA + SPACE + VALUE;
1506 } else {
1507 condition = condition + ULONG_MIN_RANGE + COMMA + SPACE + ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
1508 }
1509 }
1510 return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
1511 }
1512
Bharat saraswal8beac342016-08-04 02:00:03 +05301513 //Get method with arguments.
1514 private static String getGetMethodWithArgument(String returnType, String yangName) {
1515 return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
1516 + OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS +
1517 SEMI_COLAN;
1518 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301519
Bharat saraswal8beac342016-08-04 02:00:03 +05301520 /**
1521 * Returns add to list method interface.
1522 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301523 * @param attr java attribute
1524 * @param className name of the class
Bharat saraswal8beac342016-08-04 02:00:03 +05301525 * @return add to list method interface
1526 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301527 public static String getAddToListMethodInterface(JavaAttributeInfo attr, String className) {
1528 return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + ADD_STRING + getCapitalCase(TO) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301529 getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE +
1530 VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
1531 }
1532
1533 /**
1534 * Returns add to list method impl.
1535 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301536 * @param attr java attribute
1537 * @param generatedJavaClassName class name
1538 * @param isRoot is root
Bharat saraswal8beac342016-08-04 02:00:03 +05301539 * @return add to list method impl
1540 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301541 public static String getAddToListMethodImpl(JavaAttributeInfo attr, String generatedJavaClassName, boolean isRoot) {
1542 String retString = "";
1543 if (!isRoot) {
1544 retString = getOverRideString();
1545 }
1546 return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + generatedJavaClassName + BUILDER + SPACE +
1547 ADD_STRING +
Bharat saraswal8beac342016-08-04 02:00:03 +05301548 getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
1549 getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
1550 + NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
1551 + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301552 NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN +
Bharat saraswal8beac342016-08-04 02:00:03 +05301553 NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
1554 }
1555
1556 /**
1557 * Returns builder method for class.
1558 *
1559 * @param name name of class
1560 * @return builder method for class
1561 */
1562 static String builderMethod(String name) {
1563 return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
1564 + name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
1565 OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name +
1566 BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
1567 CLOSE_CURLY_BRACKET;
1568 }
1569
1570 /**
1571 * Returns is filter content match interface.
1572 *
1573 * @param name name of node
1574 * @return is filter content match interface
1575 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301576 static String processSubtreeFilteringInterface(String name) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301577 String method = " /**\n" +
1578 " * Checks if the passed " + name + " maps the content match query condition.\n" +
1579 " *\n" +
1580 " * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" +
1581 " for" +
1582 " content match\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301583 " * @param isSelectAllSchemaChild is select all schema child\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301584 " * @return match result\n" +
1585 " */\n";
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301586 return method + FOUR_SPACE_INDENTATION + name + SPACE + PROCESS_SUBTREE_FILTERING +
1587 OPEN_PARENTHESIS
1588 + name + SPACE + getSmallCase(name) + COMMA + SPACE + BOOLEAN_DATA_TYPE + SPACE +
1589 "isSelectAllSchemaChild" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +05301590 }
1591
1592 /**
1593 * Returns is value set interface.
1594 *
1595 * @return is value set interface
1596 */
1597 static String isLeafValueSetInterface() {
1598 String method = " /**\n" +
1599 " * Checks if the leaf value is set.\n" +
1600 " *\n" +
1601 " * @param leaf leaf whose value status needs to checked\n" +
1602 " * @return result of leaf value set in object\n" +
1603 " */\n";
1604 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS
1605 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1606 }
1607
1608 /**
1609 * Returns is select leaf set interface.
1610 *
1611 * @return is select leaf set interface
1612 */
1613 static String isSelectLeafSetInterface() {
1614 String method = " /**\n" +
1615 " * Checks if the leaf is set to be a selected leaf.\n" +
1616 " *\n" +
1617 " * @param leaf if leaf needs to be selected\n" +
1618 " * @return result of leaf value set in object\n" +
1619 " */\n";
1620 return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS
1621 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1622 }
1623
1624 /**
1625 * Returns set select leaf set interface.
1626 *
1627 * @param name node name
1628 * @return set select leaf set interface
1629 */
1630 static String setSelectLeafSetInterface(String name) {
1631 String method = " /**\n" +
1632 " * Set a leaf to be selected.\n" +
1633 " *\n" +
1634 " * @param leaf leaf needs to be selected\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301635 " * @return builder object for select leaf\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301636 " */\n";
1637 return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS
1638 + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
1639 }
1640
1641 /**
1642 * Returns leaf identifier interface enum signature.
1643 *
1644 * @param name name of node
1645 * @return leaf identifier interface enum signature
1646 */
1647 static String getInterfaceLeafIdEnumSignature(String name) {
1648 String start = " /**\n" +
1649 " * Identify the leaf of " + name + PERIOD + NEW_LINE +
1650 " */\n";
1651 return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE +
1652 OPEN_CURLY_BRACKET + NEW_LINE;
1653 }
1654
1655 /**
1656 * Returns interface leaf identifier enum method.
1657 *
1658 * @return interface leaf identifier enum method
1659 */
1660 static String getInterfaceLeafIdEnumMethods() {
1661 return " private int leafIndex;\n" +
1662 "\n" +
1663 " public int getLeafIndex() {\n" +
1664 " return leafIndex;\n" +
1665 " }\n" +
1666 "\n" +
1667 " LeafIdentifier(int value) {\n" +
1668 " this.leafIndex = value;\n" +
1669 " }\n" +
1670 " }\n";
1671 }
1672
1673 /**
1674 * Returns getter methods for operation attributes.
1675 *
1676 * @return getter methods for operation attributes
1677 */
1678 static String getOperationAttributesGetters() {
1679 return "\n" +
1680 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301681 " * Returns the valueLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301682 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301683 " * @return value of valueLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301684 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301685 " public BitSet getValueLeafFlags() {\n" +
1686 " return valueLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301687 " }\n" +
1688 "\n" +
1689 " /**\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301690 " * Returns the selectLeafFlags.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301691 " *\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301692 " * @return value of selectLeafFlags\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301693 " */\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301694 " public BitSet getSelectLeafFlags() {\n" +
1695 " return selectLeafFlags;\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301696 " }\n" +
1697 "\n";
1698 }
1699
1700 /**
1701 * Returns getter for operation type.
1702 *
1703 * @return getter for operation type
1704 */
1705 static String getGetterForOperationType() {
1706 return " /**\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301707 " * Returns the onosYangNodeOperationType.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301708 " *\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301709 " * @return value of onosYangNodeOperationType\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301710 " */\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301711 " public OnosYangNodeOperationType onosYangNodeOperationType() {\n" +
1712 " return onosYangNodeOperationType;\n" +
1713 " }\n\n";
Bharat saraswal8beac342016-08-04 02:00:03 +05301714 }
1715
1716 /**
1717 * Returns getters for value and select leaf.
1718 *
1719 * @return getters for value and select leaf
1720 */
1721 static String getGettersForValueAndSelectLeaf() {
1722 return "\n" +
1723 " @Override\n" +
1724 " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301725 " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301726 " }\n" +
1727 "\n" +
1728 " @Override\n" +
1729 " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301730 " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301731 " }\n";
1732 }
1733
1734 /**
1735 * Returns setter for operation type.
1736 *
1737 * @param name name of node
1738 * @return setter for operation type
1739 */
1740 static String getSetterForOperationType(String name) {
1741 return " /**\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301742 " * Set node operation type.\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301743 " *\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301744 " * @param onosYangNodeOperationType node operation type\n" +
1745 " * @return builder object for node operation type\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301746 " */\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301747 " public " + name + BUILDER + " onosYangNodeOperationType(OnosYangNodeOperationType " +
1748 "onosYangNodeOperationType) {\n" +
1749 " this.onosYangNodeOperationType = onosYangNodeOperationType;\n" +
Bharat saraswale304c252016-08-16 20:56:20 +05301750 " return this;\n" +
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301751 " }\n\n";
Bharat saraswal8beac342016-08-04 02:00:03 +05301752 }
1753
1754 /**
1755 * Returns setter for select leaf.
1756 *
1757 * @param name name of node
1758 * @param isRootNode if root node
1759 * @return setter for select leaf
1760 */
1761 static String getSetterForSelectLeaf(String name, boolean isRootNode) {
1762 String append = OVERRIDE;
1763 if (isRootNode) {
1764 append = EMPTY_STRING;
1765 }
1766 return "\n" +
1767 " " + append + "\n" +
1768 " public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301769 " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
Bharat saraswal8beac342016-08-04 02:00:03 +05301770 " return this;\n" +
1771 " }\n";
1772 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301773
1774 private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) {
1775 String listAttr;
1776 if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
1777 switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
1778 case QUEUE: {
1779 listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1780 break;
1781 }
1782 case SET: {
1783 listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
1784 break;
1785 }
1786 case LIST: {
1787 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1788 break;
1789 }
1790 default: {
1791 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1792 }
1793 }
1794 } else {
1795 listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
1796 }
1797 return listAttr;
1798 }
Bharat saraswal97459962016-02-20 21:57:16 +05301799}