blob: 10d98c801e6c6b48b38cf4a5d0cdc908d3f532ef [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;
Vidyashree Rama7142d9c2016-04-26 15:06:06 +053032import org.onosproject.yangutils.datamodel.YangCase;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053033import org.onosproject.yangutils.translator.exception.TranslatorException;
Vinod Kumar S38046502016-03-23 15:30:27 +053034
Bharat saraswald72411a2016-04-19 01:00:16 +053035import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
Vinod Kumar S38046502016-03-23 15:30:27 +053036import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
37import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053038import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Gaurav Agrawal56527662016-04-20 15:49:17 +053039import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
Bharat saraswale2d51d62016-03-23 19:40:35 +053040import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
Vinod Kumar S38046502016-03-23 15:30:27 +053042import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
43import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
44import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +053049import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053050import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
51import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
52import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +053054import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
Vinod Kumar S38046502016-03-23 15:30:27 +053055import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
56import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
57import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
Bharat saraswald72411a2016-04-19 01:00:16 +053058import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute;
Vinod Kumar S38046502016-03-23 15:30:27 +053059import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053060import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType;
Vinod Kumar S38046502016-03-23 15:30:27 +053061import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053062import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo;
Bharat saraswald72411a2016-04-19 01:00:16 +053063import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
Vinod Kumar S38046502016-03-23 15:30:27 +053064import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053065import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
Bharat saraswale2d51d62016-03-23 19:40:35 +053066import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
67import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswald72411a2016-04-19 01:00:16 +053068import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053069import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
70import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Gaurav Agrawal56527662016-04-20 15:49:17 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateRpcInterfaceFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053072import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053075import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
76import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
77import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
Vinod Kumar S38046502016-03-23 15:30:27 +053078import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053079import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
Vinod Kumar S38046502016-03-23 15:30:27 +053080import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
82import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
83import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053084import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S38046502016-03-23 15:30:27 +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;
Bharat saraswale2d51d62016-03-23 19:40:35 +053088import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
Vinod Kumar S38046502016-03-23 15:30:27 +053090import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Gaurav Agrawal56527662016-04-20 15:49:17 +053091import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcStringMethod;
Vinod Kumar S38046502016-03-23 15:30:27 +053092import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
93import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
94import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Gaurav Agrawal338735b2016-04-18 18:53:11 +053095import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
Vinod Kumar S38046502016-03-23 15:30:27 +053096import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
Bharat saraswalcc1cdab2016-04-16 02:28:25 +053097import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
98import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
99import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
100import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addImportsToStringAndHasCodeMethods;
101import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
102import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
103import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
104import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530105import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
106import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
107import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
108import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
109import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
110import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Bharat saraswald72411a2016-04-19 01:00:16 +0530111import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530112import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
113import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530114import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
115import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530116import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530117import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530118import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530119import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530120import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
121import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530122import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
123import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
124import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Vinod Kumar S38046502016-03-23 15:30:27 +0530125
126/**
Bharat saraswald9822e92016-04-05 15:13:44 +0530127 * Represents implementation of java code fragments temporary implementations.
Vinod Kumar S38046502016-03-23 15:30:27 +0530128 */
129public class TempJavaCodeFragmentFiles {
130
131 /**
132 * The variable which guides the types of temporary files generated using
133 * the temporary generated file types mask.
134 */
135 private int generatedTempFiles;
136
137 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530138 * The variable which guides the types of files generated using
139 * the generated file types mask.
140 */
141 private int generatedJavaFiles;
142
143 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530144 * Absolute path where the target java file needs to be generated.
145 */
146 private String absoluteDirPath;
147
148 /**
149 * Name of java file that needs to be generated.
150 */
151 private String generatedJavaClassName;
152
153 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530154 * Contains all the class name which will be extended by generated files.
155 */
156 private List<String> extendsList = new ArrayList<>();
157
158 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530159 * File type extension for java classes.
160 */
161 private static final String JAVA_FILE_EXTENSION = ".java";
162
163 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530164 * File type extension for temporary classes.
165 */
166 private static final String TEMP_FILE_EXTENSION = ".tmp";
167
168 /**
169 * Folder suffix for temporary files folder.
170 */
171 private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
172
173 /**
174 * File name for getter method.
175 */
176 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
177
178 /**
179 * File name for getter method implementation.
180 */
181 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
182
183 /**
184 * File name for setter method.
185 */
186 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
187
188 /**
189 * File name for setter method implementation.
190 */
191 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
192
193 /**
194 * File name for constructor.
195 */
196 private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
197
198 /**
199 * File name for attributes.
200 */
201 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
202
203 /**
204 * File name for to string method.
205 */
206 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
207
208 /**
209 * File name for hash code method.
210 */
211 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
212
213 /**
214 * File name for equals method.
215 */
216 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
217
218 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530219 * File name for of string method.
220 */
221 private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
222
223 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530224 * File name for temporary enum class.
225 */
226 private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
227
228 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530229 * File name for construction for special type like union, typedef.
230 */
231 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
232
233 /**
234 * File name for from string method.
235 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530236 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530237
238 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530239 * File name for interface java file name suffix.
240 */
241 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
242
243 /**
244 * File name for builder interface file name suffix.
245 */
246 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
247
248 /**
249 * File name for builder class file name suffix.
250 */
251 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
252
253 /**
254 * File name for impl class file name suffix.
255 */
256 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
257
258 /**
259 * File name for typedef class file name suffix.
260 */
261 private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
262
263 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530264 * File name for enum class file name suffix.
265 */
266 private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
267
268 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530269 * File name for rpc method.
270 */
271 private static final String RPC_FILE_NAME = "Rpc";
272
273 /**
274 * File name for generated class file for special type like union, typedef suffix.
275 */
276 private static final String RPC_INTERFACE_FILE_NAME_SUFFIX = "Service";
277
278 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530279 * File name for generated class file for special type like union, typedef suffix.
280 */
281 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
282
283 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530284 * Java file handle for interface file.
285 */
286 private File interfaceJavaFileHandle;
287
288 /**
289 * Java file handle for builder interface file.
290 */
291 private File builderInterfaceJavaFileHandle;
292
293 /**
294 * Java file handle for builder class file.
295 */
296 private File builderClassJavaFileHandle;
297
298 /**
299 * Java file handle for impl class file.
300 */
301 private File implClassJavaFileHandle;
302
303 /**
304 * Java file handle for typedef class file.
305 */
306 private File typedefClassJavaFileHandle;
307
308 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530309 * Java file handle for type class like union, typedef file.
310 */
311 private File typeClassJavaFileHandle;
312
313 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530314 * Temporary file handle for attribute.
315 */
316 private File attributesTempFileHandle;
317
318 /**
319 * Temporary file handle for getter of interface.
320 */
321 private File getterInterfaceTempFileHandle;
322
323 /**
324 * Temporary file handle for getter of class.
325 */
326 private File getterImplTempFileHandle;
327
328 /**
329 * Temporary file handle for setter of interface.
330 */
331 private File setterInterfaceTempFileHandle;
332
333 /**
334 * Temporary file handle for setter of class.
335 */
336 private File setterImplTempFileHandle;
337
338 /**
339 * Temporary file handle for constructor of class.
340 */
341 private File constructorImplTempFileHandle;
342
343 /**
344 * Temporary file handle for hash code method of class.
345 */
346 private File hashCodeImplTempFileHandle;
347
348 /**
349 * Temporary file handle for equals method of class.
350 */
351 private File equalsImplTempFileHandle;
352
353 /**
354 * Temporary file handle for to string method of class.
355 */
356 private File toStringImplTempFileHandle;
357
358 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530359 * Temporary file handle for enum class file.
360 */
361 private File enumClassTempFileHandle;
362
363 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530364 * Temporary file handle for of string method of class.
365 */
366 private File ofStringImplTempFileHandle;
367
368 /**
369 * Temporary file handle for constructor for type class.
370 */
371 private File constructorForTypeTempFileHandle;
372
373 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530374 * Temporary file handle for from string method of class.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530375 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530376 private File fromStringImplTempFileHandle;
377
378 /**
379 * Temporary file handle for rpc interface.
380 */
381 private File rpcInterfaceImplTempFileHandle;
382
383 /**
384 * Java file handle for rpc interface file.
385 */
386 private File rpcInterfaceJavaFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530387
388 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530389 * Java attribute info.
390 */
391 private JavaAttributeInfo newAttrInfo;
392
393 /**
394 * Current YANG node.
395 */
396 private YangNode curYangNode;
397
398 /**
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530399 * Import info for case.
400 */
401 private JavaQualifiedTypeInfo caseImportInfo;
402
403 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530404 * Current enum's value.
405 */
406 private int enumValue;
407
408 /**
Bharat saraswal2f11f652016-03-25 18:19:46 +0530409 * Is attribute added.
410 */
411 private boolean isAttributePresent = false;
412
Bharat saraswald72411a2016-04-19 01:00:16 +0530413 /*
414 * Java file handle for enum class.
415 */
416 private File enumClassJavaFileHandle;
417
Bharat saraswal2f11f652016-03-25 18:19:46 +0530418 /**
Bharat saraswald9822e92016-04-05 15:13:44 +0530419 * Creates an instance of temporary java code fragment.
Vinod Kumar S38046502016-03-23 15:30:27 +0530420 *
421 * @param genFileType file generation type
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530422 * @param genDir file generation directory
423 * @param className class name
Vinod Kumar S38046502016-03-23 15:30:27 +0530424 * @throws IOException when fails to create new file handle
425 */
Bharat saraswale2d51d62016-03-23 19:40:35 +0530426 public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className)
427 throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +0530428
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530429 setExtendsList(new ArrayList<>());
Vinod Kumar S38046502016-03-23 15:30:27 +0530430 generatedTempFiles = 0;
431 absoluteDirPath = genDir;
432 generatedJavaClassName = className;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530433 generatedJavaFiles = genFileType;
Vinod Kumar S38046502016-03-23 15:30:27 +0530434 /**
435 * Initialize getter when generation file type matches to interface
436 * mask.
437 */
438 if ((genFileType & INTERFACE_MASK) != 0) {
439 generatedTempFiles |= GETTER_FOR_INTERFACE_MASK;
440 }
441
442 /**
443 * Initialize getter and setter when generation file type matches to
444 * builder interface mask.
445 */
446 if ((genFileType & BUILDER_INTERFACE_MASK) != 0) {
447 generatedTempFiles |= GETTER_FOR_INTERFACE_MASK;
448 generatedTempFiles |= SETTER_FOR_INTERFACE_MASK;
449 }
450
451 /**
452 * Initialize getterImpl, setterImpl and attributes when generation file
453 * type matches to builder class mask.
454 */
455 if ((genFileType & BUILDER_CLASS_MASK) != 0) {
456 generatedTempFiles |= ATTRIBUTES_MASK;
457 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
458 generatedTempFiles |= SETTER_FOR_CLASS_MASK;
459 }
460
461 /**
462 * Initialize getterImpl, attributes, constructor, hash code, equals and
463 * to strings when generation file type matches to impl class mask.
464 */
465 if ((genFileType & IMPL_CLASS_MASK) != 0) {
466 generatedTempFiles |= ATTRIBUTES_MASK;
467 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
468 generatedTempFiles |= CONSTRUCTOR_IMPL_MASK;
469 generatedTempFiles |= HASH_CODE_IMPL_MASK;
470 generatedTempFiles |= EQUALS_IMPL_MASK;
471 generatedTempFiles |= TO_STRING_IMPL_MASK;
472 }
473
Gaurav Agrawal56527662016-04-20 15:49:17 +0530474 if ((genFileType & GENERATE_RPC_INTERFACE) != 0) {
475 generatedTempFiles |= RPC_IMPL_MASK;
476 }
477
Bharat saraswale2d51d62016-03-23 19:40:35 +0530478 /**
479 * Initialize getterImpl, attributes, hash code, equals and
480 * to strings when generation file type matches to typeDef class mask.
481 */
482 if ((genFileType & GENERATE_TYPEDEF_CLASS) != 0) {
483 generatedTempFiles |= ATTRIBUTES_MASK;
484 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
485 generatedTempFiles |= HASH_CODE_IMPL_MASK;
486 generatedTempFiles |= EQUALS_IMPL_MASK;
487 generatedTempFiles |= TO_STRING_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530488 generatedTempFiles |= OF_STRING_IMPL_MASK;
489 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530490 generatedTempFiles |= FROM_STRING_IMPL_MASK;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530491 }
492
493 /**
494 * Initialize getterImpl, attributes, hash code, equals, of string,
Gaurav Agrawal56527662016-04-20 15:49:17 +0530495 * constructor, union's to string, from string when generation
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530496 * file type matches to union class mask.
497 */
498 if ((genFileType & GENERATE_UNION_CLASS) != 0) {
499 generatedTempFiles |= ATTRIBUTES_MASK;
500 generatedTempFiles |= GETTER_FOR_CLASS_MASK;
501 generatedTempFiles |= HASH_CODE_IMPL_MASK;
502 generatedTempFiles |= EQUALS_IMPL_MASK;
503 generatedTempFiles |= OF_STRING_IMPL_MASK;
504 generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK;
505 generatedTempFiles |= TO_STRING_IMPL_MASK;
Gaurav Agrawal56527662016-04-20 15:49:17 +0530506 generatedTempFiles |= FROM_STRING_IMPL_MASK;
Bharat saraswale2d51d62016-03-23 19:40:35 +0530507 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530508 /**
509 * Initialize enum when generation file type matches to enum class mask.
510 */
511 if ((genFileType & GENERATE_ENUM_CLASS) != 0) {
512 generatedTempFiles |= ENUM_IMPL_MASK;
513 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530514
Bharat saraswald72411a2016-04-19 01:00:16 +0530515 /**
516 * Set temporary file handles.
517 */
Vinod Kumar S38046502016-03-23 15:30:27 +0530518 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
519 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
520 }
521
522 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
523 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
524 }
525
526 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
527 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
528 }
529
530 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
531 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
532 }
533
534 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
535 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
536 }
537
538 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
539 setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
540 }
541
542 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
543 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
544 }
545
546 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
547 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
548 }
549 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
550 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
551 }
Bharat saraswald72411a2016-04-19 01:00:16 +0530552 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
553 setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
554 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530555 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
556 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
557 }
558
559 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
560 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
561 }
562
Gaurav Agrawal56527662016-04-20 15:49:17 +0530563 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
564 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
565 }
566
567 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
568 setRpcInterfaceImplTempFileHandle(getTemporaryFileHandle(RPC_FILE_NAME));
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530569 }
Vinod Kumar S38046502016-03-23 15:30:27 +0530570 }
571
572 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530573 * Returns java file handle for interface file.
574 *
575 * @return java file handle for interface file
576 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530577 private File getInterfaceJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530578 return interfaceJavaFileHandle;
579 }
580
581 /**
582 * Sets the java file handle for interface file.
583 *
584 * @param interfaceJavaFileHandle java file handle
585 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530586 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530587 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
588 }
589
590 /**
591 * Returns java file handle for builder interface file.
592 *
593 * @return java file handle for builder interface file
594 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530595 private File getBuilderInterfaceJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530596 return builderInterfaceJavaFileHandle;
597 }
598
599 /**
600 * Sets the java file handle for builder interface file.
601 *
602 * @param builderInterfaceJavaFileHandle java file handle
603 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530604 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530605 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
606 }
607
608 /**
609 * Returns java file handle for builder class file.
610 *
611 * @return java file handle for builder class file
612 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530613 private File getBuilderClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530614 return builderClassJavaFileHandle;
615 }
616
617 /**
618 * Sets the java file handle for builder class file.
619 *
620 * @param builderClassJavaFileHandle java file handle
621 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530622 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530623 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
624 }
625
626 /**
627 * Returns java file handle for impl class file.
628 *
629 * @return java file handle for impl class file
630 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530631 private File getImplClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530632 return implClassJavaFileHandle;
633 }
634
635 /**
636 * Sets the java file handle for impl class file.
637 *
638 * @param implClassJavaFileHandle java file handle
639 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530640 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530641 this.implClassJavaFileHandle = implClassJavaFileHandle;
642 }
643
644 /**
645 * Returns java file handle for typedef class file.
646 *
647 * @return java file handle for typedef class file
648 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530649 private File getTypedefClassJavaFileHandle() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530650 return typedefClassJavaFileHandle;
651 }
652
653 /**
654 * Sets the java file handle for typedef class file.
655 *
656 * @param typedefClassJavaFileHandle java file handle
657 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530658 private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530659 this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
660 }
661
662 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530663 * Returns enum class java file handle.
664 *
665 * @return enum class java file handle
666 */
667 private File getEnumClassJavaFileHandle() {
668 return enumClassJavaFileHandle;
669 }
670
671 /**
672 * Sets enum class java file handle.
673 *
674 * @param enumClassJavaFileHandle enum class java file handle
675 */
676
677 private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
678 this.enumClassJavaFileHandle = enumClassJavaFileHandle;
679 }
680
681 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530682 * Returns java file handle for type class file.
683 *
684 * @return java file handle for type class file
685 */
686 private File getTypeClassJavaFileHandle() {
687 return typeClassJavaFileHandle;
688 }
689
690 /**
691 * Sets the java file handle for type class file.
692 *
693 * @param typeClassJavaFileHandle type file handle
694 */
695 private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
696 this.typeClassJavaFileHandle = typeClassJavaFileHandle;
697 }
698
699 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530700 * Returns attribute's temporary file handle.
701 *
702 * @return temporary file handle
703 */
704 public File getAttributesTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530705 return attributesTempFileHandle;
706 }
707
708 /**
709 * Sets attribute's temporary file handle.
710 *
711 * @param attributeForClass file handle for attribute
712 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530713 private void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530714 attributesTempFileHandle = attributeForClass;
715 }
716
717 /**
718 * Returns getter methods's temporary file handle.
719 *
720 * @return temporary file handle
721 */
722 public File getGetterInterfaceTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530723 return getterInterfaceTempFileHandle;
724 }
725
726 /**
727 * Sets to getter method's temporary file handle.
728 *
729 * @param getterForInterface file handle for to getter method
730 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530731 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530732 getterInterfaceTempFileHandle = getterForInterface;
733 }
734
735 /**
736 * Returns getter method's impl's temporary file handle.
737 *
738 * @return temporary file handle
739 */
740 public File getGetterImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530741 return getterImplTempFileHandle;
742 }
743
744 /**
745 * Sets to getter method's impl's temporary file handle.
746 *
747 * @param getterImpl file handle for to getter method's impl
748 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530749 private void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530750 getterImplTempFileHandle = getterImpl;
751 }
752
753 /**
754 * Returns setter method's temporary file handle.
755 *
756 * @return temporary file handle
757 */
758 public File getSetterInterfaceTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530759 return setterInterfaceTempFileHandle;
760 }
761
762 /**
763 * Sets to setter method's temporary file handle.
764 *
765 * @param setterForInterface file handle for to setter method
766 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530767 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530768 setterInterfaceTempFileHandle = setterForInterface;
769 }
770
771 /**
772 * Returns setter method's impl's temporary file handle.
773 *
774 * @return temporary file handle
775 */
776 public File getSetterImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530777 return setterImplTempFileHandle;
778 }
779
780 /**
781 * Sets to setter method's impl's temporary file handle.
782 *
783 * @param setterImpl file handle for to setter method's implementation class
784 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530785 private void setSetterImplTempFileHandle(File setterImpl) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530786 setterImplTempFileHandle = setterImpl;
787 }
788
789 /**
790 * Returns constructor's temporary file handle.
791 *
792 * @return temporary file handle
793 */
794 public File getConstructorImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530795 return constructorImplTempFileHandle;
796 }
797
798 /**
799 * Sets to constructor's temporary file handle.
800 *
801 * @param constructor file handle for to constructor
802 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530803 private void setConstructorImplTempFileHandle(File constructor) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530804 constructorImplTempFileHandle = constructor;
805 }
806
807 /**
808 * Returns hash code method's temporary file handle.
809 *
810 * @return temporary file handle
811 */
812 public File getHashCodeImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530813 return hashCodeImplTempFileHandle;
814 }
815
816 /**
817 * Sets hash code method's temporary file handle.
818 *
819 * @param hashCodeMethod file handle for hash code method
820 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530821 private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530822 hashCodeImplTempFileHandle = hashCodeMethod;
823 }
824
825 /**
826 * Returns equals mehtod's temporary file handle.
827 *
828 * @return temporary file handle
829 */
830 public File getEqualsImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530831 return equalsImplTempFileHandle;
832 }
833
834 /**
835 * Sets equals method's temporary file handle.
836 *
837 * @param equalsMethod file handle for to equals method
838 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530839 private void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530840 equalsImplTempFileHandle = equalsMethod;
841 }
842
843 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530844 * Returns rpc method's temporary file handle.
845 *
846 * @return temporary file handle
847 */
848 public File getRpcInterfaceImplTempFileHandle() {
849 return rpcInterfaceImplTempFileHandle;
850 }
851
852 /**
853 * Sets rpc method's temporary file handle.
854 *
855 * @param rpcInterfaceImplTempFileHandle file handle for to rpc method
856 */
857 public void setRpcInterfaceImplTempFileHandle(File rpcInterfaceImplTempFileHandle) {
858 this.rpcInterfaceImplTempFileHandle = rpcInterfaceImplTempFileHandle;
859 }
860
861 /**
862 * Returns rpc method's java file handle.
863 *
864 * @return java file handle
865 */
866 public File getRpcInterfaceJavaFileHandle() {
867 return rpcInterfaceJavaFileHandle;
868 }
869
870 /**
871 * Sets rpc method's java file handle.
872 *
873 * @param rpcInterfaceJavaFileHandle file handle for to rpc method
874 */
875 public void setRpcInterfaceJavaFileHandle(File rpcInterfaceJavaFileHandle) {
876 this.rpcInterfaceJavaFileHandle = rpcInterfaceJavaFileHandle;
877 }
878
879 /**
Vinod Kumar S38046502016-03-23 15:30:27 +0530880 * Returns to string method's temporary file handle.
881 *
882 * @return temporary file handle
883 */
884 public File getToStringImplTempFileHandle() {
Vinod Kumar S38046502016-03-23 15:30:27 +0530885 return toStringImplTempFileHandle;
886 }
887
888 /**
889 * Sets to string method's temporary file handle.
890 *
891 * @param toStringMethod file handle for to string method
892 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530893 private void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S38046502016-03-23 15:30:27 +0530894 toStringImplTempFileHandle = toStringMethod;
895 }
896
897 /**
Bharat saraswald72411a2016-04-19 01:00:16 +0530898 * Returns temporary file handle for enum class file.
899 *
900 * @return temporary file handle for enum class file
901 */
902 public File getEnumClassTempFileHandle() {
903 return enumClassTempFileHandle;
904 }
905
906 /**
907 * Sets temporary file handle for enum class file.
908 *
909 * @param enumClassTempFileHandle temporary file handle for enum class file
910 */
911
912 private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
913 this.enumClassTempFileHandle = enumClassTempFileHandle;
914 }
915
916 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530917 * Returns of string method's temporary file handle.
918 *
919 * @return of string method's temporary file handle
920 */
921 public File getOfStringImplTempFileHandle() {
922 return ofStringImplTempFileHandle;
923 }
924
925 /**
926 * Set of string method's temporary file handle.
927 *
928 * @param ofStringImplTempFileHandle of string method's temporary file handle
929 */
930 private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) {
931 this.ofStringImplTempFileHandle = ofStringImplTempFileHandle;
932 }
933
934 /**
935 * Returns type class constructor method's temporary file handle.
936 *
937 * @return type class constructor method's temporary file handle
938 */
939 public File getConstructorForTypeTempFileHandle() {
940 return constructorForTypeTempFileHandle;
941 }
942
943 /**
944 * Sets type class constructor method's temporary file handle.
945 *
946 * @param constructorForTypeTempFileHandle type class constructor method's temporary file handle
947 */
948 private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) {
949 this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle;
950 }
951
952 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530953 * Returns from string method's temporary file handle.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530954 *
Gaurav Agrawal56527662016-04-20 15:49:17 +0530955 * @return from string method's temporary file handle
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530956 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530957 public File getFromStringImplTempFileHandle() {
958 return fromStringImplTempFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530959 }
960
961 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +0530962 * Sets from string method's temporary file handle.
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530963 *
Gaurav Agrawal56527662016-04-20 15:49:17 +0530964 * @param fromStringImplTempFileHandle from string method's temporary file handle
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530965 */
Gaurav Agrawal56527662016-04-20 15:49:17 +0530966 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
967 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
Gaurav Agrawal338735b2016-04-18 18:53:11 +0530968 }
969
970 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +0530971 * Returns java attribute info.
972 *
973 * @return java attribute info
974 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530975 private JavaAttributeInfo getNewAttrInfo() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530976 return newAttrInfo;
977 }
978
979 /**
980 * Sets java attribute info.
981 *
982 * @param newAttrInfo java attribute info
983 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530984 private void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530985
Bharat saraswal2f11f652016-03-25 18:19:46 +0530986 if (newAttrInfo != null) {
987 isAttributePresent = true;
988 }
Bharat saraswale2d51d62016-03-23 19:40:35 +0530989 this.newAttrInfo = newAttrInfo;
990 }
991
992 /**
993 * Returns current YANG node.
994 *
995 * @return current YANG node
996 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +0530997 private YangNode getCurYangNode() {
Bharat saraswale2d51d62016-03-23 19:40:35 +0530998 return curYangNode;
999 }
1000
1001 /**
1002 * Sets current YANG node.
1003 *
1004 * @param curYangNode YANG node
1005 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301006 private void setCurYangNode(YangNode curYangNode) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301007 this.curYangNode = curYangNode;
1008 }
1009
1010 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301011 * Returns enum's value.
1012 *
1013 * @return enum's value
1014 */
1015 public int getEnumValue() {
1016 return enumValue;
1017 }
1018
1019 /**
1020 * Sets enum's value.
1021 *
1022 * @param enumValue enum's value
1023 */
1024 public void setEnumValue(int enumValue) {
1025 this.enumValue = enumValue;
1026 }
1027
1028 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301029 * Returns list of classes to be extended by generated files.
1030 *
1031 * @return list of classes to be extended by generated files
1032 */
1033 private List<String> getExtendsList() {
1034 return extendsList;
1035 }
1036
1037 /**
1038 * Sets class to be extended by generated file.
1039 *
1040 * @param extendsList list of classes to be extended
1041 */
1042
1043 private void setExtendsList(List<String> extendsList) {
1044 this.extendsList = extendsList;
1045 }
1046
1047 /**
1048 * Adds class to the extends list.
1049 *
1050 * @param extend class to be extended
1051 */
1052 public void addToExtendsList(String extend) {
1053 getExtendsList().add(extend);
1054 }
1055
1056 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301057 * Adds of string for type.
1058 *
1059 * @param attr attribute info
1060 * @throws IOException when fails to append to temporary file
1061 */
1062 private void addOfStringMethod(JavaAttributeInfo attr) throws IOException {
1063 appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, generatedJavaClassName)
1064 + NEW_LINE);
1065 }
1066
1067 /**
1068 * Adds type constructor.
1069 *
1070 * @param attr attribute info
1071 * @throws IOException when fails to append to temporary file
1072 */
1073 private void addTypeConstructor(JavaAttributeInfo attr) throws IOException {
1074 appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
1075 generatedJavaClassName) + NEW_LINE);
1076 }
1077
1078 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301079 * Adds attribute for class.
1080 *
1081 * @param attr attribute info
1082 * @throws IOException when fails to append to temporary file
1083 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301084 private void addAttribute(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301085 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION);
Vinod Kumar S38046502016-03-23 15:30:27 +05301086 }
1087
1088 /**
1089 * Adds getter for interface.
1090 *
1091 * @param attr attribute info
1092 * @throws IOException when fails to append to temporary file
1093 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301094 private void addGetterForInterface(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301095 appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301096 }
1097
1098 /**
1099 * Adds getter method's impl for class.
1100 *
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301101 * @param attr attribute info
Bharat saraswale2d51d62016-03-23 19:40:35 +05301102 * @param genFiletype generated file type
Vinod Kumar S38046502016-03-23 15:30:27 +05301103 * @throws IOException when fails to append to temporary file
1104 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301105 private void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301106
Bharat saraswale2d51d62016-03-23 19:40:35 +05301107 if ((genFiletype & BUILDER_CLASS_MASK) != 0) {
1108 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE);
1109 } else {
1110 appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false)
1111 + getGetterForClass(attr) + NEW_LINE);
1112 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301113 }
1114
1115 /**
1116 * Adds setter for interface.
1117 *
1118 * @param attr attribute info
1119 * @throws IOException when fails to append to temporary file
1120 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301121 private void addSetterForInterface(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301122 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswale2d51d62016-03-23 19:40:35 +05301123 getSetterString(attr, generatedJavaClassName) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301124 }
1125
1126 /**
1127 * Adds setter's implementation for class.
1128 *
1129 * @param attr attribute info
1130 * @throws IOException when fails to append to temporary file
1131 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301132 private void addSetterImpl(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301133 appendToFile(getSetterImplTempFileHandle(),
Bharat saraswale2d51d62016-03-23 19:40:35 +05301134 getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301135 }
1136
1137 /**
1138 * Adds build method for interface.
1139 *
1140 * @return build method for interface
Vinod Kumar S38046502016-03-23 15:30:27 +05301141 */
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301142 public String addBuildMethodForInterface() {
Vinod Kumar S38046502016-03-23 15:30:27 +05301143 return parseBuilderInterfaceBuildMethodString(generatedJavaClassName);
1144 }
1145
1146 /**
1147 * Adds build method's implementation for class.
1148 *
1149 * @return build method implementation for class
Vinod Kumar S38046502016-03-23 15:30:27 +05301150 */
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301151 public String addBuildMethodImpl() {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301152 return getBuildString(generatedJavaClassName) + NEW_LINE;
Vinod Kumar S38046502016-03-23 15:30:27 +05301153 }
1154
1155 /**
1156 * Adds constructor for class.
1157 *
1158 * @param attr attribute info
1159 * @throws IOException when fails to append to temporary file
1160 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301161 private void addConstructor(JavaAttributeInfo attr) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301162 appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr));
1163 }
1164
1165 /**
1166 * Adds default constructor for class.
1167 *
Bharat saraswale2d51d62016-03-23 19:40:35 +05301168 * @param modifier modifier for constructor.
1169 * @param toAppend string which need to be appended with the class name
Vinod Kumar S38046502016-03-23 15:30:27 +05301170 * @return default constructor for class
Vinod Kumar S38046502016-03-23 15:30:27 +05301171 */
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301172 public String addDefaultConstructor(String modifier, String toAppend) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301173 return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier);
1174 }
1175
1176 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301177 * Adds default constructor for class.
1178 *
1179 * @return default constructor for class
Bharat saraswale2d51d62016-03-23 19:40:35 +05301180 */
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301181 public String addOfMethod() {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301182 return getJavaDoc(OF_METHOD, generatedJavaClassName, false)
Bharat saraswale2d51d62016-03-23 19:40:35 +05301183 + getOfMethod(generatedJavaClassName, newAttrInfo);
Vinod Kumar S38046502016-03-23 15:30:27 +05301184 }
1185
1186 /**
1187 * Adds hash code method for class.
1188 *
1189 * @param attr attribute info
1190 * @throws IOException when fails to append to temporary file
1191 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301192 private void addHashCodeMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301193 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301194 }
1195
1196 /**
1197 * Adds equals method for class.
1198 *
1199 * @param attr attribute info
1200 * @throws IOException when fails to append to temporary file
1201 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301202 private void addEqualsMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301203 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301204 }
1205
1206 /**
1207 * Adds ToString method for class.
1208 *
1209 * @param attr attribute info
1210 * @throws IOException when fails to append to temporary file
1211 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301212 private void addToStringMethod(JavaAttributeInfo attr) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301213 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
Vinod Kumar S38046502016-03-23 15:30:27 +05301214 }
1215
1216 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301217 * Adds enum class attributes to temporary file.
1218 *
1219 * @param curEnum current YANG enum
1220 * @throws IOException when fails to do IO operations.
1221 */
1222 private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) throws IOException {
1223 appendToFile(getEnumClassTempFileHandle(),
1224 generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue()));
1225 }
1226
1227 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301228 * Add from string method for union class.
1229 *
1230 * @param javaAttributeInfo type attribute info
1231 * @param fromStringAttributeInfo from string attribute info
1232 * @throws IOException when fails to append to temporary file
1233 */
Gaurav Agrawal56527662016-04-20 15:49:17 +05301234 private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
1235 JavaAttributeInfo fromStringAttributeInfo) throws IOException {
1236 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301237 fromStringAttributeInfo) + NEW_LINE);
1238 }
1239
1240 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301241 * Adds rpc string information to applicable temp file.
1242 *
1243 * @param javaAttributeInfoOfInput rpc's input node attribute info
1244 * @param javaAttributeInfoOfOutput rpc's output node attribute info
1245 * @param rpcName name of the rpc function
1246 * @throws IOException IO operation fail
1247 */
1248 private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
1249 String rpcName) throws IOException {
1250 String rpcInput = "";
1251 String rpcOutput = "void";
1252 if (javaAttributeInfoOfInput != null) {
1253 rpcInput = javaAttributeInfoOfInput.getAttributeName();
1254 }
1255 if (javaAttributeInfoOfOutput != null) {
1256 rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
1257 }
1258 appendToFile(getRpcInterfaceImplTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
1259 getRpcStringMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
1260 }
1261
1262 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301263 * Returns a temporary file handle for the specific file type.
1264 *
1265 * @param fileName file name
1266 * @return temporary file handle
1267 * @throws IOException when fails to create new file handle
1268 */
1269 private File getTemporaryFileHandle(String fileName) throws IOException {
1270
1271 String path = getTempDirPath();
1272 File dir = new File(path);
1273 if (!dir.exists()) {
1274 dir.mkdirs();
1275 }
1276
1277 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1278 if (!file.exists()) {
1279 file.createNewFile();
Vinod Kumar S38046502016-03-23 15:30:27 +05301280 }
1281 return file;
1282 }
1283
1284 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301285 * Returns a temporary file handle for the specific file type.
1286 *
1287 * @param fileName file name
1288 * @return temporary file handle
1289 * @throws IOException when fails to create new file handle
1290 */
1291 private File getJavaFileHandle(String fileName) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301292 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1293 }
1294
1295 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301296 * Returns data from the temporary files.
1297 *
1298 * @param file temporary file handle
1299 * @return stored data from temporary files
1300 * @throws IOException when failed to get data from the given file
1301 */
1302 public String getTemporaryDataFromFileHandle(File file) throws IOException {
1303
1304 String path = getTempDirPath();
1305 if (new File(path + file.getName()).exists()) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301306 return readAppendFile(path + file.getName(), EMPTY_STRING);
Vinod Kumar S38046502016-03-23 15:30:27 +05301307 } else {
1308 throw new IOException("Unable to get data from the given "
Bharat saraswale2d51d62016-03-23 19:40:35 +05301309 + file.getName() + " file for " + generatedJavaClassName + PERIOD);
Vinod Kumar S38046502016-03-23 15:30:27 +05301310 }
1311 }
1312
1313 /**
1314 * Returns temporary directory path.
1315 *
1316 * @return directory path
1317 */
1318 private String getTempDirPath() {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301319 return getPackageDirPathFromJavaJPackage(absoluteDirPath) + SLASH + generatedJavaClassName
1320 + TEMP_FOLDER_NAME_SUFIX + SLASH;
Vinod Kumar S38046502016-03-23 15:30:27 +05301321 }
1322
1323 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301324 * Parses attribute to get the attribute string.
Vinod Kumar S38046502016-03-23 15:30:27 +05301325 *
1326 * @param attr attribute info
1327 * @return attribute string
1328 */
1329 private String parseAttribute(JavaAttributeInfo attr) {
1330
1331 /*
1332 * TODO: check if this utility needs to be called or move to the caller
1333 */
janani bde4ffab2016-04-15 16:18:30 +05301334 String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
Vinod Kumar S38046502016-03-23 15:30:27 +05301335 if (attr.isQualifiedName()) {
1336 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
1337 attributeName, attr.isListAttr());
1338 } else {
1339 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
1340 attr.isListAttr());
1341 }
1342 }
1343
1344 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301345 * Appends content to temporary file.
Vinod Kumar S38046502016-03-23 15:30:27 +05301346 *
1347 * @param file temporary file
1348 * @param data data to be appended
1349 * @throws IOException when fails to append to file
1350 */
1351 private void appendToFile(File file, String data) throws IOException {
1352
1353 try {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301354 insertDataIntoJavaFile(file, data);
Vinod Kumar S38046502016-03-23 15:30:27 +05301355 } catch (IOException ex) {
1356 throw new IOException("failed to write in temp file.");
1357 }
1358 }
1359
1360 /**
1361 * Adds current node info as and attribute to the parent generated file.
1362 *
1363 * @param curNode current node which needs to be added as an attribute in
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301364 * the parent generated code
1365 * @param isList is list construct
Vinod Kumar S38046502016-03-23 15:30:27 +05301366 * @throws IOException IO operation exception
1367 */
1368 public void addCurNodeInfoInParentTempFile(YangNode curNode,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301369 boolean isList) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301370
1371 YangNode parent = getParentNodeInGenCode(curNode);
1372 if (!(parent instanceof JavaCodeGenerator)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301373 throw new TranslatorException("missing parent node to contain current node info in generated file");
Vinod Kumar S38046502016-03-23 15:30:27 +05301374 }
1375 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode,
1376 parent, isList);
1377
1378 if (!(parent instanceof HasTempJavaCodeFragmentFiles)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301379 throw new TranslatorException("missing parent temp file handle");
Vinod Kumar S38046502016-03-23 15:30:27 +05301380 }
1381 ((HasTempJavaCodeFragmentFiles) parent)
1382 .getTempJavaCodeFragmentFiles()
1383 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1384 }
1385
1386 /**
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301387 * Adds parent's info to current node import list.
1388 *
1389 * @param curNode current node for which import list needs to be updated
1390 */
1391 public void addParentInfoInCurNodeTempFile(YangNode curNode) {
1392 caseImportInfo = new JavaQualifiedTypeInfo();
1393 YangNode parent = getParentNodeInGenCode(curNode);
1394 if (!(parent instanceof JavaCodeGenerator)) {
1395 throw new TranslatorException("missing parent node to contain current node info in generated file");
1396 }
1397
1398 if (!(curNode instanceof HasJavaFileInfo)) {
1399 throw new TranslatorException("missing java file information to get the package details "
1400 + "of attribute corresponding to child node");
1401 }
1402
1403 caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null)));
1404 caseImportInfo.setPkgInfo(((HasJavaFileInfo) parent).getJavaFileInfo().getPackage());
1405 ((HasJavaImportData) curNode).getJavaImportData().addImportInfo(curNode, caseImportInfo);
1406 }
1407
1408 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301409 * Adds leaf attributes in generated files.
1410 *
1411 * @param listOfLeaves list of YANG leaf
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301412 * @param curNode current data model node
Vinod Kumar S38046502016-03-23 15:30:27 +05301413 * @throws IOException IO operation fail
1414 */
1415 private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301416 YangNode curNode) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301417
1418 if (listOfLeaves != null) {
1419 for (YangLeaf leaf : listOfLeaves) {
1420 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf(curNode,
1421 leaf.getDataType(),
1422 leaf.getLeafName(), false);
1423 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1424 }
1425 }
1426 }
1427
1428 /**
1429 * Adds leaf list's attributes in generated files.
1430 *
1431 * @param listOfLeafList list of YANG leaves
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301432 * @param curNode cached file handle
Vinod Kumar S38046502016-03-23 15:30:27 +05301433 * @throws IOException IO operation fail
1434 */
1435 private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList,
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301436 YangNode curNode) throws IOException {
Vinod Kumar S38046502016-03-23 15:30:27 +05301437
1438 if (listOfLeafList != null) {
1439
1440 /*
1441 * Check if the attribute is of type list, then the java.lang.list
1442 * needs to be imported.
1443 */
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301444 if (!listOfLeafList.isEmpty()) {
Vinod Kumar S38046502016-03-23 15:30:27 +05301445 if (!(curNode instanceof HasJavaImportData)) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301446 throw new TranslatorException("missing import info in current data model node");
Vinod Kumar S38046502016-03-23 15:30:27 +05301447
1448 }
1449 ((HasJavaImportData) curNode).getJavaImportData()
1450 .setIfListImported(true);
1451
1452 }
1453
1454 for (YangLeafList leafList : listOfLeafList) {
1455 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf(
1456 curNode, leafList.getDataType(), leafList.getLeafName(),
1457 true);
1458 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1459 }
1460 }
1461 }
1462
1463 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301464 * Adds all the leaves in the current data model node as part of the
Vinod Kumar S38046502016-03-23 15:30:27 +05301465 * generated temporary file.
1466 *
1467 * @param curNode java file info of the generated file
1468 * @throws IOException IO operation fail
1469 */
1470 public void addCurNodeLeavesInfoToTempFiles(YangNode curNode) throws IOException {
1471
1472 if (curNode instanceof YangLeavesHolder) {
1473 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
1474 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), curNode);
1475 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), curNode);
1476 }
1477 }
1478
1479 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301480 * Add all the type in the current data model node as part of the
1481 * generated temporary file.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301482 *
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301483 * @param hasType YANG java data model node which has type info, eg union / typedef
Bharat saraswale2d51d62016-03-23 19:40:35 +05301484 * @throws IOException IO operation fail
1485 */
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301486 public void addTypeInfoToTempFiles(HasType hasType) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301487
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301488 List<YangType<?>> typeList = hasType.getTypeList();
1489 if (typeList != null) {
1490 for (YangType<?> yangType : typeList) {
1491 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfType((YangNode) hasType,
1492 yangType, getTypeName(yangType.getDataTypeName()), false);
1493 addJavaSnippetInfoToApplicableTempFiles((YangNode) hasType, javaAttributeInfo);
1494 }
1495 }
1496 }
1497
1498 private String getTypeName(String dataTypeName) {
1499 return dataTypeName;
1500 //TODO: implement the method.
1501 }
1502
1503 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301504 * Adds enum attributes to temporary files.
1505 *
1506 * @param curNode current YANG node
1507 * @throws IOException when fails to do IO operations
1508 */
1509 public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
1510
1511 if (curNode instanceof YangEnumeration) {
1512 Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet();
1513 for (YangEnum curEnum : enumSet) {
1514 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfEnumAttribute(curNode, curEnum.getNamedValue());
1515 setEnumValue(curEnum.getValue());
1516 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1517 }
1518 } else {
1519 throw new TranslatorException("curnode should be of type enum.");
1520 }
1521 }
1522
1523 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301524 * Adds the new attribute info to the target generated temporary files for union class.
1525 *
1526 * @param hasType the node for which the type is being added as an attribute
1527 * @param javaAttributeInfo the attribute info that needs to be added to temporary
1528 * files
1529 * @throws IOException IO operation fail
1530 */
1531 private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
1532 throws IOException {
1533
1534 JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo);
1535
Gaurav Agrawal56527662016-04-20 15:49:17 +05301536 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1537 addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301538 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301539 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1540 }
1541
1542 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301543 * Adds the JAVA rpc snippet information.
1544 *
1545 * @param javaAttributeInfoOfInput rpc's input node attribute info
1546 * @param javaAttributeInfoOfOutput rpc's output node attribute info
1547 * @param rpcName name of the rpc function
1548 * @throws IOException IO operation fail
1549 */
1550 public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
1551 JavaAttributeInfo javaAttributeInfoOfOutput,
1552 String rpcName) throws IOException {
1553 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1554 addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
1555 }
1556 }
1557
1558 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301559 * Adds the new attribute info to the target generated temporary files.
Vinod Kumar S38046502016-03-23 15:30:27 +05301560 *
1561 * @param newAttrInfo the attribute info that needs to be added to temporary
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301562 * files
Vinod Kumar S38046502016-03-23 15:30:27 +05301563 * @throws IOException IO operation fail
1564 */
1565 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
1566 throws IOException {
1567
Bharat saraswale2d51d62016-03-23 19:40:35 +05301568 setNewAttrInfo(newAttrInfo);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301569 if (isAttributePresent) {
1570 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
1571 addAttribute(newAttrInfo);
1572 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301573
Bharat saraswal2f11f652016-03-25 18:19:46 +05301574 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
1575 addGetterForInterface(newAttrInfo);
1576 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301577
Bharat saraswal2f11f652016-03-25 18:19:46 +05301578 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
1579 addSetterForInterface(newAttrInfo);
1580 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301581
Bharat saraswal2f11f652016-03-25 18:19:46 +05301582 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
1583 addGetterImpl(newAttrInfo, generatedJavaFiles);
1584 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301585
Bharat saraswal2f11f652016-03-25 18:19:46 +05301586 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
1587 addSetterImpl(newAttrInfo);
1588 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301589
Bharat saraswal2f11f652016-03-25 18:19:46 +05301590 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
1591 addConstructor(newAttrInfo);
1592 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301593
Bharat saraswal2f11f652016-03-25 18:19:46 +05301594 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
1595 addHashCodeMethod(newAttrInfo);
1596 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301597
Bharat saraswal2f11f652016-03-25 18:19:46 +05301598 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
1599 addEqualsMethod(newAttrInfo);
1600 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301601
Bharat saraswal2f11f652016-03-25 18:19:46 +05301602 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
1603 addToStringMethod(newAttrInfo);
1604 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301605
Bharat saraswald72411a2016-04-19 01:00:16 +05301606 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1607 addAttributesForEnumClass(newAttrInfo);
1608 }
1609
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301610 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1611 addOfStringMethod(newAttrInfo);
1612 }
1613
1614 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
1615 addTypeConstructor(newAttrInfo);
1616 }
1617
Vinod Kumar S38046502016-03-23 15:30:27 +05301618 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301619 }
1620
1621 /**
Bharat saraswald9822e92016-04-05 15:13:44 +05301622 * Returns java file info.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301623 *
1624 * @return java file info
1625 */
1626 private JavaFileInfo getJavaFileInfo() {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301627 return ((HasJavaFileInfo) getCurYangNode()).getJavaFileInfo();
1628 }
1629
1630 /**
1631 * Returns java class name.
1632 *
1633 * @param suffix for the class name based on the file type
1634 * @return java class name
1635 */
1636 private String getJavaClassName(String suffix) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301637 return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
Bharat saraswale2d51d62016-03-23 19:40:35 +05301638 }
1639
1640 /**
1641 * Returns the directory path.
1642 *
1643 * @return directory path
1644 */
1645 private String getDirPath() {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301646 return getJavaFileInfo().getPackageFilePath();
1647 }
1648
1649 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301650 * Constructs java code exit.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301651 *
1652 * @param fileType generated file type
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301653 * @param curNode current YANG node
Bharat saraswale2d51d62016-03-23 19:40:35 +05301654 * @throws IOException when fails to generate java files
1655 */
1656 public void generateJavaFile(int fileType, YangNode curNode) throws IOException {
1657
1658 setCurYangNode(curNode);
1659 List<String> imports = new ArrayList<>();
Bharat saraswal2f11f652016-03-25 18:19:46 +05301660 if (curNode instanceof HasJavaImportData && isAttributePresent) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301661 imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo());
1662 }
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301663
Bharat saraswale2d51d62016-03-23 19:40:35 +05301664 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301665 * Prepares java file generator for extends list.
Bharat saraswale2d51d62016-03-23 19:40:35 +05301666 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301667 prepareJavaFileGeneratorForExtendsList(getExtendsList());
Bharat saraswald72411a2016-04-19 01:00:16 +05301668 if (curNode.getNodeType().equals(MODULE_NODE)) {
1669 createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
1670 } else {
1671 createPackage(absoluteDirPath, ((HasJavaFileInfo) curNode.getParent()).getJavaFileInfo().getJavaName()
1672 + PACKAGE_INFO_JAVADOC_OF_CHILD);
1673 }
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301674 /**
1675 * Generate java code.
1676 */
1677 if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) {
1678
1679 /**
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301680 * Adds import for case.
1681 */
1682 if (curNode instanceof YangCase) {
1683 List<String> importData = ((HasJavaImportData) curNode).getJavaImportData().getImports();
1684 for (String importInfo : importData) {
1685 if (!imports.contains(importInfo)) {
1686 imports.add(importInfo);
1687 }
1688 }
1689 }
1690
1691 /**
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301692 * Adds import for HasAugmentation class.
1693 */
1694 if (isHasAugmentationExtended(getExtendsList())) {
1695 addHasAugmentationImport(curNode, imports, true);
1696 }
1697
1698 if (isAugmentedInfoExtended(getExtendsList())) {
1699 addAugmentedInfoImport(curNode, imports, true);
1700 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301701
1702 /**
1703 * Create interface file.
1704 */
1705 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
Bharat saraswal2f11f652016-03-25 18:19:46 +05301706 setInterfaceJavaFileHandle(
1707 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent));
Bharat saraswale2d51d62016-03-23 19:40:35 +05301708 /**
1709 * Create builder interface file.
1710 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301711 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1712
1713 setBuilderInterfaceJavaFileHandle(
1714 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1715 setBuilderInterfaceJavaFileHandle(
1716 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
1717 /**
1718 * Append builder interface file to interface file and close it.
1719 */
1720 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
1721 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301722 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale2d51d62016-03-23 19:40:35 +05301723
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301724 if (isHasAugmentationExtended(getExtendsList())) {
1725 addHasAugmentationImport(curNode, imports, false);
1726 }
1727 if (isAugmentedInfoExtended(getExtendsList())) {
1728 addAugmentedInfoImport(curNode, imports, false);
1729 }
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301730
1731 if (curNode instanceof YangCase) {
1732 removeCaseImport(imports);
1733 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301734 }
1735
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301736 if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301737
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301738 if (isAttributePresent) {
1739 addImportsToStringAndHasCodeMethods(curNode, imports);
1740 }
1741 if (isHasAugmentationExtended(getExtendsList())) {
1742 addAugmentedInfoImport(curNode, imports, true);
1743 addArrayListImport(curNode, imports, true);
1744 }
Bharat saraswale2d51d62016-03-23 19:40:35 +05301745
1746 /**
1747 * Create builder class file.
1748 */
1749 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
Bharat saraswal2f11f652016-03-25 18:19:46 +05301750 setBuilderClassJavaFileHandle(
1751 generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent));
Bharat saraswale2d51d62016-03-23 19:40:35 +05301752 /**
1753 * Create impl class file.
1754 */
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301755 if ((fileType & IMPL_CLASS_MASK) != 0) {
1756 setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
1757 setImplClassJavaFileHandle(
1758 generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
1759 /**
1760 * Append impl class to builder class and close it.
1761 */
1762 mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
1763 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301764 insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswale2d51d62016-03-23 19:40:35 +05301765 }
1766
1767 /**
1768 * Creates type def class file.
1769 */
1770 if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
Bharat saraswalcc1cdab2016-04-16 02:28:25 +05301771 addImportsToStringAndHasCodeMethods(curNode, imports);
Bharat saraswale2d51d62016-03-23 19:40:35 +05301772 setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
1773 setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports));
1774 }
1775
1776 /**
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301777 * Creates type class file.
1778 */
1779 if ((fileType & GENERATE_UNION_CLASS) != 0) {
1780 addImportsToStringAndHasCodeMethods(curNode, imports);
1781 setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
1782 setTypeClassJavaFileHandle(generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports));
1783 }
1784
1785 /**
Bharat saraswald72411a2016-04-19 01:00:16 +05301786 * Creates type enum class file.
1787 */
1788 if ((fileType & GENERATE_ENUM_CLASS) != 0) {
1789 setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
1790 setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
1791 }
1792
1793 /**
Gaurav Agrawal56527662016-04-20 15:49:17 +05301794 * Creates rpc interface file.
1795 */
1796 if ((fileType & GENERATE_RPC_INTERFACE) != 0) {
1797 setRpcInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(RPC_INTERFACE_FILE_NAME_SUFFIX)));
1798 setRpcInterfaceJavaFileHandle(generateRpcInterfaceFile(getRpcInterfaceJavaFileHandle(), curNode, imports));
1799 }
1800
1801 /**
Bharat saraswale2d51d62016-03-23 19:40:35 +05301802 * Close all the file handles.
1803 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301804 close(false);
Bharat saraswale2d51d62016-03-23 19:40:35 +05301805 }
1806
1807 /**
Vidyashree Rama7142d9c2016-04-26 15:06:06 +05301808 * Removes case import info from import list.
1809 *
1810 * @param imports list of imports
1811 * @return import for class
1812 */
1813 private List<String> removeCaseImport(List<String> imports) {
1814 if (imports != null && caseImportInfo != null) {
1815 String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
1816 SEMI_COLAN + NEW_LINE;
1817 imports.remove(caseImport);
1818 }
1819 return imports;
1820 }
1821
1822 /**
Vinod Kumar S38046502016-03-23 15:30:27 +05301823 * Removes all temporary file handles.
1824 *
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301825 * @param isErrorOccurred when translator fails to generate java files we need to close
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301826 * all open file handles include temporary files and java files.
Vinod Kumar S38046502016-03-23 15:30:27 +05301827 * @throws IOException when failed to delete the temporary files
1828 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301829 public void close(boolean isErrorOccurred) throws IOException {
Bharat saraswale2d51d62016-03-23 19:40:35 +05301830
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301831 boolean isError = isErrorOccurred;
1832 /**
1833 * Close all java file handles and when error occurs delete the files.
1834 */
Bharat saraswal2f11f652016-03-25 18:19:46 +05301835 if ((generatedJavaFiles & INTERFACE_MASK) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301836 closeFile(getInterfaceJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301837 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301838 if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301839 closeFile(getBuilderClassJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301840 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301841 if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) {
1842 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1843 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301844 if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) {
1845 closeFile(getImplClassJavaFileHandle(), true);
1846 }
Bharat saraswal2f11f652016-03-25 18:19:46 +05301847 if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) {
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301848 closeFile(getTypedefClassJavaFileHandle(), isError);
Bharat saraswal2f11f652016-03-25 18:19:46 +05301849 }
Bharat saraswald72411a2016-04-19 01:00:16 +05301850 if ((generatedJavaFiles & GENERATE_ENUM_CLASS) != 0) {
1851 closeFile(getEnumClassJavaFileHandle(), isError);
1852 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301853 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) {
1854 closeFile(getTypeClassJavaFileHandle(), isError);
1855 }
Gaurav Agrawal56527662016-04-20 15:49:17 +05301856 if ((generatedJavaFiles & GENERATE_RPC_INTERFACE) != 0) {
1857 closeFile(getRpcInterfaceJavaFileHandle(), isError);
1858 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301859
Bharat saraswal2f11f652016-03-25 18:19:46 +05301860 /**
1861 * Close all temporary file handles and delete the files.
1862 */
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301863 if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
1864 closeFile(getGetterInterfaceTempFileHandle(), true);
1865 }
1866 if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
1867 closeFile(getGetterImplTempFileHandle(), true);
1868 }
1869 if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
1870 closeFile(getSetterInterfaceTempFileHandle(), true);
1871 }
1872 if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
1873 closeFile(getSetterImplTempFileHandle(), true);
1874 }
1875 if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
1876 closeFile(getConstructorImplTempFileHandle(), true);
1877 }
1878 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
1879 closeFile(getAttributesTempFileHandle(), true);
1880 }
1881 if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
1882 closeFile(getHashCodeImplTempFileHandle(), true);
1883 }
1884 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
1885 closeFile(getToStringImplTempFileHandle(), true);
1886 }
1887 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
1888 closeFile(getEqualsImplTempFileHandle(), true);
1889 }
Bharat saraswald72411a2016-04-19 01:00:16 +05301890 if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1891 closeFile(getEnumClassTempFileHandle(), true);
1892 }
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301893 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
1894 closeFile(getConstructorForTypeTempFileHandle(), true);
1895 }
1896 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1897 closeFile(getOfStringImplTempFileHandle(), true);
1898 }
Gaurav Agrawal56527662016-04-20 15:49:17 +05301899 if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
1900 closeFile(getFromStringImplTempFileHandle(), true);
1901 }
1902 if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
1903 closeFile(getRpcInterfaceImplTempFileHandle(), true);
Gaurav Agrawal338735b2016-04-18 18:53:11 +05301904 }
Bharat saraswal6ef0b762016-04-05 12:45:45 +05301905 clean(getTempDirPath());
1906 generatedTempFiles = 0;
Vinod Kumar S38046502016-03-23 15:30:27 +05301907 }
Vinod Kumar S38046502016-03-23 15:30:27 +05301908}