blob: cc52daa0f8c5ff7830ae0fc3abb1cfa5ff4bd252 [file] [log] [blame]
Vinod Kumar S38046502016-03-23 15:30:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar S38046502016-03-23 15:30:27 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.translator.tojava;
18
19import java.io.File;
20import java.io.IOException;
Bharat saraswale2d51d62016-03-23 19:40:35 +053021import java.util.ArrayList;
Vinod Kumar S38046502016-03-23 15:30:27 +053022import java.util.List;
Bharat saraswald72411a2016-04-19 01:00:16 +053023import java.util.Set;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053024import org.onosproject.yangutils.datamodel.HasType;
Bharat saraswald72411a2016-04-19 01:00:16 +053025import org.onosproject.yangutils.datamodel.YangEnum;
26import org.onosproject.yangutils.datamodel.YangEnumeration;
Vinod Kumar S38046502016-03-23 15:30:27 +053027import org.onosproject.yangutils.datamodel.YangLeaf;
28import org.onosproject.yangutils.datamodel.YangLeafList;
29import org.onosproject.yangutils.datamodel.YangLeavesHolder;
30import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053031import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053032import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053033
Bharat saraswald72411a2016-04-19 01:00:16 +053034import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
Vinod Kumar S38046502016-03-23 15:30:27 +053035import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
36import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053037import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Gaurav Agrawal56527662016-04-20 15:49:17 +053038import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
Bharat saraswale2d51d62016-03-23 19:40:35 +053039import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053040import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
Vinod Kumar S38046502016-03-23 15:30:27 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
42import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
43import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053049import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
50import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
51import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053052import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053054import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
55import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
56import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053057import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute;
Vinod Kumar S38046502016-03-23 15:30:27 +053058import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053059import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType;
Vinod Kumar S38046502016-03-23 15:30:27 +053060import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053061import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo;
Bharat saraswald72411a2016-04-19 01:00:16 +053062import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
Vinod Kumar S38046502016-03-23 15:30:27 +053063import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053064import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
Bharat saraswale2d51d62016-03-23 19:40:35 +053065import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
66import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswald72411a2016-04-19 01:00:16 +053067import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053068import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
69import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Gaurav Agrawal56527662016-04-20 15:49:17 +053070import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateRpcInterfaceFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053072import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
75import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
76import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
Vinod Kumar S38046502016-03-23 15:30:27 +053077import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053078import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
Vinod Kumar S38046502016-03-23 15:30:27 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
80import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
82import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S38046502016-03-23 15:30:27 +053084import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
85import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
86import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Bharat saraswale2d51d62016-03-23 19:40:35 +053087import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053088import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
Vinod Kumar S38046502016-03-23 15:30:27 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Gaurav Agrawal56527662016-04-20 15:49:17 +053090import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcStringMethod;
Vinod Kumar S38046502016-03-23 15:30:27 +053091import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
92import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
93import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053094import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
Vinod Kumar S38046502016-03-23 15:30:27 +053095import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053096import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
97import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
98import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
99import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addImportsToStringAndHasCodeMethods;
100import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
101import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
102import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
103import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530104import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
105import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
106import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
107import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
108import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
109import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Bharat saraswald72411a2016-04-19 01:00:16 +0530110import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530111import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
112import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
113import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530114import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530115import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530116import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530117import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
118import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530119import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
120import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
121import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Vinod Kumar S38046502016-03-23 15:30:27 +0530122
123/**
Bharat saraswald9822e92016-04-05 15:13:44 +0530124 * Represents implementation of java code fragments temporary implementations.
Vinod Kumar S38046502016-03-23 15:30:27 +0530125 */
126public class TempJavaCodeFragmentFiles {
127
128 /**
129 * The variable which guides the types of temporary files generated using
130 * the temporary generated file types mask.
131 */
132 private int generatedTempFiles;
133
134 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530135 * The variable which guides the types of files generated using
136 * the generated file types mask.
137 */
138 private int generatedJavaFiles;
139
140 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530141 * Absolute path where the target java file needs to be generated.
142 */
143 private String absoluteDirPath;
144
145 /**
146 * Name of java file that needs to be generated.
147 */
148 private String generatedJavaClassName;
149
150 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530151 * Contains all the class name which will be extended by generated files.
152 */
153 private List<String> extendsList = new ArrayList<>();
154
155 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530156 * File type extension for java classes.
157 */
158 private static final String JAVA_FILE_EXTENSION = ".java";
159
160 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530161 * File type extension for temporary classes.
162 */
163 private static final String TEMP_FILE_EXTENSION = ".tmp";
164
165 /**
166 * Folder suffix for temporary files folder.
167 */
168 private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
169
170 /**
171 * File name for getter method.
172 */
173 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
174
175 /**
176 * File name for getter method implementation.
177 */
178 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
179
180 /**
181 * File name for setter method.
182 */
183 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
184
185 /**
186 * File name for setter method implementation.
187 */
188 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
189
190 /**
191 * File name for constructor.
192 */
193 private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
194
195 /**
196 * File name for attributes.
197 */
198 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
199
200 /**
201 * File name for to string method.
202 */
203 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
204
205 /**
206 * File name for hash code method.
207 */
208 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
209
210 /**
211 * File name for equals method.
212 */
213 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
214
215 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530216 * File name for of string method.
217 */
218 private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
219
220 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530221 * File name for temporary enum class.
222 */
223 private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
224
225 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530226 * File name for construction for special type like union, typedef.
227 */
228 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
229
230 /**
231 * File name for from string method.
232 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530233 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530234
235 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530236 * File name for interface java file name suffix.
237 */
238 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
239
240 /**
241 * File name for builder interface file name suffix.
242 */
243 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
244
245 /**
246 * File name for builder class file name suffix.
247 */
248 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
249
250 /**
251 * File name for impl class file name suffix.
252 */
253 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
254
255 /**
256 * File name for typedef class file name suffix.
257 */
258 private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
259
260 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530261 * File name for enum class file name suffix.
262 */
263 private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
264
265 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530266 * File name for rpc method.
267 */
268 private static final String RPC_FILE_NAME = "Rpc";
269
270 /**
271 * File name for generated class file for special type like union, typedef suffix.
272 */
273 private static final String RPC_INTERFACE_FILE_NAME_SUFFIX = "Service";
274
275 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530276 * File name for generated class file for special type like union, typedef suffix.
277 */
278 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
279
280 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530281 * Java file handle for interface file.
282 */
283 private File interfaceJavaFileHandle;
284
285 /**
286 * Java file handle for builder interface file.
287 */
288 private File builderInterfaceJavaFileHandle;
289
290 /**
291 * Java file handle for builder class file.
292 */
293 private File builderClassJavaFileHandle;
294
295 /**
296 * Java file handle for impl class file.
297 */
298 private File implClassJavaFileHandle;
299
300 /**
301 * Java file handle for typedef class file.
302 */
303 private File typedefClassJavaFileHandle;
304
305 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530306 * Java file handle for type class like union, typedef file.
307 */
308 private File typeClassJavaFileHandle;
309
310 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530311 * Temporary file handle for attribute.
312 */
313 private File attributesTempFileHandle;
314
315 /**
316 * Temporary file handle for getter of interface.
317 */
318 private File getterInterfaceTempFileHandle;
319
320 /**
321 * Temporary file handle for getter of class.
322 */
323 private File getterImplTempFileHandle;
324
325 /**
326 * Temporary file handle for setter of interface.
327 */
328 private File setterInterfaceTempFileHandle;
329
330 /**
331 * Temporary file handle for setter of class.
332 */
333 private File setterImplTempFileHandle;
334
335 /**
336 * Temporary file handle for constructor of class.
337 */
338 private File constructorImplTempFileHandle;
339
340 /**
341 * Temporary file handle for hash code method of class.
342 */
343 private File hashCodeImplTempFileHandle;
344
345 /**
346 * Temporary file handle for equals method of class.
347 */
348 private File equalsImplTempFileHandle;
349
350 /**
351 * Temporary file handle for to string method of class.
352 */
353 private File toStringImplTempFileHandle;
354
355 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530356 * Temporary file handle for enum class file.
357 */
358 private File enumClassTempFileHandle;
359
360 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530361 * Temporary file handle for of string method of class.
362 */
363 private File ofStringImplTempFileHandle;
364
365 /**
366 * Temporary file handle for constructor for type class.
367 */
368 private File constructorForTypeTempFileHandle;
369
370 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530371 * Temporary file handle for from string method of class.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530372 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530373 private File fromStringImplTempFileHandle;
374
375 /**
376 * Temporary file handle for rpc interface.
377 */
378 private File rpcInterfaceImplTempFileHandle;
379
380 /**
381 * Java file handle for rpc interface file.
382 */
383 private File rpcInterfaceJavaFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530384
385 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530386 * Java attribute info.
387 */
388 private JavaAttributeInfo newAttrInfo;
389
390 /**
391 * Current YANG node.
392 */
393 private YangNode curYangNode;
394
395 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530396 * Current enum's value.
397 */
398 private int enumValue;
399
400 /**
Bharat saraswal2f11f652016-03-25 18:19:46 +0530401 * Is attribute added.
402 */
403 private boolean isAttributePresent = false;
404
Bharat saraswald72411a2016-04-19 01:00:16 +0530405 /*
406 * Java file handle for enum class.
407 */
408 private File enumClassJavaFileHandle;
409
Bharat saraswal2f11f652016-03-25 18:19:46 +0530410 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530411 * Creates an instance of temporary java code fragment.
Vinod Kumar S38046502016-03-23 15:30:27 +0530412 *
413 * @param genFileType file generation type
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530414 * @param genDir file generation directory
415 * @param className class name
Vinod Kumar S38046502016-03-23 15:30:27 +0530416 * @throws IOException when fails to create new file handle
417 */
Bharat saraswale2d51d62016-03-23 19:40:35 +0530418 public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className)
419 throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +0530420
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530421 setExtendsList(new ArrayList<>());
Vinod Kumar S38046502016-03-23 15:30:27 +0530422 generatedTempFiles = 0;
423 absoluteDirPath = genDir;
424 generatedJavaClassName = className;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530425 generatedJavaFiles = genFileType;
Vinod Kumar S38046502016-03-23 15:30:27 +0530426 /**
427 * Initialize getter when generation file type matches to interface
428 * mask.
429 */
430 if ((genFileType & INTERFACE_MASK) != 0) {
431 generatedTempFiles |= GETTER_FOR_INTERFACE_MASK;
432 }
433
434 /**
435 * Initialize getter and setter when generation file type matches to
436 * builder interface mask.
437 */
438 if ((genFileType & BUILDER_INTERFACE_MASK) != 0) {
439 generatedTempFiles |= GETTER_FOR_INTERFACE_MASK;
440 generatedTempFiles |= SETTER_FOR_INTERFACE_MASK;
441 }
442
443 /**
444 * Initialize getterImpl, setterImpl and attributes when generation file
445 * type matches to builder class mask.
446 */
447 if ((genFileType & BUILDER_CLASS_MASK) != 0) {
448 generatedTempFiles |= ATTRIBUTES_MASK;
449 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
450 generatedTempFiles |= SETTER_FOR_CLASS_MASK;
451 }
452
453 /**
454 * Initialize getterImpl, attributes, constructor, hash code, equals and
455 * to strings when generation file type matches to impl class mask.
456 */
457 if ((genFileType & IMPL_CLASS_MASK) != 0) {
458 generatedTempFiles |= ATTRIBUTES_MASK;
459 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
460 generatedTempFiles |= CONSTRUCTOR_IMPL_MASK;
461 generatedTempFiles |= HASH_CODE_IMPL_MASK;
462 generatedTempFiles |= EQUALS_IMPL_MASK;
463 generatedTempFiles |= TO_STRING_IMPL_MASK;
464 }
465
Gaurav Agrawal56527662016-04-20 15:49:17 +0530466 if ((genFileType & GENERATE_RPC_INTERFACE) != 0) {
467 generatedTempFiles |= RPC_IMPL_MASK;
468 }
469
Bharat saraswale2d51d62016-03-23 19:40:35 +0530470 /**
471 * Initialize getterImpl, attributes, hash code, equals and
472 * to strings when generation file type matches to typeDef class mask.
473 */
474 if ((genFileType & GENERATE_TYPEDEF_CLASS) != 0) {
475 generatedTempFiles |= ATTRIBUTES_MASK;
476 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
477 generatedTempFiles |= HASH_CODE_IMPL_MASK;
478 generatedTempFiles |= EQUALS_IMPL_MASK;
479 generatedTempFiles |= TO_STRING_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530480 generatedTempFiles |= OF_STRING_IMPL_MASK;
481 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530482 generatedTempFiles |= FROM_STRING_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530483 }
484
485 /**
486 * Initialize getterImpl, attributes, hash code, equals, of string,
Gaurav Agrawal56527662016-04-20 15:49:17 +0530487 * constructor, union's to string, from string when generation
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530488 * file type matches to union class mask.
489 */
490 if ((genFileType & GENERATE_UNION_CLASS) != 0) {
491 generatedTempFiles |= ATTRIBUTES_MASK;
492 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
493 generatedTempFiles |= HASH_CODE_IMPL_MASK;
494 generatedTempFiles |= EQUALS_IMPL_MASK;
495 generatedTempFiles |= OF_STRING_IMPL_MASK;
496 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
497 generatedTempFiles |= TO_STRING_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530498 generatedTempFiles |= FROM_STRING_IMPL_MASK;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530499 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530500 /**
501 * Initialize enum when generation file type matches to enum class mask.
502 */
503 if ((genFileType & GENERATE_ENUM_CLASS) != 0) {
504 generatedTempFiles |= ENUM_IMPL_MASK;
505 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530506
Bharat saraswald72411a2016-04-19 01:00:16 +0530507 /**
508 * Set temporary file handles.
509 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530510 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
511 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
512 }
513
514 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
515 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
516 }
517
518 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
519 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
520 }
521
522 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
523 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
524 }
525
526 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
527 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
528 }
529
530 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
531 setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
532 }
533
534 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
535 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
536 }
537
538 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
539 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
540 }
541 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
542 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
543 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530544 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
545 setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
546 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530547 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
548 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
549 }
550
551 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
552 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
553 }
554
Gaurav Agrawal56527662016-04-20 15:49:17 +0530555 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
556 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
557 }
558
559 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
560 setRpcInterfaceImplTempFileHandle(getTemporaryFileHandle(RPC_FILE_NAME));
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530561 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530562 }
563
564 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530565 * Returns java file handle for interface file.
566 *
567 * @return java file handle for interface file
568 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530569 private File getInterfaceJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530570 return interfaceJavaFileHandle;
571 }
572
573 /**
574 * Sets the java file handle for interface file.
575 *
576 * @param interfaceJavaFileHandle java file handle
577 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530578 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530579 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
580 }
581
582 /**
583 * Returns java file handle for builder interface file.
584 *
585 * @return java file handle for builder interface file
586 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530587 private File getBuilderInterfaceJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530588 return builderInterfaceJavaFileHandle;
589 }
590
591 /**
592 * Sets the java file handle for builder interface file.
593 *
594 * @param builderInterfaceJavaFileHandle java file handle
595 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530596 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530597 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
598 }
599
600 /**
601 * Returns java file handle for builder class file.
602 *
603 * @return java file handle for builder class file
604 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530605 private File getBuilderClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530606 return builderClassJavaFileHandle;
607 }
608
609 /**
610 * Sets the java file handle for builder class file.
611 *
612 * @param builderClassJavaFileHandle java file handle
613 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530614 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530615 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
616 }
617
618 /**
619 * Returns java file handle for impl class file.
620 *
621 * @return java file handle for impl class file
622 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530623 private File getImplClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530624 return implClassJavaFileHandle;
625 }
626
627 /**
628 * Sets the java file handle for impl class file.
629 *
630 * @param implClassJavaFileHandle java file handle
631 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530632 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530633 this.implClassJavaFileHandle = implClassJavaFileHandle;
634 }
635
636 /**
637 * Returns java file handle for typedef class file.
638 *
639 * @return java file handle for typedef class file
640 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530641 private File getTypedefClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530642 return typedefClassJavaFileHandle;
643 }
644
645 /**
646 * Sets the java file handle for typedef class file.
647 *
648 * @param typedefClassJavaFileHandle java file handle
649 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530650 private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530651 this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
652 }
653
654 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530655 * Returns enum class java file handle.
656 *
657 * @return enum class java file handle
658 */
659 private File getEnumClassJavaFileHandle() {
660 return enumClassJavaFileHandle;
661 }
662
663 /**
664 * Sets enum class java file handle.
665 *
666 * @param enumClassJavaFileHandle enum class java file handle
667 */
668
669 private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
670 this.enumClassJavaFileHandle = enumClassJavaFileHandle;
671 }
672
673 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530674 * Returns java file handle for type class file.
675 *
676 * @return java file handle for type class file
677 */
678 private File getTypeClassJavaFileHandle() {
679 return typeClassJavaFileHandle;
680 }
681
682 /**
683 * Sets the java file handle for type class file.
684 *
685 * @param typeClassJavaFileHandle type file handle
686 */
687 private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
688 this.typeClassJavaFileHandle = typeClassJavaFileHandle;
689 }
690
691 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530692 * Returns attribute's temporary file handle.
693 *
694 * @return temporary file handle
695 */
696 public File getAttributesTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530697 return attributesTempFileHandle;
698 }
699
700 /**
701 * Sets attribute's temporary file handle.
702 *
703 * @param attributeForClass file handle for attribute
704 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530705 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530706 attributesTempFileHandle = attributeForClass;
707 }
708
709 /**
710 * Returns getter methods's temporary file handle.
711 *
712 * @return temporary file handle
713 */
714 public File getGetterInterfaceTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530715 return getterInterfaceTempFileHandle;
716 }
717
718 /**
719 * Sets to getter method's temporary file handle.
720 *
721 * @param getterForInterface file handle for to getter method
722 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530723 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530724 getterInterfaceTempFileHandle = getterForInterface;
725 }
726
727 /**
728 * Returns getter method's impl's temporary file handle.
729 *
730 * @return temporary file handle
731 */
732 public File getGetterImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530733 return getterImplTempFileHandle;
734 }
735
736 /**
737 * Sets to getter method's impl's temporary file handle.
738 *
739 * @param getterImpl file handle for to getter method's impl
740 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530741 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530742 getterImplTempFileHandle = getterImpl;
743 }
744
745 /**
746 * Returns setter method's temporary file handle.
747 *
748 * @return temporary file handle
749 */
750 public File getSetterInterfaceTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530751 return setterInterfaceTempFileHandle;
752 }
753
754 /**
755 * Sets to setter method's temporary file handle.
756 *
757 * @param setterForInterface file handle for to setter method
758 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530759 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530760 setterInterfaceTempFileHandle = setterForInterface;
761 }
762
763 /**
764 * Returns setter method's impl's temporary file handle.
765 *
766 * @return temporary file handle
767 */
768 public File getSetterImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530769 return setterImplTempFileHandle;
770 }
771
772 /**
773 * Sets to setter method's impl's temporary file handle.
774 *
775 * @param setterImpl file handle for to setter method's implementation class
776 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530777 private void setSetterImplTempFileHandle(File setterImpl) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530778 setterImplTempFileHandle = setterImpl;
779 }
780
781 /**
782 * Returns constructor's temporary file handle.
783 *
784 * @return temporary file handle
785 */
786 public File getConstructorImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530787 return constructorImplTempFileHandle;
788 }
789
790 /**
791 * Sets to constructor's temporary file handle.
792 *
793 * @param constructor file handle for to constructor
794 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530795 private void setConstructorImplTempFileHandle(File constructor) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530796 constructorImplTempFileHandle = constructor;
797 }
798
799 /**
800 * Returns hash code method's temporary file handle.
801 *
802 * @return temporary file handle
803 */
804 public File getHashCodeImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530805 return hashCodeImplTempFileHandle;
806 }
807
808 /**
809 * Sets hash code method's temporary file handle.
810 *
811 * @param hashCodeMethod file handle for hash code method
812 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530813 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530814 hashCodeImplTempFileHandle = hashCodeMethod;
815 }
816
817 /**
818 * Returns equals mehtod's temporary file handle.
819 *
820 * @return temporary file handle
821 */
822 public File getEqualsImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530823 return equalsImplTempFileHandle;
824 }
825
826 /**
827 * Sets equals method's temporary file handle.
828 *
829 * @param equalsMethod file handle for to equals method
830 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530831 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530832 equalsImplTempFileHandle = equalsMethod;
833 }
834
835 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530836 * Returns rpc method's temporary file handle.
837 *
838 * @return temporary file handle
839 */
840 public File getRpcInterfaceImplTempFileHandle() {
841 return rpcInterfaceImplTempFileHandle;
842 }
843
844 /**
845 * Sets rpc method's temporary file handle.
846 *
847 * @param rpcInterfaceImplTempFileHandle file handle for to rpc method
848 */
849 public void setRpcInterfaceImplTempFileHandle(File rpcInterfaceImplTempFileHandle) {
850 this.rpcInterfaceImplTempFileHandle = rpcInterfaceImplTempFileHandle;
851 }
852
853 /**
854 * Returns rpc method's java file handle.
855 *
856 * @return java file handle
857 */
858 public File getRpcInterfaceJavaFileHandle() {
859 return rpcInterfaceJavaFileHandle;
860 }
861
862 /**
863 * Sets rpc method's java file handle.
864 *
865 * @param rpcInterfaceJavaFileHandle file handle for to rpc method
866 */
867 public void setRpcInterfaceJavaFileHandle(File rpcInterfaceJavaFileHandle) {
868 this.rpcInterfaceJavaFileHandle = rpcInterfaceJavaFileHandle;
869 }
870
871 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530872 * Returns to string method's temporary file handle.
873 *
874 * @return temporary file handle
875 */
876 public File getToStringImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530877 return toStringImplTempFileHandle;
878 }
879
880 /**
881 * Sets to string method's temporary file handle.
882 *
883 * @param toStringMethod file handle for to string method
884 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530885 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530886 toStringImplTempFileHandle = toStringMethod;
887 }
888
889 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530890 * Returns temporary file handle for enum class file.
891 *
892 * @return temporary file handle for enum class file
893 */
894 public File getEnumClassTempFileHandle() {
895 return enumClassTempFileHandle;
896 }
897
898 /**
899 * Sets temporary file handle for enum class file.
900 *
901 * @param enumClassTempFileHandle temporary file handle for enum class file
902 */
903
904 private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
905 this.enumClassTempFileHandle = enumClassTempFileHandle;
906 }
907
908 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530909 * Returns of string method's temporary file handle.
910 *
911 * @return of string method's temporary file handle
912 */
913 public File getOfStringImplTempFileHandle() {
914 return ofStringImplTempFileHandle;
915 }
916
917 /**
918 * Set of string method's temporary file handle.
919 *
920 * @param ofStringImplTempFileHandle of string method's temporary file handle
921 */
922 private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) {
923 this.ofStringImplTempFileHandle = ofStringImplTempFileHandle;
924 }
925
926 /**
927 * Returns type class constructor method's temporary file handle.
928 *
929 * @return type class constructor method's temporary file handle
930 */
931 public File getConstructorForTypeTempFileHandle() {
932 return constructorForTypeTempFileHandle;
933 }
934
935 /**
936 * Sets type class constructor method's temporary file handle.
937 *
938 * @param constructorForTypeTempFileHandle type class constructor method's temporary file handle
939 */
940 private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) {
941 this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle;
942 }
943
944 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530945 * Returns from string method's temporary file handle.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530946 *
Gaurav Agrawal56527662016-04-20 15:49:17 +0530947 * @return from string method's temporary file handle
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530948 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530949 public File getFromStringImplTempFileHandle() {
950 return fromStringImplTempFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530951 }
952
953 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530954 * Sets from string method's temporary file handle.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530955 *
Gaurav Agrawal56527662016-04-20 15:49:17 +0530956 * @param fromStringImplTempFileHandle from string method's temporary file handle
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530957 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530958 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
959 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530960 }
961
962 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530963 * Returns java attribute info.
964 *
965 * @return java attribute info
966 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530967 private JavaAttributeInfo getNewAttrInfo() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530968 return newAttrInfo;
969 }
970
971 /**
972 * Sets java attribute info.
973 *
974 * @param newAttrInfo java attribute info
975 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530976 private void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530977
Bharat saraswal2f11f652016-03-25 18:19:46 +0530978 if (newAttrInfo != null) {
979 isAttributePresent = true;
980 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530981 this.newAttrInfo = newAttrInfo;
982 }
983
984 /**
985 * Returns current YANG node.
986 *
987 * @return current YANG node
988 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530989 private YangNode getCurYangNode() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530990 return curYangNode;
991 }
992
993 /**
994 * Sets current YANG node.
995 *
996 * @param curYangNode YANG node
997 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530998 private void setCurYangNode(YangNode curYangNode) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530999 this.curYangNode = curYangNode;
1000 }
1001
1002 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301003 * Returns enum's value.
1004 *
1005 * @return enum's value
1006 */
1007 public int getEnumValue() {
1008 return enumValue;
1009 }
1010
1011 /**
1012 * Sets enum's value.
1013 *
1014 * @param enumValue enum's value
1015 */
1016 public void setEnumValue(int enumValue) {
1017 this.enumValue = enumValue;
1018 }
1019
1020 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301021 * Returns list of classes to be extended by generated files.
1022 *
1023 * @return list of classes to be extended by generated files
1024 */
1025 private List<String> getExtendsList() {
1026 return extendsList;
1027 }
1028
1029 /**
1030 * Sets class to be extended by generated file.
1031 *
1032 * @param extendsList list of classes to be extended
1033 */
1034
1035 private void setExtendsList(List<String> extendsList) {
1036 this.extendsList = extendsList;
1037 }
1038
1039 /**
1040 * Adds class to the extends list.
1041 *
1042 * @param extend class to be extended
1043 */
1044 public void addToExtendsList(String extend) {
1045 getExtendsList().add(extend);
1046 }
1047
1048 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301049 * Adds of string for type.
1050 *
1051 * @param attr attribute info
1052 * @throws IOException when fails to append to temporary file
1053 */
1054 private void addOfStringMethod(JavaAttributeInfo attr) throws IOException {
1055 appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, generatedJavaClassName)
1056 + NEW_LINE);
1057 }
1058
1059 /**
1060 * Adds type constructor.
1061 *
1062 * @param attr attribute info
1063 * @throws IOException when fails to append to temporary file
1064 */
1065 private void addTypeConstructor(JavaAttributeInfo attr) throws IOException {
1066 appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
1067 generatedJavaClassName) + NEW_LINE);
1068 }
1069
1070 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301071 * Adds attribute for class.
1072 *
1073 * @param attr attribute info
1074 * @throws IOException when fails to append to temporary file
1075 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301076 private void addAttribute(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301077 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION);
Vinod Kumar S38046502016-03-23 15:30:27 +05301078 }
1079
1080 /**
1081 * Adds getter for interface.
1082 *
1083 * @param attr attribute info
1084 * @throws IOException when fails to append to temporary file
1085 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301086 private void addGetterForInterface(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301087 appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301088 }
1089
1090 /**
1091 * Adds getter method's impl for class.
1092 *
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301093 * @param attr attribute info
Bharat saraswale2d51d62016-03-23 19:40:35 +05301094 * @param genFiletype generated file type
Vinod Kumar S38046502016-03-23 15:30:27 +05301095 * @throws IOException when fails to append to temporary file
1096 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301097 private void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301098
Bharat saraswale2d51d62016-03-23 19:40:35 +05301099 if ((genFiletype & BUILDER_CLASS_MASK) != 0) {
1100 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE);
1101 } else {
1102 appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false)
1103 + getGetterForClass(attr) + NEW_LINE);
1104 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301105 }
1106
1107 /**
1108 * Adds setter for interface.
1109 *
1110 * @param attr attribute info
1111 * @throws IOException when fails to append to temporary file
1112 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301113 private void addSetterForInterface(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301114 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswale2d51d62016-03-23 19:40:35 +05301115 getSetterString(attr, generatedJavaClassName) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301116 }
1117
1118 /**
1119 * Adds setter's implementation for class.
1120 *
1121 * @param attr attribute info
1122 * @throws IOException when fails to append to temporary file
1123 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301124 private void addSetterImpl(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301125 appendToFile(getSetterImplTempFileHandle(),
Bharat saraswale2d51d62016-03-23 19:40:35 +05301126 getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301127 }
1128
1129 /**
1130 * Adds build method for interface.
1131 *
1132 * @return build method for interface
1133 * @throws IOException when fails to append to temporary file
1134 */
1135 public String addBuildMethodForInterface() throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301136 return parseBuilderInterfaceBuildMethodString(generatedJavaClassName);
1137 }
1138
1139 /**
1140 * Adds build method's implementation for class.
1141 *
1142 * @return build method implementation for class
1143 * @throws IOException when fails to append to temporary file
1144 */
1145 public String addBuildMethodImpl() throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301146 return getBuildString(generatedJavaClassName) + NEW_LINE;
Vinod Kumar S38046502016-03-23 15:30:27 +05301147 }
1148
1149 /**
1150 * Adds constructor for class.
1151 *
1152 * @param attr attribute info
1153 * @throws IOException when fails to append to temporary file
1154 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301155 private void addConstructor(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301156 appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr));
1157 }
1158
1159 /**
1160 * Adds default constructor for class.
1161 *
Bharat saraswale2d51d62016-03-23 19:40:35 +05301162 * @param modifier modifier for constructor.
1163 * @param toAppend string which need to be appended with the class name
Vinod Kumar S38046502016-03-23 15:30:27 +05301164 * @return default constructor for class
1165 * @throws IOException when fails to append to file
1166 */
Bharat saraswale2d51d62016-03-23 19:40:35 +05301167 public String addDefaultConstructor(String modifier, String toAppend) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301168 return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier);
1169 }
1170
1171 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301172 * Adds default constructor for class.
1173 *
1174 * @return default constructor for class
1175 * @throws IOException when fails to append to file
1176 */
1177 public String addOfMethod() throws IOException {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301178 return getJavaDoc(OF_METHOD, generatedJavaClassName, false)
Bharat saraswale2d51d62016-03-23 19:40:35 +05301179 + getOfMethod(generatedJavaClassName, newAttrInfo);
Vinod Kumar S38046502016-03-23 15:30:27 +05301180 }
1181
1182 /**
1183 * Adds hash code method for class.
1184 *
1185 * @param attr attribute info
1186 * @throws IOException when fails to append to temporary file
1187 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301188 private void addHashCodeMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301189 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301190 }
1191
1192 /**
1193 * Adds equals method for class.
1194 *
1195 * @param attr attribute info
1196 * @throws IOException when fails to append to temporary file
1197 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301198 private void addEqualsMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301199 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301200 }
1201
1202 /**
1203 * Adds ToString method for class.
1204 *
1205 * @param attr attribute info
1206 * @throws IOException when fails to append to temporary file
1207 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301208 private void addToStringMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301209 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301210 }
1211
1212 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301213 * Adds enum class attributes to temporary file.
1214 *
1215 * @param curEnum current YANG enum
1216 * @throws IOException when fails to do IO operations.
1217 */
1218 private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) throws IOException {
1219 appendToFile(getEnumClassTempFileHandle(),
1220 generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue()));
1221 }
1222
1223 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301224 * Add from string method for union class.
1225 *
1226 * @param javaAttributeInfo type attribute info
1227 * @param fromStringAttributeInfo from string attribute info
1228 * @throws IOException when fails to append to temporary file
1229 */
Gaurav Agrawal56527662016-04-20 15:49:17 +05301230 private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
1231 JavaAttributeInfo fromStringAttributeInfo) throws IOException {
1232 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301233 fromStringAttributeInfo) + NEW_LINE);
1234 }
1235
1236 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301237 * Adds rpc string information to applicable temp file.
1238 *
1239 * @param javaAttributeInfoOfInput rpc's input node attribute info
1240 * @param javaAttributeInfoOfOutput rpc's output node attribute info
1241 * @param rpcName name of the rpc function
1242 * @throws IOException IO operation fail
1243 */
1244 private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
1245 String rpcName) throws IOException {
1246 String rpcInput = "";
1247 String rpcOutput = "void";
1248 if (javaAttributeInfoOfInput != null) {
1249 rpcInput = javaAttributeInfoOfInput.getAttributeName();
1250 }
1251 if (javaAttributeInfoOfOutput != null) {
1252 rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
1253 }
1254 appendToFile(getRpcInterfaceImplTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
1255 getRpcStringMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
1256 }
1257
1258 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301259 * Returns a temporary file handle for the specific file type.
1260 *
1261 * @param fileName file name
1262 * @return temporary file handle
1263 * @throws IOException when fails to create new file handle
1264 */
1265 private File getTemporaryFileHandle(String fileName) throws IOException {
1266
1267 String path = getTempDirPath();
1268 File dir = new File(path);
1269 if (!dir.exists()) {
1270 dir.mkdirs();
1271 }
1272
1273 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1274 if (!file.exists()) {
1275 file.createNewFile();
Vinod Kumar S38046502016-03-23 15:30:27 +05301276 }
1277 return file;
1278 }
1279
1280 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301281 * Returns a temporary file handle for the specific file type.
1282 *
1283 * @param fileName file name
1284 * @return temporary file handle
1285 * @throws IOException when fails to create new file handle
1286 */
1287 private File getJavaFileHandle(String fileName) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301288 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1289 }
1290
1291 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301292 * Returns data from the temporary files.
1293 *
1294 * @param file temporary file handle
1295 * @return stored data from temporary files
1296 * @throws IOException when failed to get data from the given file
1297 */
1298 public String getTemporaryDataFromFileHandle(File file) throws IOException {
1299
1300 String path = getTempDirPath();
1301 if (new File(path + file.getName()).exists()) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301302 return readAppendFile(path + file.getName(), EMPTY_STRING);
Vinod Kumar S38046502016-03-23 15:30:27 +05301303 } else {
1304 throw new IOException("Unable to get data from the given "
Bharat saraswale2d51d62016-03-23 19:40:35 +05301305 + file.getName() + " file for " + generatedJavaClassName + PERIOD);
Vinod Kumar S38046502016-03-23 15:30:27 +05301306 }
1307 }
1308
1309 /**
1310 * Returns temporary directory path.
1311 *
1312 * @return directory path
1313 */
1314 private String getTempDirPath() {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301315 return getPackageDirPathFromJavaJPackage(absoluteDirPath) + SLASH + generatedJavaClassName
1316 + TEMP_FOLDER_NAME_SUFIX + SLASH;
Vinod Kumar S38046502016-03-23 15:30:27 +05301317 }
1318
1319 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301320 * Parses attribute to get the attribute string.
Vinod Kumar S38046502016-03-23 15:30:27 +05301321 *
1322 * @param attr attribute info
1323 * @return attribute string
1324 */
1325 private String parseAttribute(JavaAttributeInfo attr) {
1326
1327 /*
1328 * TODO: check if this utility needs to be called or move to the caller
1329 */
janani bde4ffab2016-04-15 16:18:30 +05301330 String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
Vinod Kumar S38046502016-03-23 15:30:27 +05301331 if (attr.isQualifiedName()) {
1332 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
1333 attributeName, attr.isListAttr());
1334 } else {
1335 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
1336 attr.isListAttr());
1337 }
1338 }
1339
1340 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301341 * Appends content to temporary file.
Vinod Kumar S38046502016-03-23 15:30:27 +05301342 *
1343 * @param file temporary file
1344 * @param data data to be appended
1345 * @throws IOException when fails to append to file
1346 */
1347 private void appendToFile(File file, String data) throws IOException {
1348
1349 try {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301350 insertDataIntoJavaFile(file, data);
Vinod Kumar S38046502016-03-23 15:30:27 +05301351 } catch (IOException ex) {
1352 throw new IOException("failed to write in temp file.");
1353 }
1354 }
1355
1356 /**
1357 * Adds current node info as and attribute to the parent generated file.
1358 *
1359 * @param curNode current node which needs to be added as an attribute in
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301360 * the parent generated code
1361 * @param isList is list construct
Vinod Kumar S38046502016-03-23 15:30:27 +05301362 * @throws IOException IO operation exception
1363 */
1364 public void addCurNodeInfoInParentTempFile(YangNode curNode,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301365 boolean isList) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301366
1367 YangNode parent = getParentNodeInGenCode(curNode);
1368 if (!(parent instanceof JavaCodeGenerator)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301369 throw new TranslatorException("missing parent node to contain current node info in generated file");
Vinod Kumar S38046502016-03-23 15:30:27 +05301370 }
1371 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode,
1372 parent, isList);
1373
1374 if (!(parent instanceof HasTempJavaCodeFragmentFiles)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301375 throw new TranslatorException("missing parent temp file handle");
Vinod Kumar S38046502016-03-23 15:30:27 +05301376 }
1377 ((HasTempJavaCodeFragmentFiles) parent)
1378 .getTempJavaCodeFragmentFiles()
1379 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1380 }
1381
1382 /**
1383 * Adds leaf attributes in generated files.
1384 *
1385 * @param listOfLeaves list of YANG leaf
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301386 * @param curNode current data model node
Vinod Kumar S38046502016-03-23 15:30:27 +05301387 * @throws IOException IO operation fail
1388 */
1389 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301390 YangNode curNode) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301391
1392 if (listOfLeaves != null) {
1393 for (YangLeaf leaf : listOfLeaves) {
1394 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf(curNode,
1395 leaf.getDataType(),
1396 leaf.getLeafName(), false);
1397 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1398 }
1399 }
1400 }
1401
1402 /**
1403 * Adds leaf list's attributes in generated files.
1404 *
1405 * @param listOfLeafList list of YANG leaves
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301406 * @param curNode cached file handle
Vinod Kumar S38046502016-03-23 15:30:27 +05301407 * @throws IOException IO operation fail
1408 */
1409 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301410 YangNode curNode) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301411
1412 if (listOfLeafList != null) {
1413
1414 /*
1415 * Check if the attribute is of type list, then the java.lang.list
1416 * needs to be imported.
1417 */
1418 if (listOfLeafList.size() != 0) {
1419 if (!(curNode instanceof HasJavaImportData)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301420 throw new TranslatorException("missing import info in current data model node");
Vinod Kumar S38046502016-03-23 15:30:27 +05301421
1422 }
1423 ((HasJavaImportData) curNode).getJavaImportData()
1424 .setIfListImported(true);
1425
1426 }
1427
1428 for (YangLeafList leafList : listOfLeafList) {
1429 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf(
1430 curNode, leafList.getDataType(), leafList.getLeafName(),
1431 true);
1432 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1433 }
1434 }
1435 }
1436
1437 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301438 * Adds all the leaves in the current data model node as part of the
Vinod Kumar S38046502016-03-23 15:30:27 +05301439 * generated temporary file.
1440 *
1441 * @param curNode java file info of the generated file
1442 * @throws IOException IO operation fail
1443 */
1444 public void addCurNodeLeavesInfoToTempFiles(YangNode curNode) throws IOException {
1445
1446 if (curNode instanceof YangLeavesHolder) {
1447 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1448 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), curNode);
1449 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), curNode);
1450 }
1451 }
1452
1453 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301454 * Add all the type in the current data model node as part of the
1455 * generated temporary file.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301456 *
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301457 * @param hasType YANG java data model node which has type info, eg union / typedef
Bharat saraswale2d51d62016-03-23 19:40:35 +05301458 * @throws IOException IO operation fail
1459 */
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301460 public void addTypeInfoToTempFiles(HasType hasType) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301461
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301462 List<YangType<?>> typeList = hasType.getTypeList();
1463 if (typeList != null) {
1464 for (YangType<?> yangType : typeList) {
1465 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfType((YangNode) hasType,
1466 yangType, getTypeName(yangType.getDataTypeName()), false);
1467 addJavaSnippetInfoToApplicableTempFiles((YangNode) hasType, javaAttributeInfo);
1468 }
1469 }
1470 }
1471
1472 private String getTypeName(String dataTypeName) {
1473 return dataTypeName;
1474 //TODO: implement the method.
1475 }
1476
1477 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301478 * Adds enum attributes to temporary files.
1479 *
1480 * @param curNode current YANG node
1481 * @throws IOException when fails to do IO operations
1482 */
1483 public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
1484
1485 if (curNode instanceof YangEnumeration) {
1486 Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet();
1487 for (YangEnum curEnum : enumSet) {
1488 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfEnumAttribute(curNode, curEnum.getNamedValue());
1489 setEnumValue(curEnum.getValue());
1490 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1491 }
1492 } else {
1493 throw new TranslatorException("curnode should be of type enum.");
1494 }
1495 }
1496
1497 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301498 * Adds the new attribute info to the target generated temporary files for union class.
1499 *
1500 * @param hasType the node for which the type is being added as an attribute
1501 * @param javaAttributeInfo the attribute info that needs to be added to temporary
1502 * files
1503 * @throws IOException IO operation fail
1504 */
1505 private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
1506 throws IOException {
1507
1508 JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo);
1509
Gaurav Agrawal56527662016-04-20 15:49:17 +05301510 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1511 addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301512 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301513 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1514 }
1515
1516 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301517 * Adds the JAVA rpc snippet information.
1518 *
1519 * @param javaAttributeInfoOfInput rpc's input node attribute info
1520 * @param javaAttributeInfoOfOutput rpc's output node attribute info
1521 * @param rpcName name of the rpc function
1522 * @throws IOException IO operation fail
1523 */
1524 public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
1525 JavaAttributeInfo javaAttributeInfoOfOutput,
1526 String rpcName) throws IOException {
1527 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1528 addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
1529 }
1530 }
1531
1532 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301533 * Adds the new attribute info to the target generated temporary files.
Vinod Kumar S38046502016-03-23 15:30:27 +05301534 *
1535 * @param newAttrInfo the attribute info that needs to be added to temporary
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301536 * files
Vinod Kumar S38046502016-03-23 15:30:27 +05301537 * @throws IOException IO operation fail
1538 */
1539 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
1540 throws IOException {
1541
Bharat saraswale2d51d62016-03-23 19:40:35 +05301542 setNewAttrInfo(newAttrInfo);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301543 if (isAttributePresent) {
1544 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
1545 addAttribute(newAttrInfo);
1546 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301547
Bharat saraswal2f11f652016-03-25 18:19:46 +05301548 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
1549 addGetterForInterface(newAttrInfo);
1550 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301551
Bharat saraswal2f11f652016-03-25 18:19:46 +05301552 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
1553 addSetterForInterface(newAttrInfo);
1554 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301555
Bharat saraswal2f11f652016-03-25 18:19:46 +05301556 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
1557 addGetterImpl(newAttrInfo, generatedJavaFiles);
1558 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301559
Bharat saraswal2f11f652016-03-25 18:19:46 +05301560 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
1561 addSetterImpl(newAttrInfo);
1562 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301563
Bharat saraswal2f11f652016-03-25 18:19:46 +05301564 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
1565 addConstructor(newAttrInfo);
1566 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301567
Bharat saraswal2f11f652016-03-25 18:19:46 +05301568 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
1569 addHashCodeMethod(newAttrInfo);
1570 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301571
Bharat saraswal2f11f652016-03-25 18:19:46 +05301572 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
1573 addEqualsMethod(newAttrInfo);
1574 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301575
Bharat saraswal2f11f652016-03-25 18:19:46 +05301576 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
1577 addToStringMethod(newAttrInfo);
1578 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301579
Bharat saraswald72411a2016-04-19 01:00:16 +05301580 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1581 addAttributesForEnumClass(newAttrInfo);
1582 }
1583
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301584 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1585 addOfStringMethod(newAttrInfo);
1586 }
1587
1588 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
1589 addTypeConstructor(newAttrInfo);
1590 }
1591
Vinod Kumar S38046502016-03-23 15:30:27 +05301592 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301593 }
1594
1595 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301596 * Returns java file info.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301597 *
1598 * @return java file info
1599 */
1600 private JavaFileInfo getJavaFileInfo() {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301601 return ((HasJavaFileInfo) getCurYangNode()).getJavaFileInfo();
1602 }
1603
1604 /**
1605 * Returns java class name.
1606 *
1607 * @param suffix for the class name based on the file type
1608 * @return java class name
1609 */
1610 private String getJavaClassName(String suffix) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301611 return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
Bharat saraswale2d51d62016-03-23 19:40:35 +05301612 }
1613
1614 /**
1615 * Returns the directory path.
1616 *
1617 * @return directory path
1618 */
1619 private String getDirPath() {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301620 return getJavaFileInfo().getPackageFilePath();
1621 }
1622
1623 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301624 * Constructs java code exit.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301625 *
1626 * @param fileType generated file type
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301627 * @param curNode current YANG node
Bharat saraswale2d51d62016-03-23 19:40:35 +05301628 * @throws IOException when fails to generate java files
1629 */
1630 public void generateJavaFile(int fileType, YangNode curNode) throws IOException {
1631
1632 setCurYangNode(curNode);
1633 List<String> imports = new ArrayList<>();
Bharat saraswal2f11f652016-03-25 18:19:46 +05301634 if (curNode instanceof HasJavaImportData && isAttributePresent) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301635 imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo());
1636 }
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301637
Bharat saraswale2d51d62016-03-23 19:40:35 +05301638 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301639 * Prepares java file generator for extends list.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301640 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301641 prepareJavaFileGeneratorForExtendsList(getExtendsList());
Bharat saraswald72411a2016-04-19 01:00:16 +05301642 if (curNode.getNodeType().equals(MODULE_NODE)) {
1643 createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
1644 } else {
1645 createPackage(absoluteDirPath, ((HasJavaFileInfo) curNode.getParent()).getJavaFileInfo().getJavaName()
1646 + PACKAGE_INFO_JAVADOC_OF_CHILD);
1647 }
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301648 /**
1649 * Generate java code.
1650 */
1651 if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) {
1652
1653 /**
1654 * Adds import for HasAugmentation class.
1655 */
1656 if (isHasAugmentationExtended(getExtendsList())) {
1657 addHasAugmentationImport(curNode, imports, true);
1658 }
1659
1660 if (isAugmentedInfoExtended(getExtendsList())) {
1661 addAugmentedInfoImport(curNode, imports, true);
1662 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301663
1664 /**
1665 * Create interface file.
1666 */
1667 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
Bharat saraswal2f11f652016-03-25 18:19:46 +05301668 setInterfaceJavaFileHandle(
1669 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent));
Bharat saraswale2d51d62016-03-23 19:40:35 +05301670 /**
1671 * Create builder interface file.
1672 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301673 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1674
1675 setBuilderInterfaceJavaFileHandle(
1676 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1677 setBuilderInterfaceJavaFileHandle(
1678 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
1679 /**
1680 * Append builder interface file to interface file and close it.
1681 */
1682 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
1683 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301684 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale2d51d62016-03-23 19:40:35 +05301685
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301686 if (isHasAugmentationExtended(getExtendsList())) {
1687 addHasAugmentationImport(curNode, imports, false);
1688 }
1689 if (isAugmentedInfoExtended(getExtendsList())) {
1690 addAugmentedInfoImport(curNode, imports, false);
1691 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301692 }
1693
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301694 if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301695
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301696 if (isAttributePresent) {
1697 addImportsToStringAndHasCodeMethods(curNode, imports);
1698 }
1699 if (isHasAugmentationExtended(getExtendsList())) {
1700 addAugmentedInfoImport(curNode, imports, true);
1701 addArrayListImport(curNode, imports, true);
1702 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301703
1704 /**
1705 * Create builder class file.
1706 */
1707 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
Bharat saraswal2f11f652016-03-25 18:19:46 +05301708 setBuilderClassJavaFileHandle(
1709 generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent));
Bharat saraswale2d51d62016-03-23 19:40:35 +05301710 /**
1711 * Create impl class file.
1712 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301713 if ((fileType & IMPL_CLASS_MASK) != 0) {
1714 setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
1715 setImplClassJavaFileHandle(
1716 generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
1717 /**
1718 * Append impl class to builder class and close it.
1719 */
1720 mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
1721 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301722 insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale2d51d62016-03-23 19:40:35 +05301723 }
1724
1725 /**
1726 * Creates type def class file.
1727 */
1728 if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301729 addImportsToStringAndHasCodeMethods(curNode, imports);
Bharat saraswale2d51d62016-03-23 19:40:35 +05301730 setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
1731 setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports));
1732 }
1733
1734 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301735 * Creates type class file.
1736 */
1737 if ((fileType & GENERATE_UNION_CLASS) != 0) {
1738 addImportsToStringAndHasCodeMethods(curNode, imports);
1739 setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
1740 setTypeClassJavaFileHandle(generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports));
1741 }
1742
1743 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301744 * Creates type enum class file.
1745 */
1746 if ((fileType & GENERATE_ENUM_CLASS) != 0) {
1747 setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
1748 setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
1749 }
1750
1751 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301752 * Creates rpc interface file.
1753 */
1754 if ((fileType & GENERATE_RPC_INTERFACE) != 0) {
1755 setRpcInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(RPC_INTERFACE_FILE_NAME_SUFFIX)));
1756 setRpcInterfaceJavaFileHandle(generateRpcInterfaceFile(getRpcInterfaceJavaFileHandle(), curNode, imports));
1757 }
1758
1759 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301760 * Close all the file handles.
1761 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301762 close(false);
Bharat saraswale2d51d62016-03-23 19:40:35 +05301763 }
1764
1765 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301766 * Removes all temporary file handles.
1767 *
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301768 * @param isErrorOccurred when translator fails to generate java files we need to close
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301769 * all open file handles include temporary files and java files.
Vinod Kumar S38046502016-03-23 15:30:27 +05301770 * @throws IOException when failed to delete the temporary files
1771 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301772 public void close(boolean isErrorOccurred) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301773
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301774 boolean isError = isErrorOccurred;
1775 /**
1776 * Close all java file handles and when error occurs delete the files.
1777 */
Bharat saraswal2f11f652016-03-25 18:19:46 +05301778 if ((generatedJavaFiles & INTERFACE_MASK) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301779 closeFile(getInterfaceJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301780 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301781 if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301782 closeFile(getBuilderClassJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301783 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301784 if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) {
1785 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1786 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301787 if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) {
1788 closeFile(getImplClassJavaFileHandle(), true);
1789 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301790 if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301791 closeFile(getTypedefClassJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301792 }
Bharat saraswald72411a2016-04-19 01:00:16 +05301793 if ((generatedJavaFiles & GENERATE_ENUM_CLASS) != 0) {
1794 closeFile(getEnumClassJavaFileHandle(), isError);
1795 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301796 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) {
1797 closeFile(getTypeClassJavaFileHandle(), isError);
1798 }
Gaurav Agrawal56527662016-04-20 15:49:17 +05301799 if ((generatedJavaFiles & GENERATE_RPC_INTERFACE) != 0) {
1800 closeFile(getRpcInterfaceJavaFileHandle(), isError);
1801 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301802
Bharat saraswal2f11f652016-03-25 18:19:46 +05301803 /**
1804 * Close all temporary file handles and delete the files.
1805 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301806 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
1807 closeFile(getGetterInterfaceTempFileHandle(), true);
1808 }
1809 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
1810 closeFile(getGetterImplTempFileHandle(), true);
1811 }
1812 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
1813 closeFile(getSetterInterfaceTempFileHandle(), true);
1814 }
1815 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
1816 closeFile(getSetterImplTempFileHandle(), true);
1817 }
1818 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
1819 closeFile(getConstructorImplTempFileHandle(), true);
1820 }
1821 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
1822 closeFile(getAttributesTempFileHandle(), true);
1823 }
1824 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
1825 closeFile(getHashCodeImplTempFileHandle(), true);
1826 }
1827 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
1828 closeFile(getToStringImplTempFileHandle(), true);
1829 }
1830 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
1831 closeFile(getEqualsImplTempFileHandle(), true);
1832 }
Bharat saraswald72411a2016-04-19 01:00:16 +05301833 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1834 closeFile(getEnumClassTempFileHandle(), true);
1835 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301836 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
1837 closeFile(getConstructorForTypeTempFileHandle(), true);
1838 }
1839 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1840 closeFile(getOfStringImplTempFileHandle(), true);
1841 }
Gaurav Agrawal56527662016-04-20 15:49:17 +05301842 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1843 closeFile(getFromStringImplTempFileHandle(), true);
1844 }
1845 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1846 closeFile(getRpcInterfaceImplTempFileHandle(), true);
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301847 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301848 clean(getTempDirPath());
1849 generatedTempFiles = 0;
Vinod Kumar S38046502016-03-23 15:30:27 +05301850 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301851}