Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | import java.util.SortedSet; |
| 25 | import java.util.TreeSet; |
| 26 | |
| 27 | import org.onosproject.yangutils.datamodel.YangType; |
| 28 | import org.onosproject.yangutils.translator.CachedFileHandle; |
| 29 | import org.onosproject.yangutils.translator.GeneratedFileType; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 30 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 32 | import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
| 34 | import org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator; |
| 35 | import org.onosproject.yangutils.utils.UtilConstants; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Maintain the information about the java file to be generated. |
| 39 | */ |
| 40 | public class CachedJavaFileHandle implements CachedFileHandle { |
| 41 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 42 | private static final int MAX_CACHABLE_ATTR = 64; |
| 43 | private static final String JAVA_FILE_EXTENSION = ".java"; |
| 44 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
| 45 | |
| 46 | /** |
| 47 | * The type(s) of java source file(s) to be generated when the cached file |
| 48 | * handle is closed. |
| 49 | */ |
| 50 | private GeneratedFileType genFileTypes; |
| 51 | |
| 52 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 53 | * Java package in which the class/interface needs to be generated. |
| 54 | */ |
| 55 | private String pkg; |
| 56 | |
| 57 | /** |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 58 | * Java package in which the child class/interface needs to be generated. |
| 59 | */ |
| 60 | private String childsPkg; |
| 61 | |
| 62 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 63 | * Name of the object in YANG file. |
| 64 | */ |
| 65 | private String yangName; |
| 66 | |
| 67 | /** |
| 68 | * Sorted set of import info, to be used to maintain the set of classes to |
| 69 | * be imported in the generated class. |
| 70 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 71 | private SortedSet<String> importSet; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Cached list of attribute info. |
| 75 | */ |
| 76 | private List<AttributeInfo> attributeList; |
| 77 | |
| 78 | /** |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 79 | * File generation directory path. |
| 80 | */ |
| 81 | private String filePath; |
| 82 | |
| 83 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 84 | * Prevent invoking default constructor. |
| 85 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 86 | public CachedJavaFileHandle() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 87 | setCachedAttributeList(new LinkedList<AttributeInfo>()); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Create a cached file handle which takes care of adding attributes to the |
| 92 | * generated java file. |
| 93 | * |
| 94 | * @param pcg package in which class/interface need to be generated. |
| 95 | * @param yangName name of the attribute in YANG file. |
| 96 | * @param types the types of files that needs to be generated. |
| 97 | * @throws IOException file IO exception. |
| 98 | */ |
| 99 | public CachedJavaFileHandle(String pcg, String yangName, GeneratedFileType types) throws IOException { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 100 | setGeneratedFileTypes(types); |
| 101 | setPackage(pcg); |
| 102 | setYangName(yangName); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get the types of files being generated corresponding to the YANG |
| 107 | * definition. |
| 108 | * |
| 109 | * @return the types of files being generated corresponding to the YANG |
| 110 | * definition. |
| 111 | */ |
| 112 | public GeneratedFileType getGeneratedFileTypes() { |
| 113 | return genFileTypes; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Set the types of files being generated corresponding to the YANG |
| 118 | * definition. |
| 119 | * |
| 120 | * @param fileTypes the types of files being generated corresponding to the |
| 121 | * YANG definition. |
| 122 | */ |
| 123 | public void setGeneratedFileTypes(GeneratedFileType fileTypes) { |
| 124 | genFileTypes = fileTypes; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Get the corresponding name defined in YANG. |
| 129 | * |
| 130 | * @return the corresponding name defined in YANG. |
| 131 | */ |
| 132 | public String getYangName() { |
| 133 | return yangName; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Set the corresponding name defined in YANG. |
| 138 | * |
| 139 | * @param yangName the corresponding name defined in YANG. |
| 140 | */ |
| 141 | public void setYangName(String yangName) { |
| 142 | this.yangName = yangName; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Get the java package. |
| 147 | * |
| 148 | * @return the java package. |
| 149 | */ |
| 150 | public String getPackage() { |
| 151 | return pkg; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Set the java package. |
| 156 | * |
| 157 | * @param pcg the package to set |
| 158 | */ |
| 159 | public void setPackage(String pcg) { |
| 160 | pkg = pcg; |
| 161 | } |
| 162 | |
| 163 | /** |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 164 | * Get the java package. |
| 165 | * |
| 166 | * @return the java package. |
| 167 | */ |
| 168 | public String getChildsPackage() { |
| 169 | return childsPkg; |
| 170 | } |
| 171 | |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 172 | @Override |
| 173 | public void setChildsPackage(String pcg) { |
| 174 | childsPkg = pcg; |
| 175 | } |
| 176 | |
| 177 | /** |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 178 | * Get the set containing the imported class/interface info. |
| 179 | * |
| 180 | * @return the set containing the imported class/interface info. |
| 181 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 182 | public SortedSet<String> getImportSet() { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 183 | return importSet; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Assign the set containing the imported class/interface info. |
| 188 | * |
| 189 | * @param importSet the set containing the imported class/interface info. |
| 190 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 191 | private void setImportSet(SortedSet<String> importSet) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 192 | this.importSet = importSet; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Add an imported class/interface info is it is not already part of the |
| 197 | * set. If already part of the set, return false, else add to set and return |
| 198 | * true. |
| 199 | * |
| 200 | * @param importInfo class/interface info being imported. |
| 201 | * @return status of new addition of class/interface to the import set |
| 202 | */ |
| 203 | public boolean addImportInfo(ImportInfo importInfo) { |
| 204 | /* |
| 205 | * implement the import info adding. The return value will be used to |
| 206 | * check if the qualified name will be used or class/interface name will |
| 207 | * be used in the generated class. |
| 208 | */ |
| 209 | if (getImportSet() == null) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 210 | setImportSet(new TreeSet<String>()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 211 | } |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 212 | return getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo)); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Get the list of cached attribute list. |
| 217 | * |
| 218 | * @return the set containing the imported class/interface info. |
| 219 | */ |
| 220 | public List<AttributeInfo> getCachedAttributeList() { |
| 221 | return attributeList; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Set the cached attribute list. |
| 226 | * |
| 227 | * @param attrList attribute list. |
| 228 | */ |
| 229 | private void setCachedAttributeList(List<AttributeInfo> attrList) { |
| 230 | attributeList = attrList; |
| 231 | } |
| 232 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 233 | @Override |
| 234 | public void setFilePath(String path) { |
| 235 | filePath = path; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Set the cached attribute list. |
| 240 | * |
| 241 | * @param attrList attribute list. |
| 242 | */ |
| 243 | private String getFilePath() { |
| 244 | return filePath; |
| 245 | } |
| 246 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 247 | /** |
| 248 | * Flush the cached attribute list to the serialized file. |
| 249 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 250 | private void flushCacheAttrToSerFile(String className) { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 251 | |
| 252 | for (AttributeInfo attr : getCachedAttributeList()) { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 253 | JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), className); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* |
| 257 | * clear the contents from the cached attribute list. |
| 258 | */ |
| 259 | getCachedAttributeList().clear(); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Add a new attribute to the file(s). |
| 264 | * |
| 265 | * @param attrType data type of the added attribute. |
| 266 | * @param name name of the attribute. |
| 267 | * @param isListAttr if the current added attribute needs to be maintained |
| 268 | * in a list. |
| 269 | */ |
| 270 | @Override |
| 271 | public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) { |
| 272 | |
| 273 | AttributeInfo newAttr = new AttributeInfo(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 274 | if (attrType != null) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 275 | newAttr.setAttributeType(attrType); |
| 276 | } else { |
| 277 | ImportInfo importInfo = new ImportInfo(); |
| 278 | importInfo.setPkgInfo(getChildsPackage()); |
| 279 | importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name)); |
| 280 | if (getImportSet() != null) { |
| 281 | getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo)); |
| 282 | } else { |
| 283 | SortedSet<String> newImportInfo = new TreeSet<>(); |
| 284 | newImportInfo.add(JavaCodeSnippetGen.getImportText(importInfo)); |
| 285 | setImportSet(newImportInfo); |
| 286 | } |
| 287 | |
| 288 | newAttr.setQualifiedName(getQualifiedFlag(JavaCodeSnippetGen.getImportText(importInfo))); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 289 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 290 | newAttr.setAttributeName(name); |
| 291 | newAttr.setListAttr(isListAttr); |
| 292 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 293 | if (newAttr.isListAttr()) { |
| 294 | newAttr.setAttributeType(AttributesJavaDataType.getListString(newAttr)); |
| 295 | } |
| 296 | |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 297 | if (isListAttr) { |
| 298 | String listImport = UtilConstants.COLLECTION_IMPORTS + UtilConstants.LIST + UtilConstants.SEMI_COLAN |
| 299 | + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; |
| 300 | if (getImportSet() != null) { |
| 301 | getImportSet().add(listImport); |
| 302 | } else { |
| 303 | SortedSet<String> newImportInfo = new TreeSet<>(); |
| 304 | newImportInfo.add(listImport); |
| 305 | setImportSet(newImportInfo); |
| 306 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 307 | |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 308 | newAttr.setQualifiedName(getQualifiedFlag(listImport)); |
| 309 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 310 | |
| 311 | if (getCachedAttributeList() != null) { |
| 312 | if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 313 | flushCacheAttrToSerFile(getYangName()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 314 | } |
| 315 | getCachedAttributeList().add(newAttr); |
| 316 | } else { |
| 317 | List<AttributeInfo> newAttributeInfo = new LinkedList<>(); |
| 318 | newAttributeInfo.add(newAttr); |
| 319 | setCachedAttributeList(newAttributeInfo); |
| 320 | } |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Check if the import set does not have a class info same as the new class |
| 325 | * info, if so the new class info be added to the import set. Otherwise |
| 326 | * check if the corresponding package info is same as the new package info, |
| 327 | * if so no need to qualified access, otherwise, it needs qualified access. |
| 328 | * |
| 329 | * @param newImportInfo new import info to be check for qualified access or |
| 330 | * not and updated in the import set accordingly. |
| 331 | * @return if the new attribute needs to be accessed in a qualified manner. |
| 332 | */ |
| 333 | private boolean getQualifiedFlag(String newImportInfo) { |
| 334 | for (String curImportInfo : getImportSet()) { |
| 335 | if (curImportInfo.equals(newImportInfo)) { |
| 336 | /* |
| 337 | * If import is already existing import with same package, we |
| 338 | * don't need qualified access, otherwise it needs to be |
| 339 | * qualified access. |
| 340 | */ |
| 341 | return !curImportInfo.equals(newImportInfo); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | getImportSet().add(newImportInfo); |
| 346 | return false; |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Flushes the cached contents to the target file, frees used resources. |
| 351 | */ |
| 352 | @Override |
| 353 | public void close() throws IOException { |
| 354 | |
| 355 | String className = getYangName(); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 356 | className = JavaIdentifierSyntax.getCaptialCase(className); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 357 | String filePath = getFilePath(); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 358 | GeneratedFileType fileType = getGeneratedFileTypes(); |
| 359 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 360 | /* |
| 361 | * TODO: add the file header using |
| 362 | * JavaCodeSnippetGen.getFileHeaderComment |
| 363 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 364 | |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 365 | List<String> imports = new LinkedList<>(); |
| 366 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 367 | if (getCachedAttributeList() != null) { |
| 368 | MethodsGenerator.setAttrInfo(getCachedAttributeList()); |
| 369 | for (AttributeInfo attr : getCachedAttributeList()) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 370 | |
| 371 | if (getImportSet() != null) { |
| 372 | imports = new ArrayList<>(getImportSet()); |
| 373 | } |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 377 | /** |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 378 | * Start generation of files. |
| 379 | */ |
| 380 | if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) { |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 381 | |
| 382 | /** |
| 383 | * Create interface file. |
| 384 | */ |
| 385 | String interfaceFileName = className; |
| 386 | File interfaceFile = new File(filePath + File.separator + interfaceFileName + JAVA_FILE_EXTENSION); |
| 387 | interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, |
| 388 | getCachedAttributeList(), getPackage()); |
| 389 | |
| 390 | /** |
| 391 | * Create temp builder interface file. |
| 392 | */ |
| 393 | String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE; |
| 394 | File builderInterfaceFile = new File( |
| 395 | filePath + File.separator + builderInterfaceFileName + TEMP_FILE_EXTENSION); |
| 396 | builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, |
| 397 | getPackage(), getCachedAttributeList()); |
| 398 | |
| 399 | /** |
| 400 | * Append builder interface file to interface file and close it. |
| 401 | */ |
| 402 | JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile); |
| 403 | JavaFileGenerator.insert(interfaceFile, |
| 404 | JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE, interfaceFileName)); |
| 405 | |
| 406 | /** |
| 407 | * Remove temp files. |
| 408 | */ |
| 409 | JavaFileGenerator.clean(builderInterfaceFile); |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) { |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 413 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 414 | /** |
| 415 | * Create builder class file. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 416 | */ |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 417 | String builderFileName = className + UtilConstants.BUILDER; |
| 418 | File builderFile = new File(filePath + File.separator + builderFileName + JAVA_FILE_EXTENSION); |
| 419 | MethodsGenerator.setBuilderClassName(className + UtilConstants.BUILDER); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 420 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 421 | builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, getPackage(), |
| 422 | getCachedAttributeList()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 423 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 424 | /** |
| 425 | * Create temp impl class file. |
| 426 | */ |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 427 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 428 | String implFileName = className + UtilConstants.IMPL; |
| 429 | File implTempFile = new File(filePath + File.separator + implFileName + TEMP_FILE_EXTENSION); |
| 430 | implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, getPackage(), |
| 431 | getCachedAttributeList()); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 432 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 433 | /** |
| 434 | * Append impl class to builder class and close it. |
| 435 | */ |
| 436 | JavaFileGenerator.appendFileContents(implTempFile, builderFile); |
| 437 | JavaFileGenerator.insert(builderFile, |
| 438 | JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS, builderFileName)); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 439 | |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame^] | 440 | /** |
| 441 | * Remove temp files. |
| 442 | */ |
| 443 | JavaFileGenerator.clean(implTempFile); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } |