blob: 4cba71da8b746ec6da024e847ce13f9e657f22e5 [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;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053030import org.onosproject.yangutils.translator.exception.TranslatorException;
31import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
Shankara-Huaweib7564772016-08-02 18:13:13 +053032import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
Bharat saraswal4aaab4d2016-05-17 14:19:38 +053033import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053034import org.onosproject.yangutils.utils.io.YangPluginConfig;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053035
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053036import java.io.File;
37import java.io.IOException;
38import java.util.List;
39
Bharat saraswalc2d3be12016-06-16 00:29:12 +053040import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053041import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
42import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053043import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053044import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
Bharat saraswalaf413b82016-07-14 15:18:20 +053045import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +053046import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053047import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053048import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
49import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053050import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053051import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053052import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
Bharat saraswale50edca2016-08-05 01:58:25 +053053import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
54import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
55import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
Bharat saraswal250a7472016-05-12 13:16:57 +053056import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053057import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
58import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
59import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
Bharat saraswal8beac342016-08-04 02:00:03 +053060import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053061import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
62import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
63import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
64import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
Shankara-Huaweib7564772016-08-02 18:13:13 +053065import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
66import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053067import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
Bharat saraswal8beac342016-08-04 02:00:03 +053068import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
69import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
Bharat saraswalaf413b82016-07-14 15:18:20 +053070import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053071import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
72import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
Bharat saraswal8beac342016-08-04 02:00:03 +053073import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053074import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053075import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
Bharat saraswald14cbe82016-07-14 13:26:18 +053076import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
Bharat saraswal8beac342016-08-04 02:00:03 +053077import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
78import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053079import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053080import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
81import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
Bharat saraswal250a7472016-05-12 13:16:57 +053082import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053083import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
84import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
85import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053086import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
87import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
88import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
Vinod Kumar S79a374b2016-04-30 21:09:15 +053089import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053090import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +053091import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
92import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
93import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
94import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
95import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
96import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
97import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
98import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
99import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
Bharat saraswal8beac342016-08-04 02:00:03 +0530100import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530101import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530102import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530103import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530104import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530105import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
106import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530107import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
Bharat saraswal8beac342016-08-04 02:00:03 +0530108import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530109import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530110import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
111import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_CLASS;
Bharat saraswal8beac342016-08-04 02:00:03 +0530112import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530113import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Bharat saraswal039f59c2016-07-14 21:57:13 +0530114import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
115import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530116import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530117import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530118import static org.onosproject.yangutils.utils.UtilConstants.YANG;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530119import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530120import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
Bharat saraswal8beac342016-08-04 02:00:03 +0530121import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530122import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
Bharat saraswale304c252016-08-16 20:56:20 +0530123import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530124import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530125import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
Bharat saraswald14cbe82016-07-14 13:26:18 +0530126import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
127import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
128import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530129import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
130import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530131import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530132
133/**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530134 * Represents implementation of java code fragments temporary implementations.
135 * Manages the common temp file required for Java file(s) generated.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530136 */
137public class TempJavaFragmentFiles {
Bharat saraswal250a7472016-05-12 13:16:57 +0530138
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530139 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530140 * File type extension for java classes.
141 */
142 private static final String JAVA_FILE_EXTENSION = ".java";
Bharat saraswal250a7472016-05-12 13:16:57 +0530143
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530144 /**
145 * File type extension for temporary classes.
146 */
147 private static final String TEMP_FILE_EXTENSION = ".tmp";
Bharat saraswal250a7472016-05-12 13:16:57 +0530148
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530149 /**
150 * Folder suffix for temporary files folder.
151 */
Bharat saraswal64e7e232016-07-14 23:33:55 +0530152 private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530153
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530154 /**
155 * File name for getter method.
156 */
157 private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530158
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530159 /**
160 * File name for setter method.
161 */
162 private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530163
164 /**
165 * File name for getter method implementation.
166 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530167 private static final String GETTER_METHOD_IMPL_FILE_NAME =
168 "GetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530169
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530170 /**
171 * File name for setter method implementation.
172 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530173 private static final String SETTER_METHOD_IMPL_FILE_NAME =
174 "SetterMethodImpl";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530175
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530176 /**
177 * File name for attributes.
178 */
179 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
Bharat saraswal250a7472016-05-12 13:16:57 +0530180
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530181 /**
182 * File name for to string method.
183 */
184 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
Bharat saraswal250a7472016-05-12 13:16:57 +0530185
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530186 /**
187 * File name for hash code method.
188 */
189 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
Bharat saraswal250a7472016-05-12 13:16:57 +0530190
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530191 /**
192 * File name for equals method.
193 */
194 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530195
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530196 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530197 * File name for from string method.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530198 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530199 private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530200
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530201 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530202 * File name for from add to list interface method.
203 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530204 private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME =
205 "addToList";
Bharat saraswal8beac342016-08-04 02:00:03 +0530206
207 /**
208 * File name for from add to list impl method.
209 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530210 private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME =
211 "addToListImpl";
Bharat saraswal8beac342016-08-04 02:00:03 +0530212
213 /**
214 * File name for from leaf identifier attributes.
215 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530216 private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME =
217 "leafIdentifierAtr";
Bharat saraswal8beac342016-08-04 02:00:03 +0530218
219 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530220 * File name for is filter content leaf match.
221 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530222 private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME =
223 "isFilterContentMatchLeafMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530224
225 /**
226 * File name for is filter content leaf-list match.
227 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530228 private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME =
229 "isFilterContentMatchLeafListMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530230
231 /**
232 * File name for is filter content node match.
233 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530234 private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME =
235 "isFilterContentMatchNodeMask";
Bharat saraswale50edca2016-08-05 01:58:25 +0530236
237 /**
238 * File name for edit content file.
239 */
240 private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
241
242 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530243 * File name for interface java file name suffix.
244 */
245 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
Bharat saraswal250a7472016-05-12 13:16:57 +0530246
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530247 /**
248 * File name for builder interface file name suffix.
249 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530250 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX =
251 BUILDER + INTERFACE;
Bharat saraswal250a7472016-05-12 13:16:57 +0530252
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530253 /**
254 * File name for builder class file name suffix.
255 */
256 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
Bharat saraswal250a7472016-05-12 13:16:57 +0530257
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530258 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530259 * Information about the java files being generated.
260 */
Bharat saraswale50edca2016-08-05 01:58:25 +0530261 private JavaFileInfoTranslator javaFileInfo;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530262
263 /**
264 * Imported class info.
265 */
266 private JavaImportData javaImportData;
267
268 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530269 * The variable which guides the types of temporary files generated using
270 * the temporary generated file types mask.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530271 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530272 private int tempFilesFlagSet;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530273
274 /**
275 * Absolute path where the target java file needs to be generated.
276 */
277 private String absoluteDirPath;
278
279 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530280 * Contains all the interface(s)/class name which will be extended by
281 * generated files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530282 */
283 private JavaExtendsListHolder javaExtendsListHolder;
284
Bharat saraswald14cbe82016-07-14 13:26:18 +0530285 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530286 * Java file handle for interface file.
287 */
288 private File interfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530289
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530290 /**
291 * Java file handle for builder interface file.
292 */
293 private File builderInterfaceJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530294
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530295 /**
296 * Java file handle for builder class file.
297 */
298 private File builderClassJavaFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530299
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530300 /**
301 * Java file handle for impl class file.
302 */
303 private File implClassJavaFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530304
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530305 /**
306 * Temporary file handle for attribute.
307 */
308 private File attributesTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530309
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530310 /**
311 * Temporary file handle for getter of interface.
312 */
313 private File getterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530314
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530315 /**
316 * Temporary file handle for setter of interface.
317 */
318 private File setterInterfaceTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530319
320 /**
321 * Temporary file handle for getter of class.
322 */
323 private File getterImplTempFileHandle;
324
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530325 /**
326 * Temporary file handle for setter of class.
327 */
328 private File setterImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530329
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530330 /**
331 * Temporary file handle for hash code method of class.
332 */
333 private File hashCodeImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530334
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530335 /**
336 * Temporary file handle for equals method of class.
337 */
338 private File equalsImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530339
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530340 /**
341 * Temporary file handle for to string method of class.
342 */
343 private File toStringImplTempFileHandle;
Bharat saraswal250a7472016-05-12 13:16:57 +0530344
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530345 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530346 * Temporary file handle for from string method of class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530347 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530348 private File fromStringImplTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530349
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530350 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530351 * Temporary file handle for add to list interface method of class.
352 */
353 private File addToListInterfaceTempFileHandle;
354
355 /**
356 * Temporary file handle for add to list impl method of class.
357 */
358 private File addToListImplTempFileHandle;
359
360 /**
361 * Temporary file handle for leaf id attributes of enum.
362 */
363 private File leafIdAttributeTempFileHandle;
364
365 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530366 * Temporary file handle for is content match method for leaf-list.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530367 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530368 private File getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530369
370 /**
371 * Temporary file handle for is content match method for node.
372 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530373 private File getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530374
375 /**
376 * Temporary file handle for is content match method for leaf.
377 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530378 private File subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +0530379
380 /**
381 * Temporary file handle for edit content file.
382 */
383 private File editContentTempFileHandle;
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530384
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530385 /**
Bharat saraswal8beac342016-08-04 02:00:03 +0530386 * Leaf count.
387 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530388 private int leafCount;
Bharat saraswal8beac342016-08-04 02:00:03 +0530389
390 /**
391 * If current node is root node.
392 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530393 private boolean rootNode;
Bharat saraswal8beac342016-08-04 02:00:03 +0530394
395 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530396 * Is attribute added.
397 */
Bharat saraswal250a7472016-05-12 13:16:57 +0530398 private boolean isAttributePresent;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530399
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530400 /**
401 * Creates an instance of temp JAVA fragment files.
402 */
Bharat saraswalaf413b82016-07-14 15:18:20 +0530403 TempJavaFragmentFiles() {
404 }
405
406 /**
407 * Creates an instance of temporary java code fragment.
408 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530409 * @param fileInfo generated java file information
Bharat saraswalaf413b82016-07-14 15:18:20 +0530410 * @throws IOException when fails to create new file handle
411 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530412 protected TempJavaFragmentFiles(JavaFileInfoTranslator fileInfo)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530413 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530414 javaExtendsListHolder = new JavaExtendsListHolder();
415 javaImportData = new JavaImportData();
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530416 javaFileInfo = fileInfo;
417 absoluteDirPath = getAbsolutePackagePath(fileInfo.getBaseCodeGenPath(),
418 fileInfo.getPackageFilePath());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530419 /*
420 * Initialize getter when generation file type matches to interface
421 * mask.
422 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530423 if (javaFlagSet(INTERFACE_MASK)) {
424 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
425 ADD_TO_LIST_INTERFACE_MASK |
426 LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530427 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530428 /*
429 * Initialize getter and setter when generation file type matches to
430 * builder interface mask.
431 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530432 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
433 addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
434 SETTER_FOR_INTERFACE_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530435 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530436 /*
437 * Initialize getterImpl, setterImpl and attributes when generation file
438 * type matches to builder class mask.
439 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530440 if (javaFlagSet(BUILDER_CLASS_MASK)) {
441 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
442 SETTER_FOR_CLASS_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530443 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530444 /*
445 * Initialize getterImpl, attributes, constructor, hash code, equals and
446 * to strings when generation file type matches to impl class mask.
447 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530448 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
449 addGeneratedTempFile(
450 ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
451 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
452 TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
453 FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
454 FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
455 FILTER_CONTENT_MATCH_FOR_NODES_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530456 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530457 /*
458 * Initialize temp files to generate type class.
459 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530460 if (javaFlagSet(GENERATE_TYPE_CLASS)) {
461 addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
462 HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
463 TO_STRING_IMPL_MASK |
464 FROM_STRING_IMPL_MASK);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530465 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530466 //Initialize temp files to generate enum class.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530467 if (javaFlagSet(GENERATE_ENUM_CLASS)) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530468 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
469 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530470 //Set temporary file handles
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530471 if (tempFlagSet(ATTRIBUTES_MASK)) {
472 attributesTempFileHandle =
473 getTemporaryFileHandle(ATTRIBUTE_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530474 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530475 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
476 getterInterfaceTempFileHandle =
477 getTemporaryFileHandle(GETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530478 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530479 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
480 setterInterfaceTempFileHandle =
481 getTemporaryFileHandle(SETTER_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530482 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530483 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
484 getterImplTempFileHandle =
485 getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530486 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530487 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
488 setterImplTempFileHandle =
489 getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530490 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530491 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
492 hashCodeImplTempFileHandle =
493 getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530494 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530495 if (tempFlagSet(EQUALS_IMPL_MASK)) {
496 equalsImplTempFileHandle =
497 getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530498 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530499 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
500 toStringImplTempFileHandle =
501 getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530502 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530503 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
504 fromStringImplTempFileHandle =
505 getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530506 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530507 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
508 addToListInterfaceTempFileHandle =
509 getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530510 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530511 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
512 addToListImplTempFileHandle =
513 getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530514 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530515 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
516 leafIdAttributeTempFileHandle =
517 getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
Bharat saraswal8beac342016-08-04 02:00:03 +0530518 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530519 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
520 subtreeFilteringForLeafTempFileHandle =
521 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530522 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530523 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
524 getSubtreeFilteringForListTempFileHandle =
525 getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530526 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530527 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
528 getSubtreeFilteringForChildNodeTempFileHandle =
529 getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530530 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530531 if (tempFlagSet(EDIT_CONTENT_MASK)) {
532 editContentTempFileHandle =
533 getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
Bharat saraswale50edca2016-08-05 01:58:25 +0530534 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530535 }
536
537 /**
538 * Adds current node info as and attribute to the parent generated file.
539 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530540 * @param curNode current node
541 * @param isList is list construct
542 * @param config plugin configurations
Bharat saraswalaf413b82016-07-14 15:18:20 +0530543 * @throws IOException IO operation exception
544 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530545 protected static void addCurNodeInfoInParentTempFile(YangNode curNode,
546 boolean isList,
547 YangPluginConfig config)
Bharat saraswalaf413b82016-07-14 15:18:20 +0530548 throws IOException {
549 YangNode parent = getParentNodeInGenCode(curNode);
550 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530551 throw new TranslatorException(getErrorMsg(MISSING_PARENT_NODE,
552 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530553 }
Shankara-Huaweib7564772016-08-02 18:13:13 +0530554 if (parent instanceof YangJavaGroupingTranslator) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530555 /*
556 * In case of grouping, there is no need to add the information, it
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530557 * will be taken care in uses.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530558 */
559 return;
560 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530561 TempJavaBeanFragmentFiles tempFiles =
562 getBeanFiles((JavaCodeGeneratorInfo) parent);
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530563
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530564 JavaAttributeInfo attr =
565 getCurNodeAsAttributeInTarget(curNode, parent, isList,
566 tempFiles);
567 tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530568 }
569
570 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530571 * Creates an attribute info object corresponding to a data model node
572 * and return it.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530573 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530574 * @param curNode current node
575 * @param targetNode target node
576 * @param listNode flag indicating if a node is a list node
577 * @param tempFiles temp java fragment files
578 * @return java attribute info
Bharat saraswalaf413b82016-07-14 15:18:20 +0530579 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530580 public static JavaAttributeInfo
581 getCurNodeAsAttributeInTarget(YangNode curNode, YangNode targetNode,
582 boolean listNode,
583 TempJavaFragmentFiles tempFiles) {
584 JavaFileInfoTranslator translator =
585 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
586 String curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530587 if (curNodeName == null) {
588 updateJavaFileInfo(curNode, null);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530589 curNodeName = translator.getJavaName();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530590 }
Bharat saraswalaf413b82016-07-14 15:18:20 +0530591 /*
592 * Get the import info corresponding to the attribute for import in
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530593 * generated java files or qualified access.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530594 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530595 JavaQualifiedTypeInfoTranslator typeInfo =
596 getQualifiedTypeInfoOfCurNode(curNode,
597 getCapitalCase(curNodeName));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530598 if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530599 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
600 curNode));
Bharat saraswalaf413b82016-07-14 15:18:20 +0530601 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530602 JavaImportData parentImportData = tempFiles.getJavaImportData();
603 JavaFileInfoTranslator fileInfo =
604 ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
Bharat saraswalaf413b82016-07-14 15:18:20 +0530605
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530606 boolean qualified;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530607 if (tempFiles instanceof TempJavaServiceFragmentFiles &&
608 typeInfo.getClassInfo().contentEquals(SERVICE) ||
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530609 typeInfo.getClassInfo()
610 .contentEquals(getCapitalCase(fileInfo.getJavaName() +
611 SERVICE))) {
612 qualified = true;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530613 } else {
614 String className;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530615 if (tempFiles instanceof TempJavaServiceFragmentFiles) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530616 className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530617 } else {
618 className = getCapitalCase(fileInfo.getJavaName());
619 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530620 qualified = parentImportData.addImportInfo(typeInfo, className,
621 fileInfo.getPackage());
Bharat saraswalaf413b82016-07-14 15:18:20 +0530622 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530623 boolean collectionSet = false;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530624 if (curNode instanceof YangList) {
625 YangList yangList = (YangList) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530626 if (yangList.getCompilerAnnotation() != null &&
627 yangList.getCompilerAnnotation()
628 .getYangAppDataStructure() != null) {
629 switch (yangList.getCompilerAnnotation()
630 .getYangAppDataStructure().getDataStructure()) {
Vidyashree Ramab3670472016-08-06 15:49:56 +0530631 case QUEUE: {
632 parentImportData.setQueueToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530633 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530634 break;
635 }
636 case SET: {
637 parentImportData.setSetToImport(true);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530638 collectionSet = true;
Vidyashree Ramab3670472016-08-06 15:49:56 +0530639 break;
640 }
641 default: {
642 // TODO : to be implemented
643 }
644 }
645 }
646 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530647 if (listNode && !collectionSet) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530648 parentImportData.setIfListImported(true);
649 }
Vidyashree Ramab3670472016-08-06 15:49:56 +0530650 if (curNode instanceof YangList) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530651 return getAttributeInfoForTheData(typeInfo, curNodeName,
652 null, qualified, listNode,
653 ((YangList) curNode)
654 .getCompilerAnnotation());
Vidyashree Ramab3670472016-08-06 15:49:56 +0530655 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530656 return getAttributeInfoForTheData(typeInfo, curNodeName, null,
657 qualified, listNode);
Bharat saraswalaf413b82016-07-14 15:18:20 +0530658 }
659
660 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530661 * Returns java attribute for leaf.
662 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530663 * @param tempFiles temporary generated file
664 * @param container JAVA leaf info container
665 * @param config plugin configurations
666 * @param leafList flag indicating if it's leaf list
667 * @return java attribute info
Bharat saraswal64e7e232016-07-14 23:33:55 +0530668 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530669 private static JavaAttributeInfo
670 getJavaAttributeOfLeaf(TempJavaFragmentFiles tempFiles,
671 JavaLeafInfoContainer container,
672 YangPluginConfig config, boolean leafList) {
673 if (leafList) {
674 tempFiles.getJavaImportData().setIfListImported(true);
675 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
676 true);
677 }
678 return getAttributeOfLeafInfoContainer(tempFiles, container, config,
679 false);
Bharat saraswal64e7e232016-07-14 23:33:55 +0530680 }
681
682 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530683 * Returns java attribute for leaf container.
Bharat saraswal64e7e232016-07-14 23:33:55 +0530684 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530685 * @param tempFiles temporary generated file
686 * @param container JAVA leaf info container
687 * @param config plugin configurations
688 * @param listAttribute flag indicating if list attribute
689 * @return JAVA attribute information
Bharat saraswal64e7e232016-07-14 23:33:55 +0530690 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530691 private static JavaAttributeInfo
692 getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
693 JavaLeafInfoContainer container,
694 YangPluginConfig config,
695 boolean listAttribute) {
696 container.setConflictResolveConfig(config.getConflictResolver());
697 container.updateJavaQualifiedInfo();
Bharat saraswal64e7e232016-07-14 23:33:55 +0530698 return getAttributeInfoForTheData(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530699 container.getJavaQualifiedInfo(),
700 container.getJavaName(config.getConflictResolver()),
701 container.getDataType(),
702 tempFiles.getIsQualifiedAccessOrAddToImportList(
703 container.getJavaQualifiedInfo()), listAttribute);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530704 }
705
706 /**
707 * Sets absolute path where the file needs to be generated.
708 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530709 * @param absoluteDirPath absolute path where the file needs to be
710 * generated
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530711 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530712 protected void setAbsoluteDirPath(String absoluteDirPath) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530713 this.absoluteDirPath = absoluteDirPath;
714 }
715
716 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530717 * Returns the generated java file information.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530718 *
719 * @return generated java file information
720 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530721 protected JavaFileInfoTranslator getJavaFileInfo() {
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530722 return javaFileInfo;
723 }
724
725 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530726 * Sets the generated java file information.
727 *
728 * @param javaFileInfo generated java file information
729 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530730 protected void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
Bharat saraswalaf413b82016-07-14 15:18:20 +0530731 this.javaFileInfo = javaFileInfo;
732 }
733
734 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530735 * Returns the flag-set for generated temp files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530736 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530737 * @return flag-set
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530738 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530739 protected int getGeneratedTempFiles() {
740 return tempFilesFlagSet;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530741 }
742
743 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530744 * Adds to the flag-set for generated temp files.
Bharat saraswalaf413b82016-07-14 15:18:20 +0530745 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530746 * @param flags generated temp files flag-set
Bharat saraswalaf413b82016-07-14 15:18:20 +0530747 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530748 protected void addGeneratedTempFile(int flags) {
749 tempFilesFlagSet |= flags;
Bharat saraswalaf413b82016-07-14 15:18:20 +0530750 }
751
752 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530753 * Returns the generated Java files.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530754 *
755 * @return generated Java files
756 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530757 protected int getGeneratedJavaFiles() {
758 return javaFileInfo.getGeneratedFileTypes();
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530759 }
760
761 /**
762 * Retrieves the mapped Java class name.
763 *
764 * @return mapped Java class name
765 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530766 protected String getGeneratedJavaClassName() {
767 return getCapitalCase(javaFileInfo.getJavaName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530768 }
769
770 /**
771 * Retrieves the import data for the generated Java file.
772 *
773 * @return import data for the generated Java file
774 */
775 public JavaImportData getJavaImportData() {
776 return javaImportData;
777 }
778
779 /**
780 * Sets import data for the generated Java file.
781 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530782 * @param data import data for the generated Java file
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530783 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530784 protected void setJavaImportData(JavaImportData data) {
785 javaImportData = data;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530786 }
787
788 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530789 * Retrieves the status of any attributes added.
790 *
791 * @return status of any attributes added
792 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530793 protected boolean isAttributePresent() {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530794 return isAttributePresent;
795 }
796
797 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530798 * Returns getter methods's temporary file handle.
799 *
800 * @return temporary file handle
801 */
802 public File getGetterInterfaceTempFileHandle() {
803 return getterInterfaceTempFileHandle;
804 }
805
806 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530807 * Returns setter method's temporary file handle.
808 *
809 * @return temporary file handle
810 */
811 public File getSetterInterfaceTempFileHandle() {
812 return setterInterfaceTempFileHandle;
813 }
814
815 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530816 * Returns setter method's impl's temporary file handle.
817 *
818 * @return temporary file handle
819 */
820 public File getSetterImplTempFileHandle() {
821 return setterImplTempFileHandle;
822 }
823
824 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530825 * Returns from string method's temporary file handle.
826 *
827 * @return from string method's temporary file handle
828 */
829 public File getFromStringImplTempFileHandle() {
830 return fromStringImplTempFileHandle;
831 }
832
833 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530834 * Returns attribute's temporary file handle.
835 *
836 * @return temporary file handle
837 */
838 public File getAttributesTempFileHandle() {
839 return attributesTempFileHandle;
840 }
841
842 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530843 * Returns getter method's impl's temporary file handle.
844 *
845 * @return temporary file handle
846 */
847 public File getGetterImplTempFileHandle() {
848 return getterImplTempFileHandle;
849 }
850
851 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530852 * Returns hash code method's temporary file handle.
853 *
854 * @return temporary file handle
855 */
856 public File getHashCodeImplTempFileHandle() {
857 return hashCodeImplTempFileHandle;
858 }
859
860 /**
Bharat saraswal64e7e232016-07-14 23:33:55 +0530861 * Returns equals method's temporary file handle.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530862 *
863 * @return temporary file handle
864 */
865 public File getEqualsImplTempFileHandle() {
866 return equalsImplTempFileHandle;
867 }
868
869 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530870 * Returns to string method's temporary file handle.
871 *
872 * @return temporary file handle
873 */
874 public File getToStringImplTempFileHandle() {
875 return toStringImplTempFileHandle;
876 }
877
878 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530879 * Returns java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530880 *
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530881 * @return java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530882 */
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530883 public JavaExtendsListHolder getJavaExtendsListHolder() {
884 return javaExtendsListHolder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530885 }
886
887 /**
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530888 * Sets java extends list holder.
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530889 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530890 * @param holder java extends list holder
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530891 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530892 protected void setJavaExtendsListHolder(
893 JavaExtendsListHolder holder) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530894 javaExtendsListHolder = holder;
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530895 }
896
897 /**
Bharat saraswale50edca2016-08-05 01:58:25 +0530898 * Adds is filter content match for leaf.
899 *
900 * @param attr java attribute
901 * @throws IOException when fails to do IO operations
902 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530903 private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530904 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530905 appendToFile(subtreeFilteringForLeafTempFileHandle,
906 getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
907 NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530908 }
909
910 /**
911 * Adds is filter content match for leaf-list.
912 *
913 * @param attr java attribute
914 * @throws IOException when fails to do IO operations
915 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530916 private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530917 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530918 appendToFile(getSubtreeFilteringForListTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +0530919 getSubtreeFilteringForLeafList(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530920 }
921
922 /**
923 * Adds is filter content match for nodes.
924 *
925 * @param attr java attribute
926 * @throws IOException when fails to do IO operations
927 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530928 private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
Bharat saraswale50edca2016-08-05 01:58:25 +0530929 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530930 appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
Bharat saraswal1edde622016-09-06 10:18:04 +0530931 getSubtreeFilteringForNode(attr) + NEW_LINE);
Bharat saraswale50edca2016-08-05 01:58:25 +0530932 }
933
934 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530935 * Adds attribute for class.
936 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530937 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530938 * @throws IOException when fails to append to temporary file
939 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530940 private void addAttribute(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530941 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530942 appendToFile(attributesTempFileHandle, parseAttribute(attr));
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530943 }
944
945 /**
946 * Adds getter for interface.
947 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530948 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530949 * @throws IOException when fails to append to temporary file
950 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530951 private void addGetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530952 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530953 appendToFile(getterInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530954 getGetterString(attr, getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530955 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530956 }
957
958 /**
959 * Adds setter for interface.
960 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530961 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530962 * @throws IOException when fails to append to temporary file
963 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530964 private void addSetterForInterface(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530965 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530966 appendToFile(setterInterfaceTempFileHandle,
967 getSetterString(attr, getGeneratedJavaClassName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530968 getGeneratedJavaFiles()) +
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530969 NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530970 }
971
972 /**
973 * Adds setter's implementation for class.
974 *
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +0530975 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530976 * @throws IOException when fails to append to temporary file
977 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530978 private void addSetterImpl(JavaAttributeInfo attr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +0530979 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530980 String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
981 getGeneratedJavaFiles());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530982 if (rootNode) {
983 appendToFile(setterImplTempFileHandle,
984 getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530985 attr.isListAttr(), null) + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +0530986 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +0530987 appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
Bharat saraswal8beac342016-08-04 02:00:03 +0530988 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530989 }
990
991 /**
992 * Adds getter method's impl for class.
993 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530994 * @param attr attribute info
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530995 * @throws IOException when fails to append to temporary file
996 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530997 protected void addGetterImpl(JavaAttributeInfo attr)
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530998 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530999 String getter = getGetterForClass(attr, getGeneratedJavaFiles());
1000 if (javaFlagSet(BUILDER_CLASS_MASK)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301001 if (!rootNode) {
1002 appendToFile(getterImplTempFileHandle, getOverRideString() +
1003 getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301004 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301005 appendToFile(getterImplTempFileHandle, getter);
Bharat saraswal8beac342016-08-04 02:00:03 +05301006 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301007 } else {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301008 String appDataStructure = null;
1009 if (attr.getCompilerAnnotation() != null) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301010 appDataStructure = attr.getCompilerAnnotation()
1011 .getYangAppDataStructure().getDataStructure().name();
Vidyashree Ramab3670472016-08-06 15:49:56 +05301012 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301013 appendToFile(getterImplTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301014 getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
1015 false, appDataStructure) + getter);
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301016 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301017 }
1018
1019 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301020 * Adds add to list interface method.
1021 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301022 * @param attr attribute
Bharat saraswal8beac342016-08-04 02:00:03 +05301023 * @throws IOException when fails to do IO operations
1024 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301025 private void addAddToListInterface(JavaAttributeInfo attr)
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301026 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301027 appendToFile(addToListInterfaceTempFileHandle,
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301028 getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
1029 null) + getAddToListMethodInterface(
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301030 attr, getGeneratedJavaClassName()) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301031 }
1032
1033 /**
1034 * Adds add to list interface method.
1035 *
1036 * @param attr attribute
1037 * @throws IOException when fails to do IO operations
1038 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301039 private void addAddToListImpl(JavaAttributeInfo attr)
1040 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301041 appendToFile(addToListImplTempFileHandle,
1042 getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
1043 rootNode) + NEW_LINE);
Bharat saraswal8beac342016-08-04 02:00:03 +05301044 }
1045
1046 /**
1047 * Adds leaf identifier enum attributes.
1048 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301049 * @param attr attribute
1050 * @param value value
Bharat saraswal8beac342016-08-04 02:00:03 +05301051 * @throws IOException when fails to do IO operations
1052 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301053 private void addLeafIdAttributes(JavaAttributeInfo attr, int value)
Bharat saraswal8beac342016-08-04 02:00:03 +05301054 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301055 appendToFile(leafIdAttributeTempFileHandle, FOUR_SPACE_INDENTATION +
1056 generateEnumAttributeString(attr.getAttributeName(), value));
Bharat saraswal8beac342016-08-04 02:00:03 +05301057 }
1058
1059 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301060 * Adds build method for interface.
1061 *
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301062 * @return build method for interface
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301063 * @throws IOException when fails to append to temporary file
1064 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301065 protected String addBuildMethodForInterface()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301066 throws IOException {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301067 return parseBuilderInterfaceBuildMethodString(
1068 getGeneratedJavaClassName());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301069 }
1070
1071 /**
1072 * Adds build method's implementation for class.
1073 *
1074 * @return build method implementation for class
1075 * @throws IOException when fails to append to temporary file
1076 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301077 protected String addBuildMethodImpl()
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301078 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301079 return getBuildString(getGeneratedJavaClassName(), rootNode) + NEW_LINE;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301080 }
1081
1082 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301083 * Adds default constructor for class.
1084 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301085 * @param modifier modifier for constructor
1086 * @param toAppend string which need to be appended with the class name
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301087 * @param suffix is value need to be appended as suffix
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301088 * @return default constructor for class
1089 * @throws IOException when fails to append to file
1090 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301091 protected String addDefaultConstructor(String modifier, String toAppend,
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301092 boolean suffix)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301093 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301094 StringBuilder name = new StringBuilder();
1095 name.append(getGeneratedJavaClassName());
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301096 if (rootNode && !toAppend.equals(BUILDER)) {
1097 name.append(OP_PARAM);
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301098 return getDefaultConstructorString(name.toString(), modifier
1099 );
Bharat saraswal8beac342016-08-04 02:00:03 +05301100 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301101 if (suffix) {
1102 name.append(toAppend);
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301103 return getDefaultConstructorString(name.toString(), modifier
1104 );
Bharat saraswal8beac342016-08-04 02:00:03 +05301105 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301106 StringBuilder appended = new StringBuilder();
Bharat saraswal8beac342016-08-04 02:00:03 +05301107 if (toAppend.equals(DEFAULT)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301108 appended.append(getCapitalCase(toAppend));
Bharat saraswal8beac342016-08-04 02:00:03 +05301109 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301110 appended.append(toAppend);
Bharat saraswal8beac342016-08-04 02:00:03 +05301111 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301112 return NEW_LINE + getDefaultConstructorString(appended.append(
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301113 name).toString(), modifier);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301114 // TODO getDefaultConstructorString to handle new line.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301115 }
1116
1117 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301118 * Adds hash code method for class.
1119 *
1120 * @param attr attribute info
1121 * @throws IOException when fails to append to temporary file
1122 */
1123 private void addHashCodeMethod(JavaAttributeInfo attr)
1124 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301125 appendToFile(hashCodeImplTempFileHandle,
1126 getHashCodeMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301127 }
1128
1129 /**
1130 * Adds equals method for class.
1131 *
1132 * @param attr attribute info
1133 * @throws IOException when fails to append to temporary file
1134 */
1135 private void addEqualsMethod(JavaAttributeInfo attr)
1136 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301137 appendToFile(equalsImplTempFileHandle,
1138 getEqualsMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301139 }
1140
1141 /**
1142 * Adds ToString method for class.
1143 *
1144 * @param attr attribute info
1145 * @throws IOException when fails to append to temporary file
1146 */
1147 private void addToStringMethod(JavaAttributeInfo attr)
1148 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301149 appendToFile(toStringImplTempFileHandle,
1150 getToStringMethod(attr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301151 }
1152
1153 /**
Bharat saraswal250a7472016-05-12 13:16:57 +05301154 * Adds from string method for union class.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301155 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301156 * @param attr type attribute info
1157 * @param fromStringAttr from string attribute info
Bharat saraswal250a7472016-05-12 13:16:57 +05301158 * @throws IOException when fails to append to temporary file
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301159 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301160 void addFromStringMethod(JavaAttributeInfo attr,
1161 JavaAttributeInfo fromStringAttr)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301162 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301163 appendToFile(fromStringImplTempFileHandle,
1164 getFromStringMethod(attr, fromStringAttr) + NEW_LINE);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301165 }
1166
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301167 /**
1168 * Returns a temporary file handle for the specific file type.
1169 *
1170 * @param fileName file name
1171 * @return temporary file handle
1172 * @throws IOException when fails to create new file handle
1173 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301174 protected File getTemporaryFileHandle(String fileName)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301175 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301176 String path = getTempDirPath(absoluteDirPath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301177 File dir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +05301178 boolean isCreated;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301179 if (!dir.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301180 isCreated = dir.mkdirs();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301181 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301182 throw new IOException("failed to create temporary directory " +
1183 "for " + fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301184 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301185 }
1186 File file = new File(path + fileName + TEMP_FILE_EXTENSION);
1187 if (!file.exists()) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301188 isCreated = file.createNewFile();
Shankara-Huaweib7564772016-08-02 18:13:13 +05301189 if (!isCreated) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301190 throw new IOException("failed to create temporary file for " +
1191 fileName);
Shankara-Huaweib7564772016-08-02 18:13:13 +05301192 }
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301193 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301194 throw new IOException(fileName + " is reused due to YANG naming. " +
1195 "probably your previous build " +
1196 "would have failed");
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301197 }
1198 return file;
1199 }
1200
1201 /**
1202 * Returns a temporary file handle for the specific file type.
1203 *
1204 * @param fileName file name
1205 * @return temporary file handle
1206 * @throws IOException when fails to create new file handle
1207 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301208 protected File getJavaFileHandle(String fileName)
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301209 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301210 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
1211 javaFileInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301212 }
1213
1214 /**
1215 * Returns data from the temporary files.
1216 *
Bharat saraswalaf413b82016-07-14 15:18:20 +05301217 * @param file temporary file handle
Bharat saraswald14cbe82016-07-14 13:26:18 +05301218 * @param absolutePath absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301219 * @return stored data from temporary files
1220 * @throws IOException when failed to get data from the given file
1221 */
Bharat saraswald14cbe82016-07-14 13:26:18 +05301222 public String getTemporaryDataFromFileHandle(File file, String absolutePath)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301223 throws IOException {
Bharat saraswald14cbe82016-07-14 13:26:18 +05301224 String path = getTempDirPath(absolutePath);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301225 if (new File(path + file.getName()).exists()) {
1226 return readAppendFile(path + file.getName(), EMPTY_STRING);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301227 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301228 throw new IOException("Unable to get data from the given " +
1229 file.getName() + " file for " +
1230 getGeneratedJavaClassName() + PERIOD);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301231 }
1232
1233 /**
1234 * Returns temporary directory path.
1235 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301236 * @param path absolute path
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301237 * @return directory path
1238 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301239 private String getTempDirPath(String path) {
1240 return getPackageDirPathFromJavaJPackage(path) + SLASH +
1241 getGeneratedJavaClassName() + TEMP_FOLDER_NAME_SUFFIX + SLASH;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301242 }
1243
1244 /**
1245 * Parses attribute to get the attribute string.
1246 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301247 * @param attr attribute info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301248 * @return attribute string
1249 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301250 protected String parseAttribute(JavaAttributeInfo attr) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301251 /*
1252 * TODO: check if this utility needs to be called or move to the caller
1253 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301254 String attrName = attr.getAttributeName();
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301255 String attrAccessType = PRIVATE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301256 if ((getGeneratedJavaFiles() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301257 attrAccessType = PROTECTED;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301258 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301259 String pkg = null;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301260 if (attr.isQualifiedName()) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301261 pkg = attr.getImportInfo().getPkgInfo();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301262 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301263 return getJavaAttributeDefinition(
1264 pkg, attr.getImportInfo().getClassInfo(), attrName,
1265 attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301266 }
1267
1268 /**
1269 * Appends content to temporary file.
1270 *
1271 * @param file temporary file
1272 * @param data data to be appended
1273 * @throws IOException when fails to append to file
1274 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301275 protected void appendToFile(File file, String data)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301276 throws IOException {
1277 try {
1278 insertDataIntoJavaFile(file, data);
1279 } catch (IOException ex) {
1280 throw new IOException("failed to write in temp file.");
1281 }
1282 }
1283
1284 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301285 * Adds parent's info to current node import list.
1286 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301287 * @param curNode current node
1288 * @param config plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301289 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301290 protected void addParentInfoInCurNodeTempFile(YangNode curNode,
1291 YangPluginConfig config) {
1292 JavaQualifiedTypeInfoTranslator caseImportInfo =
1293 new JavaQualifiedTypeInfoTranslator();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301294 YangNode parent = getParentNodeInGenCode(curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301295 if (curNode instanceof YangCase && parent instanceof YangAugment) {
1296 return;
1297 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301298 if (!(parent instanceof JavaCodeGenerator)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301299 throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301300 }
1301 if (!(curNode instanceof JavaFileInfoContainer)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301302 throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301303 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301304 caseImportInfo.setClassInfo(
1305 getCapitalCase(getCamelCase(parent.getName(),
1306 config.getConflictResolver())));
1307 caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo()
1308 .getPackage());
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301309
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301310 JavaFileInfoTranslator fileInfo =
1311 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301312
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301313 getBeanFiles(curNode).getJavaImportData().addImportInfo(
1314 caseImportInfo, getCapitalCase(fileInfo.getJavaName()),
1315 fileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301316 }
1317
1318 /**
1319 * Adds leaf attributes in generated files.
1320 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301321 * @param entry JAVA leaf info container
1322 * @param config plugin config
1323 * @param curNode current node
1324 * @param leafList flag indicating whether leaf container is leafList
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301325 * @throws IOException IO operation fail
1326 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301327 private void addLeafInfoToTempFiles(JavaLeafInfoContainer entry,
1328 YangPluginConfig config,
1329 YangNode curNode,
1330 boolean leafList)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301331 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301332 if (entry != null) {
1333 if (curNode instanceof RpcNotificationContainer) {
1334 TempJavaBeanFragmentFiles tempFiles = getBeanFiles(curNode);
1335 addJavaSnippetInfoToApplicableTempFiles(
1336 getJavaAttributeOfLeaf(tempFiles, entry,
1337 config, leafList), config);
1338 } else {
1339 addJavaSnippetInfoToApplicableTempFiles(
1340 getJavaAttributeOfLeaf(this, entry,
1341 config, leafList), config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301342 }
1343 }
1344 }
1345
1346 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301347 * Adds all the leaves in the current data model node as part of the
1348 * generated temporary file.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301349 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301350 * @param curNode current node
1351 * @param config plugin config
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301352 * @throws IOException IO operation fail
1353 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301354 protected void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
1355 YangPluginConfig config)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301356 throws IOException {
1357 if (!(curNode instanceof YangLeavesHolder)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301358 throw new TranslatorException(getErrorMsg(INVALID_LEAF_HOLDER,
1359 curNode));
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301360 }
1361 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301362
1363 for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
1364 addLeafInfoToTempFiles((JavaLeafInfoContainer) leaf, config,
1365 curNode, false);
1366 }
1367
1368 for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
1369 addLeafInfoToTempFiles((JavaLeafInfoContainer) leafList, config,
1370 curNode, true);
1371 }
1372 }
1373
1374 /**
1375 * Adds operation type to temp files.
1376 *
1377 * @param curNode current YANG node
1378 * @param config YANG plugin config
1379 * @throws IOException IO exception
1380 */
1381 protected void addOperationTypeToTempFiles(YangNode curNode,
1382 YangPluginConfig config)
1383 throws IOException {
1384 JavaQualifiedTypeInfoTranslator typeInfo =
1385 new JavaQualifiedTypeInfoTranslator();
1386 typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
1387 typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
1388 .getPackage());
1389 JavaAttributeInfo attributeInfo =
1390 getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
1391 curNode.getJavaClassNameOrBuiltInType()) +
1392 OPERATION_TYPE_ATTRIBUTE, null, false, false);
1393 addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301394 }
1395
1396 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301397 * Adds the new attribute info to the target generated temporary files.
1398 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301399 * @param newAttrInfo new attribute info
Bharat saraswal715d3fc2016-05-17 19:59:16 +05301400 * @param pluginConfig plugin configurations
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301401 * @throws IOException IO operation fail
1402 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301403 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
1404 YangPluginConfig pluginConfig)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301405 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301406 isAttributePresent = true;
1407 if (tempFlagSet(ATTRIBUTES_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301408 addAttribute(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301409 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301410 if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301411 addGetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301412 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301413 if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301414 addSetterForInterface(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301415 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301416 if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301417 addSetterImpl(newAttrInfo);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301418 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301419 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301420 addHashCodeMethod(newAttrInfo);
1421 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301422 if (tempFlagSet(EQUALS_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301423 addEqualsMethod(newAttrInfo);
1424 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301425 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301426 addToStringMethod(newAttrInfo);
1427 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301428 if (tempFlagSet(EDIT_CONTENT_MASK)) {
Bharat saraswale50edca2016-08-05 01:58:25 +05301429 //TODO: add implementation for edit content match.
1430 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301431 boolean listAttr = newAttrInfo.isListAttr();
1432 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK) && listAttr) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301433 addAddToListImpl(newAttrInfo);
1434 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301435 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301436 addAddToListInterface(newAttrInfo);
Bharat saraswal8beac342016-08-04 02:00:03 +05301437 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301438 YangType attrType = newAttrInfo.getAttributeType();
1439 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
1440 attrType == null && !newAttrInfo.getAttributeName()
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301441 .contains(OPERATION_TYPE_ATTRIBUTE)) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301442 addSubtreeFilteringForChildNode(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301443 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301444 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
1445 !listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301446 addSubTreeFilteringForLeaf(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301447 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301448 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
1449 listAttr && attrType != null) {
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301450 addSubtreeFilteringForLeafList(newAttrInfo);
Bharat saraswale50edca2016-08-05 01:58:25 +05301451 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301452 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
1453 !listAttr && attrType != null) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301454 leafCount++;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301455 addLeafIdAttributes(newAttrInfo, leafCount);
Bharat saraswal8beac342016-08-04 02:00:03 +05301456 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301457 if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
1458 !newAttrInfo.isShortConflict()) {
1459 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301460 addGetterImpl(newAttrInfo);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301461 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301462 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1463 JavaQualifiedTypeInfoTranslator typeInfo =
1464 getQualifiedInfoOfFromString(newAttrInfo,
1465 pluginConfig.getConflictResolver());
Bharat saraswal250a7472016-05-12 13:16:57 +05301466 /*
1467 * Create a new java attribute info with qualified information of
1468 * wrapper classes.
1469 */
Bharat saraswal748fc3c2016-09-06 16:38:20 +05301470 JavaAttributeInfo fromStringAttributeInfo =
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301471 getAttributeInfoForTheData(
1472 typeInfo, newAttrInfo.getAttributeName(),
1473 attrType, getIsQualifiedAccessOrAddToImportList(
1474 typeInfo), false);
Bharat saraswal64e7e232016-07-14 23:33:55 +05301475 addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1476 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301477 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301478 }
1479
1480 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301481 * Returns JAVA class name for non implementation classes.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301482 *
1483 * @param suffix for the class name based on the file type
1484 * @return java class name
1485 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301486 protected String getJavaClassName(String suffix) {
1487 return getCapitalCase(javaFileInfo.getJavaName()) + suffix;
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301488 }
1489
1490 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301491 * Returns class name for implementation classes.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301492 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301493 * @param node YANG node
Bharat saraswald14cbe82016-07-14 13:26:18 +05301494 * @return java class name
1495 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301496 private String getImplClassName(YangNode node) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301497 if (node instanceof RpcNotificationContainer) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301498 return getGeneratedJavaClassName() + OP_PARAM;
Bharat saraswal8beac342016-08-04 02:00:03 +05301499 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301500 return DEFAULT_CAPS + getGeneratedJavaClassName();
Bharat saraswald14cbe82016-07-14 13:26:18 +05301501 }
1502
1503 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301504 * Returns the directory path.
1505 *
1506 * @return directory path
1507 */
1508 private String getDirPath() {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301509 return javaFileInfo.getPackageFilePath();
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301510 }
1511
1512 /**
1513 * Constructs java code exit.
1514 *
1515 * @param fileType generated file type
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +05301516 * @param curNode current YANG node
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301517 * @throws IOException when fails to generate java files
1518 */
1519 public void generateJavaFile(int fileType, YangNode curNode)
1520 throws IOException {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301521 List<String> imports =
1522 getBeanFiles(curNode).getJavaImportData().getImports();
Bharat saraswal8beac342016-08-04 02:00:03 +05301523 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301524 addImportsForAugmentableClass(imports, true, true, curNode);
Bharat saraswal8beac342016-08-04 02:00:03 +05301525 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301526 createPackage(curNode);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301527
1528 //Generate java code.
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301529 if ((fileType & INTERFACE_MASK) != 0 ||
1530 (fileType & BUILDER_INTERFACE_MASK) != 0) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301531
1532 //Create interface file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301533 interfaceJavaFileHandle =
1534 getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
1535 interfaceJavaFileHandle =
1536 generateInterfaceFile(interfaceJavaFileHandle, imports,
1537 curNode, isAttributePresent);
1538 if (!(curNode instanceof RpcNotificationContainer)) {
Vidyashree Ramab3670472016-08-06 15:49:56 +05301539
1540 //Create builder interface file.
Bharat saraswal8beac342016-08-04 02:00:03 +05301541 if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301542 builderInterfaceJavaFileHandle =
1543 getJavaFileHandle(getJavaClassName(
1544 BUILDER_INTERFACE_FILE_NAME_SUFFIX));
1545 builderInterfaceJavaFileHandle =
1546 generateBuilderInterfaceFile(
1547 builderInterfaceJavaFileHandle,
1548 curNode, isAttributePresent);
1549 /*
1550 * Append builder interface file to interface file and
1551 * close it.
1552 */
1553 mergeJavaFiles(builderInterfaceJavaFileHandle,
1554 interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301555 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301556 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301557 insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301558 validateLineLength(interfaceJavaFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301559 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301560 addImportsForAugmentableClass(imports, false, true, curNode);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301561 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301562 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301563 if ((fileType & BUILDER_CLASS_MASK) != 0 ||
1564 (fileType & DEFAULT_CLASS_MASK) != 0) {
1565 if (isAttributePresent) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301566 addImportsToStringAndHasCodeMethods(imports, true);
Bharat saraswal8beac342016-08-04 02:00:03 +05301567 addArrayListImport(imports);
Bharat saraswalaf413b82016-07-14 15:18:20 +05301568 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301569
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301570 boolean leavesPresent;
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301571 if (curNode instanceof YangLeavesHolder) {
1572 YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301573 leavesPresent = leavesHolder.getListOfLeaf() != null &&
1574 !leavesHolder.getListOfLeaf().isEmpty() ||
1575 leavesHolder.getListOfLeafList() != null &&
1576 !leavesHolder.getListOfLeafList().isEmpty();
1577 if (leavesPresent) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301578 addBitsetImport(imports);
1579 }
1580 }
Bharat saraswalaf413b82016-07-14 15:18:20 +05301581 if (curNode instanceof YangAugmentableNode) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301582 addImportsForAugmentableClass(imports, true, false, curNode);
Bharat saraswale50edca2016-08-05 01:58:25 +05301583 addInvocationExceptionImport(imports);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301584 }
Bharat saraswal250a7472016-05-12 13:16:57 +05301585 sortImports(imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301586
1587 //Create impl class file.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301588 implClassJavaFileHandle =
1589 getJavaFileHandle(getImplClassName(curNode));
1590 implClassJavaFileHandle =
1591 generateDefaultClassFile(implClassJavaFileHandle,
1592 curNode, isAttributePresent,
1593 imports);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301594
1595 //Create builder class file.
Bharat saraswald14cbe82016-07-14 13:26:18 +05301596 if ((fileType & BUILDER_CLASS_MASK) != 0) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301597 builderClassJavaFileHandle =
1598 getJavaFileHandle(getJavaClassName(
1599 BUILDER_CLASS_FILE_NAME_SUFFIX));
1600 builderClassJavaFileHandle =
1601 generateBuilderClassFile(builderClassJavaFileHandle,
1602 curNode,
1603 isAttributePresent);
Vidyashree Ramab3670472016-08-06 15:49:56 +05301604
1605 //Append impl class to builder class and close it.
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301606 mergeJavaFiles(builderClassJavaFileHandle,
1607 implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301608 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301609 insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301610 validateLineLength(implClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301611 }
Vidyashree Ramab3670472016-08-06 15:49:56 +05301612 //Close all the file handles.
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301613 freeTemporaryResources(false);
1614 }
1615
Vidyashree Ramab3670472016-08-06 15:49:56 +05301616 //Adds import for array list.
Bharat saraswal8beac342016-08-04 02:00:03 +05301617 private void addArrayListImport(List<String> imports) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301618 if (imports.contains(javaImportData.getImportForList())) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301619 imports.add(ARRAY_LIST_IMPORT);
1620 }
1621 }
1622
Bharat saraswal8beac342016-08-04 02:00:03 +05301623 private void addBitsetImport(List<String> imports) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301624 imports.add(javaImportData.getImportForToBitSet());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301625 }
1626
1627 /**
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301628 * Adds imports for ToString and HashCodeMethod.
1629 *
Bharat saraswal039f59c2016-07-14 21:57:13 +05301630 * @param imports import list
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301631 * @param operation add or remove
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301632 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301633 protected void addImportsToStringAndHasCodeMethods(List<String> imports,
1634 boolean operation) {
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301635 if (operation) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301636 imports.add(javaImportData.getImportForHashAndEquals());
1637 imports.add(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301638 } else {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301639 imports.remove(javaImportData.getImportForHashAndEquals());
1640 imports.remove(javaImportData.getImportForToString());
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301641 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301642 // TODO change boolean to OPERATION, in all related places.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301643 }
1644
1645 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +05301646 * Adds import for map and hash map.
1647 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301648 * @param imports import list
1649 * @param operations true for adding and false for deletion
1650 * @param isInterfaceFile if need to add in interface file
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301651 * @param curNode current node
Bharat saraswalaf413b82016-07-14 15:18:20 +05301652 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301653 private void addImportsForAugmentableClass(List<String> imports,
1654 boolean operations,
1655 boolean isInterfaceFile,
VinodKumarS-Huawei8f164222016-08-31 15:47:30 +05301656 YangNode curNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +05301657 if (operations) {
Bharat saraswal8beac342016-08-04 02:00:03 +05301658 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301659 imports.add(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301660 }
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301661 // Add import for hash map only if node is not a YANG choice.
1662 if (!(curNode instanceof YangChoice)) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301663 imports.add(javaImportData.getMapImport());
Gaurav Agrawal8a147522016-08-10 13:43:01 +05301664 }
Bharat saraswal039f59c2016-07-14 21:57:13 +05301665 } else {
Bharat saraswal8beac342016-08-04 02:00:03 +05301666 if (!isInterfaceFile) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301667 imports.remove(javaImportData.getHashMapImport());
Bharat saraswal8beac342016-08-04 02:00:03 +05301668 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301669 imports.remove(javaImportData.getMapImport());
Bharat saraswald14cbe82016-07-14 13:26:18 +05301670 }
Bharat saraswal8beac342016-08-04 02:00:03 +05301671 sortImports(imports);
Bharat saraswald14cbe82016-07-14 13:26:18 +05301672 }
1673
1674 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301675 * Adds invocation exception import.
Bharat saraswal039f59c2016-07-14 21:57:13 +05301676 *
1677 * @param imports list of imports
Bharat saraswal039f59c2016-07-14 21:57:13 +05301678 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301679 private void addInvocationExceptionImport(List<String> imports) {
1680 imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
Bharat saraswal039f59c2016-07-14 21:57:13 +05301681 }
1682
1683 /**
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301684 * Removes all temporary file handles.
1685 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301686 * @param errorOccurred flag indicating if error occurred
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301687 * @throws IOException when failed to delete the temporary files
1688 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301689 public void freeTemporaryResources(boolean errorOccurred)
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301690 throws IOException {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301691 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301692 * Close all java file handles and when error occurs delete the files.
1693 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301694 if (javaFlagSet(INTERFACE_MASK)) {
1695 closeFile(interfaceJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301696 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301697 if (javaFlagSet(BUILDER_CLASS_MASK)) {
1698 closeFile(builderClassJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301699 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301700 if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
1701 closeFile(builderInterfaceJavaFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301702 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301703 if (javaFlagSet(DEFAULT_CLASS_MASK)) {
1704 closeFile(implClassJavaFileHandle, errorOccurred);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301705 }
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +05301706 /*
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301707 * Close all temporary file handles and delete the files.
1708 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301709 if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
1710 closeFile(getterImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301711 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301712 if (tempFlagSet(ATTRIBUTES_MASK)) {
1713 closeFile(attributesTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301714 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301715 if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
1716 closeFile(hashCodeImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301717 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301718 if (tempFlagSet(TO_STRING_IMPL_MASK)) {
1719 closeFile(toStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301720 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301721 if (tempFlagSet(EQUALS_IMPL_MASK)) {
1722 closeFile(equalsImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301723 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301724 if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
1725 closeFile(fromStringImplTempFileHandle);
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301726 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301727 if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
1728 closeFile(addToListImplTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301729 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301730 if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
1731 closeFile(addToListInterfaceTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301732 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301733 if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
1734 closeFile(leafIdAttributeTempFileHandle);
Bharat saraswal8beac342016-08-04 02:00:03 +05301735 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301736 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
1737 closeFile(subtreeFilteringForLeafTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301738 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301739 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
1740 closeFile(getSubtreeFilteringForListTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301741 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301742 if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
1743 closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301744 }
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301745 if (tempFlagSet(EDIT_CONTENT_MASK)) {
1746 closeFile(editContentTempFileHandle);
Bharat saraswale50edca2016-08-05 01:58:25 +05301747 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301748 }
1749
1750 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301751 * Returns if the attribute needs to be accessed in a qualified manner or
1752 * not, if it needs to be imported, then the same needs to be done.
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301753 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301754 * @param importInfo import info
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301755 * @return status of the qualified access to the attribute
1756 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +05301757 protected boolean getIsQualifiedAccessOrAddToImportList(
1758 JavaQualifiedTypeInfo importInfo) {
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301759 return javaImportData
1760 .addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
1761 getGeneratedJavaClassName(),
1762 javaFileInfo.getPackage());
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301763 }
1764
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301765 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301766 * Returns temp file handle for add to list interface.
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301767 *
Bharat saraswal8beac342016-08-04 02:00:03 +05301768 * @return temp file handle for add to list interface
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301769 */
Bharat saraswal8beac342016-08-04 02:00:03 +05301770 public File getAddToListInterfaceTempFileHandle() {
1771 return addToListInterfaceTempFileHandle;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301772 }
1773
1774 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301775 * Returns temp file handle for add to list impl.
1776 *
1777 * @return temp file handle for add to list impl
1778 */
1779 public File getAddToListImplTempFileHandle() {
1780 return addToListImplTempFileHandle;
1781 }
1782
1783 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301784 * Returns temp file handle for leaf identifier attributes.
1785 *
1786 * @return temp file handle for leaf identifier attributes
1787 */
1788 public File getLeafIdAttributeTempFileHandle() {
1789 return leafIdAttributeTempFileHandle;
1790 }
1791
1792 /**
Bharat saraswal8beac342016-08-04 02:00:03 +05301793 * Sets true if root node.
1794 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301795 * @param rootNode true if root node
Bharat saraswal8beac342016-08-04 02:00:03 +05301796 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301797 void setRootNode(boolean rootNode) {
1798 this.rootNode = rootNode;
Shankara-Huaweia1039e52016-07-14 16:53:09 +05301799 }
Bharat saraswale50edca2016-08-05 01:58:25 +05301800
1801 /**
1802 * Returns temp file for is content match.
1803 *
1804 * @return temp file for is content match
1805 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301806 public File getSubtreeFilteringForLeafTempFileHandle() {
1807 return subtreeFilteringForLeafTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301808 }
1809
1810 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301811 * Returns temp file for edit content file.
1812 *
1813 * @return temp file for edit content file
1814 */
1815 public File getEditContentTempFileHandle() {
1816 return editContentTempFileHandle;
1817 }
1818
1819 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301820 * Returns temp file for is content match.
1821 *
1822 * @return temp file for is content match
1823 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301824 public File getGetSubtreeFilteringForListTempFileHandle() {
1825 return getSubtreeFilteringForListTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301826 }
1827
1828 /**
Bharat saraswale50edca2016-08-05 01:58:25 +05301829 * Returns temp file for is content match.
1830 *
1831 * @return temp file for is content match
1832 */
VinodKumarS-Huawei9a91b482016-08-19 23:22:59 +05301833 public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
1834 return getSubtreeFilteringForChildNodeTempFileHandle;
Bharat saraswale50edca2016-08-05 01:58:25 +05301835 }
1836
1837 /**
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301838 * Checks if a given flag is set in generated java files.
1839 * Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
1840 * <pre>
1841 * javaFlagSet(FOO | BAR)
1842 * </pre>
1843 * returns true if either FOO flag or BAR flag is set.
Bharat saraswale50edca2016-08-05 01:58:25 +05301844 *
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301845 * @param flag input flag mask value
1846 * @return true if set, else false
Bharat saraswale50edca2016-08-05 01:58:25 +05301847 */
Gaurav Agrawal3b57f362016-09-07 13:16:35 +05301848 private boolean javaFlagSet(int flag) {
1849 return (getGeneratedJavaFiles() & flag) != 0;
1850 }
1851
1852 /**
1853 * Checks if a given flag is set in temp files.
1854 *
1855 * @param flag input flag mask value
1856 * @return true if set, else false
1857 */
1858 private boolean tempFlagSet(int flag) {
1859 return (tempFilesFlagSet & flag) != 0;
Bharat saraswale50edca2016-08-05 01:58:25 +05301860 }
Vinod Kumar S79a374b2016-04-30 21:09:15 +05301861}