Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.yangutils.translator.tojava; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.IOException; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.List; |
| 22 | import java.util.Set; |
| 23 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangCase; |
| 26 | import org.onosproject.yangutils.datamodel.YangEnum; |
| 27 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
| 28 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 29 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 30 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 31 | import org.onosproject.yangutils.datamodel.YangNode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 33 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 35 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
| 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
| 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 52 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
| 54 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; |
| 55 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
| 56 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
| 57 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
| 58 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; |
| 59 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; |
| 60 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; |
| 61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
| 63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 64 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 65 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 66 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
| 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
| 68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
| 70 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 71 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
| 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 78 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
| 80 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
| 81 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
| 82 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
| 84 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; |
| 85 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils |
| 86 | .isHasAugmentationExtended; |
| 87 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils |
| 88 | .prepareJavaFileGeneratorForExtendsList; |
| 89 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 90 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 91 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 92 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 93 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 94 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
| 95 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 97 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 98 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 99 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
| 100 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
| 101 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 102 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 104 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 105 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 106 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
| 107 | |
| 108 | /** |
| 109 | * Represents implementation of java code fragments temporary implementations. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 110 | * Manages the common temp file required for Java file(s) generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 111 | */ |
| 112 | public class TempJavaFragmentFiles { |
| 113 | /** |
| 114 | * Information about the java files being generated. |
| 115 | */ |
| 116 | private JavaFileInfo javaFileInfo; |
| 117 | /** |
| 118 | * Imported class info. |
| 119 | */ |
| 120 | private JavaImportData javaImportData; |
| 121 | /** |
| 122 | * The variable which guides the types of temporary files generated using |
| 123 | * the temporary generated file types mask. |
| 124 | */ |
| 125 | private int generatedTempFiles; |
| 126 | /** |
| 127 | * Absolute path where the target java file needs to be generated. |
| 128 | */ |
| 129 | private String absoluteDirPath; |
| 130 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 131 | * Contains all the interface(s)/class name which will be extended by generated files. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 132 | */ |
| 133 | private List<String> extendsList = new ArrayList<>(); |
| 134 | /** |
| 135 | * File type extension for java classes. |
| 136 | */ |
| 137 | private static final String JAVA_FILE_EXTENSION = ".java"; |
| 138 | /** |
| 139 | * File type extension for temporary classes. |
| 140 | */ |
| 141 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
| 142 | /** |
| 143 | * Folder suffix for temporary files folder. |
| 144 | */ |
| 145 | private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 146 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 147 | /** |
| 148 | * File name for getter method. |
| 149 | */ |
| 150 | private static final String GETTER_METHOD_FILE_NAME = "GetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 151 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 152 | /** |
| 153 | * File name for setter method. |
| 154 | */ |
| 155 | private static final String SETTER_METHOD_FILE_NAME = "SetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * File name for getter method implementation. |
| 159 | */ |
| 160 | private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl"; |
| 161 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 162 | /** |
| 163 | * File name for setter method implementation. |
| 164 | */ |
| 165 | private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 166 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 167 | /** |
| 168 | * File name for attributes. |
| 169 | */ |
| 170 | private static final String ATTRIBUTE_FILE_NAME = "Attributes"; |
| 171 | /** |
| 172 | * File name for to string method. |
| 173 | */ |
| 174 | private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; |
| 175 | /** |
| 176 | * File name for hash code method. |
| 177 | */ |
| 178 | private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; |
| 179 | /** |
| 180 | * File name for equals method. |
| 181 | */ |
| 182 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 183 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 184 | /** |
| 185 | * File name for temporary enum class. |
| 186 | */ |
| 187 | private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 188 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 189 | /** |
| 190 | * File name for interface java file name suffix. |
| 191 | */ |
| 192 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
| 193 | /** |
| 194 | * File name for builder interface file name suffix. |
| 195 | */ |
| 196 | private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; |
| 197 | /** |
| 198 | * File name for builder class file name suffix. |
| 199 | */ |
| 200 | private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; |
| 201 | /** |
| 202 | * File name for impl class file name suffix. |
| 203 | */ |
| 204 | private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 205 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 206 | /** |
| 207 | * File name for enum class file name suffix. |
| 208 | */ |
| 209 | private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 210 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 211 | /** |
| 212 | * Java file handle for interface file. |
| 213 | */ |
| 214 | private File interfaceJavaFileHandle; |
| 215 | /** |
| 216 | * Java file handle for builder interface file. |
| 217 | */ |
| 218 | private File builderInterfaceJavaFileHandle; |
| 219 | /** |
| 220 | * Java file handle for builder class file. |
| 221 | */ |
| 222 | private File builderClassJavaFileHandle; |
| 223 | /** |
| 224 | * Java file handle for impl class file. |
| 225 | */ |
| 226 | private File implClassJavaFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 227 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 228 | /** |
| 229 | * Temporary file handle for attribute. |
| 230 | */ |
| 231 | private File attributesTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 232 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 233 | /** |
| 234 | * Temporary file handle for getter of interface. |
| 235 | */ |
| 236 | private File getterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 237 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 238 | /** |
| 239 | * Temporary file handle for setter of interface. |
| 240 | */ |
| 241 | private File setterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * Temporary file handle for getter of class. |
| 245 | */ |
| 246 | private File getterImplTempFileHandle; |
| 247 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 248 | /** |
| 249 | * Temporary file handle for setter of class. |
| 250 | */ |
| 251 | private File setterImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 252 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 253 | /** |
| 254 | * Temporary file handle for hash code method of class. |
| 255 | */ |
| 256 | private File hashCodeImplTempFileHandle; |
| 257 | /** |
| 258 | * Temporary file handle for equals method of class. |
| 259 | */ |
| 260 | private File equalsImplTempFileHandle; |
| 261 | /** |
| 262 | * Temporary file handle for to string method of class. |
| 263 | */ |
| 264 | private File toStringImplTempFileHandle; |
| 265 | /** |
| 266 | * Temporary file handle for enum class file. |
| 267 | */ |
| 268 | private File enumClassTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 269 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 270 | /** |
| 271 | * Import info for case. |
| 272 | */ |
| 273 | private JavaQualifiedTypeInfo caseImportInfo; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 274 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 275 | /** |
| 276 | * Is attribute added. |
| 277 | */ |
| 278 | private boolean isAttributePresent = false; |
| 279 | /** |
| 280 | * Current enum's value. |
| 281 | */ |
| 282 | private int enumValue; |
| 283 | /* |
| 284 | * Java file handle for enum class. |
| 285 | */ |
| 286 | private File enumClassJavaFileHandle; |
| 287 | |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame^] | 288 | public TempJavaFragmentFiles() { |
| 289 | } |
| 290 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 291 | /** |
| 292 | * Returns enum class java file handle. |
| 293 | * |
| 294 | * @return enum class java file handle |
| 295 | */ |
| 296 | private File getEnumClassJavaFileHandle() { |
| 297 | return enumClassJavaFileHandle; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Sets enum class java file handle. |
| 302 | * |
| 303 | * @param enumClassJavaFileHandle enum class java file handle |
| 304 | */ |
| 305 | private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) { |
| 306 | this.enumClassJavaFileHandle = enumClassJavaFileHandle; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Returns enum's value. |
| 311 | * |
| 312 | * @return enum's value |
| 313 | */ |
| 314 | private int getEnumValue() { |
| 315 | return enumValue; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Sets enum's value. |
| 320 | * |
| 321 | * @param enumValue enum's value |
| 322 | */ |
| 323 | private void setEnumValue(int enumValue) { |
| 324 | this.enumValue = enumValue; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Retrieves the absolute path where the file needs to be generated. |
| 329 | * |
| 330 | * @return absolute path where the file needs to be generated |
| 331 | */ |
| 332 | private String getAbsoluteDirPath() { |
| 333 | return absoluteDirPath; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Sets absolute path where the file needs to be generated. |
| 338 | * |
| 339 | * @param absoluteDirPath absolute path where the file needs to be |
| 340 | * generated. |
| 341 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 342 | void setAbsoluteDirPath(String absoluteDirPath) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 343 | this.absoluteDirPath = absoluteDirPath; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Sets the generated java file information. |
| 348 | * |
| 349 | * @param javaFileInfo generated java file information |
| 350 | */ |
| 351 | public void setJavaFileInfo(JavaFileInfo javaFileInfo) { |
| 352 | this.javaFileInfo = javaFileInfo; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Retrieves the generated java file information. |
| 357 | * |
| 358 | * @return generated java file information |
| 359 | */ |
| 360 | public JavaFileInfo getJavaFileInfo() { |
| 361 | return javaFileInfo; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Retrieves the generated temp files. |
| 366 | * |
| 367 | * @return generated temp files |
| 368 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 369 | int getGeneratedTempFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 370 | return generatedTempFiles; |
| 371 | } |
| 372 | |
| 373 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 374 | * Clears the generated file mask. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 375 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 376 | void clearGeneratedTempFileMask() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 377 | generatedTempFiles = 0; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Sets generated file files. |
| 382 | * |
| 383 | * @param generatedTempFile generated file |
| 384 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 385 | void addGeneratedTempFile(int generatedTempFile) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 386 | generatedTempFiles |= generatedTempFile; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Retrieves the generated Java files. |
| 391 | * |
| 392 | * @return generated Java files |
| 393 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 394 | int getGeneratedJavaFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 395 | return getJavaFileInfo().getGeneratedFileTypes(); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Retrieves the mapped Java class name. |
| 400 | * |
| 401 | * @return mapped Java class name |
| 402 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 403 | String getGeneratedJavaClassName() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 404 | return getJavaFileInfo().getJavaName(); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Retrieves the import data for the generated Java file. |
| 409 | * |
| 410 | * @return import data for the generated Java file |
| 411 | */ |
| 412 | public JavaImportData getJavaImportData() { |
| 413 | return javaImportData; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Sets import data for the generated Java file. |
| 418 | * |
| 419 | * @param javaImportData import data for the generated Java file |
| 420 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 421 | void setJavaImportData(JavaImportData javaImportData) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 422 | this.javaImportData = javaImportData; |
| 423 | } |
| 424 | |
| 425 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 426 | * Retrieves the status of any attributes added. |
| 427 | * |
| 428 | * @return status of any attributes added |
| 429 | */ |
| 430 | public boolean isAttributePresent() { |
| 431 | return isAttributePresent; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Sets status of any attributes added. |
| 436 | * |
| 437 | * @param attributePresent status of any attributes added |
| 438 | */ |
| 439 | public void setAttributePresent(boolean attributePresent) { |
| 440 | isAttributePresent = attributePresent; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Returns getter methods's temporary file handle. |
| 445 | * |
| 446 | * @return temporary file handle |
| 447 | */ |
| 448 | public File getGetterInterfaceTempFileHandle() { |
| 449 | return getterInterfaceTempFileHandle; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Sets to getter method's temporary file handle. |
| 454 | * |
| 455 | * @param getterForInterface file handle for to getter method |
| 456 | */ |
| 457 | private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
| 458 | getterInterfaceTempFileHandle = getterForInterface; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Returns setter method's temporary file handle. |
| 463 | * |
| 464 | * @return temporary file handle |
| 465 | */ |
| 466 | public File getSetterInterfaceTempFileHandle() { |
| 467 | return setterInterfaceTempFileHandle; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Sets to setter method's temporary file handle. |
| 472 | * |
| 473 | * @param setterForInterface file handle for to setter method |
| 474 | */ |
| 475 | private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
| 476 | setterInterfaceTempFileHandle = setterForInterface; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Returns setter method's impl's temporary file handle. |
| 481 | * |
| 482 | * @return temporary file handle |
| 483 | */ |
| 484 | public File getSetterImplTempFileHandle() { |
| 485 | return setterImplTempFileHandle; |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Sets to setter method's impl's temporary file handle. |
| 490 | * |
| 491 | * @param setterImpl file handle for to setter method's implementation class |
| 492 | */ |
| 493 | private void setSetterImplTempFileHandle(File setterImpl) { |
| 494 | setterImplTempFileHandle = setterImpl; |
| 495 | } |
| 496 | |
| 497 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 498 | * Creates an instance of temporary java code fragment. |
| 499 | * |
| 500 | * @param javaFileInfo generated java file information |
| 501 | * @throws IOException when fails to create new file handle |
| 502 | */ |
| 503 | TempJavaFragmentFiles(JavaFileInfo javaFileInfo) |
| 504 | throws IOException { |
| 505 | setExtendsList(new ArrayList<>()); |
| 506 | setJavaImportData(new JavaImportData()); |
| 507 | setJavaFileInfo(javaFileInfo); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 508 | clearGeneratedTempFileMask(); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 509 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 510 | getJavaFileInfo().getPackageFilePath())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 511 | |
| 512 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 513 | * Initialize getter when generation file type matches to interface |
| 514 | * mask. |
| 515 | */ |
| 516 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 517 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 518 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 519 | |
| 520 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 521 | * Initialize getter and setter when generation file type matches to |
| 522 | * builder interface mask. |
| 523 | */ |
| 524 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 525 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 526 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
| 527 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 528 | |
| 529 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 530 | * Initialize getterImpl, setterImpl and attributes when generation file |
| 531 | * type matches to builder class mask. |
| 532 | */ |
| 533 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 534 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 535 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 536 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
| 537 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 538 | |
| 539 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 540 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 541 | * to strings when generation file type matches to impl class mask. |
| 542 | */ |
| 543 | if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) { |
| 544 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 545 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 546 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 547 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 548 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
| 549 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * Initialize temp files to generate type class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 553 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 554 | if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 555 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 556 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 557 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 558 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 559 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 560 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * Initialize getter and setter when generation file type matches to |
| 564 | * builder interface mask. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 565 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 566 | if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 567 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 568 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 569 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 570 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 571 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 572 | |
| 573 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 574 | * Initialize enum when generation file type matches to enum class mask. |
| 575 | */ |
| 576 | if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) { |
| 577 | addGeneratedTempFile(ENUM_IMPL_MASK); |
| 578 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 579 | |
| 580 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 581 | * Set temporary file handles. |
| 582 | */ |
| 583 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 584 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
| 585 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 586 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 587 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 588 | setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME)); |
| 589 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 590 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 591 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 592 | setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME)); |
| 593 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 594 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 595 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 596 | setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME)); |
| 597 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 598 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 599 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 600 | setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME)); |
| 601 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 602 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 603 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 604 | setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME)); |
| 605 | } |
| 606 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 607 | setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME)); |
| 608 | } |
| 609 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 610 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
| 611 | } |
| 612 | if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { |
| 613 | setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME)); |
| 614 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Returns java file handle for interface file. |
| 619 | * |
| 620 | * @return java file handle for interface file |
| 621 | */ |
| 622 | private File getInterfaceJavaFileHandle() { |
| 623 | return interfaceJavaFileHandle; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Sets the java file handle for interface file. |
| 628 | * |
| 629 | * @param interfaceJavaFileHandle java file handle |
| 630 | */ |
| 631 | private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
| 632 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Returns java file handle for builder interface file. |
| 637 | * |
| 638 | * @return java file handle for builder interface file |
| 639 | */ |
| 640 | private File getBuilderInterfaceJavaFileHandle() { |
| 641 | return builderInterfaceJavaFileHandle; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Sets the java file handle for builder interface file. |
| 646 | * |
| 647 | * @param builderInterfaceJavaFileHandle java file handle |
| 648 | */ |
| 649 | private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
| 650 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Returns java file handle for builder class file. |
| 655 | * |
| 656 | * @return java file handle for builder class file |
| 657 | */ |
| 658 | private File getBuilderClassJavaFileHandle() { |
| 659 | return builderClassJavaFileHandle; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Sets the java file handle for builder class file. |
| 664 | * |
| 665 | * @param builderClassJavaFileHandle java file handle |
| 666 | */ |
| 667 | private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
| 668 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Returns java file handle for impl class file. |
| 673 | * |
| 674 | * @return java file handle for impl class file |
| 675 | */ |
| 676 | private File getImplClassJavaFileHandle() { |
| 677 | return implClassJavaFileHandle; |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Sets the java file handle for impl class file. |
| 682 | * |
| 683 | * @param implClassJavaFileHandle java file handle |
| 684 | */ |
| 685 | private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
| 686 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
| 687 | } |
| 688 | |
| 689 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 690 | * Returns attribute's temporary file handle. |
| 691 | * |
| 692 | * @return temporary file handle |
| 693 | */ |
| 694 | public File getAttributesTempFileHandle() { |
| 695 | return attributesTempFileHandle; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Sets attribute's temporary file handle. |
| 700 | * |
| 701 | * @param attributeForClass file handle for attribute |
| 702 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 703 | void setAttributesTempFileHandle(File attributeForClass) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 704 | attributesTempFileHandle = attributeForClass; |
| 705 | } |
| 706 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 707 | |
| 708 | /** |
| 709 | * Returns getter method's impl's temporary file handle. |
| 710 | * |
| 711 | * @return temporary file handle |
| 712 | */ |
| 713 | public File getGetterImplTempFileHandle() { |
| 714 | return getterImplTempFileHandle; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Sets to getter method's impl's temporary file handle. |
| 719 | * |
| 720 | * @param getterImpl file handle for to getter method's impl |
| 721 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 722 | void setGetterImplTempFileHandle(File getterImpl) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 723 | getterImplTempFileHandle = getterImpl; |
| 724 | } |
| 725 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 726 | |
| 727 | /** |
| 728 | * Returns hash code method's temporary file handle. |
| 729 | * |
| 730 | * @return temporary file handle |
| 731 | */ |
| 732 | public File getHashCodeImplTempFileHandle() { |
| 733 | return hashCodeImplTempFileHandle; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Sets hash code method's temporary file handle. |
| 738 | * |
| 739 | * @param hashCodeMethod file handle for hash code method |
| 740 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 741 | void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 742 | hashCodeImplTempFileHandle = hashCodeMethod; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns equals mehtod's temporary file handle. |
| 747 | * |
| 748 | * @return temporary file handle |
| 749 | */ |
| 750 | public File getEqualsImplTempFileHandle() { |
| 751 | return equalsImplTempFileHandle; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Sets equals method's temporary file handle. |
| 756 | * |
| 757 | * @param equalsMethod file handle for to equals method |
| 758 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 759 | void setEqualsImplTempFileHandle(File equalsMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 760 | equalsImplTempFileHandle = equalsMethod; |
| 761 | } |
| 762 | |
| 763 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 764 | * Returns to string method's temporary file handle. |
| 765 | * |
| 766 | * @return temporary file handle |
| 767 | */ |
| 768 | public File getToStringImplTempFileHandle() { |
| 769 | return toStringImplTempFileHandle; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Sets to string method's temporary file handle. |
| 774 | * |
| 775 | * @param toStringMethod file handle for to string method |
| 776 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 777 | void setToStringImplTempFileHandle(File toStringMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 778 | toStringImplTempFileHandle = toStringMethod; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Returns temporary file handle for enum class file. |
| 783 | * |
| 784 | * @return temporary file handle for enum class file |
| 785 | */ |
| 786 | public File getEnumClassTempFileHandle() { |
| 787 | return enumClassTempFileHandle; |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * Sets temporary file handle for enum class file. |
| 792 | * |
| 793 | * @param enumClassTempFileHandle temporary file handle for enum class file |
| 794 | */ |
| 795 | private void setEnumClassTempFileHandle(File enumClassTempFileHandle) { |
| 796 | this.enumClassTempFileHandle = enumClassTempFileHandle; |
| 797 | } |
| 798 | |
| 799 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 800 | * Returns list of classes to be extended by generated files. |
| 801 | * |
| 802 | * @return list of classes to be extended by generated files |
| 803 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 804 | List<String> getExtendsList() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 805 | return extendsList; |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Sets class to be extended by generated file. |
| 810 | * |
| 811 | * @param extendsList list of classes to be extended |
| 812 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 813 | void setExtendsList(List<String> extendsList) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 814 | this.extendsList = extendsList; |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Adds class to the extends list. |
| 819 | * |
| 820 | * @param extend class to be extended |
| 821 | */ |
| 822 | public void addToExtendsList(String extend) { |
| 823 | getExtendsList().add(extend); |
| 824 | } |
| 825 | |
| 826 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 827 | * Adds attribute for class. |
| 828 | * |
| 829 | * @param attr attribute info |
| 830 | * @throws IOException when fails to append to temporary file |
| 831 | */ |
| 832 | private void addAttribute(JavaAttributeInfo attr) |
| 833 | throws IOException { |
| 834 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Adds getter for interface. |
| 839 | * |
| 840 | * @param attr attribute info |
| 841 | * @throws IOException when fails to append to temporary file |
| 842 | */ |
| 843 | private void addGetterForInterface(JavaAttributeInfo attr) |
| 844 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 845 | appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Adds setter for interface. |
| 850 | * |
| 851 | * @param attr attribute info |
| 852 | * @throws IOException when fails to append to temporary file |
| 853 | */ |
| 854 | private void addSetterForInterface(JavaAttributeInfo attr) |
| 855 | throws IOException { |
| 856 | appendToFile(getSetterInterfaceTempFileHandle(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 857 | getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /** |
| 861 | * Adds setter's implementation for class. |
| 862 | * |
| 863 | * @param attr attribute info |
| 864 | * @throws IOException when fails to append to temporary file |
| 865 | */ |
| 866 | private void addSetterImpl(JavaAttributeInfo attr) |
| 867 | throws IOException { |
| 868 | appendToFile(getSetterImplTempFileHandle(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 869 | getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + |
| 870 | NEW_LINE); |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Adds getter method's impl for class. |
| 875 | * |
| 876 | * @param attr attribute info |
| 877 | * @throws IOException when fails to append to temporary file |
| 878 | */ |
| 879 | private void addGetterImpl(JavaAttributeInfo attr) |
| 880 | throws IOException { |
| 881 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 |
| 882 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 883 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr, |
| 884 | getGeneratedJavaFiles()) + NEW_LINE); |
| 885 | } else { |
| 886 | appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false) |
| 887 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); |
| 888 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | /** |
| 892 | * Adds build method for interface. |
| 893 | * |
| 894 | * @return build method for interface |
| 895 | * @throws IOException when fails to append to temporary file |
| 896 | */ |
| 897 | String addBuildMethodForInterface() |
| 898 | throws IOException { |
| 899 | return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName()); |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * Adds build method's implementation for class. |
| 904 | * |
| 905 | * @return build method implementation for class |
| 906 | * @throws IOException when fails to append to temporary file |
| 907 | */ |
| 908 | String addBuildMethodImpl() |
| 909 | throws IOException { |
| 910 | return getBuildString(getGeneratedJavaClassName()) + NEW_LINE; |
| 911 | } |
| 912 | |
| 913 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 914 | * Adds default constructor for class. |
| 915 | * |
| 916 | * @param modifier modifier for constructor. |
| 917 | * @param toAppend string which need to be appended with the class name |
| 918 | * @return default constructor for class |
| 919 | * @throws IOException when fails to append to file |
| 920 | */ |
| 921 | String addDefaultConstructor(String modifier, String toAppend) |
| 922 | throws IOException { |
| 923 | return NEW_LINE + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier); |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * Adds default constructor for class. |
| 928 | * |
| 929 | * @return default constructor for class |
| 930 | * @throws IOException when fails to append to file |
| 931 | */ |
| 932 | public String addOfMethod() |
| 933 | throws IOException { |
| 934 | return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false) |
| 935 | + getOfMethod(getGeneratedJavaClassName(), null); |
| 936 | } |
| 937 | |
| 938 | /** |
| 939 | * Adds hash code method for class. |
| 940 | * |
| 941 | * @param attr attribute info |
| 942 | * @throws IOException when fails to append to temporary file |
| 943 | */ |
| 944 | private void addHashCodeMethod(JavaAttributeInfo attr) |
| 945 | throws IOException { |
| 946 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * Adds equals method for class. |
| 951 | * |
| 952 | * @param attr attribute info |
| 953 | * @throws IOException when fails to append to temporary file |
| 954 | */ |
| 955 | private void addEqualsMethod(JavaAttributeInfo attr) |
| 956 | throws IOException { |
| 957 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Adds ToString method for class. |
| 962 | * |
| 963 | * @param attr attribute info |
| 964 | * @throws IOException when fails to append to temporary file |
| 965 | */ |
| 966 | private void addToStringMethod(JavaAttributeInfo attr) |
| 967 | throws IOException { |
| 968 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * Adds enum class attributes to temporary file. |
| 973 | * |
| 974 | * @param curEnumInfo current YANG enum |
| 975 | * @throws IOException when fails to do IO operations. |
| 976 | */ |
| 977 | private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) |
| 978 | throws IOException { |
| 979 | appendToFile(getEnumClassTempFileHandle(), |
| 980 | generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue())); |
| 981 | } |
| 982 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 983 | |
| 984 | /** |
| 985 | * Returns a temporary file handle for the specific file type. |
| 986 | * |
| 987 | * @param fileName file name |
| 988 | * @return temporary file handle |
| 989 | * @throws IOException when fails to create new file handle |
| 990 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 991 | File getTemporaryFileHandle(String fileName) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 992 | throws IOException { |
| 993 | String path = getTempDirPath(); |
| 994 | File dir = new File(path); |
| 995 | if (!dir.exists()) { |
| 996 | dir.mkdirs(); |
| 997 | } |
| 998 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
| 999 | if (!file.exists()) { |
| 1000 | file.createNewFile(); |
| 1001 | } |
| 1002 | return file; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * Returns a temporary file handle for the specific file type. |
| 1007 | * |
| 1008 | * @param fileName file name |
| 1009 | * @return temporary file handle |
| 1010 | * @throws IOException when fails to create new file handle |
| 1011 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1012 | File getJavaFileHandle(String fileName) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1013 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1014 | // createPackage(getAbsoluteDirPath(), getJavaFileInfo().getJavaName()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1015 | return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Returns data from the temporary files. |
| 1020 | * |
| 1021 | * @param file temporary file handle |
| 1022 | * @return stored data from temporary files |
| 1023 | * @throws IOException when failed to get data from the given file |
| 1024 | */ |
| 1025 | public String getTemporaryDataFromFileHandle(File file) |
| 1026 | throws IOException { |
| 1027 | String path = getTempDirPath(); |
| 1028 | if (new File(path + file.getName()).exists()) { |
| 1029 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
| 1030 | } else { |
| 1031 | throw new IOException("Unable to get data from the given " |
| 1032 | + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /** |
| 1037 | * Returns temporary directory path. |
| 1038 | * |
| 1039 | * @return directory path |
| 1040 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1041 | String getTempDirPath() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1042 | return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName() |
| 1043 | + TEMP_FOLDER_NAME_SUFIX + SLASH; |
| 1044 | } |
| 1045 | |
| 1046 | /** |
| 1047 | * Parses attribute to get the attribute string. |
| 1048 | * |
| 1049 | * @param attr attribute info |
| 1050 | * @return attribute string |
| 1051 | */ |
| 1052 | private String parseAttribute(JavaAttributeInfo attr) { |
| 1053 | /* |
| 1054 | * TODO: check if this utility needs to be called or move to the caller |
| 1055 | */ |
| 1056 | String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null); |
| 1057 | if (attr.isQualifiedName()) { |
| 1058 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), |
| 1059 | attributeName, attr.isListAttr()); |
| 1060 | } else { |
| 1061 | return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName, |
| 1062 | attr.isListAttr()); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | /** |
| 1067 | * Appends content to temporary file. |
| 1068 | * |
| 1069 | * @param file temporary file |
| 1070 | * @param data data to be appended |
| 1071 | * @throws IOException when fails to append to file |
| 1072 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1073 | void appendToFile(File file, String data) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1074 | throws IOException { |
| 1075 | try { |
| 1076 | insertDataIntoJavaFile(file, data); |
| 1077 | } catch (IOException ex) { |
| 1078 | throw new IOException("failed to write in temp file."); |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * Adds current node info as and attribute to the parent generated file. |
| 1084 | * |
| 1085 | * @param curNode current node which needs to be added as an attribute in |
| 1086 | * the parent generated code |
| 1087 | * @param isList is list construct |
| 1088 | * @throws IOException IO operation exception |
| 1089 | */ |
| 1090 | public static void addCurNodeInfoInParentTempFile(YangNode curNode, |
| 1091 | boolean isList) |
| 1092 | throws IOException { |
| 1093 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1094 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1095 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1096 | } |
| 1097 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, |
| 1098 | parent, isList); |
| 1099 | if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) { |
| 1100 | throw new TranslatorException("missing parent temp file handle"); |
| 1101 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1102 | getNodesInterfaceFragmentFiles(parent) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1103 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Creates an attribute info object corresponding to a data model node and |
| 1108 | * return it. |
| 1109 | * |
| 1110 | * @param curNode current data model node for which the java code generation |
| 1111 | * is being handled |
| 1112 | * @param parentNode parent node in which the current node is an attribute |
| 1113 | * @param isListNode is the current added attribute needs to be a list |
| 1114 | * @return AttributeInfo attribute details required to add in temporary |
| 1115 | * files |
| 1116 | */ |
| 1117 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( |
| 1118 | YangNode curNode, YangNode parentNode, boolean isListNode) { |
| 1119 | String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 1120 | /* |
| 1121 | * Get the import info corresponding to the attribute for import in |
| 1122 | * generated java files or qualified access |
| 1123 | */ |
| 1124 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, |
| 1125 | curNodeName); |
| 1126 | if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) { |
| 1127 | throw new TranslatorException("Parent node does not have file info"); |
| 1128 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1129 | TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1130 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); |
| 1131 | boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo); |
| 1132 | return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode); |
| 1133 | } |
| 1134 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1135 | public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) { |
| 1136 | TempJavaFragmentFiles tempJavaFragmentFiles; |
| 1137 | if (node instanceof RpcNotificationContainer) { |
| 1138 | tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node) |
| 1139 | .getTempJavaCodeFragmentFiles() |
| 1140 | .getServiceTempFiles(); |
| 1141 | } else { |
| 1142 | tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node) |
| 1143 | .getTempJavaCodeFragmentFiles() |
| 1144 | .getBeanTempFiles(); |
| 1145 | } |
| 1146 | return tempJavaFragmentFiles; |
| 1147 | } |
| 1148 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1149 | /** |
| 1150 | * Adds parent's info to current node import list. |
| 1151 | * |
| 1152 | * @param curNode current node for which import list needs to be updated |
| 1153 | */ |
| 1154 | public void addParentInfoInCurNodeTempFile(YangNode curNode) { |
| 1155 | caseImportInfo = new JavaQualifiedTypeInfo(); |
| 1156 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1157 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1158 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1159 | } |
| 1160 | if (!(curNode instanceof JavaFileInfoContainer)) { |
| 1161 | throw new TranslatorException("missing java file information to get the package details " |
| 1162 | + "of attribute corresponding to child node"); |
| 1163 | } |
| 1164 | caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null))); |
| 1165 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); |
| 1166 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1167 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo); |
| 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * Adds leaf attributes in generated files. |
| 1172 | * |
| 1173 | * @param listOfLeaves list of YANG leaf |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1174 | * @param yangPluginConfig |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1175 | * @throws IOException IO operation fail |
| 1176 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1177 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
| 1178 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1179 | throws IOException { |
| 1180 | if (listOfLeaves != null) { |
| 1181 | for (YangLeaf leaf : listOfLeaves) { |
| 1182 | if (!(leaf instanceof JavaLeafInfoContainer)) { |
| 1183 | throw new TranslatorException("Leaf does not have java information"); |
| 1184 | } |
| 1185 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; |
| 1186 | javaLeaf.updateJavaQualifiedInfo(); |
| 1187 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
| 1188 | javaLeaf.getJavaQualifiedInfo(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1189 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 1190 | javaLeaf.getDataType(), |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1191 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 1192 | false); |
| 1193 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * Adds leaf list's attributes in generated files. |
| 1200 | * |
| 1201 | * @param listOfLeafList list of YANG leaves |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1202 | * @param yangPluginConfig |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1203 | * @throws IOException IO operation fail |
| 1204 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1205 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1206 | throws IOException { |
| 1207 | if (listOfLeafList != null) { |
| 1208 | for (YangLeafList leafList : listOfLeafList) { |
| 1209 | if (!(leafList instanceof JavaLeafInfoContainer)) { |
| 1210 | throw new TranslatorException("Leaf-list does not have java information"); |
| 1211 | } |
| 1212 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; |
| 1213 | javaLeaf.updateJavaQualifiedInfo(); |
| 1214 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
| 1215 | javaLeaf.getJavaQualifiedInfo(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1216 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 1217 | javaLeaf.getDataType(), |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1218 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 1219 | true); |
| 1220 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Adds all the leaves in the current data model node as part of the |
| 1227 | * generated temporary file. |
| 1228 | * |
| 1229 | * @param curNode java file info of the generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1230 | * @param yangPluginConfig plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1231 | * @throws IOException IO operation fail |
| 1232 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1233 | public void addCurNodeLeavesInfoToTempFiles(YangNode curNode, |
| 1234 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1235 | throws IOException { |
| 1236 | if (!(curNode instanceof YangLeavesHolder)) { |
| 1237 | throw new TranslatorException("Data model node does not have any leaves"); |
| 1238 | } |
| 1239 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1240 | addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig); |
| 1241 | addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Adds enum attributes to temporary files. |
| 1246 | * |
| 1247 | * @param curNode current YANG node |
| 1248 | * @throws IOException when fails to do IO operations |
| 1249 | */ |
| 1250 | public void addEnumAttributeToTempFiles(YangNode curNode) |
| 1251 | throws IOException { |
| 1252 | if (curNode instanceof YangEnumeration) { |
| 1253 | Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet(); |
| 1254 | /* |
| 1255 | * Get the import info corresponding to the attribute for import in |
| 1256 | * generated java files or qualified access |
| 1257 | */ |
| 1258 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
| 1259 | getJavaFileInfo().getJavaName()); |
| 1260 | for (YangEnum curEnum : enumSet) { |
| 1261 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, |
| 1262 | curEnum.getNamedValue(), null, false, false); |
| 1263 | setEnumValue(curEnum.getValue()); |
| 1264 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1265 | } |
| 1266 | } else { |
| 1267 | throw new TranslatorException("current node should be of type enum."); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1272 | * Adds the new attribute info to the target generated temporary files. |
| 1273 | * |
| 1274 | * @param newAttrInfo the attribute info that needs to be added to temporary |
| 1275 | * files |
| 1276 | * @throws IOException IO operation fail |
| 1277 | */ |
| 1278 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
| 1279 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1280 | setAttributePresent(true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1281 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1282 | addAttribute(newAttrInfo); |
| 1283 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1284 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1285 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 1286 | addGetterForInterface(newAttrInfo); |
| 1287 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1288 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1289 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 1290 | addSetterForInterface(newAttrInfo); |
| 1291 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1292 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1293 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 1294 | addSetterImpl(newAttrInfo); |
| 1295 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1296 | |
| 1297 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1298 | addGetterImpl(newAttrInfo); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1299 | } |
| 1300 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1301 | addHashCodeMethod(newAttrInfo); |
| 1302 | } |
| 1303 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1304 | addEqualsMethod(newAttrInfo); |
| 1305 | } |
| 1306 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1307 | addToStringMethod(newAttrInfo); |
| 1308 | } |
| 1309 | if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { |
| 1310 | addAttributesForEnumClass(newAttrInfo); |
| 1311 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * Returns java class name. |
| 1316 | * |
| 1317 | * @param suffix for the class name based on the file type |
| 1318 | * @return java class name |
| 1319 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1320 | String getJavaClassName(String suffix) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1321 | return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix; |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Returns the directory path. |
| 1326 | * |
| 1327 | * @return directory path |
| 1328 | */ |
| 1329 | private String getDirPath() { |
| 1330 | return getJavaFileInfo().getPackageFilePath(); |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * Constructs java code exit. |
| 1335 | * |
| 1336 | * @param fileType generated file type |
| 1337 | * @param curNode current YANG node |
| 1338 | * @throws IOException when fails to generate java files |
| 1339 | */ |
| 1340 | public void generateJavaFile(int fileType, YangNode curNode) |
| 1341 | throws IOException { |
| 1342 | List<String> imports = new ArrayList<>(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1343 | if (isAttributePresent()) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1344 | imports = getJavaImportData().getImports(); |
| 1345 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1346 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1347 | * Prepares java file generator for extends list. |
| 1348 | */ |
| 1349 | prepareJavaFileGeneratorForExtendsList(getExtendsList()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1350 | createPackage(curNode); |
| 1351 | |
| 1352 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1353 | * Generate java code. |
| 1354 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1355 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & |
| 1356 | BUILDER_INTERFACE_MASK) != 0) { |
| 1357 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1358 | * Adds import for case. |
| 1359 | */ |
| 1360 | if (curNode instanceof YangCase) { |
| 1361 | List<String> importData = ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1362 | .getBeanTempFiles().getJavaImportData().getImports(); |
| 1363 | for (String importInfo : importData) { |
| 1364 | if (!imports.contains(importInfo)) { |
| 1365 | imports.add(importInfo); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1369 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1370 | * Adds import for HasAugmentation class. |
| 1371 | */ |
| 1372 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1373 | addHasAugmentationImport(curNode, imports, true); |
| 1374 | } |
| 1375 | if (isAugmentedInfoExtended(getExtendsList())) { |
| 1376 | addAugmentedInfoImport(curNode, imports, true); |
| 1377 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1378 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1379 | * Create interface file. |
| 1380 | */ |
| 1381 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
| 1382 | setInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1383 | generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent())); |
| 1384 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1385 | * Create builder interface file. |
| 1386 | */ |
| 1387 | if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1388 | setBuilderInterfaceJavaFileHandle( |
| 1389 | getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
| 1390 | setBuilderInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1391 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, |
| 1392 | isAttributePresent())); |
| 1393 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1394 | * Append builder interface file to interface file and close it. |
| 1395 | */ |
| 1396 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
| 1397 | } |
| 1398 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
| 1399 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1400 | addHasAugmentationImport(curNode, imports, false); |
| 1401 | } |
| 1402 | if (isAugmentedInfoExtended(getExtendsList())) { |
| 1403 | addAugmentedInfoImport(curNode, imports, false); |
| 1404 | } |
| 1405 | if (curNode instanceof YangCase) { |
| 1406 | removeCaseImport(imports); |
| 1407 | } |
| 1408 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1409 | if (((fileType & GENERATE_SERVICE_AND_MANAGER) != 0) |
| 1410 | && ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0)) { |
| 1411 | if (isAttributePresent()) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1412 | addImportsToStringAndHasCodeMethods(curNode, imports); |
| 1413 | } |
| 1414 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1415 | addAugmentedInfoImport(curNode, imports, true); |
| 1416 | addArrayListImport(curNode, imports, true); |
| 1417 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1418 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1419 | * Create builder class file. |
| 1420 | */ |
| 1421 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
| 1422 | setBuilderClassJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1423 | generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent())); |
| 1424 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1425 | * Create impl class file. |
| 1426 | */ |
| 1427 | if ((fileType & IMPL_CLASS_MASK) != 0) { |
| 1428 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); |
| 1429 | setImplClassJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1430 | generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent())); |
| 1431 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1432 | * Append impl class to builder class and close it. |
| 1433 | */ |
| 1434 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); |
| 1435 | } |
| 1436 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); |
| 1437 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1438 | |
| 1439 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1440 | * Creates type enum class file. |
| 1441 | */ |
| 1442 | if ((fileType & GENERATE_ENUM_CLASS) != 0) { |
| 1443 | setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX))); |
| 1444 | setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode)); |
| 1445 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1446 | |
| 1447 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1448 | * Close all the file handles. |
| 1449 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1450 | freeTemporaryResources(false); |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * Adds imports for ToString and HashCodeMethod. |
| 1455 | * |
| 1456 | * @param curNode current YANG node |
| 1457 | * @param imports import list |
| 1458 | * @return import list |
| 1459 | */ |
| 1460 | public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) { |
| 1461 | imports.add(getJavaImportData().getImportForHashAndEquals()); |
| 1462 | imports.add(getJavaImportData().getImportForToString()); |
| 1463 | return imports; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
| 1467 | * Removes case import info from import list. |
| 1468 | * |
| 1469 | * @param imports list of imports |
| 1470 | * @return import for class |
| 1471 | */ |
| 1472 | private List<String> removeCaseImport(List<String> imports) { |
| 1473 | if (imports != null && caseImportInfo != null) { |
| 1474 | String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() + |
| 1475 | SEMI_COLAN + NEW_LINE; |
| 1476 | imports.remove(caseImport); |
| 1477 | } |
| 1478 | return imports; |
| 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * Removes all temporary file handles. |
| 1483 | * |
| 1484 | * @param isErrorOccurred when translator fails to generate java files we |
| 1485 | * need to close all open file handles include temporary files |
| 1486 | * and java files. |
| 1487 | * @throws IOException when failed to delete the temporary files |
| 1488 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1489 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1490 | throws IOException { |
| 1491 | boolean isError = isErrorOccurred; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1492 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1493 | * Close all java file handles and when error occurs delete the files. |
| 1494 | */ |
| 1495 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 1496 | closeFile(getInterfaceJavaFileHandle(), isError); |
| 1497 | } |
| 1498 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 1499 | closeFile(getBuilderClassJavaFileHandle(), isError); |
| 1500 | } |
| 1501 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 1502 | closeFile(getBuilderInterfaceJavaFileHandle(), true); |
| 1503 | } |
| 1504 | if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) { |
| 1505 | closeFile(getImplClassJavaFileHandle(), true); |
| 1506 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1507 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1508 | if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) { |
| 1509 | closeFile(getEnumClassJavaFileHandle(), isError); |
| 1510 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1511 | |
| 1512 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1513 | * Close all temporary file handles and delete the files. |
| 1514 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1515 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1516 | closeFile(getGetterImplTempFileHandle(), true); |
| 1517 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1518 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1519 | closeFile(getAttributesTempFileHandle(), true); |
| 1520 | } |
| 1521 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1522 | closeFile(getHashCodeImplTempFileHandle(), true); |
| 1523 | } |
| 1524 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1525 | closeFile(getToStringImplTempFileHandle(), true); |
| 1526 | } |
| 1527 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1528 | closeFile(getEqualsImplTempFileHandle(), true); |
| 1529 | } |
| 1530 | if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { |
| 1531 | closeFile(getEnumClassTempFileHandle(), true); |
| 1532 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * Returns if the attribute needs to be accessed in a qualified manner or |
| 1537 | * not, if it needs to be imported, then the same needs to be done. |
| 1538 | * |
| 1539 | * @param importInfo import info for the current attribute being added |
| 1540 | * @return status of the qualified access to the attribute |
| 1541 | */ |
| 1542 | public boolean getIsQualifiedAccessOrAddToImportList( |
| 1543 | JavaQualifiedTypeInfo importInfo) { |
| 1544 | boolean isImportPkgEqualCurNodePkg; |
| 1545 | if (importInfo.getClassInfo().contentEquals( |
| 1546 | getGeneratedJavaClassName())) { |
| 1547 | /* |
| 1548 | * if the current class name is same as the attribute class name, |
| 1549 | * then the attribute must be accessed in a qualified manner. |
| 1550 | */ |
| 1551 | return true; |
| 1552 | } else if (importInfo.getPkgInfo() != null) { |
| 1553 | /* |
| 1554 | * If the attribute type is having the package info, it is contender |
| 1555 | * for import list and also need to check if it needs to be a |
| 1556 | * qualified access. |
| 1557 | */ |
| 1558 | isImportPkgEqualCurNodePkg = isImportPkgEqualCurNodePkg(importInfo); |
| 1559 | if (!isImportPkgEqualCurNodePkg) { |
| 1560 | /* |
| 1561 | * If the package of the attribute added is not same as the |
| 1562 | * current class package, then it must either be imported for |
| 1563 | * access or it must be a qualified access. |
| 1564 | */ |
| 1565 | boolean isImportAdded = getJavaImportData().addImportInfo(importInfo); |
| 1566 | if (!isImportAdded) { |
| 1567 | /* |
| 1568 | * If the attribute type info is not imported, then it must |
| 1569 | * be a qualified access. |
| 1570 | */ |
| 1571 | return true; |
| 1572 | } |
| 1573 | } |
| 1574 | } |
| 1575 | return false; |
| 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * Checks if the import info is same as the package of the current generated |
| 1580 | * java file. |
| 1581 | * |
| 1582 | * @param importInfo import info for an attribute |
| 1583 | * @return true if the import info is same as the current nodes package |
| 1584 | * false otherwise |
| 1585 | */ |
| 1586 | public boolean isImportPkgEqualCurNodePkg(JavaQualifiedTypeInfo importInfo) { |
| 1587 | return getJavaFileInfo().getPackage() |
| 1588 | .contentEquals(importInfo.getPkgInfo()); |
| 1589 | } |
| 1590 | } |