blob: ec97d8e2c19ecc2d0710492ced0e74eb6416ede6 [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
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053018import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
Bharat saraswale50edca2016-08-05 01:58:25 +053019import org.onosproject.yangutils.datamodel.YangAugment;
Bharat saraswalaf413b82016-07-14 15:18:20 +053020import org.onosproject.yangutils.datamodel.YangAugmentableNode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053021import org.onosproject.yangutils.datamodel.YangCase;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053022import org.onosproject.yangutils.datamodel.YangChoice;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053023import org.onosproject.yangutils.datamodel.YangLeaf;
24import org.onosproject.yangutils.datamodel.YangLeafList;
25import org.onosproject.yangutils.datamodel.YangLeavesHolder;
Vidyashree Ramab3670472016-08-06 15:49:56 +053026import org.onosproject.yangutils.datamodel.YangList;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053027import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053028import org.onosproject.yangutils.datamodel.YangType;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053029import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053030import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053031import org.onosproject.yangutils.translator.exception.TranslatorException;
32import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Shankara-Huaweib7564772016-08-02 18:13:13 +053033import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053034import org.onosproject.yangutils.translator.tojava.utils.BitsJavaInfoHandler;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053035import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053036import org.onosproject.yangutils.utils.io.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053037
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053038import java.io.File;
39import java.io.IOException;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053040import java.util.ArrayList;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053041import java.util.List;
42
Bharat saraswalc2d3be12016-06-16 00:29:12 +053043import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
45import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
Bharat saraswalaf413b82016-07-14 15:18:20 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Bharat saraswal54e4bab2016-10-05 23:32:14 +053049import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053050import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
52import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053054import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053055import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053056import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
57import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
58import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
Bharat saraswal250a7472016-05-12 13:16:57 +053059import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053060import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
61import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
62import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053063import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053064import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
65import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
66import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
67import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Shankara-Huaweib7564772016-08-02 18:13:13 +053068import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
69import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053070import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
Bharat saraswal8beac342016-08-04 02:00:03 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
72import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
Bharat saraswalaf413b82016-07-14 15:18:20 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
75import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswal8beac342016-08-04 02:00:03 +053076import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053077import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053078import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswald14cbe82016-07-14 13:26:18 +053079import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
Bharat saraswal8beac342016-08-04 02:00:03 +053080import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
84import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053085import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053086import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
87import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
88import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
90import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
91import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053092import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053093import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053094import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
95import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
96import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
97import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
98import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
99import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
100import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
101import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
102import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
Bharat saraswal8beac342016-08-04 02:00:03 +0530103import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530104import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530105import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530106import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530107import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530108import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530109import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
110import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530111import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530112import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530113import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_PKG;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530114import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530115import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
116import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_CLASS;
Bharat saraswal8beac342016-08-04 02:00:03 +0530117import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530118import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530119import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
120import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530121import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530122import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530123import static org.onosproject.yangutils.utils.UtilConstants.YANG;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530124import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530125import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswal8beac342016-08-04 02:00:03 +0530126import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530127import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswale304c252016-08-16 20:56:20 +0530128import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530129import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530130import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530131import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
132import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
133import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530134import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
135import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530136import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530137
138/**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530139 * Represents implementation of java code fragments temporary implementations.
140 * Manages the common temp file required for Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530141 */
142public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530143
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530144 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530145 * File type extension for java classes.
146 */
147 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530148
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530149 /**
150 * File type extension for temporary classes.
151 */
152 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530153
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530154 /**
155 * Folder suffix for temporary files folder.
156 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530157 private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530158
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530159 /**
160 * File name for getter method.
161 */
162 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530163
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530164 /**
165 * File name for setter method.
166 */
167 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530168
169 /**
170 * File name for getter method implementation.
171 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530172 private static final String GETTER_METHOD_IMPL_FILE_NAME =
173 "GetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530174
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530175 /**
176 * File name for setter method implementation.
177 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530178 private static final String SETTER_METHOD_IMPL_FILE_NAME =
179 "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530180
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530181 /**
182 * File name for attributes.
183 */
184 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530185
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530186 /**
187 * File name for to string method.
188 */
189 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530190
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530191 /**
192 * File name for hash code method.
193 */
194 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530195
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530196 /**
197 * File name for equals method.
198 */
199 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530200
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530201 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530202 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530203 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530204 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530205
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530206 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530207 * File name for from add to list interface method.
208 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530209 private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME =
210 "addToList";
Bharat saraswal8beac342016-08-04 02:00:03 +0530211
212 /**
213 * File name for from add to list impl method.
214 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530215 private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME =
216 "addToListImpl";
Bharat saraswal8beac342016-08-04 02:00:03 +0530217
218 /**
219 * File name for from leaf identifier attributes.
220 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530221 private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME =
222 "leafIdentifierAtr";
Bharat saraswal8beac342016-08-04 02:00:03 +0530223
224 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530225 * File name for is filter content leaf match.
226 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530227 private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME =
228 "isFilterContentMatchLeafMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530229
230 /**
231 * File name for is filter content leaf-list match.
232 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530233 private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME =
234 "isFilterContentMatchLeafListMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530235
236 /**
237 * File name for is filter content node match.
238 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530239 private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME =
240 "isFilterContentMatchNodeMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530241
242 /**
243 * File name for edit content file.
244 */
245 private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
246
247 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530248 * File name for interface java file name suffix.
249 */
250 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530251
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530252 /**
253 * File name for builder interface file name suffix.
254 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530255 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX =
256 BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530257
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530258 /**
259 * File name for builder class file name suffix.
260 */
261 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530262
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530263 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530264 * Information about the java files being generated.
265 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530266 private JavaFileInfoTranslator javaFileInfo;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530267
268 /**
269 * Imported class info.
270 */
271 private JavaImportData javaImportData;
272
273 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530274 * The variable which guides the types of temporary files generated using
275 * the temporary generated file types mask.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530276 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530277 private int tempFilesFlagSet;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530278
279 /**
280 * Absolute path where the target java file needs to be generated.
281 */
282 private String absoluteDirPath;
283
284 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530285 * Contains all the interface(s)/class name which will be extended by
286 * generated files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530287 */
288 private JavaExtendsListHolder javaExtendsListHolder;
289
Bharat saraswald14cbe82016-07-14 13:26:18 +0530290 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530291 * Java file handle for interface file.
292 */
293 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530294
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530295 /**
296 * Java file handle for builder interface file.
297 */
298 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530299
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530300 /**
301 * Java file handle for builder class file.
302 */
303 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530304
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530305 /**
306 * Java file handle for impl class file.
307 */
308 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530309
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530310 /**
311 * Temporary file handle for attribute.
312 */
313 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530314
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530315 /**
316 * Temporary file handle for getter of interface.
317 */
318 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530319
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530320 /**
321 * Temporary file handle for setter of interface.
322 */
323 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530324
325 /**
326 * Temporary file handle for getter of class.
327 */
328 private File getterImplTempFileHandle;
329
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530330 /**
331 * Temporary file handle for setter of class.
332 */
333 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530334
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530335 /**
336 * Temporary file handle for hash code method of class.
337 */
338 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530339
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530340 /**
341 * Temporary file handle for equals method of class.
342 */
343 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530344
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530345 /**
346 * Temporary file handle for to string method of class.
347 */
348 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530349
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530350 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530351 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530352 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530353 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530354
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530355 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530356 * Temporary file handle for add to list interface method of class.
357 */
358 private File addToListInterfaceTempFileHandle;
359
360 /**
361 * Temporary file handle for add to list impl method of class.
362 */
363 private File addToListImplTempFileHandle;
364
365 /**
366 * Temporary file handle for leaf id attributes of enum.
367 */
368 private File leafIdAttributeTempFileHandle;
369
370 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530371 * Temporary file handle for is content match method for leaf-list.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530372 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530373 private File getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530374
375 /**
376 * Temporary file handle for is content match method for node.
377 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530378 private File getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530379
380 /**
381 * Temporary file handle for is content match method for leaf.
382 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530383 private File subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530384
385 /**
386 * Temporary file handle for edit content file.
387 */
388 private File editContentTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530389
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530390 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530391 * Leaf count.
392 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530393 private int leafCount;
Bharat saraswal8beac342016-08-04 02:00:03 +0530394
395 /**
396 * If current node is root node.
397 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530398 private boolean rootNode;
Bharat saraswal8beac342016-08-04 02:00:03 +0530399
400 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530401 * Is attribute added.
402 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530403 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530404
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530405 /**
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530406 * List of bits attributes.
407 */
408 private List<BitsJavaInfoHandler> bitsHandler = new ArrayList<>();
409
410 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530411 * Creates an instance of temp JAVA fragment files.
412 */
Bharat saraswalaf413b82016-07-14 15:18:20 +0530413 TempJavaFragmentFiles() {
414 }
415
416 /**
417 * Creates an instance of temporary java code fragment.
418 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530419 * @param fileInfo generated java file information
Bharat saraswalaf413b82016-07-14 15:18:20 +0530420 * @throws IOException when fails to create new file handle
421 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530422 protected TempJavaFragmentFiles(JavaFileInfoTranslator fileInfo)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530423 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530424 javaExtendsListHolder = new JavaExtendsListHolder();
425 javaImportData = new JavaImportData();
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530426 javaFileInfo = fileInfo;
427 absoluteDirPath = getAbsolutePackagePath(fileInfo.getBaseCodeGenPath(),
428 fileInfo.getPackageFilePath());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530429 /*
430 * Initialize getter when generation file type matches to interface
431 * mask.
432 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530433 if (javaFlagSet(INTERFACE_MASK)) {
434 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
435 ADD_TO_LIST_INTERFACE_MASK |
436 LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530437 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530438 /*
439 * Initialize getter and setter when generation file type matches to
440 * builder interface mask.
441 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530442 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
443 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
444 SETTER_FOR_INTERFACE_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530445 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530446 /*
447 * Initialize getterImpl, setterImpl and attributes when generation file
448 * type matches to builder class mask.
449 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530450 if (javaFlagSet(BUILDER_CLASS_MASK)) {
451 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
452 SETTER_FOR_CLASS_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530453 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530454 /*
455 * Initialize getterImpl, attributes, constructor, hash code, equals and
456 * to strings when generation file type matches to impl class mask.
457 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530458 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
459 addGeneratedTempFile(
460 ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
461 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
462 TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
463 FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
464 FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
465 FILTER_CONTENT_MATCH_FOR_NODES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530466 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530467 /*
468 * Initialize temp files to generate type class.
469 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530470 if (javaFlagSet(GENERATE_TYPE_CLASS)) {
471 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
472 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530473 FROM_STRING_IMPL_MASK);
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530474
475 if (getGeneratedJavaFiles() != GENERATE_UNION_CLASS) {
476 addGeneratedTempFile(TO_STRING_IMPL_MASK);
477 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530478 }
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530479
Vidyashree Ramab3670472016-08-06 15:49:56 +0530480 //Set temporary file handles
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530481 if (tempFlagSet(ATTRIBUTES_MASK)) {
482 attributesTempFileHandle =
483 getTemporaryFileHandle(ATTRIBUTE_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530484 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530485 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
486 getterInterfaceTempFileHandle =
487 getTemporaryFileHandle(GETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530488 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530489 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
490 setterInterfaceTempFileHandle =
491 getTemporaryFileHandle(SETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530492 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530493 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
494 getterImplTempFileHandle =
495 getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530496 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530497 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
498 setterImplTempFileHandle =
499 getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530500 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530501 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
502 hashCodeImplTempFileHandle =
503 getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530504 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530505 if (tempFlagSet(EQUALS_IMPL_MASK)) {
506 equalsImplTempFileHandle =
507 getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530508 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530509 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
510 toStringImplTempFileHandle =
511 getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530512 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530513 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
514 fromStringImplTempFileHandle =
515 getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530516 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530517 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
518 addToListInterfaceTempFileHandle =
519 getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530520 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530521 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
522 addToListImplTempFileHandle =
523 getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530524 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530525 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
526 leafIdAttributeTempFileHandle =
527 getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530528 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530529 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
530 subtreeFilteringForLeafTempFileHandle =
531 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530532 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530533 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
534 getSubtreeFilteringForListTempFileHandle =
535 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530536 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530537 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
538 getSubtreeFilteringForChildNodeTempFileHandle =
539 getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530540 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530541 if (tempFlagSet(EDIT_CONTENT_MASK)) {
542 editContentTempFileHandle =
543 getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530544 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530545 }
546
547 /**
548 * Adds current node info as and attribute to the parent generated file.
549 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530550 * @param curNode current node
551 * @param isList is list construct
552 * @param config plugin configurations
Bharat saraswalaf413b82016-07-14 15:18:20 +0530553 * @throws IOException IO operation exception
554 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530555 protected static void addCurNodeInfoInParentTempFile(YangNode curNode,
556 boolean isList,
557 YangPluginConfig config)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530558 throws IOException {
559 YangNode parent = getParentNodeInGenCode(curNode);
560 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530561 throw new TranslatorException(getErrorMsg(MISSING_PARENT_NODE,
562 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530563 }
Shankara-Huaweib7564772016-08-02 18:13:13 +0530564 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530565 /*
566 * In case of grouping, there is no need to add the information, it
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530567 * will be taken care in uses.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530568 */
569 return;
570 }
Gaurav Agrawal9381ebb2016-09-29 19:00:33 +0530571 addCurNodeInfoInParentTempFile(curNode, isList, config, parent);
572 }
573
574 /**
575 * Adds current node info as and attribute to a specified parent generated
576 * file. In case of grouping parent will be referred grouping node or
577 * referred node in grouping.
578 *
579 * @param curNode current node
580 * @param isList is list construct
581 * @param config plugin configurations
582 * @param parent parent node
583 * @throws IOException IO operation exception
584 */
585 protected static void addCurNodeInfoInParentTempFile(
586 YangNode curNode, boolean isList, YangPluginConfig config,
587 YangNode parent)
588 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530589 TempJavaBeanFragmentFiles tempFiles =
590 getBeanFiles((JavaCodeGeneratorInfo) parent);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530591 JavaAttributeInfo attr =
592 getCurNodeAsAttributeInTarget(curNode, parent, isList,
593 tempFiles);
594 tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530595 }
596
597 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530598 * Creates an attribute info object corresponding to a data model node
599 * and return it.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530600 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530601 * @param curNode current node
602 * @param targetNode target node
603 * @param listNode flag indicating if a node is a list node
604 * @param tempFiles temp java fragment files
605 * @return java attribute info
Bharat saraswalaf413b82016-07-14 15:18:20 +0530606 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530607 public static JavaAttributeInfo
608 getCurNodeAsAttributeInTarget(YangNode curNode, YangNode targetNode,
609 boolean listNode,
610 TempJavaFragmentFiles tempFiles) {
611 JavaFileInfoTranslator translator =
612 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
613 String curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530614 if (curNodeName == null) {
615 updateJavaFileInfo(curNode, null);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530616 curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530617 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530618 /*
619 * Get the import info corresponding to the attribute for import in
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530620 * generated java files or qualified access.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530621 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530622 JavaQualifiedTypeInfoTranslator typeInfo =
623 getQualifiedTypeInfoOfCurNode(curNode,
624 getCapitalCase(curNodeName));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530625 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530626 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
627 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530628 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530629 JavaImportData parentImportData = tempFiles.getJavaImportData();
630 JavaFileInfoTranslator fileInfo =
631 ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530632
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530633 boolean qualified;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530634 if (tempFiles instanceof TempJavaServiceFragmentFiles &&
635 typeInfo.getClassInfo().contentEquals(SERVICE) ||
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530636 typeInfo.getClassInfo()
637 .contentEquals(getCapitalCase(fileInfo.getJavaName() +
638 SERVICE))) {
639 qualified = true;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530640 } else {
641 String className;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530642 if (tempFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530643 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530644 } else {
645 className = getCapitalCase(fileInfo.getJavaName());
646 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530647 qualified = parentImportData.addImportInfo(typeInfo, className,
648 fileInfo.getPackage());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530649 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530650 boolean collectionSet = false;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530651 if (curNode instanceof YangList) {
652 YangList yangList = (YangList) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530653 if (yangList.getCompilerAnnotation() != null &&
654 yangList.getCompilerAnnotation()
655 .getYangAppDataStructure() != null) {
656 switch (yangList.getCompilerAnnotation()
657 .getYangAppDataStructure().getDataStructure()) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530658 case QUEUE: {
659 parentImportData.setQueueToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530660 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530661 break;
662 }
663 case SET: {
664 parentImportData.setSetToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530665 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530666 break;
667 }
668 default: {
669 // TODO : to be implemented
670 }
671 }
672 }
673 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530674 if (listNode && !collectionSet) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530675 parentImportData.setIfListImported(true);
676 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530677 if (curNode instanceof YangList) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530678 return getAttributeInfoForTheData(typeInfo, curNodeName,
679 null, qualified, listNode,
680 ((YangList) curNode)
681 .getCompilerAnnotation());
Vidyashree Ramab3670472016-08-06 15:49:56 +0530682 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530683 return getAttributeInfoForTheData(typeInfo, curNodeName, null,
684 qualified, listNode);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530685 }
686
687 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530688 * Returns java attribute for leaf.
689 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530690 * @param tempFiles temporary generated file
691 * @param container JAVA leaf info container
692 * @param config plugin configurations
693 * @param leafList flag indicating if it's leaf list
694 * @return java attribute info
Bharat saraswal64e7e232016-07-14 23:33:55 +0530695 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530696 private static JavaAttributeInfo
697 getJavaAttributeOfLeaf(TempJavaFragmentFiles tempFiles,
698 JavaLeafInfoContainer container,
699 YangPluginConfig config, boolean leafList) {
700 if (leafList) {
701 tempFiles.getJavaImportData().setIfListImported(true);
702 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
703 true);
704 }
705 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
706 false);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530707 }
708
709 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530710 * Returns java attribute for leaf container.
Bharat saraswal64e7e232016-07-14 23:33:55 +0530711 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530712 * @param tempFiles temporary generated file
713 * @param container JAVA leaf info container
714 * @param config plugin configurations
715 * @param listAttribute flag indicating if list attribute
716 * @return JAVA attribute information
Bharat saraswal64e7e232016-07-14 23:33:55 +0530717 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530718 private static JavaAttributeInfo
719 getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
720 JavaLeafInfoContainer container,
721 YangPluginConfig config,
722 boolean listAttribute) {
723 container.setConflictResolveConfig(config.getConflictResolver());
724 container.updateJavaQualifiedInfo();
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530725 addImportForLeafInfo(tempFiles, container);
726 JavaAttributeInfo attr = getAttributeInfoForTheData(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530727 container.getJavaQualifiedInfo(),
728 container.getJavaName(config.getConflictResolver()),
729 container.getDataType(),
730 tempFiles.getIsQualifiedAccessOrAddToImportList(
731 container.getJavaQualifiedInfo()), listAttribute);
Bharat saraswal54e4bab2016-10-05 23:32:14 +0530732 if (container.getDataType().getDataType() == YangDataTypes.BITS) {
733 addBitsHandler(attr, container.getDataType(), tempFiles);
734 }
735 return attr;
736 }
737
738 /**
739 * Adds bits handler attribute for bits to string method.
740 *
741 * @param attr attribute
742 * @param type type
743 * @param tempFiles temp fragment file
744 */
745 static void addBitsHandler(JavaAttributeInfo attr, YangType type,
746 TempJavaFragmentFiles tempFiles) {
747 BitsJavaInfoHandler handler
748 = new BitsJavaInfoHandler(attr, type);
749 tempFiles.getBitsHandler().add(handler);
750 }
751
752 /**
753 * Adds attribute types import to leaf info container's parent.
754 *
755 * @param tempFiles temp java file
756 * @param container leaf info container
757 */
758 private static void addImportForLeafInfo(TempJavaFragmentFiles tempFiles,
759 JavaLeafInfoContainer container) {
760 String containedInCls = getCapitalCase(tempFiles.getJavaFileInfo()
761 .getJavaName());
762 String containedInPkg = tempFiles.getJavaFileInfo().getPackage();
763 JavaQualifiedTypeInfoTranslator info = new JavaQualifiedTypeInfoTranslator();
764 if (container.getDataType().getDataType() == YangDataTypes.BITS) {
765 //Add bitset import for type and leaf value flags.
766 info = new JavaQualifiedTypeInfoTranslator();
767 info.setClassInfo(BIT_SET);
768 info.setPkgInfo(JAVA_UTIL_PKG);
769 tempFiles.getJavaImportData().addImportInfo(info, containedInCls,
770 containedInPkg);
771 }
772 tempFiles.getJavaImportData().addImportInfo(
773 (JavaQualifiedTypeInfoTranslator) container
774 .getJavaQualifiedInfo(), containedInCls, containedInPkg);
775
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530776 }
777
778 /**
779 * Sets absolute path where the file needs to be generated.
780 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530781 * @param absoluteDirPath absolute path where the file needs to be
782 * generated
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530783 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530784 protected void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530785 this.absoluteDirPath = absoluteDirPath;
786 }
787
788 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530789 * Returns the generated java file information.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530790 *
791 * @return generated java file information
792 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530793 protected JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530794 return javaFileInfo;
795 }
796
797 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530798 * Sets the generated java file information.
799 *
800 * @param javaFileInfo generated java file information
801 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530802 protected void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530803 this.javaFileInfo = javaFileInfo;
804 }
805
806 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530807 * Returns the flag-set for generated temp files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530808 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530809 * @return flag-set
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530810 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530811 protected int getGeneratedTempFiles() {
812 return tempFilesFlagSet;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530813 }
814
815 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530816 * Adds to the flag-set for generated temp files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530817 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530818 * @param flags generated temp files flag-set
Bharat saraswalaf413b82016-07-14 15:18:20 +0530819 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530820 protected void addGeneratedTempFile(int flags) {
821 tempFilesFlagSet |= flags;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530822 }
823
824 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530825 * Returns the generated Java files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530826 *
827 * @return generated Java files
828 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530829 protected int getGeneratedJavaFiles() {
830 return javaFileInfo.getGeneratedFileTypes();
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530831 }
832
833 /**
834 * Retrieves the mapped Java class name.
835 *
836 * @return mapped Java class name
837 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530838 protected String getGeneratedJavaClassName() {
839 return getCapitalCase(javaFileInfo.getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530840 }
841
842 /**
843 * Retrieves the import data for the generated Java file.
844 *
845 * @return import data for the generated Java file
846 */
847 public JavaImportData getJavaImportData() {
848 return javaImportData;
849 }
850
851 /**
852 * Sets import data for the generated Java file.
853 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530854 * @param data import data for the generated Java file
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530855 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530856 protected void setJavaImportData(JavaImportData data) {
857 javaImportData = data;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530858 }
859
860 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530861 * Retrieves the status of any attributes added.
862 *
863 * @return status of any attributes added
864 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530865 protected boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530866 return isAttributePresent;
867 }
868
869 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530870 * Returns getter methods's temporary file handle.
871 *
872 * @return temporary file handle
873 */
874 public File getGetterInterfaceTempFileHandle() {
875 return getterInterfaceTempFileHandle;
876 }
877
878 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530879 * Returns setter method's temporary file handle.
880 *
881 * @return temporary file handle
882 */
883 public File getSetterInterfaceTempFileHandle() {
884 return setterInterfaceTempFileHandle;
885 }
886
887 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530888 * Returns setter method's impl's temporary file handle.
889 *
890 * @return temporary file handle
891 */
892 public File getSetterImplTempFileHandle() {
893 return setterImplTempFileHandle;
894 }
895
896 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530897 * Returns from string method's temporary file handle.
898 *
899 * @return from string method's temporary file handle
900 */
901 public File getFromStringImplTempFileHandle() {
902 return fromStringImplTempFileHandle;
903 }
904
905 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530906 * Returns attribute's temporary file handle.
907 *
908 * @return temporary file handle
909 */
910 public File getAttributesTempFileHandle() {
911 return attributesTempFileHandle;
912 }
913
914 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530915 * Returns getter method's impl's temporary file handle.
916 *
917 * @return temporary file handle
918 */
919 public File getGetterImplTempFileHandle() {
920 return getterImplTempFileHandle;
921 }
922
923 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530924 * Returns hash code method's temporary file handle.
925 *
926 * @return temporary file handle
927 */
928 public File getHashCodeImplTempFileHandle() {
929 return hashCodeImplTempFileHandle;
930 }
931
932 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530933 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530934 *
935 * @return temporary file handle
936 */
937 public File getEqualsImplTempFileHandle() {
938 return equalsImplTempFileHandle;
939 }
940
941 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530942 * Returns to string method's temporary file handle.
943 *
944 * @return temporary file handle
945 */
946 public File getToStringImplTempFileHandle() {
947 return toStringImplTempFileHandle;
948 }
949
950 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530951 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530952 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530953 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530954 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530955 public JavaExtendsListHolder getJavaExtendsListHolder() {
956 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530957 }
958
959 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530960 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530961 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530962 * @param holder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530963 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530964 protected void setJavaExtendsListHolder(
965 JavaExtendsListHolder holder) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530966 javaExtendsListHolder = holder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530967 }
968
969 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530970 * Adds is filter content match for leaf.
971 *
972 * @param attr java attribute
973 * @throws IOException when fails to do IO operations
974 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530975 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530976 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530977 appendToFile(subtreeFilteringForLeafTempFileHandle,
978 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
979 NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530980 }
981
982 /**
983 * Adds is filter content match for leaf-list.
984 *
985 * @param attr java attribute
986 * @throws IOException when fails to do IO operations
987 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530988 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530989 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530990 appendToFile(getSubtreeFilteringForListTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +0530991 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530992 }
993
994 /**
995 * Adds is filter content match for nodes.
996 *
997 * @param attr java attribute
998 * @throws IOException when fails to do IO operations
999 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301000 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +05301001 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301002 appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +05301003 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +05301004 }
1005
1006 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301007 * Adds attribute for class.
1008 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301009 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301010 * @throws IOException when fails to append to temporary file
1011 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301012 private void addAttribute(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301013 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301014 appendToFile(attributesTempFileHandle, parseAttribute(attr));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301015 }
1016
1017 /**
1018 * Adds getter for interface.
1019 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301020 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301021 * @throws IOException when fails to append to temporary file
1022 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301023 private void addGetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301024 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301025 appendToFile(getterInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301026 getGetterString(attr, getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301027 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301028 }
1029
1030 /**
1031 * Adds setter for interface.
1032 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301033 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301034 * @throws IOException when fails to append to temporary file
1035 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301036 private void addSetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301037 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301038 appendToFile(setterInterfaceTempFileHandle,
1039 getSetterString(attr, getGeneratedJavaClassName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301040 getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301041 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301042 }
1043
1044 /**
1045 * Adds setter's implementation for class.
1046 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301047 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301048 * @throws IOException when fails to append to temporary file
1049 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301050 private void addSetterImpl(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301051 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301052 String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
1053 getGeneratedJavaFiles());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301054 if (rootNode) {
1055 appendToFile(setterImplTempFileHandle,
1056 getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301057 attr.isListAttr(), null) + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301058 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301059 appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301060 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301061 }
1062
1063 /**
1064 * Adds getter method's impl for class.
1065 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301066 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301067 * @throws IOException when fails to append to temporary file
1068 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301069 protected void addGetterImpl(JavaAttributeInfo attr)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301070 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301071 String getter = getGetterForClass(attr, getGeneratedJavaFiles());
1072 if (javaFlagSet(BUILDER_CLASS_MASK)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301073 if (!rootNode) {
1074 appendToFile(getterImplTempFileHandle, getOverRideString() +
1075 getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301076 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301077 appendToFile(getterImplTempFileHandle, getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301078 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301079 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301080 String appDataStructure = null;
1081 if (attr.getCompilerAnnotation() != null) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301082 appDataStructure = attr.getCompilerAnnotation()
1083 .getYangAppDataStructure().getDataStructure().name();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301084 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301085 appendToFile(getterImplTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301086 getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
1087 false, appDataStructure) + getter);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301088 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301089 }
1090
1091 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301092 * Adds add to list interface method.
1093 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301094 * @param attr attribute
Bharat saraswal8beac342016-08-04 02:00:03 +05301095 * @throws IOException when fails to do IO operations
1096 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301097 private void addAddToListInterface(JavaAttributeInfo attr)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301098 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301099 appendToFile(addToListInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301100 getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
1101 null) + getAddToListMethodInterface(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301102 attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301103 }
1104
1105 /**
1106 * Adds add to list interface method.
1107 *
1108 * @param attr attribute
1109 * @throws IOException when fails to do IO operations
1110 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301111 private void addAddToListImpl(JavaAttributeInfo attr)
1112 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301113 appendToFile(addToListImplTempFileHandle,
1114 getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
1115 rootNode) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301116 }
1117
1118 /**
1119 * Adds leaf identifier enum attributes.
1120 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301121 * @param attr attribute
1122 * @param value value
Bharat saraswal8beac342016-08-04 02:00:03 +05301123 * @throws IOException when fails to do IO operations
1124 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301125 private void addLeafIdAttributes(JavaAttributeInfo attr, int value)
Bharat saraswal8beac342016-08-04 02:00:03 +05301126 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301127 appendToFile(leafIdAttributeTempFileHandle, FOUR_SPACE_INDENTATION +
1128 generateEnumAttributeString(attr.getAttributeName(), value));
Bharat saraswal8beac342016-08-04 02:00:03 +05301129 }
1130
1131 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301132 * Adds build method for interface.
1133 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301134 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301135 * @throws IOException when fails to append to temporary file
1136 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301137 protected String addBuildMethodForInterface()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301138 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301139 return parseBuilderInterfaceBuildMethodString(
1140 getGeneratedJavaClassName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301141 }
1142
1143 /**
1144 * Adds build method's implementation for class.
1145 *
1146 * @return build method implementation for class
1147 * @throws IOException when fails to append to temporary file
1148 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301149 protected String addBuildMethodImpl()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301150 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301151 return getBuildString(getGeneratedJavaClassName(), rootNode) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301152 }
1153
1154 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301155 * Adds default constructor for class.
1156 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301157 * @param modifier modifier for constructor
1158 * @param toAppend string which need to be appended with the class name
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301159 * @param suffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301160 * @return default constructor for class
1161 * @throws IOException when fails to append to file
1162 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301163 protected String addDefaultConstructor(String modifier, String toAppend,
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301164 boolean suffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301165 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301166 StringBuilder name = new StringBuilder();
1167 name.append(getGeneratedJavaClassName());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301168 if (rootNode && !toAppend.equals(BUILDER)) {
1169 name.append(OP_PARAM);
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301170 return getDefaultConstructorString(name.toString(), modifier);
Bharat saraswal8beac342016-08-04 02:00:03 +05301171 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301172 if (suffix) {
1173 name.append(toAppend);
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301174 return getDefaultConstructorString(name.toString(), modifier);
Bharat saraswal8beac342016-08-04 02:00:03 +05301175 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301176 StringBuilder appended = new StringBuilder();
Bharat saraswal8beac342016-08-04 02:00:03 +05301177 if (toAppend.equals(DEFAULT)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301178 appended.append(getCapitalCase(toAppend));
Bharat saraswal8beac342016-08-04 02:00:03 +05301179 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301180 appended.append(toAppend);
Bharat saraswal8beac342016-08-04 02:00:03 +05301181 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301182 return NEW_LINE + getDefaultConstructorString(appended.append(
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301183 name).toString(), modifier);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301184 // TODO getDefaultConstructorString to handle new line.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301185 }
1186
1187 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301188 * Adds hash code method for class.
1189 *
1190 * @param attr attribute info
1191 * @throws IOException when fails to append to temporary file
1192 */
1193 private void addHashCodeMethod(JavaAttributeInfo attr)
1194 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301195 appendToFile(hashCodeImplTempFileHandle,
1196 getHashCodeMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301197 }
1198
1199 /**
1200 * Adds equals method for class.
1201 *
1202 * @param attr attribute info
1203 * @throws IOException when fails to append to temporary file
1204 */
1205 private void addEqualsMethod(JavaAttributeInfo attr)
1206 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301207 appendToFile(equalsImplTempFileHandle,
1208 getEqualsMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301209 }
1210
1211 /**
1212 * Adds ToString method for class.
1213 *
1214 * @param attr attribute info
1215 * @throws IOException when fails to append to temporary file
1216 */
1217 private void addToStringMethod(JavaAttributeInfo attr)
1218 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301219 appendToFile(toStringImplTempFileHandle,
1220 getToStringMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301221 }
1222
1223 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301224 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301225 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301226 * @param attr type attribute info
1227 * @param fromStringAttr from string attribute info
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301228 * @param genClassName generated class name
Bharat saraswal250a7472016-05-12 13:16:57 +05301229 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301230 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301231 void addFromStringMethod(JavaAttributeInfo attr,
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301232 JavaAttributeInfo fromStringAttr, String genClassName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301233 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301234 appendToFile(fromStringImplTempFileHandle,
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301235 getFromStringMethod(attr, fromStringAttr, genClassName) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301236 }
1237
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301238 /**
1239 * Returns a temporary file handle for the specific file type.
1240 *
1241 * @param fileName file name
1242 * @return temporary file handle
1243 * @throws IOException when fails to create new file handle
1244 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301245 protected File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301246 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301247 String path = getTempDirPath(absoluteDirPath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301248 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301249 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301250 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301251 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301252 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301253 throw new IOException("failed to create temporary directory " +
1254 "for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301255 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301256 }
1257 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1258 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301259 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301260 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301261 throw new IOException("failed to create temporary file for " +
1262 fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301263 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301264 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301265 throw new IOException(fileName + " is reused due to YANG naming. " +
1266 "probably your previous build " +
1267 "would have failed");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301268 }
1269 return file;
1270 }
1271
1272 /**
1273 * Returns a temporary file handle for the specific file type.
1274 *
1275 * @param fileName file name
1276 * @return temporary file handle
1277 * @throws IOException when fails to create new file handle
1278 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301279 protected File getJavaFileHandle(String fileName)
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301280 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301281 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
1282 javaFileInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301283 }
1284
1285 /**
1286 * Returns data from the temporary files.
1287 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301288 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301289 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301290 * @return stored data from temporary files
1291 * @throws IOException when failed to get data from the given file
1292 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301293 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301294 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301295 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301296 if (new File(path + file.getName()).exists()) {
1297 return readAppendFile(path + file.getName(), EMPTY_STRING);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301298 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301299 throw new IOException("Unable to get data from the given " +
1300 file.getName() + " file for " +
1301 getGeneratedJavaClassName() + PERIOD);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301302 }
1303
1304 /**
1305 * Returns temporary directory path.
1306 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301307 * @param path absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301308 * @return directory path
1309 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301310 private String getTempDirPath(String path) {
1311 return getPackageDirPathFromJavaJPackage(path) + SLASH +
1312 getGeneratedJavaClassName() + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301313 }
1314
1315 /**
1316 * Parses attribute to get the attribute string.
1317 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301318 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301319 * @return attribute string
1320 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301321 protected String parseAttribute(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301322 /*
1323 * TODO: check if this utility needs to be called or move to the caller
1324 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301325 String attrName = attr.getAttributeName();
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301326 String attrAccessType = PRIVATE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301327 if ((getGeneratedJavaFiles() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301328 attrAccessType = PROTECTED;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301329 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301330 String pkg = null;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301331 if (attr.isQualifiedName()) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301332 pkg = attr.getImportInfo().getPkgInfo();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301333 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301334 return getJavaAttributeDefinition(
1335 pkg, attr.getImportInfo().getClassInfo(), attrName,
1336 attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301337 }
1338
1339 /**
1340 * Appends content to temporary file.
1341 *
1342 * @param file temporary file
1343 * @param data data to be appended
1344 * @throws IOException when fails to append to file
1345 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301346 protected void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301347 throws IOException {
1348 try {
1349 insertDataIntoJavaFile(file, data);
1350 } catch (IOException ex) {
1351 throw new IOException("failed to write in temp file.");
1352 }
1353 }
1354
1355 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301356 * Adds parent's info to current node import list.
1357 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301358 * @param curNode current node
1359 * @param config plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301360 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301361 protected void addParentInfoInCurNodeTempFile(YangNode curNode,
1362 YangPluginConfig config) {
1363 JavaQualifiedTypeInfoTranslator caseImportInfo =
1364 new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301365 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301366 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1367 return;
1368 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301369 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301370 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301371 }
1372 if (!(curNode instanceof JavaFileInfoContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301373 throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301374 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301375 caseImportInfo.setClassInfo(
1376 getCapitalCase(getCamelCase(parent.getName(),
1377 config.getConflictResolver())));
1378 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo()
1379 .getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301380
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301381 JavaFileInfoTranslator fileInfo =
1382 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301383
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301384 getBeanFiles(curNode).getJavaImportData().addImportInfo(
1385 caseImportInfo, getCapitalCase(fileInfo.getJavaName()),
1386 fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301387 }
1388
1389 /**
1390 * Adds leaf attributes in generated files.
1391 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301392 * @param entry JAVA leaf info container
1393 * @param config plugin config
1394 * @param curNode current node
1395 * @param leafList flag indicating whether leaf container is leafList
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301396 * @throws IOException IO operation fail
1397 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301398 private void addLeafInfoToTempFiles(JavaLeafInfoContainer entry,
1399 YangPluginConfig config,
1400 YangNode curNode,
1401 boolean leafList)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301402 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301403 if (entry != null) {
1404 if (curNode instanceof RpcNotificationContainer) {
1405 TempJavaBeanFragmentFiles tempFiles = getBeanFiles(curNode);
1406 addJavaSnippetInfoToApplicableTempFiles(
1407 getJavaAttributeOfLeaf(tempFiles, entry,
1408 config, leafList), config);
1409 } else {
1410 addJavaSnippetInfoToApplicableTempFiles(
1411 getJavaAttributeOfLeaf(this, entry,
1412 config, leafList), config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301413 }
1414 }
1415 }
1416
1417 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301418 * Adds all the leaves in the current data model node as part of the
1419 * generated temporary file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301420 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301421 * @param curNode current node
1422 * @param config plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301423 * @throws IOException IO operation fail
1424 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301425 protected void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
1426 YangPluginConfig config)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301427 throws IOException {
1428 if (!(curNode instanceof YangLeavesHolder)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301429 throw new TranslatorException(getErrorMsg(INVALID_LEAF_HOLDER,
1430 curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301431 }
1432 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301433
1434 for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
1435 addLeafInfoToTempFiles((JavaLeafInfoContainer) leaf, config,
1436 curNode, false);
1437 }
1438
1439 for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
1440 addLeafInfoToTempFiles((JavaLeafInfoContainer) leafList, config,
1441 curNode, true);
1442 }
1443 }
1444
1445 /**
1446 * Adds operation type to temp files.
1447 *
1448 * @param curNode current YANG node
1449 * @param config YANG plugin config
1450 * @throws IOException IO exception
1451 */
1452 protected void addOperationTypeToTempFiles(YangNode curNode,
1453 YangPluginConfig config)
1454 throws IOException {
1455 JavaQualifiedTypeInfoTranslator typeInfo =
1456 new JavaQualifiedTypeInfoTranslator();
1457 typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
1458 typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
1459 .getPackage());
1460 JavaAttributeInfo attributeInfo =
1461 getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
1462 curNode.getJavaClassNameOrBuiltInType()) +
1463 OPERATION_TYPE_ATTRIBUTE, null, false, false);
1464 addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301465 }
1466
1467 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301468 * Adds the new attribute info to the target generated temporary files.
1469 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301470 * @param newAttrInfo new attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301471 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301472 * @throws IOException IO operation fail
1473 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301474 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
1475 YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301476 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301477 isAttributePresent = true;
1478 if (tempFlagSet(ATTRIBUTES_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301479 addAttribute(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301480 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301481 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301482 addGetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301483 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301484 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301485 addSetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301486 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301487 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301488 addSetterImpl(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301489 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301490 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301491 addHashCodeMethod(newAttrInfo);
1492 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301493 if (tempFlagSet(EQUALS_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301494 addEqualsMethod(newAttrInfo);
1495 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301496 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301497 addToStringMethod(newAttrInfo);
1498 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301499 if (tempFlagSet(EDIT_CONTENT_MASK)) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301500 //TODO: add implementation for edit content match.
1501 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301502 boolean listAttr = newAttrInfo.isListAttr();
1503 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK) && listAttr) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301504 addAddToListImpl(newAttrInfo);
1505 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301506 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301507 addAddToListInterface(newAttrInfo);
Bharat saraswal8beac342016-08-04 02:00:03 +05301508 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301509 YangType attrType = newAttrInfo.getAttributeType();
1510 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
1511 attrType == null && !newAttrInfo.getAttributeName()
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301512 .contains(OPERATION_TYPE_ATTRIBUTE)) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301513 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301514 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301515 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
1516 !listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301517 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301518 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301519 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
1520 listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301521 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301522 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301523 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
1524 !listAttr && attrType != null) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301525 leafCount++;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301526 addLeafIdAttributes(newAttrInfo, leafCount);
Bharat saraswal8beac342016-08-04 02:00:03 +05301527 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301528 if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
1529 !newAttrInfo.isShortConflict()) {
1530 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301531 addGetterImpl(newAttrInfo);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301532 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301533 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1534 JavaQualifiedTypeInfoTranslator typeInfo =
1535 getQualifiedInfoOfFromString(newAttrInfo,
1536 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301537 /*
1538 * Create a new java attribute info with qualified information of
1539 * wrapper classes.
1540 */
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301541 JavaAttributeInfo fromStringAttributeInfo =
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301542 getAttributeInfoForTheData(
1543 typeInfo, newAttrInfo.getAttributeName(),
1544 attrType, getIsQualifiedAccessOrAddToImportList(
1545 typeInfo), false);
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301546 addFromStringMethod(newAttrInfo, fromStringAttributeInfo,
1547 getGeneratedJavaClassName());
Bharat saraswal64e7e232016-07-14 23:33:55 +05301548 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301549 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301550 }
1551
1552 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301553 * Returns JAVA class name for non implementation classes.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301554 *
1555 * @param suffix for the class name based on the file type
1556 * @return java class name
1557 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301558 protected String getJavaClassName(String suffix) {
1559 return getCapitalCase(javaFileInfo.getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301560 }
1561
1562 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301563 * Returns class name for implementation classes.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301564 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301565 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301566 * @return java class name
1567 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301568 private String getImplClassName(YangNode node) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301569 if (node instanceof RpcNotificationContainer) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301570 return getGeneratedJavaClassName() + OP_PARAM;
Bharat saraswal8beac342016-08-04 02:00:03 +05301571 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301572 return DEFAULT_CAPS + getGeneratedJavaClassName();
Bharat saraswald14cbe82016-07-14 13:26:18 +05301573 }
1574
1575 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301576 * Returns the directory path.
1577 *
1578 * @return directory path
1579 */
1580 private String getDirPath() {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301581 return javaFileInfo.getPackageFilePath();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301582 }
1583
1584 /**
1585 * Constructs java code exit.
1586 *
1587 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301588 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301589 * @throws IOException when fails to generate java files
1590 */
1591 public void generateJavaFile(int fileType, YangNode curNode)
1592 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301593 List<String> imports =
1594 getBeanFiles(curNode).getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301595 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301596 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301597 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301598 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301599
1600 //Generate java code.
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301601 if ((fileType & INTERFACE_MASK) != 0 ||
1602 (fileType & BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301603
1604 //Create interface file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301605 interfaceJavaFileHandle =
1606 getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
1607 interfaceJavaFileHandle =
1608 generateInterfaceFile(interfaceJavaFileHandle, imports,
1609 curNode, isAttributePresent);
1610 if (!(curNode instanceof RpcNotificationContainer)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301611
1612 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301613 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301614 builderInterfaceJavaFileHandle =
1615 getJavaFileHandle(getJavaClassName(
1616 BUILDER_INTERFACE_FILE_NAME_SUFFIX));
1617 builderInterfaceJavaFileHandle =
1618 generateBuilderInterfaceFile(
1619 builderInterfaceJavaFileHandle,
1620 curNode, isAttributePresent);
1621 /*
1622 * Append builder interface file to interface file and
1623 * close it.
1624 */
1625 mergeJavaFiles(builderInterfaceJavaFileHandle,
1626 interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301627 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301628 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301629 insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301630 validateLineLength(interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301631 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301632 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301633 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301634 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301635 if ((fileType & BUILDER_CLASS_MASK) != 0 ||
1636 (fileType & DEFAULT_CLASS_MASK) != 0) {
1637 if (isAttributePresent) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301638 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301639 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301640 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301641
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301642 addBitsAndBase64Imports(curNode, imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301643 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301644 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301645 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301646 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301647 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301648
1649 //Create impl class file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301650 implClassJavaFileHandle =
1651 getJavaFileHandle(getImplClassName(curNode));
1652 implClassJavaFileHandle =
1653 generateDefaultClassFile(implClassJavaFileHandle,
1654 curNode, isAttributePresent,
1655 imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301656
1657 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301658 if ((fileType & BUILDER_CLASS_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301659 builderClassJavaFileHandle =
1660 getJavaFileHandle(getJavaClassName(
1661 BUILDER_CLASS_FILE_NAME_SUFFIX));
1662 builderClassJavaFileHandle =
1663 generateBuilderClassFile(builderClassJavaFileHandle,
1664 curNode,
1665 isAttributePresent);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301666
1667 //Append impl class to builder class and close it.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301668 mergeJavaFiles(builderClassJavaFileHandle,
1669 implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301670 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301671 insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301672 validateLineLength(implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301673 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301674 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301675 freeTemporaryResources(false);
1676 }
1677
Vidyashree Ramab3670472016-08-06 15:49:56 +05301678 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301679 private void addArrayListImport(List<String> imports) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301680 if (imports.contains(javaImportData.getImportForList())) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301681 imports.add(ARRAY_LIST_IMPORT);
1682 }
1683 }
1684
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301685 //Adds import for bitset and base64 list.
1686 private void addBitsAndBase64Imports(YangNode curNode, List<String> imports) {
1687 if (curNode instanceof YangLeavesHolder) {
1688 YangLeavesHolder holder = (YangLeavesHolder) curNode;
1689 String impt = this.getJavaImportData()
1690 .getImportForToBitSet();
1691 if (!holder.getListOfLeaf().isEmpty() &&
1692 !imports.contains(impt)) {
1693 imports.add(impt);
1694 }
1695 }
Bharat saraswald14cbe82016-07-14 13:26:18 +05301696 }
1697
1698 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301699 * Adds imports for ToString and HashCodeMethod.
1700 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301701 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301702 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301703 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301704 protected void addImportsToStringAndHasCodeMethods(List<String> imports,
1705 boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301706 if (operation) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301707 imports.add(javaImportData.getImportForHashAndEquals());
1708 imports.add(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301709 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301710 imports.remove(javaImportData.getImportForHashAndEquals());
1711 imports.remove(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301712 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301713 // TODO change boolean to OPERATION, in all related places.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301714 }
1715
1716 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301717 * Adds import for map and hash map.
1718 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301719 * @param imports import list
1720 * @param operations true for adding and false for deletion
1721 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301722 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301723 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301724 private void addImportsForAugmentableClass(List<String> imports,
1725 boolean operations,
1726 boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301727 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301728 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301729 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301730 imports.add(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301731 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301732 // Add import for hash map only if node is not a YANG choice.
1733 if (!(curNode instanceof YangChoice)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301734 imports.add(javaImportData.getMapImport());
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301735 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301736 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301737 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301738 imports.remove(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301739 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301740 imports.remove(javaImportData.getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301741 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301742 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301743 }
1744
1745 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301746 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301747 *
1748 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301749 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301750 private void addInvocationExceptionImport(List<String> imports) {
1751 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301752 }
1753
1754 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301755 * Removes all temporary file handles.
1756 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301757 * @param errorOccurred flag indicating if error occurred
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301758 * @throws IOException when failed to delete the temporary files
1759 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301760 public void freeTemporaryResources(boolean errorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301761 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301762 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301763 * Close all java file handles and when error occurs delete the files.
1764 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301765 if (javaFlagSet(INTERFACE_MASK)) {
1766 closeFile(interfaceJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301767 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301768 if (javaFlagSet(BUILDER_CLASS_MASK)) {
1769 closeFile(builderClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301770 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301771 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
1772 closeFile(builderInterfaceJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301773 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301774 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
1775 closeFile(implClassJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301776 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301777 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301778 * Close all temporary file handles and delete the files.
1779 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301780 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
1781 closeFile(getterImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301782 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301783 if (tempFlagSet(ATTRIBUTES_MASK)) {
1784 closeFile(attributesTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301785 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301786 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
1787 closeFile(hashCodeImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301788 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301789 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
1790 closeFile(toStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301791 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301792 if (tempFlagSet(EQUALS_IMPL_MASK)) {
1793 closeFile(equalsImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301794 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301795 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1796 closeFile(fromStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301797 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301798 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
1799 closeFile(addToListImplTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301800 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301801 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
1802 closeFile(addToListInterfaceTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301803 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301804 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
1805 closeFile(leafIdAttributeTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301806 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301807 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
1808 closeFile(subtreeFilteringForLeafTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301809 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301810 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
1811 closeFile(getSubtreeFilteringForListTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301812 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301813 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
1814 closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301815 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301816 if (tempFlagSet(EDIT_CONTENT_MASK)) {
1817 closeFile(editContentTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301818 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301819 }
1820
1821 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301822 * Returns if the attribute needs to be accessed in a qualified manner or
1823 * not, if it needs to be imported, then the same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301824 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301825 * @param importInfo import info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301826 * @return status of the qualified access to the attribute
1827 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301828 protected boolean getIsQualifiedAccessOrAddToImportList(
1829 JavaQualifiedTypeInfo importInfo) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301830 return javaImportData
1831 .addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
1832 getGeneratedJavaClassName(),
1833 javaFileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301834 }
1835
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301836 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301837 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301838 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301839 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301840 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301841 public File getAddToListInterfaceTempFileHandle() {
1842 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301843 }
1844
1845 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301846 * Returns temp file handle for add to list impl.
1847 *
1848 * @return temp file handle for add to list impl
1849 */
1850 public File getAddToListImplTempFileHandle() {
1851 return addToListImplTempFileHandle;
1852 }
1853
1854 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301855 * Returns temp file handle for leaf identifier attributes.
1856 *
1857 * @return temp file handle for leaf identifier attributes
1858 */
1859 public File getLeafIdAttributeTempFileHandle() {
1860 return leafIdAttributeTempFileHandle;
1861 }
1862
1863 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301864 * Sets true if root node.
1865 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301866 * @param rootNode true if root node
Bharat saraswal8beac342016-08-04 02:00:03 +05301867 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301868 void setRootNode(boolean rootNode) {
1869 this.rootNode = rootNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301870 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301871
1872 /**
1873 * Returns temp file for is content match.
1874 *
1875 * @return temp file for is content match
1876 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301877 public File getSubtreeFilteringForLeafTempFileHandle() {
1878 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301879 }
1880
1881 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301882 * Returns temp file for edit content file.
1883 *
1884 * @return temp file for edit content file
1885 */
1886 public File getEditContentTempFileHandle() {
1887 return editContentTempFileHandle;
1888 }
1889
1890 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301891 * Returns temp file for is content match.
1892 *
1893 * @return temp file for is content match
1894 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301895 public File getGetSubtreeFilteringForListTempFileHandle() {
1896 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301897 }
1898
1899 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301900 * Returns temp file for is content match.
1901 *
1902 * @return temp file for is content match
1903 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301904 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
1905 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301906 }
1907
1908 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301909 * Checks if a given flag is set in generated java files.
1910 * Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
1911 * <pre>
1912 * javaFlagSet(FOO | BAR)
1913 * </pre>
1914 * returns true if either FOO flag or BAR flag is set.
Bharat saraswale50edca2016-08-05 01:58:25 +05301915 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301916 * @param flag input flag mask value
1917 * @return true if set, else false
Bharat saraswale50edca2016-08-05 01:58:25 +05301918 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301919 private boolean javaFlagSet(int flag) {
1920 return (getGeneratedJavaFiles() & flag) != 0;
1921 }
1922
1923 /**
1924 * Checks if a given flag is set in temp files.
1925 *
1926 * @param flag input flag mask value
1927 * @return true if set, else false
1928 */
1929 private boolean tempFlagSet(int flag) {
1930 return (tempFilesFlagSet & flag) != 0;
Bharat saraswale50edca2016-08-05 01:58:25 +05301931 }
Bharat saraswal54e4bab2016-10-05 23:32:14 +05301932
1933 /**
1934 * Returns list of bits attributes.
1935 *
1936 * @return list of bits attributes
1937 */
1938 public List<BitsJavaInfoHandler> getBitsHandler() {
1939 return bitsHandler;
1940 }
1941
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301942}