blob: 756062dc9f56f6ca1c112d64819eae97743174a8 [file] [log] [blame]
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16package org.onosproject.yangutils.translator.tojava;
17
18import java.io.File;
19import java.io.IOException;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053020import java.util.List;
Bharat saraswale304c252016-08-16 20:56:20 +053021
Bharat saraswale50edca2016-08-05 01:58:25 +053022import org.onosproject.yangutils.datamodel.YangAugment;
Bharat saraswalaf413b82016-07-14 15:18:20 +053023import org.onosproject.yangutils.datamodel.YangAugmentableNode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053024import org.onosproject.yangutils.datamodel.YangCase;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053025import org.onosproject.yangutils.datamodel.YangChoice;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053026import org.onosproject.yangutils.datamodel.YangLeaf;
27import org.onosproject.yangutils.datamodel.YangLeafList;
28import org.onosproject.yangutils.datamodel.YangLeavesHolder;
Vidyashree Ramab3670472016-08-06 15:49:56 +053029import org.onosproject.yangutils.datamodel.YangList;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053030import org.onosproject.yangutils.datamodel.YangModule;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053031import org.onosproject.yangutils.datamodel.YangNode;
Bharat saraswalaf413b82016-07-14 15:18:20 +053032import org.onosproject.yangutils.datamodel.YangSubModule;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053033import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053034import org.onosproject.yangutils.translator.exception.TranslatorException;
35import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Shankara-Huaweib7564772016-08-02 18:13:13 +053036import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053037import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053038import org.onosproject.yangutils.utils.io.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053039
Bharat saraswalc2d3be12016-06-16 00:29:12 +053040import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
42import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053043import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Bharat saraswalaf413b82016-07-14 15:18:20 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
47import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053049import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
50import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053052import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053054import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
55import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
56import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
Bharat saraswal250a7472016-05-12 13:16:57 +053057import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053058import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
59import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
60import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053061import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053062import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
63import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
64import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
65import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Shankara-Huaweib7564772016-08-02 18:13:13 +053066import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
67import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053068import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
Bharat saraswal8beac342016-08-04 02:00:03 +053069import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
70import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
Bharat saraswalaf413b82016-07-14 15:18:20 +053072import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
74import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswal8beac342016-08-04 02:00:03 +053075import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053076import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053077import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswald14cbe82016-07-14 13:26:18 +053078import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
Bharat saraswal8beac342016-08-04 02:00:03 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
80import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053081import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
83import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053084import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053085import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
86import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
87import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053088import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
90import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
91import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053092import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +053093import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
94 .getSubtreeFilteringForLeaf;
95import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
96 .getSubtreeFilteringForLeafList;
97import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
98 .getSubtreeFilteringForNode;
Bharat saraswal8beac342016-08-04 02:00:03 +053099import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530100import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530101import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530102import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
103import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530104import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530105import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530106import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530107import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530108import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530109import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
110import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530111import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530112import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530113import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530114import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswal8beac342016-08-04 02:00:03 +0530115import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530116import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswale304c252016-08-16 20:56:20 +0530117import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530118import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530119import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530120import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
121import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
122import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530123import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
124import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530125import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530126
127/**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530128 * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for
129 * Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530130 */
131public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530132
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530133 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530134 * File type extension for java classes.
135 */
136 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530137
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530138 /**
139 * File type extension for temporary classes.
140 */
141 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530142
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530143 /**
144 * Folder suffix for temporary files folder.
145 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530146 private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530147
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530148 /**
149 * File name for getter method.
150 */
151 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530152
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530153 /**
154 * File name for setter method.
155 */
156 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530157
158 /**
159 * File name for getter method implementation.
160 */
161 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
162
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530163 /**
164 * File name for setter method implementation.
165 */
166 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530167
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530168 /**
169 * File name for attributes.
170 */
171 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530172
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530173 /**
174 * File name for to string method.
175 */
176 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530177
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530178 /**
179 * File name for hash code method.
180 */
181 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530182
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530183 /**
184 * File name for equals method.
185 */
186 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530187
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530188 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530189 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530190 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530191 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530192
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530193 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530194 * File name for from add to list interface method.
195 */
196 private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList";
197
198 /**
199 * File name for from add to list impl method.
200 */
201 private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl";
202
203 /**
204 * File name for from leaf identifier attributes.
205 */
206 private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr";
207
208 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530209 * File name for is filter content leaf match.
210 */
211 private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME = "isFilterContentMatchLeafMask";
212
213 /**
214 * File name for is filter content leaf-list match.
215 */
216 private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME = "isFilterContentMatchLeafListMask";
217
218 /**
219 * File name for is filter content node match.
220 */
221 private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME = "isFilterContentMatchNodeMask";
222
223 /**
224 * File name for edit content file.
225 */
226 private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
227
228 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530229 * File name for interface java file name suffix.
230 */
231 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530232
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530233 /**
234 * File name for builder interface file name suffix.
235 */
236 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530237
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530238 /**
239 * File name for builder class file name suffix.
240 */
241 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530242
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530243 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530244 * Information about the java files being generated.
245 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530246 private JavaFileInfoTranslator javaFileInfo;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530247
248 /**
249 * Imported class info.
250 */
251 private JavaImportData javaImportData;
252
253 /**
254 * The variable which guides the types of temporary files generated using the temporary generated file types mask.
255 */
256 private int generatedTempFiles;
257
258 /**
259 * Absolute path where the target java file needs to be generated.
260 */
261 private String absoluteDirPath;
262
263 /**
264 * Contains all the interface(s)/class name which will be extended by generated files.
265 */
266 private JavaExtendsListHolder javaExtendsListHolder;
267
Bharat saraswald14cbe82016-07-14 13:26:18 +0530268 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530269 * Java file handle for interface file.
270 */
271 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530272
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530273 /**
274 * Java file handle for builder interface file.
275 */
276 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530277
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530278 /**
279 * Java file handle for builder class file.
280 */
281 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530282
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530283 /**
284 * Java file handle for impl class file.
285 */
286 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530287
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530288 /**
289 * Temporary file handle for attribute.
290 */
291 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530292
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530293 /**
294 * Temporary file handle for getter of interface.
295 */
296 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530297
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530298 /**
299 * Temporary file handle for setter of interface.
300 */
301 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530302
303 /**
304 * Temporary file handle for getter of class.
305 */
306 private File getterImplTempFileHandle;
307
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530308 /**
309 * Temporary file handle for setter of class.
310 */
311 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530312
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530313 /**
314 * Temporary file handle for hash code method of class.
315 */
316 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530317
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530318 /**
319 * Temporary file handle for equals method of class.
320 */
321 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530322
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530323 /**
324 * Temporary file handle for to string method of class.
325 */
326 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530327
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530328 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530329 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530330 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530331 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530332
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530333 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530334 * Temporary file handle for add to list interface method of class.
335 */
336 private File addToListInterfaceTempFileHandle;
337
338 /**
339 * Temporary file handle for add to list impl method of class.
340 */
341 private File addToListImplTempFileHandle;
342
343 /**
344 * Temporary file handle for leaf id attributes of enum.
345 */
346 private File leafIdAttributeTempFileHandle;
347
348 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530349 * Temporary file handle for is content match method for leaf-list.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530350 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530351 private File getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530352
353 /**
354 * Temporary file handle for is content match method for node.
355 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530356 private File getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530357
358 /**
359 * Temporary file handle for is content match method for leaf.
360 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530361 private File subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530362
363 /**
364 * Temporary file handle for edit content file.
365 */
366 private File editContentTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530367
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530368 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530369 * Leaf count.
370 */
371 private int leafCount = 0;
372
373 /**
374 * If current node is root node.
375 */
376 private boolean isRooNode;
377
378 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530379 * Is attribute added.
380 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530381 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530382
Bharat saraswalaf413b82016-07-14 15:18:20 +0530383 TempJavaFragmentFiles() {
384 }
385
386 /**
387 * Creates an instance of temporary java code fragment.
388 *
389 * @param javaFileInfo generated java file information
390 * @throws IOException when fails to create new file handle
391 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530392 TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530393 throws IOException {
394 setJavaExtendsListHolder(new JavaExtendsListHolder());
395 setJavaImportData(new JavaImportData());
396 setJavaFileInfo(javaFileInfo);
Bharat saraswal8beac342016-08-04 02:00:03 +0530397 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
Bharat saraswal1edde622016-09-06 10:18:04 +0530398 getJavaFileInfo().getPackageFilePath()));
Bharat saraswal8beac342016-08-04 02:00:03 +0530399
Bharat saraswalaf413b82016-07-14 15:18:20 +0530400 /*
401 * Initialize getter when generation file type matches to interface
402 * mask.
403 */
404 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
405 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
Bharat saraswal8beac342016-08-04 02:00:03 +0530406 addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK);
407 addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530408 }
409
410 /*
411 * Initialize getter and setter when generation file type matches to
412 * builder interface mask.
413 */
414 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
415 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
416 addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
417 }
418
419 /*
420 * Initialize getterImpl, setterImpl and attributes when generation file
421 * type matches to builder class mask.
422 */
423 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
424 addGeneratedTempFile(ATTRIBUTES_MASK);
425 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
426 addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530427 }
428
429 /*
430 * Initialize getterImpl, attributes, constructor, hash code, equals and
431 * to strings when generation file type matches to impl class mask.
432 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530433 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530434 addGeneratedTempFile(ATTRIBUTES_MASK);
435 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
436 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
437 addGeneratedTempFile(EQUALS_IMPL_MASK);
438 addGeneratedTempFile(TO_STRING_IMPL_MASK);
Bharat saraswal8beac342016-08-04 02:00:03 +0530439 addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK);
Bharat saraswale50edca2016-08-05 01:58:25 +0530440 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK);
441 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_MASK);
442 addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_NODES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530443 }
444
445 /*
446 * Initialize temp files to generate type class.
447 */
448 if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
449 addGeneratedTempFile(ATTRIBUTES_MASK);
450 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
451 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
452 addGeneratedTempFile(EQUALS_IMPL_MASK);
453 addGeneratedTempFile(TO_STRING_IMPL_MASK);
454 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
455 }
456
Vidyashree Ramab3670472016-08-06 15:49:56 +0530457 //Initialize temp files to generate enum class.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530458 if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
459 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
460 }
461
Vidyashree Ramab3670472016-08-06 15:49:56 +0530462 //Set temporary file handles
Bharat saraswalaf413b82016-07-14 15:18:20 +0530463 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
464 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
465 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530466 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
467 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
468 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530469 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
470 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
471 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530472 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
473 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
474 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530475 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
476 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
477 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530478 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
479 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
480 }
481 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
482 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
483 }
484 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
485 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
486 }
487 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
488 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
489 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530490 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
491 setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME));
492 }
493 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
494 setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME));
495 }
496 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
497 setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME));
498 }
Bharat saraswale50edca2016-08-05 01:58:25 +0530499 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530500 setSubtreeFilteringForLeafTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530501 }
502 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530503 setGetSubtreeFilteringForListTempFileHandle(
504 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530505 }
506 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530507 setGetSubtreeFilteringForChildNodeTempFileHandle(
508 getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME));
Bharat saraswale50edca2016-08-05 01:58:25 +0530509 }
510 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
511 setEditContentTempFileHandle(getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME));
512 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530513 }
514
515 /**
516 * Adds current node info as and attribute to the parent generated file.
517 *
518 * @param curNode current node which needs to be added as an attribute in the parent generated code
519 * @param isList is list construct
520 * @param pluginConfig plugin configurations
521 * @throws IOException IO operation exception
522 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530523 static void addCurNodeInfoInParentTempFile(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530524 boolean isList, YangPluginConfig pluginConfig)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530525 throws IOException {
526 YangNode parent = getParentNodeInGenCode(curNode);
527 if (!(parent instanceof JavaCodeGenerator)) {
Bharat saraswale3175d32016-08-31 17:50:11 +0530528 throw new TranslatorException("missing parent node to contain current node info in generated file "
Bharat saraswal1edde622016-09-06 10:18:04 +0530529 + parent.getName() + " in " + parent.getLineNumber() + " at " +
530 parent.getCharPosition()
531 + " in " + parent.getFileName());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530532 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530533
Shankara-Huaweib7564772016-08-02 18:13:13 +0530534 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530535 /*
536 * In case of grouping, there is no need to add the information, it
537 * will be taken care in uses
538 */
539 return;
540 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530541
Bharat saraswalaf413b82016-07-14 15:18:20 +0530542 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
543 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
544
545 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
Bharat saraswal1edde622016-09-06 10:18:04 +0530546 parent, isList, tempJavaBeanFragmentFiles);
Bharat saraswal8beac342016-08-04 02:00:03 +0530547 tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530548 }
549
550 /**
551 * Creates an attribute info object corresponding to a data model node and return it.
552 *
553 * @param curNode current data model node for which the java code generation is being handled
554 * @param targetNode target node in which the current node is an attribute
555 * @param isListNode is the current added attribute needs to be a list
556 * @param tempJavaFragmentFiles temp java fragment files
557 * @return AttributeInfo attribute details required to add in temporary files
558 */
559 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530560 YangNode targetNode, boolean isListNode,
561 TempJavaFragmentFiles tempJavaFragmentFiles) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530562 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
563 if (curNodeName == null) {
564 updateJavaFileInfo(curNode, null);
565 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
566 }
567
568 /*
569 * Get the import info corresponding to the attribute for import in
570 * generated java files or qualified access
571 */
Shankara-Huaweib7564772016-08-02 18:13:13 +0530572 JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
Bharat saraswal1edde622016-09-06 10:18:04 +0530573 getCapitalCase(curNodeName));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530574 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +0530575 throw new TranslatorException("Parent node does not have file info "
Bharat saraswal1edde622016-09-06 10:18:04 +0530576 + targetNode.getName() + " in " + targetNode.getLineNumber() +
577 " at " + targetNode.getCharPosition()
578 + " in " + targetNode.getFileName());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530579 }
580 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
Bharat saraswale50edca2016-08-05 01:58:25 +0530581 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530582
583 boolean isQualified;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530584 if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
Bharat saraswal8beac342016-08-04 02:00:03 +0530585 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
586 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530587
588 isQualified = true;
589 } else {
590 String className;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530591 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530592 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530593 } else {
594 className = getCapitalCase(fileInfo.getJavaName());
595 }
596
597 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
Bharat saraswal1edde622016-09-06 10:18:04 +0530598 className, fileInfo.getPackage());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530599 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530600 boolean collectionSetFlag = false;
601 if (curNode instanceof YangList) {
602 YangList yangList = (YangList) curNode;
603 if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
604 .getYangAppDataStructure() != null) {
605 switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
606 case QUEUE: {
607 parentImportData.setQueueToImport(true);
608 collectionSetFlag = true;
609 break;
610 }
611 case SET: {
612 parentImportData.setSetToImport(true);
613 collectionSetFlag = true;
614 break;
615 }
616 default: {
617 // TODO : to be implemented
618 }
619 }
620 }
621 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530622 if (isListNode && !(collectionSetFlag)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530623 parentImportData.setIfListImported(true);
624 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530625 if (curNode instanceof YangList) {
626 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
Bharat saraswal1edde622016-09-06 10:18:04 +0530627 ((YangList) curNode).getCompilerAnnotation());
Vidyashree Ramab3670472016-08-06 15:49:56 +0530628 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530629 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
630 }
631
632 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530633 * Returns java attribute for leaf.
634 *
635 * @param tempJavaFragmentFiles temporary generated file
636 * @param leaf YANG leaf
637 * @param yangPluginConfig plugin configurations
638 * @return java attribute for leaf
639 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530640 private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530641 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530642 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
643 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
644 javaLeaf.updateJavaQualifiedInfo();
645 return getAttributeInfoForTheData(
646 javaLeaf.getJavaQualifiedInfo(),
647 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
648 javaLeaf.getDataType(),
649 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
650 false);
651 }
652
653 /**
654 * Returns java attribute for leaf-list.
655 *
656 * @param tempJavaFragmentFiles temporary generated file
657 * @param leafList YANG leaf-list
658 * @param yangPluginConfig plugin configurations
659 * @return java attribute for leaf-list
660 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530661 private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530662 YangLeafList leafList,
663 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530664 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
665 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
666 javaLeaf.updateJavaQualifiedInfo();
667 tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
668 return getAttributeInfoForTheData(
669 javaLeaf.getJavaQualifiedInfo(),
670 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
671 javaLeaf.getDataType(),
672 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
673 true);
674 }
675
Bharat saraswal039f59c2016-07-14 21:57:13 +0530676 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530677 * Retrieves the absolute path where the file needs to be generated.
678 *
679 * @return absolute path where the file needs to be generated
680 */
681 private String getAbsoluteDirPath() {
682 return absoluteDirPath;
683 }
684
685 /**
686 * Sets absolute path where the file needs to be generated.
687 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530688 * @param absoluteDirPath absolute path where the file needs to be generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530689 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530690 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530691 this.absoluteDirPath = absoluteDirPath;
692 }
693
694 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530695 * Retrieves the generated java file information.
696 *
697 * @return generated java file information
698 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530699 public JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530700 return javaFileInfo;
701 }
702
703 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530704 * Sets the generated java file information.
705 *
706 * @param javaFileInfo generated java file information
707 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530708 public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530709 this.javaFileInfo = javaFileInfo;
710 }
711
712 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530713 * Retrieves the generated temp files.
714 *
715 * @return generated temp files
716 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530717 int getGeneratedTempFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530718 return generatedTempFiles;
719 }
720
721 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530722 * Sets generated file files.
723 *
724 * @param fileType generated file type
725 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530726 private void setGeneratedTempFiles(int fileType) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530727 generatedTempFiles = fileType;
728 }
729
730 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530731 * Adds to generated temporary files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530732 *
733 * @param generatedTempFile generated file
734 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530735 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530736 generatedTempFiles |= generatedTempFile;
Bharat saraswal250a7472016-05-12 13:16:57 +0530737 setGeneratedTempFiles(generatedTempFiles);
738 }
739
740 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530741 * Retrieves the generated Java files.
742 *
743 * @return generated Java files
744 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530745 int getGeneratedJavaFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530746 return getJavaFileInfo().getGeneratedFileTypes();
747 }
748
749 /**
750 * Retrieves the mapped Java class name.
751 *
752 * @return mapped Java class name
753 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530754 String getGeneratedJavaClassName() {
janani b703cfe42016-05-17 13:12:22 +0530755 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530756 }
757
758 /**
759 * Retrieves the import data for the generated Java file.
760 *
761 * @return import data for the generated Java file
762 */
763 public JavaImportData getJavaImportData() {
764 return javaImportData;
765 }
766
767 /**
768 * Sets import data for the generated Java file.
769 *
770 * @param javaImportData import data for the generated Java file
771 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530772 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530773 this.javaImportData = javaImportData;
774 }
775
776 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530777 * Retrieves the status of any attributes added.
778 *
779 * @return status of any attributes added
780 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530781 boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530782 return isAttributePresent;
783 }
784
785 /**
786 * Sets status of any attributes added.
787 *
788 * @param attributePresent status of any attributes added
789 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530790 private void setAttributePresent(boolean attributePresent) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530791 isAttributePresent = attributePresent;
792 }
793
794 /**
795 * Returns getter methods's temporary file handle.
796 *
797 * @return temporary file handle
798 */
799 public File getGetterInterfaceTempFileHandle() {
800 return getterInterfaceTempFileHandle;
801 }
802
803 /**
804 * Sets to getter method's temporary file handle.
805 *
806 * @param getterForInterface file handle for to getter method
807 */
808 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
809 getterInterfaceTempFileHandle = getterForInterface;
810 }
811
812 /**
813 * Returns setter method's temporary file handle.
814 *
815 * @return temporary file handle
816 */
817 public File getSetterInterfaceTempFileHandle() {
818 return setterInterfaceTempFileHandle;
819 }
820
821 /**
822 * Sets to setter method's temporary file handle.
823 *
824 * @param setterForInterface file handle for to setter method
825 */
826 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
827 setterInterfaceTempFileHandle = setterForInterface;
828 }
829
830 /**
831 * Returns setter method's impl's temporary file handle.
832 *
833 * @return temporary file handle
834 */
835 public File getSetterImplTempFileHandle() {
836 return setterImplTempFileHandle;
837 }
838
839 /**
840 * Sets to setter method's impl's temporary file handle.
841 *
842 * @param setterImpl file handle for to setter method's implementation class
843 */
844 private void setSetterImplTempFileHandle(File setterImpl) {
845 setterImplTempFileHandle = setterImpl;
846 }
847
848 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530849 * Returns from string method's temporary file handle.
850 *
851 * @return from string method's temporary file handle
852 */
853 public File getFromStringImplTempFileHandle() {
854 return fromStringImplTempFileHandle;
855 }
856
857 /**
858 * Sets from string method's temporary file handle.
859 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530860 * @param fromStringImplTempFileHandle from string method's temporary file handle
Bharat saraswal250a7472016-05-12 13:16:57 +0530861 */
862 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
863 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
864 }
865
866 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530867 * Returns java file handle for interface file.
868 *
869 * @return java file handle for interface file
870 */
871 private File getInterfaceJavaFileHandle() {
872 return interfaceJavaFileHandle;
873 }
874
875 /**
876 * Sets the java file handle for interface file.
877 *
878 * @param interfaceJavaFileHandle java file handle
879 */
880 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
881 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
882 }
883
884 /**
885 * Returns java file handle for builder interface file.
886 *
887 * @return java file handle for builder interface file
888 */
889 private File getBuilderInterfaceJavaFileHandle() {
890 return builderInterfaceJavaFileHandle;
891 }
892
893 /**
894 * Sets the java file handle for builder interface file.
895 *
896 * @param builderInterfaceJavaFileHandle java file handle
897 */
898 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
899 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
900 }
901
902 /**
903 * Returns java file handle for builder class file.
904 *
905 * @return java file handle for builder class file
906 */
907 private File getBuilderClassJavaFileHandle() {
908 return builderClassJavaFileHandle;
909 }
910
911 /**
912 * Sets the java file handle for builder class file.
913 *
914 * @param builderClassJavaFileHandle java file handle
915 */
916 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
917 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
918 }
919
920 /**
921 * Returns java file handle for impl class file.
922 *
923 * @return java file handle for impl class file
924 */
925 private File getImplClassJavaFileHandle() {
926 return implClassJavaFileHandle;
927 }
928
929 /**
930 * Sets the java file handle for impl class file.
931 *
932 * @param implClassJavaFileHandle java file handle
933 */
934 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
935 this.implClassJavaFileHandle = implClassJavaFileHandle;
936 }
937
938 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530939 * Returns attribute's temporary file handle.
940 *
941 * @return temporary file handle
942 */
943 public File getAttributesTempFileHandle() {
944 return attributesTempFileHandle;
945 }
946
947 /**
948 * Sets attribute's temporary file handle.
949 *
950 * @param attributeForClass file handle for attribute
951 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530952 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530953 attributesTempFileHandle = attributeForClass;
954 }
955
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530956 /**
957 * Returns getter method's impl's temporary file handle.
958 *
959 * @return temporary file handle
960 */
961 public File getGetterImplTempFileHandle() {
962 return getterImplTempFileHandle;
963 }
964
965 /**
966 * Sets to getter method's impl's temporary file handle.
967 *
968 * @param getterImpl file handle for to getter method's impl
969 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530970 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530971 getterImplTempFileHandle = getterImpl;
972 }
973
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530974 /**
975 * Returns hash code method's temporary file handle.
976 *
977 * @return temporary file handle
978 */
979 public File getHashCodeImplTempFileHandle() {
980 return hashCodeImplTempFileHandle;
981 }
982
983 /**
984 * Sets hash code method's temporary file handle.
985 *
986 * @param hashCodeMethod file handle for hash code method
987 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530988 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530989 hashCodeImplTempFileHandle = hashCodeMethod;
990 }
991
992 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530993 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530994 *
995 * @return temporary file handle
996 */
997 public File getEqualsImplTempFileHandle() {
998 return equalsImplTempFileHandle;
999 }
1000
1001 /**
1002 * Sets equals method's temporary file handle.
1003 *
1004 * @param equalsMethod file handle for to equals method
1005 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301006 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301007 equalsImplTempFileHandle = equalsMethod;
1008 }
1009
1010 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301011 * Returns to string method's temporary file handle.
1012 *
1013 * @return temporary file handle
1014 */
1015 public File getToStringImplTempFileHandle() {
1016 return toStringImplTempFileHandle;
1017 }
1018
1019 /**
1020 * Sets to string method's temporary file handle.
1021 *
1022 * @param toStringMethod file handle for to string method
1023 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301024 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301025 toStringImplTempFileHandle = toStringMethod;
1026 }
1027
1028 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301029 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301030 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301031 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301032 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301033 public JavaExtendsListHolder getJavaExtendsListHolder() {
1034 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301035 }
1036
1037 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301038 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301039 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301040 * @param javaExtendsListHolder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301041 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301042 void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301043 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301044 }
1045
1046 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301047 * Adds is filter content match for leaf.
1048 *
1049 * @param attr java attribute
1050 * @throws IOException when fails to do IO operations
1051 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301052 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301053 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301054 appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301055 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301056 }
1057
1058 /**
1059 * Adds is filter content match for leaf-list.
1060 *
1061 * @param attr java attribute
1062 * @throws IOException when fails to do IO operations
1063 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301064 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301065 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301066 appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301067 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301068 }
1069
1070 /**
1071 * Adds is filter content match for nodes.
1072 *
1073 * @param attr java attribute
1074 * @throws IOException when fails to do IO operations
1075 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301076 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301077 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301078 appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301079 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301080 }
1081
1082 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301083 * Adds attribute for class.
1084 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301085 * @param attr attribute info
1086 * @param yangPluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301087 * @throws IOException when fails to append to temporary file
1088 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301089 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301090 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301091 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
1092 + FOUR_SPACE_INDENTATION);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301093 }
1094
1095 /**
1096 * Adds getter for interface.
1097 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301098 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301099 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301100 * @throws IOException when fails to append to temporary file
1101 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301102 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301103 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301104 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301105 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301106 }
1107
1108 /**
1109 * Adds setter for interface.
1110 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301111 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301112 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301113 * @throws IOException when fails to append to temporary file
1114 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301115 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301116 throws IOException {
1117 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301118 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
1119 + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301120 }
1121
1122 /**
1123 * Adds setter's implementation for class.
1124 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301125 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301126 * @throws IOException when fails to append to temporary file
1127 */
Bharat saraswale304c252016-08-16 20:56:20 +05301128 private void addSetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301129 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301130 if (isRooNode()) {
Bharat saraswale304c252016-08-16 20:56:20 +05301131 appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301132 attr.isListAttr(), pluginConfig, null) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301133 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
Bharat saraswale304c252016-08-16 20:56:20 +05301134 + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301135 } else {
1136 appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
1137 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
1138 + NEW_LINE);
1139 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301140 }
1141
1142 /**
1143 * Adds getter method's impl for class.
1144 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301145 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301146 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301147 * @throws IOException when fails to append to temporary file
1148 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301149 void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301150 throws IOException {
1151 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
1152 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301153 if (!isRooNode()) {
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301154 appendToFile(getGetterImplTempFileHandle(), getOverRideString() +
1155 getGetterForClass(attr, getGeneratedJavaFiles()) +
Bharat saraswal1edde622016-09-06 10:18:04 +05301156 NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301157 } else {
1158 appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
Bharat saraswal1edde622016-09-06 10:18:04 +05301159 getGeneratedJavaFiles()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301160 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301161 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301162 String appDataStructure = null;
1163 if (attr.getCompilerAnnotation() != null) {
1164 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1165 }
janani b703cfe42016-05-17 13:12:22 +05301166 appendToFile(getGetterImplTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301167 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
1168 appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301169 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301170 }
1171
1172 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301173 * Adds add to list interface method.
1174 *
1175 * @param attr attribute
1176 * @param pluginConfig plugin configurations
1177 * @throws IOException when fails to do IO operations
1178 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301179 private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
1180 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301181 appendToFile(getAddToListInterfaceTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301182 getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
1183 + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301184 }
1185
1186 /**
1187 * Adds add to list interface method.
1188 *
1189 * @param attr attribute
1190 * @throws IOException when fails to do IO operations
1191 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301192 private void addAddToListImpl(JavaAttributeInfo attr)
1193 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301194 appendToFile(getAddToListImplTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301195 getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301196 }
1197
1198 /**
1199 * Adds leaf identifier enum attributes.
1200 *
1201 * @param attr attribute
1202 * @param value value
1203 * @param yangPluginConfig plugin config
1204 * @throws IOException when fails to do IO operations
1205 */
1206 private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
1207 throws IOException {
1208 appendToFile(getLeafIdAttributeTempFileHandle(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301209 FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301210 value));
Bharat saraswal8beac342016-08-04 02:00:03 +05301211 }
1212
1213 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301214 * Adds build method for interface.
1215 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301216 * @param pluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301217 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301218 * @throws IOException when fails to append to temporary file
1219 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301220 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301221 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301222 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301223 }
1224
1225 /**
1226 * Adds build method's implementation for class.
1227 *
1228 * @return build method implementation for class
1229 * @throws IOException when fails to append to temporary file
1230 */
1231 String addBuildMethodImpl()
1232 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301233 return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301234 }
1235
1236 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301237 * Adds default constructor for class.
1238 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301239 * @param modifier modifier for constructor.
1240 * @param toAppend string which need to be appended with the class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301241 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +05301242 * @param isSuffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301243 * @return default constructor for class
1244 * @throws IOException when fails to append to file
1245 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301246 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301247 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301248 String name = getGeneratedJavaClassName();
1249 if (isRooNode() && !toAppend.equals(BUILDER)) {
1250 name = name + OP_PARAM;
1251 return NEW_LINE
1252 + getDefaultConstructorString(name, modifier,
Bharat saraswal1edde622016-09-06 10:18:04 +05301253 pluginConfig);
Bharat saraswal8beac342016-08-04 02:00:03 +05301254 }
1255 if (isSuffix) {
1256 return NEW_LINE +
1257 getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
1258 }
1259 String appended;
1260 if (toAppend.equals(DEFAULT)) {
1261 appended = getCapitalCase(toAppend);
1262 } else {
1263 appended = toAppend;
1264 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301265 return NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +05301266 + getDefaultConstructorString(appended + name, modifier,
Bharat saraswal1edde622016-09-06 10:18:04 +05301267 pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301268 }
1269
1270 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301271 * Adds hash code method for class.
1272 *
1273 * @param attr attribute info
1274 * @throws IOException when fails to append to temporary file
1275 */
1276 private void addHashCodeMethod(JavaAttributeInfo attr)
1277 throws IOException {
1278 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
1279 }
1280
1281 /**
1282 * Adds equals method for class.
1283 *
1284 * @param attr attribute info
1285 * @throws IOException when fails to append to temporary file
1286 */
1287 private void addEqualsMethod(JavaAttributeInfo attr)
1288 throws IOException {
1289 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
1290 }
1291
1292 /**
1293 * Adds ToString method for class.
1294 *
1295 * @param attr attribute info
1296 * @throws IOException when fails to append to temporary file
1297 */
1298 private void addToStringMethod(JavaAttributeInfo attr)
1299 throws IOException {
1300 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
1301 }
1302
1303 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301304 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301305 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301306 * @param javaAttributeInfo type attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301307 * @param fromStringAttributeInfo from string attribute info
1308 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301309 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301310 void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301311 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301312 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301313 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
Bharat saraswal1edde622016-09-06 10:18:04 +05301314 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301315 }
1316
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301317 /**
1318 * Returns a temporary file handle for the specific file type.
1319 *
1320 * @param fileName file name
1321 * @return temporary file handle
1322 * @throws IOException when fails to create new file handle
1323 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301324 File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301325 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301326 String path = getTempDirPath(getAbsoluteDirPath());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301327 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301328 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301329 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301330 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301331 if (!isCreated) {
1332 throw new IOException("failed to create temporary directory for " + fileName);
1333 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301334 }
1335 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1336 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301337 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301338 if (!isCreated) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301339 throw new IOException("failed to create temporary file for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301340 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301341 } else {
Bharat saraswale3175d32016-08-31 17:50:11 +05301342 throw new IOException(fileName + " is reused due to YANG naming. probably your previous build would have " +
Bharat saraswal1edde622016-09-06 10:18:04 +05301343 "failed");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301344 }
1345 return file;
1346 }
1347
1348 /**
1349 * Returns a temporary file handle for the specific file type.
1350 *
1351 * @param fileName file name
1352 * @return temporary file handle
1353 * @throws IOException when fails to create new file handle
1354 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301355 File getJavaFileHandle(String fileName)
1356 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301357 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301358 }
1359
1360 /**
1361 * Returns data from the temporary files.
1362 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301363 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301364 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301365 * @return stored data from temporary files
1366 * @throws IOException when failed to get data from the given file
1367 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301368 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301369 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301370 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301371 if (new File(path + file.getName()).exists()) {
1372 return readAppendFile(path + file.getName(), EMPTY_STRING);
1373 } else {
1374 throw new IOException("Unable to get data from the given "
Bharat saraswal1edde622016-09-06 10:18:04 +05301375 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301376 }
1377 }
1378
1379 /**
1380 * Returns temporary directory path.
1381 *
Bharat saraswald14cbe82016-07-14 13:26:18 +05301382 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301383 * @return directory path
1384 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301385 private String getTempDirPath(String absolutePath) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301386 return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
Bharat saraswal64e7e232016-07-14 23:33:55 +05301387 + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301388 }
1389
1390 /**
1391 * Parses attribute to get the attribute string.
1392 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301393 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301394 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301395 * @return attribute string
1396 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301397 String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301398 /*
1399 * TODO: check if this utility needs to be called or move to the caller
1400 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301401 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301402 String attributeAccessType = PRIVATE;
1403 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
1404 attributeAccessType = PROTECTED;
1405 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301406 if (attr.isQualifiedName()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301407 return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301408 attr.getImportInfo().getClassInfo(),
1409 attributeName, attr.isListAttr(), attributeAccessType,
1410 attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301411 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301412 return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
Bharat saraswal1edde622016-09-06 10:18:04 +05301413 attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301414 }
1415 }
1416
1417 /**
1418 * Appends content to temporary file.
1419 *
1420 * @param file temporary file
1421 * @param data data to be appended
1422 * @throws IOException when fails to append to file
1423 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301424 void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301425 throws IOException {
1426 try {
1427 insertDataIntoJavaFile(file, data);
1428 } catch (IOException ex) {
1429 throw new IOException("failed to write in temp file.");
1430 }
1431 }
1432
1433 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301434 * Adds parent's info to current node import list.
1435 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301436 * @param curNode current node for which import list needs to be updated
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301437 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301438 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301439 void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301440 JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301441 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301442 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1443 return;
1444 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301445 if (!(parent instanceof JavaCodeGenerator)) {
1446 throw new TranslatorException("missing parent node to contain current node info in generated file");
1447 }
1448 if (!(curNode instanceof JavaFileInfoContainer)) {
1449 throw new TranslatorException("missing java file information to get the package details "
Bharat saraswal1edde622016-09-06 10:18:04 +05301450 + "of attribute corresponding to child node " +
1451 curNode.getName() + " in " + curNode.getLineNumber() + " at " +
1452 curNode.getCharPosition()
1453 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301454 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301455 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
Bharat saraswal1edde622016-09-06 10:18:04 +05301456 pluginConfig.getConflictResolver())));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301457 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301458
Bharat saraswale50edca2016-08-05 01:58:25 +05301459 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301460
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301461 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301462 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
Bharat saraswal1edde622016-09-06 10:18:04 +05301463 getCapitalCase(fileInfo.getJavaName()),
1464 fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301465 }
1466
1467 /**
1468 * Adds leaf attributes in generated files.
1469 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301470 * @param listOfLeaves list of YANG leaf
1471 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301472 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301473 * @throws IOException IO operation fail
1474 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301475 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301476 YangPluginConfig yangPluginConfig, YangNode curNode)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301477 throws IOException {
1478 if (listOfLeaves != null) {
1479 for (YangLeaf leaf : listOfLeaves) {
1480 if (!(leaf instanceof JavaLeafInfoContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301481 throw new TranslatorException("Leaf does not have java information " +
Bharat saraswal1edde622016-09-06 10:18:04 +05301482 leaf.getName() + " in " + leaf.getLineNumber() + " at " +
1483 leaf.getCharPosition()
1484 + " in " + leaf.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301485 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301486 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1487 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1488 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1489 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
Bharat saraswal1edde622016-09-06 10:18:04 +05301490 yangPluginConfig), yangPluginConfig);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301491 } else {
1492 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
Bharat saraswal1edde622016-09-06 10:18:04 +05301493 yangPluginConfig);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301494 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301495 }
1496 }
1497 }
1498
1499 /**
1500 * Adds leaf list's attributes in generated files.
1501 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301502 * @param listOfLeafList list of YANG leaves
1503 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301504 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301505 * @throws IOException IO operation fail
1506 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301507 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301508 YangNode curNode)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301509 throws IOException {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301510 if (listOfLeafList != null) {
1511 for (YangLeafList leafList : listOfLeafList) {
1512 if (!(leafList instanceof JavaLeafInfoContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301513 throw new TranslatorException("Leaf-list does not have java information " +
Bharat saraswal1edde622016-09-06 10:18:04 +05301514 curNode.getName() + " in " + curNode.getLineNumber() +
1515 " at " + curNode.getCharPosition()
1516 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301517 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301518 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1519 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1520 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1521 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
Bharat saraswal1edde622016-09-06 10:18:04 +05301522 leafList, yangPluginConfig),
1523 yangPluginConfig);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301524 } else {
1525 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
Bharat saraswal1edde622016-09-06 10:18:04 +05301526 leafList, yangPluginConfig),
1527 yangPluginConfig);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301528 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301529 }
1530 }
1531 }
1532
1533 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301534 * Adds all the leaves in the current data model node as part of the generated temporary file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301535 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301536 * @param curNode current node
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301537 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301538 * @throws IOException IO operation fail
1539 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301540 void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301541 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301542 throws IOException {
1543 if (!(curNode instanceof YangLeavesHolder)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301544 throw new TranslatorException("Data model node does not have any leaves " +
Bharat saraswal1edde622016-09-06 10:18:04 +05301545 curNode.getName() + " in " + curNode.getLineNumber() + " at " +
1546 curNode.getCharPosition()
1547 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301548 }
1549 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301550 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
1551 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301552 }
1553
1554 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301555 * Adds the new attribute info to the target generated temporary files.
1556 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301557 * @param newAttrInfo the attribute info that needs to be added to temporary files
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301558 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301559 * @throws IOException IO operation fail
1560 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301561 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301562 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301563 setAttributePresent(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301564 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301565 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301566 }
1567 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301568 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301569 }
1570 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301571 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301572 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301573 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswale304c252016-08-16 20:56:20 +05301574 addSetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301575 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301576 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1577 addHashCodeMethod(newAttrInfo);
1578 }
1579 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1580 addEqualsMethod(newAttrInfo);
1581 }
1582 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1583 addToStringMethod(newAttrInfo);
1584 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301585 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1586 //TODO: add implementation for edit content match.
1587 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301588 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
1589 addAddToListImpl(newAttrInfo);
1590 }
1591 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
1592 addAddToListInterface(newAttrInfo, pluginConfig);
1593 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301594 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0
1595 && newAttrInfo.getAttributeType() == null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301596 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301597 }
1598 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr()
1599 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301600 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301601 }
1602 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr()
1603 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301604 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301605 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301606 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
1607 && newAttrInfo.getAttributeType() != null) {
1608 leafCount++;
1609 addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
1610 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301611 if (!newAttrInfo.isIntConflict() &&
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301612 !newAttrInfo.isLongConflict() && !newAttrInfo.isShortConflict()) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301613 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1614 addGetterImpl(newAttrInfo, pluginConfig);
1615 }
1616
1617 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301618 JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString =
1619 getQualifiedInfoOfFromString(newAttrInfo, pluginConfig
1620 .getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301621 /*
1622 * Create a new java attribute info with qualified information of
1623 * wrapper classes.
1624 */
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301625 JavaAttributeInfo fromStringAttributeInfo =
1626 getAttributeInfoForTheData(qualifiedInfoOfFromString, newAttrInfo.getAttributeName(),
1627 newAttrInfo.getAttributeType(),
1628 getIsQualifiedAccessOrAddToImportList(
1629 qualifiedInfoOfFromString),
1630 false);
Bharat saraswal250a7472016-05-12 13:16:57 +05301631
Bharat saraswal64e7e232016-07-14 23:33:55 +05301632 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1633 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301634 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301635 }
1636
1637 /**
1638 * Returns java class name.
1639 *
1640 * @param suffix for the class name based on the file type
1641 * @return java class name
1642 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301643 String getJavaClassName(String suffix) {
janani b703cfe42016-05-17 13:12:22 +05301644 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301645 }
1646
1647 /**
Bharat saraswald14cbe82016-07-14 13:26:18 +05301648 * Returns java class name.
1649 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301650 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301651 * @return java class name
1652 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301653 private String getImplClassName(YangNode node) {
1654 if (node instanceof YangModule || node instanceof YangSubModule) {
1655 return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
1656 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301657 return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
1658 }
1659
1660 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301661 * Returns the directory path.
1662 *
1663 * @return directory path
1664 */
1665 private String getDirPath() {
1666 return getJavaFileInfo().getPackageFilePath();
1667 }
1668
1669 /**
1670 * Constructs java code exit.
1671 *
1672 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301673 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301674 * @throws IOException when fails to generate java files
1675 */
1676 public void generateJavaFile(int fileType, YangNode curNode)
1677 throws IOException {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301678 List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
1679 .getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301680 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301681 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301682 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301683 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301684
1685 //Generate java code.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301686 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1687 BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301688
1689 //Create interface file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301690 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1691 setInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301692 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
Bharat saraswal8beac342016-08-04 02:00:03 +05301693 if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301694
1695 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301696 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1697 setBuilderInterfaceJavaFileHandle(
1698 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1699 setBuilderInterfaceJavaFileHandle(
1700 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
Bharat saraswal1edde622016-09-06 10:18:04 +05301701 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301702
1703 //Append builder interface file to interface file and close it.
Bharat saraswal8beac342016-08-04 02:00:03 +05301704 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301705 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301706 }
1707 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301708 validateLineLength(getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301709 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301710 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301711 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301712 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301713 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301714 if (isAttributePresent()) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301715 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301716 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301717 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301718
1719 boolean isLeavesPresent;
1720 if (curNode instanceof YangLeavesHolder) {
1721 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1722 isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
1723 || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
1724 if (isLeavesPresent) {
1725 addBitsetImport(imports);
1726 }
1727 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301728 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301729 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301730 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301731 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301732 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301733
1734 //Create impl class file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301735 setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
Bharat saraswald14cbe82016-07-14 13:26:18 +05301736 setImplClassJavaFileHandle(
Bharat saraswal8beac342016-08-04 02:00:03 +05301737 generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301738
1739 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301740 if ((fileType & BUILDER_CLASS_MASK) != 0) {
1741 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1742 setBuilderClassJavaFileHandle(
1743 generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
Bharat saraswal1edde622016-09-06 10:18:04 +05301744 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301745
1746 //Append impl class to builder class and close it.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301747 mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301748 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301749 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301750 validateLineLength(getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301751 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301752 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301753 freeTemporaryResources(false);
1754 }
1755
Vidyashree Ramab3670472016-08-06 15:49:56 +05301756 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301757 private void addArrayListImport(List<String> imports) {
1758 if (imports.contains(getJavaImportData().getImportForList())) {
1759 imports.add(ARRAY_LIST_IMPORT);
1760 }
1761 }
1762
Bharat saraswal8beac342016-08-04 02:00:03 +05301763 private void addBitsetImport(List<String> imports) {
1764 imports.add(getJavaImportData().getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301765 }
1766
1767 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301768 * Adds imports for ToString and HashCodeMethod.
1769 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301770 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301771 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301772 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301773 void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301774 if (operation) {
1775 imports.add(getJavaImportData().getImportForHashAndEquals());
1776 imports.add(getJavaImportData().getImportForToString());
1777 } else {
1778 imports.remove(getJavaImportData().getImportForHashAndEquals());
1779 imports.remove(getJavaImportData().getImportForToString());
1780 }
1781 }
1782
1783 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301784 * Adds import for map and hash map.
1785 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301786 * @param imports import list
1787 * @param operations true for adding and false for deletion
1788 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301789 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301790 */
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301791 private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301792 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301793 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301794 if (!isInterfaceFile) {
1795 imports.add(getJavaImportData().getHashMapImport());
1796 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301797 // Add import for hash map only if node is not a YANG choice.
1798 if (!(curNode instanceof YangChoice)) {
1799 imports.add(getJavaImportData().getMapImport());
1800 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301801 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301802 if (!isInterfaceFile) {
1803 imports.remove(getJavaImportData().getHashMapImport());
1804 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301805 imports.remove(getJavaImportData().getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301806 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301807 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301808 }
1809
1810 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301811 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301812 *
1813 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301814 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301815 private void addInvocationExceptionImport(List<String> imports) {
1816 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301817 }
1818
1819 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301820 * Removes all temporary file handles.
1821 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301822 * @param isErrorOccurred flag to tell translator that error has occurred while file generation
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301823 * @throws IOException when failed to delete the temporary files
1824 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301825 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301826 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301827 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301828 * Close all java file handles and when error occurs delete the files.
1829 */
1830 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301831 closeFile(getInterfaceJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301832 }
1833 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301834 closeFile(getBuilderClassJavaFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301835 }
1836 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1837 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1838 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301839 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301840 closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301841 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301842 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301843 * Close all temporary file handles and delete the files.
1844 */
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301845 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1846 closeFile(getGetterImplTempFileHandle(), true);
1847 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301848 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1849 closeFile(getAttributesTempFileHandle(), true);
1850 }
1851 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1852 closeFile(getHashCodeImplTempFileHandle(), true);
1853 }
1854 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1855 closeFile(getToStringImplTempFileHandle(), true);
1856 }
1857 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1858 closeFile(getEqualsImplTempFileHandle(), true);
1859 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301860 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1861 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301862 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301863 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
1864 closeFile(getAddToListImplTempFileHandle(), true);
1865 }
1866 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
1867 closeFile(getAddToListInterfaceTempFileHandle(), true);
1868 }
1869 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
1870 closeFile(getLeafIdAttributeTempFileHandle(), true);
1871 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301872 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301873 closeFile(getSubtreeFilteringForLeafTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301874 }
1875 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301876 closeFile(getGetSubtreeFilteringForListTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301877 }
1878 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301879 closeFile(getGetSubtreeFilteringForChildNodeTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301880 }
1881 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1882 closeFile(getEditContentTempFileHandle(), true);
1883 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301884 }
1885
1886 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301887 * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
1888 * same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301889 *
1890 * @param importInfo import info for the current attribute being added
1891 * @return status of the qualified access to the attribute
1892 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301893 boolean getIsQualifiedAccessOrAddToImportList(
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301894 JavaQualifiedTypeInfo importInfo) {
1895 return getJavaImportData().addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
Bharat saraswal1edde622016-09-06 10:18:04 +05301896 getGeneratedJavaClassName(),
1897 getJavaFileInfo().getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301898 }
1899
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301900 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301901 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301902 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301903 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301904 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301905 public File getAddToListInterfaceTempFileHandle() {
1906 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301907 }
1908
1909 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301910 * Sets temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301911 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301912 * @param addToListInterfaceTempFileHandle temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301913 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301914 private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
1915 this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
1916 }
1917
1918 /**
1919 * Returns temp file handle for add to list impl.
1920 *
1921 * @return temp file handle for add to list impl
1922 */
1923 public File getAddToListImplTempFileHandle() {
1924 return addToListImplTempFileHandle;
1925 }
1926
1927 /**
1928 * Sets temp file handle for add to list impl.
1929 *
1930 * @param addToListImplTempFileHandle temp file handle for add to list impl
1931 */
1932 private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
1933 this.addToListImplTempFileHandle = addToListImplTempFileHandle;
1934 }
1935
1936 /**
1937 * Returns temp file handle for leaf identifier attributes.
1938 *
1939 * @return temp file handle for leaf identifier attributes
1940 */
1941 public File getLeafIdAttributeTempFileHandle() {
1942 return leafIdAttributeTempFileHandle;
1943 }
1944
1945 /**
1946 * Sets temp file handle for leaf identifier attributes.
1947 *
Bharat saraswale50edca2016-08-05 01:58:25 +05301948 * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes
Bharat saraswal8beac342016-08-04 02:00:03 +05301949 */
1950 private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
1951 this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
1952 }
1953
1954 /**
1955 * Returns if root node is set.
1956 *
1957 * @return true if root node
1958 */
1959 private boolean isRooNode() {
1960 return isRooNode;
1961 }
1962
1963 /**
1964 * Sets true if root node.
1965 *
1966 * @param rooNode true if root node
1967 */
Bharat saraswale50edca2016-08-05 01:58:25 +05301968 void setRooNode(boolean rooNode) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301969 isRooNode = rooNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301970 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301971
1972 /**
1973 * Returns temp file for is content match.
1974 *
1975 * @return temp file for is content match
1976 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301977 public File getSubtreeFilteringForLeafTempFileHandle() {
1978 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301979 }
1980
1981 /**
1982 * Sets temp file handle for is content match.
1983 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301984 * @param subtreeFilteringForLeafTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301985 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301986 private void setSubtreeFilteringForLeafTempFileHandle(File subtreeFilteringForLeafTempFileHandle) {
1987 this.subtreeFilteringForLeafTempFileHandle = subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301988 }
1989
1990 /**
1991 * Returns temp file for edit content file.
1992 *
1993 * @return temp file for edit content file
1994 */
1995 public File getEditContentTempFileHandle() {
1996 return editContentTempFileHandle;
1997 }
1998
1999 /**
2000 * Sets temp file for edit content file.
2001 *
2002 * @param editContentTempFileHandle temp file for edit content file
2003 */
2004 private void setEditContentTempFileHandle(File editContentTempFileHandle) {
2005 this.editContentTempFileHandle = editContentTempFileHandle;
2006 }
2007
2008 /**
2009 * Returns temp file for is content match.
2010 *
2011 * @return temp file for is content match
2012 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302013 public File getGetSubtreeFilteringForListTempFileHandle() {
2014 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302015 }
2016
2017 /**
2018 * Sets temp file handle for is content match.
2019 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302020 * @param getSubtreeFilteringForListTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302021 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302022 private void setGetSubtreeFilteringForListTempFileHandle(File getSubtreeFilteringForListTempFileHandle) {
2023 this.getSubtreeFilteringForListTempFileHandle = getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302024 }
2025
2026 /**
2027 * Returns temp file for is content match.
2028 *
2029 * @return temp file for is content match
2030 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302031 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
2032 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302033 }
2034
2035 /**
2036 * Sets temp file handle for is content match.
2037 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302038 * @param getSubtreeFilteringForChildNodeTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302039 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302040 private void setGetSubtreeFilteringForChildNodeTempFileHandle(File getSubtreeFilteringForChildNodeTempFileHandle) {
2041 this.getSubtreeFilteringForChildNodeTempFileHandle = getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302042 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05302043}