blob: 42438528a202b63d76deff747287504df64e9b6f [file] [log] [blame]
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.yangutils.translator.tojava;
17
18import java.io.File;
19import java.io.IOException;
20import java.util.ArrayList;
21import java.util.List;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053022
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053023import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053024import org.onosproject.yangutils.datamodel.YangCase;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053025import org.onosproject.yangutils.datamodel.YangLeaf;
26import org.onosproject.yangutils.datamodel.YangLeafList;
27import org.onosproject.yangutils.datamodel.YangLeavesHolder;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053028import org.onosproject.yangutils.datamodel.YangList;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053029import org.onosproject.yangutils.datamodel.YangNode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053030import org.onosproject.yangutils.translator.exception.TranslatorException;
31import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +053032import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +053033import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +053034import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053035import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053036import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053037
Vinod Kumar S79a374b2016-04-30 21:09:15 +053038import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
39import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
40import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
42import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053043import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
44import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
45import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswal250a7472016-05-12 13:16:57 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
49import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
50import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
52import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
53import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
54import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Bharat saraswal250a7472016-05-12 13:16:57 +053055import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053056import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053057import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.updateJavaFileInfo;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053058import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
59import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
60import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
61import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053062import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
63import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053064import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
65import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
janani b703cfe42016-05-17 13:12:22 +053066import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053067import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
68import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +053069import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053070import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053071import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
72import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053073import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053074import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
75import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
76import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
77import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053078import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
80import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
83import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053084import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
85 .addAugmentationHoldersImport;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053086import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053087import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053088import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
89 .isAugmentationHolderExtended;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053090import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
Bharat saraswal250a7472016-05-12 13:16:57 +053091import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053092import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053093import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +053094import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
95import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053096import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
97import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
98import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
99import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
100import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530101import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530102import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530103import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530104import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
105import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530106import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530107import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530108import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
109import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
110import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
111import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
112import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530113import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530114import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
115import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
116import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
117
118/**
119 * Represents implementation of java code fragments temporary implementations.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530120 * Manages the common temp file required for Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530121 */
122public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530123
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530124 /**
125 * Information about the java files being generated.
126 */
127 private JavaFileInfo javaFileInfo;
Bharat saraswal250a7472016-05-12 13:16:57 +0530128
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530129 /**
130 * Imported class info.
131 */
132 private JavaImportData javaImportData;
Bharat saraswal250a7472016-05-12 13:16:57 +0530133
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530134 /**
135 * The variable which guides the types of temporary files generated using
136 * the temporary generated file types mask.
137 */
138 private int generatedTempFiles;
Bharat saraswal250a7472016-05-12 13:16:57 +0530139
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530140 /**
141 * Absolute path where the target java file needs to be generated.
142 */
143 private String absoluteDirPath;
Bharat saraswal250a7472016-05-12 13:16:57 +0530144
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530145 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530146 * Contains all the interface(s)/class name which will be extended by generated files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530147 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530148 private JavaExtendsListHolder javaExtendsListHolder;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530149
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530150 /**
151 * File type extension for java classes.
152 */
153 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530154
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530155 /**
156 * File type extension for temporary classes.
157 */
158 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530159
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530160 /**
161 * Folder suffix for temporary files folder.
162 */
163 private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530164
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530165 /**
166 * File name for getter method.
167 */
168 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530169
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530170 /**
171 * File name for setter method.
172 */
173 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530174
175 /**
176 * File name for getter method implementation.
177 */
178 private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
179
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530180 /**
181 * File name for setter method implementation.
182 */
183 private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530184
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530185 /**
186 * File name for attributes.
187 */
188 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530189
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530190 /**
191 * File name for to string method.
192 */
193 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530194
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530195 /**
196 * File name for hash code method.
197 */
198 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530199
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530200 /**
201 * File name for equals method.
202 */
203 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530204
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530205 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530206 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530207 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530208 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530209
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530210 /**
211 * File name for interface java file name suffix.
212 */
213 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530214
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530215 /**
216 * File name for builder interface file name suffix.
217 */
218 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530219
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530220 /**
221 * File name for builder class file name suffix.
222 */
223 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530224
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530225 /**
226 * File name for impl class file name suffix.
227 */
228 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530229
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530230 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530231 * Java file handle for interface file.
232 */
233 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530234
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530235 /**
236 * Java file handle for builder interface file.
237 */
238 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530239
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530240 /**
241 * Java file handle for builder class file.
242 */
243 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530244
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530245 /**
246 * Java file handle for impl class file.
247 */
248 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530249
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530250 /**
251 * Temporary file handle for attribute.
252 */
253 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530254
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530255 /**
256 * Temporary file handle for getter of interface.
257 */
258 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530259
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530260 /**
261 * Temporary file handle for setter of interface.
262 */
263 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530264
265 /**
266 * Temporary file handle for getter of class.
267 */
268 private File getterImplTempFileHandle;
269
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530270 /**
271 * Temporary file handle for setter of class.
272 */
273 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530274
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530275 /**
276 * Temporary file handle for hash code method of class.
277 */
278 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530279
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530280 /**
281 * Temporary file handle for equals method of class.
282 */
283 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530284
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530285 /**
286 * Temporary file handle for to string method of class.
287 */
288 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530289
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530290 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530291 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530292 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530293 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530294
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530295 /**
296 * Import info for case.
297 */
298 private JavaQualifiedTypeInfo caseImportInfo;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530299
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530300 /**
301 * Is attribute added.
302 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530303 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530304
Bharat saraswal250a7472016-05-12 13:16:57 +0530305 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530306 * Retrieves the absolute path where the file needs to be generated.
307 *
308 * @return absolute path where the file needs to be generated
309 */
310 private String getAbsoluteDirPath() {
311 return absoluteDirPath;
312 }
313
314 /**
315 * Sets absolute path where the file needs to be generated.
316 *
317 * @param absoluteDirPath absolute path where the file needs to be
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530318 * generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530319 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530320 void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530321 this.absoluteDirPath = absoluteDirPath;
322 }
323
324 /**
325 * Sets the generated java file information.
326 *
327 * @param javaFileInfo generated java file information
328 */
329 public void setJavaFileInfo(JavaFileInfo javaFileInfo) {
330 this.javaFileInfo = javaFileInfo;
331 }
332
333 /**
334 * Retrieves the generated java file information.
335 *
336 * @return generated java file information
337 */
338 public JavaFileInfo getJavaFileInfo() {
339 return javaFileInfo;
340 }
341
342 /**
343 * Retrieves the generated temp files.
344 *
345 * @return generated temp files
346 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530347 int getGeneratedTempFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530348 return generatedTempFiles;
349 }
350
351 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530352 * Clears the generated file mask.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530353 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530354 void clearGeneratedTempFileMask() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530355 generatedTempFiles = 0;
356 }
357
358 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530359 * Adds to generated temporary files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530360 *
361 * @param generatedTempFile generated file
362 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530363 void addGeneratedTempFile(int generatedTempFile) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530364 generatedTempFiles |= generatedTempFile;
Bharat saraswal250a7472016-05-12 13:16:57 +0530365 setGeneratedTempFiles(generatedTempFiles);
366 }
367
368 /**
369 * Sets generated file files.
370 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530371 * @param fileType generated file type
Bharat saraswal250a7472016-05-12 13:16:57 +0530372 */
373 void setGeneratedTempFiles(int fileType) {
374 generatedTempFiles = fileType;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530375 }
376
377 /**
378 * Retrieves the generated Java files.
379 *
380 * @return generated Java files
381 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530382 int getGeneratedJavaFiles() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530383 return getJavaFileInfo().getGeneratedFileTypes();
384 }
385
386 /**
387 * Retrieves the mapped Java class name.
388 *
389 * @return mapped Java class name
390 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530391 String getGeneratedJavaClassName() {
janani b703cfe42016-05-17 13:12:22 +0530392 return getCapitalCase(getJavaFileInfo().getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530393 }
394
395 /**
396 * Retrieves the import data for the generated Java file.
397 *
398 * @return import data for the generated Java file
399 */
400 public JavaImportData getJavaImportData() {
401 return javaImportData;
402 }
403
404 /**
405 * Sets import data for the generated Java file.
406 *
407 * @param javaImportData import data for the generated Java file
408 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530409 void setJavaImportData(JavaImportData javaImportData) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530410 this.javaImportData = javaImportData;
411 }
412
413 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530414 * Retrieves the status of any attributes added.
415 *
416 * @return status of any attributes added
417 */
418 public boolean isAttributePresent() {
419 return isAttributePresent;
420 }
421
422 /**
423 * Sets status of any attributes added.
424 *
425 * @param attributePresent status of any attributes added
426 */
427 public void setAttributePresent(boolean attributePresent) {
428 isAttributePresent = attributePresent;
429 }
430
431 /**
432 * Returns getter methods's temporary file handle.
433 *
434 * @return temporary file handle
435 */
436 public File getGetterInterfaceTempFileHandle() {
437 return getterInterfaceTempFileHandle;
438 }
439
440 /**
441 * Sets to getter method's temporary file handle.
442 *
443 * @param getterForInterface file handle for to getter method
444 */
445 private void setGetterInterfaceTempFileHandle(File getterForInterface) {
446 getterInterfaceTempFileHandle = getterForInterface;
447 }
448
449 /**
450 * Returns setter method's temporary file handle.
451 *
452 * @return temporary file handle
453 */
454 public File getSetterInterfaceTempFileHandle() {
455 return setterInterfaceTempFileHandle;
456 }
457
458 /**
459 * Sets to setter method's temporary file handle.
460 *
461 * @param setterForInterface file handle for to setter method
462 */
463 private void setSetterInterfaceTempFileHandle(File setterForInterface) {
464 setterInterfaceTempFileHandle = setterForInterface;
465 }
466
467 /**
468 * Returns setter method's impl's temporary file handle.
469 *
470 * @return temporary file handle
471 */
472 public File getSetterImplTempFileHandle() {
473 return setterImplTempFileHandle;
474 }
475
476 /**
477 * Sets to setter method's impl's temporary file handle.
478 *
479 * @param setterImpl file handle for to setter method's implementation class
480 */
481 private void setSetterImplTempFileHandle(File setterImpl) {
482 setterImplTempFileHandle = setterImpl;
483 }
484
485 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530486 * Returns from string method's temporary file handle.
487 *
488 * @return from string method's temporary file handle
489 */
490 public File getFromStringImplTempFileHandle() {
491 return fromStringImplTempFileHandle;
492 }
493
494 /**
495 * Sets from string method's temporary file handle.
496 *
497 * @param fromStringImplTempFileHandle from string method's temporary file
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530498 * handle
Bharat saraswal250a7472016-05-12 13:16:57 +0530499 */
500 private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
501 this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
502 }
503
504 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530505 * Creates an instance of temporary java code fragment.
506 *
507 * @param javaFileInfo generated java file information
508 * @throws IOException when fails to create new file handle
509 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530510 TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
511 throws IOException {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530512 setJavaExtendsListHolder(new JavaExtendsListHolder());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530513 setJavaImportData(new JavaImportData());
514 setJavaFileInfo(javaFileInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530515 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
516 getJavaFileInfo().getPackageFilePath()));
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530517
518 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530519 * Initialize getter when generation file type matches to interface
520 * mask.
521 */
522 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
523 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
524 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530525
526 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530527 * Initialize getter and setter when generation file type matches to
528 * builder interface mask.
529 */
530 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
531 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
532 addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
533 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530534
535 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530536 * Initialize getterImpl, setterImpl and attributes when generation file
537 * type matches to builder class mask.
538 */
539 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
540 addGeneratedTempFile(ATTRIBUTES_MASK);
541 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
542 addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
543 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530544
545 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530546 * Initialize getterImpl, attributes, constructor, hash code, equals and
547 * to strings when generation file type matches to impl class mask.
548 */
549 if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
550 addGeneratedTempFile(ATTRIBUTES_MASK);
551 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530552 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
553 addGeneratedTempFile(EQUALS_IMPL_MASK);
554 addGeneratedTempFile(TO_STRING_IMPL_MASK);
555 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530556
557 /*
558 * Initialize temp files to generate type class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530559 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530560 if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530561 addGeneratedTempFile(ATTRIBUTES_MASK);
562 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
563 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
564 addGeneratedTempFile(EQUALS_IMPL_MASK);
565 addGeneratedTempFile(TO_STRING_IMPL_MASK);
Bharat saraswal250a7472016-05-12 13:16:57 +0530566 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530567 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530568
569 /*
Bharat saraswal250a7472016-05-12 13:16:57 +0530570 * Initialize temp files to generate enum class.
571 */
572 if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
573 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
574 }
575 /*
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530576 * Initialize getter and setter when generation file type matches to
577 * builder interface mask.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530578 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530579 if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
580 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
581 addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530582 addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530583 addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530584 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530585
586 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530587 * Set temporary file handles.
588 */
589 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
590 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
591 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530592
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530593 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
594 setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
595 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530596
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530597 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
598 setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
599 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530600
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530601 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
602 setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
603 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530604
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530605 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
606 setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
607 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530608
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530609 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
610 setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
611 }
612 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
613 setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
614 }
615 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
616 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
617 }
Bharat saraswal250a7472016-05-12 13:16:57 +0530618 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
619 setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530620 }
Bharat saraswal250a7472016-05-12 13:16:57 +0530621
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530622 }
623
624 /**
625 * Returns java file handle for interface file.
626 *
627 * @return java file handle for interface file
628 */
629 private File getInterfaceJavaFileHandle() {
630 return interfaceJavaFileHandle;
631 }
632
633 /**
634 * Sets the java file handle for interface file.
635 *
636 * @param interfaceJavaFileHandle java file handle
637 */
638 private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
639 this.interfaceJavaFileHandle = interfaceJavaFileHandle;
640 }
641
642 /**
643 * Returns java file handle for builder interface file.
644 *
645 * @return java file handle for builder interface file
646 */
647 private File getBuilderInterfaceJavaFileHandle() {
648 return builderInterfaceJavaFileHandle;
649 }
650
651 /**
652 * Sets the java file handle for builder interface file.
653 *
654 * @param builderInterfaceJavaFileHandle java file handle
655 */
656 private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
657 this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
658 }
659
660 /**
661 * Returns java file handle for builder class file.
662 *
663 * @return java file handle for builder class file
664 */
665 private File getBuilderClassJavaFileHandle() {
666 return builderClassJavaFileHandle;
667 }
668
669 /**
670 * Sets the java file handle for builder class file.
671 *
672 * @param builderClassJavaFileHandle java file handle
673 */
674 private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
675 this.builderClassJavaFileHandle = builderClassJavaFileHandle;
676 }
677
678 /**
679 * Returns java file handle for impl class file.
680 *
681 * @return java file handle for impl class file
682 */
683 private File getImplClassJavaFileHandle() {
684 return implClassJavaFileHandle;
685 }
686
687 /**
688 * Sets the java file handle for impl class file.
689 *
690 * @param implClassJavaFileHandle java file handle
691 */
692 private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
693 this.implClassJavaFileHandle = implClassJavaFileHandle;
694 }
695
696 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530697 * Returns attribute's temporary file handle.
698 *
699 * @return temporary file handle
700 */
701 public File getAttributesTempFileHandle() {
702 return attributesTempFileHandle;
703 }
704
705 /**
706 * Sets attribute's temporary file handle.
707 *
708 * @param attributeForClass file handle for attribute
709 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530710 void setAttributesTempFileHandle(File attributeForClass) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530711 attributesTempFileHandle = attributeForClass;
712 }
713
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530714 /**
715 * Returns getter method's impl's temporary file handle.
716 *
717 * @return temporary file handle
718 */
719 public File getGetterImplTempFileHandle() {
720 return getterImplTempFileHandle;
721 }
722
723 /**
724 * Sets to getter method's impl's temporary file handle.
725 *
726 * @param getterImpl file handle for to getter method's impl
727 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530728 void setGetterImplTempFileHandle(File getterImpl) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530729 getterImplTempFileHandle = getterImpl;
730 }
731
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530732 /**
733 * Returns hash code method's temporary file handle.
734 *
735 * @return temporary file handle
736 */
737 public File getHashCodeImplTempFileHandle() {
738 return hashCodeImplTempFileHandle;
739 }
740
741 /**
742 * Sets hash code method's temporary file handle.
743 *
744 * @param hashCodeMethod file handle for hash code method
745 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530746 void setHashCodeImplTempFileHandle(File hashCodeMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530747 hashCodeImplTempFileHandle = hashCodeMethod;
748 }
749
750 /**
751 * Returns equals mehtod's temporary file handle.
752 *
753 * @return temporary file handle
754 */
755 public File getEqualsImplTempFileHandle() {
756 return equalsImplTempFileHandle;
757 }
758
759 /**
760 * Sets equals method's temporary file handle.
761 *
762 * @param equalsMethod file handle for to equals method
763 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530764 void setEqualsImplTempFileHandle(File equalsMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530765 equalsImplTempFileHandle = equalsMethod;
766 }
767
768 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530769 * Returns to string method's temporary file handle.
770 *
771 * @return temporary file handle
772 */
773 public File getToStringImplTempFileHandle() {
774 return toStringImplTempFileHandle;
775 }
776
777 /**
778 * Sets to string method's temporary file handle.
779 *
780 * @param toStringMethod file handle for to string method
781 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530782 void setToStringImplTempFileHandle(File toStringMethod) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530783 toStringImplTempFileHandle = toStringMethod;
784 }
785
786 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530787 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530788 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530789 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530790 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530791 public JavaExtendsListHolder getJavaExtendsListHolder() {
792 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530793 }
794
795 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530796 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530797 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530798 * @param javaExtendsListHolder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530799 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530800 public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
801 this.javaExtendsListHolder = javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530802 }
803
804 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530805 * Adds attribute for class.
806 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530807 * @param attr attribute info
808 * @param yangPluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530809 * @throws IOException when fails to append to temporary file
810 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530811 private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530812 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530813 appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
814 + FOUR_SPACE_INDENTATION);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530815 }
816
817 /**
818 * Adds getter for interface.
819 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530820 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530821 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530822 * @throws IOException when fails to append to temporary file
823 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530824 private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530825 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +0530826 appendToFile(getGetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530827 getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530828 }
829
830 /**
831 * Adds setter for interface.
832 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530833 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530834 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530835 * @throws IOException when fails to append to temporary file
836 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530837 private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530838 throws IOException {
839 appendToFile(getSetterInterfaceTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530840 getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
841 + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530842 }
843
844 /**
845 * Adds setter's implementation for class.
846 *
847 * @param attr attribute info
848 * @throws IOException when fails to append to temporary file
849 */
850 private void addSetterImpl(JavaAttributeInfo attr)
851 throws IOException {
852 appendToFile(getSetterImplTempFileHandle(),
Bharat saraswal250a7472016-05-12 13:16:57 +0530853 getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
854 +
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530855 NEW_LINE);
856 }
857
858 /**
859 * Adds getter method's impl for class.
860 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530861 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530862 * @param pluginConfig plugin configurations
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530863 * @throws IOException when fails to append to temporary file
864 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530865 private void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530866 throws IOException {
867 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
868 || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
869 appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
870 getGeneratedJavaFiles()) + NEW_LINE);
871 } else {
janani b703cfe42016-05-17 13:12:22 +0530872 appendToFile(getGetterImplTempFileHandle(),
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530873 getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
janani b703cfe42016-05-17 13:12:22 +0530874 + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530875 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530876 }
877
878 /**
879 * Adds build method for interface.
880 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530881 * @param pluginConfig plugin configurations
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530882 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530883 * @throws IOException when fails to append to temporary file
884 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530885 String addBuildMethodForInterface(YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530886 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530887 return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530888 }
889
890 /**
891 * Adds build method's implementation for class.
892 *
893 * @return build method implementation for class
894 * @throws IOException when fails to append to temporary file
895 */
896 String addBuildMethodImpl()
897 throws IOException {
898 return getBuildString(getGeneratedJavaClassName()) + NEW_LINE;
899 }
900
901 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530902 * Adds default constructor for class.
903 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530904 * @param modifier modifier for constructor.
905 * @param toAppend string which need to be appended with the class name
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530906 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530907 * @return default constructor for class
908 * @throws IOException when fails to append to file
909 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530910 String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530911 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530912 return NEW_LINE
913 + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530914 }
915
916 /**
917 * Adds default constructor for class.
918 *
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530919 * @param pluginCnfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530920 * @return default constructor for class
921 * @throws IOException when fails to append to file
922 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530923 public String addOfMethod(YangPluginConfig pluginCnfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530924 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530925 return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530926 + getOfMethod(getGeneratedJavaClassName(), null);
927 }
928
929 /**
930 * Adds hash code method for class.
931 *
932 * @param attr attribute info
933 * @throws IOException when fails to append to temporary file
934 */
935 private void addHashCodeMethod(JavaAttributeInfo attr)
936 throws IOException {
937 appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
938 }
939
940 /**
941 * Adds equals method for class.
942 *
943 * @param attr attribute info
944 * @throws IOException when fails to append to temporary file
945 */
946 private void addEqualsMethod(JavaAttributeInfo attr)
947 throws IOException {
948 appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
949 }
950
951 /**
952 * Adds ToString method for class.
953 *
954 * @param attr attribute info
955 * @throws IOException when fails to append to temporary file
956 */
957 private void addToStringMethod(JavaAttributeInfo attr)
958 throws IOException {
959 appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
960 }
961
962 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530963 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530964 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530965 * @param javaAttributeInfo type attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +0530966 * @param fromStringAttributeInfo from string attribute info
967 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530968 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530969 private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
970 JavaAttributeInfo fromStringAttributeInfo)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530971 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +0530972 appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
973 fromStringAttributeInfo) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530974 }
975
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530976 /**
977 * Returns a temporary file handle for the specific file type.
978 *
979 * @param fileName file name
980 * @return temporary file handle
981 * @throws IOException when fails to create new file handle
982 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530983 File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530984 throws IOException {
985 String path = getTempDirPath();
986 File dir = new File(path);
987 if (!dir.exists()) {
988 dir.mkdirs();
989 }
990 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
991 if (!file.exists()) {
992 file.createNewFile();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530993 } else {
994 throw new IOException(fileName + " is reused due to YANG naming");
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530995 }
996 return file;
997 }
998
999 /**
1000 * Returns a temporary file handle for the specific file type.
1001 *
1002 * @param fileName file name
1003 * @return temporary file handle
1004 * @throws IOException when fails to create new file handle
1005 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301006 File getJavaFileHandle(String fileName)
1007 throws IOException {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301008 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1009 }
1010
1011 /**
1012 * Returns data from the temporary files.
1013 *
1014 * @param file temporary file handle
1015 * @return stored data from temporary files
1016 * @throws IOException when failed to get data from the given file
1017 */
1018 public String getTemporaryDataFromFileHandle(File file)
1019 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301020
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301021 String path = getTempDirPath();
1022 if (new File(path + file.getName()).exists()) {
1023 return readAppendFile(path + file.getName(), EMPTY_STRING);
1024 } else {
1025 throw new IOException("Unable to get data from the given "
1026 + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
1027 }
1028 }
1029
1030 /**
1031 * Returns temporary directory path.
1032 *
1033 * @return directory path
1034 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301035 String getTempDirPath() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301036 return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName()
1037 + TEMP_FOLDER_NAME_SUFIX + SLASH;
1038 }
1039
1040 /**
1041 * Parses attribute to get the attribute string.
1042 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301043 * @param attr attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301044 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301045 * @return attribute string
1046 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301047 public String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301048 /*
1049 * TODO: check if this utility needs to be called or move to the caller
1050 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301051 String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301052 if (attr.isQualifiedName()) {
Bharat saraswal250a7472016-05-12 13:16:57 +05301053 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
1054 attr.getImportInfo().getClassInfo(),
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301055 attributeName, attr.isListAttr());
1056 } else {
1057 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
1058 attr.isListAttr());
1059 }
1060 }
1061
1062 /**
1063 * Appends content to temporary file.
1064 *
1065 * @param file temporary file
1066 * @param data data to be appended
1067 * @throws IOException when fails to append to file
1068 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301069 void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301070 throws IOException {
1071 try {
1072 insertDataIntoJavaFile(file, data);
1073 } catch (IOException ex) {
1074 throw new IOException("failed to write in temp file.");
1075 }
1076 }
1077
1078 /**
1079 * Adds current node info as and attribute to the parent generated file.
1080 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301081 * @param curNode current node which needs to be added as an attribute in
1082 * the parent generated code
1083 * @param isList is list construct
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301084 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301085 * @throws IOException IO operation exception
1086 */
1087 public static void addCurNodeInfoInParentTempFile(YangNode curNode,
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301088 boolean isList, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301089 throws IOException {
1090 YangNode parent = getParentNodeInGenCode(curNode);
1091 if (!(parent instanceof JavaCodeGenerator)) {
1092 throw new TranslatorException("missing parent node to contain current node info in generated file");
1093 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301094
1095 if (parent instanceof YangJavaGrouping) {
1096 /*
1097 * In case of grouping, there is no need to add the information, it will be taken care in
1098 * uses
1099 */
1100 return;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301101 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301102
1103 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301104 parent, isList);
1105 if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
1106 throw new TranslatorException("missing parent temp file handle");
1107 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301108 getNodesInterfaceFragmentFiles(parent)
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301109 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301110 }
1111
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301112
1113 /**
1114 * Adds current node info as and attribute to the parent generated file.
1115 *
1116 * @param curNode current node which needs to be added as an attribute in
1117 * the parent generated code
1118 * @param pluginConfig plugin configurations
1119 * @param targetNode target node to add the attribute
1120 * @throws IOException IO operation exception
1121 */
1122 public static void addCurNodeAsAttributeInTargetTempFile(YangNode curNode,
1123 YangPluginConfig pluginConfig, YangNode targetNode)
1124 throws IOException {
1125
1126 if (!(targetNode instanceof JavaCodeGenerator)) {
1127 throw new TranslatorException("invalid target node to generated file");
1128 }
1129
1130 if (targetNode instanceof YangJavaGrouping) {
1131 /*
1132 * In case of grouping, there is no need to add the information, it will be taken care in
1133 * uses
1134 */
1135 return;
1136 }
1137
1138 boolean isList = curNode instanceof YangList;
1139
1140 JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
1141 targetNode, isList);
1142 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
1143 throw new TranslatorException("missing target node's temp file handle");
1144 }
1145 getNodesInterfaceFragmentFiles(targetNode)
1146 .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
1147 }
1148
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301149 /**
1150 * Creates an attribute info object corresponding to a data model node and
1151 * return it.
1152 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301153 * @param curNode current data model node for which the java code generation
1154 * is being handled
1155 * @param targetNode target node in which the current node is an attribute
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301156 * @param isListNode is the current added attribute needs to be a list
1157 * @return AttributeInfo attribute details required to add in temporary
1158 * files
1159 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301160 public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
1161 YangNode targetNode, boolean isListNode) {
1162 String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
1163 if (curNodeName == null) {
1164 updateJavaFileInfo(curNode, null);
1165 curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
Bharat saraswal250a7472016-05-12 13:16:57 +05301166 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301167
1168 /*
1169 * Get the import info corresponding to the attribute for import in
1170 * generated java files or qualified access
1171 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301172 JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
1173 getCapitalCase(curNodeName));
1174 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
1175 throw new TranslatorException("Parent node does not have file info");
1176 }
1177 TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(targetNode);
1178 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
1179 JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301180
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301181 boolean isQualified;
1182 if ((targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule)
1183 && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
1184 || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
1185 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
1186 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
1187 || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
1188 || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE))
1189 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
1190 || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
1191
1192 isQualified = true;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301193 } else {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301194 String className;
1195 if (targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule) {
1196 className = getCapitalCase(fileInfo.getJavaName()) + "Service";
1197 } else {
1198 className = getCapitalCase(fileInfo.getJavaName());
1199 }
1200
1201 isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
1202 className, fileInfo.getPackage());
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301203 }
1204
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301205 if (isListNode) {
1206 parentImportData.setIfListImported(true);
Bharat saraswal250a7472016-05-12 13:16:57 +05301207 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301208
1209
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301210 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
1211 }
1212
Bharat saraswal250a7472016-05-12 13:16:57 +05301213 /**
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301214 * Resolves groupings java qualified info.
1215 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301216 * @param curNode grouping node
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +05301217 * @param pluginConfig plugin configurations
1218 * @return groupings java qualified info
1219 */
1220 public static JavaQualifiedTypeInfo resolveGroupingsQuailifiedInfo(YangNode curNode,
1221 YangPluginConfig pluginConfig) {
1222
1223 JavaFileInfo groupingFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1224 JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
1225 if (groupingFileInfo.getPackage() == null) {
1226 List<String> parentNames = new ArrayList<>();
1227
1228 YangNode tempNode = curNode.getParent();
1229 YangNode groupingSuperParent = null;
1230 while (tempNode != null) {
1231 parentNames.add(tempNode.getName());
1232 groupingSuperParent = tempNode;
1233 tempNode = tempNode.getParent();
1234 }
1235
1236 String pkg = null;
1237 JavaFileInfo parentInfo = ((JavaFileInfoContainer) groupingSuperParent).getJavaFileInfo();
1238 if (parentInfo.getPackage() == null) {
1239 if (groupingSuperParent instanceof YangJavaModule) {
1240 YangJavaModule module = (YangJavaModule) groupingSuperParent;
1241 String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
1242 .getRevision().getRevDate(), pluginConfig.getConflictResolver());
1243 pkg = modulePkg;
1244 } else if (groupingSuperParent instanceof YangJavaSubModule) {
1245 YangJavaSubModule submodule = (YangJavaSubModule) groupingSuperParent;
1246 String subModulePkg = getRootPackage(submodule.getVersion(),
1247 submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
1248 submodule.getRevision().getRevDate(), pluginConfig.getConflictResolver());
1249 pkg = subModulePkg;
1250 }
1251 } else {
1252 pkg = parentInfo.getPackage();
1253 }
1254 for (String name : parentNames) {
1255 pkg = pkg + PERIOD + getCamelCase(name, pluginConfig.getConflictResolver());
1256 }
1257
1258 qualifiedTypeInfo.setPkgInfo(pkg.toLowerCase());
1259 qualifiedTypeInfo.setClassInfo(
1260 getCapitalCase(getCamelCase(curNode.getName(), pluginConfig.getConflictResolver())));
1261 return qualifiedTypeInfo;
1262
1263 } else {
1264 qualifiedTypeInfo.setPkgInfo(groupingFileInfo.getPackage().toLowerCase());
1265 qualifiedTypeInfo.setClassInfo(getCapitalCase(groupingFileInfo.getJavaName()));
1266 return qualifiedTypeInfo;
1267 }
1268 }
1269
1270 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301271 * Returns interface fragment files for node.
1272 *
1273 * @param node YANG node
1274 * @return interface fragment files for node
1275 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301276 public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) {
1277 TempJavaFragmentFiles tempJavaFragmentFiles;
1278 if (node instanceof RpcNotificationContainer) {
1279 tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
1280 .getTempJavaCodeFragmentFiles()
1281 .getServiceTempFiles();
1282 } else {
1283 tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
1284 .getTempJavaCodeFragmentFiles()
1285 .getBeanTempFiles();
1286 }
1287 return tempJavaFragmentFiles;
1288 }
1289
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301290 /**
1291 * Adds parent's info to current node import list.
1292 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301293 * @param curNode current node for which import list needs to be updated
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301294 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301295 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301296 public void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301297 caseImportInfo = new JavaQualifiedTypeInfo();
1298 YangNode parent = getParentNodeInGenCode(curNode);
1299 if (!(parent instanceof JavaCodeGenerator)) {
1300 throw new TranslatorException("missing parent node to contain current node info in generated file");
1301 }
1302 if (!(curNode instanceof JavaFileInfoContainer)) {
1303 throw new TranslatorException("missing java file information to get the package details "
1304 + "of attribute corresponding to child node");
1305 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301306 caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
1307 pluginConfig.getConflictResolver())));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301308 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301309
1310 JavaFileInfo fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
1311
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301312 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301313 .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
1314 getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301315 }
1316
1317 /**
1318 * Adds leaf attributes in generated files.
1319 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301320 * @param listOfLeaves list of YANG leaf
1321 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301322 * @throws IOException IO operation fail
1323 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301324 public void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301325 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301326 throws IOException {
1327 if (listOfLeaves != null) {
1328 for (YangLeaf leaf : listOfLeaves) {
1329 if (!(leaf instanceof JavaLeafInfoContainer)) {
1330 throw new TranslatorException("Leaf does not have java information");
1331 }
1332 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301333 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301334 javaLeaf.updateJavaQualifiedInfo();
1335 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
1336 javaLeaf.getJavaQualifiedInfo(),
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301337 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1338 javaLeaf.getDataType(),
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301339 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1340 false);
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301341 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301342 }
1343 }
1344 }
1345
1346 /**
1347 * Adds leaf list's attributes in generated files.
1348 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301349 * @param listOfLeafList list of YANG leaves
1350 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301351 * @throws IOException IO operation fail
1352 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301353 public void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301354 throws IOException {
1355 if (listOfLeafList != null) {
1356 for (YangLeafList leafList : listOfLeafList) {
1357 if (!(leafList instanceof JavaLeafInfoContainer)) {
1358 throw new TranslatorException("Leaf-list does not have java information");
1359 }
1360 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301361 javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301362 javaLeaf.updateJavaQualifiedInfo();
Bharat saraswal250a7472016-05-12 13:16:57 +05301363 getJavaImportData().setIfListImported(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301364 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
1365 javaLeaf.getJavaQualifiedInfo(),
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301366 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
1367 javaLeaf.getDataType(),
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301368 getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
1369 true);
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301370 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301371 }
1372 }
1373 }
1374
1375 /**
1376 * Adds all the leaves in the current data model node as part of the
1377 * generated temporary file.
1378 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301379 * @param curNode java file info of the generated file
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301380 * @param yangPluginConfig plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301381 * @throws IOException IO operation fail
1382 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301383 public void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
1384 YangPluginConfig yangPluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301385 throws IOException {
1386 if (!(curNode instanceof YangLeavesHolder)) {
1387 throw new TranslatorException("Data model node does not have any leaves");
1388 }
1389 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301390 addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig);
1391 addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301392 }
1393
1394 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301395 * Adds the new attribute info to the target generated temporary files.
1396 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301397 * @param newAttrInfo the attribute info that needs to be added to temporary
1398 * files
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301399 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301400 * @throws IOException IO operation fail
1401 */
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301402 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301403 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301404 setAttributePresent(true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301405 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301406 addAttribute(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301407 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301408
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301409 if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301410 addGetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301411 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301412
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301413 if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301414 addSetterForInterface(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301415 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301416
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301417 if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
1418 addSetterImpl(newAttrInfo);
1419 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301420
1421 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301422 addGetterImpl(newAttrInfo, pluginConfig);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301423 }
1424 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1425 addHashCodeMethod(newAttrInfo);
1426 }
1427 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1428 addEqualsMethod(newAttrInfo);
1429 }
1430 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1431 addToStringMethod(newAttrInfo);
1432 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301433
1434 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301435 JavaQualifiedTypeInfo qualifiedInfoOfFromString =
1436 getQualifiedInfoOfFromString(newAttrInfo, pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301437 /*
1438 * Create a new java attribute info with qualified information of
1439 * wrapper classes.
1440 */
1441 JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1442 newAttrInfo.getAttributeName(),
1443 newAttrInfo.getAttributeType(),
1444 getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
1445
1446 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301447 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301448 }
1449
1450 /**
1451 * Returns java class name.
1452 *
1453 * @param suffix for the class name based on the file type
1454 * @return java class name
1455 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301456 String getJavaClassName(String suffix) {
janani b703cfe42016-05-17 13:12:22 +05301457 return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301458 }
1459
1460 /**
1461 * Returns the directory path.
1462 *
1463 * @return directory path
1464 */
1465 private String getDirPath() {
1466 return getJavaFileInfo().getPackageFilePath();
1467 }
1468
1469 /**
1470 * Constructs java code exit.
1471 *
1472 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301473 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301474 * @throws IOException when fails to generate java files
1475 */
1476 public void generateJavaFile(int fileType, YangNode curNode)
1477 throws IOException {
1478 List<String> imports = new ArrayList<>();
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301479 imports = getJavaImportData().getImports();
1480
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301481 createPackage(curNode);
1482
1483 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301484 * Generate java code.
1485 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301486 if ((fileType & INTERFACE_MASK) != 0 || (fileType &
1487 BUILDER_INTERFACE_MASK) != 0) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301488
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301489 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301490 * Create interface file.
1491 */
1492 setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
1493 setInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301494 generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
1495 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301496 * Create builder interface file.
1497 */
1498 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
1499 setBuilderInterfaceJavaFileHandle(
1500 getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
1501 setBuilderInterfaceJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301502 generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
1503 isAttributePresent()));
1504 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301505 * Append builder interface file to interface file and close it.
1506 */
1507 mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
1508 }
1509 insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301510 if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
1511 addAugmentationHoldersImport(curNode, imports, false);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301512 }
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301513 if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301514 addAugmentedInfoImport(curNode, imports, false);
1515 }
1516 if (curNode instanceof YangCase) {
1517 removeCaseImport(imports);
1518 }
1519 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301520 if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301521 if (isAttributePresent()) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301522 addImportsToStringAndHasCodeMethods(curNode, imports);
1523 }
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301524 if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301525 addAugmentedInfoImport(curNode, imports, true);
1526 addArrayListImport(curNode, imports, true);
1527 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301528 sortImports(imports);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301529 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301530 * Create builder class file.
1531 */
1532 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1533 setBuilderClassJavaFileHandle(
Bharat saraswal250a7472016-05-12 13:16:57 +05301534 generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode,
1535 isAttributePresent()));
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301536 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301537 * Create impl class file.
1538 */
1539 if ((fileType & IMPL_CLASS_MASK) != 0) {
1540 setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
1541 setImplClassJavaFileHandle(
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301542 generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent()));
1543 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301544 * Append impl class to builder class and close it.
1545 */
1546 mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
1547 }
1548 insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
Bharat saraswal4aaab4d2016-05-17 14:19:38 +05301549 if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
1550 addAugmentedInfoImport(curNode, imports, false);
1551 addArrayListImport(curNode, imports, false);
1552 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301553 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301554 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301555 * Close all the file handles.
1556 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301557 freeTemporaryResources(false);
1558 }
1559
1560 /**
1561 * Adds imports for ToString and HashCodeMethod.
1562 *
1563 * @param curNode current YANG node
1564 * @param imports import list
1565 * @return import list
1566 */
1567 public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
1568 imports.add(getJavaImportData().getImportForHashAndEquals());
1569 imports.add(getJavaImportData().getImportForToString());
1570 return imports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301571 }
1572
1573 /**
1574 * Removes case import info from import list.
1575 *
1576 * @param imports list of imports
1577 * @return import for class
1578 */
1579 private List<String> removeCaseImport(List<String> imports) {
1580 if (imports != null && caseImportInfo != null) {
1581 String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
1582 SEMI_COLAN + NEW_LINE;
1583 imports.remove(caseImport);
1584 }
1585 return imports;
1586 }
1587
1588 /**
1589 * Removes all temporary file handles.
1590 *
1591 * @param isErrorOccurred when translator fails to generate java files we
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301592 * need to close all open file handles include temporary files
1593 * and java files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301594 * @throws IOException when failed to delete the temporary files
1595 */
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301596 public void freeTemporaryResources(boolean isErrorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301597 throws IOException {
1598 boolean isError = isErrorOccurred;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301599 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301600 * Close all java file handles and when error occurs delete the files.
1601 */
1602 if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
1603 closeFile(getInterfaceJavaFileHandle(), isError);
1604 }
1605 if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
1606 closeFile(getBuilderClassJavaFileHandle(), isError);
1607 }
1608 if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
1609 closeFile(getBuilderInterfaceJavaFileHandle(), true);
1610 }
1611 if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
1612 closeFile(getImplClassJavaFileHandle(), true);
1613 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301614
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301615 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301616 * Close all temporary file handles and delete the files.
1617 */
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301618 if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
1619 closeFile(getGetterImplTempFileHandle(), true);
1620 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301621 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
1622 closeFile(getAttributesTempFileHandle(), true);
1623 }
1624 if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
1625 closeFile(getHashCodeImplTempFileHandle(), true);
1626 }
1627 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1628 closeFile(getToStringImplTempFileHandle(), true);
1629 }
1630 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1631 closeFile(getEqualsImplTempFileHandle(), true);
1632 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301633 if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1634 closeFile(getFromStringImplTempFileHandle(), true);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301635 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301636 }
1637
1638 /**
1639 * Returns if the attribute needs to be accessed in a qualified manner or
1640 * not, if it needs to be imported, then the same needs to be done.
1641 *
1642 * @param importInfo import info for the current attribute being added
1643 * @return status of the qualified access to the attribute
1644 */
1645 public boolean getIsQualifiedAccessOrAddToImportList(
1646 JavaQualifiedTypeInfo importInfo) {
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301647
1648 return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(),
1649 getJavaFileInfo().getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301650 }
1651
1652 /**
1653 * Checks if the import info is same as the package of the current generated
1654 * java file.
1655 *
1656 * @param importInfo import info for an attribute
1657 * @return true if the import info is same as the current nodes package
1658 * false otherwise
1659 */
1660 public boolean isImportPkgEqualCurNodePkg(JavaQualifiedTypeInfo importInfo) {
1661 return getJavaFileInfo().getPackage()
1662 .contentEquals(importInfo.getPkgInfo());
1663 }
1664}