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