blob: d8bba5e782c92f69dbb17514e0784039166594da [file] [log] [blame]
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.yangutils.translator.tojava;
17
18import java.io.File;
19import java.io.IOException;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053020import java.util.List;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053021
Bharat saraswalb551aae2016-07-14 15:18:20 +053022import org.onosproject.yangutils.datamodel.YangAugmentableNode;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053023import org.onosproject.yangutils.datamodel.YangCase;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053024import org.onosproject.yangutils.datamodel.YangLeaf;
25import org.onosproject.yangutils.datamodel.YangLeafList;
26import org.onosproject.yangutils.datamodel.YangLeavesHolder;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053027import org.onosproject.yangutils.datamodel.YangList;
Bharat saraswalb551aae2016-07-14 15:18:20 +053028import org.onosproject.yangutils.datamodel.YangModule;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053029import org.onosproject.yangutils.datamodel.YangNode;
Bharat saraswalb551aae2016-07-14 15:18:20 +053030import org.onosproject.yangutils.datamodel.YangSubModule;
31import org.onosproject.yangutils.datamodel.YangUses;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053032import org.onosproject.yangutils.translator.exception.TranslatorException;
33import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053034import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
Bharat saraswalcad0e652016-05-26 23:48:38 +053035import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Bharat saraswalcad0e652016-05-26 23:48:38 +053036import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
Bharat saraswalcad0e652016-05-26 23:48:38 +053037import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Bharat saraswalab4c6ba2016-05-17 14:19:38 +053038import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a5af142016-06-15 13:58:01 +053039import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053040
Bharat saraswal96dfef02016-06-16 00:29:12 +053041import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053042import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
43import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
44import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Bharat saraswalb551aae2016-07-14 15:18:20 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
47import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
49import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
50import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053052import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswalc0e04842016-05-12 13:16:57 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053054import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
55import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
56import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053057import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
58import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
59import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
60import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Bharat saraswalc0e04842016-05-12 13:16:57 +053061import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053062import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
Gaurav Agrawal8a5af142016-06-15 13:58:01 +053063import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053064import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
65import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
Bharat saraswalb551aae2016-07-14 15:18:20 +053066import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053067import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
68import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053069import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
70import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Bharat saraswalb551aae2016-07-14 15:18:20 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053072import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
74import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053075import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053076import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
77import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswalc0e04842016-05-12 13:16:57 +053078import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
80import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
84import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
85import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053086import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053087import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053088import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053089import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
90import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
Bharat saraswalb1170bd2016-07-14 13:26:18 +053091import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053092import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
93import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
94import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
95import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
96import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +053097import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053098import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053099import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530100import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
101import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530102import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530103import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530104import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Bharat saraswalb551aae2016-07-14 15:18:20 +0530105import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530106import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
107import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530108import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530109import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530110import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
111import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
112import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530113import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
114import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswal96dfef02016-06-16 00:29:12 +0530115import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530116
117/**
Bharat saraswalb551aae2016-07-14 15:18:20 +0530118 * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for
119 * Java file(s) generated.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530120 */
121public class TempJavaFragmentFiles {
Bharat saraswalc0e04842016-05-12 13:16:57 +0530122
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530123 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530124 * File type extension for java classes.
125 */
126 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswalc0e04842016-05-12 13:16:57 +0530127
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530128 /**
129 * File type extension for temporary classes.
130 */
131 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswalc0e04842016-05-12 13:16:57 +0530132
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530133 /**
134 * Folder suffix for temporary files folder.
135 */
136 private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530137
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530138 /**
139 * File name for getter method.
140 */
141 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530142
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530143 /**
144 * File name for setter method.
145 */
146 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530147
148 /**
149 * File name for getter method implementation.
150 */
151 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
152
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530153 /**
154 * File name for setter method implementation.
155 */
156 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530157
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530158 /**
159 * File name for attributes.
160 */
161 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswalc0e04842016-05-12 13:16:57 +0530162
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530163 /**
164 * File name for to string method.
165 */
166 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswalc0e04842016-05-12 13:16:57 +0530167
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530168 /**
169 * File name for hash code method.
170 */
171 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswalc0e04842016-05-12 13:16:57 +0530172
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530173 /**
174 * File name for equals method.
175 */
176 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530177
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530178 /**
Bharat saraswalc0e04842016-05-12 13:16:57 +0530179 * File name for from string method.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530180 */
Bharat saraswalc0e04842016-05-12 13:16:57 +0530181 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530182
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530183 /**
184 * File name for interface java file name suffix.
185 */
186 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530187
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530188 /**
189 * File name for builder interface file name suffix.
190 */
191 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530192
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530193 /**
194 * File name for builder class file name suffix.
195 */
196 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530197
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530198 /**
199 * File name for impl class file name suffix.
200 */
201 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530202
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530203 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530204 * File name for augment copy constructor method.
205 */
206 private static final String AUGMENT_CONSTRUCTOR_FILE_NAME = "AugmentConstructor";
Bharat saraswalb551aae2016-07-14 15:18:20 +0530207
208 /**
209 * Information about the java files being generated.
210 */
211 private JavaFileInfo javaFileInfo;
212
213 /**
214 * Imported class info.
215 */
216 private JavaImportData javaImportData;
217
218 /**
219 * The variable which guides the types of temporary files generated using the temporary generated file types mask.
220 */
221 private int generatedTempFiles;
222
223 /**
224 * Absolute path where the target java file needs to be generated.
225 */
226 private String absoluteDirPath;
227
228 /**
229 * Contains all the interface(s)/class name which will be extended by generated files.
230 */
231 private JavaExtendsListHolder javaExtendsListHolder;
232
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530233 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530234 * Java file handle for interface file.
235 */
236 private File interfaceJavaFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530237
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530238 /**
239 * Java file handle for builder interface file.
240 */
241 private File builderInterfaceJavaFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530242
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530243 /**
244 * Java file handle for builder class file.
245 */
246 private File builderClassJavaFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530247
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530248 /**
249 * Java file handle for impl class file.
250 */
251 private File implClassJavaFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530252
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530253 /**
254 * Temporary file handle for attribute.
255 */
256 private File attributesTempFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530257
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530258 /**
259 * Temporary file handle for getter of interface.
260 */
261 private File getterInterfaceTempFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530262
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530263 /**
264 * Temporary file handle for setter of interface.
265 */
266 private File setterInterfaceTempFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530267
268 /**
269 * Temporary file handle for getter of class.
270 */
271 private File getterImplTempFileHandle;
272
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530273 /**
274 * Temporary file handle for setter of class.
275 */
276 private File setterImplTempFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530277
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530278 /**
279 * Temporary file handle for hash code method of class.
280 */
281 private File hashCodeImplTempFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530282
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530283 /**
284 * Temporary file handle for equals method of class.
285 */
286 private File equalsImplTempFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530287
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530288 /**
289 * Temporary file handle for to string method of class.
290 */
291 private File toStringImplTempFileHandle;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530292
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530293 /**
Bharat saraswalc0e04842016-05-12 13:16:57 +0530294 * Temporary file handle for from string method of class.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530295 */
Bharat saraswalc0e04842016-05-12 13:16:57 +0530296 private File fromStringImplTempFileHandle;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530297
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530298 /**
299 * Import info for case.
300 */
301 private JavaQualifiedTypeInfo caseImportInfo;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530302
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530303 /**
304 * Is attribute added.
305 */
Bharat saraswalc0e04842016-05-12 13:16:57 +0530306 private boolean isAttributePresent;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530307
Bharat saraswalc0e04842016-05-12 13:16:57 +0530308 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530309 * Temporary file handle for augments copy constructor method of class.
310 */
311 private File augmentConstructorImplTempFileHandle;
312
Bharat saraswalb551aae2016-07-14 15:18:20 +0530313 TempJavaFragmentFiles() {
314 }
315
316 /**
317 * Creates an instance of temporary java code fragment.
318 *
319 * @param javaFileInfo generated java file information
320 * @throws IOException when fails to create new file handle
321 */
322 TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
323 throws IOException {
324 setJavaExtendsListHolder(new JavaExtendsListHolder());
325 setJavaImportData(new JavaImportData());
326 setJavaFileInfo(javaFileInfo);
327 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
328 getJavaFileInfo().getPackageFilePath()));
329
330 /*
331 * Initialize getter when generation file type matches to interface
332 * mask.
333 */
334 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
335 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
336 }
337
338 /*
339 * Initialize getter and setter when generation file type matches to
340 * builder interface mask.
341 */
342 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
343 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
344 addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
345 }
346
347 /*
348 * Initialize getterImpl, setterImpl and attributes when generation file
349 * type matches to builder class mask.
350 */
351 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
352 addGeneratedTempFile(ATTRIBUTES_MASK);
353 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
354 addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
355 addGeneratedTempFile(AUGMENTE_CLASS_CONSTRUCTOR_MASK);
356 }
357
358 /*
359 * Initialize getterImpl, attributes, constructor, hash code, equals and
360 * to strings when generation file type matches to impl class mask.
361 */
362 if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
363 addGeneratedTempFile(ATTRIBUTES_MASK);
364 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
365 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
366 addGeneratedTempFile(EQUALS_IMPL_MASK);
367 addGeneratedTempFile(TO_STRING_IMPL_MASK);
368 }
369
370 /*
371 * Initialize temp files to generate type class.
372 */
373 if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
374 addGeneratedTempFile(ATTRIBUTES_MASK);
375 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
376 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
377 addGeneratedTempFile(EQUALS_IMPL_MASK);
378 addGeneratedTempFile(TO_STRING_IMPL_MASK);
379 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
380 }
381
382 /*
383 * Initialize temp files to generate enum class.
384 */
385 if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
386 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
387 }
388
389 /*
390 * Set temporary file handles.
391 */
392 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
393 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
394 }
395
396 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
397 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
398 }
399
400 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
401 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
402 }
403
404 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
405 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
406 }
407
408 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
409 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
410 }
411
412 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
413 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
414 }
415 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
416 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
417 }
418 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
419 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
420 }
421 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
422 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
423 }
424 if ((getGeneratedTempFiles() & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
425 setAugmentConstructorImplTempFileHandle(getTemporaryFileHandle(AUGMENT_CONSTRUCTOR_FILE_NAME));
426 }
427
428 }
429
430 /**
431 * Adds current node info as and attribute to the parent generated file.
432 *
433 * @param curNode current node which needs to be added as an attribute in the parent generated code
434 * @param isList is list construct
435 * @param pluginConfig plugin configurations
436 * @throws IOException IO operation exception
437 */
438 public static void addCurNodeInfoInParentTempFile(YangNode curNode,
439 boolean isList, YangPluginConfig pluginConfig)
440 throws IOException {
441 YangNode parent = getParentNodeInGenCode(curNode);
442 if (!(parent instanceof JavaCodeGenerator)) {
443 throw new TranslatorException("missing parent node to contain current node info in generated file");
444 }
445
446 if (parent instanceof YangJavaGrouping) {
447 /*
448 * In case of grouping, there is no need to add the information, it
449 * will be taken care in uses
450 */
451 return;
452 }
453 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
454 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
455
456 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
457 parent, isList, tempJavaBeanFragmentFiles);
458 if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
459 throw new TranslatorException("missing parent temp file handle");
460 }
461 getNodesInterfaceFragmentFiles(parent, javaAttributeInfo, pluginConfig);
462 }
463
464 /**
465 * Creates an attribute info object corresponding to a data model node and return it.
466 *
467 * @param curNode current data model node for which the java code generation is being handled
468 * @param targetNode target node in which the current node is an attribute
469 * @param isListNode is the current added attribute needs to be a list
470 * @param tempJavaFragmentFiles temp java fragment files
471 * @return AttributeInfo attribute details required to add in temporary files
472 */
473 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
474 YangNode targetNode, boolean isListNode,
475 TempJavaFragmentFiles tempJavaFragmentFiles) {
476 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
477 if (curNodeName == null) {
478 updateJavaFileInfo(curNode, null);
479 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
480 }
481
482 /*
483 * Get the import info corresponding to the attribute for import in
484 * generated java files or qualified access
485 */
486 JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
487 getCapitalCase(curNodeName));
488 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
489 throw new TranslatorException("Parent node does not have file info");
490 }
491 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
492 JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
493
494 boolean isQualified;
495 if ((targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule)
496 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
497 || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
498 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
499 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
500 || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
501 || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE))
502 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
503 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
504
505 isQualified = true;
506 } else {
507 String className;
508 if (targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule) {
509 className = getCapitalCase(fileInfo.getJavaName()) + "Service";
510 } else {
511 className = getCapitalCase(fileInfo.getJavaName());
512 }
513
514 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
515 className, fileInfo.getPackage());
516 }
517
518 if (isListNode) {
519 parentImportData.setIfListImported(true);
520 }
521
522 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
523 }
524
525 /**
526 * Adds java code snippet for corresponding files.
527 *
528 * @param node java node
529 * @param attr attribute info
530 * @param config plugin configurations
531 * @throws IOException when fails to do IO operations
532 */
533 public static void getNodesInterfaceFragmentFiles(YangNode node, JavaAttributeInfo attr,
534 YangPluginConfig config) throws IOException {
535 TempJavaFragmentFiles tempJavaFragmentFiles;
536 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
537 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
538 tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
539 .getTempJavaCodeFragmentFiles()
540 .getServiceTempFiles();
541 tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
542 }
543 if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
544 tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
545 .getTempJavaCodeFragmentFiles()
546 .getBeanTempFiles();
547 tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
548 }
549
550 }
551
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530552 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530553 * Retrieves the absolute path where the file needs to be generated.
554 *
555 * @return absolute path where the file needs to be generated
556 */
557 private String getAbsoluteDirPath() {
558 return absoluteDirPath;
559 }
560
561 /**
562 * Sets absolute path where the file needs to be generated.
563 *
Bharat saraswalb551aae2016-07-14 15:18:20 +0530564 * @param absoluteDirPath absolute path where the file needs to be generated.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530565 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530566 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530567 this.absoluteDirPath = absoluteDirPath;
568 }
569
570 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530571 * Retrieves the generated java file information.
572 *
573 * @return generated java file information
574 */
575 public JavaFileInfo getJavaFileInfo() {
576 return javaFileInfo;
577 }
578
579 /**
Bharat saraswalb551aae2016-07-14 15:18:20 +0530580 * Sets the generated java file information.
581 *
582 * @param javaFileInfo generated java file information
583 */
584 public void setJavaFileInfo(JavaFileInfo javaFileInfo) {
585 this.javaFileInfo = javaFileInfo;
586 }
587
588 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530589 * Retrieves the generated temp files.
590 *
591 * @return generated temp files
592 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530593 int getGeneratedTempFiles() {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530594 return generatedTempFiles;
595 }
596
597 /**
Bharat saraswalb551aae2016-07-14 15:18:20 +0530598 * Sets generated file files.
599 *
600 * @param fileType generated file type
601 */
602 void setGeneratedTempFiles(int fileType) {
603 generatedTempFiles = fileType;
604 }
605
606 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530607 * Clears the generated file mask.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530608 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530609 void clearGeneratedTempFileMask() {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530610 generatedTempFiles = 0;
611 }
612
613 /**
Bharat saraswalc0e04842016-05-12 13:16:57 +0530614 * Adds to generated temporary files.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530615 *
616 * @param generatedTempFile generated file
617 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530618 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530619 generatedTempFiles |= generatedTempFile;
Bharat saraswalc0e04842016-05-12 13:16:57 +0530620 setGeneratedTempFiles(generatedTempFiles);
621 }
622
623 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530624 * Retrieves the generated Java files.
625 *
626 * @return generated Java files
627 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530628 int getGeneratedJavaFiles() {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530629 return getJavaFileInfo().getGeneratedFileTypes();
630 }
631
632 /**
633 * Retrieves the mapped Java class name.
634 *
635 * @return mapped Java class name
636 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530637 String getGeneratedJavaClassName() {
janani b4a6711a2016-05-17 13:12:22 +0530638 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530639 }
640
641 /**
642 * Retrieves the import data for the generated Java file.
643 *
644 * @return import data for the generated Java file
645 */
646 public JavaImportData getJavaImportData() {
647 return javaImportData;
648 }
649
650 /**
651 * Sets import data for the generated Java file.
652 *
653 * @param javaImportData import data for the generated Java file
654 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530655 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530656 this.javaImportData = javaImportData;
657 }
658
659 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530660 * Retrieves the status of any attributes added.
661 *
662 * @return status of any attributes added
663 */
664 public boolean isAttributePresent() {
665 return isAttributePresent;
666 }
667
668 /**
669 * Sets status of any attributes added.
670 *
671 * @param attributePresent status of any attributes added
672 */
673 public void setAttributePresent(boolean attributePresent) {
674 isAttributePresent = attributePresent;
675 }
676
677 /**
678 * Returns getter methods's temporary file handle.
679 *
680 * @return temporary file handle
681 */
682 public File getGetterInterfaceTempFileHandle() {
683 return getterInterfaceTempFileHandle;
684 }
685
686 /**
687 * Sets to getter method's temporary file handle.
688 *
689 * @param getterForInterface file handle for to getter method
690 */
691 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
692 getterInterfaceTempFileHandle = getterForInterface;
693 }
694
695 /**
696 * Returns setter method's temporary file handle.
697 *
698 * @return temporary file handle
699 */
700 public File getSetterInterfaceTempFileHandle() {
701 return setterInterfaceTempFileHandle;
702 }
703
704 /**
705 * Sets to setter method's temporary file handle.
706 *
707 * @param setterForInterface file handle for to setter method
708 */
709 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
710 setterInterfaceTempFileHandle = setterForInterface;
711 }
712
713 /**
714 * Returns setter method's impl's temporary file handle.
715 *
716 * @return temporary file handle
717 */
718 public File getSetterImplTempFileHandle() {
719 return setterImplTempFileHandle;
720 }
721
722 /**
723 * Sets to setter method's impl's temporary file handle.
724 *
725 * @param setterImpl file handle for to setter method's implementation class
726 */
727 private void setSetterImplTempFileHandle(File setterImpl) {
728 setterImplTempFileHandle = setterImpl;
729 }
730
731 /**
Bharat saraswalc0e04842016-05-12 13:16:57 +0530732 * Returns from string method's temporary file handle.
733 *
734 * @return from string method's temporary file handle
735 */
736 public File getFromStringImplTempFileHandle() {
737 return fromStringImplTempFileHandle;
738 }
739
740 /**
741 * Sets from string method's temporary file handle.
742 *
Bharat saraswalb551aae2016-07-14 15:18:20 +0530743 * @param fromStringImplTempFileHandle from string method's temporary file handle
Bharat saraswalc0e04842016-05-12 13:16:57 +0530744 */
745 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
746 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
747 }
748
749 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530750 * Returns java file handle for interface file.
751 *
752 * @return java file handle for interface file
753 */
754 private File getInterfaceJavaFileHandle() {
755 return interfaceJavaFileHandle;
756 }
757
758 /**
759 * Sets the java file handle for interface file.
760 *
761 * @param interfaceJavaFileHandle java file handle
762 */
763 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
764 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
765 }
766
767 /**
768 * Returns java file handle for builder interface file.
769 *
770 * @return java file handle for builder interface file
771 */
772 private File getBuilderInterfaceJavaFileHandle() {
773 return builderInterfaceJavaFileHandle;
774 }
775
776 /**
777 * Sets the java file handle for builder interface file.
778 *
779 * @param builderInterfaceJavaFileHandle java file handle
780 */
781 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
782 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
783 }
784
785 /**
786 * Returns java file handle for builder class file.
787 *
788 * @return java file handle for builder class file
789 */
790 private File getBuilderClassJavaFileHandle() {
791 return builderClassJavaFileHandle;
792 }
793
794 /**
795 * Sets the java file handle for builder class file.
796 *
797 * @param builderClassJavaFileHandle java file handle
798 */
799 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
800 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
801 }
802
803 /**
804 * Returns java file handle for impl class file.
805 *
806 * @return java file handle for impl class file
807 */
808 private File getImplClassJavaFileHandle() {
809 return implClassJavaFileHandle;
810 }
811
812 /**
813 * Sets the java file handle for impl class file.
814 *
815 * @param implClassJavaFileHandle java file handle
816 */
817 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
818 this.implClassJavaFileHandle = implClassJavaFileHandle;
819 }
820
821 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530822 * Returns attribute's temporary file handle.
823 *
824 * @return temporary file handle
825 */
826 public File getAttributesTempFileHandle() {
827 return attributesTempFileHandle;
828 }
829
830 /**
831 * Sets attribute's temporary file handle.
832 *
833 * @param attributeForClass file handle for attribute
834 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530835 void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530836 attributesTempFileHandle = attributeForClass;
837 }
838
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530839 /**
840 * Returns getter method's impl's temporary file handle.
841 *
842 * @return temporary file handle
843 */
844 public File getGetterImplTempFileHandle() {
845 return getterImplTempFileHandle;
846 }
847
848 /**
849 * Sets to getter method's impl's temporary file handle.
850 *
851 * @param getterImpl file handle for to getter method's impl
852 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530853 void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530854 getterImplTempFileHandle = getterImpl;
855 }
856
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530857 /**
858 * Returns hash code method's temporary file handle.
859 *
860 * @return temporary file handle
861 */
862 public File getHashCodeImplTempFileHandle() {
863 return hashCodeImplTempFileHandle;
864 }
865
866 /**
867 * Sets hash code method's temporary file handle.
868 *
869 * @param hashCodeMethod file handle for hash code method
870 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530871 void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530872 hashCodeImplTempFileHandle = hashCodeMethod;
873 }
874
875 /**
876 * Returns equals mehtod's temporary file handle.
877 *
878 * @return temporary file handle
879 */
880 public File getEqualsImplTempFileHandle() {
881 return equalsImplTempFileHandle;
882 }
883
884 /**
885 * Sets equals method's temporary file handle.
886 *
887 * @param equalsMethod file handle for to equals method
888 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530889 void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530890 equalsImplTempFileHandle = equalsMethod;
891 }
892
893 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530894 * Returns to string method's temporary file handle.
895 *
896 * @return temporary file handle
897 */
898 public File getToStringImplTempFileHandle() {
899 return toStringImplTempFileHandle;
900 }
901
902 /**
903 * Sets to string method's temporary file handle.
904 *
905 * @param toStringMethod file handle for to string method
906 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530907 void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530908 toStringImplTempFileHandle = toStringMethod;
909 }
910
911 /**
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530912 * Returns java extends list holder.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530913 *
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530914 * @return java extends list holder
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530915 */
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530916 public JavaExtendsListHolder getJavaExtendsListHolder() {
917 return javaExtendsListHolder;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530918 }
919
920 /**
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530921 * Sets java extends list holder.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530922 *
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530923 * @param javaExtendsListHolder java extends list holder
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530924 */
Bharat saraswalab4c6ba2016-05-17 14:19:38 +0530925 public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
926 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530927 }
928
929 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +0530930 * Returns augments copy constructor method impl class file.
931 *
932 * @return augments copy constructor method impl class file
933 */
934 public File getAugmentConstructorImplTempFileHandle() {
935 return augmentConstructorImplTempFileHandle;
936 }
937
938 /**
939 * Sets augments copy constructor method impl class.
940 *
941 * @param augmentConstructorImplTempFileHandle augments copy constructor method impl class file
942 */
943 public void setAugmentConstructorImplTempFileHandle(File augmentConstructorImplTempFileHandle) {
944 this.augmentConstructorImplTempFileHandle = augmentConstructorImplTempFileHandle;
945 }
946
947 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530948 * Adds attribute for class.
949 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530950 * @param attr attribute info
951 * @param yangPluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530952 * @throws IOException when fails to append to temporary file
953 */
Bharat saraswal33dfa012016-05-17 19:59:16 +0530954 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530955 throws IOException {
Bharat saraswal33dfa012016-05-17 19:59:16 +0530956 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
957 + FOUR_SPACE_INDENTATION);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530958 }
959
960 /**
961 * Adds getter for interface.
962 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530963 * @param attr attribute info
Bharat saraswal33dfa012016-05-17 19:59:16 +0530964 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530965 * @throws IOException when fails to append to temporary file
966 */
Bharat saraswal33dfa012016-05-17 19:59:16 +0530967 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530968 throws IOException {
Bharat saraswalc0e04842016-05-12 13:16:57 +0530969 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal33dfa012016-05-17 19:59:16 +0530970 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530971 }
972
973 /**
974 * Adds setter for interface.
975 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +0530976 * @param attr attribute info
Bharat saraswal33dfa012016-05-17 19:59:16 +0530977 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530978 * @throws IOException when fails to append to temporary file
979 */
Bharat saraswal33dfa012016-05-17 19:59:16 +0530980 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530981 throws IOException {
982 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal33dfa012016-05-17 19:59:16 +0530983 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
984 + NEW_LINE);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530985 }
986
987 /**
988 * Adds setter's implementation for class.
989 *
990 * @param attr attribute info
991 * @throws IOException when fails to append to temporary file
992 */
993 private void addSetterImpl(JavaAttributeInfo attr)
994 throws IOException {
995 appendToFile(getSetterImplTempFileHandle(),
Bharat saraswalc0e04842016-05-12 13:16:57 +0530996 getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
997 +
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +0530998 NEW_LINE);
999 }
1000
1001 /**
1002 * Adds getter method's impl for class.
1003 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301004 * @param attr attribute info
Bharat saraswal33dfa012016-05-17 19:59:16 +05301005 * @param pluginConfig plugin configurations
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301006 * @throws IOException when fails to append to temporary file
1007 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301008 private void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301009 throws IOException {
1010 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
1011 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
1012 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
1013 getGeneratedJavaFiles()) + NEW_LINE);
1014 } else {
janani b4a6711a2016-05-17 13:12:22 +05301015 appendToFile(getGetterImplTempFileHandle(),
Bharat saraswal33dfa012016-05-17 19:59:16 +05301016 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
janani b4a6711a2016-05-17 13:12:22 +05301017 + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301018 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301019 }
1020
1021 /**
1022 * Adds build method for interface.
1023 *
Bharat saraswal33dfa012016-05-17 19:59:16 +05301024 * @param pluginConfig plugin configurations
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301025 * @return build method for interface
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301026 * @throws IOException when fails to append to temporary file
1027 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301028 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301029 throws IOException {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301030 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301031 }
1032
1033 /**
1034 * Adds build method's implementation for class.
1035 *
1036 * @return build method implementation for class
1037 * @throws IOException when fails to append to temporary file
1038 */
1039 String addBuildMethodImpl()
1040 throws IOException {
1041 return getBuildString(getGeneratedJavaClassName()) + NEW_LINE;
1042 }
1043
1044 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301045 * Adds default constructor for class.
1046 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301047 * @param modifier modifier for constructor.
1048 * @param toAppend string which need to be appended with the class name
Bharat saraswal33dfa012016-05-17 19:59:16 +05301049 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301050 * @return default constructor for class
1051 * @throws IOException when fails to append to file
1052 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301053 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301054 throws IOException {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301055 return NEW_LINE
1056 + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301057 }
1058
1059 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301060 * Adds hash code method for class.
1061 *
1062 * @param attr attribute info
1063 * @throws IOException when fails to append to temporary file
1064 */
1065 private void addHashCodeMethod(JavaAttributeInfo attr)
1066 throws IOException {
1067 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
1068 }
1069
1070 /**
1071 * Adds equals method for class.
1072 *
1073 * @param attr attribute info
1074 * @throws IOException when fails to append to temporary file
1075 */
1076 private void addEqualsMethod(JavaAttributeInfo attr)
1077 throws IOException {
1078 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
1079 }
1080
1081 /**
1082 * Adds ToString method for class.
1083 *
1084 * @param attr attribute info
1085 * @throws IOException when fails to append to temporary file
1086 */
1087 private void addToStringMethod(JavaAttributeInfo attr)
1088 throws IOException {
1089 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
1090 }
1091
1092 /**
Bharat saraswalc0e04842016-05-12 13:16:57 +05301093 * Adds from string method for union class.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301094 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301095 * @param javaAttributeInfo type attribute info
Bharat saraswalc0e04842016-05-12 13:16:57 +05301096 * @param fromStringAttributeInfo from string attribute info
1097 * @throws IOException when fails to append to temporary file
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301098 */
Bharat saraswalc0e04842016-05-12 13:16:57 +05301099 private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301100 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301101 throws IOException {
Bharat saraswalc0e04842016-05-12 13:16:57 +05301102 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
1103 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301104 }
1105
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301106 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301107 * Adds constructor for augment class.
1108 *
1109 * @param attr attribute info
1110 * @throws IOException when fails to append to temporary file
1111 */
1112 private void addAugmentConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
1113 throws IOException {
1114 appendToFile(getAugmentConstructorImplTempFileHandle(), getAugmentedConstructor(attr, pluginConfig));
1115 }
1116
1117 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301118 * Returns a temporary file handle for the specific file type.
1119 *
1120 * @param fileName file name
1121 * @return temporary file handle
1122 * @throws IOException when fails to create new file handle
1123 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301124 File getTemporaryFileHandle(String fileName)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301125 throws IOException {
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301126 String path = getTempDirPath(getAbsoluteDirPath());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301127 File dir = new File(path);
1128 if (!dir.exists()) {
1129 dir.mkdirs();
1130 }
1131 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1132 if (!file.exists()) {
1133 file.createNewFile();
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301134 } else {
1135 throw new IOException(fileName + " is reused due to YANG naming");
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301136 }
1137 return file;
1138 }
1139
1140 /**
1141 * Returns a temporary file handle for the specific file type.
1142 *
1143 * @param fileName file name
1144 * @return temporary file handle
1145 * @throws IOException when fails to create new file handle
1146 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301147 File getJavaFileHandle(String fileName)
1148 throws IOException {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301149 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1150 }
1151
1152 /**
1153 * Returns data from the temporary files.
1154 *
Bharat saraswalb551aae2016-07-14 15:18:20 +05301155 * @param file temporary file handle
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301156 * @param absolutePath absolute path
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301157 * @return stored data from temporary files
1158 * @throws IOException when failed to get data from the given file
1159 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301160 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301161 throws IOException {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301162
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301163 String path = getTempDirPath(absolutePath);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301164 if (new File(path + file.getName()).exists()) {
1165 return readAppendFile(path + file.getName(), EMPTY_STRING);
1166 } else {
1167 throw new IOException("Unable to get data from the given "
1168 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
1169 }
1170 }
1171
1172 /**
1173 * Returns temporary directory path.
1174 *
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301175 * @param absolutePath absolute path
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301176 * @return directory path
1177 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301178 String getTempDirPath(String absolutePath) {
1179 return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301180 + TEMP_FOLDER_NAME_SUFIX + SLASH;
1181 }
1182
1183 /**
1184 * Parses attribute to get the attribute string.
1185 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301186 * @param attr attribute info
Bharat saraswal33dfa012016-05-17 19:59:16 +05301187 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301188 * @return attribute string
1189 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301190 public String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301191 /*
1192 * TODO: check if this utility needs to be called or move to the caller
1193 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301194 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301195 if (attr.isQualifiedName()) {
Bharat saraswalc0e04842016-05-12 13:16:57 +05301196 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
1197 attr.getImportInfo().getClassInfo(),
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301198 attributeName, attr.isListAttr());
1199 } else {
1200 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
1201 attr.isListAttr());
1202 }
1203 }
1204
1205 /**
1206 * Appends content to temporary file.
1207 *
1208 * @param file temporary file
1209 * @param data data to be appended
1210 * @throws IOException when fails to append to file
1211 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301212 void appendToFile(File file, String data)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301213 throws IOException {
1214 try {
1215 insertDataIntoJavaFile(file, data);
1216 } catch (IOException ex) {
1217 throw new IOException("failed to write in temp file.");
1218 }
1219 }
1220
1221 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301222 * Adds parent's info to current node import list.
1223 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301224 * @param curNode current node for which import list needs to be updated
Bharat saraswal33dfa012016-05-17 19:59:16 +05301225 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301226 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301227 public void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301228 caseImportInfo = new JavaQualifiedTypeInfo();
1229 YangNode parent = getParentNodeInGenCode(curNode);
1230 if (!(parent instanceof JavaCodeGenerator)) {
1231 throw new TranslatorException("missing parent node to contain current node info in generated file");
1232 }
1233 if (!(curNode instanceof JavaFileInfoContainer)) {
1234 throw new TranslatorException("missing java file information to get the package details "
1235 + "of attribute corresponding to child node");
1236 }
Bharat saraswal33dfa012016-05-17 19:59:16 +05301237 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1238 pluginConfig.getConflictResolver())));
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301239 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301240
1241 JavaFileInfo fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1242
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301243 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301244 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301245 getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301246 }
1247
1248 /**
1249 * Adds leaf attributes in generated files.
1250 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301251 * @param listOfLeaves list of YANG leaf
1252 * @param yangPluginConfig plugin config
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301253 * @throws IOException IO operation fail
1254 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301255 public void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301256 YangPluginConfig yangPluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301257 throws IOException {
1258 if (listOfLeaves != null) {
1259 for (YangLeaf leaf : listOfLeaves) {
1260 if (!(leaf instanceof JavaLeafInfoContainer)) {
1261 throw new TranslatorException("Leaf does not have java information");
1262 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301263 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(leaf, yangPluginConfig),
1264 yangPluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301265 }
1266 }
1267 }
1268
1269 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301270 * Returns java attribute for leaf.
1271 *
1272 * @param leaf YANG leaf
1273 * @param yangPluginConfig plugin configurations
1274 * @return java attribute for leaf
1275 */
1276 private JavaAttributeInfo getJavaAttributeOfLeaf(YangLeaf leaf,
1277 YangPluginConfig yangPluginConfig) {
1278 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
1279 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1280 javaLeaf.updateJavaQualifiedInfo();
1281 return getAttributeInfoForTheData(
1282 javaLeaf.getJavaQualifiedInfo(),
1283 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1284 javaLeaf.getDataType(),
1285 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1286 false);
1287 }
1288
1289 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301290 * Adds leaf list's attributes in generated files.
1291 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301292 * @param listOfLeafList list of YANG leaves
1293 * @param yangPluginConfig plugin config
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301294 * @throws IOException IO operation fail
1295 */
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301296 public void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301297 throws IOException {
1298 if (listOfLeafList != null) {
1299 for (YangLeafList leafList : listOfLeafList) {
1300 if (!(leafList instanceof JavaLeafInfoContainer)) {
1301 throw new TranslatorException("Leaf-list does not have java information");
1302 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301303 addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(leafList, yangPluginConfig),
1304 yangPluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301305 }
1306 }
1307 }
1308
1309 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301310 * Returns java attribute for leaf-list.
1311 *
1312 * @param leafList YANG leaf-list
1313 * @param yangPluginConfig plugin configurations
1314 * @return java attribute for leaf-list
1315 */
1316 private JavaAttributeInfo getJavaAttributeOfLeafList(YangLeafList leafList, YangPluginConfig yangPluginConfig) {
1317 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
1318 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
1319 javaLeaf.updateJavaQualifiedInfo();
1320 getJavaImportData().setIfListImported(true);
1321 return getAttributeInfoForTheData(
1322 javaLeaf.getJavaQualifiedInfo(),
1323 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1324 javaLeaf.getDataType(),
1325 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1326 true);
1327 }
1328
1329 /**
Bharat saraswalb551aae2016-07-14 15:18:20 +05301330 * Adds all the leaves in the current data model node as part of the generated temporary file.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301331 *
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301332 * @param curNode java file info of the generated file
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301333 * @param yangPluginConfig plugin config
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301334 * @throws IOException IO operation fail
1335 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301336 public void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301337 YangPluginConfig yangPluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301338 throws IOException {
1339 if (!(curNode instanceof YangLeavesHolder)) {
1340 throw new TranslatorException("Data model node does not have any leaves");
1341 }
1342 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301343 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig);
1344 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301345 }
1346
1347 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301348 * Adds the new attribute info to the target generated temporary files.
1349 *
Bharat saraswalb551aae2016-07-14 15:18:20 +05301350 * @param newAttrInfo the attribute info that needs to be added to temporary files
Bharat saraswal33dfa012016-05-17 19:59:16 +05301351 * @param pluginConfig plugin configurations
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301352 * @throws IOException IO operation fail
1353 */
Bharat saraswal33dfa012016-05-17 19:59:16 +05301354 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301355 throws IOException {
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301356 setAttributePresent(true);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301357 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301358 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301359 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301360
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301361 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301362 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301363 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301364
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301365 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301366 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301367 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301368
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301369 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
1370 addSetterImpl(newAttrInfo);
1371 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301372
1373 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswal33dfa012016-05-17 19:59:16 +05301374 addGetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301375 }
1376 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1377 addHashCodeMethod(newAttrInfo);
1378 }
1379 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1380 addEqualsMethod(newAttrInfo);
1381 }
1382 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1383 addToStringMethod(newAttrInfo);
1384 }
Bharat saraswalc0e04842016-05-12 13:16:57 +05301385
1386 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Bharat saraswal96dfef02016-06-16 00:29:12 +05301387 JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
1388 pluginConfig.getConflictResolver());
Bharat saraswalc0e04842016-05-12 13:16:57 +05301389 /*
1390 * Create a new java attribute info with qualified information of
1391 * wrapper classes.
1392 */
1393 JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1394 newAttrInfo.getAttributeName(),
1395 newAttrInfo.getAttributeType(),
1396 getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
1397
1398 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301399 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301400 }
1401
1402 /**
1403 * Returns java class name.
1404 *
1405 * @param suffix for the class name based on the file type
1406 * @return java class name
1407 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301408 String getJavaClassName(String suffix) {
janani b4a6711a2016-05-17 13:12:22 +05301409 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301410 }
1411
1412 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301413 * Returns java class name.
1414 *
1415 * @return java class name
1416 */
1417 String getImplClassName() {
1418 return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
1419 }
1420
1421 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301422 * Returns the directory path.
1423 *
1424 * @return directory path
1425 */
1426 private String getDirPath() {
1427 return getJavaFileInfo().getPackageFilePath();
1428 }
1429
1430 /**
1431 * Constructs java code exit.
1432 *
1433 * @param fileType generated file type
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301434 * @param curNode current YANG node
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301435 * @throws IOException when fails to generate java files
1436 */
1437 public void generateJavaFile(int fileType, YangNode curNode)
1438 throws IOException {
Bharat saraswalb551aae2016-07-14 15:18:20 +05301439
1440 if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
1441 addResolvedAugmentedDataNodeImports(curNode);
1442 }
1443 List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
1444 .getJavaImportData().getImports();
Bharat saraswal33dfa012016-05-17 19:59:16 +05301445
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301446 JavaFileInfo curInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1447
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301448 createPackage(curNode);
1449
1450 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301451 * Generate java code.
1452 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301453 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1454 BUILDER_INTERFACE_MASK) != 0) {
Bharat saraswalab4c6ba2016-05-17 14:19:38 +05301455
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301456 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301457 * Create interface file.
1458 */
1459 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1460 setInterfaceJavaFileHandle(
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301461 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
1462 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301463 * Create builder interface file.
1464 */
1465 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1466 setBuilderInterfaceJavaFileHandle(
1467 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1468 setBuilderInterfaceJavaFileHandle(
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301469 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
1470 isAttributePresent()));
1471 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301472 * Append builder interface file to interface file and close it.
1473 */
1474 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
Bharat saraswal96dfef02016-06-16 00:29:12 +05301475 validateLineLength(getInterfaceJavaFileHandle());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301476 }
1477 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301478
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301479 if (curNode instanceof YangCase) {
1480 removeCaseImport(imports);
1481 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301482 if (curNode instanceof YangJavaAugment) {
1483 updateAugmentConstructorTempFile(curNode, curInfo.getPluginConfig());
1484 YangJavaAugment augment = (YangJavaAugment) curNode;
1485 List<JavaQualifiedTypeInfo> infoList = augment.getExtendedClassInfo();
1486 for (JavaQualifiedTypeInfo info : infoList) {
1487 if (info.getClassInfo()
1488 .equals(getCapitalCase(getCamelCase(augment.getAugmentedNode().getName(), null)))) {
1489 removeAugmentedImport(imports, info);
1490 }
1491
1492 }
1493 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301494 }
Bharat saraswalc0e04842016-05-12 13:16:57 +05301495 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301496 if (isAttributePresent()) {
Bharat saraswalb551aae2016-07-14 15:18:20 +05301497 addImportsToStringAndHasCodeMethods(imports);
1498 }
1499 if (curNode instanceof YangAugmentableNode) {
1500 addImportsForAugmentableClass(imports);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301501 }
Bharat saraswalc0e04842016-05-12 13:16:57 +05301502 sortImports(imports);
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301503 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301504 * Create impl class file.
1505 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301506 setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName()));
1507 setImplClassJavaFileHandle(
1508 generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
1509
1510 /*
1511 * Create builder class file.
1512 */
1513 if ((fileType & BUILDER_CLASS_MASK) != 0) {
1514 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1515 setBuilderClassJavaFileHandle(
1516 generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
1517 isAttributePresent()));
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301518 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301519 * Append impl class to builder class and close it.
1520 */
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301521 mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
1522 validateLineLength(getImplClassJavaFileHandle());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301523 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301524 insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301525 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301526 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301527 * Close all the file handles.
1528 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301529 freeTemporaryResources(false);
1530 }
1531
1532 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301533 * Updates augment constructor temp file.
1534 *
1535 * @param curNode current augment node
1536 * @param pluginConfig plugin configurations
1537 * @throws IOException when fails to do IO operations
1538 */
1539 private void updateAugmentConstructorTempFile(YangNode curNode, YangPluginConfig pluginConfig)
1540 throws IOException {
1541 YangJavaAugment augment = (YangJavaAugment) curNode;
1542
Bharat saraswalb551aae2016-07-14 15:18:20 +05301543 TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
1544 .getTempJavaCodeFragmentFiles().getBeanTempFiles();
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301545 YangNode augmentedNode = augment.getAugmentedNode();
1546 if (augmentedNode instanceof YangLeavesHolder) {
1547 YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
1548 if (holder.getListOfLeaf() != null) {
1549 for (YangLeaf leaf : holder.getListOfLeaf()) {
1550 addAugmentConstructor(getJavaAttributeOfLeaf(leaf,
1551 pluginConfig), pluginConfig);
1552 }
1553
1554 }
1555 if (holder.getListOfLeafList() != null) {
1556 for (YangLeafList leafList : holder.getListOfLeafList()) {
1557 addAugmentConstructor(getJavaAttributeOfLeafList(leafList,
1558 pluginConfig), pluginConfig);
1559 }
1560
1561 }
1562 }
1563 augmentedNode = augmentedNode.getChild();
1564 boolean isList = false;
1565 while (augmentedNode != null) {
1566 if (augmentedNode instanceof YangList) {
1567 isList = true;
1568 }
Bharat saraswalb551aae2016-07-14 15:18:20 +05301569 if (!(augmentedNode instanceof YangUses)) {
1570 addAugmentConstructor(getCurNodeAsAttributeInTarget(augmentedNode, augment, isList,
1571 tempJavaBeanFragmentFiles), pluginConfig);
1572 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301573 augmentedNode = augmentedNode.getNextSibling();
1574 }
1575
1576 }
1577
1578 /**
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301579 * Adds imports for ToString and HashCodeMethod.
1580 *
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301581 * @param imports import list
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301582 */
Bharat saraswalb551aae2016-07-14 15:18:20 +05301583 public void addImportsToStringAndHasCodeMethods(List<String> imports) {
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301584 imports.add(getJavaImportData().getImportForHashAndEquals());
1585 imports.add(getJavaImportData().getImportForToString());
Bharat saraswalb551aae2016-07-14 15:18:20 +05301586 }
1587
1588
1589 /**
1590 * Adds import for map and hash map.
1591 *
1592 * @param imports import list
1593 */
1594 public void addImportsForAugmentableClass(List<String> imports) {
1595 imports.add(getJavaImportData().getHashMapImport());
1596 imports.add(getJavaImportData().getMapImport());
1597 imports.add(getJavaImportData().getYangAugmentedInfoImport());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301598 }
1599
1600 /**
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301601 * Removes augmented node import info from import list.
1602 *
1603 * @param imports list of imports
1604 * @return import for class
1605 */
1606 private List<String> removeAugmentedImport(List<String> imports, JavaQualifiedTypeInfo augmentedInfo) {
Bharat saraswalb551aae2016-07-14 15:18:20 +05301607 String augmentedNodeImport;
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301608 if (imports != null && augmentedInfo != null) {
1609 augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD + getCapitalCase(DEFAULT)
1610 + augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
1611 + BUILDER + SEMI_COLAN + NEW_LINE;
1612 imports.remove(augmentedNodeImport);
1613 augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD
1614 + augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
1615 + BUILDER + SEMI_COLAN + NEW_LINE;
1616 imports.remove(augmentedNodeImport);
Bharat saraswalb551aae2016-07-14 15:18:20 +05301617 imports.remove(getJavaImportData().getYangAugmentedInfoImport());
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301618 }
1619 return imports;
1620 }
1621
1622 /**
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301623 * Removes case import info from import list.
1624 *
1625 * @param imports list of imports
1626 * @return import for class
1627 */
1628 private List<String> removeCaseImport(List<String> imports) {
1629 if (imports != null && caseImportInfo != null) {
1630 String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
1631 SEMI_COLAN + NEW_LINE;
1632 imports.remove(caseImport);
1633 }
1634 return imports;
1635 }
1636
1637 /**
1638 * Removes all temporary file handles.
1639 *
Bharat saraswalb551aae2016-07-14 15:18:20 +05301640 * @param isErrorOccurred when translator fails to generate java files we need to close all open file handles
1641 * include temporary files and java files.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301642 * @throws IOException when failed to delete the temporary files
1643 */
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301644 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301645 throws IOException {
1646 boolean isError = isErrorOccurred;
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301647 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301648 * Close all java file handles and when error occurs delete the files.
1649 */
1650 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
1651 closeFile(getInterfaceJavaFileHandle(), isError);
1652 }
1653 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301654 closeFile(getBuilderClassJavaFileHandle(), true);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301655 }
1656 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1657 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1658 }
1659 if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301660 closeFile(getImplClassJavaFileHandle(), isError);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301661 }
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301662
VinodKumarS-Huaweicb3a1f52016-05-10 17:58:57 +05301663 /*
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301664 * Close all temporary file handles and delete the files.
1665 */
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301666 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1667 closeFile(getGetterImplTempFileHandle(), true);
1668 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301669 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1670 closeFile(getAttributesTempFileHandle(), true);
1671 }
1672 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1673 closeFile(getHashCodeImplTempFileHandle(), true);
1674 }
1675 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1676 closeFile(getToStringImplTempFileHandle(), true);
1677 }
1678 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1679 closeFile(getEqualsImplTempFileHandle(), true);
1680 }
Bharat saraswalc0e04842016-05-12 13:16:57 +05301681 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1682 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301683 }
Bharat saraswalb1170bd2016-07-14 13:26:18 +05301684 if ((getGeneratedTempFiles() & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
1685 closeFile(getAugmentConstructorImplTempFileHandle(), true);
1686 }
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301687 }
1688
1689 /**
Bharat saraswalb551aae2016-07-14 15:18:20 +05301690 * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
1691 * same needs to be done.
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301692 *
1693 * @param importInfo import info for the current attribute being added
1694 * @return status of the qualified access to the attribute
1695 */
1696 public boolean getIsQualifiedAccessOrAddToImportList(
1697 JavaQualifiedTypeInfo importInfo) {
VinodKumarS-Huawei2ee9e7e2016-06-01 14:30:22 +05301698
1699 return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(),
1700 getJavaFileInfo().getPackage());
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301701 }
1702
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301703}