Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 22 | import java.util.List; |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 23 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangAugment; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 26 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 28 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 29 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangModule; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangSubModule; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 38 | import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo; |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 40 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator; |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 42 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 43 | import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 44 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 45 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 46 | import org.onosproject.yangutils.translator.tojava.YangJavaModelUtils; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 47 | import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 48 | |
| 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK; |
| 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 63 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 67 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; |
| 68 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; |
| 69 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 70 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 71 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 72 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 74 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 75 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 77 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 80 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 81 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 83 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; |
| 85 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 86 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 87 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart; |
| 88 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 90 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod; |
| 91 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; |
| 93 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 94 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoMapImpl; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager; |
| 96 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBaseClassMethodImpl; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 98 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 99 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor; |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 101 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
| 102 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; |
| 104 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 105 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 106 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 107 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
| 109 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 110 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilterContentMatch; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 111 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart; |
| 113 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter; |
| 114 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypegetter; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 115 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
| 116 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 117 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeaf; |
| 118 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeafList; |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 119 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 120 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafListgetter; |
| 121 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafgetter; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 122 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
| 123 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 124 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter; |
| 125 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 126 | import static org.onosproject.yangutils.utils.UtilConstants.BASE64; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 127 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 128 | import static org.onosproject.yangutils.utils.UtilConstants.BITSET; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 129 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 130 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 131 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 132 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 133 | import static org.onosproject.yangutils.utils.UtilConstants.CREATE; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 134 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 135 | import static org.onosproject.yangutils.utils.UtilConstants.DELETE; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 136 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 137 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 138 | import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING; |
| 139 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
| 140 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 141 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; |
| 142 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 143 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 144 | import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF; |
| 145 | import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 146 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 147 | import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 148 | import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF; |
| 149 | import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 150 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 151 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 152 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS; |
| 153 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 154 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 155 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 156 | import static org.onosproject.yangutils.utils.UtilConstants.MERGE; |
| 157 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 158 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 159 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 160 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 161 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 162 | import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM; |
| 163 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 164 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 165 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 166 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
| 167 | import static org.onosproject.yangutils.utils.UtilConstants.REMOVE; |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 168 | import static org.onosproject.yangutils.utils.UtilConstants.REPLACE; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 169 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 170 | import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF; |
| 171 | import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST; |
| 172 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 173 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; |
| 174 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 175 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 176 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 177 | import static org.onosproject.yangutils.utils.UtilConstants.SUPER; |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 178 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 179 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 180 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 181 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 182 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 183 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 184 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 185 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 186 | import static java.util.Collections.sort; |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 187 | |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 188 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 189 | * Representation of java file generator. |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 190 | */ |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 191 | public final class JavaFileGenerator { |
| 192 | |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 193 | private JavaFileGenerator() { |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Returns generated interface file for current node. |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 198 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 199 | * @param file file |
| 200 | * @param imports imports for the file |
| 201 | * @param curNode current YANG node |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 202 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 203 | * @return interface file |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 204 | * @throws IOException when fails to write in file |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 205 | */ |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 206 | public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 207 | boolean isAttrPresent) |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 208 | throws IOException { |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 209 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 210 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 211 | |
| 212 | String path; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 213 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 214 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 215 | } else { |
| 216 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 217 | } |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 218 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 219 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 220 | |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 221 | initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className); |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 222 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 223 | if (isAttrPresent) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 224 | // Add getter methods to interface file. |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 225 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 226 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 227 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, |
| 228 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 229 | .getBeanTempFiles(), path)); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 230 | } catch (IOException e) { |
| 231 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 232 | + " while interface file generation"); |
| 233 | } |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 234 | } |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 235 | return validateLineLength(file); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 239 | * Returns generated builder interface file for current node. |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 240 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 241 | * @param file file |
| 242 | * @param curNode current YANG node |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 243 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 244 | * @return builder interface file |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 245 | * @throws IOException when fails to write in file |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 246 | */ |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 247 | public static File generateBuilderInterfaceFile(File file, YangNode curNode, boolean isAttrPresent) |
| 248 | throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 249 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 250 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 251 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 252 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 253 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 254 | String path; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 255 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 256 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 257 | } else { |
| 258 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 259 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 260 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 261 | initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, className); |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 262 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 263 | if (isAttrPresent) { |
| 264 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 265 | |
| 266 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 267 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, |
| 268 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 269 | .getBeanTempFiles(), path)); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 270 | |
| 271 | //Setter methods. |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 272 | methods.add(NEW_LINE); |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 273 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, |
| 274 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 275 | .getBeanTempFiles(), path)); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 276 | } catch (IOException e) { |
| 277 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 278 | + " while builder interface file generation"); |
| 279 | } |
Bharat saraswal | 8f2a6c5 | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 280 | } |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 281 | |
| 282 | //Add build method to builder interface file. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 283 | methods.add( |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 284 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 285 | .addBuildMethodForInterface(pluginConfig)); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 286 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 287 | |
| 288 | //Add getters and setters in builder interface. |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 289 | for (String method : methods) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 290 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 291 | } |
| 292 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 293 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 294 | return validateLineLength(file); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Returns generated builder class file for current node. |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 299 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 300 | * @param file file |
| 301 | * @param curNode current YANG node |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 302 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 303 | * @return builder class file |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 304 | * @throws IOException when fails to write in file |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 305 | */ |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 306 | public static File generateBuilderClassFile(File file, YangNode curNode, |
| 307 | boolean isAttrPresent) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 308 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 309 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 310 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 311 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 312 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 313 | |
| 314 | String path; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 315 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 316 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 317 | } else { |
| 318 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 319 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 320 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 321 | initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, className); |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 322 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 323 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 324 | if (isAttrPresent) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 325 | |
| 326 | //Add attribute strings. |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 327 | try { |
| 328 | insertDataIntoJavaFile(file, |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 329 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 330 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 331 | .getBeanTempFiles(), path)); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 332 | } catch (IOException e) { |
| 333 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 334 | + " while builder class file generation"); |
| 335 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 336 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 337 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 338 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 339 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
| 340 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 341 | .getBeanTempFiles(), path)); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 342 | // Setter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 343 | methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, |
| 344 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 345 | .getBeanTempFiles(), path)); |
| 346 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 347 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 348 | } catch (IOException e) { |
| 349 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 350 | + " while builder class file generation"); |
| 351 | } |
| 352 | } else { |
| 353 | insertDataIntoJavaFile(file, NEW_LINE); |
| 354 | } |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 355 | |
| 356 | // Add default constructor and build method impl. |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 357 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 358 | .addBuildMethodImpl()); |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 359 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 360 | .addDefaultConstructor(PUBLIC, BUILDER, pluginConfig)); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 361 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 362 | |
| 363 | //Add methods in builder class. |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 364 | for (String method : methods) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 365 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 366 | } |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 367 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 368 | return validateLineLength(file); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 372 | * Returns generated op param builder class file for current node. |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 373 | * |
| 374 | * @param file file handle |
| 375 | * @param curNode current YANG node |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 376 | * @param isAttrPresent if any attribute is present or not |
| 377 | * @return builder class file |
| 378 | * @throws IOException when fails to write in file |
| 379 | */ |
| 380 | public static File generateOpParamBuilderClassFile(File file, YangNode curNode, |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 381 | boolean isAttrPresent) throws IOException { |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 382 | |
| 383 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 384 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
| 385 | |
| 386 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
| 387 | |
| 388 | initiateJavaFileGeneration(file, OPERATION_BUILDER_CLASS_MASK, null, curNode, className); |
| 389 | List<String> methods = new ArrayList<>(); |
| 390 | |
| 391 | if (isAttrPresent) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 392 | //Add attribute strings. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 393 | try { |
| 394 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 395 | OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE); |
| 396 | |
| 397 | } catch (IOException e) { |
| 398 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 399 | + " while impl class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | try { |
| 403 | if (curNode instanceof YangLeavesHolder) { |
| 404 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 405 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 406 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 407 | |
| 408 | if (leaves != null && !leaves.isEmpty()) { |
| 409 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 410 | BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE + |
| 411 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
| 412 | + NEW_LINE); |
| 413 | |
| 414 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 415 | BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE + |
| 416 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 417 | + SEMI_COLAN + NEW_LINE); |
| 418 | } |
| 419 | |
| 420 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 421 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 422 | BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 423 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 424 | + SEMI_COLAN + NEW_LINE); |
| 425 | |
| 426 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 427 | BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 428 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 429 | + SEMI_COLAN + NEW_LINE); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | } catch (IOException e) { |
| 434 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 435 | + " while impl class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 439 | // Setter methods. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 440 | methods.add(getSetterForLeaf(className, curNode, pluginConfig)); |
| 441 | methods.add(getSetterForLeafList(className, curNode, pluginConfig)); |
| 442 | |
| 443 | if (curNode instanceof YangLeavesHolder) { |
| 444 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 445 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 446 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 447 | |
| 448 | if (leaves != null && !leaves.isEmpty()) { |
| 449 | methods.add(getToStringLeafgetter()); |
| 450 | methods.add(getToStringSelectLeafgetter()); |
| 451 | } |
| 452 | |
| 453 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 454 | methods.add(getToStringLeafListgetter()); |
| 455 | methods.add(getToStringSelectLeafListgetter()); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | methods.add(getOperationTypegetter()); |
| 460 | methods.add(getOperationTypeSetter()); |
| 461 | insertDataIntoJavaFile(file, NEW_LINE); |
| 462 | } catch (IOException e) { |
| 463 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 464 | + " while builder class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 465 | } |
| 466 | } else { |
| 467 | insertDataIntoJavaFile(file, NEW_LINE); |
| 468 | } |
| 469 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 470 | // Add methods in builder class. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 471 | for (String method : methods) { |
| 472 | insertDataIntoJavaFile(file, method); |
| 473 | } |
| 474 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
| 475 | return validateLineLength(file); |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /** |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 480 | * Returns generated manager class file for current node. |
| 481 | * |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 482 | * @param file file |
| 483 | * @param imports imports for the file |
| 484 | * @param curNode current YANG node |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 485 | * @return builder class file |
| 486 | * @throws IOException when fails to write in file |
| 487 | */ |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 488 | public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode) |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 489 | throws IOException { |
| 490 | |
| 491 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 492 | |
janani b | dd1314f | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 493 | String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 494 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 495 | |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 496 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 497 | |
| 498 | List<String> methods = new ArrayList<>(); |
| 499 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 500 | insertDataIntoJavaFile(file, LOGGER_STATEMENT); |
| 501 | methods.add(addActivateMethod()); |
| 502 | methods.add(addDeActivateMethod()); |
| 503 | |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 504 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 505 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 506 | |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 507 | JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 508 | tempJavaServiceFragmentFiles); |
| 509 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 510 | //Getter methods. |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 511 | methods.add(getOverRideString() + |
| 512 | getGetterForClass(rootAttribute, GENERATE_SERVICE_AND_MANAGER) + NEW_LINE); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 513 | // Setter methods. |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 514 | methods.add(getOverRideString() + |
| 515 | getSetterForClass(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER) |
| 516 | + NEW_LINE); |
| 517 | |
| 518 | methods.add(getAugmentsDataMethodForManager(curNode) + NEW_LINE); |
| 519 | |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 520 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 521 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
| 522 | |
| 523 | //Rpc methods |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 524 | methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 525 | javaGenInfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 526 | } |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 527 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 528 | |
| 529 | } catch (IOException e) { |
| 530 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 531 | + " while manager class file generation"); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 532 | } |
| 533 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 534 | // Add methods in builder class. |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 535 | for (String method : methods) { |
| 536 | insertDataIntoJavaFile(file, method); |
| 537 | } |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 538 | return validateLineLength(file); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 542 | * Returns generated impl class file for current node. |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 543 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 544 | * @param file file |
| 545 | * @param curNode current YANG node |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 546 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 547 | * @param imports list of imports |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 548 | * @return impl class file |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 549 | * @throws IOException when fails to write in file |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 550 | */ |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 551 | public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent, List<String> imports) |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 552 | throws IOException { |
| 553 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 554 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 555 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 556 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 557 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 558 | String path; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 559 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 560 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath(); |
| 561 | } else { |
| 562 | path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 563 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 564 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 565 | initiateJavaFileGeneration(file, IMPL_CLASS_MASK, imports, curNode, className); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 566 | |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 567 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 568 | if (curNode instanceof YangAugmentableNode) { |
| 569 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
| 570 | } |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 571 | if (isAttrPresent) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 572 | |
| 573 | //Add attribute strings. |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 574 | try { |
| 575 | insertDataIntoJavaFile(file, |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 576 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 577 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 578 | .getBeanTempFiles(), path)); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 579 | } catch (IOException e) { |
| 580 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 581 | + " while impl class file generation"); |
| 582 | } |
Bharat saraswal | 8f2a6c5 | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 583 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 584 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 585 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 586 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
| 587 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 588 | .getBeanTempFiles(), path)); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 589 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 590 | |
| 591 | // Hash code method. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 592 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 593 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 594 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 595 | .getBeanTempFiles(), path).replace(NEW_LINE, EMPTY_STRING))); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 596 | |
| 597 | //Equals method. |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 598 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(getCapitalCase(DEFAULT) + className) |
| 599 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 600 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 601 | .getBeanTempFiles(), path))); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 602 | |
| 603 | // To string method. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 604 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 605 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 606 | .getBeanTempFiles(), path) |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 607 | + getToStringMethodClose()); |
| 608 | |
| 609 | } catch (IOException e) { |
| 610 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 611 | + " while impl class file generation"); |
| 612 | } |
| 613 | } else { |
| 614 | insertDataIntoJavaFile(file, NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 615 | } |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 616 | try { |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 617 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 618 | //Constructor. |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 619 | String constructor = getConstructorStart(className, pluginConfig); |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 620 | constructor = constructor + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, |
| 621 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 622 | .getBeanTempFiles(), path); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 623 | |
| 624 | methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 625 | } catch (IOException e) { |
| 626 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 627 | + " while impl class file generation"); |
Vinod Kumar S | c421600 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 628 | } |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 629 | |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 630 | if (curNode instanceof YangAugmentableNode) { |
| 631 | methods.add(getAddAugmentInfoMethodImpl()); |
| 632 | methods.add(getAugmentInfoImpl()); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 633 | methods.add(getAugmentInfoMapImpl(javaFileInfo.getPluginConfig())); |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 634 | } |
| 635 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 636 | // Add methods in impl class. |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 637 | for (String method : methods) { |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 638 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 639 | } |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 640 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 641 | return validateLineLength(file); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /** |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 645 | * Returns generated op param class file for current node. |
| 646 | * |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 647 | * @param file file handle |
| 648 | * @param curNode current YANG node |
| 649 | * @param isAttrPresent if any attribute is present or not |
| 650 | * @param imports import list |
| 651 | * @return returns generated op param class file for current node |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 652 | * @throws IOException when fails to write in file |
| 653 | */ |
| 654 | public static File generateOpParamImplClassFile(File file, YangNode curNode, |
| 655 | boolean isAttrPresent, List<String> imports) |
| 656 | throws IOException { |
| 657 | |
| 658 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 659 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
| 660 | |
| 661 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 662 | |
| 663 | initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className); |
| 664 | |
| 665 | List<String> methods = new ArrayList<>(); |
| 666 | |
| 667 | if (isAttrPresent) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 668 | |
| 669 | // Add attribute strings. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 670 | try { |
| 671 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + |
| 672 | SPACE + ENUM + SPACE + OPERATION_ENUM + SPACE + OPEN_CURLY_BRACKET + |
| 673 | NEW_LINE + EIGHT_SPACE_INDENTATION + MERGE + |
| 674 | NEW_LINE + EIGHT_SPACE_INDENTATION + REPLACE + |
| 675 | NEW_LINE + EIGHT_SPACE_INDENTATION + CREATE + |
| 676 | NEW_LINE + EIGHT_SPACE_INDENTATION + DELETE + |
| 677 | NEW_LINE + EIGHT_SPACE_INDENTATION + REMOVE + |
| 678 | NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE); |
| 679 | |
| 680 | } catch (IOException e) { |
| 681 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 682 | + " while impl class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 683 | } |
| 684 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 685 | |
| 686 | // Add attribute strings. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 687 | try { |
| 688 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 689 | OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE); |
| 690 | |
| 691 | } catch (IOException e) { |
| 692 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 693 | + " while impl class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | try { |
| 697 | if (curNode instanceof YangLeavesHolder) { |
| 698 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 699 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 700 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 701 | |
| 702 | if (leaves != null && !leaves.isEmpty()) { |
| 703 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 704 | BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE + |
| 705 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 706 | + SEMI_COLAN + NEW_LINE); |
| 707 | |
| 708 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 709 | BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE + |
| 710 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 711 | + SEMI_COLAN + NEW_LINE); |
| 712 | } |
| 713 | |
| 714 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 715 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 716 | BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 717 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 718 | + SEMI_COLAN + NEW_LINE); |
| 719 | |
| 720 | insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE + |
| 721 | BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE + |
| 722 | NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 723 | + SEMI_COLAN + NEW_LINE); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | } catch (IOException e) { |
| 728 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 729 | + " while impl class file generation"); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | if (curNode instanceof YangLeavesHolder) { |
| 733 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 734 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 735 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 736 | |
| 737 | if (leaves != null && !leaves.isEmpty()) { |
| 738 | methods.add(getToStringLeafgetter()); |
| 739 | methods.add(getToStringSelectLeafgetter()); |
| 740 | } |
| 741 | |
| 742 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 743 | methods.add(getToStringLeafListgetter()); |
| 744 | methods.add(getToStringSelectLeafListgetter()); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | methods.add(getOperationTypegetter()); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 749 | methods.add(getIsFilterContentMatch(className, curNode, pluginConfig)); |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 750 | |
| 751 | } else { |
| 752 | insertDataIntoJavaFile(file, NEW_LINE); |
| 753 | } |
| 754 | String constructor = getOpParamConstructorStart(className, pluginConfig); |
| 755 | |
| 756 | constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS |
| 757 | + BUILDER.toLowerCase() + OBJECT |
| 758 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 759 | |
| 760 | if (curNode instanceof YangLeavesHolder) { |
| 761 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 762 | List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); |
| 763 | List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList(); |
| 764 | String filterLeaf = ""; |
| 765 | String filterLeafList = ""; |
| 766 | |
| 767 | if (leaves != null && !leaves.isEmpty()) { |
| 768 | filterLeaf = EIGHT_SPACE_INDENTATION + FILTER_LEAF + SPACE + EQUAL + SPACE |
| 769 | + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF + OPEN_PARENTHESIS |
| 770 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 771 | } |
| 772 | |
| 773 | if (listOfLeafList != null && !listOfLeafList.isEmpty()) { |
| 774 | filterLeafList = EIGHT_SPACE_INDENTATION + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE |
| 775 | + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS |
| 776 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
| 777 | } |
| 778 | |
| 779 | constructor = constructor + filterLeaf + filterLeafList; |
| 780 | } |
| 781 | |
| 782 | methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); |
| 783 | |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 784 | if (curNode instanceof YangAugment) { |
| 785 | String clsName = getCapitalCase(DEFAULT) + |
| 786 | getCapitalCase(YangJavaModelUtils.getAugmentClassName((YangAugment) curNode, pluginConfig)); |
| 787 | methods.add(getBaseClassMethodImpl(clsName)); |
| 788 | } |
| 789 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 790 | // Add methods in impl class. |
Shankara-Huawei | b9999eb | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 791 | for (String method : methods) { |
| 792 | insertDataIntoJavaFile(file, method); |
| 793 | } |
| 794 | |
| 795 | |
| 796 | return validateLineLength(file); |
| 797 | } |
| 798 | |
| 799 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 800 | * Generates class file for type def. |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 801 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 802 | * @param file generated file |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 803 | * @param curNode current YANG node |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 804 | * @param imports imports for file |
| 805 | * @return type def class file |
| 806 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 807 | */ |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 808 | public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports) |
| 809 | throws IOException { |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 810 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 811 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 812 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 813 | |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 814 | // import |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 815 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 816 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 817 | YangTypeDef typeDef = (YangTypeDef) curNode; |
| 818 | List<YangType<?>> types = typeDef.getTypeList(); |
| 819 | YangType type = types.get(0); |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 820 | YangDataTypes yangDataTypes = type.getDataType(); |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 821 | if (type.getDataType().equals(YangDataTypes.BINARY)) { |
| 822 | imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_IMPORT_BASE64_CLASS); |
| 823 | } |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 824 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 825 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 826 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 827 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 828 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 829 | |
| 830 | //Add attribute strings. |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 831 | try { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 832 | insertDataIntoJavaFile(file, |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 833 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 834 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 835 | .getTypeTempFiles(), path)); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 836 | } catch (IOException e) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 837 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 838 | + " while type def class file generation"); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 839 | } |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 840 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 841 | |
| 842 | //Default constructor. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 843 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 844 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 845 | |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 846 | try { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 847 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 848 | |
| 849 | //Type constructor. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 850 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 851 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 852 | path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 853 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 854 | |
| 855 | //Of method. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 856 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 857 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 858 | path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 859 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 860 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 861 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 862 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 863 | path)); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 864 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 865 | |
| 866 | // Hash code method. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 867 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 868 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 869 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 870 | .getTypeTempFiles(), path) |
| 871 | .replace(NEW_LINE, EMPTY_STRING))); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 872 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 873 | |
| 874 | //Equals method. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 875 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 876 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 877 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 878 | .getTypeTempFiles(), path))); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 879 | |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 880 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 881 | //To string method. |
| 882 | if (type.getDataType().equals(YangDataTypes.BINARY)) { |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 883 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 884 | getCapitalCase("binary")); |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 885 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 886 | JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "binary", null, false, |
| 887 | false); |
| 888 | String attributeName = attr.getAttributeName(); |
| 889 | String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC |
| 890 | + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 891 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 892 | + RETURN + SPACE + BASE64 + PERIOD + GET_ENCODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
| 893 | + PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + attributeName + CLOSE_PARENTHESIS |
| 894 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
| 895 | methods.add(bitsToStringMethod); |
| 896 | } else if (type.getDataType().equals(YangDataTypes.BITS)) { |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 897 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 898 | getCapitalCase("bits")); |
| 899 | |
| 900 | JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "bits", null, false, false); |
| 901 | String attributeName = attr.getAttributeName(); |
| 902 | String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC |
| 903 | + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 904 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
| 905 | + RETURN + SPACE + attributeName + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS |
| 906 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
| 907 | + NEW_LINE; |
| 908 | methods.add(bitsToStringMethod); |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 909 | } else { |
| 910 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 911 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 912 | .getTypeTempFiles(), path) + getToStringMethodClose()); |
Mahesh Poojary Huawei | 30c116a | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 913 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 914 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 915 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
| 916 | |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame^] | 917 | if ((type.getDataType().equals(YangDataTypes.DERIVED)) |
| 918 | && (((YangDerivedInfo) type.getDataTypeExtendedInfo()).getEffectiveBuiltInType() |
| 919 | .equals(YangDataTypes.IDENTITYREF))) { |
| 920 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 921 | } |
| 922 | |
| 923 | if (type.getDataType().equals(YangDataTypes.IDENTITYREF)) { |
| 924 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 925 | } |
| 926 | |
| 927 | if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) { |
| 928 | |
| 929 | |
| 930 | //From string method. |
| 931 | methods.add(getFromStringMethodSignature(className, pluginConfig) |
| 932 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGenInfo |
| 933 | .getTempJavaCodeFragmentFiles() |
| 934 | .getTypeTempFiles(), path) |
| 935 | + getFromStringMethodClose()); |
| 936 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 937 | |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 938 | } catch (IOException e) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 939 | throw new IOException("No data found in temporary java code fragment files for " + className |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 940 | + " while type def class file generation"); |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 941 | } |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 942 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 943 | for (String method : methods) { |
| 944 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 945 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 946 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 947 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 948 | return validateLineLength(file); |
Bharat saraswal | 2f00b4b | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 949 | } |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 950 | |
| 951 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 952 | * Generates class file for union type. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 953 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 954 | * @param file generated file |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 955 | * @param curNode current YANG node |
| 956 | * @param imports imports for file |
| 957 | * @return type def class file |
| 958 | * @throws IOException when fails to generate class file |
| 959 | */ |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 960 | public static File generateUnionClassFile(File file, YangNode curNode, List<String> imports) |
| 961 | throws IOException { |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 962 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 963 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 964 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 965 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 966 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 967 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 968 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 969 | TempJavaTypeFragmentFiles tempJavaTypeFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 970 | .getTempJavaCodeFragmentFiles().getTypeTempFiles(); |
| 971 | |
| 972 | boolean isIntConflict = false; |
| 973 | boolean isLongConflict = false; |
| 974 | JavaAttributeInfo intAttr = tempJavaTypeFragmentFiles.getIntAttribute(); |
| 975 | if (intAttr == null) { |
| 976 | intAttr = tempJavaTypeFragmentFiles.getUIntAttribute(); |
| 977 | } |
| 978 | |
| 979 | JavaAttributeInfo longAttr = tempJavaTypeFragmentFiles.getLongAttribute(); |
| 980 | if (longAttr == null) { |
| 981 | longAttr = tempJavaTypeFragmentFiles.getULongAttribute(); |
| 982 | } |
| 983 | |
| 984 | if (intAttr != null) { |
| 985 | isIntConflict = intAttr.isIntConflict(); |
| 986 | } |
| 987 | if (longAttr != null) { |
| 988 | isLongConflict = longAttr.isLongConflict(); |
| 989 | } |
| 990 | |
| 991 | if (isLongConflict) { |
| 992 | imports.add(tempJavaTypeFragmentFiles.getJavaImportData().getBigIntegerImport()); |
| 993 | sort(imports); |
| 994 | } |
| 995 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 996 | initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path, pluginConfig); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 997 | |
| 998 | List<String> methods = new ArrayList<>(); |
| 999 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1000 | |
| 1001 | // Add attribute strings. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1002 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1003 | if (isIntConflict) { |
| 1004 | insertDataIntoJavaFile(file, JavaCodeSnippetGen.addStaticAttributeIntRange(PRIVATE, |
| 1005 | tempJavaTypeFragmentFiles.getIntIndex() < tempJavaTypeFragmentFiles.getUIntIndex())); |
| 1006 | } |
| 1007 | |
| 1008 | if (isLongConflict) { |
| 1009 | insertDataIntoJavaFile(file, JavaCodeSnippetGen.addStaticAttributeLongRange(PRIVATE, |
| 1010 | tempJavaTypeFragmentFiles.getLongIndex() < tempJavaTypeFragmentFiles.getULongIndex())); |
| 1011 | } |
| 1012 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1013 | insertDataIntoJavaFile(file, |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1014 | NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 1015 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1016 | .getTypeTempFiles(), path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1017 | } catch (IOException e) { |
| 1018 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1019 | + " while union class file generation"); |
| 1020 | } |
| 1021 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1022 | |
| 1023 | //Default constructor. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1024 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1025 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1026 | |
| 1027 | try { |
| 1028 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1029 | |
| 1030 | //Type constructor. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1031 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1032 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1033 | path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1034 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1035 | |
| 1036 | // Of string method. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1037 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1038 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1039 | path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1040 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1041 | //Getter methods. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1042 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1043 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
| 1044 | path)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1045 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1046 | |
| 1047 | //Hash code method. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1048 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1049 | getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, |
| 1050 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1051 | .getTypeTempFiles(), path) |
| 1052 | .replace(NEW_LINE, EMPTY_STRING))); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1053 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1054 | //Equals method. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1055 | methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1056 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1057 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1058 | .getTypeTempFiles(), path))); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1059 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1060 | |
| 1061 | //To string method. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1062 | methods.add(getToStringMethodOpen() + getOmitNullValueString() + |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1063 | getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 1064 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1065 | .getTypeTempFiles(), path) |
| 1066 | + getToStringMethodClose()); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1067 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1068 | |
| 1069 | //From string method. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1070 | methods.add(getFromStringMethodSignature(className, pluginConfig) |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1071 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1072 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1073 | .getTypeTempFiles(), path) |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1074 | + getFromStringMethodClose()); |
| 1075 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1076 | if (isIntConflict) { |
| 1077 | methods.add(MethodsGenerator.getRangeValidatorMethodForUnion(INT)); |
| 1078 | } |
| 1079 | if (isLongConflict) { |
| 1080 | methods.add(MethodsGenerator.getRangeValidatorMethodForUnion(BIG_INTEGER)); |
| 1081 | } |
| 1082 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1083 | } catch (IOException e) { |
| 1084 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1085 | + " while union class file generation"); |
| 1086 | } |
| 1087 | |
| 1088 | for (String method : methods) { |
| 1089 | insertDataIntoJavaFile(file, method); |
| 1090 | } |
| 1091 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1092 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1093 | return validateLineLength(file); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1094 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1095 | |
| 1096 | /** |
| 1097 | * Generates class file for type enum. |
| 1098 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1099 | * @param file generated file |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1100 | * @param curNode current YANG node |
| 1101 | * @return class file for type enum |
| 1102 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1103 | */ |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1104 | public static File generateEnumClassFile(File file, YangNode curNode) |
| 1105 | throws IOException { |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1106 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1107 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1108 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1109 | |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1110 | String className = javaFileInfo.getJavaName(); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1111 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 1112 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1113 | initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path, pluginConfig); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1114 | |
| 1115 | //Add attribute strings. |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1116 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1117 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1118 | insertDataIntoJavaFile(file, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1119 | trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, javaGenInfo |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1120 | .getTempJavaCodeFragmentFiles().getEnumerationTempFiles(), path), COMMA), NEW_LINE) |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1121 | + SEMI_COLAN + NEW_LINE); |
| 1122 | } catch (IOException e) { |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1123 | throw new IOException("No data found in temporary java code fragment files for " + getCapitalCase(className) |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1124 | + " while enum class file generation"); |
| 1125 | } |
| 1126 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1127 | |
| 1128 | // Add an attribute to get the enum's values. |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1129 | insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className))); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1130 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1131 | // Add a constructor for enum. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1132 | insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig) |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1133 | + getEnumsConstructor(getCapitalCase(className)) + NEW_LINE); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1134 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1135 | TempJavaEnumerationFragmentFiles enumFragFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1136 | .getTempJavaCodeFragmentFiles() |
| 1137 | .getEnumerationTempFiles(); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1138 | insertDataIntoJavaFile(file, getEnumsOfMethod(className, |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1139 | enumFragFiles.getJavaAttributeForEnum(pluginConfig), |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1140 | enumFragFiles.getEnumSetJavaMap(), |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1141 | enumFragFiles.getEnumStringList(), pluginConfig) |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1142 | + NEW_LINE); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1143 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1144 | // Add a getter method for enum. |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1145 | insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig) |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1146 | + getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1147 | |
| 1148 | try { |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1149 | insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig) |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1150 | + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1151 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1152 | .getEnumerationTempFiles(), path) |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1153 | + getFromStringMethodClose()); |
| 1154 | } catch (IOException e) { |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1155 | throw new IOException("No data found in temporary java code fragment files for " + |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1156 | getCapitalCase(className) + " while enum class file generation"); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1157 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1158 | |
| 1159 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1160 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1161 | return validateLineLength(file); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1162 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1163 | |
| 1164 | /** |
| 1165 | * Generates interface file for rpc. |
| 1166 | * |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1167 | * @param file generated file |
| 1168 | * @param curNode current YANG node |
| 1169 | * @param imports imports for file |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1170 | * @return rpc class file |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1171 | * @throws IOException when fails to generate class file |
| 1172 | */ |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1173 | public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports) |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1174 | throws IOException { |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1175 | |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1176 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1177 | |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1178 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1179 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
janani b | 4a6711a | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1180 | String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1181 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1182 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1183 | |
| 1184 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1185 | JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 1186 | tempJavaServiceFragmentFiles); |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1187 | |
| 1188 | try { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1189 | |
| 1190 | //Getter methods. |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1191 | methods.add(getGetterString(rootAttribute, GENERATE_SERVICE_AND_MANAGER, |
| 1192 | javaFileInfo.getPluginConfig()) + NEW_LINE); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1193 | // Setter methods. |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1194 | methods.add(getSetterString(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER, |
| 1195 | javaFileInfo.getPluginConfig()) + NEW_LINE); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1196 | |
Bharat saraswal | b551aae | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1197 | methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE); |
| 1198 | |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1199 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1200 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
| 1201 | |
| 1202 | // Rpc methods |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1203 | methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1204 | javaGenInfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)); |
Bharat saraswal | c0e0484 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1205 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1206 | } catch (IOException e) { |
| 1207 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1208 | + " while rpc class file generation"); |
| 1209 | } |
| 1210 | |
| 1211 | for (String method : methods) { |
| 1212 | insertDataIntoJavaFile(file, method); |
| 1213 | } |
| 1214 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1215 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1216 | return validateLineLength(file); |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1217 | } |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1218 | |
| 1219 | /** |
| 1220 | * Generates event file. |
| 1221 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1222 | * @param file generated file |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1223 | * @param curNode current YANG node |
| 1224 | * @param imports imports for file |
| 1225 | * @throws IOException when fails to generate class file |
| 1226 | */ |
Bharat saraswal | ab4c6ba | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1227 | public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException { |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1228 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1229 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1230 | + EVENT_STRING; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1231 | |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1232 | TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1233 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1234 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1235 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath() |
| 1236 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1237 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className); |
| 1238 | try { |
| 1239 | insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() + |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1240 | trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles, path), COMMA) |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1241 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1242 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1243 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles, path)); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1244 | |
| 1245 | } catch (IOException e) { |
| 1246 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1247 | + " while event class file generation"); |
| 1248 | } |
| 1249 | |
| 1250 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1251 | validateLineLength(file); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * Generates event listener file. |
| 1256 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1257 | * @param file generated file |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1258 | * @param curNode current YANG node |
| 1259 | * @param imports imports for file |
| 1260 | * @throws IOException when fails to generate class file |
| 1261 | */ |
| 1262 | public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports) |
| 1263 | throws IOException { |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1264 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1265 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1266 | + EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1267 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1268 | initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1269 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1270 | validateLineLength(file); |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Generates event subject's file. |
| 1275 | * |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1276 | * @param file file handle |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1277 | * @param curNode current YANG node |
| 1278 | * @throws IOException when fails to do IO exceptions |
| 1279 | */ |
| 1280 | public static void generateEventSubjectFile(File file, YangNode curNode) |
| 1281 | throws IOException { |
| 1282 | |
| 1283 | String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName()) |
| 1284 | + EVENT_SUBJECT_NAME_SUFFIX; |
| 1285 | |
| 1286 | initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className); |
| 1287 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1288 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath() |
| 1289 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath(); |
Bharat saraswal | d50c638 | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1290 | |
| 1291 | TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1292 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1293 | |
| 1294 | insertDataIntoJavaFile(file, NEW_LINE); |
| 1295 | try { |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1296 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path)); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1297 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1298 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles, path)); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1299 | |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1300 | insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles, path)); |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1301 | |
| 1302 | } catch (IOException e) { |
| 1303 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 1304 | + " while event class file generation"); |
| 1305 | } |
| 1306 | |
| 1307 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1308 | validateLineLength(file); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1309 | } |
Bharat saraswal | 4bf8b15 | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1310 | } |