blob: 14fcdc1eec4b6caa644a3662da06bb131fa8a204 [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)) {
528 throw new TranslatorException("missing parent node to contain current node info in generated file");
529 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530530
Shankara-Huaweib7564772016-08-02 18:13:13 +0530531 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530532 /*
533 * In case of grouping, there is no need to add the information, it
534 * will be taken care in uses
535 */
536 return;
537 }
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530538
Bharat saraswalaf413b82016-07-14 15:18:20 +0530539 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
540 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
541
542 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
543 parent, isList, tempJavaBeanFragmentFiles);
Bharat saraswal8beac342016-08-04 02:00:03 +0530544 tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530545 }
546
547 /**
548 * Creates an attribute info object corresponding to a data model node and return it.
549 *
550 * @param curNode current data model node for which the java code generation is being handled
551 * @param targetNode target node in which the current node is an attribute
552 * @param isListNode is the current added attribute needs to be a list
553 * @param tempJavaFragmentFiles temp java fragment files
554 * @return AttributeInfo attribute details required to add in temporary files
555 */
556 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530557 YangNode targetNode, boolean isListNode,
558 TempJavaFragmentFiles tempJavaFragmentFiles) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530559 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
560 if (curNodeName == null) {
561 updateJavaFileInfo(curNode, null);
562 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
563 }
564
565 /*
566 * Get the import info corresponding to the attribute for import in
567 * generated java files or qualified access
568 */
Shankara-Huaweib7564772016-08-02 18:13:13 +0530569 JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
Bharat saraswalaf413b82016-07-14 15:18:20 +0530570 getCapitalCase(curNodeName));
571 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
572 throw new TranslatorException("Parent node does not have file info");
573 }
574 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
Bharat saraswale50edca2016-08-05 01:58:25 +0530575 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530576
577 boolean isQualified;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530578 if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
Bharat saraswal8beac342016-08-04 02:00:03 +0530579 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
580 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530581
582 isQualified = true;
583 } else {
584 String className;
Bharat saraswalaab24b92016-08-02 18:43:16 +0530585 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530586 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530587 } else {
588 className = getCapitalCase(fileInfo.getJavaName());
589 }
590
591 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
592 className, fileInfo.getPackage());
593 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530594 boolean collectionSetFlag = false;
595 if (curNode instanceof YangList) {
596 YangList yangList = (YangList) curNode;
597 if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
598 .getYangAppDataStructure() != null) {
599 switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
600 case QUEUE: {
601 parentImportData.setQueueToImport(true);
602 collectionSetFlag = true;
603 break;
604 }
605 case SET: {
606 parentImportData.setSetToImport(true);
607 collectionSetFlag = true;
608 break;
609 }
610 default: {
611 // TODO : to be implemented
612 }
613 }
614 }
615 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530616 if (isListNode && !(collectionSetFlag)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530617 parentImportData.setIfListImported(true);
618 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530619 if (curNode instanceof YangList) {
620 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
621 ((YangList) curNode).getCompilerAnnotation());
622 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530623 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
624 }
625
626 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530627 * Returns java attribute for leaf.
628 *
629 * @param tempJavaFragmentFiles temporary generated file
630 * @param leaf YANG leaf
631 * @param yangPluginConfig plugin configurations
632 * @return java attribute for leaf
633 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530634 private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530635 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530636 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
637 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
638 javaLeaf.updateJavaQualifiedInfo();
639 return getAttributeInfoForTheData(
640 javaLeaf.getJavaQualifiedInfo(),
641 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
642 javaLeaf.getDataType(),
643 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
644 false);
645 }
646
647 /**
648 * Returns java attribute for leaf-list.
649 *
650 * @param tempJavaFragmentFiles temporary generated file
651 * @param leafList YANG leaf-list
652 * @param yangPluginConfig plugin configurations
653 * @return java attribute for leaf-list
654 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530655 private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +0530656 YangLeafList leafList,
657 YangPluginConfig yangPluginConfig) {
Bharat saraswal64e7e232016-07-14 23:33:55 +0530658 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
659 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
660 javaLeaf.updateJavaQualifiedInfo();
661 tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
662 return getAttributeInfoForTheData(
663 javaLeaf.getJavaQualifiedInfo(),
664 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
665 javaLeaf.getDataType(),
666 tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
667 true);
668 }
669
Bharat saraswal039f59c2016-07-14 21:57:13 +0530670 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530671 * Retrieves the absolute path where the file needs to be generated.
672 *
673 * @return absolute path where the file needs to be generated
674 */
675 private String getAbsoluteDirPath() {
676 return absoluteDirPath;
677 }
678
679 /**
680 * Sets absolute path where the file needs to be generated.
681 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530682 * @param absoluteDirPath absolute path where the file needs to be generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530683 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530684 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530685 this.absoluteDirPath = absoluteDirPath;
686 }
687
688 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530689 * Retrieves the generated java file information.
690 *
691 * @return generated java file information
692 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530693 public JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530694 return javaFileInfo;
695 }
696
697 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530698 * Sets the generated java file information.
699 *
700 * @param javaFileInfo generated java file information
701 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530702 public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530703 this.javaFileInfo = javaFileInfo;
704 }
705
706 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530707 * Retrieves the generated temp files.
708 *
709 * @return generated temp files
710 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530711 int getGeneratedTempFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530712 return generatedTempFiles;
713 }
714
715 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530716 * Sets generated file files.
717 *
718 * @param fileType generated file type
719 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530720 private void setGeneratedTempFiles(int fileType) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530721 generatedTempFiles = fileType;
722 }
723
724 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530725 * Adds to generated temporary files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530726 *
727 * @param generatedTempFile generated file
728 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530729 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530730 generatedTempFiles |= generatedTempFile;
Bharat saraswal250a7472016-05-12 13:16:57 +0530731 setGeneratedTempFiles(generatedTempFiles);
732 }
733
734 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530735 * Retrieves the generated Java files.
736 *
737 * @return generated Java files
738 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530739 int getGeneratedJavaFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530740 return getJavaFileInfo().getGeneratedFileTypes();
741 }
742
743 /**
744 * Retrieves the mapped Java class name.
745 *
746 * @return mapped Java class name
747 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530748 String getGeneratedJavaClassName() {
janani b703cfe42016-05-17 13:12:22 +0530749 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530750 }
751
752 /**
753 * Retrieves the import data for the generated Java file.
754 *
755 * @return import data for the generated Java file
756 */
757 public JavaImportData getJavaImportData() {
758 return javaImportData;
759 }
760
761 /**
762 * Sets import data for the generated Java file.
763 *
764 * @param javaImportData import data for the generated Java file
765 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530766 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530767 this.javaImportData = javaImportData;
768 }
769
770 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530771 * Retrieves the status of any attributes added.
772 *
773 * @return status of any attributes added
774 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530775 boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530776 return isAttributePresent;
777 }
778
779 /**
780 * Sets status of any attributes added.
781 *
782 * @param attributePresent status of any attributes added
783 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530784 private void setAttributePresent(boolean attributePresent) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530785 isAttributePresent = attributePresent;
786 }
787
788 /**
789 * Returns getter methods's temporary file handle.
790 *
791 * @return temporary file handle
792 */
793 public File getGetterInterfaceTempFileHandle() {
794 return getterInterfaceTempFileHandle;
795 }
796
797 /**
798 * Sets to getter method's temporary file handle.
799 *
800 * @param getterForInterface file handle for to getter method
801 */
802 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
803 getterInterfaceTempFileHandle = getterForInterface;
804 }
805
806 /**
807 * Returns setter method's temporary file handle.
808 *
809 * @return temporary file handle
810 */
811 public File getSetterInterfaceTempFileHandle() {
812 return setterInterfaceTempFileHandle;
813 }
814
815 /**
816 * Sets to setter method's temporary file handle.
817 *
818 * @param setterForInterface file handle for to setter method
819 */
820 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
821 setterInterfaceTempFileHandle = setterForInterface;
822 }
823
824 /**
825 * Returns setter method's impl's temporary file handle.
826 *
827 * @return temporary file handle
828 */
829 public File getSetterImplTempFileHandle() {
830 return setterImplTempFileHandle;
831 }
832
833 /**
834 * Sets to setter method's impl's temporary file handle.
835 *
836 * @param setterImpl file handle for to setter method's implementation class
837 */
838 private void setSetterImplTempFileHandle(File setterImpl) {
839 setterImplTempFileHandle = setterImpl;
840 }
841
842 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530843 * Returns from string method's temporary file handle.
844 *
845 * @return from string method's temporary file handle
846 */
847 public File getFromStringImplTempFileHandle() {
848 return fromStringImplTempFileHandle;
849 }
850
851 /**
852 * Sets from string method's temporary file handle.
853 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530854 * @param fromStringImplTempFileHandle from string method's temporary file handle
Bharat saraswal250a7472016-05-12 13:16:57 +0530855 */
856 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
857 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
858 }
859
860 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530861 * Returns java file handle for interface file.
862 *
863 * @return java file handle for interface file
864 */
865 private File getInterfaceJavaFileHandle() {
866 return interfaceJavaFileHandle;
867 }
868
869 /**
870 * Sets the java file handle for interface file.
871 *
872 * @param interfaceJavaFileHandle java file handle
873 */
874 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
875 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
876 }
877
878 /**
879 * Returns java file handle for builder interface file.
880 *
881 * @return java file handle for builder interface file
882 */
883 private File getBuilderInterfaceJavaFileHandle() {
884 return builderInterfaceJavaFileHandle;
885 }
886
887 /**
888 * Sets the java file handle for builder interface file.
889 *
890 * @param builderInterfaceJavaFileHandle java file handle
891 */
892 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
893 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
894 }
895
896 /**
897 * Returns java file handle for builder class file.
898 *
899 * @return java file handle for builder class file
900 */
901 private File getBuilderClassJavaFileHandle() {
902 return builderClassJavaFileHandle;
903 }
904
905 /**
906 * Sets the java file handle for builder class file.
907 *
908 * @param builderClassJavaFileHandle java file handle
909 */
910 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
911 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
912 }
913
914 /**
915 * Returns java file handle for impl class file.
916 *
917 * @return java file handle for impl class file
918 */
919 private File getImplClassJavaFileHandle() {
920 return implClassJavaFileHandle;
921 }
922
923 /**
924 * Sets the java file handle for impl class file.
925 *
926 * @param implClassJavaFileHandle java file handle
927 */
928 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
929 this.implClassJavaFileHandle = implClassJavaFileHandle;
930 }
931
932 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530933 * Returns attribute's temporary file handle.
934 *
935 * @return temporary file handle
936 */
937 public File getAttributesTempFileHandle() {
938 return attributesTempFileHandle;
939 }
940
941 /**
942 * Sets attribute's temporary file handle.
943 *
944 * @param attributeForClass file handle for attribute
945 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530946 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530947 attributesTempFileHandle = attributeForClass;
948 }
949
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530950 /**
951 * Returns getter method's impl's temporary file handle.
952 *
953 * @return temporary file handle
954 */
955 public File getGetterImplTempFileHandle() {
956 return getterImplTempFileHandle;
957 }
958
959 /**
960 * Sets to getter method's impl's temporary file handle.
961 *
962 * @param getterImpl file handle for to getter method's impl
963 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530964 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530965 getterImplTempFileHandle = getterImpl;
966 }
967
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530968 /**
969 * Returns hash code method's temporary file handle.
970 *
971 * @return temporary file handle
972 */
973 public File getHashCodeImplTempFileHandle() {
974 return hashCodeImplTempFileHandle;
975 }
976
977 /**
978 * Sets hash code method's temporary file handle.
979 *
980 * @param hashCodeMethod file handle for hash code method
981 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530982 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530983 hashCodeImplTempFileHandle = hashCodeMethod;
984 }
985
986 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530987 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530988 *
989 * @return temporary file handle
990 */
991 public File getEqualsImplTempFileHandle() {
992 return equalsImplTempFileHandle;
993 }
994
995 /**
996 * Sets equals method's temporary file handle.
997 *
998 * @param equalsMethod file handle for to equals method
999 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301000 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301001 equalsImplTempFileHandle = equalsMethod;
1002 }
1003
1004 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301005 * Returns to string method's temporary file handle.
1006 *
1007 * @return temporary file handle
1008 */
1009 public File getToStringImplTempFileHandle() {
1010 return toStringImplTempFileHandle;
1011 }
1012
1013 /**
1014 * Sets to string method's temporary file handle.
1015 *
1016 * @param toStringMethod file handle for to string method
1017 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301018 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301019 toStringImplTempFileHandle = toStringMethod;
1020 }
1021
1022 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301023 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301024 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301025 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301026 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301027 public JavaExtendsListHolder getJavaExtendsListHolder() {
1028 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301029 }
1030
1031 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301032 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301033 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301034 * @param javaExtendsListHolder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301035 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301036 void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301037 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301038 }
1039
1040 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301041 * Adds is filter content match for leaf.
1042 *
1043 * @param attr java attribute
1044 * @throws IOException when fails to do IO operations
1045 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301046 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301047 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301048 appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
1049 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301050 }
1051
1052 /**
1053 * Adds is filter content match for leaf-list.
1054 *
1055 * @param attr java attribute
1056 * @throws IOException when fails to do IO operations
1057 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301058 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301059 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301060 appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
1061 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301062 }
1063
1064 /**
1065 * Adds is filter content match for nodes.
1066 *
1067 * @param attr java attribute
1068 * @throws IOException when fails to do IO operations
1069 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301070 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301071 throws IOException {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301072 appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
1073 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301074 }
1075
1076 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301077 * Adds attribute for class.
1078 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301079 * @param attr attribute info
1080 * @param yangPluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301081 * @throws IOException when fails to append to temporary file
1082 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301083 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301084 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301085 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
1086 + FOUR_SPACE_INDENTATION);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301087 }
1088
1089 /**
1090 * Adds getter for interface.
1091 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301092 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301093 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301094 * @throws IOException when fails to append to temporary file
1095 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301096 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301097 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301098 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301099 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301100 }
1101
1102 /**
1103 * Adds setter for interface.
1104 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301105 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301106 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301107 * @throws IOException when fails to append to temporary file
1108 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301109 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301110 throws IOException {
1111 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301112 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
1113 + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301114 }
1115
1116 /**
1117 * Adds setter's implementation for class.
1118 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301119 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301120 * @throws IOException when fails to append to temporary file
1121 */
Bharat saraswale304c252016-08-16 20:56:20 +05301122 private void addSetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301123 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301124 if (isRooNode()) {
Bharat saraswale304c252016-08-16 20:56:20 +05301125 appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
1126 attr.isListAttr(), pluginConfig, null) +
Bharat saraswal8beac342016-08-04 02:00:03 +05301127 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
Bharat saraswale304c252016-08-16 20:56:20 +05301128 + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301129 } else {
1130 appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
1131 getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
1132 + NEW_LINE);
1133 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301134 }
1135
1136 /**
1137 * Adds getter method's impl for class.
1138 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301139 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301140 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301141 * @throws IOException when fails to append to temporary file
1142 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301143 void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301144 throws IOException {
1145 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
1146 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301147 if (!isRooNode()) {
1148 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
1149 getGeneratedJavaFiles()) + NEW_LINE);
1150 } else {
1151 appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
1152 getGeneratedJavaFiles()) + NEW_LINE);
1153 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301154 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301155 String appDataStructure = null;
1156 if (attr.getCompilerAnnotation() != null) {
1157 appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
1158 }
janani b703cfe42016-05-17 13:12:22 +05301159 appendToFile(getGetterImplTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301160 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
1161 appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301162 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301163 }
1164
1165 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301166 * Adds add to list interface method.
1167 *
1168 * @param attr attribute
1169 * @param pluginConfig plugin configurations
1170 * @throws IOException when fails to do IO operations
1171 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301172 private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
1173 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301174 appendToFile(getAddToListInterfaceTempFileHandle(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301175 getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301176 + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301177 }
1178
1179 /**
1180 * Adds add to list interface method.
1181 *
1182 * @param attr attribute
1183 * @throws IOException when fails to do IO operations
1184 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301185 private void addAddToListImpl(JavaAttributeInfo attr)
1186 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301187 appendToFile(getAddToListImplTempFileHandle(),
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301188 getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301189 }
1190
1191 /**
1192 * Adds leaf identifier enum attributes.
1193 *
1194 * @param attr attribute
1195 * @param value value
1196 * @param yangPluginConfig plugin config
1197 * @throws IOException when fails to do IO operations
1198 */
1199 private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
1200 throws IOException {
1201 appendToFile(getLeafIdAttributeTempFileHandle(),
1202 FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
1203 value, yangPluginConfig));
1204 }
1205
1206 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301207 * Adds build method for interface.
1208 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301209 * @param pluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301210 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301211 * @throws IOException when fails to append to temporary file
1212 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301213 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301214 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301215 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301216 }
1217
1218 /**
1219 * Adds build method's implementation for class.
1220 *
1221 * @return build method implementation for class
1222 * @throws IOException when fails to append to temporary file
1223 */
1224 String addBuildMethodImpl()
1225 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301226 return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301227 }
1228
1229 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301230 * Adds default constructor for class.
1231 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301232 * @param modifier modifier for constructor.
1233 * @param toAppend string which need to be appended with the class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301234 * @param pluginConfig plugin configurations
Bharat saraswal8beac342016-08-04 02:00:03 +05301235 * @param isSuffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301236 * @return default constructor for class
1237 * @throws IOException when fails to append to file
1238 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301239 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301240 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301241 String name = getGeneratedJavaClassName();
1242 if (isRooNode() && !toAppend.equals(BUILDER)) {
1243 name = name + OP_PARAM;
1244 return NEW_LINE
1245 + getDefaultConstructorString(name, modifier,
1246 pluginConfig);
1247 }
1248 if (isSuffix) {
1249 return NEW_LINE +
1250 getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
1251 }
1252 String appended;
1253 if (toAppend.equals(DEFAULT)) {
1254 appended = getCapitalCase(toAppend);
1255 } else {
1256 appended = toAppend;
1257 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301258 return NEW_LINE
Bharat saraswal8beac342016-08-04 02:00:03 +05301259 + getDefaultConstructorString(appended + name, modifier,
1260 pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301261 }
1262
1263 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301264 * Adds hash code method for class.
1265 *
1266 * @param attr attribute info
1267 * @throws IOException when fails to append to temporary file
1268 */
1269 private void addHashCodeMethod(JavaAttributeInfo attr)
1270 throws IOException {
1271 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
1272 }
1273
1274 /**
1275 * Adds equals method for class.
1276 *
1277 * @param attr attribute info
1278 * @throws IOException when fails to append to temporary file
1279 */
1280 private void addEqualsMethod(JavaAttributeInfo attr)
1281 throws IOException {
1282 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
1283 }
1284
1285 /**
1286 * Adds ToString method for class.
1287 *
1288 * @param attr attribute info
1289 * @throws IOException when fails to append to temporary file
1290 */
1291 private void addToStringMethod(JavaAttributeInfo attr)
1292 throws IOException {
1293 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
1294 }
1295
1296 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301297 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301298 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301299 * @param javaAttributeInfo type attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301300 * @param fromStringAttributeInfo from string attribute info
1301 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301302 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301303 void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301304 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301305 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +05301306 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
1307 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301308 }
1309
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301310 /**
1311 * Returns a temporary file handle for the specific file type.
1312 *
1313 * @param fileName file name
1314 * @return temporary file handle
1315 * @throws IOException when fails to create new file handle
1316 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301317 File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301318 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301319 String path = getTempDirPath(getAbsoluteDirPath());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301320 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301321 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301322 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301323 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301324 if (!isCreated) {
1325 throw new IOException("failed to create temporary directory for " + fileName);
1326 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301327 }
1328 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1329 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301330 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301331 if (!isCreated) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301332 throw new IOException("failed to create temporary file for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301333 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301334 } else {
1335 throw new IOException(fileName + " is reused due to YANG naming");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301336 }
1337 return file;
1338 }
1339
1340 /**
1341 * Returns a temporary file handle for the specific file type.
1342 *
1343 * @param fileName file name
1344 * @return temporary file handle
1345 * @throws IOException when fails to create new file handle
1346 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301347 File getJavaFileHandle(String fileName)
1348 throws IOException {
Bharat saraswal8beac342016-08-04 02:00:03 +05301349 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301350 }
1351
1352 /**
1353 * Returns data from the temporary files.
1354 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301355 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301356 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301357 * @return stored data from temporary files
1358 * @throws IOException when failed to get data from the given file
1359 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301360 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301361 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301362 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301363 if (new File(path + file.getName()).exists()) {
1364 return readAppendFile(path + file.getName(), EMPTY_STRING);
1365 } else {
1366 throw new IOException("Unable to get data from the given "
1367 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
1368 }
1369 }
1370
1371 /**
1372 * Returns temporary directory path.
1373 *
Bharat saraswald14cbe82016-07-14 13:26:18 +05301374 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301375 * @return directory path
1376 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301377 private String getTempDirPath(String absolutePath) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301378 return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
Bharat saraswal64e7e232016-07-14 23:33:55 +05301379 + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301380 }
1381
1382 /**
1383 * Parses attribute to get the attribute string.
1384 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301385 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301386 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301387 * @return attribute string
1388 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301389 String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301390 /*
1391 * TODO: check if this utility needs to be called or move to the caller
1392 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301393 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301394 String attributeAccessType = PRIVATE;
1395 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
1396 attributeAccessType = PROTECTED;
1397 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301398 if (attr.isQualifiedName()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301399 return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
Bharat saraswal250a7472016-05-12 13:16:57 +05301400 attr.getImportInfo().getClassInfo(),
Vidyashree Ramab3670472016-08-06 15:49:56 +05301401 attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301402 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301403 return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
Vidyashree Ramab3670472016-08-06 15:49:56 +05301404 attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301405 }
1406 }
1407
1408 /**
1409 * Appends content to temporary file.
1410 *
1411 * @param file temporary file
1412 * @param data data to be appended
1413 * @throws IOException when fails to append to file
1414 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301415 void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301416 throws IOException {
1417 try {
1418 insertDataIntoJavaFile(file, data);
1419 } catch (IOException ex) {
1420 throw new IOException("failed to write in temp file.");
1421 }
1422 }
1423
1424 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301425 * Adds parent's info to current node import list.
1426 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301427 * @param curNode current node for which import list needs to be updated
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301428 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301429 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301430 void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301431 JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301432 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301433 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1434 return;
1435 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301436 if (!(parent instanceof JavaCodeGenerator)) {
1437 throw new TranslatorException("missing parent node to contain current node info in generated file");
1438 }
1439 if (!(curNode instanceof JavaFileInfoContainer)) {
1440 throw new TranslatorException("missing java file information to get the package details "
1441 + "of attribute corresponding to child node");
1442 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301443 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1444 pluginConfig.getConflictResolver())));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301445 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301446
Bharat saraswale50edca2016-08-05 01:58:25 +05301447 JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301448
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301449 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301450 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
Bharat saraswald14cbe82016-07-14 13:26:18 +05301451 getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301452 }
1453
1454 /**
1455 * Adds leaf attributes in generated files.
1456 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301457 * @param listOfLeaves list of YANG leaf
1458 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301459 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301460 * @throws IOException IO operation fail
1461 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301462 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301463 YangPluginConfig yangPluginConfig, YangNode curNode)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301464 throws IOException {
1465 if (listOfLeaves != null) {
1466 for (YangLeaf leaf : listOfLeaves) {
1467 if (!(leaf instanceof JavaLeafInfoContainer)) {
1468 throw new TranslatorException("Leaf does not have java information");
1469 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301470 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1471 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1472 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1473 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
1474 yangPluginConfig), yangPluginConfig);
1475 } else {
1476 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
1477 yangPluginConfig);
1478 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301479 }
1480 }
1481 }
1482
1483 /**
1484 * Adds leaf list's attributes in generated files.
1485 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301486 * @param listOfLeafList list of YANG leaves
1487 * @param yangPluginConfig plugin config
Bharat saraswal64e7e232016-07-14 23:33:55 +05301488 * @param curNode current node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301489 * @throws IOException IO operation fail
1490 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301491 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301492 YangNode curNode)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301493 throws IOException {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301494 if (listOfLeafList != null) {
1495 for (YangLeafList leafList : listOfLeafList) {
1496 if (!(leafList instanceof JavaLeafInfoContainer)) {
1497 throw new TranslatorException("Leaf-list does not have java information");
1498 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301499 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1500 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1501 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
1502 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
1503 leafList, yangPluginConfig), yangPluginConfig);
1504 } else {
1505 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
1506 leafList, yangPluginConfig), yangPluginConfig);
1507 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301508 }
1509 }
1510 }
1511
1512 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +05301513 * Adds all the leaves in the current data model node as part of the generated temporary file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301514 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301515 * @param curNode current node
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301516 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301517 * @throws IOException IO operation fail
1518 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301519 void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301520 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301521 throws IOException {
1522 if (!(curNode instanceof YangLeavesHolder)) {
1523 throw new TranslatorException("Data model node does not have any leaves");
1524 }
1525 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Bharat saraswal64e7e232016-07-14 23:33:55 +05301526 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
1527 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301528 }
1529
1530 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301531 * Adds the new attribute info to the target generated temporary files.
1532 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301533 * @param newAttrInfo the attribute info that needs to be added to temporary files
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301534 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301535 * @throws IOException IO operation fail
1536 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301537 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301538 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301539 setAttributePresent(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301540 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301541 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301542 }
1543 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301544 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301545 }
1546 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301547 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301548 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301549 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswale304c252016-08-16 20:56:20 +05301550 addSetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301551 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301552 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1553 addHashCodeMethod(newAttrInfo);
1554 }
1555 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1556 addEqualsMethod(newAttrInfo);
1557 }
1558 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1559 addToStringMethod(newAttrInfo);
1560 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301561 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1562 //TODO: add implementation for edit content match.
1563 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301564 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
1565 addAddToListImpl(newAttrInfo);
1566 }
1567 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
1568 addAddToListInterface(newAttrInfo, pluginConfig);
1569 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301570 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0
1571 && newAttrInfo.getAttributeType() == null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301572 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301573 }
1574 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr()
1575 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301576 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301577 }
1578 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr()
1579 && newAttrInfo.getAttributeType() != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301580 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301581 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301582 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
1583 && newAttrInfo.getAttributeType() != null) {
1584 leafCount++;
1585 addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
1586 }
Bharat saraswal64e7e232016-07-14 23:33:55 +05301587 if (!newAttrInfo.isIntConflict() &&
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301588 !newAttrInfo.isLongConflict() && !newAttrInfo.isShortConflict()) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301589 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1590 addGetterImpl(newAttrInfo, pluginConfig);
1591 }
1592
1593 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Shankara-Huaweib7564772016-08-02 18:13:13 +05301594 JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
Bharat saraswal64e7e232016-07-14 23:33:55 +05301595 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301596 /*
1597 * Create a new java attribute info with qualified information of
1598 * wrapper classes.
1599 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301600 JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1601 newAttrInfo.getAttributeName(),
1602 newAttrInfo.getAttributeType(),
1603 getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
Bharat saraswal250a7472016-05-12 13:16:57 +05301604
Bharat saraswal64e7e232016-07-14 23:33:55 +05301605 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1606 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301607 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301608 }
1609
1610 /**
1611 * Returns java class name.
1612 *
1613 * @param suffix for the class name based on the file type
1614 * @return java class name
1615 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301616 String getJavaClassName(String suffix) {
janani b703cfe42016-05-17 13:12:22 +05301617 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301618 }
1619
1620 /**
Bharat saraswald14cbe82016-07-14 13:26:18 +05301621 * Returns java class name.
1622 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301623 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301624 * @return java class name
1625 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301626 private String getImplClassName(YangNode node) {
1627 if (node instanceof YangModule || node instanceof YangSubModule) {
1628 return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
1629 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301630 return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
1631 }
1632
1633 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301634 * Returns the directory path.
1635 *
1636 * @return directory path
1637 */
1638 private String getDirPath() {
1639 return getJavaFileInfo().getPackageFilePath();
1640 }
1641
1642 /**
1643 * Constructs java code exit.
1644 *
1645 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301646 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301647 * @throws IOException when fails to generate java files
1648 */
1649 public void generateJavaFile(int fileType, YangNode curNode)
1650 throws IOException {
Bharat saraswalaf413b82016-07-14 15:18:20 +05301651 List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
1652 .getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301653 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301654 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301655 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301656 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301657
1658 //Generate java code.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301659 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1660 BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301661
1662 //Create interface file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301663 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1664 setInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301665 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
Bharat saraswal8beac342016-08-04 02:00:03 +05301666 if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301667
1668 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301669 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1670 setBuilderInterfaceJavaFileHandle(
1671 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1672 setBuilderInterfaceJavaFileHandle(
1673 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
1674 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301675
1676 //Append builder interface file to interface file and close it.
Bharat saraswal8beac342016-08-04 02:00:03 +05301677 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301678 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301679 }
1680 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301681 validateLineLength(getInterfaceJavaFileHandle());
Bharat saraswal8beac342016-08-04 02:00:03 +05301682 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301683 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301684 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301685 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301686 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301687 if (isAttributePresent()) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301688 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301689 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301690 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301691
1692 boolean isLeavesPresent;
1693 if (curNode instanceof YangLeavesHolder) {
1694 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1695 isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
1696 || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
1697 if (isLeavesPresent) {
1698 addBitsetImport(imports);
1699 }
1700 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301701 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301702 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301703 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301704 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301705 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301706
1707 //Create impl class file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301708 setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
Bharat saraswald14cbe82016-07-14 13:26:18 +05301709 setImplClassJavaFileHandle(
Bharat saraswal8beac342016-08-04 02:00:03 +05301710 generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301711
1712 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301713 if ((fileType & BUILDER_CLASS_MASK) != 0) {
1714 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1715 setBuilderClassJavaFileHandle(
1716 generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
1717 isAttributePresent()));
Vidyashree Ramab3670472016-08-06 15:49:56 +05301718
1719 //Append impl class to builder class and close it.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301720 mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301721 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301722 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale304c252016-08-16 20:56:20 +05301723 validateLineLength(getImplClassJavaFileHandle());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301724 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301725 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301726 freeTemporaryResources(false);
1727 }
1728
Vidyashree Ramab3670472016-08-06 15:49:56 +05301729 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301730 private void addArrayListImport(List<String> imports) {
1731 if (imports.contains(getJavaImportData().getImportForList())) {
1732 imports.add(ARRAY_LIST_IMPORT);
1733 }
1734 }
1735
Bharat saraswal8beac342016-08-04 02:00:03 +05301736 private void addBitsetImport(List<String> imports) {
1737 imports.add(getJavaImportData().getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301738 }
1739
1740 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301741 * Adds imports for ToString and HashCodeMethod.
1742 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301743 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301744 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301745 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301746 void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301747 if (operation) {
1748 imports.add(getJavaImportData().getImportForHashAndEquals());
1749 imports.add(getJavaImportData().getImportForToString());
1750 } else {
1751 imports.remove(getJavaImportData().getImportForHashAndEquals());
1752 imports.remove(getJavaImportData().getImportForToString());
1753 }
1754 }
1755
1756 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301757 * Adds import for map and hash map.
1758 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301759 * @param imports import list
1760 * @param operations true for adding and false for deletion
1761 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301762 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301763 */
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301764 private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301765 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301766 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301767 if (!isInterfaceFile) {
1768 imports.add(getJavaImportData().getHashMapImport());
1769 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301770 // Add import for hash map only if node is not a YANG choice.
1771 if (!(curNode instanceof YangChoice)) {
1772 imports.add(getJavaImportData().getMapImport());
1773 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301774 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301775 if (!isInterfaceFile) {
1776 imports.remove(getJavaImportData().getHashMapImport());
1777 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301778 imports.remove(getJavaImportData().getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301779 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301780 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301781 }
1782
1783 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301784 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301785 *
1786 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301787 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301788 private void addInvocationExceptionImport(List<String> imports) {
1789 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301790 }
1791
1792 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301793 * Removes all temporary file handles.
1794 *
Bharat saraswal64e7e232016-07-14 23:33:55 +05301795 * @param isErrorOccurred flag to tell translator that error has occurred while file generation
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301796 * @throws IOException when failed to delete the temporary files
1797 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301798 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301799 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301800 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301801 * Close all java file handles and when error occurs delete the files.
1802 */
1803 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301804 closeFile(getInterfaceJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301805 }
1806 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301807 closeFile(getBuilderClassJavaFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301808 }
1809 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1810 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1811 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301812 if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
Bharat saraswal64e7e232016-07-14 23:33:55 +05301813 closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301814 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301815 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301816 * Close all temporary file handles and delete the files.
1817 */
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301818 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1819 closeFile(getGetterImplTempFileHandle(), true);
1820 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301821 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1822 closeFile(getAttributesTempFileHandle(), true);
1823 }
1824 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1825 closeFile(getHashCodeImplTempFileHandle(), true);
1826 }
1827 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1828 closeFile(getToStringImplTempFileHandle(), true);
1829 }
1830 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1831 closeFile(getEqualsImplTempFileHandle(), true);
1832 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301833 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1834 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301835 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301836 if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
1837 closeFile(getAddToListImplTempFileHandle(), true);
1838 }
1839 if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
1840 closeFile(getAddToListInterfaceTempFileHandle(), true);
1841 }
1842 if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
1843 closeFile(getLeafIdAttributeTempFileHandle(), true);
1844 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301845 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301846 closeFile(getSubtreeFilteringForLeafTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301847 }
1848 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301849 closeFile(getGetSubtreeFilteringForListTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301850 }
1851 if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301852 closeFile(getGetSubtreeFilteringForChildNodeTempFileHandle(), true);
Bharat saraswale50edca2016-08-05 01:58:25 +05301853 }
1854 if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
1855 closeFile(getEditContentTempFileHandle(), true);
1856 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301857 }
1858
1859 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301860 * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
1861 * same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301862 *
1863 * @param importInfo import info for the current attribute being added
1864 * @return status of the qualified access to the attribute
1865 */
Bharat saraswal64e7e232016-07-14 23:33:55 +05301866 boolean getIsQualifiedAccessOrAddToImportList(
Bharat saraswal2da23bf2016-08-25 15:28:39 +05301867 JavaQualifiedTypeInfo importInfo) {
1868 return getJavaImportData().addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
1869 getGeneratedJavaClassName(),
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301870 getJavaFileInfo().getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301871 }
1872
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301873 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301874 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301875 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301876 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301877 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301878 public File getAddToListInterfaceTempFileHandle() {
1879 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301880 }
1881
1882 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301883 * Sets temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301884 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301885 * @param addToListInterfaceTempFileHandle temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301886 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301887 private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
1888 this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
1889 }
1890
1891 /**
1892 * Returns temp file handle for add to list impl.
1893 *
1894 * @return temp file handle for add to list impl
1895 */
1896 public File getAddToListImplTempFileHandle() {
1897 return addToListImplTempFileHandle;
1898 }
1899
1900 /**
1901 * Sets temp file handle for add to list impl.
1902 *
1903 * @param addToListImplTempFileHandle temp file handle for add to list impl
1904 */
1905 private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
1906 this.addToListImplTempFileHandle = addToListImplTempFileHandle;
1907 }
1908
1909 /**
1910 * Returns temp file handle for leaf identifier attributes.
1911 *
1912 * @return temp file handle for leaf identifier attributes
1913 */
1914 public File getLeafIdAttributeTempFileHandle() {
1915 return leafIdAttributeTempFileHandle;
1916 }
1917
1918 /**
1919 * Sets temp file handle for leaf identifier attributes.
1920 *
Bharat saraswale50edca2016-08-05 01:58:25 +05301921 * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes
Bharat saraswal8beac342016-08-04 02:00:03 +05301922 */
1923 private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
1924 this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
1925 }
1926
1927 /**
1928 * Returns if root node is set.
1929 *
1930 * @return true if root node
1931 */
1932 private boolean isRooNode() {
1933 return isRooNode;
1934 }
1935
1936 /**
1937 * Sets true if root node.
1938 *
1939 * @param rooNode true if root node
1940 */
Bharat saraswale50edca2016-08-05 01:58:25 +05301941 void setRooNode(boolean rooNode) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301942 isRooNode = rooNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301943 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301944
1945 /**
1946 * Returns temp file for is content match.
1947 *
1948 * @return temp file for is content match
1949 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301950 public File getSubtreeFilteringForLeafTempFileHandle() {
1951 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301952 }
1953
1954 /**
1955 * Sets temp file handle for is content match.
1956 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301957 * @param subtreeFilteringForLeafTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301958 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301959 private void setSubtreeFilteringForLeafTempFileHandle(File subtreeFilteringForLeafTempFileHandle) {
1960 this.subtreeFilteringForLeafTempFileHandle = subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301961 }
1962
1963 /**
1964 * Returns temp file for edit content file.
1965 *
1966 * @return temp file for edit content file
1967 */
1968 public File getEditContentTempFileHandle() {
1969 return editContentTempFileHandle;
1970 }
1971
1972 /**
1973 * Sets temp file for edit content file.
1974 *
1975 * @param editContentTempFileHandle temp file for edit content file
1976 */
1977 private void setEditContentTempFileHandle(File editContentTempFileHandle) {
1978 this.editContentTempFileHandle = editContentTempFileHandle;
1979 }
1980
1981 /**
1982 * Returns temp file for is content match.
1983 *
1984 * @return temp file for is content match
1985 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301986 public File getGetSubtreeFilteringForListTempFileHandle() {
1987 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301988 }
1989
1990 /**
1991 * Sets temp file handle for is content match.
1992 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301993 * @param getSubtreeFilteringForListTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05301994 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301995 private void setGetSubtreeFilteringForListTempFileHandle(File getSubtreeFilteringForListTempFileHandle) {
1996 this.getSubtreeFilteringForListTempFileHandle = getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301997 }
1998
1999 /**
2000 * Returns temp file for is content match.
2001 *
2002 * @return temp file for is content match
2003 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302004 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
2005 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302006 }
2007
2008 /**
2009 * Sets temp file handle for is content match.
2010 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302011 * @param getSubtreeFilteringForChildNodeTempFileHandle temp file handle for is content match
Bharat saraswale50edca2016-08-05 01:58:25 +05302012 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05302013 private void setGetSubtreeFilteringForChildNodeTempFileHandle(File getSubtreeFilteringForChildNodeTempFileHandle) {
2014 this.getSubtreeFilteringForChildNodeTempFileHandle = getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05302015 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05302016}