Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | c46ee2a | 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 | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 22 | import java.util.List; |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 23 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangCase; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangChoice; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 28 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangModule; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangSubModule; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.YangType; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 38 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 39 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 40 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 41 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator; |
| 42 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 43 | import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 44 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 45 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 46 | import org.onosproject.yangutils.utils.io.YangPluginConfig; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 47 | |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 48 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY; |
| 49 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS; |
| 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
| 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK; |
| 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
| 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
| 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
| 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
| 60 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK; |
| 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK; |
| 63 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
| 64 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
| 65 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
| 66 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
| 67 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
| 68 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; |
| 69 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; |
| 70 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 71 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 72 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
| 73 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
| 74 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 75 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 76 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
| 77 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK; |
| 78 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
| 79 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
| 80 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 81 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 82 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 83 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
| 84 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode; |
| 85 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; |
| 86 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getQualifierInfoForCasesParent; |
| 87 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired; |
| 88 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute; |
| 89 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute; |
| 90 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart; |
| 91 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributeForConstructor; |
| 92 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributes; |
| 93 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeAttr; |
| 94 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum; |
| 95 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeForConstructor; |
| 96 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen |
| 97 | .getYangAugmentedMapObjectForConstruct; |
| 98 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
| 99 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
| 100 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.builderMethod; |
| 101 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; |
| 102 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodInterface; |
| 103 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService; |
| 104 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
| 105 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumValueOfSchemaNameMethod; |
| 106 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor; |
| 107 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfValueMethod; |
| 108 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
| 109 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
| 110 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; |
| 111 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; |
| 112 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter; |
| 113 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForOperationType; |
| 114 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 115 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGettersForValueAndSelectLeaf; |
| 116 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
| 117 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
| 118 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumMethods; |
| 119 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature; |
| 120 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; |
| 121 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationAttributesGetters; |
| 122 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
| 123 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion; |
| 124 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForOperationType; |
| 125 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf; |
| 126 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 127 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
| 128 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
| 129 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoImpl; |
| 130 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoInterface; |
| 131 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapImpl; |
| 132 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapInterface; |
| 133 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface; |
| 134 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface; |
| 135 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.processSubtreeFilteringInterface; |
| 136 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface; |
| 137 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 138 | .getAugmentableSubTreeFiltering; |
| 139 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 140 | .getProcessChildNodeSubtreeFiltering; |
| 141 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 142 | .getProcessLeafListSubtreeFiltering; |
| 143 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 144 | .getProcessLeafSubtreeFiltering; |
| 145 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 146 | .getProcessSubTreeFilteringEnd; |
| 147 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 148 | .getProcessSubtreeFilteringStart; |
| 149 | import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator |
| 150 | .getProcessSubtreeFunctionBody; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 151 | import static org.onosproject.yangutils.utils.UtilConstants.BASE64; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 152 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 153 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 154 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 155 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 156 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 157 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 158 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 159 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 160 | import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 161 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 162 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 163 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; |
| 164 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 165 | import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 166 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 167 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 168 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 169 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 170 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 171 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 172 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 173 | import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 174 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 175 | import static org.onosproject.yangutils.utils.UtilConstants.RETURN; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 176 | import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 177 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 178 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 179 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 180 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 181 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 182 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 183 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 184 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 185 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 186 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Gaurav Agrawal | 8a14752 | 2016-08-10 13:43:01 +0530 | [diff] [blame] | 187 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.replaceLast; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 188 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 189 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; |
| 190 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 191 | import static java.util.Collections.sort; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 192 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 193 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 194 | * Representation of java file generator. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 195 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 196 | public final class JavaFileGenerator { |
| 197 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 198 | private JavaFileGenerator() { |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Returns generated interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 203 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 204 | * @param file file |
| 205 | * @param imports imports for the file |
| 206 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 207 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 208 | * @return interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 209 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 210 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 211 | public static File generateInterfaceFile(File file, List<String> imports, |
| 212 | YangNode curNode, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 213 | boolean isAttrPresent) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 214 | throws IOException { |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 215 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 216 | JavaFileInfoTranslator javaFileInfo = |
| 217 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 218 | |
| 219 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 220 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 221 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 222 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 223 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 224 | path = javaFileInfo.getBaseCodeGenPath() + |
| 225 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 226 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 227 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 228 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 229 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 230 | boolean isLeavesPresent; |
| 231 | YangLeavesHolder leavesHolder; |
| 232 | if (curNode instanceof YangLeavesHolder) { |
| 233 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 234 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 235 | !leavesHolder.getListOfLeaf().isEmpty() |
| 236 | || leavesHolder.getListOfLeafList() != null && |
| 237 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 238 | } else { |
| 239 | isLeavesPresent = false; |
| 240 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 241 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 242 | initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, |
| 243 | className); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 244 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 245 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 246 | // Add getter methods to interface file. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 247 | try { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 248 | //Leaf identifier enum. |
| 249 | if (isLeavesPresent) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 250 | insertDataIntoJavaFile(file, NEW_LINE + |
| 251 | getInterfaceLeafIdEnumSignature(className) + |
| 252 | NEW_LINE + |
| 253 | trimAtLast(replaceLast(getDataFromTempFileHandle( |
| 254 | LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK, |
| 255 | ((TempJavaCodeFragmentFilesContainer) |
| 256 | curNode) |
| 257 | .getTempJavaCodeFragmentFiles() |
| 258 | .getBeanTempFiles(), path), |
| 259 | COMMA, SEMI_COLAN), |
| 260 | NEW_LINE) + |
| 261 | NEW_LINE + NEW_LINE + |
| 262 | getInterfaceLeafIdEnumMethods()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 263 | } |
| 264 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 265 | //Getter methods. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 266 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 267 | GETTER_FOR_INTERFACE_MASK, |
| 268 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 269 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 270 | .getBeanTempFiles(), path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 271 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 272 | throw new IOException( |
| 273 | "No data found in temporary java code fragment files " + |
| 274 | "for " + |
| 275 | className |
| 276 | + " while interface file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 277 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 278 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 279 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 280 | if (curNode instanceof YangAugmentableNode && |
| 281 | !(curNode instanceof YangChoice)) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 282 | methods.add(getYangAugmentInfoInterface()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 283 | methods.add(getYangAugmentInfoMapInterface( |
| 284 | javaFileInfo.getPluginConfig())); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 285 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 286 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 287 | if (curNode instanceof YangCase) { |
| 288 | YangNode caseParent = curNode.getParent(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 289 | JavaQualifiedTypeInfo qualifiedTypeInfo = |
| 290 | getQualifierInfoForCasesParent(caseParent, |
| 291 | javaFileInfo |
| 292 | .getPluginConfig()); |
| 293 | methods.add(NEW_LINE + processSubtreeFilteringInterface |
| 294 | (qualifiedTypeInfo.getClassInfo())); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 295 | } else { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 296 | methods.add(NEW_LINE + processSubtreeFilteringInterface(className)); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 297 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 298 | |
| 299 | if (isLeavesPresent) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 300 | methods.add(NEW_LINE + isLeafValueSetInterface()); |
| 301 | methods.add(NEW_LINE + isSelectLeafSetInterface()); |
| 302 | } |
| 303 | for (String method : methods) { |
| 304 | insertDataIntoJavaFile(file, method); |
| 305 | } |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 306 | return file; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 307 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 311 | * Returns generated builder interface file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 312 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 313 | * @param file file |
| 314 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 315 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 316 | * @return builder interface file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 317 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 318 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 319 | public static File generateBuilderInterfaceFile(File file, YangNode curNode, |
| 320 | boolean isAttrPresent) |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 321 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 322 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 323 | JavaFileInfoTranslator javaFileInfo = |
| 324 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 325 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 326 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 327 | boolean isLeavesPresent; |
| 328 | YangLeavesHolder leavesHolder; |
| 329 | if (curNode instanceof YangLeavesHolder) { |
| 330 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 331 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 332 | !leavesHolder.getListOfLeaf().isEmpty() |
| 333 | || leavesHolder.getListOfLeafList() != null && |
| 334 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 335 | } else { |
| 336 | isLeavesPresent = false; |
| 337 | } |
| 338 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 339 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 340 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 341 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 342 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 343 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 344 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 345 | path = javaFileInfo.getBaseCodeGenPath() + |
| 346 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 347 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 348 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 349 | initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, |
| 350 | className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 351 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 352 | if (isAttrPresent) { |
| 353 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 354 | |
| 355 | //Getter methods. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 356 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle( |
| 357 | GETTER_FOR_INTERFACE_MASK, |
| 358 | ((TempJavaCodeFragmentFilesContainer) |
| 359 | curNode) |
| 360 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 361 | .getBeanTempFiles(), path)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 362 | |
| 363 | //Setter methods. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 364 | methods.add(NEW_LINE); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 365 | methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle( |
| 366 | SETTER_FOR_INTERFACE_MASK, |
| 367 | ((TempJavaCodeFragmentFilesContainer) |
| 368 | curNode) |
| 369 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 370 | .getBeanTempFiles(), path)); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 371 | |
| 372 | //Add to list method. |
| 373 | methods.add(NEW_LINE); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 374 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 375 | ADD_TO_LIST_INTERFACE_MASK, |
| 376 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 377 | .getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 378 | .getBeanTempFiles(), path)); |
| 379 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 380 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 381 | throw new IOException( |
| 382 | "No data found in temporary java code fragment files " + |
| 383 | "for " + |
| 384 | className |
| 385 | + " while builder interface file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 386 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 387 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 388 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 389 | if (curNode instanceof YangAugmentableNode && |
| 390 | !(curNode instanceof YangChoice)) { |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 391 | methods.add(getAddAugmentInfoMethodInterface()); |
| 392 | methods.add(getYangAugmentInfoInterface()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 393 | methods.add(getYangAugmentInfoMapInterface( |
| 394 | javaFileInfo.getPluginConfig())); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 395 | } |
| 396 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 397 | if (isLeavesPresent) { |
| 398 | methods.add(NEW_LINE + setSelectLeafSetInterface(className)); |
| 399 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 400 | //Add build method to builder interface file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 401 | methods.add( |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 402 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 403 | .getTempJavaCodeFragmentFiles() |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 404 | .addBuildMethodForInterface(pluginConfig)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 405 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 406 | |
| 407 | //Add getters and setters in builder interface. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 408 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 409 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 410 | } |
| 411 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 412 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 413 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Returns generated builder class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 418 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 419 | * @param file file |
| 420 | * @param curNode current YANG node |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 421 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 422 | * @return builder class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 423 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 424 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 425 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 426 | public static File generateBuilderClassFile(File file, YangNode curNode, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 427 | boolean isAttrPresent) |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 428 | throws IOException { |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 429 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 430 | JavaFileInfoTranslator javaFileInfo = |
| 431 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 432 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 433 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 434 | boolean isLeavesPresent; |
| 435 | YangLeavesHolder leavesHolder; |
| 436 | if (curNode instanceof YangLeavesHolder) { |
| 437 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 438 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 439 | !leavesHolder.getListOfLeaf().isEmpty() |
| 440 | || leavesHolder.getListOfLeafList() != null && |
| 441 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 442 | } else { |
| 443 | isLeavesPresent = false; |
| 444 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 445 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 446 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
| 447 | boolean isRootNode = false; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 448 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 449 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 450 | isRootNode = true; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 451 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 452 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 453 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 454 | path = javaFileInfo.getBaseCodeGenPath() + |
| 455 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 456 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 457 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 458 | initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, |
| 459 | className); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 460 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 461 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 462 | if (curNode instanceof YangAugmentableNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 463 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 464 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 465 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 466 | |
| 467 | //Add attribute strings. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 468 | try { |
| 469 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 470 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 471 | getDataFromTempFileHandle( |
| 472 | ATTRIBUTES_MASK, |
| 473 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 474 | .getTempJavaCodeFragmentFiles() |
| 475 | .getBeanTempFiles(), |
| 476 | path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 477 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 478 | throw new IOException( |
| 479 | "No data found in temporary java code fragment files " + |
| 480 | "for " + className + |
| 481 | " while builder class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 482 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 483 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 484 | insertDataIntoJavaFile(file, getOperationTypeAttr()); |
| 485 | if (isLeavesPresent) { |
| 486 | insertDataIntoJavaFile(file, getOperationAttributes()); |
| 487 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 488 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 489 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 490 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 491 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 492 | .getTempJavaCodeFragmentFiles() |
| 493 | .getBeanTempFiles(), |
| 494 | path)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 495 | // Setter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 496 | methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 497 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 498 | .getTempJavaCodeFragmentFiles() |
| 499 | .getBeanTempFiles(), |
| 500 | path)); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 501 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 502 | //Add to list impl method. |
| 503 | methods.add(getDataFromTempFileHandle(ADD_TO_LIST_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 504 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 505 | .getTempJavaCodeFragmentFiles() |
| 506 | .getBeanTempFiles(), |
| 507 | path)); |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 508 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 509 | insertDataIntoJavaFile(file, NEW_LINE); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 510 | |
| 511 | methods.add(getGetterForOperationType()); |
| 512 | methods.add(getSetterForOperationType(className)); |
| 513 | //Add operation attribute methods. |
| 514 | if (isLeavesPresent) { |
| 515 | methods.add(getOperationAttributesGetters() + NEW_LINE); |
| 516 | methods.add(getSetterForSelectLeaf(className, isRootNode)); |
| 517 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 518 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 519 | throw new IOException( |
| 520 | "No data found in temporary java code fragment files " + |
| 521 | "for " + className + |
| 522 | " while builder class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 523 | } |
| 524 | } else { |
| 525 | insertDataIntoJavaFile(file, NEW_LINE); |
| 526 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 527 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 528 | if (curNode instanceof YangAugmentableNode) { |
| 529 | methods.add(getAddAugmentInfoMethodImpl()); |
| 530 | methods.add(getYangAugmentInfoImpl()); |
| 531 | methods.add(getYangAugmentInfoMapImpl()); |
| 532 | } |
| 533 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 534 | // Add default constructor and build method impl. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 535 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 536 | .getTempJavaCodeFragmentFiles() |
| 537 | .addBuildMethodImpl(curNode)); |
| 538 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 539 | .getTempJavaCodeFragmentFiles() |
| 540 | .addDefaultConstructor(PUBLIC, BUILDER, |
| 541 | pluginConfig, curNode)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 542 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 543 | |
| 544 | //Add methods in builder class. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 545 | for (String method : methods) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 546 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 547 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 548 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 549 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET); |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 550 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 554 | * Returns generated default class file for current node. |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 555 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 556 | * @param file file |
| 557 | * @param curNode current YANG node |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 558 | * @param isAttrPresent if any attribute is present or not |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 559 | * @param imports list of imports |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 560 | * @return impl class file |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 561 | * @throws IOException when fails to write in file |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 562 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 563 | public static File generateDefaultClassFile(File file, YangNode curNode, |
| 564 | boolean isAttrPresent, |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 565 | List<String> imports) |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 566 | throws IOException { |
| 567 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 568 | JavaFileInfoTranslator javaFileInfo = |
| 569 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 570 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 571 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 572 | boolean isLeavesPresent; |
| 573 | YangLeavesHolder leavesHolder; |
| 574 | if (curNode instanceof YangLeavesHolder) { |
| 575 | leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 576 | isLeavesPresent = leavesHolder.getListOfLeaf() != null && |
| 577 | !leavesHolder.getListOfLeaf().isEmpty() || |
| 578 | leavesHolder.getListOfLeafList() != null && |
| 579 | !leavesHolder.getListOfLeafList().isEmpty(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 580 | } else { |
| 581 | isLeavesPresent = false; |
| 582 | } |
| 583 | |
| 584 | boolean isRootNode = false; |
| 585 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 586 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 587 | String opParamClassName = className; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 588 | String path; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 589 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 590 | opParamClassName = className + OP_PARAM; |
| 591 | isRootNode = true; |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 592 | path = javaFileInfo.getPluginConfig().getCodeGenDir() + |
| 593 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 594 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 595 | path = javaFileInfo.getBaseCodeGenPath() + |
| 596 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 597 | } |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 598 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 599 | initiateJavaFileGeneration(file, DEFAULT_CLASS_MASK, imports, curNode, |
| 600 | className); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 601 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 602 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 603 | if (curNode instanceof YangAugmentableNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 604 | insertDataIntoJavaFile(file, addAugmentationAttribute()); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 605 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 606 | if (isAttrPresent) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 607 | |
| 608 | //Add attribute strings. |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 609 | try { |
| 610 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 611 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 612 | getDataFromTempFileHandle( |
| 613 | ATTRIBUTES_MASK, |
| 614 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 615 | .getTempJavaCodeFragmentFiles() |
| 616 | .getBeanTempFiles(), |
| 617 | path)); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 618 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 619 | throw new IOException( |
| 620 | "No data found in temporary java code fragment files " + |
| 621 | "for " + className + |
| 622 | " while impl class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 623 | } |
Bharat saraswal | 5600f0f | 2016-03-09 18:34:56 +0530 | [diff] [blame] | 624 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 625 | //Add operation attributes |
| 626 | insertDataIntoJavaFile(file, getOperationTypeEnum()); |
| 627 | insertDataIntoJavaFile(file, getOperationTypeAttr()); |
| 628 | if (isLeavesPresent) { |
| 629 | insertDataIntoJavaFile(file, getOperationAttributes()); |
| 630 | } |
| 631 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 632 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 633 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 634 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 635 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 636 | .getTempJavaCodeFragmentFiles() |
| 637 | .getBeanTempFiles(), |
| 638 | path)); |
| 639 | |
| 640 | methods.add(getGetterForOperationType()); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 641 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 642 | // Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 643 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 644 | getDataFromTempFileHandle( |
| 645 | HASH_CODE_IMPL_MASK, |
| 646 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 647 | .getTempJavaCodeFragmentFiles() |
| 648 | .getBeanTempFiles(), |
| 649 | path) |
| 650 | .replace( |
| 651 | NEW_LINE, |
| 652 | EMPTY_STRING))); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 653 | |
| 654 | //Equals method. |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 655 | if (isRootNode) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 656 | methods.add(getEqualsMethodClose( |
| 657 | getEqualsMethodOpen(opParamClassName) + |
| 658 | getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 659 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 660 | .getTempJavaCodeFragmentFiles() |
| 661 | .getBeanTempFiles(), |
| 662 | path))); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 663 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 664 | methods.add(getEqualsMethodClose(getEqualsMethodOpen( |
| 665 | getCapitalCase(DEFAULT) + className) + |
| 666 | getDataFromTempFileHandle( |
| 667 | EQUALS_IMPL_MASK, |
| 668 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 669 | .getTempJavaCodeFragmentFiles() |
| 670 | .getBeanTempFiles(), |
| 671 | path))); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 672 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 673 | // To string method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 674 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle( |
| 675 | TO_STRING_IMPL_MASK, |
| 676 | ((TempJavaCodeFragmentFilesContainer) |
| 677 | curNode) |
| 678 | .getTempJavaCodeFragmentFiles() |
| 679 | .getBeanTempFiles(), path) + |
| 680 | getToStringMethodClose()); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 681 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 682 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 683 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 684 | throw new IOException( |
| 685 | "No data found in temporary java code fragment files " + |
| 686 | "for " + className + |
| 687 | " while impl class file generation"); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 688 | } |
| 689 | } else { |
| 690 | insertDataIntoJavaFile(file, NEW_LINE); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 691 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 692 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 693 | if (curNode instanceof YangAugmentableNode) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 694 | methods.add(getYangAugmentInfoImpl()); |
| 695 | methods.add(getYangAugmentInfoMapImpl()); |
| 696 | } |
| 697 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 698 | //Constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 699 | String constructor = |
| 700 | getConstructorStart(className, pluginConfig, isRootNode); |
| 701 | constructor = constructor + |
| 702 | getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, |
| 703 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 704 | .getTempJavaCodeFragmentFiles() |
| 705 | .getBeanTempFiles(), |
| 706 | path); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 707 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 708 | if (isAttrPresent) { |
| 709 | constructor = constructor + getOperationTypeForConstructor(); |
| 710 | } |
| 711 | if (isLeavesPresent) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 712 | constructor = |
| 713 | constructor + getOperationAttributeForConstructor(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 714 | } |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 715 | if (curNode instanceof YangAugmentableNode) { |
| 716 | constructor = constructor + getYangAugmentedMapObjectForConstruct(); |
| 717 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 718 | methods.add( |
| 719 | constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + |
| 720 | NEW_LINE); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 721 | |
| 722 | // add is filter content match. |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 723 | String augmentableSubTreeFiltering = ""; |
| 724 | if (curNode instanceof YangAugmentableNode) { |
| 725 | augmentableSubTreeFiltering = getAugmentableSubTreeFiltering(); |
| 726 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 727 | |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 728 | methods.add(getProcessSubtreeFilteringStart(curNode, pluginConfig) |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 729 | + getProcessSubtreeFunctionBody(curNode) |
| 730 | + augmentableSubTreeFiltering |
| 731 | + getProcessSubTreeFilteringEnd()); |
| 732 | |
| 733 | if (curNode instanceof YangLeavesHolder) { |
| 734 | if (((YangLeavesHolder) curNode).getListOfLeaf() != null |
| 735 | && !((YangLeavesHolder) curNode).getListOfLeaf() |
| 736 | .isEmpty()) { |
| 737 | methods.add(getProcessLeafSubtreeFiltering(curNode, |
| 738 | pluginConfig, |
| 739 | path)); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | if (curNode instanceof YangLeavesHolder) { |
| 745 | if (((YangLeavesHolder) curNode).getListOfLeafList() != null |
| 746 | && !((YangLeavesHolder) curNode).getListOfLeafList() |
| 747 | .isEmpty()) { |
| 748 | methods.add(getProcessLeafListSubtreeFiltering(curNode, |
| 749 | pluginConfig, |
| 750 | path)); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | if (curNode.getChild() != null) { |
| 755 | methods.add(getProcessChildNodeSubtreeFiltering(curNode, |
| 756 | pluginConfig, |
| 757 | path)); |
| 758 | } |
| 759 | |
| 760 | |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 761 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 762 | throw new IOException( |
| 763 | "No data found in temporary java code fragment files for " + |
| 764 | className + " while impl class file generation"); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 765 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 766 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 767 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 768 | .getTempJavaCodeFragmentFiles() |
| 769 | .addDefaultConstructor(PROTECTED, DEFAULT, |
| 770 | pluginConfig, curNode)); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 771 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 772 | methods.add(builderMethod(className) + NEW_LINE); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 773 | if (isLeavesPresent) { |
| 774 | methods.add(getOperationAttributesGetters()); |
| 775 | methods.add(getGettersForValueAndSelectLeaf()); |
| 776 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 777 | // Add methods in impl class. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 778 | for (String method : methods) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 779 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 780 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 781 | |
Bharat saraswal | e304c25 | 2016-08-16 20:56:20 +0530 | [diff] [blame] | 782 | return file; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 786 | * Generates class file for type def. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 787 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 788 | * @param file generated file |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 789 | * @param curNode current YANG node |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 790 | * @param imports imports for file |
| 791 | * @return type def class file |
| 792 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 793 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 794 | public static File generateTypeDefClassFile(File file, YangNode curNode, |
| 795 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 796 | throws IOException { |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 797 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 798 | JavaFileInfoTranslator javaFileInfo = |
| 799 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 800 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 801 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 802 | // import |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 803 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 804 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 805 | javaFileInfo.getPackageFilePath(); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 806 | YangTypeDef typeDef = (YangTypeDef) curNode; |
| 807 | List<YangType<?>> types = typeDef.getTypeList(); |
| 808 | YangType type = types.get(0); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 809 | YangDataTypes yangDataTypes = type.getDataType(); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 810 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 811 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, |
| 812 | imports, path, pluginConfig); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 813 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 814 | List<String> methods = new ArrayList<>(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 815 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 816 | |
| 817 | //Add attribute strings. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 818 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 819 | insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION + |
| 820 | getDataFromTempFileHandle(ATTRIBUTES_MASK, |
| 821 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 822 | .getTempJavaCodeFragmentFiles() |
| 823 | .getTypeTempFiles(), |
| 824 | path)); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 825 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 826 | throw new IOException( |
| 827 | "No data found in temporary java code fragment files for " + |
| 828 | className + " while type def class file " + |
| 829 | "generation"); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 830 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 831 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 832 | |
| 833 | //Default constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 834 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 835 | .getTempJavaCodeFragmentFiles() |
| 836 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, |
| 837 | pluginConfig, curNode)); |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 838 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 839 | try { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 840 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 841 | //Type constructor. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 842 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 843 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 844 | .getTempJavaCodeFragmentFiles() |
| 845 | .getTypeTempFiles(), |
| 846 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 847 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 848 | |
| 849 | //Of method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 850 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 851 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 852 | .getTempJavaCodeFragmentFiles() |
| 853 | .getTypeTempFiles(), |
| 854 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 855 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 856 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 857 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 858 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 859 | .getTempJavaCodeFragmentFiles() |
| 860 | .getTypeTempFiles(), |
| 861 | path)); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 862 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 863 | // Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 864 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 865 | getDataFromTempFileHandle( |
| 866 | HASH_CODE_IMPL_MASK, |
| 867 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 868 | .getTempJavaCodeFragmentFiles() |
| 869 | .getTypeTempFiles(), |
| 870 | path) |
| 871 | .replace( |
| 872 | NEW_LINE, |
| 873 | EMPTY_STRING))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 874 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 875 | |
| 876 | //Equals method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 877 | methods.add(getEqualsMethodClose( |
| 878 | getEqualsMethodOpen(className + EMPTY_STRING) |
| 879 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 880 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 881 | .getTempJavaCodeFragmentFiles() |
| 882 | .getTypeTempFiles(), |
| 883 | path))); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 884 | |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 885 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 886 | //To string method. |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 887 | if (type.getDataType().equals(BINARY)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 888 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = |
| 889 | getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase( |
| 890 | "binary")); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 891 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 892 | JavaAttributeInfo attr = |
| 893 | getAttributeInfoForTheData(qualifiedTypeInfo, "binary", |
| 894 | null, false, false); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 895 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 896 | String bitsToStringMethod = |
| 897 | getOverRideString() + FOUR_SPACE_INDENTATION + |
| 898 | PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO + |
| 899 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 900 | CLOSE_PARENTHESIS + SPACE + |
| 901 | OPEN_CURLY_BRACKET + NEW_LINE + |
| 902 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + |
| 903 | BASE64 + PERIOD + GET_ENCODER + |
| 904 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + |
| 905 | PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + |
| 906 | attributeName + CLOSE_PARENTHESIS + |
| 907 | SEMI_COLAN + NEW_LINE + |
| 908 | FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + |
| 909 | NEW_LINE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 910 | methods.add(bitsToStringMethod); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 911 | } else if (type.getDataType().equals(BITS)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 912 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = |
| 913 | getQualifiedTypeInfoOfCurNode(curNode, |
| 914 | getCapitalCase( |
| 915 | "bits")); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 916 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 917 | JavaAttributeInfo attr = |
| 918 | getAttributeInfoForTheData(qualifiedTypeInfo, "bits", |
| 919 | null, false, false); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 920 | String attributeName = attr.getAttributeName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 921 | String bitsToStringMethod = |
| 922 | getOverRideString() + FOUR_SPACE_INDENTATION + |
| 923 | PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO + |
| 924 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 925 | CLOSE_PARENTHESIS + SPACE + |
| 926 | OPEN_CURLY_BRACKET + NEW_LINE + |
| 927 | EIGHT_SPACE_INDENTATION + RETURN + SPACE + |
| 928 | attributeName + PERIOD + TO + |
| 929 | STRING_DATA_TYPE + OPEN_PARENTHESIS + |
| 930 | CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + |
| 931 | FOUR_SPACE_INDENTATION + |
| 932 | CLOSE_CURLY_BRACKET + NEW_LINE; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 933 | methods.add(bitsToStringMethod); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 934 | } else { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 935 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle( |
| 936 | TO_STRING_IMPL_MASK, |
| 937 | ((TempJavaCodeFragmentFilesContainer) |
| 938 | curNode) |
| 939 | .getTempJavaCodeFragmentFiles() |
| 940 | .getTypeTempFiles(), path) + |
| 941 | getToStringMethodClose()); |
Mahesh Poojary Huawei | 41547ad | 2016-07-14 17:49:50 +0530 | [diff] [blame] | 942 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 943 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 944 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
| 945 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 946 | //From string method. |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 947 | if ((type.getDataType().equals(YangDataTypes.DERIVED)) |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 948 | && (((YangDerivedInfo) type.getDataTypeExtendedInfo()) |
| 949 | .getEffectiveBuiltInType() |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 950 | .equals(YangDataTypes.IDENTITYREF))) { |
| 951 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 952 | } |
| 953 | |
| 954 | if (type.getDataType().equals(YangDataTypes.IDENTITYREF)) { |
| 955 | yangDataTypes = YangDataTypes.IDENTITYREF; |
| 956 | } |
| 957 | |
| 958 | if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 959 | methods.add( |
| 960 | getFromStringMethodSignature(className, pluginConfig) + |
| 961 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 962 | javaGenInfo |
| 963 | .getTempJavaCodeFragmentFiles() |
| 964 | .getTypeTempFiles(), |
| 965 | path) + |
| 966 | getFromStringMethodClose()); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 967 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 968 | |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 969 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 970 | throw new IOException( |
| 971 | "No data found in temporary java code fragment files for " + |
| 972 | className + " while type def class file " + |
| 973 | "generation"); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 974 | } |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 975 | |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 976 | for (String method : methods) { |
| 977 | insertDataIntoJavaFile(file, method); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 978 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 979 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 980 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 981 | return validateLineLength(file); |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 982 | } |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 983 | |
| 984 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 985 | * Generates class file for union type. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 986 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 987 | * @param file generated file |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 988 | * @param curNode current YANG node |
| 989 | * @param imports imports for file |
| 990 | * @return type def class file |
| 991 | * @throws IOException when fails to generate class file |
| 992 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 993 | public static File generateUnionClassFile(File file, YangNode curNode, |
| 994 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 995 | throws IOException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 996 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 997 | JavaFileInfoTranslator javaFileInfo = |
| 998 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 999 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1000 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1001 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1002 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1003 | javaFileInfo.getPackageFilePath(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1004 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1005 | TempJavaTypeFragmentFiles tempJavaTypeFragmentFiles = |
| 1006 | ((JavaCodeGeneratorInfo) curNode) |
| 1007 | .getTempJavaCodeFragmentFiles().getTypeTempFiles(); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1008 | |
| 1009 | boolean isIntConflict = false; |
| 1010 | boolean isLongConflict = false; |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1011 | boolean isShortConflict = false; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1012 | JavaAttributeInfo intAttr = tempJavaTypeFragmentFiles.getIntAttribute(); |
| 1013 | if (intAttr == null) { |
| 1014 | intAttr = tempJavaTypeFragmentFiles.getUIntAttribute(); |
| 1015 | } |
| 1016 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1017 | JavaAttributeInfo longAttr = |
| 1018 | tempJavaTypeFragmentFiles.getLongAttribute(); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1019 | if (longAttr == null) { |
| 1020 | longAttr = tempJavaTypeFragmentFiles.getULongAttribute(); |
| 1021 | } |
| 1022 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1023 | JavaAttributeInfo shortAttr = |
| 1024 | tempJavaTypeFragmentFiles.getShortAttribute(); |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1025 | if (shortAttr == null) { |
| 1026 | shortAttr = tempJavaTypeFragmentFiles.getUInt8Attribute(); |
| 1027 | } |
| 1028 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1029 | if (intAttr != null) { |
| 1030 | isIntConflict = intAttr.isIntConflict(); |
| 1031 | } |
| 1032 | if (longAttr != null) { |
| 1033 | isLongConflict = longAttr.isLongConflict(); |
| 1034 | } |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1035 | if (shortAttr != null) { |
| 1036 | isShortConflict = shortAttr.isShortConflict(); |
| 1037 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1038 | if (isLongConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1039 | imports.add(tempJavaTypeFragmentFiles.getJavaImportData() |
| 1040 | .getBigIntegerImport()); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1041 | sort(imports); |
| 1042 | } |
| 1043 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1044 | initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, |
| 1045 | imports, path, pluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1046 | |
| 1047 | List<String> methods = new ArrayList<>(); |
| 1048 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1049 | |
| 1050 | // Add attribute strings. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1051 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1052 | if (isIntConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1053 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1054 | .addStaticAttributeIntRange(PRIVATE, |
| 1055 | tempJavaTypeFragmentFiles |
| 1056 | .getIntIndex() < |
| 1057 | tempJavaTypeFragmentFiles |
| 1058 | .getUIntIndex())); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | if (isLongConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1062 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1063 | .addStaticAttributeLongRange(PRIVATE, |
| 1064 | tempJavaTypeFragmentFiles |
| 1065 | .getLongIndex() < |
| 1066 | tempJavaTypeFragmentFiles |
| 1067 | .getULongIndex())); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1068 | } |
| 1069 | |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1070 | if (isShortConflict) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1071 | insertDataIntoJavaFile(file, JavaCodeSnippetGen |
| 1072 | .addStaticAttributeShortRange(PRIVATE, |
| 1073 | tempJavaTypeFragmentFiles |
| 1074 | .getShortIndex() < |
| 1075 | tempJavaTypeFragmentFiles |
| 1076 | .getUInt8Index())); |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1077 | } |
| 1078 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1079 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1080 | NEW_LINE + FOUR_SPACE_INDENTATION + |
| 1081 | getDataFromTempFileHandle( |
| 1082 | ATTRIBUTES_MASK, |
| 1083 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1084 | .getTempJavaCodeFragmentFiles() |
| 1085 | .getTypeTempFiles(), |
| 1086 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1087 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1088 | throw new IOException( |
| 1089 | "No data found in temporary java code fragment files for " + |
| 1090 | className + " while union class file generation"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1091 | } |
| 1092 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1093 | |
| 1094 | //Default constructor. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1095 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode) |
| 1096 | .getTempJavaCodeFragmentFiles() |
| 1097 | .addDefaultConstructor(PRIVATE, EMPTY_STRING, |
| 1098 | pluginConfig, curNode)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1099 | |
| 1100 | try { |
| 1101 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1102 | |
| 1103 | //Type constructor. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1104 | methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1105 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1106 | .getTempJavaCodeFragmentFiles() |
| 1107 | .getTypeTempFiles(), |
| 1108 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1109 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1110 | |
| 1111 | // Of string method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1112 | methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1113 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1114 | .getTempJavaCodeFragmentFiles() |
| 1115 | .getTypeTempFiles(), |
| 1116 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1117 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1118 | //Getter methods. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1119 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1120 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1121 | .getTempJavaCodeFragmentFiles() |
| 1122 | .getTypeTempFiles(), |
| 1123 | path)); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1124 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1125 | |
| 1126 | //Hash code method. |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1127 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1128 | getDataFromTempFileHandle( |
| 1129 | HASH_CODE_IMPL_MASK, |
| 1130 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1131 | .getTempJavaCodeFragmentFiles() |
| 1132 | .getTypeTempFiles(), |
| 1133 | path).replace( |
| 1134 | NEW_LINE, |
| 1135 | EMPTY_STRING))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1136 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1137 | //Equals method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1138 | methods.add(getEqualsMethodClose( |
| 1139 | getEqualsMethodOpen(className + EMPTY_STRING) |
| 1140 | + getDataFromTempFileHandle(EQUALS_IMPL_MASK, |
| 1141 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1142 | .getTempJavaCodeFragmentFiles() |
| 1143 | .getTypeTempFiles(), |
| 1144 | path))); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1145 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1146 | |
| 1147 | //To string method. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1148 | methods.add(getToStringMethodOpen() + getOmitNullValueString() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1149 | getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
| 1150 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1151 | .getTempJavaCodeFragmentFiles() |
| 1152 | .getTypeTempFiles(), |
| 1153 | path) + |
| 1154 | getToStringMethodClose()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1155 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1156 | |
| 1157 | //From string method. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1158 | methods.add(getFromStringMethodSignature(className, pluginConfig) + |
| 1159 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 1160 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1161 | .getTempJavaCodeFragmentFiles() |
| 1162 | .getTypeTempFiles(), |
| 1163 | path) + |
| 1164 | getFromStringMethodClose()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1165 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1166 | if (isIntConflict) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1167 | methods.add(getRangeValidatorMethodForUnion(INT)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1168 | } |
| 1169 | if (isLongConflict) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1170 | methods.add(getRangeValidatorMethodForUnion(BIG_INTEGER)); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1171 | } |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1172 | if (isShortConflict && !isIntConflict) { |
Bharat saraswal | 2da23bf | 2016-08-25 15:28:39 +0530 | [diff] [blame] | 1173 | methods.add(getRangeValidatorMethodForUnion(INT)); |
| 1174 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1175 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1176 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1177 | throw new IOException( |
| 1178 | "No data found in temporary java code fragment files for " + |
| 1179 | className + " while union class file generation"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | for (String method : methods) { |
| 1183 | insertDataIntoJavaFile(file, method); |
| 1184 | } |
| 1185 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1186 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1187 | return validateLineLength(file); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1188 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1189 | |
| 1190 | /** |
| 1191 | * Generates class file for type enum. |
| 1192 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1193 | * @param file generated file |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1194 | * @param curNode current YANG node |
| 1195 | * @return class file for type enum |
| 1196 | * @throws IOException when fails to generate class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1197 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1198 | public static File generateEnumClassFile(File file, YangNode curNode) |
| 1199 | throws IOException { |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1200 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1201 | JavaFileInfoTranslator javaFileInfo = |
| 1202 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1203 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1204 | |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1205 | String className = javaFileInfo.getJavaName(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1206 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1207 | javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1208 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1209 | initiateJavaFileGeneration(file, getCapitalCase(className), |
| 1210 | GENERATE_ENUM_CLASS, null, path, |
| 1211 | pluginConfig); |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1212 | |
| 1213 | //Add attribute strings. |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1214 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1215 | JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1216 | insertDataIntoJavaFile(file, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1217 | trimAtLast(trimAtLast( |
| 1218 | getDataFromTempFileHandle( |
| 1219 | ENUM_IMPL_MASK, javaGenInfo |
| 1220 | .getTempJavaCodeFragmentFiles() |
| 1221 | .getEnumerationTempFiles(), |
| 1222 | path), COMMA), |
| 1223 | NEW_LINE) + SEMI_COLAN + |
| 1224 | NEW_LINE); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1225 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1226 | throw new IOException( |
| 1227 | "No data found in temporary java code fragment files for " + |
| 1228 | getCapitalCase(className) + " while enum class " + |
| 1229 | "file generation"); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1230 | } |
| 1231 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1232 | |
| 1233 | // Add an attribute to get the enum's values. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1234 | insertDataIntoJavaFile(file, getEnumsValueAttribute( |
| 1235 | getCapitalCase(className))); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1236 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1237 | // Add a constructor for enum. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1238 | insertDataIntoJavaFile(file, |
| 1239 | getJavaDoc(TYPE_CONSTRUCTOR, className, false, |
| 1240 | pluginConfig, null) |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 1241 | + getEnumsConstructor(getCapitalCase(className)) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1242 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1243 | insertDataIntoJavaFile(file, |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 1244 | getEnumsOfValueMethod(className, (YangEnumeration) curNode, pluginConfig) + NEW_LINE); |
| 1245 | insertDataIntoJavaFile(file, |
| 1246 | getEnumValueOfSchemaNameMethod(className, pluginConfig, (YangEnumeration) curNode)); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1247 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1248 | // Add a getter method for enum. |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1249 | insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, |
| 1250 | pluginConfig, null) + |
| 1251 | getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE); |
Bharat saraswal | 748fc3c | 2016-09-06 16:38:20 +0530 | [diff] [blame^] | 1252 | insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false, |
| 1253 | pluginConfig, null) + |
| 1254 | getGetter(STRING_DATA_TYPE, SCHEMA_NAME, |
| 1255 | GENERATE_ENUM_CLASS) + NEW_LINE); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1256 | |
| 1257 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1258 | insertDataIntoJavaFile(file, getFromStringMethodSignature( |
| 1259 | getCapitalCase(className), pluginConfig) + |
| 1260 | getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, |
| 1261 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1262 | .getTempJavaCodeFragmentFiles() |
| 1263 | .getEnumerationTempFiles(), |
| 1264 | path) + |
| 1265 | getFromStringMethodClose()); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1266 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1267 | throw new IOException( |
| 1268 | "No data found in temporary java code fragment files for " + |
| 1269 | getCapitalCase(className) + |
| 1270 | " while enum class file generation"); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1271 | } |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1272 | |
| 1273 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1274 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1275 | return validateLineLength(file); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1276 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1277 | |
| 1278 | /** |
| 1279 | * Generates interface file for rpc. |
| 1280 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1281 | * @param file generated file |
| 1282 | * @param curNode current YANG node |
| 1283 | * @param imports imports for file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1284 | * @return rpc class file |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1285 | * @throws IOException when fails to generate class file |
| 1286 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1287 | public static File generateServiceInterfaceFile(File file, YangNode curNode, |
| 1288 | List<String> imports) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1289 | throws IOException { |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1290 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1291 | JavaFileInfoTranslator javaFileInfo = |
| 1292 | ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1293 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1294 | TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = |
| 1295 | ((JavaCodeGeneratorInfo) curNode) |
| 1296 | .getTempJavaCodeFragmentFiles().getServiceTempFiles(); |
| 1297 | String className = getCapitalCase(javaFileInfo.getJavaName()) + |
| 1298 | SERVICE_METHOD_STRING; |
| 1299 | String path = javaFileInfo.getBaseCodeGenPath() + |
| 1300 | javaFileInfo.getPackageFilePath(); |
| 1301 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, |
| 1302 | curNode, className); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1303 | |
| 1304 | List<String> methods = new ArrayList<>(); |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1305 | JavaAttributeInfo rootAttribute = |
| 1306 | getCurNodeAsAttributeInTarget(curNode, curNode, false, |
| 1307 | tempJavaServiceFragmentFiles); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1308 | |
| 1309 | try { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1310 | |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 1311 | if (isGetSetOfRootNodeRequired(curNode)) { |
| 1312 | //Getter methods. |
| 1313 | methods.add(getGetterString(rootAttribute, |
| 1314 | GENERATE_SERVICE_AND_MANAGER, |
| 1315 | javaFileInfo.getPluginConfig()) + |
| 1316 | NEW_LINE); |
| 1317 | // Setter methods. |
| 1318 | methods.add(getSetterString(rootAttribute, className, |
| 1319 | GENERATE_SERVICE_AND_MANAGER, |
| 1320 | javaFileInfo.getPluginConfig()) + |
| 1321 | NEW_LINE); |
| 1322 | } |
| 1323 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1324 | methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE); |
| 1325 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1326 | if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles() |
| 1327 | .getServiceTempFiles() != null) { |
| 1328 | JavaCodeGeneratorInfo javaGenInfo = |
| 1329 | (JavaCodeGeneratorInfo) curNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1330 | |
| 1331 | // Rpc methods |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1332 | methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1333 | javaGenInfo |
| 1334 | .getTempJavaCodeFragmentFiles() |
| 1335 | .getServiceTempFiles(), |
| 1336 | path)); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1337 | } |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1338 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1339 | throw new IOException( |
| 1340 | "No data found in temporary java code fragment files for " + |
| 1341 | className + " while rpc class file generation"); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | for (String method : methods) { |
| 1345 | insertDataIntoJavaFile(file, method); |
| 1346 | } |
| 1347 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1348 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1349 | return validateLineLength(file); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1350 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1351 | |
| 1352 | /** |
| 1353 | * Generates event file. |
| 1354 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1355 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1356 | * @param curNode current YANG node |
| 1357 | * @param imports imports for file |
| 1358 | * @throws IOException when fails to generate class file |
| 1359 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1360 | public static void generateEventFile(File file, YangNode curNode, |
| 1361 | List<String> imports) |
VinodKumarS-Huawei | 9a91b48 | 2016-08-19 23:22:59 +0530 | [diff] [blame] | 1362 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1363 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1364 | String className = getCapitalCase( |
| 1365 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1366 | .getJavaName()) |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1367 | + EVENT_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1368 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1369 | TempJavaEventFragmentFiles tempFiles = |
| 1370 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1371 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1372 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1373 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1374 | .getBaseCodeGenPath() |
| 1375 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1376 | .getPackageFilePath(); |
| 1377 | initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, |
| 1378 | className); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1379 | try { |
| 1380 | insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() + |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1381 | trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, |
| 1382 | tempFiles, path), |
| 1383 | COMMA) + FOUR_SPACE_INDENTATION + |
| 1384 | CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1385 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1386 | insertDataIntoJavaFile(file, |
| 1387 | getDataFromTempFileHandle(EVENT_METHOD_MASK, |
| 1388 | tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1389 | |
| 1390 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1391 | throw new IOException( |
| 1392 | "No data found in temporary java code fragment files for " + |
| 1393 | className + " while event class file generation"); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1397 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * Generates event listener file. |
| 1402 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1403 | * @param file generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1404 | * @param curNode current YANG node |
| 1405 | * @param imports imports for file |
| 1406 | * @throws IOException when fails to generate class file |
| 1407 | */ |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1408 | public static void generateEventListenerFile(File file, YangNode curNode, |
| 1409 | List<String> imports) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1410 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1411 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1412 | String className = getCapitalCase( |
| 1413 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1414 | .getJavaName()) + EVENT_LISTENER_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1415 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1416 | initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, |
| 1417 | imports, curNode, className); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1418 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1419 | validateLineLength(file); |
| 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * Generates event subject's file. |
| 1424 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1425 | * @param file file handle |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1426 | * @param curNode current YANG node |
| 1427 | * @throws IOException when fails to do IO exceptions |
| 1428 | */ |
| 1429 | public static void generateEventSubjectFile(File file, YangNode curNode) |
| 1430 | throws IOException { |
| 1431 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1432 | String className = getCapitalCase( |
| 1433 | ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1434 | .getJavaName()) + EVENT_SUBJECT_NAME_SUFFIX; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1435 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1436 | initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, |
| 1437 | curNode, className); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1438 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1439 | String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1440 | .getBaseCodeGenPath() |
| 1441 | + ((JavaFileInfoContainer) curNode).getJavaFileInfo() |
| 1442 | .getPackageFilePath(); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1443 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1444 | TempJavaEventFragmentFiles tempFiles = |
| 1445 | ((TempJavaCodeFragmentFilesContainer) curNode) |
| 1446 | .getTempJavaCodeFragmentFiles().getEventFragmentFiles(); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1447 | |
| 1448 | insertDataIntoJavaFile(file, NEW_LINE); |
| 1449 | try { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1450 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1451 | EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1452 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1453 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1454 | EVENT_SUBJECT_GETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1455 | |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1456 | insertDataIntoJavaFile(file, getDataFromTempFileHandle( |
| 1457 | EVENT_SUBJECT_SETTER_MASK, tempFiles, path)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1458 | |
| 1459 | } catch (IOException e) { |
VinodKumarS-Huawei | 8f16422 | 2016-08-31 15:47:30 +0530 | [diff] [blame] | 1460 | throw new IOException( |
| 1461 | "No data found in temporary java code fragment files for " + |
| 1462 | className + " while event class file generation"); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 1466 | validateLineLength(file); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1467 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1468 | } |