blob: e20d7880a660fba9d39b135cb965fc5699860b3f [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(),
398 getJavaFileInfo().getPackageFilePath()));
399
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 "
529 + parent.getName() + " in " + parent.getLineNumber() + " at " + parent.getCharPosition()
530 + " in " + parent.getFileName());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530531 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530532
Shankara-Huaweib7564772016-08-02 18:13:13 +0530533 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530534 /*
535 * In case of grouping, there is no need to add the information, it
536 * will be taken care in uses
537 */
538 return;
539 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530540
Bharat saraswalaf413b82016-07-14 15:18:20 +0530541 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
542 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
543
544 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
545 parent, isList, tempJavaBeanFragmentFiles);
Bharat saraswal8beac342016-08-04 02:00:03 +0530546 tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530547 }
548
549 /**
550 * Creates an attribute info object corresponding to a data model node and return it.
551 *
552 * @param curNode current data model node for which the java code generation is being handled
553 * @param targetNode target node in which the current node is an attribute
554 * @param isListNode is the current added attribute needs to be a list
555 * @param tempJavaFragmentFiles temp java fragment files
556 * @return AttributeInfo attribute details required to add in temporary files
557 */
558 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530559 YangNode targetNode, boolean isListNode,
560 TempJavaFragmentFiles tempJavaFragmentFiles) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530561 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
562 if (curNodeName == null) {
563 updateJavaFileInfo(curNode, null);
564 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
565 }
566
567 /*
568 * Get the import info corresponding to the attribute for import in
569 * generated java files or qualified access
570 */
Shankara-Huaweib7564772016-08-02 18:13:13 +0530571 JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
Bharat saraswalaf413b82016-07-14 15:18:20 +0530572 getCapitalCase(curNodeName));
573 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +0530574 throw new TranslatorException("Parent node does not have file info "
575 + targetNode.getName() + " in " + targetNode.getLineNumber() + " at " + targetNode.getCharPosition()
576 + " in " + targetNode.getFileName());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530577 }
578 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
Bharat saraswale50edca2016-08-05 01:58:25 +0530579 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530580
581 boolean isQualified;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530582 if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
Bharat saraswal8beac342016-08-04 02:00:03 +0530583 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
584 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530585
586 isQualified = true;
587 } else {
588 String className;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530589 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530590 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530591 } else {
592 className = getCapitalCase(fileInfo.getJavaName());
593 }
594
595 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
596 className, fileInfo.getPackage());
597 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530598 boolean collectionSetFlag = false;
599 if (curNode instanceof YangList) {
600 YangList yangList = (YangList) curNode;
601 if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
602 .getYangAppDataStructure() != null) {
603 switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
604 case QUEUE: {
605 parentImportData.setQueueToImport(true);
606 collectionSetFlag = true;
607 break;
608 }
609 case SET: {
610 parentImportData.setSetToImport(true);
611 collectionSetFlag = true;
612 break;
613 }
614 default: {
615 // TODO : to be implemented
616 }
617 }
618 }
619 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530620 if (isListNode && !(collectionSetFlag)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530621 parentImportData.setIfListImported(true);
622 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530623 if (curNode instanceof YangList) {
624 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
625 ((YangList) curNode).getCompilerAnnotation());
626 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530627 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
628 }
629
630 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530631 * Returns java attribute for leaf.
632 *
633 * @param tempJavaFragmentFiles temporary generated file
634 * @param leaf YANG leaf
635 * @param yangPluginConfig plugin configurations
636 * @return java attribute for leaf
637 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530638 private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530639 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530640 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
641 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
642 javaLeaf.updateJavaQualifiedInfo();
643 return getAttributeInfoForTheData(
644 javaLeaf.getJavaQualifiedInfo(),
645 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
646 javaLeaf.getDataType(),
647 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
648 false);
649 }
650
651 /**
652 * Returns java attribute for leaf-list.
653 *
654 * @param tempJavaFragmentFiles temporary generated file
655 * @param leafList YANG leaf-list
656 * @param yangPluginConfig plugin configurations
657 * @return java attribute for leaf-list
658 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530659 private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530660 YangLeafList leafList,
661 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530662 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
663 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
664 javaLeaf.updateJavaQualifiedInfo();
665 tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
666 return getAttributeInfoForTheData(
667 javaLeaf.getJavaQualifiedInfo(),
668 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
669 javaLeaf.getDataType(),
670 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
671 true);
672 }
673
Bharat saraswal039f59c2016-07-14 21:57:13 +0530674 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530675 * Retrieves the absolute path where the file needs to be generated.
676 *
677 * @return absolute path where the file needs to be generated
678 */
679 private String getAbsoluteDirPath() {
680 return absoluteDirPath;
681 }
682
683 /**
684 * Sets absolute path where the file needs to be generated.
685 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530686 * @param absoluteDirPath absolute path where the file needs to be generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530687 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530688 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530689 this.absoluteDirPath = absoluteDirPath;
690 }
691
692 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530693 * Retrieves the generated java file information.
694 *
695 * @return generated java file information
696 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530697 public JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530698 return javaFileInfo;
699 }
700
701 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530702 * Sets the generated java file information.
703 *
704 * @param javaFileInfo generated java file information
705 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530706 public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530707 this.javaFileInfo = javaFileInfo;
708 }
709
710 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530711 * Retrieves the generated temp files.
712 *
713 * @return generated temp files
714 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530715 int getGeneratedTempFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530716 return generatedTempFiles;
717 }
718
719 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530720 * Sets generated file files.
721 *
722 * @param fileType generated file type
723 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530724 private void setGeneratedTempFiles(int fileType) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530725 generatedTempFiles = fileType;
726 }
727
728 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530729 * Adds to generated temporary files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530730 *
731 * @param generatedTempFile generated file
732 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530733 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530734 generatedTempFiles |= generatedTempFile;
Bharat saraswal250a7472016-05-12 13:16:57 +0530735 setGeneratedTempFiles(generatedTempFiles);
736 }
737
738 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530739 * Retrieves the generated Java files.
740 *
741 * @return generated Java files
742 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530743 int getGeneratedJavaFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530744 return getJavaFileInfo().getGeneratedFileTypes();
745 }
746
747 /**
748 * Retrieves the mapped Java class name.
749 *
750 * @return mapped Java class name
751 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530752 String getGeneratedJavaClassName() {
janani b703cfe42016-05-17 13:12:22 +0530753 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530754 }
755
756 /**
757 * Retrieves the import data for the generated Java file.
758 *
759 * @return import data for the generated Java file
760 */
761 public JavaImportData getJavaImportData() {
762 return javaImportData;
763 }
764
765 /**
766 * Sets import data for the generated Java file.
767 *
768 * @param javaImportData import data for the generated Java file
769 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530770 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530771 this.javaImportData = javaImportData;
772 }
773
774 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530775 * Retrieves the status of any attributes added.
776 *
777 * @return status of any attributes added
778 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530779 boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530780 return isAttributePresent;
781 }
782
783 /**
784 * Sets status of any attributes added.
785 *
786 * @param attributePresent status of any attributes added
787 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530788 private void setAttributePresent(boolean attributePresent) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530789 isAttributePresent = attributePresent;
790 }
791
792 /**
793 * Returns getter methods's temporary file handle.
794 *
795 * @return temporary file handle
796 */
797 public File getGetterInterfaceTempFileHandle() {
798 return getterInterfaceTempFileHandle;
799 }
800
801 /**
802 * Sets to getter method's temporary file handle.
803 *
804 * @param getterForInterface file handle for to getter method
805 */
806 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
807 getterInterfaceTempFileHandle = getterForInterface;
808 }
809
810 /**
811 * Returns setter method's temporary file handle.
812 *
813 * @return temporary file handle
814 */
815 public File getSetterInterfaceTempFileHandle() {
816 return setterInterfaceTempFileHandle;
817 }
818
819 /**
820 * Sets to setter method's temporary file handle.
821 *
822 * @param setterForInterface file handle for to setter method
823 */
824 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
825 setterInterfaceTempFileHandle = setterForInterface;
826 }
827
828 /**
829 * Returns setter method's impl's temporary file handle.
830 *
831 * @return temporary file handle
832 */
833 public File getSetterImplTempFileHandle() {
834 return setterImplTempFileHandle;
835 }
836
837 /**
838 * Sets to setter method's impl's temporary file handle.
839 *
840 * @param setterImpl file handle for to setter method's implementation class
841 */
842 private void setSetterImplTempFileHandle(File setterImpl) {
843 setterImplTempFileHandle = setterImpl;
844 }
845
846 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530847 * Returns from string method's temporary file handle.
848 *
849 * @return from string method's temporary file handle
850 */
851 public File getFromStringImplTempFileHandle() {
852 return fromStringImplTempFileHandle;
853 }
854
855 /**
856 * Sets from string method's temporary file handle.
857 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530858 * @param fromStringImplTempFileHandle from string method's temporary file handle
Bharat saraswal250a7472016-05-12 13:16:57 +0530859 */
860 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
861 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
862 }
863
864 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530865 * Returns java file handle for interface file.
866 *
867 * @return java file handle for interface file
868 */
869 private File getInterfaceJavaFileHandle() {
870 return interfaceJavaFileHandle;
871 }
872
873 /**
874 * Sets the java file handle for interface file.
875 *
876 * @param interfaceJavaFileHandle java file handle
877 */
878 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
879 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
880 }
881
882 /**
883 * Returns java file handle for builder interface file.
884 *
885 * @return java file handle for builder interface file
886 */
887 private File getBuilderInterfaceJavaFileHandle() {
888 return builderInterfaceJavaFileHandle;
889 }
890
891 /**
892 * Sets the java file handle for builder interface file.
893 *
894 * @param builderInterfaceJavaFileHandle java file handle
895 */
896 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
897 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
898 }
899
900 /**
901 * Returns java file handle for builder class file.
902 *
903 * @return java file handle for builder class file
904 */
905 private File getBuilderClassJavaFileHandle() {
906 return builderClassJavaFileHandle;
907 }
908
909 /**
910 * Sets the java file handle for builder class file.
911 *
912 * @param builderClassJavaFileHandle java file handle
913 */
914 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
915 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
916 }
917
918 /**
919 * Returns java file handle for impl class file.
920 *
921 * @return java file handle for impl class file
922 */
923 private File getImplClassJavaFileHandle() {
924 return implClassJavaFileHandle;
925 }
926
927 /**
928 * Sets the java file handle for impl class file.
929 *
930 * @param implClassJavaFileHandle java file handle
931 */
932 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
933 this.implClassJavaFileHandle = implClassJavaFileHandle;
934 }
935
936 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530937 * Returns attribute's temporary file handle.
938 *
939 * @return temporary file handle
940 */
941 public File getAttributesTempFileHandle() {
942 return attributesTempFileHandle;
943 }
944
945 /**
946 * Sets attribute's temporary file handle.
947 *
948 * @param attributeForClass file handle for attribute
949 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530950 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530951 attributesTempFileHandle = attributeForClass;
952 }
953
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530954 /**
955 * Returns getter method's impl's temporary file handle.
956 *
957 * @return temporary file handle
958 */
959 public File getGetterImplTempFileHandle() {
960 return getterImplTempFileHandle;
961 }
962
963 /**
964 * Sets to getter method's impl's temporary file handle.
965 *
966 * @param getterImpl file handle for to getter method's impl
967 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530968 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530969 getterImplTempFileHandle = getterImpl;
970 }
971
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530972 /**
973 * Returns hash code method's temporary file handle.
974 *
975 * @return temporary file handle
976 */
977 public File getHashCodeImplTempFileHandle() {
978 return hashCodeImplTempFileHandle;
979 }
980
981 /**
982 * Sets hash code method's temporary file handle.
983 *
984 * @param hashCodeMethod file handle for hash code method
985 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530986 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530987 hashCodeImplTempFileHandle = hashCodeMethod;
988 }
989
990 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530991 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530992 *
993 * @return temporary file handle
994 */
995 public File getEqualsImplTempFileHandle() {
996 return equalsImplTempFileHandle;
997 }
998
999 /**
1000 * Sets equals method's temporary file handle.
1001 *
1002 * @param equalsMethod file handle for to equals method
1003 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301004 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301005 equalsImplTempFileHandle = equalsMethod;
1006 }
1007
1008 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301009 * Returns to string method's temporary file handle.
1010 *
1011 * @return temporary file handle
1012 */
1013 public File getToStringImplTempFileHandle() {
1014 return toStringImplTempFileHandle;
1015 }
1016
1017 /**
1018 * Sets to string method's temporary file handle.
1019 *
1020 * @param toStringMethod file handle for to string method
1021 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301022 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301023 toStringImplTempFileHandle = toStringMethod;
1024 }
1025
1026 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301027 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301028 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301029 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301030 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301031 public JavaExtendsListHolder getJavaExtendsListHolder() {
1032 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301033 }
1034
1035 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301036 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301037 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301038 * @param javaExtendsListHolder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301039 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301040 void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301041 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301042 }
1043
1044 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301045 * Adds is filter content match for leaf.
1046 *
1047 * @param attr java attribute
1048 * @throws IOException when fails to do IO operations
1049 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301050 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301051 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301052 appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
1053 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301054 }
1055
1056 /**
1057 * Adds is filter content match for leaf-list.
1058 *
1059 * @param attr java attribute
1060 * @throws IOException when fails to do IO operations
1061 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301062 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301063 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301064 appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
1065 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301066 }
1067
1068 /**
1069 * Adds is filter content match for nodes.
1070 *
1071 * @param attr java attribute
1072 * @throws IOException when fails to do IO operations
1073 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301074 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301075 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301076 appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
1077 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301078 }
1079
1080 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301081 * Adds attribute for class.
1082 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301083 * @param attr attribute info
1084 * @param yangPluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301085 * @throws IOException when fails to append to temporary file
1086 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301087 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301088 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301089 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
1090 + FOUR_SPACE_INDENTATION);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301091 }
1092
1093 /**
1094 * Adds getter for interface.
1095 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301096 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301097 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301098 * @throws IOException when fails to append to temporary file
1099 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301100 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301101 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301102 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301103 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301104 }
1105
1106 /**
1107 * Adds setter for interface.
1108 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301109 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301110 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301111 * @throws IOException when fails to append to temporary file
1112 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301113 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301114 throws IOException {
1115 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301116 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
1117 + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301118 }
1119
1120 /**
1121 * Adds setter's implementation for class.
1122 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301123 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301124 * @throws IOException when fails to append to temporary file
1125 */
Bharat saraswale304c252016-08-16 20:56:20 +05301126 private void addSetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301127 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301128 if (isRooNode()) {
Bharat saraswale304c252016-08-16 20:56:20 +05301129 appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
1130 attr.isListAttr(), pluginConfig, null) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301131 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
Bharat saraswale304c252016-08-16 20:56:20 +05301132 + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301133 } else {
1134 appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
1135 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
1136 + NEW_LINE);
1137 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301138 }
1139
1140 /**
1141 * Adds getter method's impl for class.
1142 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301143 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301144 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301145 * @throws IOException when fails to append to temporary file
1146 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301147 void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301148 throws IOException {
1149 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
1150 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301151 if (!isRooNode()) {
1152 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
1153 getGeneratedJavaFiles()) + NEW_LINE);
1154 } else {
1155 appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
1156 getGeneratedJavaFiles()) + NEW_LINE);
1157 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301158 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301159 String appDataStructure = null;
1160 if (attr.getCompilerAnnotation() != null) {
1161 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1162 }
janani b703cfe42016-05-17 13:12:22 +05301163 appendToFile(getGetterImplTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301164 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
1165 appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301166 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301167 }
1168
1169 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301170 * Adds add to list interface method.
1171 *
1172 * @param attr attribute
1173 * @param pluginConfig plugin configurations
1174 * @throws IOException when fails to do IO operations
1175 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301176 private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
1177 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301178 appendToFile(getAddToListInterfaceTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301179 getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301180 + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301181 }
1182
1183 /**
1184 * Adds add to list interface method.
1185 *
1186 * @param attr attribute
1187 * @throws IOException when fails to do IO operations
1188 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301189 private void addAddToListImpl(JavaAttributeInfo attr)
1190 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301191 appendToFile(getAddToListImplTempFileHandle(),
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301192 getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301193 }
1194
1195 /**
1196 * Adds leaf identifier enum attributes.
1197 *
1198 * @param attr attribute
1199 * @param value value
1200 * @param yangPluginConfig plugin config
1201 * @throws IOException when fails to do IO operations
1202 */
1203 private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
1204 throws IOException {
1205 appendToFile(getLeafIdAttributeTempFileHandle(),
1206 FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
1207 value, yangPluginConfig));
1208 }
1209
1210 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301211 * Adds build method for interface.
1212 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301213 * @param pluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301214 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301215 * @throws IOException when fails to append to temporary file
1216 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301217 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301218 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301219 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301220 }
1221
1222 /**
1223 * Adds build method's implementation for class.
1224 *
1225 * @return build method implementation for class
1226 * @throws IOException when fails to append to temporary file
1227 */
1228 String addBuildMethodImpl()
1229 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301230 return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301231 }
1232
1233 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301234 * Adds default constructor for class.
1235 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301236 * @param modifier modifier for constructor.
1237 * @param toAppend string which need to be appended with the class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301238 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +05301239 * @param isSuffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301240 * @return default constructor for class
1241 * @throws IOException when fails to append to file
1242 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301243 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301244 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301245 String name = getGeneratedJavaClassName();
1246 if (isRooNode() && !toAppend.equals(BUILDER)) {
1247 name = name + OP_PARAM;
1248 return NEW_LINE
1249 + getDefaultConstructorString(name, modifier,
1250 pluginConfig);
1251 }
1252 if (isSuffix) {
1253 return NEW_LINE +
1254 getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
1255 }
1256 String appended;
1257 if (toAppend.equals(DEFAULT)) {
1258 appended = getCapitalCase(toAppend);
1259 } else {
1260 appended = toAppend;
1261 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301262 return NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +05301263 + getDefaultConstructorString(appended + name, modifier,
1264 pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301265 }
1266
1267 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301268 * Adds hash code method for class.
1269 *
1270 * @param attr attribute info
1271 * @throws IOException when fails to append to temporary file
1272 */
1273 private void addHashCodeMethod(JavaAttributeInfo attr)
1274 throws IOException {
1275 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
1276 }
1277
1278 /**
1279 * Adds equals method for class.
1280 *
1281 * @param attr attribute info
1282 * @throws IOException when fails to append to temporary file
1283 */
1284 private void addEqualsMethod(JavaAttributeInfo attr)
1285 throws IOException {
1286 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
1287 }
1288
1289 /**
1290 * Adds ToString method for class.
1291 *
1292 * @param attr attribute info
1293 * @throws IOException when fails to append to temporary file
1294 */
1295 private void addToStringMethod(JavaAttributeInfo attr)
1296 throws IOException {
1297 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
1298 }
1299
1300 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301301 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301302 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301303 * @param javaAttributeInfo type attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301304 * @param fromStringAttributeInfo from string attribute info
1305 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301306 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301307 void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301308 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301309 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301310 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
1311 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301312 }
1313
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301314 /**
1315 * Returns a temporary file handle for the specific file type.
1316 *
1317 * @param fileName file name
1318 * @return temporary file handle
1319 * @throws IOException when fails to create new file handle
1320 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301321 File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301322 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301323 String path = getTempDirPath(getAbsoluteDirPath());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301324 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301325 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301326 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301327 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301328 if (!isCreated) {
1329 throw new IOException("failed to create temporary directory for " + fileName);
1330 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301331 }
1332 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1333 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301334 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301335 if (!isCreated) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301336 throw new IOException("failed to create temporary file for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301337 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301338 } else {
Bharat saraswale3175d32016-08-31 17:50:11 +05301339 throw new IOException(fileName + " is reused due to YANG naming. probably your previous build would have " +
1340 "failed");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301341 }
1342 return file;
1343 }
1344
1345 /**
1346 * Returns a temporary file handle for the specific file type.
1347 *
1348 * @param fileName file name
1349 * @return temporary file handle
1350 * @throws IOException when fails to create new file handle
1351 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301352 File getJavaFileHandle(String fileName)
1353 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301354 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301355 }
1356
1357 /**
1358 * Returns data from the temporary files.
1359 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301360 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301361 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301362 * @return stored data from temporary files
1363 * @throws IOException when failed to get data from the given file
1364 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301365 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301366 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301367 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301368 if (new File(path + file.getName()).exists()) {
1369 return readAppendFile(path + file.getName(), EMPTY_STRING);
1370 } else {
1371 throw new IOException("Unable to get data from the given "
1372 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
1373 }
1374 }
1375
1376 /**
1377 * Returns temporary directory path.
1378 *
Bharat saraswald14cbe82016-07-14 13:26:18 +05301379 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301380 * @return directory path
1381 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301382 private String getTempDirPath(String absolutePath) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301383 return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
Bharat saraswal64e7e232016-07-14 23:33:55 +05301384 + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301385 }
1386
1387 /**
1388 * Parses attribute to get the attribute string.
1389 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301390 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301391 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301392 * @return attribute string
1393 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301394 String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301395 /*
1396 * TODO: check if this utility needs to be called or move to the caller
1397 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301398 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301399 String attributeAccessType = PRIVATE;
1400 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
1401 attributeAccessType = PROTECTED;
1402 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301403 if (attr.isQualifiedName()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301404 return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
Bharat saraswal250a7472016-05-12 13:16:57 +05301405 attr.getImportInfo().getClassInfo(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301406 attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301407 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301408 return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
Vidyashree Ramab3670472016-08-06 15:49:56 +05301409 attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301410 }
1411 }
1412
1413 /**
1414 * Appends content to temporary file.
1415 *
1416 * @param file temporary file
1417 * @param data data to be appended
1418 * @throws IOException when fails to append to file
1419 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301420 void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301421 throws IOException {
1422 try {
1423 insertDataIntoJavaFile(file, data);
1424 } catch (IOException ex) {
1425 throw new IOException("failed to write in temp file.");
1426 }
1427 }
1428
1429 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301430 * Adds parent's info to current node import list.
1431 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301432 * @param curNode current node for which import list needs to be updated
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301433 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301434 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301435 void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301436 JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301437 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301438 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1439 return;
1440 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301441 if (!(parent instanceof JavaCodeGenerator)) {
1442 throw new TranslatorException("missing parent node to contain current node info in generated file");
1443 }
1444 if (!(curNode instanceof JavaFileInfoContainer)) {
1445 throw new TranslatorException("missing java file information to get the package details "
Bharat saraswale3175d32016-08-31 17:50:11 +05301446 + "of attribute corresponding to child node " +
1447 curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
1448 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301449 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301450 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1451 pluginConfig.getConflictResolver())));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301452 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301453
Bharat saraswale50edca2016-08-05 01:58:25 +05301454 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301455
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301456 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301457 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
Bharat saraswald14cbe82016-07-14 13:26:18 +05301458 getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301459 }
1460
1461 /**
1462 * Adds leaf attributes in generated files.
1463 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301464 * @param listOfLeaves list of YANG leaf
1465 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301466 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301467 * @throws IOException IO operation fail
1468 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301469 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301470 YangPluginConfig yangPluginConfig, YangNode curNode)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301471 throws IOException {
1472 if (listOfLeaves != null) {
1473 for (YangLeaf leaf : listOfLeaves) {
1474 if (!(leaf instanceof JavaLeafInfoContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301475 throw new TranslatorException("Leaf does not have java information " +
1476 leaf.getName() + " in " + leaf.getLineNumber() + " at " +
1477 leaf.getCharPosition()
1478 + " in " + leaf.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301479 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301480 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1481 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1482 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1483 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
1484 yangPluginConfig), yangPluginConfig);
1485 } else {
1486 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
1487 yangPluginConfig);
1488 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301489 }
1490 }
1491 }
1492
1493 /**
1494 * Adds leaf list's attributes in generated files.
1495 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301496 * @param listOfLeafList list of YANG leaves
1497 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301498 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301499 * @throws IOException IO operation fail
1500 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301501 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301502 YangNode curNode)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301503 throws IOException {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301504 if (listOfLeafList != null) {
1505 for (YangLeafList leafList : listOfLeafList) {
1506 if (!(leafList instanceof JavaLeafInfoContainer)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301507 throw new TranslatorException("Leaf-list does not have java information " +
1508 curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
1509 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301510 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301511 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1512 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1513 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1514 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
1515 leafList, yangPluginConfig), yangPluginConfig);
1516 } else {
1517 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
1518 leafList, yangPluginConfig), yangPluginConfig);
1519 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301520 }
1521 }
1522 }
1523
1524 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301525 * Adds all the leaves in the current data model node as part of the generated temporary file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301526 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301527 * @param curNode current node
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301528 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301529 * @throws IOException IO operation fail
1530 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301531 void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301532 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301533 throws IOException {
1534 if (!(curNode instanceof YangLeavesHolder)) {
Bharat saraswale3175d32016-08-31 17:50:11 +05301535 throw new TranslatorException("Data model node does not have any leaves " +
1536 curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
1537 + " in " + curNode.getFileName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301538 }
1539 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301540 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
1541 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301542 }
1543
1544 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301545 * Adds the new attribute info to the target generated temporary files.
1546 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301547 * @param newAttrInfo the attribute info that needs to be added to temporary files
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301548 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301549 * @throws IOException IO operation fail
1550 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301551 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301552 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301553 setAttributePresent(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301554 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301555 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301556 }
1557 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301558 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301559 }
1560 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301561 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301562 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301563 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswale304c252016-08-16 20:56:20 +05301564 addSetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301565 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301566 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1567 addHashCodeMethod(newAttrInfo);
1568 }
1569 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1570 addEqualsMethod(newAttrInfo);
1571 }
1572 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1573 addToStringMethod(newAttrInfo);
1574 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301575 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1576 //TODO: add implementation for edit content match.
1577 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301578 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
1579 addAddToListImpl(newAttrInfo);
1580 }
1581 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
1582 addAddToListInterface(newAttrInfo, pluginConfig);
1583 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301584 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0
1585 && newAttrInfo.getAttributeType() == null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301586 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301587 }
1588 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr()
1589 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301590 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301591 }
1592 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr()
1593 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301594 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301595 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301596 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
1597 && newAttrInfo.getAttributeType() != null) {
1598 leafCount++;
1599 addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
1600 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301601 if (!newAttrInfo.isIntConflict() &&
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301602 !newAttrInfo.isLongConflict() && !newAttrInfo.isShortConflict()) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301603 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1604 addGetterImpl(newAttrInfo, pluginConfig);
1605 }
1606
1607 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Shankara-Huaweib7564772016-08-02 18:13:13 +05301608 JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
Bharat saraswal64e7e232016-07-14 23:33:55 +05301609 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301610 /*
1611 * Create a new java attribute info with qualified information of
1612 * wrapper classes.
1613 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301614 JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1615 newAttrInfo.getAttributeName(),
1616 newAttrInfo.getAttributeType(),
1617 getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
Bharat saraswal250a7472016-05-12 13:16:57 +05301618
Bharat saraswal64e7e232016-07-14 23:33:55 +05301619 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1620 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301621 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301622 }
1623
1624 /**
1625 * Returns java class name.
1626 *
1627 * @param suffix for the class name based on the file type
1628 * @return java class name
1629 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301630 String getJavaClassName(String suffix) {
janani b703cfe42016-05-17 13:12:22 +05301631 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301632 }
1633
1634 /**
Bharat saraswald14cbe82016-07-14 13:26:18 +05301635 * Returns java class name.
1636 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301637 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301638 * @return java class name
1639 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301640 private String getImplClassName(YangNode node) {
1641 if (node instanceof YangModule || node instanceof YangSubModule) {
1642 return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
1643 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301644 return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
1645 }
1646
1647 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301648 * Returns the directory path.
1649 *
1650 * @return directory path
1651 */
1652 private String getDirPath() {
1653 return getJavaFileInfo().getPackageFilePath();
1654 }
1655
1656 /**
1657 * Constructs java code exit.
1658 *
1659 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301660 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301661 * @throws IOException when fails to generate java files
1662 */
1663 public void generateJavaFile(int fileType, YangNode curNode)
1664 throws IOException {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301665 List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
1666 .getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301667 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301668 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301669 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301670 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301671
1672 //Generate java code.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301673 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1674 BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301675
1676 //Create interface file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301677 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1678 setInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301679 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
Bharat saraswal8beac342016-08-04 02:00:03 +05301680 if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301681
1682 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301683 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1684 setBuilderInterfaceJavaFileHandle(
1685 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1686 setBuilderInterfaceJavaFileHandle(
1687 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
1688 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301689
1690 //Append builder interface file to interface file and close it.
Bharat saraswal8beac342016-08-04 02:00:03 +05301691 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301692 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301693 }
1694 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301695 validateLineLength(getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301696 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301697 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301698 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301699 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301700 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301701 if (isAttributePresent()) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301702 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301703 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301704 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301705
1706 boolean isLeavesPresent;
1707 if (curNode instanceof YangLeavesHolder) {
1708 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1709 isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
1710 || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
1711 if (isLeavesPresent) {
1712 addBitsetImport(imports);
1713 }
1714 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301715 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301716 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301717 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301718 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301719 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301720
1721 //Create impl class file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301722 setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
Bharat saraswald14cbe82016-07-14 13:26:18 +05301723 setImplClassJavaFileHandle(
Bharat saraswal8beac342016-08-04 02:00:03 +05301724 generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301725
1726 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301727 if ((fileType & BUILDER_CLASS_MASK) != 0) {
1728 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1729 setBuilderClassJavaFileHandle(
1730 generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
1731 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301732
1733 //Append impl class to builder class and close it.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301734 mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301735 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301736 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301737 validateLineLength(getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301738 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301739 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301740 freeTemporaryResources(false);
1741 }
1742
Vidyashree Ramab3670472016-08-06 15:49:56 +05301743 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301744 private void addArrayListImport(List<String> imports) {
1745 if (imports.contains(getJavaImportData().getImportForList())) {
1746 imports.add(ARRAY_LIST_IMPORT);
1747 }
1748 }
1749
Bharat saraswal8beac342016-08-04 02:00:03 +05301750 private void addBitsetImport(List<String> imports) {
1751 imports.add(getJavaImportData().getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301752 }
1753
1754 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301755 * Adds imports for ToString and HashCodeMethod.
1756 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301757 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301758 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301759 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301760 void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301761 if (operation) {
1762 imports.add(getJavaImportData().getImportForHashAndEquals());
1763 imports.add(getJavaImportData().getImportForToString());
1764 } else {
1765 imports.remove(getJavaImportData().getImportForHashAndEquals());
1766 imports.remove(getJavaImportData().getImportForToString());
1767 }
1768 }
1769
1770 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301771 * Adds import for map and hash map.
1772 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301773 * @param imports import list
1774 * @param operations true for adding and false for deletion
1775 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301776 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301777 */
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301778 private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301779 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301780 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301781 if (!isInterfaceFile) {
1782 imports.add(getJavaImportData().getHashMapImport());
1783 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301784 // Add import for hash map only if node is not a YANG choice.
1785 if (!(curNode instanceof YangChoice)) {
1786 imports.add(getJavaImportData().getMapImport());
1787 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301788 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301789 if (!isInterfaceFile) {
1790 imports.remove(getJavaImportData().getHashMapImport());
1791 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301792 imports.remove(getJavaImportData().getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301793 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301794 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301795 }
1796
1797 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301798 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301799 *
1800 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301801 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301802 private void addInvocationExceptionImport(List<String> imports) {
1803 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301804 }
1805
1806 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301807 * Removes all temporary file handles.
1808 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301809 * @param isErrorOccurred flag to tell translator that error has occurred while file generation
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301810 * @throws IOException when failed to delete the temporary files
1811 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301812 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301813 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301814 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301815 * Close all java file handles and when error occurs delete the files.
1816 */
1817 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301818 closeFile(getInterfaceJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301819 }
1820 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301821 closeFile(getBuilderClassJavaFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301822 }
1823 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1824 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1825 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301826 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301827 closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301828 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301829 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301830 * Close all temporary file handles and delete the files.
1831 */
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301832 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1833 closeFile(getGetterImplTempFileHandle(), true);
1834 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301835 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1836 closeFile(getAttributesTempFileHandle(), true);
1837 }
1838 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1839 closeFile(getHashCodeImplTempFileHandle(), true);
1840 }
1841 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1842 closeFile(getToStringImplTempFileHandle(), true);
1843 }
1844 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1845 closeFile(getEqualsImplTempFileHandle(), true);
1846 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301847 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1848 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301849 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301850 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
1851 closeFile(getAddToListImplTempFileHandle(), true);
1852 }
1853 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
1854 closeFile(getAddToListInterfaceTempFileHandle(), true);
1855 }
1856 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
1857 closeFile(getLeafIdAttributeTempFileHandle(), true);
1858 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301859 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301860 closeFile(getSubtreeFilteringForLeafTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301861 }
1862 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301863 closeFile(getGetSubtreeFilteringForListTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301864 }
1865 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301866 closeFile(getGetSubtreeFilteringForChildNodeTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301867 }
1868 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1869 closeFile(getEditContentTempFileHandle(), true);
1870 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301871 }
1872
1873 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301874 * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
1875 * same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301876 *
1877 * @param importInfo import info for the current attribute being added
1878 * @return status of the qualified access to the attribute
1879 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301880 boolean getIsQualifiedAccessOrAddToImportList(
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301881 JavaQualifiedTypeInfo importInfo) {
1882 return getJavaImportData().addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
1883 getGeneratedJavaClassName(),
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301884 getJavaFileInfo().getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301885 }
1886
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301887 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301888 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301889 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301890 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301891 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301892 public File getAddToListInterfaceTempFileHandle() {
1893 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301894 }
1895
1896 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301897 * Sets temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301898 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301899 * @param addToListInterfaceTempFileHandle temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301900 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301901 private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
1902 this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
1903 }
1904
1905 /**
1906 * Returns temp file handle for add to list impl.
1907 *
1908 * @return temp file handle for add to list impl
1909 */
1910 public File getAddToListImplTempFileHandle() {
1911 return addToListImplTempFileHandle;
1912 }
1913
1914 /**
1915 * Sets temp file handle for add to list impl.
1916 *
1917 * @param addToListImplTempFileHandle temp file handle for add to list impl
1918 */
1919 private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
1920 this.addToListImplTempFileHandle = addToListImplTempFileHandle;
1921 }
1922
1923 /**
1924 * Returns temp file handle for leaf identifier attributes.
1925 *
1926 * @return temp file handle for leaf identifier attributes
1927 */
1928 public File getLeafIdAttributeTempFileHandle() {
1929 return leafIdAttributeTempFileHandle;
1930 }
1931
1932 /**
1933 * Sets temp file handle for leaf identifier attributes.
1934 *
Bharat saraswale50edca2016-08-05 01:58:25 +05301935 * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes
Bharat saraswal8beac342016-08-04 02:00:03 +05301936 */
1937 private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
1938 this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
1939 }
1940
1941 /**
1942 * Returns if root node is set.
1943 *
1944 * @return true if root node
1945 */
1946 private boolean isRooNode() {
1947 return isRooNode;
1948 }
1949
1950 /**
1951 * Sets true if root node.
1952 *
1953 * @param rooNode true if root node
1954 */
Bharat saraswale50edca2016-08-05 01:58:25 +05301955 void setRooNode(boolean rooNode) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301956 isRooNode = rooNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301957 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301958
1959 /**
1960 * Returns temp file for is content match.
1961 *
1962 * @return temp file for is content match
1963 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301964 public File getSubtreeFilteringForLeafTempFileHandle() {
1965 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301966 }
1967
1968 /**
1969 * Sets temp file handle for is content match.
1970 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301971 * @param subtreeFilteringForLeafTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301972 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301973 private void setSubtreeFilteringForLeafTempFileHandle(File subtreeFilteringForLeafTempFileHandle) {
1974 this.subtreeFilteringForLeafTempFileHandle = subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301975 }
1976
1977 /**
1978 * Returns temp file for edit content file.
1979 *
1980 * @return temp file for edit content file
1981 */
1982 public File getEditContentTempFileHandle() {
1983 return editContentTempFileHandle;
1984 }
1985
1986 /**
1987 * Sets temp file for edit content file.
1988 *
1989 * @param editContentTempFileHandle temp file for edit content file
1990 */
1991 private void setEditContentTempFileHandle(File editContentTempFileHandle) {
1992 this.editContentTempFileHandle = editContentTempFileHandle;
1993 }
1994
1995 /**
1996 * Returns temp file for is content match.
1997 *
1998 * @return temp file for is content match
1999 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302000 public File getGetSubtreeFilteringForListTempFileHandle() {
2001 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302002 }
2003
2004 /**
2005 * Sets temp file handle for is content match.
2006 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302007 * @param getSubtreeFilteringForListTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302008 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302009 private void setGetSubtreeFilteringForListTempFileHandle(File getSubtreeFilteringForListTempFileHandle) {
2010 this.getSubtreeFilteringForListTempFileHandle = getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302011 }
2012
2013 /**
2014 * Returns temp file for is content match.
2015 *
2016 * @return temp file for is content match
2017 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302018 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
2019 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302020 }
2021
2022 /**
2023 * Sets temp file handle for is content match.
2024 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302025 * @param getSubtreeFilteringForChildNodeTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302026 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302027 private void setGetSubtreeFilteringForChildNodeTempFileHandle(File getSubtreeFilteringForChildNodeTempFileHandle) {
2028 this.getSubtreeFilteringForChildNodeTempFileHandle = getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302029 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05302030}