Bharat saraswal
Committed by Gerrit Code Review

ST defect fixes and review comments fixes

Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
Showing 40 changed files with 1756 additions and 703 deletions
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
22 <dependency> 22 <dependency>
23 <groupId>org.apache.maven</groupId> 23 <groupId>org.apache.maven</groupId>
24 <artifactId>maven-core</artifactId> 24 <artifactId>maven-core</artifactId>
25 - <version>3.2.5</version> 25 + <version>3.3.9</version>
26 </dependency> 26 </dependency>
27 <dependency> 27 <dependency>
28 <groupId>org.apache.maven</groupId> 28 <groupId>org.apache.maven</groupId>
29 <artifactId>maven-plugin-api</artifactId> 29 <artifactId>maven-plugin-api</artifactId>
30 - <version>3.2.5</version> 30 + <version>3.3.9</version>
31 </dependency> 31 </dependency>
32 <dependency> 32 <dependency>
33 <groupId>org.apache.maven.plugin-tools</groupId> 33 <groupId>org.apache.maven.plugin-tools</groupId>
...@@ -38,18 +38,18 @@ ...@@ -38,18 +38,18 @@
38 <dependency> 38 <dependency>
39 <groupId>org.apache.felix</groupId> 39 <groupId>org.apache.felix</groupId>
40 <artifactId>maven-scr-plugin</artifactId> 40 <artifactId>maven-scr-plugin</artifactId>
41 - <version>1.9.0</version> 41 + <version>1.21.0</version>
42 <scope>compile</scope> 42 <scope>compile</scope>
43 </dependency> 43 </dependency>
44 <dependency> 44 <dependency>
45 <groupId>org.apache.maven</groupId> 45 <groupId>org.apache.maven</groupId>
46 <artifactId>maven-artifact</artifactId> 46 <artifactId>maven-artifact</artifactId>
47 - <version>3.2.5</version> 47 + <version>3.3.9</version>
48 </dependency> 48 </dependency>
49 <dependency> 49 <dependency>
50 <groupId>org.apache.maven</groupId> 50 <groupId>org.apache.maven</groupId>
51 <artifactId>maven-project</artifactId> 51 <artifactId>maven-project</artifactId>
52 - <version>2.2.1</version> 52 + <version>3.0-alpha-2</version>
53 </dependency> 53 </dependency>
54 <dependency> 54 <dependency>
55 <groupId>org.apache.maven.plugin-testing</groupId> 55 <groupId>org.apache.maven.plugin-testing</groupId>
...@@ -60,12 +60,12 @@ ...@@ -60,12 +60,12 @@
60 <dependency> 60 <dependency>
61 <groupId>org.apache.maven</groupId> 61 <groupId>org.apache.maven</groupId>
62 <artifactId>maven-model</artifactId> 62 <artifactId>maven-model</artifactId>
63 - <version>3.2.5</version> 63 + <version>3.3.9</version>
64 </dependency> 64 </dependency>
65 <dependency> 65 <dependency>
66 <groupId>org.apache.maven</groupId> 66 <groupId>org.apache.maven</groupId>
67 <artifactId>maven-compat</artifactId> 67 <artifactId>maven-compat</artifactId>
68 - <version>3.2.5</version> 68 + <version>3.3.9</version>
69 <scope>test</scope> 69 <scope>test</scope>
70 </dependency> 70 </dependency>
71 71
......
...@@ -340,9 +340,11 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo ...@@ -340,9 +340,11 @@ public class YangAugment extends YangNode implements YangLeavesHolder, YangCommo
340 /** 340 /**
341 * Prepare the information for java code generation corresponding to YANG 341 * Prepare the information for java code generation corresponding to YANG
342 * grouping info. 342 * grouping info.
343 + *
344 + * @param codeGenDir code generation directory
343 */ 345 */
344 @Override 346 @Override
345 - public void generateJavaCodeEntry() { 347 + public void generateJavaCodeEntry(String codeGenDir) {
346 // TODO Auto-generated method stub 348 // TODO Auto-generated method stub
347 349
348 } 350 }
......
...@@ -337,9 +337,11 @@ public class YangCase extends YangNode ...@@ -337,9 +337,11 @@ public class YangCase extends YangNode
337 337
338 /** 338 /**
339 * Generate the code corresponding to YANG case info. 339 * Generate the code corresponding to YANG case info.
340 + *
341 + * @param codeGenDir code generation directory
340 */ 342 */
341 @Override 343 @Override
342 - public void generateJavaCodeEntry() { 344 + public void generateJavaCodeEntry(String codeGenDir) {
343 // TODO Auto-generated method stub 345 // TODO Auto-generated method stub
344 346
345 } 347 }
......
...@@ -140,22 +140,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co ...@@ -140,22 +140,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co
140 super(YangNodeType.CHOICE_NODE); 140 super(YangNodeType.CHOICE_NODE);
141 } 141 }
142 142
143 - /*
144 - * (non-Javadoc)
145 - *
146 - * @see org.onosproject.yangutils.datamodel.YangNode#getName()
147 - */
148 @Override 143 @Override
149 public String getName() { 144 public String getName() {
150 return name; 145 return name;
151 } 146 }
152 147
153 - /*
154 - * (non-Javadoc)
155 - *
156 - * @see
157 - * org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
158 - */
159 @Override 148 @Override
160 public void setName(String name) { 149 public void setName(String name) {
161 this.name = name; 150 this.name = name;
...@@ -305,48 +294,24 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co ...@@ -305,48 +294,24 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co
305 // TODO auto-generated method stub, to be implemented by parser 294 // TODO auto-generated method stub, to be implemented by parser
306 } 295 }
307 296
308 - /*
309 - * (non-Javadoc)
310 - *
311 - * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
312 - */
313 @Override 297 @Override
314 public String getPackage() { 298 public String getPackage() {
315 // TODO Auto-generated method stub 299 // TODO Auto-generated method stub
316 return null; 300 return null;
317 } 301 }
318 302
319 - /*
320 - * (non-Javadoc)
321 - *
322 - * @see
323 - * org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
324 - */
325 @Override 303 @Override
326 public void setPackage(String pkg) { 304 public void setPackage(String pkg) {
327 // TODO Auto-generated method stub 305 // TODO Auto-generated method stub
328 306
329 } 307 }
330 308
331 - /*
332 - * (non-Javadoc)
333 - *
334 - * @see
335 - * org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry(
336 - * )
337 - */
338 @Override 309 @Override
339 - public void generateJavaCodeEntry() { 310 + public void generateJavaCodeEntry(String codeGenDir) {
340 // TODO Auto-generated method stub 311 // TODO Auto-generated method stub
341 312
342 } 313 }
343 314
344 - /*
345 - * (non-Javadoc)
346 - *
347 - * @see
348 - * org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
349 - */
350 @Override 315 @Override
351 public void generateJavaCodeExit() { 316 public void generateJavaCodeExit() {
352 // TODO Auto-generated method stub 317 // TODO Auto-generated method stub
......
...@@ -16,18 +16,19 @@ ...@@ -16,18 +16,19 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
20 +
19 import java.io.IOException; 21 import java.io.IOException;
20 import java.util.LinkedList; 22 import java.util.LinkedList;
21 import java.util.List; 23 import java.util.List;
22 24
23 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 25 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25 import org.onosproject.yangutils.parser.Parsable; 26 import org.onosproject.yangutils.parser.Parsable;
26 -import org.onosproject.yangutils.utils.YangConstructType;
27 import org.onosproject.yangutils.translator.CachedFileHandle; 27 import org.onosproject.yangutils.translator.CachedFileHandle;
28 import org.onosproject.yangutils.translator.GeneratedFileType; 28 import org.onosproject.yangutils.translator.GeneratedFileType;
29 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 29 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
30 import org.onosproject.yangutils.utils.UtilConstants; 30 import org.onosproject.yangutils.utils.UtilConstants;
31 +import org.onosproject.yangutils.utils.YangConstructType;
31 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; 32 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
32 /*- 33 /*-
33 * Reference RFC 6020. 34 * Reference RFC 6020.
...@@ -476,20 +477,24 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom ...@@ -476,20 +477,24 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
476 /** 477 /**
477 * Generate the java code corresponding to YANG container. 478 * Generate the java code corresponding to YANG container.
478 * 479 *
479 - * @throws IOException when fails to generate the source files 480 + * @param codeGenDir code generation directory
481 + * @throws IOException when fails to generate the source files.
480 */ 482 */
481 @Override 483 @Override
482 - public void generateJavaCodeEntry() throws IOException { 484 + public void generateJavaCodeEntry(String codeGenDir) throws IOException {
483 YangNode parent = getParent(); 485 YangNode parent = getParent();
484 String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName()); 486 String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName());
487 +
488 + contPkg = JavaIdentifierSyntax.getCamelCase(contPkg).toLowerCase();
485 setPackage(contPkg); 489 setPackage(contPkg);
486 490
487 CachedFileHandle handle = null; 491 CachedFileHandle handle = null;
488 try { 492 try {
489 - FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName()); 493 + FileSystemUtil.createPackage(codeGenDir + getPackage(), parent.getName() + UtilConstants.CHILDREN);
490 handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), 494 handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
491 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER); 495 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
492 - handle.setRelativeFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/")); 496 + handle.setRelativeFilePath(getPackage().replace(".", "/"));
497 + handle.setCodeGenFilePath(codeGenDir);
493 } catch (IOException e) { 498 } catch (IOException e) {
494 throw new IOException("Failed to create the source files."); 499 throw new IOException("Failed to create the source files.");
495 } 500 }
......
...@@ -299,9 +299,11 @@ public class YangGrouping extends YangNode ...@@ -299,9 +299,11 @@ public class YangGrouping extends YangNode
299 299
300 /** 300 /**
301 * Generate the code for YANG grouping. 301 * Generate the code for YANG grouping.
302 + *
303 + * @param codeGenDir code generated directory.
302 */ 304 */
303 @Override 305 @Override
304 - public void generateJavaCodeEntry() { 306 + public void generateJavaCodeEntry(String codeGenDir) {
305 // TODO Auto-generated method stub 307 // TODO Auto-generated method stub
306 308
307 } 309 }
......
...@@ -622,9 +622,11 @@ public class YangList extends YangNode ...@@ -622,9 +622,11 @@ public class YangList extends YangNode
622 /** 622 /**
623 * Populate the cached handle with information about the list attributes to 623 * Populate the cached handle with information about the list attributes to
624 * generate java code. 624 * generate java code.
625 + *
626 + * @param codeGenDir code generated directory
625 */ 627 */
626 @Override 628 @Override
627 - public void generateJavaCodeEntry() { 629 + public void generateJavaCodeEntry(String codeGenDir) {
628 // TODO Auto-generated method stub 630 // TODO Auto-generated method stub
629 631
630 } 632 }
......
...@@ -15,21 +15,21 @@ ...@@ -15,21 +15,21 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; 18 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
19 +
20 +import java.io.IOException;
21 +import java.util.LinkedList;
22 +import java.util.List;
23 +
24 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 import org.onosproject.yangutils.parser.Parsable; 25 import org.onosproject.yangutils.parser.Parsable;
21 import org.onosproject.yangutils.translator.CachedFileHandle; 26 import org.onosproject.yangutils.translator.CachedFileHandle;
22 import org.onosproject.yangutils.translator.CodeGenerator; 27 import org.onosproject.yangutils.translator.CodeGenerator;
23 import org.onosproject.yangutils.translator.GeneratedFileType; 28 import org.onosproject.yangutils.translator.GeneratedFileType;
24 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 29 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
25 -import org.onosproject.yangutils.utils.UtilConstants;
26 import org.onosproject.yangutils.utils.YangConstructType; 30 import org.onosproject.yangutils.utils.YangConstructType;
27 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; 31 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
28 32
29 -import java.io.IOException;
30 -import java.util.LinkedList;
31 -import java.util.List;
32 -
33 /*- 33 /*-
34 * Reference:RFC 6020. 34 * Reference:RFC 6020.
35 * The "module" statement defines the module's name, 35 * The "module" statement defines the module's name,
...@@ -211,7 +211,7 @@ public class YangModule extends YangNode ...@@ -211,7 +211,7 @@ public class YangModule extends YangNode
211 /** 211 /**
212 * Get name of the module. 212 * Get name of the module.
213 * 213 *
214 - * @return module name. 214 + * @return module name
215 */ 215 */
216 @Override 216 @Override
217 public String getName() { 217 public String getName() {
...@@ -221,7 +221,7 @@ public class YangModule extends YangNode ...@@ -221,7 +221,7 @@ public class YangModule extends YangNode
221 /** 221 /**
222 * Set module name. 222 * Set module name.
223 * 223 *
224 - * @param moduleName module name. 224 + * @param moduleName module name
225 */ 225 */
226 @Override 226 @Override
227 public void setName(String moduleName) { 227 public void setName(String moduleName) {
...@@ -231,7 +231,7 @@ public class YangModule extends YangNode ...@@ -231,7 +231,7 @@ public class YangModule extends YangNode
231 /** 231 /**
232 * Get the contact details of the module owner. 232 * Get the contact details of the module owner.
233 * 233 *
234 - * @return the contact details of YANG owner. 234 + * @return the contact details of YANG owner
235 */ 235 */
236 public String getContact() { 236 public String getContact() {
237 return contact; 237 return contact;
...@@ -240,7 +240,7 @@ public class YangModule extends YangNode ...@@ -240,7 +240,7 @@ public class YangModule extends YangNode
240 /** 240 /**
241 * Set the contact details of the module owner. 241 * Set the contact details of the module owner.
242 * 242 *
243 - * @param contact the contact details of YANG owner. 243 + * @param contact the contact details of YANG owner
244 */ 244 */
245 public void setContact(String contact) { 245 public void setContact(String contact) {
246 this.contact = contact; 246 this.contact = contact;
...@@ -249,7 +249,7 @@ public class YangModule extends YangNode ...@@ -249,7 +249,7 @@ public class YangModule extends YangNode
249 /** 249 /**
250 * Get the description of module. 250 * Get the description of module.
251 * 251 *
252 - * @return the description of YANG module. 252 + * @return the description of YANG module
253 */ 253 */
254 @Override 254 @Override
255 public String getDescription() { 255 public String getDescription() {
...@@ -259,7 +259,7 @@ public class YangModule extends YangNode ...@@ -259,7 +259,7 @@ public class YangModule extends YangNode
259 /** 259 /**
260 * Set the description of module. 260 * Set the description of module.
261 * 261 *
262 - * @param description set the description of YANG module. 262 + * @param description set the description of YANG module
263 */ 263 */
264 @Override 264 @Override
265 public void setDescription(String description) { 265 public void setDescription(String description) {
...@@ -269,7 +269,7 @@ public class YangModule extends YangNode ...@@ -269,7 +269,7 @@ public class YangModule extends YangNode
269 /** 269 /**
270 * Get the list of imported modules. 270 * Get the list of imported modules.
271 * 271 *
272 - * @return the list of imported modules. 272 + * @return the list of imported modules
273 */ 273 */
274 public List<YangImport> getImportList() { 274 public List<YangImport> getImportList() {
275 return importList; 275 return importList;
...@@ -278,7 +278,7 @@ public class YangModule extends YangNode ...@@ -278,7 +278,7 @@ public class YangModule extends YangNode
278 /** 278 /**
279 * prevent setting the import list from outside. 279 * prevent setting the import list from outside.
280 * 280 *
281 - * @param importList the import list to set. 281 + * @param importList the import list to set
282 */ 282 */
283 private void setImportList(List<YangImport> importList) { 283 private void setImportList(List<YangImport> importList) {
284 this.importList = importList; 284 this.importList = importList;
...@@ -287,7 +287,7 @@ public class YangModule extends YangNode ...@@ -287,7 +287,7 @@ public class YangModule extends YangNode
287 /** 287 /**
288 * Add the imported module information to the import list. 288 * Add the imported module information to the import list.
289 * 289 *
290 - * @param importedModule module being imported. 290 + * @param importedModule module being imported
291 */ 291 */
292 public void addImportedInfo(YangImport importedModule) { 292 public void addImportedInfo(YangImport importedModule) {
293 293
...@@ -303,7 +303,7 @@ public class YangModule extends YangNode ...@@ -303,7 +303,7 @@ public class YangModule extends YangNode
303 /** 303 /**
304 * Get the list of included sub modules. 304 * Get the list of included sub modules.
305 * 305 *
306 - * @return the included list of sub modules. 306 + * @return the included list of sub modules
307 */ 307 */
308 public List<YangInclude> getIncludeList() { 308 public List<YangInclude> getIncludeList() {
309 return includeList; 309 return includeList;
...@@ -312,7 +312,7 @@ public class YangModule extends YangNode ...@@ -312,7 +312,7 @@ public class YangModule extends YangNode
312 /** 312 /**
313 * Set the list of included sub modules. 313 * Set the list of included sub modules.
314 * 314 *
315 - * @param includeList the included list to set. 315 + * @param includeList the included list to set
316 */ 316 */
317 private void setIncludeList(List<YangInclude> includeList) { 317 private void setIncludeList(List<YangInclude> includeList) {
318 this.includeList = includeList; 318 this.includeList = includeList;
...@@ -321,7 +321,7 @@ public class YangModule extends YangNode ...@@ -321,7 +321,7 @@ public class YangModule extends YangNode
321 /** 321 /**
322 * Add the included sub module information to the include list. 322 * Add the included sub module information to the include list.
323 * 323 *
324 - * @param includeModule submodule being included. 324 + * @param includeModule submodule being included
325 */ 325 */
326 public void addIncludedInfo(YangInclude includeModule) { 326 public void addIncludedInfo(YangInclude includeModule) {
327 327
...@@ -336,7 +336,7 @@ public class YangModule extends YangNode ...@@ -336,7 +336,7 @@ public class YangModule extends YangNode
336 /** 336 /**
337 * Get the list of leaves in module. 337 * Get the list of leaves in module.
338 * 338 *
339 - * @return the list of leaves. 339 + * @return the list of leaves
340 */ 340 */
341 @Override 341 @Override
342 public List<YangLeaf> getListOfLeaf() { 342 public List<YangLeaf> getListOfLeaf() {
...@@ -346,7 +346,7 @@ public class YangModule extends YangNode ...@@ -346,7 +346,7 @@ public class YangModule extends YangNode
346 /** 346 /**
347 * Set the list of leaf in module. 347 * Set the list of leaf in module.
348 * 348 *
349 - * @param leafsList the list of leaf to set. 349 + * @param leafsList the list of leaf to set
350 */ 350 */
351 private void setListOfLeaf(List<YangLeaf> leafsList) { 351 private void setListOfLeaf(List<YangLeaf> leafsList) {
352 listOfLeaf = leafsList; 352 listOfLeaf = leafsList;
...@@ -355,7 +355,7 @@ public class YangModule extends YangNode ...@@ -355,7 +355,7 @@ public class YangModule extends YangNode
355 /** 355 /**
356 * Add a leaf in module. 356 * Add a leaf in module.
357 * 357 *
358 - * @param leaf the leaf to be added. 358 + * @param leaf the leaf to be added
359 */ 359 */
360 @Override 360 @Override
361 public void addLeaf(YangLeaf leaf) { 361 public void addLeaf(YangLeaf leaf) {
...@@ -369,7 +369,7 @@ public class YangModule extends YangNode ...@@ -369,7 +369,7 @@ public class YangModule extends YangNode
369 /** 369 /**
370 * Get the list of leaf-list from module. 370 * Get the list of leaf-list from module.
371 * 371 *
372 - * @return the list of leaf-list. 372 + * @return the list of leaf-list
373 */ 373 */
374 @Override 374 @Override
375 public List<YangLeafList> getListOfLeafList() { 375 public List<YangLeafList> getListOfLeafList() {
...@@ -379,7 +379,7 @@ public class YangModule extends YangNode ...@@ -379,7 +379,7 @@ public class YangModule extends YangNode
379 /** 379 /**
380 * Set the list of leaf-list in module. 380 * Set the list of leaf-list in module.
381 * 381 *
382 - * @param listOfLeafList the list of leaf-list to set. 382 + * @param listOfLeafList the list of leaf-list to set
383 */ 383 */
384 private void setListOfLeafList(List<YangLeafList> listOfLeafList) { 384 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
385 this.listOfLeafList = listOfLeafList; 385 this.listOfLeafList = listOfLeafList;
...@@ -388,7 +388,7 @@ public class YangModule extends YangNode ...@@ -388,7 +388,7 @@ public class YangModule extends YangNode
388 /** 388 /**
389 * Add a leaf-list in module. 389 * Add a leaf-list in module.
390 * 390 *
391 - * @param leafList the leaf-list to be added. 391 + * @param leafList the leaf-list to be added
392 */ 392 */
393 @Override 393 @Override
394 public void addLeafList(YangLeafList leafList) { 394 public void addLeafList(YangLeafList leafList) {
...@@ -402,7 +402,7 @@ public class YangModule extends YangNode ...@@ -402,7 +402,7 @@ public class YangModule extends YangNode
402 /** 402 /**
403 * Get the name space of module elements. 403 * Get the name space of module elements.
404 * 404 *
405 - * @return the nameSpace. 405 + * @return the nameSpace
406 */ 406 */
407 public YangNameSpace getNameSpace() { 407 public YangNameSpace getNameSpace() {
408 return nameSpace; 408 return nameSpace;
...@@ -411,7 +411,7 @@ public class YangModule extends YangNode ...@@ -411,7 +411,7 @@ public class YangModule extends YangNode
411 /** 411 /**
412 * Set the name space of module elements. 412 * Set the name space of module elements.
413 * 413 *
414 - * @param nameSpace the nameSpace to set. 414 + * @param nameSpace the nameSpace to set
415 */ 415 */
416 public void setNameSpace(YangNameSpace nameSpace) { 416 public void setNameSpace(YangNameSpace nameSpace) {
417 this.nameSpace = nameSpace; 417 this.nameSpace = nameSpace;
...@@ -420,7 +420,7 @@ public class YangModule extends YangNode ...@@ -420,7 +420,7 @@ public class YangModule extends YangNode
420 /** 420 /**
421 * Get the modules organization. 421 * Get the modules organization.
422 * 422 *
423 - * @return the organization. 423 + * @return the organization
424 */ 424 */
425 public String getOrganization() { 425 public String getOrganization() {
426 return organization; 426 return organization;
...@@ -429,7 +429,7 @@ public class YangModule extends YangNode ...@@ -429,7 +429,7 @@ public class YangModule extends YangNode
429 /** 429 /**
430 * Set the modules organization. 430 * Set the modules organization.
431 * 431 *
432 - * @param org the organization to set. 432 + * @param org the organization to set
433 */ 433 */
434 public void setOrganization(String org) { 434 public void setOrganization(String org) {
435 organization = org; 435 organization = org;
...@@ -447,7 +447,7 @@ public class YangModule extends YangNode ...@@ -447,7 +447,7 @@ public class YangModule extends YangNode
447 /** 447 /**
448 * Set the prefix. 448 * Set the prefix.
449 * 449 *
450 - * @param prefix the prefix to set. 450 + * @param prefix the prefix to set
451 */ 451 */
452 public void setPrefix(String prefix) { 452 public void setPrefix(String prefix) {
453 this.prefix = prefix; 453 this.prefix = prefix;
...@@ -456,7 +456,7 @@ public class YangModule extends YangNode ...@@ -456,7 +456,7 @@ public class YangModule extends YangNode
456 /** 456 /**
457 * Get the textual reference. 457 * Get the textual reference.
458 * 458 *
459 - * @return the reference. 459 + * @return the reference
460 */ 460 */
461 @Override 461 @Override
462 public String getReference() { 462 public String getReference() {
...@@ -466,7 +466,7 @@ public class YangModule extends YangNode ...@@ -466,7 +466,7 @@ public class YangModule extends YangNode
466 /** 466 /**
467 * Set the textual reference. 467 * Set the textual reference.
468 * 468 *
469 - * @param reference the reference to set. 469 + * @param reference the reference to set
470 */ 470 */
471 @Override 471 @Override
472 public void setReference(String reference) { 472 public void setReference(String reference) {
...@@ -476,7 +476,7 @@ public class YangModule extends YangNode ...@@ -476,7 +476,7 @@ public class YangModule extends YangNode
476 /** 476 /**
477 * Get the revision. 477 * Get the revision.
478 * 478 *
479 - * @return the revision. 479 + * @return the revision
480 */ 480 */
481 public YangRevision getRevision() { 481 public YangRevision getRevision() {
482 return revision; 482 return revision;
...@@ -485,7 +485,7 @@ public class YangModule extends YangNode ...@@ -485,7 +485,7 @@ public class YangModule extends YangNode
485 /** 485 /**
486 * Set the revision. 486 * Set the revision.
487 * 487 *
488 - * @param revision the revision to set. 488 + * @param revision the revision to set
489 */ 489 */
490 public void setRevision(YangRevision revision) { 490 public void setRevision(YangRevision revision) {
491 this.revision = revision; 491 this.revision = revision;
...@@ -494,7 +494,7 @@ public class YangModule extends YangNode ...@@ -494,7 +494,7 @@ public class YangModule extends YangNode
494 /** 494 /**
495 * Get the version. 495 * Get the version.
496 * 496 *
497 - * @return the version. 497 + * @return the version
498 */ 498 */
499 public byte getVersion() { 499 public byte getVersion() {
500 return version; 500 return version;
...@@ -503,7 +503,7 @@ public class YangModule extends YangNode ...@@ -503,7 +503,7 @@ public class YangModule extends YangNode
503 /** 503 /**
504 * Set the version. 504 * Set the version.
505 * 505 *
506 - * @param version the version to set. 506 + * @param version the version to set
507 */ 507 */
508 public void setVersion(byte version) { 508 public void setVersion(byte version) {
509 this.version = version; 509 this.version = version;
...@@ -558,7 +558,7 @@ public class YangModule extends YangNode ...@@ -558,7 +558,7 @@ public class YangModule extends YangNode
558 /** 558 /**
559 * Get the list of nested reference's which required resolution. 559 * Get the list of nested reference's which required resolution.
560 * 560 *
561 - * @return list of nested reference's which required resolution. 561 + * @return list of nested reference's which required resolution
562 */ 562 */
563 public List<YangNode> getNestedReferenceResoulutionList() { 563 public List<YangNode> getNestedReferenceResoulutionList() {
564 return nestedReferenceResoulutionList; 564 return nestedReferenceResoulutionList;
...@@ -568,7 +568,7 @@ public class YangModule extends YangNode ...@@ -568,7 +568,7 @@ public class YangModule extends YangNode
568 * Set list of nested reference's which requires resolution. 568 * Set list of nested reference's which requires resolution.
569 * 569 *
570 * @param nestedReferenceResoulutionList list of nested reference's which 570 * @param nestedReferenceResoulutionList list of nested reference's which
571 - * requires resolution. 571 + * requires resolution
572 */ 572 */
573 private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) { 573 private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) {
574 this.nestedReferenceResoulutionList = nestedReferenceResoulutionList; 574 this.nestedReferenceResoulutionList = nestedReferenceResoulutionList;
...@@ -577,7 +577,7 @@ public class YangModule extends YangNode ...@@ -577,7 +577,7 @@ public class YangModule extends YangNode
577 /** 577 /**
578 * Set list of nested reference's which requires resolution. 578 * Set list of nested reference's which requires resolution.
579 * 579 *
580 - * @param nestedReference nested reference which requires resolution. 580 + * @param nestedReference nested reference which requires resolution
581 */ 581 */
582 public void addToNestedReferenceResoulutionList(YangNode nestedReference) { 582 public void addToNestedReferenceResoulutionList(YangNode nestedReference) {
583 if (getNestedReferenceResoulutionList() == null) { 583 if (getNestedReferenceResoulutionList() == null) {
...@@ -589,7 +589,7 @@ public class YangModule extends YangNode ...@@ -589,7 +589,7 @@ public class YangModule extends YangNode
589 /** 589 /**
590 * Returns the type of the parsed data. 590 * Returns the type of the parsed data.
591 * 591 *
592 - * @return returns MODULE_DATA. 592 + * @return returns MODULE_DATA
593 */ 593 */
594 @Override 594 @Override
595 public YangConstructType getYangConstructType() { 595 public YangConstructType getYangConstructType() {
...@@ -625,18 +625,21 @@ public class YangModule extends YangNode ...@@ -625,18 +625,21 @@ public class YangModule extends YangNode
625 /** 625 /**
626 * Generates java code for module. 626 * Generates java code for module.
627 * 627 *
628 - * @throws IOException when fails to generate the source files. 628 + * @param codeGenDir code generation directory
629 + * @throws IOException when fails to generate the source files
629 */ 630 */
630 @Override 631 @Override
631 - public void generateJavaCodeEntry() throws IOException { 632 + public void generateJavaCodeEntry(String codeGenDir) throws IOException {
632 String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(), 633 String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
633 getRevision().getRevDate()); 634 getRevision().getRevDate());
634 635
636 + modPkg = JavaIdentifierSyntax.getCamelCase(modPkg);
635 CachedFileHandle handle = null; 637 CachedFileHandle handle = null;
636 try { 638 try {
637 - FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + modPkg, getName()); 639 + FileSystemUtil.createPackage(codeGenDir + modPkg, getName());
638 handle = FileSystemUtil.createSourceFiles(modPkg, getName(), 640 handle = FileSystemUtil.createSourceFiles(modPkg, getName(),
639 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER); 641 GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
642 + handle.setCodeGenFilePath(codeGenDir);
640 } catch (IOException e) { 643 } catch (IOException e) {
641 throw new IOException("Failed to create the source files."); 644 throw new IOException("Failed to create the source files.");
642 } 645 }
...@@ -680,8 +683,8 @@ public class YangModule extends YangNode ...@@ -680,8 +683,8 @@ public class YangModule extends YangNode
680 /** 683 /**
681 * Add a type to resolve the nested references. 684 * Add a type to resolve the nested references.
682 * 685 *
683 - * @param node grouping or typedef node which needs to be resolved. 686 + * @param node grouping or typedef node which needs to be resolved
684 - * @throws DataModelException data model exception. 687 + * @throws DataModelException data model exception
685 */ 688 */
686 public static void addToResolveList(YangNode node) throws DataModelException { 689 public static void addToResolveList(YangNode node) throws DataModelException {
687 /* get the module node to add maintain the list of nested reference */ 690 /* get the module node to add maintain the list of nested reference */
......
...@@ -470,9 +470,11 @@ public class YangSubModule extends YangNode ...@@ -470,9 +470,11 @@ public class YangSubModule extends YangNode
470 470
471 /** 471 /**
472 * Generates java code for sub-module. 472 * Generates java code for sub-module.
473 + *
474 + * @param codeGenDir code generation directory.
473 */ 475 */
474 @Override 476 @Override
475 - public void generateJavaCodeEntry() { 477 + public void generateJavaCodeEntry(String codeGenDir) {
476 // TODO Auto-generated method stub 478 // TODO Auto-generated method stub
477 } 479 }
478 480
......
...@@ -47,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -47,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
47 /** 47 /**
48 * Maintains the data type information. 48 * Maintains the data type information.
49 * 49 *
50 - * @param <T> YANG data type info. 50 + * @param <T> YANG data type info
51 */ 51 */
52 public class YangType<T> implements Parsable { 52 public class YangType<T> implements Parsable {
53 53
...@@ -57,6 +57,11 @@ public class YangType<T> implements Parsable { ...@@ -57,6 +57,11 @@ public class YangType<T> implements Parsable {
57 private String dataTypeName; 57 private String dataTypeName;
58 58
59 /** 59 /**
60 + * Java package in which the Java type is defined.
61 + */
62 + private String javaPackage;
63 +
64 + /**
60 * YANG data type. 65 * YANG data type.
61 */ 66 */
62 private YangDataTypes dataType; 67 private YangDataTypes dataType;
...@@ -93,6 +98,24 @@ public class YangType<T> implements Parsable { ...@@ -93,6 +98,24 @@ public class YangType<T> implements Parsable {
93 } 98 }
94 99
95 /** 100 /**
101 + * Get the Java package where the type is defined.
102 + *
103 + * @return Java package where the type is defined
104 + */
105 + public String getJavaPackage() {
106 + return javaPackage;
107 + }
108 +
109 + /**
110 + * Set Java package where the type is defined.
111 + *
112 + * @param javaPackage Java package where the type is defined
113 + */
114 + public void setJavaPackage(String javaPackage) {
115 + this.javaPackage = javaPackage;
116 + }
117 +
118 + /**
96 * Get the type of data. 119 * Get the type of data.
97 * 120 *
98 * @return the data type 121 * @return the data type
......
...@@ -15,10 +15,16 @@ ...@@ -15,10 +15,16 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.io.IOException;
19 +
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
20 import org.onosproject.yangutils.translator.CachedFileHandle; 22 import org.onosproject.yangutils.translator.CachedFileHandle;
23 +import org.onosproject.yangutils.translator.GeneratedFileType;
24 +import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
25 +import org.onosproject.yangutils.utils.UtilConstants;
21 import org.onosproject.yangutils.utils.YangConstructType; 26 import org.onosproject.yangutils.utils.YangConstructType;
27 +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
22 28
23 /*- 29 /*-
24 * Reference RFC 6020. 30 * Reference RFC 6020.
...@@ -91,6 +97,11 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -91,6 +97,11 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
91 private String pkg; 97 private String pkg;
92 98
93 /** 99 /**
100 + * Cached Java File Handle.
101 + */
102 + private CachedFileHandle fileHandle;
103 +
104 + /**
94 * Create a typedef node. 105 * Create a typedef node.
95 */ 106 */
96 public YangTypeDef() { 107 public YangTypeDef() {
...@@ -298,20 +309,60 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -298,20 +309,60 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
298 309
299 /** 310 /**
300 * Generate java code snippet corresponding to YANG typedef. 311 * Generate java code snippet corresponding to YANG typedef.
312 + *
313 + * @param codeGenDir code generation directory
314 + * @throws IOException when fails to generate files for typedef
301 */ 315 */
302 @Override 316 @Override
303 - public void generateJavaCodeEntry() { 317 + public void generateJavaCodeEntry(String codeGenDir) throws IOException {
304 - // TODO Auto-generated method stub 318 +
319 + YangNode parent = getParent();
320 + String typeDefPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName());
321 +
322 + typeDefPkg = JavaIdentifierSyntax.getCamelCase(typeDefPkg).toLowerCase();
323 + setPackage(typeDefPkg);
324 +
325 + CachedFileHandle handle = null;
326 + try {
327 + FileSystemUtil.createPackage(codeGenDir + getPackage(), parent.getName() + UtilConstants.CHILDREN);
328 + handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
329 + GeneratedFileType.GENERATE_TYPEDEF_CLASS);
330 + handle.setRelativeFilePath(getPackage().replace(".", "/"));
331 + handle.setCodeGenFilePath(codeGenDir);
332 + } catch (IOException e) {
333 + throw new IOException("Failed to create the source files.");
334 + }
335 + setFileHandle(handle);
336 + addAttributeInfo();
337 + addAttributeInParent();
338 + }
339 +
340 + /**
341 + * Adds current node attribute to parent file.
342 + */
343 + private void addAttributeInParent() {
344 + if (getParent() != null) {
345 + getParent().getFileHandle().addAttributeInfo(null, getName(), false);
346 + }
347 + }
305 348
349 + /**
350 + * Adds attribute to file handle.
351 + */
352 + private void addAttributeInfo() {
353 + getFileHandle().addAttributeInfo(getDerivedType().getDataTypeExtendedInfo().getBaseType(),
354 + JavaIdentifierSyntax.getCamelCase(getName()), false);
306 } 355 }
307 356
308 /** 357 /**
309 * Free resource used for code generation of YANG typedef. 358 * Free resource used for code generation of YANG typedef.
359 + *
360 + * @throws IOException when fails to generate files
310 */ 361 */
311 @Override 362 @Override
312 - public void generateJavaCodeExit() { 363 + public void generateJavaCodeExit() throws IOException {
313 - // TODO Auto-generated method stub 364 + getFileHandle().close();
314 - 365 + return;
315 } 366 }
316 367
317 /** 368 /**
...@@ -342,18 +393,16 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -342,18 +393,16 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
342 */ 393 */
343 @Override 394 @Override
344 public CachedFileHandle getFileHandle() { 395 public CachedFileHandle getFileHandle() {
345 - // TODO Auto-generated method stub 396 + return fileHandle;
346 - return null;
347 } 397 }
348 398
349 /** 399 /**
350 * Set the file handle to be used used for code generation. 400 * Set the file handle to be used used for code generation.
351 * 401 *
352 - * @param fileHandle cached file handle 402 + * @param handle cached file handle
353 */ 403 */
354 @Override 404 @Override
355 - public void setFileHandle(CachedFileHandle fileHandle) { 405 + public void setFileHandle(CachedFileHandle handle) {
356 - // TODO Auto-generated method stub 406 + fileHandle = handle;
357 -
358 } 407 }
359 } 408 }
......
...@@ -213,54 +213,36 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -213,54 +213,36 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
213 // TODO auto-generated method stub, to be implemented by parser 213 // TODO auto-generated method stub, to be implemented by parser
214 } 214 }
215 215
216 - /* (non-Javadoc)
217 - * @see org.onosproject.yangutils.datamodel.YangNode#getName()
218 - */
219 @Override 216 @Override
220 public String getName() { 217 public String getName() {
221 // TODO Auto-generated method stub 218 // TODO Auto-generated method stub
222 return null; 219 return null;
223 } 220 }
224 221
225 - /* (non-Javadoc)
226 - * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
227 - */
228 @Override 222 @Override
229 public void setName(String name) { 223 public void setName(String name) {
230 // TODO Auto-generated method stub 224 // TODO Auto-generated method stub
231 225
232 } 226 }
233 227
234 - /* (non-Javadoc)
235 - * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
236 - */
237 @Override 228 @Override
238 - public void generateJavaCodeEntry() { 229 + public void generateJavaCodeEntry(String codeGenDir) {
239 // TODO Auto-generated method stub 230 // TODO Auto-generated method stub
240 231
241 } 232 }
242 233
243 - /* (non-Javadoc)
244 - * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
245 - */
246 @Override 234 @Override
247 public void generateJavaCodeExit() { 235 public void generateJavaCodeExit() {
248 // TODO Auto-generated method stub 236 // TODO Auto-generated method stub
249 237
250 } 238 }
251 239
252 - /* (non-Javadoc)
253 - * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
254 - */
255 @Override 240 @Override
256 public String getPackage() { 241 public String getPackage() {
257 // TODO Auto-generated method stub 242 // TODO Auto-generated method stub
258 return null; 243 return null;
259 } 244 }
260 245
261 - /* (non-Javadoc)
262 - * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
263 - */
264 @Override 246 @Override
265 public void setPackage(String pkg) { 247 public void setPackage(String pkg) {
266 // TODO Auto-generated method stub 248 // TODO Auto-generated method stub
......
...@@ -43,7 +43,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; ...@@ -43,7 +43,7 @@ import org.sonatype.plexus.build.incremental.BuildContext;
43 43
44 /** 44 /**
45 * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase 45 * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase
46 - * in generate-sources requiresDependencyResolution at compile time 46 + * in generate-sources requiresDependencyResolution at compile time.
47 */ 47 */
48 @Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES, 48 @Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
49 requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) 49 requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
...@@ -56,6 +56,12 @@ public class YangUtilManager extends AbstractMojo { ...@@ -56,6 +56,12 @@ public class YangUtilManager extends AbstractMojo {
56 private String yangFilesDir; 56 private String yangFilesDir;
57 57
58 /** 58 /**
59 + * Base directory for project.
60 + */
61 + @Parameter(property = "basedir", defaultValue = "${basedir}")
62 + private String baseDir;
63 +
64 + /**
59 * Output directory. 65 * Output directory.
60 */ 66 */
61 @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes") 67 @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes")
...@@ -74,13 +80,13 @@ public class YangUtilManager extends AbstractMojo { ...@@ -74,13 +80,13 @@ public class YangUtilManager extends AbstractMojo {
74 private BuildContext context; 80 private BuildContext context;
75 81
76 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); 82 private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
77 - private String baseDir;
78 private String searchDir; 83 private String searchDir;
84 + private String codeGenDir;
79 85
80 /** 86 /**
81 * Set current project. 87 * Set current project.
82 * 88 *
83 - * @param curProject maven project. 89 + * @param curProject maven project
84 */ 90 */
85 public void setCurrentProject(final MavenProject curProject) { 91 public void setCurrentProject(final MavenProject curProject) {
86 project = curProject; 92 project = curProject;
...@@ -92,7 +98,6 @@ public class YangUtilManager extends AbstractMojo { ...@@ -92,7 +98,6 @@ public class YangUtilManager extends AbstractMojo {
92 try { 98 try {
93 99
94 CopyrightHeader.parseCopyrightHeader(); 100 CopyrightHeader.parseCopyrightHeader();
95 - baseDir = project.getBasedir().toString();
96 101
97 /** 102 /**
98 * For deleting the generated code in previous build. 103 * For deleting the generated code in previous build.
...@@ -100,6 +105,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -100,6 +105,7 @@ public class YangUtilManager extends AbstractMojo {
100 YangIoUtils.clean(baseDir); 105 YangIoUtils.clean(baseDir);
101 106
102 searchDir = baseDir + File.separator + yangFilesDir; 107 searchDir = baseDir + File.separator + yangFilesDir;
108 + codeGenDir = baseDir + File.separator + UtilConstants.YANG_GEN_DIR;
103 109
104 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); 110 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
105 Iterator<String> yangFileIterator = yangFiles.iterator(); 111 Iterator<String> yangFileIterator = yangFiles.iterator();
...@@ -107,7 +113,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -107,7 +113,7 @@ public class YangUtilManager extends AbstractMojo {
107 String yangFile = yangFileIterator.next(); 113 String yangFile = yangFileIterator.next();
108 try { 114 try {
109 YangNode yangNode = yangUtilsParser.getDataModel(yangFile); 115 YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
110 - JavaCodeGenerator.generateJavaCode(yangNode); 116 + JavaCodeGenerator.generateJavaCode(yangNode, codeGenDir);
111 } catch (ParserException e) { 117 } catch (ParserException e) {
112 String logInfo = "Error in file: " + e.getFileName(); 118 String logInfo = "Error in file: " + e.getFileName();
113 if (e.getLineNumber() != 0) { 119 if (e.getLineNumber() != 0) {
......
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
16 16
17 package org.onosproject.yangutils.translator; 17 package org.onosproject.yangutils.translator;
18 18
19 +import java.io.FileNotFoundException;
19 import java.io.IOException; 20 import java.io.IOException;
20 21
21 import org.onosproject.yangutils.datamodel.YangType; 22 import org.onosproject.yangutils.datamodel.YangType;
23 +import org.onosproject.yangutils.translator.tojava.utils.TempDataStoreTypes;
22 24
23 /** 25 /**
24 * Cached java file handle, which supports the addition of member attributes and 26 * Cached java file handle, which supports the addition of member attributes and
...@@ -56,4 +58,43 @@ public interface CachedFileHandle { ...@@ -56,4 +58,43 @@ public interface CachedFileHandle {
56 * @return directory package path for code generation 58 * @return directory package path for code generation
57 */ 59 */
58 String getRelativeFilePath(); 60 String getRelativeFilePath();
61 +
62 + /**
63 + * Gets base directory package path for code generation.
64 + *
65 + * @return directory package path for code generation
66 + */
67 + String getCodeGenFilePath();
68 +
69 + /**
70 + * Sets base directory package path for code generation.
71 + *
72 + * @param path base directory path
73 + */
74 + void setCodeGenFilePath(String path);
75 +
76 + /**
77 + * Writes specific info to a Temp file.
78 + *
79 + * @param data data to be stored
80 + * @param type type of Temp data store
81 + * @param className class name
82 + * @param genDir generated directory
83 + * @throws IOException when fails to create a Temp data file
84 + */
85 + void setTempData(String data, TempDataStoreTypes type, String className, String genDir) throws IOException;
86 +
87 + /**
88 + * Get the Temp data.
89 + *
90 + * @param type type of Temp data store
91 + * @param className name of the class
92 + * @param genDir generated directory
93 + * @return temp data
94 + * @throws IOException when fails to read from the file
95 + * @throws ClassNotFoundException when class is missing
96 + * @throws FileNotFoundException when file is missing
97 + */
98 + String getTempData(TempDataStoreTypes type, String className, String genDir)
99 + throws IOException, FileNotFoundException, ClassNotFoundException;
59 } 100 }
......
...@@ -26,9 +26,10 @@ public interface CodeGenerator { ...@@ -26,9 +26,10 @@ public interface CodeGenerator {
26 /** 26 /**
27 * Traverse the schema of application and generate corresponding code. 27 * Traverse the schema of application and generate corresponding code.
28 * 28 *
29 + * @param codeGenDir code generation directory
29 * @throws IOException when fails to translate the data model tree 30 * @throws IOException when fails to translate the data model tree
30 */ 31 */
31 - void generateJavaCodeEntry() throws IOException; 32 + void generateJavaCodeEntry(String codeGenDir) throws IOException;
32 33
33 /** 34 /**
34 * Traverse the schema of application and generate corresponding code. 35 * Traverse the schema of application and generate corresponding code.
......
...@@ -41,7 +41,7 @@ public class AttributeInfo { ...@@ -41,7 +41,7 @@ public class AttributeInfo {
41 /** 41 /**
42 * If the added attribute has to be accessed in a fully qualified manner. 42 * If the added attribute has to be accessed in a fully qualified manner.
43 */ 43 */
44 - private boolean isQualifiedName; 44 + private boolean isQualifiedName = false;
45 45
46 /** 46 /**
47 * The class info will be used to set the attribute type and package info 47 * The class info will be used to set the attribute type and package info
......
...@@ -16,21 +16,26 @@ ...@@ -16,21 +16,26 @@
16 16
17 package org.onosproject.yangutils.translator.tojava; 17 package org.onosproject.yangutils.translator.tojava;
18 18
19 +import java.io.BufferedReader;
19 import java.io.File; 20 import java.io.File;
21 +import java.io.FileNotFoundException;
22 +import java.io.FileReader;
20 import java.io.IOException; 23 import java.io.IOException;
24 +import java.util.ArrayList;
21 import java.util.LinkedList; 25 import java.util.LinkedList;
22 import java.util.List; 26 import java.util.List;
23 import java.util.SortedSet; 27 import java.util.SortedSet;
24 import java.util.TreeSet; 28 import java.util.TreeSet;
25 29
26 import org.onosproject.yangutils.datamodel.YangType; 30 import org.onosproject.yangutils.datamodel.YangType;
27 -import org.onosproject.yangutils.datamodel.YangTypeDef;
28 import org.onosproject.yangutils.translator.CachedFileHandle; 31 import org.onosproject.yangutils.translator.CachedFileHandle;
29 import org.onosproject.yangutils.translator.GeneratedFileType; 32 import org.onosproject.yangutils.translator.GeneratedFileType;
30 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; 33 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
31 import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator; 34 import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator;
32 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 35 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
36 +import org.onosproject.yangutils.translator.tojava.utils.TempDataStoreTypes;
33 import org.onosproject.yangutils.utils.UtilConstants; 37 import org.onosproject.yangutils.utils.UtilConstants;
38 +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
34 39
35 /** 40 /**
36 * Maintain the information about the java file to be generated. 41 * Maintain the information about the java file to be generated.
...@@ -40,6 +45,17 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -40,6 +45,17 @@ public class CachedJavaFileHandle implements CachedFileHandle {
40 private static final int MAX_CACHABLE_ATTR = 64; 45 private static final int MAX_CACHABLE_ATTR = 64;
41 private static final String JAVA_FILE_EXTENSION = ".java"; 46 private static final String JAVA_FILE_EXTENSION = ".java";
42 private static final String TEMP_FILE_EXTENSION = ".tmp"; 47 private static final String TEMP_FILE_EXTENSION = ".tmp";
48 + private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
49 + private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
50 + private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
51 + private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
52 + private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
53 + private static final String ATTRIBUTE_FILE_NAME = "Attributes";
54 + private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
55 + private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
56 + private static final String EQUALS_METHOD_FILE_NAME = "Equals";
57 + private static final String TYPE_DEF_FILE_NAME = "TypeDef";
58 + private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
43 59
44 /** 60 /**
45 * The type(s) of java source file(s) to be generated when the cached file 61 * The type(s) of java source file(s) to be generated when the cached file
...@@ -69,9 +85,9 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -69,9 +85,9 @@ public class CachedJavaFileHandle implements CachedFileHandle {
69 private String relativeFilePath; 85 private String relativeFilePath;
70 86
71 /** 87 /**
72 - * Typedef Info. 88 + * File generation base directory path.
73 */ 89 */
74 - private YangTypeDef typedefInfo; 90 + private String codeGenDirFilePath;
75 91
76 /** 92 /**
77 * Prevent invoking default constructor. 93 * Prevent invoking default constructor.
...@@ -185,33 +201,34 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -185,33 +201,34 @@ public class CachedJavaFileHandle implements CachedFileHandle {
185 attributeList = attrList; 201 attributeList = attrList;
186 } 202 }
187 203
188 - /**
189 - * Set the package relative path.
190 - *
191 - * @param path package relative path
192 - */
193 @Override 204 @Override
194 public void setRelativeFilePath(String path) { 205 public void setRelativeFilePath(String path) {
195 relativeFilePath = path; 206 relativeFilePath = path;
196 } 207 }
197 208
198 - /**
199 - * Get the package relative path.
200 - *
201 - * @return package relative path
202 - */
203 @Override 209 @Override
204 public String getRelativeFilePath() { 210 public String getRelativeFilePath() {
205 return relativeFilePath; 211 return relativeFilePath;
206 } 212 }
207 213
214 + @Override
215 + public String getCodeGenFilePath() {
216 + return codeGenDirFilePath;
217 + }
218 +
219 + @Override
220 + public void setCodeGenFilePath(String path) {
221 + codeGenDirFilePath = path;
222 + }
223 +
208 /** 224 /**
209 * Flush the cached attribute list to the corresponding temporary file. 225 * Flush the cached attribute list to the corresponding temporary file.
210 */ 226 */
211 private void flushCacheAttrToTempFile() { 227 private void flushCacheAttrToTempFile() {
212 228
213 for (AttributeInfo attr : getCachedAttributeList()) { 229 for (AttributeInfo attr : getCachedAttributeList()) {
214 - JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), getYangName()); 230 + JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), getYangName(), getCodeGenFilePath() +
231 + getRelativeFilePath().replace(UtilConstants.PERIOD, UtilConstants.SLASH), this);
215 } 232 }
216 233
217 /* 234 /*
...@@ -220,14 +237,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -220,14 +237,6 @@ public class CachedJavaFileHandle implements CachedFileHandle {
220 getCachedAttributeList().clear(); 237 getCachedAttributeList().clear();
221 } 238 }
222 239
223 - /**
224 - * Add a new attribute to the file(s).
225 - *
226 - * @param attrType data type of the added attribute
227 - * @param name name of the attribute
228 - * @param isListAttr if the current added attribute needs to be maintained
229 - * in a list
230 - */
231 @Override 240 @Override
232 public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) { 241 public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) {
233 /* YANG name is mapped to java name */ 242 /* YANG name is mapped to java name */
...@@ -256,16 +265,29 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -256,16 +265,29 @@ public class CachedJavaFileHandle implements CachedFileHandle {
256 265
257 } else { 266 } else {
258 importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name)); 267 importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name));
259 -
260 importInfo.setPkgInfo(getRelativeFilePath().replace('/', '.') 268 importInfo.setPkgInfo(getRelativeFilePath().replace('/', '.')
261 - + "." + getYangName()); 269 + + "." + getYangName().toLowerCase());
262 isImport = true; 270 isImport = true;
263 } 271 }
264 272
265 newAttr.setQualifiedName(false); 273 newAttr.setQualifiedName(false);
266 if (isImport) { 274 if (isImport) {
267 - boolean isNewImport = addImportInfo(importInfo); 275 + addImportInfo(importInfo);
268 - if (!isNewImport) { 276 + }
277 +
278 + if (isListAttr) {
279 + ImportInfo listImportInfo = new ImportInfo();
280 + listImportInfo.setPkgInfo(UtilConstants.COLLECTION_IMPORTS);
281 + listImportInfo.setClassInfo(UtilConstants.LIST);
282 + addImportInfo(listImportInfo);
283 + }
284 +
285 + /**
286 + * If two classes with different packages have same class info for import than use qualified name.
287 + */
288 + for (ImportInfo imports : getImportSet()) {
289 + if (imports.getClassInfo().equals(importInfo.getClassInfo())
290 + && !imports.getPkgInfo().equals(importInfo.getPkgInfo())) {
269 newAttr.setQualifiedName(true); 291 newAttr.setQualifiedName(true);
270 } 292 }
271 } 293 }
...@@ -280,9 +302,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -280,9 +302,6 @@ public class CachedJavaFileHandle implements CachedFileHandle {
280 getCachedAttributeList().add(newAttr); 302 getCachedAttributeList().add(newAttr);
281 } 303 }
282 304
283 - /**
284 - * Flushes the cached contents to the target file, frees used resources.
285 - */
286 @Override 305 @Override
287 public void close() throws IOException { 306 public void close() throws IOException {
288 307
...@@ -298,17 +317,18 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -298,17 +317,18 @@ public class CachedJavaFileHandle implements CachedFileHandle {
298 * JavaCodeSnippetGen.getFileHeaderComment 317 * JavaCodeSnippetGen.getFileHeaderComment
299 */ 318 */
300 319
301 - List<String> imports = new LinkedList<>(); 320 + List<String> imports = new ArrayList<>();
302 String importString; 321 String importString;
303 322
304 - for (ImportInfo importInfo : getImportSet()) { 323 + for (ImportInfo importInfo : new ArrayList<ImportInfo>(getImportSet())) {
305 - importString = ""; 324 + importString = UtilConstants.IMPORT;
306 if (importInfo.getPkgInfo() != null) { 325 if (importInfo.getPkgInfo() != null) {
307 importString = importString + importInfo.getPkgInfo() + "."; 326 importString = importString + importInfo.getPkgInfo() + ".";
308 } 327 }
309 - importString = importString + importInfo.getClassInfo(); 328 + importString = importString + importInfo.getClassInfo() + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE;
310 imports.add(importString); 329 imports.add(importString);
311 } 330 }
331 + java.util.Collections.sort(imports);
312 332
313 /** 333 /**
314 * Start generation of files. 334 * Start generation of files.
...@@ -320,25 +340,28 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -320,25 +340,28 @@ public class CachedJavaFileHandle implements CachedFileHandle {
320 * Create interface file. 340 * Create interface file.
321 */ 341 */
322 String interfaceFileName = className; 342 String interfaceFileName = className;
323 - File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION); 343 + File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION, this);
324 interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, 344 interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports,
325 - getCachedAttributeList(), path.replace('/', '.')); 345 + getCachedAttributeList(), path.replace('/', '.'), this);
326 -
327 /** 346 /**
328 * Create temp builder interface file. 347 * Create temp builder interface file.
329 */ 348 */
330 String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE; 349 String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE;
331 File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName, 350 File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName,
332 - TEMP_FILE_EXTENSION); 351 + TEMP_FILE_EXTENSION, this);
333 builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, 352 builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className,
334 - path.replace('/', '.'), getCachedAttributeList()); 353 + path.replace('/', '.'), getCachedAttributeList(), this);
335 -
336 /** 354 /**
337 * Append builder interface file to interface file and close it. 355 * Append builder interface file to interface file and close it.
338 */ 356 */
339 JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile); 357 JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile);
340 JavaFileGenerator.insert(interfaceFile, 358 JavaFileGenerator.insert(interfaceFile,
341 JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE_MASK, interfaceFileName)); 359 JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE_MASK, interfaceFileName));
360 + /**
361 + * Close file handle for interface files.
362 + */
363 + JavaFileGenerator.closeFileHandles(builderInterfaceFile);
364 + JavaFileGenerator.closeFileHandles(interfaceFile);
342 365
343 /** 366 /**
344 * Remove temp files. 367 * Remove temp files.
...@@ -346,6 +369,10 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -346,6 +369,10 @@ public class CachedJavaFileHandle implements CachedFileHandle {
346 JavaFileGenerator.clean(builderInterfaceFile); 369 JavaFileGenerator.clean(builderInterfaceFile);
347 } 370 }
348 371
372 + imports.add(UtilConstants.MORE_OBJECT_IMPORT);
373 + imports.add(UtilConstants.JAVA_UTIL_OBJECTS_IMPORT);
374 + java.util.Collections.sort(imports);
375 +
349 if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0 376 if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0
350 || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) { 377 || fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) {
351 378
...@@ -353,19 +380,17 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -353,19 +380,17 @@ public class CachedJavaFileHandle implements CachedFileHandle {
353 * Create builder class file. 380 * Create builder class file.
354 */ 381 */
355 String builderFileName = className + UtilConstants.BUILDER; 382 String builderFileName = className + UtilConstants.BUILDER;
356 - File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION); 383 + File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION, this);
357 builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, 384 builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports,
358 - path.replace('/', '.'), getCachedAttributeList()); 385 + path.replace('/', '.'), getCachedAttributeList(), this);
359 -
360 /** 386 /**
361 * Create temp impl class file. 387 * Create temp impl class file.
362 */ 388 */
363 389
364 String implFileName = className + UtilConstants.IMPL; 390 String implFileName = className + UtilConstants.IMPL;
365 - File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION); 391 + File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION, this);
366 implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, 392 implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className,
367 - path.replace('/', '.'), getCachedAttributeList()); 393 + path.replace('/', '.'), getCachedAttributeList(), this);
368 -
369 /** 394 /**
370 * Append impl class to builder class and close it. 395 * Append impl class to builder class and close it.
371 */ 396 */
...@@ -374,17 +399,210 @@ public class CachedJavaFileHandle implements CachedFileHandle { ...@@ -374,17 +399,210 @@ public class CachedJavaFileHandle implements CachedFileHandle {
374 JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS_MASK, builderFileName)); 399 JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS_MASK, builderFileName));
375 400
376 /** 401 /**
402 + * Close file handle for classes files.
403 + */
404 + JavaFileGenerator.closeFileHandles(implTempFile);
405 + JavaFileGenerator.closeFileHandles(builderFile);
406 +
407 + /**
377 * Remove temp files. 408 * Remove temp files.
378 */ 409 */
379 JavaFileGenerator.clean(implTempFile); 410 JavaFileGenerator.clean(implTempFile);
380 } 411 }
412 +
413 + if ((fileType & GeneratedFileType.GENERATE_TYPEDEF_CLASS) != 0) {
414 +
415 + /**
416 + * Create builder class file.
417 + */
418 + String typeDefFileName = className;
419 + File typeDefFile = JavaFileGenerator.getFileObject(path, typeDefFileName, JAVA_FILE_EXTENSION, this);
420 + typeDefFile = JavaFileGenerator.generateTypeDefClassFile(typeDefFile, className, imports,
421 + path.replace('/', '.'), getCachedAttributeList(), this);
422 + JavaFileGenerator.insert(typeDefFile,
423 + JavaFileGenerator.closeFile(GeneratedFileType.GENERATE_TYPEDEF_CLASS, typeDefFileName));
424 +
425 + /**
426 + * Close file handle for classes files.
427 + */
428 + JavaFileGenerator.closeFileHandles(typeDefFile);
381 } 429 }
382 430
383 - public YangTypeDef getTypedefInfo() { 431 + closeTempDataFileHandles(className, getCodeGenFilePath() + getRelativeFilePath());
384 - return typedefInfo; 432 + JavaFileGenerator
433 + .cleanTempFiles(new File(getCodeGenFilePath() + getRelativeFilePath() + File.separator + className
434 + + TEMP_FOLDER_NAME_SUFIX));
385 } 435 }
386 436
387 - public void setTypedefInfo(YangTypeDef typedefInfo) { 437 + @Override
388 - this.typedefInfo = typedefInfo; 438 + public void setTempData(String data, TempDataStoreTypes type, String className, String genDir)
439 + throws IOException {
440 +
441 + String fileName = "";
442 + if (type.equals(TempDataStoreTypes.ATTRIBUTE)) {
443 + fileName = ATTRIBUTE_FILE_NAME;
444 + } else if (type.equals(TempDataStoreTypes.GETTER_METHODS)) {
445 + fileName = GETTER_METHOD_FILE_NAME;
446 + } else if (type.equals(TempDataStoreTypes.GETTER_METHODS_IMPL)) {
447 + fileName = GETTER_METHOD_IMPL_FILE_NAME;
448 + } else if (type.equals(TempDataStoreTypes.SETTER_METHODS)) {
449 + fileName = SETTER_METHOD_FILE_NAME;
450 + } else if (type.equals(TempDataStoreTypes.SETTER_METHODS_IMPL)) {
451 + fileName = SETTER_METHOD_IMPL_FILE_NAME;
452 + } else if (type.equals(TempDataStoreTypes.TYPE_DEF)) {
453 + fileName = TYPE_DEF_FILE_NAME;
454 + } else if (type.equals(TempDataStoreTypes.TO_STRING)) {
455 + fileName = TO_STRING_METHOD_FILE_NAME;
456 + } else if (type.equals(TempDataStoreTypes.HASH_CODE)) {
457 + fileName = HASH_CODE_METHOD_FILE_NAME;
458 + } else if (type.equals(TempDataStoreTypes.EQUALS)) {
459 + fileName = EQUALS_METHOD_FILE_NAME;
460 + } else {
461 + fileName = CONSTRUCTOR_FILE_NAME;
462 + }
463 +
464 + String path = genDir.replace(UtilConstants.PERIOD, UtilConstants.SLASH)
465 + + File.separator + className
466 + + TEMP_FOLDER_NAME_SUFIX + File.separator;
467 + File dir = new File(path);
468 + if (!dir.exists()) {
469 + dir.mkdirs();
470 + }
471 + File file = new File(path + fileName + TEMP_FILE_EXTENSION);
472 + try {
473 + if (!file.exists()) {
474 + file.createNewFile();
475 + JavaFileGenerator.insert(file, data);
476 + } else {
477 + JavaFileGenerator.insert(file, data);
478 + }
479 + } catch (IOException ex) {
480 + throw new IOException("failed to write in temp file.");
481 + }
482 + }
483 +
484 + @Override
485 + public String getTempData(TempDataStoreTypes type, String className, String genDir)
486 + throws IOException, FileNotFoundException, ClassNotFoundException {
487 +
488 + String fileName = "";
489 + if (type.equals(TempDataStoreTypes.ATTRIBUTE)) {
490 + fileName = ATTRIBUTE_FILE_NAME;
491 + } else if (type.equals(TempDataStoreTypes.GETTER_METHODS)) {
492 + fileName = GETTER_METHOD_FILE_NAME;
493 + } else if (type.equals(TempDataStoreTypes.GETTER_METHODS_IMPL)) {
494 + fileName = GETTER_METHOD_IMPL_FILE_NAME;
495 + } else if (type.equals(TempDataStoreTypes.SETTER_METHODS)) {
496 + fileName = SETTER_METHOD_FILE_NAME;
497 + } else if (type.equals(TempDataStoreTypes.SETTER_METHODS_IMPL)) {
498 + fileName = SETTER_METHOD_IMPL_FILE_NAME;
499 + } else if (type.equals(TempDataStoreTypes.TYPE_DEF)) {
500 + fileName = TYPE_DEF_FILE_NAME;
501 + } else if (type.equals(TempDataStoreTypes.TO_STRING)) {
502 + fileName = TO_STRING_METHOD_FILE_NAME;
503 + } else if (type.equals(TempDataStoreTypes.HASH_CODE)) {
504 + fileName = HASH_CODE_METHOD_FILE_NAME;
505 + } else if (type.equals(TempDataStoreTypes.EQUALS)) {
506 + fileName = EQUALS_METHOD_FILE_NAME;
507 + } else {
508 + fileName = CONSTRUCTOR_FILE_NAME;
509 + }
510 +
511 + String path = genDir.replace(UtilConstants.PERIOD, UtilConstants.SLASH)
512 + + File.separator + className + TEMP_FOLDER_NAME_SUFIX + File.separator;
513 +
514 + try {
515 + return readFile(path + fileName + TEMP_FILE_EXTENSION);
516 +
517 + } catch (FileNotFoundException e) {
518 + throw new FileNotFoundException("No such file or directory.");
519 + }
520 + }
521 +
522 + /**
523 + * Reads file and convert it to string.
524 + *
525 + * @param toAppend file to be converted
526 + * @return string of file
527 + * @throws IOException when fails to convert to string
528 + */
529 + private static String readFile(String toAppend) throws IOException {
530 + BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
531 + try {
532 + StringBuilder stringBuilder = new StringBuilder();
533 + String line = bufferReader.readLine();
534 +
535 + while (line != null) {
536 + stringBuilder.append(line);
537 + stringBuilder.append("\n");
538 + line = bufferReader.readLine();
539 + }
540 + return stringBuilder.toString();
541 + } finally {
542 + bufferReader.close();
543 + }
544 + }
545 +
546 + /**
547 + * Closes the temp file handles.
548 + *
549 + * @param className class name
550 + * @param genDir generated directory
551 + * @throws IOException when failes to close file handle
552 + */
553 + private void closeTempDataFileHandles(String className, String genDir)
554 + throws IOException {
555 +
556 + String path = genDir.replace(UtilConstants.PERIOD, UtilConstants.SLASH) + File.separator + className
557 + + TEMP_FOLDER_NAME_SUFIX + File.separator;
558 +
559 + String fileName = "";
560 + fileName = ATTRIBUTE_FILE_NAME;
561 + closeTempFile(fileName, path);
562 +
563 + fileName = GETTER_METHOD_FILE_NAME;
564 + closeTempFile(fileName, path);
565 +
566 + fileName = GETTER_METHOD_IMPL_FILE_NAME;
567 + closeTempFile(fileName, path);
568 +
569 + fileName = SETTER_METHOD_FILE_NAME;
570 + closeTempFile(fileName, path);
571 +
572 + fileName = SETTER_METHOD_IMPL_FILE_NAME;
573 + closeTempFile(fileName, path);
574 +
575 + fileName = TYPE_DEF_FILE_NAME;
576 + closeTempFile(fileName, path);
577 +
578 + fileName = TO_STRING_METHOD_FILE_NAME;
579 + closeTempFile(fileName, path);
580 +
581 + fileName = HASH_CODE_METHOD_FILE_NAME;
582 + closeTempFile(fileName, path);
583 +
584 + fileName = EQUALS_METHOD_FILE_NAME;
585 + closeTempFile(fileName, path);
586 +
587 + fileName = CONSTRUCTOR_FILE_NAME;
588 + closeTempFile(fileName, path);
589 + }
590 +
591 + /**
592 + * Closes the specific temp file.
593 + *
594 + * @param fileName temp file name
595 + * @param path path
596 + * @throws IOException when failed to close file handle
597 + */
598 + private void closeTempFile(String fileName, String path) throws IOException {
599 + File file = new File(path + fileName + TEMP_FILE_EXTENSION);
600 + try {
601 + if (!file.exists()) {
602 + FileSystemUtil.updateFileHandle(file, null, true);
603 + }
604 + } catch (IOException ex) {
605 + throw new IOException("failed to close the temp file handle.");
606 + }
389 } 607 }
390 } 608 }
......
...@@ -35,16 +35,16 @@ public final class JavaCodeGenerator { ...@@ -35,16 +35,16 @@ public final class JavaCodeGenerator {
35 * Generate Java code files corresponding to the YANG schema. 35 * Generate Java code files corresponding to the YANG schema.
36 * 36 *
37 * @param rootNode root node of the data model tree 37 * @param rootNode root node of the data model tree
38 - * @throws IOException when fails to generate java code file the current 38 + * @param codeGenDir code generation directory
39 - * node 39 + * @throws IOException when fails to generate java code file the current node
40 */ 40 */
41 - public static void generateJavaCode(YangNode rootNode) throws IOException { 41 + public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
42 YangNode curNode = rootNode; 42 YangNode curNode = rootNode;
43 TraversalType curTraversal = TraversalType.ROOT; 43 TraversalType curTraversal = TraversalType.ROOT;
44 44
45 while (!(curNode == null)) { 45 while (!(curNode == null)) {
46 if (curTraversal != TraversalType.PARENT) { 46 if (curTraversal != TraversalType.PARENT) {
47 - curNode.generateJavaCodeEntry(); 47 + curNode.generateJavaCodeEntry(codeGenDir);
48 } 48 }
49 if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) { 49 if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
50 curTraversal = TraversalType.CHILD; 50 curTraversal = TraversalType.CHILD;
......
...@@ -79,7 +79,7 @@ public final class AttributesJavaDataType { ...@@ -79,7 +79,7 @@ public final class AttributesJavaDataType {
79 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { 79 } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
80 //TODO:INSTANCE_IDENTIFIER 80 //TODO:INSTANCE_IDENTIFIER
81 } else if (type.equals(YangDataTypes.DERIVED)) { 81 } else if (type.equals(YangDataTypes.DERIVED)) {
82 - //TODO:DERIVED 82 + return yangType.getDataTypeName();
83 } 83 }
84 return null; 84 return null;
85 } 85 }
......
...@@ -56,6 +56,9 @@ public final class ClassDefinitionGenerator { ...@@ -56,6 +56,9 @@ public final class ClassDefinitionGenerator {
56 } else if ((genFileTypes & GeneratedFileType.BUILDER_INTERFACE_MASK) != 0) { 56 } else if ((genFileTypes & GeneratedFileType.BUILDER_INTERFACE_MASK) != 0) {
57 57
58 return getBuilderInterfaceDefinition(yangName); 58 return getBuilderInterfaceDefinition(yangName);
59 + } else if ((genFileTypes & GeneratedFileType.GENERATE_TYPEDEF_CLASS) != 0) {
60 +
61 + return getTypeDefClassDefinition(yangName);
59 } 62 }
60 return null; 63 return null;
61 } 64 }
...@@ -94,7 +97,7 @@ public final class ClassDefinitionGenerator { ...@@ -94,7 +97,7 @@ public final class ClassDefinitionGenerator {
94 97
95 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName 98 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName
96 + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE 99 + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE
97 - + yangName + UtilConstants.PERIOD + UtilConstants.BUILDER + UtilConstants.SPACE 100 + + yangName + UtilConstants.PERIOD + yangName + UtilConstants.BUILDER + UtilConstants.SPACE
98 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; 101 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
99 } 102 }
100 103
...@@ -108,8 +111,22 @@ public final class ClassDefinitionGenerator { ...@@ -108,8 +111,22 @@ public final class ClassDefinitionGenerator {
108 111
109 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE 112 return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
110 + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE 113 + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE
111 - + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.OPEN_CURLY_BRACKET 114 + + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE
115 + + UtilConstants.OPEN_CURLY_BRACKET
112 + UtilConstants.SPACE + UtilConstants.NEW_LINE; 116 + UtilConstants.SPACE + UtilConstants.NEW_LINE;
113 } 117 }
114 118
119 + /**
120 + * Returns typeDef file class definition.
121 + *
122 + * @param yangName file name
123 + * @return definition
124 + */
125 + private static String getTypeDefClassDefinition(String yangName) {
126 +
127 + return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
128 + + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE
129 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.SPACE + UtilConstants.NEW_LINE;
130 + }
131 +
115 } 132 }
......
...@@ -78,14 +78,16 @@ public final class JavaCodeSnippetGen { ...@@ -78,14 +78,16 @@ public final class JavaCodeSnippetGen {
78 * @param javaAttributeTypePkg Package of the attribute type 78 * @param javaAttributeTypePkg Package of the attribute type
79 * @param javaAttributeType java attribute type 79 * @param javaAttributeType java attribute type
80 * @param javaAttributeName name of the attribute 80 * @param javaAttributeName name of the attribute
81 + * @param isList is list attribute
81 * @return the textual java code for attribute definition in class 82 * @return the textual java code for attribute definition in class
82 */ 83 */
83 public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, 84 public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
84 - String javaAttributeName) { 85 + String javaAttributeName, boolean isList) {
85 86
86 String attributeDefination = UtilConstants.PRIVATE 87 String attributeDefination = UtilConstants.PRIVATE
87 + UtilConstants.SPACE; 88 + UtilConstants.SPACE;
88 89
90 + if (!isList) {
89 if (javaAttributeTypePkg != null) { 91 if (javaAttributeTypePkg != null) {
90 attributeDefination = attributeDefination 92 attributeDefination = attributeDefination
91 + javaAttributeTypePkg + "."; 93 + javaAttributeTypePkg + ".";
...@@ -96,7 +98,17 @@ public final class JavaCodeSnippetGen { ...@@ -96,7 +98,17 @@ public final class JavaCodeSnippetGen {
96 + UtilConstants.SPACE 98 + UtilConstants.SPACE
97 + javaAttributeName 99 + javaAttributeName
98 + UtilConstants.SEMI_COLAN; 100 + UtilConstants.SEMI_COLAN;
101 + } else {
102 + attributeDefination = attributeDefination + UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET;
103 + if (javaAttributeTypePkg != null) {
104 + attributeDefination = attributeDefination
105 + + javaAttributeTypePkg + ".";
106 + }
99 107
108 + attributeDefination = attributeDefination
109 + + javaAttributeType + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE
110 + + javaAttributeName + UtilConstants.SEMI_COLAN;
111 + }
100 return attributeDefination; 112 return attributeDefination;
101 } 113 }
102 114
...@@ -126,6 +138,9 @@ public final class JavaCodeSnippetGen { ...@@ -126,6 +138,9 @@ public final class JavaCodeSnippetGen {
126 } else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) { 138 } else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) {
127 139
128 return UtilConstants.CLOSE_CURLY_BRACKET; 140 return UtilConstants.CLOSE_CURLY_BRACKET;
141 + } else if ((genFileTypes & GeneratedFileType.GENERATE_TYPEDEF_CLASS) != 0) {
142 +
143 + return UtilConstants.CLOSE_CURLY_BRACKET;
129 } 144 }
130 return null; 145 return null;
131 } 146 }
......
...@@ -16,26 +16,28 @@ ...@@ -16,26 +16,28 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 +import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_CLASS_MASK;
20 +import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_INTERFACE_MASK;
21 +import static org.onosproject.yangutils.translator.GeneratedFileType.GENERATE_TYPEDEF_CLASS;
22 +import static org.onosproject.yangutils.translator.GeneratedFileType.IMPL_CLASS_MASK;
23 +import static org.onosproject.yangutils.translator.GeneratedFileType.INTERFACE_MASK;
24 +import static org.slf4j.LoggerFactory.getLogger;
25 +
19 import java.io.File; 26 import java.io.File;
20 import java.io.IOException; 27 import java.io.IOException;
28 +import java.util.ArrayList;
21 import java.util.List; 29 import java.util.List;
22 30
31 +import org.apache.commons.io.FileUtils;
32 +import org.onosproject.yangutils.translator.CachedFileHandle;
23 import org.onosproject.yangutils.translator.tojava.AttributeInfo; 33 import org.onosproject.yangutils.translator.tojava.AttributeInfo;
24 import org.onosproject.yangutils.utils.UtilConstants; 34 import org.onosproject.yangutils.utils.UtilConstants;
25 import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; 35 import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
26 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; 36 import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
27 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 37 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
28 import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; 38 import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
29 -import org.onosproject.yangutils.utils.io.impl.TempDataStore;
30 -import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType;
31 import org.slf4j.Logger; 39 import org.slf4j.Logger;
32 40
33 -import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_CLASS_MASK;
34 -import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_INTERFACE_MASK;
35 -import static org.onosproject.yangutils.translator.GeneratedFileType.IMPL_CLASS_MASK;
36 -import static org.onosproject.yangutils.translator.GeneratedFileType.INTERFACE_MASK;
37 -import static org.slf4j.LoggerFactory.getLogger;
38 -
39 /** 41 /**
40 * Generates java file. 42 * Generates java file.
41 */ 43 */
...@@ -55,10 +57,11 @@ public final class JavaFileGenerator { ...@@ -55,10 +57,11 @@ public final class JavaFileGenerator {
55 * @param fileName file name 57 * @param fileName file name
56 * @param filePath file package path 58 * @param filePath file package path
57 * @param extension file extension 59 * @param extension file extension
60 + * @param handle cached file handle
58 * @return file object 61 * @return file object
59 */ 62 */
60 - public static File getFileObject(String filePath, String fileName, String extension) { 63 + public static File getFileObject(String filePath, String fileName, String extension, CachedFileHandle handle) {
61 - return new File(UtilConstants.YANG_GEN_DIR + filePath + File.separator + fileName + extension); 64 + return new File(handle.getCodeGenFilePath() + filePath + File.separator + fileName + extension);
62 } 65 }
63 66
64 /** 67 /**
...@@ -69,17 +72,18 @@ public final class JavaFileGenerator { ...@@ -69,17 +72,18 @@ public final class JavaFileGenerator {
69 * @param imports imports for the file 72 * @param imports imports for the file
70 * @param attrList attribute info 73 * @param attrList attribute info
71 * @param pkg generated file package 74 * @param pkg generated file package
75 + * @param handle cached file handle
72 * @return interface file 76 * @return interface file
73 * @throws IOException when fails to write in file 77 * @throws IOException when fails to write in file
74 */ 78 */
75 public static File generateInterfaceFile(File file, String className, List<String> imports, 79 public static File generateInterfaceFile(File file, String className, List<String> imports,
76 - List<AttributeInfo> attrList, String pkg) throws IOException { 80 + List<AttributeInfo> attrList, String pkg, CachedFileHandle handle) throws IOException {
77 - 81 + String path = handle.getCodeGenFilePath() + pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
78 initiateFile(file, className, INTERFACE_MASK, imports, pkg); 82 initiateFile(file, className, INTERFACE_MASK, imports, pkg);
79 83
80 - List<String> methods; 84 + List<String> methods = new ArrayList<>();
81 try { 85 try {
82 - methods = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, className); 86 + methods.add(handle.getTempData(TempDataStoreTypes.GETTER_METHODS, className, path));
83 } catch (ClassNotFoundException | IOException e) { 87 } catch (ClassNotFoundException | IOException e) {
84 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 88 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
85 throw new IOException("Fail to read data from temp file."); 89 throw new IOException("Fail to read data from temp file.");
...@@ -101,17 +105,19 @@ public final class JavaFileGenerator { ...@@ -101,17 +105,19 @@ public final class JavaFileGenerator {
101 * @param className class name 105 * @param className class name
102 * @param pkg generated file package 106 * @param pkg generated file package
103 * @param attrList attribute info 107 * @param attrList attribute info
108 + * @param handle cached file handle
104 * @return builder interface file 109 * @return builder interface file
105 * @throws IOException when fails to write in file 110 * @throws IOException when fails to write in file
106 */ 111 */
107 public static File generateBuilderInterfaceFile(File file, String className, String pkg, 112 public static File generateBuilderInterfaceFile(File file, String className, String pkg,
108 - List<AttributeInfo> attrList) throws IOException { 113 + List<AttributeInfo> attrList, CachedFileHandle handle) throws IOException {
109 - 114 + String path = handle.getCodeGenFilePath() + pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
110 initiateFile(file, className, BUILDER_INTERFACE_MASK, null, pkg); 115 initiateFile(file, className, BUILDER_INTERFACE_MASK, null, pkg);
111 - List<String> methods; 116 + List<String> methods = new ArrayList<>();
117 +
112 try { 118 try {
113 - methods = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, 119 + methods.add(handle.getTempData(TempDataStoreTypes.GETTER_METHODS, className, path));
114 - className + UtilConstants.BUILDER + UtilConstants.INTERFACE); 120 + methods.add(handle.getTempData(TempDataStoreTypes.SETTER_METHODS, className, path));
115 } catch (ClassNotFoundException | IOException e) { 121 } catch (ClassNotFoundException | IOException e) {
116 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 122 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
117 throw new IOException("Fail to read data from temp file."); 123 throw new IOException("Fail to read data from temp file.");
...@@ -126,7 +132,7 @@ public final class JavaFileGenerator { ...@@ -126,7 +132,7 @@ public final class JavaFileGenerator {
126 * Add getters and setters in builder interface. 132 * Add getters and setters in builder interface.
127 */ 133 */
128 for (String method : methods) { 134 for (String method : methods) {
129 - appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); 135 + appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method);
130 } 136 }
131 137
132 insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); 138 insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE);
...@@ -141,20 +147,21 @@ public final class JavaFileGenerator { ...@@ -141,20 +147,21 @@ public final class JavaFileGenerator {
141 * @param imports imports for the file 147 * @param imports imports for the file
142 * @param pkg generated file package 148 * @param pkg generated file package
143 * @param attrList attribute info 149 * @param attrList attribute info
150 + * @param handle cached file handle
144 * @return builder class file 151 * @return builder class file
145 * @throws IOException when fails to write in file 152 * @throws IOException when fails to write in file
146 */ 153 */
147 public static File generateBuilderClassFile(File file, String className, List<String> imports, String pkg, 154 public static File generateBuilderClassFile(File file, String className, List<String> imports, String pkg,
148 - List<AttributeInfo> attrList) throws IOException { 155 + List<AttributeInfo> attrList, CachedFileHandle handle) throws IOException {
149 - 156 + String path = handle.getCodeGenFilePath() + pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
150 initiateFile(file, className, BUILDER_CLASS_MASK, imports, pkg); 157 initiateFile(file, className, BUILDER_CLASS_MASK, imports, pkg);
151 158
152 /** 159 /**
153 * Add attribute strings. 160 * Add attribute strings.
154 */ 161 */
155 - List<String> attributes; 162 + List<String> attributes = new ArrayList<>();
156 try { 163 try {
157 - attributes = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, className); 164 + attributes.add(handle.getTempData(TempDataStoreTypes.ATTRIBUTE, className, path));
158 } catch (ClassNotFoundException | IOException e) { 165 } catch (ClassNotFoundException | IOException e) {
159 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 166 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
160 throw new IOException("Fail to read data from temp file."); 167 throw new IOException("Fail to read data from temp file.");
...@@ -165,11 +172,11 @@ public final class JavaFileGenerator { ...@@ -165,11 +172,11 @@ public final class JavaFileGenerator {
165 for (String attribute : attributes) { 172 for (String attribute : attributes) {
166 insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute); 173 insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
167 } 174 }
168 - insert(file, UtilConstants.NEW_LINE);
169 175
170 - List<String> methods; 176 + List<String> methods = new ArrayList<>();
171 try { 177 try {
172 - methods = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, className + UtilConstants.BUILDER); 178 + methods.add(handle.getTempData(TempDataStoreTypes.GETTER_METHODS_IMPL, className, path));
179 + methods.add(handle.getTempData(TempDataStoreTypes.SETTER_METHODS_IMPL, className, path));
173 } catch (ClassNotFoundException | IOException e) { 180 } catch (ClassNotFoundException | IOException e) {
174 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 181 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
175 throw new IOException("Fail to read data from temp file."); 182 throw new IOException("Fail to read data from temp file.");
...@@ -179,7 +186,8 @@ public final class JavaFileGenerator { ...@@ -179,7 +186,8 @@ public final class JavaFileGenerator {
179 * Add default constructor and build method impl. 186 * Add default constructor and build method impl.
180 */ 187 */
181 methods.add(UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE 188 methods.add(UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
182 - + MethodsGenerator.getDefaultConstructorString(BUILDER_CLASS_MASK, className)); 189 + + MethodsGenerator.getDefaultConstructorString(className + UtilConstants.BUILDER,
190 + UtilConstants.PUBLIC));
183 methods.add(MethodsGenerator.getBuildString(className)); 191 methods.add(MethodsGenerator.getBuildString(className));
184 192
185 /** 193 /**
...@@ -198,17 +206,19 @@ public final class JavaFileGenerator { ...@@ -198,17 +206,19 @@ public final class JavaFileGenerator {
198 * @param className class name 206 * @param className class name
199 * @param pkg generated file package 207 * @param pkg generated file package
200 * @param attrList attribute's info 208 * @param attrList attribute's info
209 + * @param handle cached file handle
201 * @return impl class file 210 * @return impl class file
202 * @throws IOException when fails to write in file 211 * @throws IOException when fails to write in file
203 */ 212 */
204 - public static File generateImplClassFile(File file, String className, String pkg, List<AttributeInfo> attrList) 213 + public static File generateImplClassFile(File file, String className, String pkg, List<AttributeInfo> attrList,
214 + CachedFileHandle handle)
205 throws IOException { 215 throws IOException {
216 + String path = handle.getCodeGenFilePath() + pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
217 + initiateFile(file, className, IMPL_CLASS_MASK, null, path);
206 218
207 - initiateFile(file, className, IMPL_CLASS_MASK, null, pkg); 219 + List<String> attributes = new ArrayList<>();
208 -
209 - List<String> attributes;
210 try { 220 try {
211 - attributes = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, className); 221 + attributes.add(handle.getTempData(TempDataStoreTypes.ATTRIBUTE, className, path));
212 } catch (ClassNotFoundException | IOException e) { 222 } catch (ClassNotFoundException | IOException e) {
213 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 223 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
214 throw new IOException("Fail to read data from temp file."); 224 throw new IOException("Fail to read data from temp file.");
...@@ -220,24 +230,34 @@ public final class JavaFileGenerator { ...@@ -220,24 +230,34 @@ public final class JavaFileGenerator {
220 for (String attribute : attributes) { 230 for (String attribute : attributes) {
221 insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute); 231 insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
222 } 232 }
223 - insert(file, UtilConstants.NEW_LINE);
224 233
225 - List<String> methods; 234 + List<String> methods = new ArrayList<>();
226 try { 235 try {
227 - methods = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, className + UtilConstants.IMPL); 236 +
237 + methods.add(handle.getTempData(TempDataStoreTypes.GETTER_METHODS_IMPL, className, path));
238 +
239 + methods.add(getConstructorString(className)
240 + + handle.getTempData(TempDataStoreTypes.CONSTRUCTOR, className, path)
241 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET);
242 +
243 + methods.add(MethodsGenerator.getHashCodeMethodClose(MethodsGenerator.getHashCodeMethodOpen()
244 + + handle.getTempData(TempDataStoreTypes.HASH_CODE, className, path).replace(UtilConstants.NEW_LINE,
245 + "")));
246 +
247 + methods.add(MethodsGenerator
248 + .getEqualsMethodClose(MethodsGenerator.getEqualsMethodOpen(className + UtilConstants.IMPL)
249 + + handle.getTempData(TempDataStoreTypes.EQUALS, className, path)));
250 +
251 + methods.add(MethodsGenerator.getToStringMethodOpen()
252 + + handle.getTempData(TempDataStoreTypes.TO_STRING, className, path)
253 + + MethodsGenerator.getToStringMethodClose());
254 +
228 } catch (ClassNotFoundException | IOException e) { 255 } catch (ClassNotFoundException | IOException e) {
229 log.info("There is no attribute info of " + className + " YANG file in the temporary files."); 256 log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
230 throw new IOException("Fail to read data from temp file."); 257 throw new IOException("Fail to read data from temp file.");
231 } 258 }
232 259
233 /** 260 /**
234 - * Add default constructor and constructor methods.
235 - */
236 - methods.add(UtilConstants.JAVA_DOC_FIRST_LINE
237 - + MethodsGenerator.getDefaultConstructorString(IMPL_CLASS_MASK, className));
238 - methods.add(MethodsGenerator.getConstructorString(className));
239 -
240 - /**
241 * Add methods in impl class. 261 * Add methods in impl class.
242 */ 262 */
243 for (String method : methods) { 263 for (String method : methods) {
...@@ -249,6 +269,58 @@ public final class JavaFileGenerator { ...@@ -249,6 +269,58 @@ public final class JavaFileGenerator {
249 } 269 }
250 270
251 /** 271 /**
272 + * Generate class file for type def.
273 + *
274 + * @param file generated file
275 + * @param className file name
276 + * @param imports imports for file
277 + * @param pkg package path
278 + * @param cachedAttributeList attribute list
279 + * @param handle cached file handle
280 + * @return type def class file
281 + * @throws IOException when fails to generate class file
282 + */
283 + public static File generateTypeDefClassFile(File file, String className, List<String> imports,
284 + String pkg, List<AttributeInfo> cachedAttributeList, CachedFileHandle handle) throws IOException {
285 + String path = handle.getCodeGenFilePath() + pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH);
286 + initiateFile(file, className, GENERATE_TYPEDEF_CLASS, imports, pkg);
287 +
288 + List<String> typeDef = new ArrayList<>();
289 + try {
290 + typeDef.add(handle.getTempData(TempDataStoreTypes.TYPE_DEF, className, path));
291 + } catch (ClassNotFoundException | IOException e) {
292 + log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
293 + throw new IOException("Fail to read data from temp file.");
294 + }
295 +
296 + /**
297 + * Add attributes to the file.
298 + */
299 + for (String attribute : typeDef) {
300 + insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
301 + }
302 +
303 + return file;
304 + }
305 +
306 + /**
307 + * Returns constructor string for impl class.
308 + *
309 + * @param yangName class name
310 + * @return constructor string
311 + */
312 + private static String getConstructorString(String yangName) {
313 +
314 + String builderAttribute = yangName.substring(0, 1).toLowerCase() + yangName.substring(1);
315 + String javadoc = MethodsGenerator.getConstructorString(yangName);
316 + String constructor = UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
317 + + yangName + UtilConstants.IMPL + UtilConstants.OPEN_PARENTHESIS + yangName + UtilConstants.BUILDER
318 + + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT + UtilConstants.CLOSE_PARENTHESIS
319 + + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
320 + return javadoc + constructor;
321 + }
322 +
323 + /**
252 * Initiate generation of file based on generated file type. 324 * Initiate generation of file based on generated file type.
253 * 325 *
254 * @param file generated file 326 * @param file generated file
...@@ -288,7 +360,6 @@ public final class JavaFileGenerator { ...@@ -288,7 +360,6 @@ public final class JavaFileGenerator {
288 * 360 *
289 * @param file file in which method needs to be appended 361 * @param file file in which method needs to be appended
290 * @param method method which needs to be appended 362 * @param method method which needs to be appended
291 - * @exception IOException file operation exceptions
292 */ 363 */
293 private static void appendMethod(File file, String method) throws IOException { 364 private static void appendMethod(File file, String method) throws IOException {
294 insert(file, method); 365 insert(file, method);
...@@ -309,17 +380,30 @@ public final class JavaFileGenerator { ...@@ -309,17 +380,30 @@ public final class JavaFileGenerator {
309 * Parses attribute info and fetch specific data and creates serialized 380 * Parses attribute info and fetch specific data and creates serialized
310 * files of it. 381 * files of it.
311 * 382 *
312 - * @param attr attribute info 383 + * @param attr attribute info.
313 * @param genFileType generated file type 384 * @param genFileType generated file type
314 * @param className class name 385 * @param className class name
386 + * @param path file path
387 + * @param handle cached file handle
315 */ 388 */
316 - public static void parseAttributeInfo(AttributeInfo attr, int genFileType, String className) { 389 + public static void parseAttributeInfo(AttributeInfo attr, int genFileType, String className, String path,
390 + CachedFileHandle handle) {
317 391
318 String attrString = ""; 392 String attrString = "";
319 - String builderInterfaceMethodString = ""; 393 +
320 - String builderClassMethodString = "";
321 - String implClassMethodString = "";
322 String getterString = ""; 394 String getterString = "";
395 + String getterImplString = "";
396 +
397 + String setterString = "";
398 + String setterImplString = "";
399 +
400 + String constructorString = "";
401 + String typeDefString = "";
402 +
403 + String toString = "";
404 + String hashCodeString = "";
405 + String equalsString = "";
406 +
323 className = JavaIdentifierSyntax.getCaptialCase(className); 407 className = JavaIdentifierSyntax.getCaptialCase(className);
324 408
325 try { 409 try {
...@@ -327,33 +411,124 @@ public final class JavaFileGenerator { ...@@ -327,33 +411,124 @@ public final class JavaFileGenerator {
327 * Get the attribute definition and save attributes to temporary 411 * Get the attribute definition and save attributes to temporary
328 * file. 412 * file.
329 */ 413 */
414 +
415 + boolean isList = attr.isListAttr();
416 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
417 + if (attr.isQualifiedName()) {
330 attrString = JavaCodeSnippetGen.getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), 418 attrString = JavaCodeSnippetGen.getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
331 attr.getImportInfo().getClassInfo(), 419 attr.getImportInfo().getClassInfo(),
332 - attr.getAttributeName()); 420 + attributeName, attr.isListAttr());
333 - TempDataStore.setTempData(attrString, TempDataStore.TempDataStoreType.ATTRIBUTE, className); 421 + } else {
422 + attrString = JavaCodeSnippetGen.getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(),
423 + attributeName, attr.isListAttr());
424 + }
425 + handle.setTempData(attrString + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION,
426 + TempDataStoreTypes.ATTRIBUTE, className,
427 + path);
334 428
335 if ((genFileType & INTERFACE_MASK) != 0) { 429 if ((genFileType & INTERFACE_MASK) != 0) {
336 getterString = MethodsGenerator.getGetterString(attr); 430 getterString = MethodsGenerator.getGetterString(attr);
337 - TempDataStore.setTempData(getterString, TempDataStore.TempDataStoreType.GETTER_METHODS, className); 431 + handle.setTempData(getterString + UtilConstants.NEW_LINE,
432 + TempDataStoreTypes.GETTER_METHODS,
433 + className,
434 + path);
435 +
338 } 436 }
339 437
340 if ((genFileType & BUILDER_INTERFACE_MASK) != 0) { 438 if ((genFileType & BUILDER_INTERFACE_MASK) != 0) {
341 - builderInterfaceMethodString = MethodsGenerator.parseBuilderInterfaceMethodString(attr, className); 439 + setterString = MethodsGenerator.getSetterString(attr, className);
342 - TempDataStore.setTempData(builderInterfaceMethodString, 440 + handle.setTempData(setterString + UtilConstants.NEW_LINE,
343 - TempDataStore.TempDataStoreType.BUILDER_INTERFACE_METHODS, 441 + TempDataStoreTypes.SETTER_METHODS,
344 - className + UtilConstants.BUILDER + UtilConstants.INTERFACE); 442 + className,
443 + path);
345 } 444 }
346 445
347 if ((genFileType & BUILDER_CLASS_MASK) != 0) { 446 if ((genFileType & BUILDER_CLASS_MASK) != 0) {
348 - builderClassMethodString = MethodsGenerator.parseBuilderMethodString(attr, className); 447 + getterImplString = MethodsGenerator.getGetterForClass(attr);
349 - TempDataStore.setTempData(builderClassMethodString, TempDataStore.TempDataStoreType.BUILDER_METHODS, 448 + handle.setTempData(
350 - className + UtilConstants.BUILDER); 449 + MethodsGenerator.getOverRideString() + getterImplString + UtilConstants.NEW_LINE,
450 + TempDataStoreTypes.GETTER_METHODS_IMPL, className,
451 + path);
452 + setterImplString = MethodsGenerator.getSetterForClass(attr, className);
453 + handle.setTempData(
454 + MethodsGenerator.getOverRideString() + setterImplString + UtilConstants.NEW_LINE,
455 + TempDataStoreTypes.SETTER_METHODS_IMPL, className,
456 + path);
351 } 457 }
352 458
353 if ((genFileType & IMPL_CLASS_MASK) != 0) { 459 if ((genFileType & IMPL_CLASS_MASK) != 0) {
354 - implClassMethodString = MethodsGenerator.parseImplMethodString(attr); 460 + constructorString = MethodsGenerator.getConstructor(className, attr);
355 - TempDataStore.setTempData(implClassMethodString, TempDataStore.TempDataStoreType.IMPL_METHODS, 461 + handle.setTempData(constructorString, TempDataStoreTypes.CONSTRUCTOR, className,
356 - className + UtilConstants.IMPL); 462 + path);
463 +
464 + hashCodeString = MethodsGenerator.getHashCodeMethod(attr);
465 + handle.setTempData(hashCodeString + UtilConstants.NEW_LINE,
466 + TempDataStoreTypes.HASH_CODE,
467 + className,
468 + path);
469 + equalsString = MethodsGenerator.getEqualsMethod(attr);
470 + handle.setTempData(equalsString + UtilConstants.NEW_LINE,
471 + TempDataStoreTypes.EQUALS,
472 + className,
473 + path);
474 +
475 + toString = MethodsGenerator.getToStringMethod(attr);
476 + handle.setTempData(toString + UtilConstants.NEW_LINE,
477 + TempDataStoreTypes.TO_STRING,
478 + className,
479 + path);
480 +
481 + }
482 +
483 + if ((genFileType & GENERATE_TYPEDEF_CLASS) != 0) {
484 +
485 + if (attr.isQualifiedName()) {
486 + typeDefString = JavaCodeSnippetGen.getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
487 + attr.getImportInfo().getClassInfo(),
488 + attributeName, attr.isListAttr()) + UtilConstants.NEW_LINE;
489 + } else {
490 + typeDefString = JavaCodeSnippetGen.getJavaAttributeDefination(null,
491 + attr.getImportInfo().getClassInfo(),
492 + attributeName, attr.isListAttr()) + UtilConstants.NEW_LINE;
493 + }
494 +
495 + typeDefString = typeDefString + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
496 + + UtilConstants.JAVA_DOC_FIRST_LINE;
497 +
498 + typeDefString = typeDefString
499 + + MethodsGenerator.getDefaultConstructorString(className, UtilConstants.PRIVATE)
500 + + UtilConstants.NEW_LINE;
501 +
502 + typeDefString = typeDefString
503 + + JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_CONSTRUCTOR, className, isList)
504 + + MethodsGenerator.getTypeDefConstructor(attr, className)
505 + + UtilConstants.NEW_LINE;
506 +
507 + typeDefString = typeDefString + JavaDocGen.getJavaDoc(JavaDocType.OF, className, isList)
508 + + MethodsGenerator.getOfMethod(className, attr) + UtilConstants.NEW_LINE;
509 +
510 + typeDefString = typeDefString + JavaDocGen.getJavaDoc(JavaDocType.GETTER, className, isList)
511 + + MethodsGenerator.getGetterForClass(attr) + UtilConstants.NEW_LINE;
512 +
513 + typeDefString = typeDefString + JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, className, isList)
514 + + MethodsGenerator.getSetterForTypeDefClass(attr)
515 + + UtilConstants.NEW_LINE;
516 +
517 + hashCodeString = hashCodeString + MethodsGenerator.getHashCodeMethodOpen()
518 + + MethodsGenerator.getHashCodeMethod(attr).replace(UtilConstants.NEW_LINE, "");
519 + hashCodeString = MethodsGenerator.getHashCodeMethodClose(hashCodeString) + UtilConstants.NEW_LINE;
520 +
521 + equalsString = equalsString + MethodsGenerator.getEqualsMethodOpen(className) + UtilConstants.NEW_LINE
522 + + MethodsGenerator.getEqualsMethod(attr);
523 + equalsString = MethodsGenerator.getEqualsMethodClose(equalsString) + UtilConstants.NEW_LINE;
524 +
525 + toString = toString + MethodsGenerator.getToStringMethodOpen()
526 + + MethodsGenerator.getToStringMethod(attr) + UtilConstants.NEW_LINE
527 + + MethodsGenerator.getToStringMethodClose()
528 + + UtilConstants.NEW_LINE;
529 + typeDefString = typeDefString + hashCodeString + equalsString + toString;
530 + handle.setTempData(typeDefString, TempDataStoreTypes.TYPE_DEF, className,
531 + path);
357 } 532 }
358 } catch (IOException e) { 533 } catch (IOException e) {
359 log.info("Failed to set data for " + attr.getAttributeName() + " in temp data files."); 534 log.info("Failed to set data for " + attr.getAttributeName() + " in temp data files.");
...@@ -368,18 +543,34 @@ public final class JavaFileGenerator { ...@@ -368,18 +543,34 @@ public final class JavaFileGenerator {
368 * @param fileName generated file name 543 * @param fileName generated file name
369 * @param type generated file type 544 * @param type generated file type
370 * @param pkg generated file package 545 * @param pkg generated file package
371 - * @param importsList list of java imports 546 + * @param importsList list of java imports.
372 * @throws IOException when fails to append contents 547 * @throws IOException when fails to append contents
373 */ 548 */
374 private static void appendContents(File file, String fileName, int type, List<String> importsList, 549 private static void appendContents(File file, String fileName, int type, List<String> importsList,
375 String pkg) throws IOException { 550 String pkg) throws IOException {
376 551
552 + if (pkg.contains(UtilConstants.YANG_GEN_DIR)) {
553 + String[] strArray = pkg.split(UtilConstants.YANG_GEN_DIR);
554 + pkg = strArray[1].replace(UtilConstants.SLASH, UtilConstants.PERIOD);
555 + }
556 +
377 if ((type & IMPL_CLASS_MASK) != 0) { 557 if ((type & IMPL_CLASS_MASK) != 0) {
378 558
379 write(file, fileName, type, JavaDocType.IMPL_CLASS); 559 write(file, fileName, type, JavaDocType.IMPL_CLASS);
380 } else if ((type & BUILDER_INTERFACE_MASK) != 0) { 560 } else if ((type & BUILDER_INTERFACE_MASK) != 0) {
381 561
382 write(file, fileName, type, JavaDocType.BUILDER_INTERFACE); 562 write(file, fileName, type, JavaDocType.BUILDER_INTERFACE);
563 + } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) {
564 + insert(file, CopyrightHeader.getCopyrightHeader());
565 + insert(file, "package" + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE);
566 + if (importsList != null) {
567 + insert(file, UtilConstants.NEW_LINE);
568 + for (String imports : importsList) {
569 + insert(file, imports);
570 + }
571 + insert(file, UtilConstants.NEW_LINE);
572 + }
573 + write(file, fileName, type, JavaDocType.IMPL_CLASS);
383 } else { 574 } else {
384 575
385 if ((type & INTERFACE_MASK) != 0) { 576 if ((type & INTERFACE_MASK) != 0) {
...@@ -420,7 +611,7 @@ public final class JavaFileGenerator { ...@@ -420,7 +611,7 @@ public final class JavaFileGenerator {
420 private static void write(File file, String fileName, int genType, JavaDocGen.JavaDocType javaDocType) 611 private static void write(File file, String fileName, int genType, JavaDocGen.JavaDocType javaDocType)
421 throws IOException { 612 throws IOException {
422 613
423 - insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName)); 614 + insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName, false));
424 insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName)); 615 insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName));
425 } 616 }
426 617
...@@ -433,13 +624,27 @@ public final class JavaFileGenerator { ...@@ -433,13 +624,27 @@ public final class JavaFileGenerator {
433 */ 624 */
434 public static void insert(File file, String data) throws IOException { 625 public static void insert(File file, String data) throws IOException {
435 try { 626 try {
436 - FileSystemUtil.insertStringInFile(file, data); 627 + FileSystemUtil.updateFileHandle(file, data, false);
437 } catch (IOException e) { 628 } catch (IOException e) {
438 throw new IOException("Failed to insert in " + file + "file"); 629 throw new IOException("Failed to insert in " + file + "file");
439 } 630 }
440 } 631 }
441 632
442 /** 633 /**
634 + * Closes the files handle for generate files.
635 + *
636 + * @param file generate files
637 + * @throws IOException when failed to close the file handle
638 + */
639 + public static void closeFileHandles(File file) throws IOException {
640 + try {
641 + FileSystemUtil.updateFileHandle(file, null, true);
642 + } catch (IOException e) {
643 + throw new IOException("Failed to close file handle for " + file + "file");
644 + }
645 + }
646 +
647 + /**
443 * Removes temp files. 648 * Removes temp files.
444 * 649 *
445 * @param file file to be removed 650 * @param file file to be removed
...@@ -449,4 +654,14 @@ public final class JavaFileGenerator { ...@@ -449,4 +654,14 @@ public final class JavaFileGenerator {
449 file.delete(); 654 file.delete();
450 } 655 }
451 } 656 }
657 +
658 + /**
659 + * Removes temp files.
660 + *
661 + * @param tempDir temp directory
662 + * @throws IOException when fails to delete the directory
663 + */
664 + public static void cleanTempFiles(File tempDir) throws IOException {
665 + FileUtils.deleteDirectory(tempDir);
666 + }
452 } 667 }
......
...@@ -31,7 +31,6 @@ public final class JavaIdentifierSyntax { ...@@ -31,7 +31,6 @@ public final class JavaIdentifierSyntax {
31 private static final int INDEX_ZERO = 0; 31 private static final int INDEX_ZERO = 0;
32 private static final int INDEX_ONE = 1; 32 private static final int INDEX_ONE = 1;
33 private static final int INDEX_TWO = 2; 33 private static final int INDEX_TWO = 2;
34 - private static final int INDEX_THREE = 3;
35 34
36 /** 35 /**
37 * Default constructor. 36 * Default constructor.
...@@ -100,9 +99,7 @@ public final class JavaIdentifierSyntax { ...@@ -100,9 +99,7 @@ public final class JavaIdentifierSyntax {
100 String[] revisionArr = date.split(UtilConstants.HYPHEN); 99 String[] revisionArr = date.split(UtilConstants.HYPHEN);
101 100
102 String rev = "rev"; 101 String rev = "rev";
103 - String year = revisionArr[INDEX_ZERO]; 102 + rev = rev + revisionArr[INDEX_ZERO];
104 - char[] yearBytes = year.toCharArray();
105 - rev = rev + yearBytes[INDEX_TWO] + yearBytes[INDEX_THREE];
106 103
107 if ((Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS) 104 if ((Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS)
108 && Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) { 105 && Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) {
......
...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import org.onosproject.yangutils.translator.tojava.AttributeInfo; 19 import org.onosproject.yangutils.translator.tojava.AttributeInfo;
20 import org.onosproject.yangutils.utils.UtilConstants; 20 import org.onosproject.yangutils.utils.UtilConstants;
21 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 21 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
22 +import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
22 23
23 /** 24 /**
24 * Generated methods for generated files based on the file type. 25 * Generated methods for generated files based on the file type.
...@@ -32,45 +33,6 @@ public final class MethodsGenerator { ...@@ -32,45 +33,6 @@ public final class MethodsGenerator {
32 } 33 }
33 34
34 /** 35 /**
35 - * Returns the methods strings for builder class.
36 - *
37 - * @param attr attribute info
38 - * @param className java class name
39 - * @return method string for builder class
40 - */
41 - static String parseBuilderMethodString(AttributeInfo attr, String className) {
42 - String attrQuaifiedType = "";
43 - if (attr.getImportInfo().getPkgInfo() != null) {
44 - attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
45 - }
46 - attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
47 -
48 - String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
49 - + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE;
50 - String getterString = getGetterForClass(attr.getAttributeName(), attrQuaifiedType);
51 - String setterString = getSetterForClass(attr.getAttributeName(), attrQuaifiedType, className);
52 - return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString;
53 - }
54 -
55 - /**
56 - * Returns the methods strings for builder class.
57 - *
58 - * @param attr attribute info
59 - * @return method string for builder class
60 - */
61 - static String parseImplMethodString(AttributeInfo attr) {
62 -
63 - String attrQuaifiedType = "";
64 - if (attr.getImportInfo().getPkgInfo() != null) {
65 - attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
66 - }
67 - attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
68 -
69 - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
70 - + UtilConstants.NEW_LINE + getGetterForClass(attr.getAttributeName(), attrQuaifiedType);
71 - }
72 -
73 - /**
74 * Returns the methods strings for builder interface. 36 * Returns the methods strings for builder interface.
75 * 37 *
76 * @param attr attribute info 38 * @param attr attribute info
...@@ -90,7 +52,7 @@ public final class MethodsGenerator { ...@@ -90,7 +52,7 @@ public final class MethodsGenerator {
90 */ 52 */
91 public static String parseBuilderInterfaceBuildMethodString(String name) { 53 public static String parseBuilderInterfaceBuildMethodString(String name) {
92 54
93 - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name) 55 + return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name, false)
94 + getBuildForInterface(name); 56 + getBuildForInterface(name);
95 } 57 }
96 58
...@@ -103,14 +65,17 @@ public final class MethodsGenerator { ...@@ -103,14 +65,17 @@ public final class MethodsGenerator {
103 public static String getGetterString(AttributeInfo attr) { 65 public static String getGetterString(AttributeInfo attr) {
104 66
105 String returnType = ""; 67 String returnType = "";
106 - if (attr.getImportInfo().getPkgInfo() != null) { 68 + boolean isList = attr.isListAttr();
69 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
107 returnType = attr.getImportInfo().getPkgInfo() + "."; 70 returnType = attr.getImportInfo().getPkgInfo() + ".";
108 } 71 }
109 72
110 returnType = returnType + attr.getImportInfo().getClassInfo(); 73 returnType = returnType + attr.getImportInfo().getClassInfo();
74 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
75 +
76 + return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.GETTER, attributeName, isList) +
111 77
112 - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.GETTER, attr.getAttributeName()) 78 + getGetterForInterface(attributeName, returnType, attr.isListAttr())
113 - + getGetterForInterface(attr.getAttributeName(), returnType)
114 + UtilConstants.NEW_LINE; 79 + UtilConstants.NEW_LINE;
115 } 80 }
116 81
...@@ -121,17 +86,20 @@ public final class MethodsGenerator { ...@@ -121,17 +86,20 @@ public final class MethodsGenerator {
121 * @param className java class name 86 * @param className java class name
122 * @return setter string 87 * @return setter string
123 */ 88 */
124 - private static String getSetterString(AttributeInfo attr, String className) { 89 + public static String getSetterString(AttributeInfo attr, String className) {
125 90
126 String attrType = ""; 91 String attrType = "";
127 - if (attr.getImportInfo().getPkgInfo() != null) { 92 + boolean isList = attr.isListAttr();
93 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
128 attrType = attr.getImportInfo().getPkgInfo() + "."; 94 attrType = attr.getImportInfo().getPkgInfo() + ".";
129 } 95 }
130 96
131 attrType = attrType + attr.getImportInfo().getClassInfo(); 97 attrType = attrType + attr.getImportInfo().getClassInfo();
98 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
132 99
133 - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.SETTER, attr.getAttributeName()) 100 + return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.SETTER, attributeName, isList)
134 - + getSetterForInterface(attr.getAttributeName(), attrType, className); 101 + + getSetterForInterface(attributeName, attrType, className, attr.isListAttr())
102 + + UtilConstants.NEW_LINE;
135 } 103 }
136 104
137 /** 105 /**
...@@ -142,21 +110,75 @@ public final class MethodsGenerator { ...@@ -142,21 +110,75 @@ public final class MethodsGenerator {
142 */ 110 */
143 public static String getConstructorString(String name) { 111 public static String getConstructorString(String name) {
144 112
145 - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name) 113 + return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name, false);
146 - + getConstructor(name);
147 } 114 }
148 115
149 /** 116 /**
150 * Returns default constructor method string. 117 * Returns default constructor method string.
151 * 118 *
152 - * @param type generated file type
153 * @param name class name 119 * @param name class name
120 + * @param modifierType modifier type
154 * @return default constructor string 121 * @return default constructor string
155 */ 122 */
156 - public static String getDefaultConstructorString(int type, String name) { 123 + public static String getDefaultConstructorString(String name, String modifierType) {
157 124
158 - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR, name) 125 + return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR, name, false)
159 - + getDefaultConstructor(name + UtilConstants.BUILDER); 126 + + getDefaultConstructor(name, modifierType);
127 + }
128 +
129 + /**
130 + * Returns default constructor method string.
131 + *
132 + * @param attr attribute info
133 + * @param className class name
134 + * @return default constructor string
135 + */
136 + public static String getTypeDefConstructor(AttributeInfo attr, String className) {
137 +
138 + String attrQuaifiedType = "";
139 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
140 + attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
141 + }
142 + attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
143 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
144 +
145 + if (!attr.isListAttr()) {
146 + return getTypeDefConstructorString(attrQuaifiedType, attributeName, className);
147 + }
148 + String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET;
149 + return getTypeDefConstructorString(listAttr, attributeName, className);
150 + }
151 +
152 + /**
153 + * Returns type def's constructor for attribute.
154 + *
155 + * @param type data type
156 + * @param name attribute name
157 + * @param className class name
158 + * @return setter for type def's attribute
159 + */
160 + private static String getTypeDefConstructorString(String type, String name, String className) {
161 +
162 + return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
163 + + className + UtilConstants.OPEN_PARENTHESIS
164 + + type + UtilConstants.SPACE + "value" + UtilConstants.CLOSE_PARENTHESIS
165 + + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
166 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS
167 + + UtilConstants.PERIOD + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE
168 + + "value" + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
169 + + UtilConstants.CLOSE_CURLY_BRACKET;
170 + }
171 +
172 + /**
173 + * Returns check not null string.
174 + *
175 + * @param name attribute name
176 + * @return check not null string
177 + */
178 + public static String getCheckNotNull(String name) {
179 + return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.CHECK_NOT_NULL_STRING
180 + + UtilConstants.OPEN_PARENTHESIS + name + UtilConstants.COMMA + UtilConstants.SPACE + name
181 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE;
160 } 182 }
161 183
162 /** 184 /**
...@@ -174,56 +196,171 @@ public final class MethodsGenerator { ...@@ -174,56 +196,171 @@ public final class MethodsGenerator {
174 /** 196 /**
175 * Returns the getter method strings for class file. 197 * Returns the getter method strings for class file.
176 * 198 *
177 - * @param attrName name of the attribute 199 + * @param attr attribute info
178 - * @param attrType return type of attribute
179 * @return getter method for class 200 * @return getter method for class
180 */ 201 */
181 - private static String getGetterForClass(String attrName, String attrType) { 202 + public static String getGetterForClass(AttributeInfo attr) {
203 +
204 + String attrQuaifiedType = "";
205 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
206 + attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
207 + }
208 + attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
209 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
210 +
211 + if (!attr.isListAttr()) {
212 + return getGetter(attrQuaifiedType, attributeName);
213 + }
214 + String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET;
215 + return getGetter(listAttr, attributeName);
216 + }
217 +
218 + /**
219 + * Returns getter for attribute.
220 + *
221 + * @param type return type
222 + * @param name attribute name
223 + * @return getter for attribute
224 + */
225 + private static String getGetter(String type, String name) {
182 226
183 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE 227 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
184 - + attrType + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX 228 + + type + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX
185 - + JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS 229 + + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS
186 + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET 230 + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
187 + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN 231 + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
188 - + UtilConstants.SPACE + attrName + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE 232 + + UtilConstants.SPACE + name + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
189 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; 233 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
190 } 234 }
191 235
192 /** 236 /**
193 * Returns the setter method strings for class file. 237 * Returns the setter method strings for class file.
194 * 238 *
195 - * @param attrName name of the attribute 239 + * @param attr attribute info
196 - * @param attrType return type of attribute
197 * @param className name of the class 240 * @param className name of the class
198 * @return setter method for class 241 * @return setter method for class
199 */ 242 */
200 - private static String getSetterForClass(String attrName, String attrType, String className) { 243 + public static String getSetterForClass(AttributeInfo attr, String className) {
244 +
245 + String attrQuaifiedType = "";
246 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
247 + attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
248 + }
249 + attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
250 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
251 + if (!attr.isListAttr()) {
252 + return getSetter(className, attributeName, attrQuaifiedType);
253 + }
254 + String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET;
255 + return getSetter(className, attributeName, listAttr);
256 + }
257 +
258 + /**
259 + * Returns setter for attribute.
260 + *
261 + * @param className class name
262 + * @param name attribute name
263 + * @param type return type
264 + * @return setter for attribute
265 + */
266 + private static String getSetter(String className, String name, String type) {
201 267
202 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE 268 return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
203 + className + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX 269 + className + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX
204 - + JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS 270 + + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS
205 - + attrType + UtilConstants.SPACE + attrName + UtilConstants.CLOSE_PARENTHESIS 271 + + type + UtilConstants.SPACE + name + UtilConstants.CLOSE_PARENTHESIS
206 + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE 272 + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
207 + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD 273 + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD
208 - + attrName + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + attrName 274 + + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE
209 - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION 275 + + name + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
210 + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN 276 + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN
211 + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; 277 + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
212 } 278 }
213 279
214 /** 280 /**
281 + * Returns the setter method strings for class file.
282 + *
283 + * @param attr attribute info
284 + * @return setter method for class
285 + */
286 + public static String getSetterForTypeDefClass(AttributeInfo attr) {
287 +
288 + String attrQuaifiedType = "";
289 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
290 + attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
291 + }
292 + attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
293 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
294 +
295 + if (!attr.isListAttr()) {
296 + return getTypeDefSetter(attrQuaifiedType, attributeName);
297 + }
298 + String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET;
299 + return getTypeDefSetter(listAttr, attributeName);
300 + }
301 +
302 + /**
303 + * Returns type def's setter for attribute.
304 + *
305 + * @param type data type
306 + * @param name attribute name
307 + * @return setter for type def's attribute
308 + */
309 + private static String getTypeDefSetter(String type, String name) {
310 +
311 + return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
312 + + UtilConstants.VOID + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX
313 + + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS
314 + + type + UtilConstants.SPACE + "value" + UtilConstants.CLOSE_PARENTHESIS
315 + + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
316 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD
317 + + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE
318 + + "value" + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
319 + + UtilConstants.CLOSE_CURLY_BRACKET;
320 + }
321 +
322 + /**
323 + * Returns override string.
324 + *
325 + * @return override string
326 + */
327 + public static String getOverRideString() {
328 + return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
329 + + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE;
330 + }
331 +
332 + /**
215 * Returns the getter method strings for interface file. 333 * Returns the getter method strings for interface file.
216 * 334 *
217 * @param yangName name of the attribute 335 * @param yangName name of the attribute
218 * @param returnType return type of attribute 336 * @param returnType return type of attribute
337 + * @param isList is list attribute
219 * @return getter method for interface 338 * @return getter method for interface
220 */ 339 */
221 - private static String getGetterForInterface(String yangName, String returnType) { 340 + public static String getGetterForInterface(String yangName, String returnType, boolean isList) {
341 +
342 + if (!isList) {
343 + return getGetterInterfaceString(returnType, yangName);
344 + }
345 + String listAttr = getListString() + returnType + UtilConstants.DIAMOND_CLOSE_BRACKET;
346 + return getGetterInterfaceString(listAttr, yangName);
347 + }
348 +
349 + /**
350 + * Returns getter for attribute in interface.
351 + *
352 + * @param returnType return type
353 + * @param yangName attribute name
354 + * @return getter for interface
355 + */
356 + private static String getGetterInterfaceString(String returnType, String yangName) {
357 +
222 return UtilConstants.FOUR_SPACE_INDENTATION + returnType 358 return UtilConstants.FOUR_SPACE_INDENTATION + returnType
223 + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX 359 + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX
224 + JavaIdentifierSyntax.getCaptialCase(yangName) 360 + JavaIdentifierSyntax.getCaptialCase(yangName)
225 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS 361 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
226 + UtilConstants.SEMI_COLAN; 362 + UtilConstants.SEMI_COLAN;
363 +
227 } 364 }
228 365
229 /** 366 /**
...@@ -232,9 +369,28 @@ public final class MethodsGenerator { ...@@ -232,9 +369,28 @@ public final class MethodsGenerator {
232 * @param attrName name of the attribute 369 * @param attrName name of the attribute
233 * @param attrType return type of attribute 370 * @param attrType return type of attribute
234 * @param className name of the java class being generated 371 * @param className name of the java class being generated
372 + * @param isList is list attribute
235 * @return setter method for interface 373 * @return setter method for interface
236 */ 374 */
237 - private static String getSetterForInterface(String attrName, String attrType, String className) { 375 + public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) {
376 +
377 + if (!isList) {
378 + return getSetterInterfaceString(className, attrName, attrType);
379 + }
380 + String listAttr = getListString() + attrType + UtilConstants.DIAMOND_CLOSE_BRACKET;
381 + return getSetterInterfaceString(className, attrName, listAttr);
382 + }
383 +
384 + /**
385 + * Returns setter string for interface.
386 + *
387 + * @param className class name
388 + * @param attrName attribute name
389 + * @param attrType attribute type
390 + * @return setter string
391 + */
392 + private static String getSetterInterfaceString(String className, String attrName, String attrType) {
393 +
238 return UtilConstants.FOUR_SPACE_INDENTATION + className + UtilConstants.BUILDER 394 return UtilConstants.FOUR_SPACE_INDENTATION + className + UtilConstants.BUILDER
239 + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX 395 + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX
240 + JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS 396 + JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS
...@@ -243,48 +399,47 @@ public final class MethodsGenerator { ...@@ -243,48 +399,47 @@ public final class MethodsGenerator {
243 } 399 }
244 400
245 /** 401 /**
402 + * Returns list string.
403 + *
404 + * @return list string
405 + */
406 + private static String getListString() {
407 + return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET;
408 + }
409 +
410 + /**
246 * Returns the build method strings for interface file. 411 * Returns the build method strings for interface file.
247 * 412 *
248 * @param yangName name of the interface 413 * @param yangName name of the interface
249 * @return build method for interface 414 * @return build method for interface
250 */ 415 */
251 - private static String getBuildForInterface(String yangName) { 416 + public static String getBuildForInterface(String yangName) {
252 417
253 return UtilConstants.FOUR_SPACE_INDENTATION + yangName + UtilConstants.SPACE + UtilConstants.BUILD 418 return UtilConstants.FOUR_SPACE_INDENTATION + yangName + UtilConstants.SPACE + UtilConstants.BUILD
254 - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN; 419 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
420 + + UtilConstants.NEW_LINE;
255 } 421 }
256 422
257 /** 423 /**
258 * Returns the constructor strings for class file. 424 * Returns the constructor strings for class file.
259 * 425 *
260 * @param yangName name of the class 426 * @param yangName name of the class
427 + * @param attr attribute info
261 * @return constructor for class 428 * @return constructor for class
262 */ 429 */
263 - private static String getConstructor(String yangName) { 430 + public static String getConstructor(String yangName, AttributeInfo attr) {
264 - 431 +
265 - String builderAttribute = yangName.substring(0, 1).toLowerCase() + yangName.substring(1); 432 + String builderAttribute = JavaIdentifierSyntax.getLowerCase(yangName);
266 - String constructor = UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE 433 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
267 - + yangName + UtilConstants.IMPL + UtilConstants.OPEN_PARENTHESIS + yangName + UtilConstants.BUILDER 434 + String constructor = UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS
268 - + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT + UtilConstants.CLOSE_PARENTHESIS 435 + + UtilConstants.PERIOD + JavaIdentifierSyntax.getCamelCase(attributeName)
269 - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; 436 + + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute
270 - 437 + + UtilConstants.OBJECT + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
271 - // TODO: need to get the partial constructor from constructor temp file. 438 + + JavaIdentifierSyntax.getCaptialCase(JavaIdentifierSyntax.getCamelCase(attributeName))
272 - // if (getAttrInfo() != null) { 439 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
273 - // for (AttributeInfo attribute : getAttrInfo()) { 440 + + UtilConstants.NEW_LINE;
274 - // attribute.setAttributeName(JavaIdentifierSyntax.getCamelCase(attribute.getAttributeName()));
275 - // constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
276 - // + UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
277 - // + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
278 - // + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
279 - // + JavaIdentifierSyntax.getCaptialCase(attribute.getAttributeName())
280 - // + UtilConstants.OPEN_PARENTHESIS
281 - // + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
282 - // + UtilConstants.NEW_LINE;
283 - // }
284 - // getAttrInfo().clear();
285 - // }
286 441
287 - return constructor + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; 442 + return constructor;
288 } 443 }
289 444
290 /** 445 /**
...@@ -293,10 +448,10 @@ public final class MethodsGenerator { ...@@ -293,10 +448,10 @@ public final class MethodsGenerator {
293 * @param yangName class name 448 * @param yangName class name
294 * @return build method string for class 449 * @return build method string for class
295 */ 450 */
296 - private static String getBuild(String yangName) { 451 + public static String getBuild(String yangName) {
297 452
298 - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + yangName 453 + return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
299 - + UtilConstants.SPACE + UtilConstants.BUILD + UtilConstants.OPEN_PARENTHESIS 454 + + yangName + UtilConstants.SPACE + UtilConstants.BUILD + UtilConstants.OPEN_PARENTHESIS
300 + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET 455 + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
301 + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN 456 + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
302 + UtilConstants.SPACE + UtilConstants.NEW + UtilConstants.SPACE + yangName + UtilConstants.IMPL 457 + UtilConstants.SPACE + UtilConstants.NEW + UtilConstants.SPACE + yangName + UtilConstants.IMPL
...@@ -309,14 +464,205 @@ public final class MethodsGenerator { ...@@ -309,14 +464,205 @@ public final class MethodsGenerator {
309 * Returns the Default constructor strings for class file. 464 * Returns the Default constructor strings for class file.
310 * 465 *
311 * @param name name of the class 466 * @param name name of the class
467 + * @param modifierType modifier type for default constructor
312 * @return Default constructor for class 468 * @return Default constructor for class
313 */ 469 */
314 - private static String getDefaultConstructor(String name) { 470 + private static String getDefaultConstructor(String name, String modifierType) {
315 471
316 - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + name 472 + return UtilConstants.FOUR_SPACE_INDENTATION + modifierType + UtilConstants.SPACE + name
317 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE 473 + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
318 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION 474 + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
319 + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; 475 + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE;
320 } 476 }
321 477
478 + /**
479 + * Returns to string method open strings.
480 + *
481 + * @return to string method open string
482 + */
483 + public static String getToStringMethodOpen() {
484 +
485 + return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
486 + + UtilConstants.STRING + UtilConstants.SPACE + "to" + UtilConstants.STRING
487 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
488 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
489 + + UtilConstants.RETURN + " MoreObjects.toStringHelper(getClass())" + UtilConstants.NEW_LINE;
490 + }
491 +
492 + /**
493 + * Returns to string methods close string.
494 + *
495 + * @return to string method close string
496 + */
497 + public static String getToStringMethodClose() {
498 + return UtilConstants.TWELVE_SPACE_INDENTATION + ".to" + UtilConstants.STRING
499 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
500 + + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
501 + + UtilConstants.CLOSE_CURLY_BRACKET;
502 + }
503 +
504 + /**
505 + * To string method for class.
506 + *
507 + * @param attr attribute info
508 + * @return to string method
509 + */
510 + public static String getToStringMethod(AttributeInfo attr) {
511 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
512 + return UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.PERIOD + UtilConstants.ADD_STRING
513 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.QUOTES
514 + + attributeName + UtilConstants.QUOTES + UtilConstants.COMMA + UtilConstants.SPACE + attributeName
515 + + UtilConstants.CLOSE_PARENTHESIS;
516 +
517 + }
518 +
519 + /**
520 + * Returns to hash code method open strings.
521 + *
522 + * @return to hash code method open string
523 + */
524 + public static String getHashCodeMethodOpen() {
525 +
526 + return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
527 + + UtilConstants.INT + UtilConstants.SPACE + UtilConstants.HASH_CODE_STRING
528 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
529 + + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
530 + + UtilConstants.RETURN + " Objects.hash" + UtilConstants.OPEN_PARENTHESIS;
531 + }
532 +
533 + /**
534 + * Returns to hash code methods close string.
535 + *
536 + * @param hashcodeString hash code string
537 + * @return to hash code method close string
538 + */
539 + public static String getHashCodeMethodClose(String hashcodeString) {
540 + hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.COMMA);
541 + hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.SPACE);
542 + hashcodeString = YangIoUtils.partString(hashcodeString);
543 + return hashcodeString + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
544 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
545 + }
546 +
547 + /**
548 + * Hash code method for class.
549 + *
550 + * @param attr attribute info
551 + * @return hash code method
552 + */
553 + public static String getHashCodeMethod(AttributeInfo attr) {
554 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
555 + return attributeName
556 + + UtilConstants.COMMA + UtilConstants.SPACE;
557 +
558 + }
559 +
560 + /**
561 + * Returns to equals method open strings.
562 + *
563 + * @param className class name
564 + * @return to equals method open string
565 + */
566 + public static String getEqualsMethodOpen(String className) {
567 +
568 + return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
569 + + UtilConstants.BOOLEAN + UtilConstants.SPACE + UtilConstants.EQUALS_STRING
570 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.OBJECT_STRING + UtilConstants.SPACE + "obj"
571 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
572 + + UtilConstants.NEW_LINE + getEqualsMethodsCommonIfCondition()
573 + + getEqualsMethodsSpecificIfCondition(className);
574 + }
575 +
576 + /**
577 + * Returns equal methods if condition string.
578 + *
579 + * @return if condition string
580 + */
581 + private static String getEqualsMethodsCommonIfCondition() {
582 + return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.IF + UtilConstants.SPACE
583 + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.THIS
584 + + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.EQUAL + UtilConstants.SPACE + "obj"
585 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
586 + + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.RETURN
587 + + UtilConstants.SPACE + UtilConstants.TRUE + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
588 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE;
589 + }
590 +
591 + /**
592 + * Returns if condition for specific class object in equals method.
593 + *
594 + * @param className class name
595 + * @return if condition string
596 + */
597 + private static String getEqualsMethodsSpecificIfCondition(String className) {
598 + return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.IF + UtilConstants.SPACE
599 + + UtilConstants.OPEN_PARENTHESIS + "obj" + UtilConstants.INSTANCE_OF + className
600 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
601 + + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + className + UtilConstants.SPACE
602 + + "other " + UtilConstants.EQUAL + UtilConstants.SPACE + UtilConstants.OPEN_PARENTHESIS + className
603 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + "obj" + UtilConstants.SEMI_COLAN
604 + + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.RETURN
605 + + UtilConstants.NEW_LINE;
606 + }
607 +
608 + /**
609 + * Returns to equals methods close string.
610 + *
611 + * @param equalMethodString equal method string
612 + * @return to equals method close string
613 + */
614 + public static String getEqualsMethodClose(String equalMethodString) {
615 + equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.AND);
616 + equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.AND);
617 + equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.SPACE);
618 + equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.NEW_LINE) + UtilConstants.SEMI_COLAN
619 + + UtilConstants.NEW_LINE;
620 + return equalMethodString + UtilConstants.EIGHT_SPACE_INDENTATION
621 + + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE
622 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE
623 + + UtilConstants.FALSE + UtilConstants.SEMI_COLAN
624 + + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
625 + + UtilConstants.CLOSE_CURLY_BRACKET;
626 + }
627 +
628 + /**
629 + * Equals method for class.
630 + *
631 + * @param attr attribute info
632 + * @return equals method
633 + */
634 + public static String getEqualsMethod(AttributeInfo attr) {
635 + String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName());
636 + return UtilConstants.SIXTEEN_SPACE_INDENTATION + UtilConstants.SPACE + UtilConstants.OBJECT_STRING + "s"
637 + + UtilConstants.PERIOD + UtilConstants.EQUALS_STRING + UtilConstants.OPEN_PARENTHESIS + attributeName
638 + + UtilConstants.COMMA + UtilConstants.SPACE + "other." + attributeName + UtilConstants.CLOSE_PARENTHESIS
639 + + UtilConstants.SPACE + UtilConstants.AND + UtilConstants.AND;
640 +
641 + }
642 +
643 + /**
644 + * Returns of method string for class.
645 + *
646 + * @param name class name
647 + * @param attr attribute info
648 + * @return of method string
649 + */
650 + public static String getOfMethod(String name, AttributeInfo attr) {
651 +
652 + String attrQuaifiedType = "";
653 + if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
654 + attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
655 + }
656 + attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
657 +
658 + return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.STATIC
659 + + UtilConstants.SPACE + name + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.OPEN_PARENTHESIS
660 + + attrQuaifiedType + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.CLOSE_PARENTHESIS
661 + + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
662 + + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.NEW
663 + + UtilConstants.SPACE + name + UtilConstants.OPEN_PARENTHESIS + UtilConstants.VALUE
664 + + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
665 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE;
666 + }
667 +
322 } 668 }
......
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.utils;
18 +
19 +/**
20 + * Data Store types.
21 + */
22 +public enum TempDataStoreTypes {
23 +
24 + /**
25 + * Getter methods for interfaces.
26 + */
27 + GETTER_METHODS,
28 +
29 + /**
30 + * Getter methods impl for classes.
31 + */
32 + GETTER_METHODS_IMPL,
33 +
34 + /**
35 + * Setter methods for interfaces.
36 + */
37 + SETTER_METHODS,
38 +
39 + /**
40 + * Setter methods impl for classes.
41 + */
42 + SETTER_METHODS_IMPL,
43 +
44 + /**
45 + * Constructor for impl class.
46 + */
47 + CONSTRUCTOR,
48 +
49 + /**
50 + * Attributes.
51 + */
52 + ATTRIBUTE,
53 +
54 + /**
55 + * TypeDef.
56 + */
57 + TYPE_DEF,
58 +
59 + /**
60 + * ToString method.
61 + */
62 + TO_STRING,
63 +
64 + /**
65 + * HashCode method.
66 + */
67 + HASH_CODE,
68 +
69 + /**
70 + * Equals method.
71 + */
72 + EQUALS
73 +}
...@@ -256,6 +256,7 @@ public final class UtilConstants { ...@@ -256,6 +256,7 @@ public final class UtilConstants {
256 public static final String BUILD = "build"; 256 public static final String BUILD = "build";
257 public static final String OBJECT = "Object"; 257 public static final String OBJECT = "Object";
258 public static final String OVERRIDE = "@Override"; 258 public static final String OVERRIDE = "@Override";
259 + public static final String CHILDREN = "'s children";
259 260
260 /** 261 /**
261 * For collections. 262 * For collections.
......
...@@ -104,7 +104,7 @@ public final class FileSystemUtil { ...@@ -104,7 +104,7 @@ public final class FileSystemUtil {
104 */ 104 */
105 public static void appendFileContents(File toAppend, File srcFile) throws IOException { 105 public static void appendFileContents(File toAppend, File srcFile) throws IOException {
106 106
107 - insertStringInFile(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString())); 107 + updateFileHandle(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString()), false);
108 return; 108 return;
109 } 109 }
110 110
...@@ -133,18 +133,23 @@ public final class FileSystemUtil { ...@@ -133,18 +133,23 @@ public final class FileSystemUtil {
133 } 133 }
134 134
135 /** 135 /**
136 - * Insert content to the generated file. 136 + * Update the generated file handle.
137 * 137 *
138 * @param inputFile input file 138 * @param inputFile input file
139 * @param contentTobeAdded content to be appended to the file 139 * @param contentTobeAdded content to be appended to the file
140 + * @param isClose when close of file is called.
140 * @throws IOException when fails to append content to the file 141 * @throws IOException when fails to append content to the file
141 */ 142 */
142 - public static void insertStringInFile(File inputFile, String contentTobeAdded) throws IOException { 143 + public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException {
143 FileWriter fileWriter = new FileWriter(inputFile, true); 144 FileWriter fileWriter = new FileWriter(inputFile, true);
144 PrintWriter outputPrintWriter = new PrintWriter(fileWriter); 145 PrintWriter outputPrintWriter = new PrintWriter(fileWriter);
146 + if (!isClose) {
145 outputPrintWriter.write(contentTobeAdded); 147 outputPrintWriter.write(contentTobeAdded);
146 outputPrintWriter.flush(); 148 outputPrintWriter.flush();
147 outputPrintWriter.close(); 149 outputPrintWriter.close();
148 - 150 + } else {
151 + fileWriter.flush();
152 + fileWriter.close();
153 + }
149 } 154 }
150 } 155 }
......
...@@ -71,6 +71,21 @@ public final class JavaDocGen { ...@@ -71,6 +71,21 @@ public final class JavaDocGen {
71 SETTER, 71 SETTER,
72 72
73 /** 73 /**
74 + * For type def's setters.
75 + */
76 + TYPE_DEF_SETTER,
77 +
78 + /**
79 + * For type def's constructor.
80 + */
81 + TYPE_DEF_CONSTRUCTOR,
82 +
83 + /**
84 + * For of method.
85 + */
86 + OF,
87 +
88 + /**
74 * For default constructor. 89 * For default constructor.
75 */ 90 */
76 DEFAULT_CONSTRUCTOR, 91 DEFAULT_CONSTRUCTOR,
...@@ -91,10 +106,11 @@ public final class JavaDocGen { ...@@ -91,10 +106,11 @@ public final class JavaDocGen {
91 * 106 *
92 * @param type java doc type 107 * @param type java doc type
93 * @param name name of the YangNode 108 * @param name name of the YangNode
94 - * @return javadocs 109 + * @param isList is list attribute
110 + * @return javadocs.
95 */ 111 */
96 - public static String getJavaDoc(JavaDocType type, String name) { 112 + public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
97 - name = JavaIdentifierSyntax.getCamelCase(name); 113 + name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name));
98 String javaDoc = ""; 114 String javaDoc = "";
99 if (type.equals(JavaDocType.IMPL_CLASS)) { 115 if (type.equals(JavaDocType.IMPL_CLASS)) {
100 javaDoc = generateForImplClass(name); 116 javaDoc = generateForImplClass(name);
...@@ -107,9 +123,15 @@ public final class JavaDocGen { ...@@ -107,9 +123,15 @@ public final class JavaDocGen {
107 } else if (type.equals(JavaDocType.PACKAGE_INFO)) { 123 } else if (type.equals(JavaDocType.PACKAGE_INFO)) {
108 javaDoc = generateForPackage(name); 124 javaDoc = generateForPackage(name);
109 } else if (type.equals(JavaDocType.GETTER)) { 125 } else if (type.equals(JavaDocType.GETTER)) {
110 - javaDoc = generateForGetters(name); 126 + javaDoc = generateForGetters(name, isList);
127 + } else if (type.equals(JavaDocType.TYPE_DEF_SETTER)) {
128 + javaDoc = generateForTypeDefSetter(name);
129 + } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) {
130 + javaDoc = generateForTypeDefConstructor(name);
111 } else if (type.equals(JavaDocType.SETTER)) { 131 } else if (type.equals(JavaDocType.SETTER)) {
112 - javaDoc = generateForSetters(name); 132 + javaDoc = generateForSetters(name, isList);
133 + } else if (type.equals(JavaDocType.OF)) {
134 + javaDoc = generateForOf(name);
113 } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { 135 } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
114 javaDoc = generateForDefaultConstructors(); 136 javaDoc = generateForDefaultConstructors();
115 } else if (type.equals(JavaDocType.BUILD)) { 137 } else if (type.equals(JavaDocType.BUILD)) {
...@@ -124,32 +146,96 @@ public final class JavaDocGen { ...@@ -124,32 +146,96 @@ public final class JavaDocGen {
124 * Generate javaDocs for getter method. 146 * Generate javaDocs for getter method.
125 * 147 *
126 * @param attribute attribute 148 * @param attribute attribute
149 + * @param isList is list attribute
127 * @return javaDocs 150 * @return javaDocs
128 */ 151 */
129 - private static String generateForGetters(String attribute) { 152 + private static String generateForGetters(String attribute, boolean isList) {
130 - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE 153 + String getter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
154 + + UtilConstants.JAVA_DOC_FIRST_LINE
131 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute 155 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute
132 + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION 156 + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
133 - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN 157 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN;
134 - + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION 158 + if (isList) {
159 + attribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE
160 + + attribute;
161 + }
162 +
163 + getter = getter + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
135 + UtilConstants.JAVA_DOC_END_LINE; 164 + UtilConstants.JAVA_DOC_END_LINE;
165 + return getter;
136 } 166 }
137 167
138 /** 168 /**
139 * Generates javaDocs for setter method. 169 * Generates javaDocs for setter method.
140 * 170 *
141 * @param attribute attribute 171 * @param attribute attribute
172 + * @param isList is list attribute
142 * @return javaDocs 173 * @return javaDocs
143 */ 174 */
144 - private static String generateForSetters(String attribute) { 175 + private static String generateForSetters(String attribute, boolean isList) {
145 - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE 176 + String setter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
177 + + UtilConstants.JAVA_DOC_FIRST_LINE
146 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute 178 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute
147 + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION 179 + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
148 + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM 180 + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
149 - + attribute + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE 181 + + attribute + UtilConstants.SPACE;
182 + if (isList) {
183 + attribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE
184 + + attribute;
185 + }
186 +
187 + setter = setter + attribute + UtilConstants.NEW_LINE
150 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT 188 + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT
151 + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION 189 + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
152 + UtilConstants.JAVA_DOC_END_LINE; 190 + UtilConstants.JAVA_DOC_END_LINE;
191 + return setter;
192 + }
193 +
194 + /**
195 + * Generates javaDocs for of method.
196 + *
197 + * @param attribute attribute
198 + * @return javaDocs
199 + */
200 + private static String generateForOf(String attribute) {
201 + return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
202 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_OF + attribute
203 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
204 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
205 + + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
206 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.OBJECT
207 + + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
208 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE;
209 + }
210 +
211 + /**
212 + * Generates javaDocs for typedef setter method.
213 + *
214 + * @param attribute attribute
215 + * @return javaDocs
216 + */
217 + private static String generateForTypeDefSetter(String attribute) {
218 + return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
219 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS_COMMON + attribute
220 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
221 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
222 + + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
223 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
224 + }
225 +
226 + /**
227 + * Generates javaDocs for typedef constructor.
228 + *
229 + * @param attribute attribute
230 + * @return javaDocs
231 + */
232 + private static String generateForTypeDefConstructor(String attribute) {
233 + return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
234 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_CONSTRUCTOR + attribute
235 + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
236 + + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
237 + + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE
238 + + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
153 } 239 }
154 240
155 /** 241 /**
...@@ -170,8 +256,8 @@ public final class JavaDocGen { ...@@ -170,8 +256,8 @@ public final class JavaDocGen {
170 * @return javaDocs 256 * @return javaDocs
171 */ 257 */
172 private static String generateForBuilderClass(String className) { 258 private static String generateForBuilderClass(String className) {
173 - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC + className 259 + return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC
174 - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; 260 + + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
175 } 261 }
176 262
177 /** 263 /**
...@@ -181,8 +267,8 @@ public final class JavaDocGen { ...@@ -181,8 +267,8 @@ public final class JavaDocGen {
181 * @return javaDocs 267 * @return javaDocs
182 */ 268 */
183 private static String generateForInterface(String interfaceName) { 269 private static String generateForInterface(String interfaceName) {
184 - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC + interfaceName 270 + return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC
185 - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; 271 + + interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
186 } 272 }
187 273
188 /** 274 /**
......
...@@ -38,7 +38,7 @@ public final class YangFileScanner { ...@@ -38,7 +38,7 @@ public final class YangFileScanner {
38 * 38 *
39 * @param root specified directory 39 * @param root specified directory
40 * @return list of java files 40 * @return list of java files
41 - * @throws NullPointerException when no files are there 41 + * @throws NullPointerException when no files are there.
42 * @throws IOException when files get deleted while performing the 42 * @throws IOException when files get deleted while performing the
43 * operations 43 * operations
44 */ 44 */
...@@ -67,7 +67,6 @@ public final class YangFileScanner { ...@@ -67,7 +67,6 @@ public final class YangFileScanner {
67 * @return list of required files 67 * @return list of required files
68 * @throws IOException when files get deleted while performing the 68 * @throws IOException when files get deleted while performing the
69 * operations 69 * operations
70 - * @throws NullPointerException null pointer access
71 */ 70 */
72 public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { 71 public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException {
73 List<String> store = new LinkedList<>(); 72 List<String> store = new LinkedList<>();
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.yangutils.utils.io.impl; 17 package org.onosproject.yangutils.utils.io.impl;
18 18
19 +import static org.slf4j.LoggerFactory.getLogger;
20 +
19 import java.io.BufferedWriter; 21 import java.io.BufferedWriter;
20 import java.io.File; 22 import java.io.File;
21 import java.io.FileWriter; 23 import java.io.FileWriter;
...@@ -29,8 +31,6 @@ import org.onosproject.yangutils.utils.UtilConstants; ...@@ -29,8 +31,6 @@ import org.onosproject.yangutils.utils.UtilConstants;
29 import org.slf4j.Logger; 31 import org.slf4j.Logger;
30 import org.sonatype.plexus.build.incremental.BuildContext; 32 import org.sonatype.plexus.build.incremental.BuildContext;
31 33
32 -import static org.slf4j.LoggerFactory.getLogger;
33 -
34 /** 34 /**
35 * Provides common utility functionalities for code generation. 35 * Provides common utility functionalities for code generation.
36 */ 36 */
...@@ -80,7 +80,7 @@ public final class YangIoUtils { ...@@ -80,7 +80,7 @@ public final class YangIoUtils {
80 fileWriter = new FileWriter(packageInfo); 80 fileWriter = new FileWriter(packageInfo);
81 bufferedWriter = new BufferedWriter(fileWriter); 81 bufferedWriter = new BufferedWriter(fileWriter);
82 bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); 82 bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
83 - bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo)); 83 + bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo, false));
84 bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN); 84 bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN);
85 bufferedWriter.close(); 85 bufferedWriter.close();
86 } catch (IOException e) { 86 } catch (IOException e) {
...@@ -127,4 +127,38 @@ public final class YangIoUtils { ...@@ -127,4 +127,38 @@ public final class YangIoUtils {
127 log.info("Source directory added to compilation root: " + source); 127 log.info("Source directory added to compilation root: " + source);
128 } 128 }
129 129
130 + /**
131 + * Removes extra char from the string.
132 + *
133 + * @param valueString string to be trimmed
134 + * @param removealStirng extra chars
135 + * @return new string
136 + */
137 + public static String trimAtLast(String valueString, String removealStirng) {
138 + StringBuilder stringBuilder = new StringBuilder(valueString);
139 + int index = valueString.lastIndexOf(removealStirng);
140 + stringBuilder.deleteCharAt(index);
141 + return stringBuilder.toString();
142 + }
143 +
144 + /**
145 + * Returns new parted string.
146 + *
147 + * @param partString string to be parted
148 + * @return parted string
149 + */
150 + public static String partString(String partString) {
151 + String[] strArray = partString.split(UtilConstants.COMMA);
152 + String newString = "";
153 + for (int i = 0; i < strArray.length; i++) {
154 + if (i % 4 != 0) {
155 + newString = newString + strArray[i] + UtilConstants.COMMA;
156 + } else {
157 + newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + strArray[i]
158 + + UtilConstants.COMMA;
159 + }
160 + }
161 + return trimAtLast(newString, UtilConstants.COMMA);
162 + }
163 +
130 } 164 }
......
...@@ -20,6 +20,10 @@ import java.io.File; ...@@ -20,6 +20,10 @@ import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 21
22 import org.junit.Test; 22 import org.junit.Test;
23 +
24 +import static org.hamcrest.MatcherAssert.assertThat;
25 +import static org.hamcrest.core.Is.is;
26 +
23 import org.onosproject.yangutils.datamodel.YangDataTypes; 27 import org.onosproject.yangutils.datamodel.YangDataTypes;
24 import org.onosproject.yangutils.datamodel.YangType; 28 import org.onosproject.yangutils.datamodel.YangType;
25 import org.onosproject.yangutils.translator.CachedFileHandle; 29 import org.onosproject.yangutils.translator.CachedFileHandle;
...@@ -33,7 +37,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; ...@@ -33,7 +37,7 @@ import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
33 */ 37 */
34 public class CachedJavaFileHandleTest { 38 public class CachedJavaFileHandleTest {
35 39
36 - private static final String DIR_PKG = "target/unit/cachedfile/"; 40 + private static final String DIR_PKG = "target/unit/cachedfile/yangmodel/";
37 private static final String PKG = "org.onosproject.unittest"; 41 private static final String PKG = "org.onosproject.unittest";
38 private static final String CHILD_PKG = "target/unit/cachedfile/child"; 42 private static final String CHILD_PKG = "target/unit/cachedfile/child";
39 private static final String YANG_NAME = "Test1"; 43 private static final String YANG_NAME = "Test1";
...@@ -42,7 +46,7 @@ public class CachedJavaFileHandleTest { ...@@ -42,7 +46,7 @@ public class CachedJavaFileHandleTest {
42 /** 46 /**
43 * Unit test case for add attribute info. 47 * Unit test case for add attribute info.
44 * 48 *
45 - * @throws IOException when fails to add an attribute. 49 + * @throws IOException when fails to add an attribute
46 */ 50 */
47 @Test 51 @Test
48 public void testForAddAttributeInfo() throws IOException { 52 public void testForAddAttributeInfo() throws IOException {
...@@ -55,39 +59,23 @@ public class CachedJavaFileHandleTest { ...@@ -55,39 +59,23 @@ public class CachedJavaFileHandleTest {
55 /** 59 /**
56 * Unit test case for close of cached files. 60 * Unit test case for close of cached files.
57 * 61 *
58 - * @throws IOException when fails to generate files. 62 + * @throws IOException when fails to generate files
59 */ 63 */
60 @Test 64 @Test
61 public void testForClose() throws IOException { 65 public void testForClose() throws IOException {
62 66
63 - // TODO: update to new framework. 67 + CopyrightHeader.parseCopyrightHeader();
64 - // CopyrightHeader.parseCopyrightHeader();
65 - //
66 - // AttributeInfo attr = getAttr();
67 - // attr.setListAttr(false);
68 - // CachedFileHandle handle = getFileHandle();
69 - // handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
70 - // handle.close();
71 - //
72 - // assertThat(true, is(getStubDir().exists()));
73 - // assertThat(true, is(getStubPkgInfo().exists()));
74 - // assertThat(true, is(getStubInterfaceFile().exists()));
75 - // assertThat(true, is(getStubBuilderFile().exists()));
76 - }
77 -
78 - /**
79 - * Unit test case for setting child's package.
80 - *
81 - * @throws IOException when fails to add child's package
82 - */
83 - @Test
84 - public void testForSetChildsPackage() throws IOException {
85 68
86 AttributeInfo attr = getAttr(); 69 AttributeInfo attr = getAttr();
87 attr.setListAttr(false); 70 attr.setListAttr(false);
88 CachedFileHandle handle = getFileHandle(); 71 CachedFileHandle handle = getFileHandle();
89 handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr()); 72 handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
73 + handle.close();
90 74
75 + assertThat(true, is(getStubDir().exists()));
76 + assertThat(true, is(getStubPkgInfo().exists()));
77 + assertThat(true, is(getStubInterfaceFile().exists()));
78 + assertThat(true, is(getStubBuilderFile().exists()));
91 } 79 }
92 80
93 /** 81 /**
...@@ -113,14 +101,14 @@ public class CachedJavaFileHandleTest { ...@@ -113,14 +101,14 @@ public class CachedJavaFileHandleTest {
113 /** 101 /**
114 * Returns cached java file handle. 102 * Returns cached java file handle.
115 * 103 *
116 - * @return java file handle. 104 + * @return java file handle
117 */ 105 */
118 private CachedFileHandle getFileHandle() throws IOException { 106 private CachedFileHandle getFileHandle() throws IOException {
119 CopyrightHeader.parseCopyrightHeader(); 107 CopyrightHeader.parseCopyrightHeader();
120 FileSystemUtil.createPackage(DIR_PKG + File.separator + PKG, YANG_NAME); 108 FileSystemUtil.createPackage(DIR_PKG + File.separator + PKG, YANG_NAME);
121 CachedFileHandle fileHandle = FileSystemUtil.createSourceFiles(PKG, YANG_NAME, GEN_TYPE); 109 CachedFileHandle fileHandle = FileSystemUtil.createSourceFiles(PKG, YANG_NAME, GEN_TYPE);
122 - fileHandle.setRelativeFilePath(DIR_PKG + PKG.replace(".", "/")); 110 + fileHandle.setRelativeFilePath(PKG.replace(".", "/"));
123 - 111 + fileHandle.setCodeGenFilePath(DIR_PKG);
124 return fileHandle; 112 return fileHandle;
125 } 113 }
126 114
......
...@@ -16,17 +16,16 @@ ...@@ -16,17 +16,16 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 -import java.lang.reflect.Constructor;
20 -import java.lang.reflect.InvocationTargetException;
21 -
22 import org.junit.Test; 19 import org.junit.Test;
23 import org.onosproject.yangutils.translator.GeneratedFileType; 20 import org.onosproject.yangutils.translator.GeneratedFileType;
24 import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; 21 import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
25 import org.onosproject.yangutils.translator.tojava.TraversalType; 22 import org.onosproject.yangutils.translator.tojava.TraversalType;
26 import org.onosproject.yangutils.utils.UtilConstants; 23 import org.onosproject.yangutils.utils.UtilConstants;
27 24
28 -import static org.hamcrest.core.Is.is; 25 +import java.lang.reflect.Constructor;
26 +import java.lang.reflect.InvocationTargetException;
29 import static org.junit.Assert.assertNotNull; 27 import static org.junit.Assert.assertNotNull;
28 +import static org.hamcrest.core.Is.is;
30 import static org.junit.Assert.assertThat; 29 import static org.junit.Assert.assertThat;
31 30
32 /** 31 /**
...@@ -40,18 +39,14 @@ public final class ClassDefinitionGeneratorTest { ...@@ -40,18 +39,14 @@ public final class ClassDefinitionGeneratorTest {
40 * @throws SecurityException if any security violation is observed 39 * @throws SecurityException if any security violation is observed
41 * @throws NoSuchMethodException if when the method is not found 40 * @throws NoSuchMethodException if when the method is not found
42 * @throws IllegalArgumentException if there is illegal argument found 41 * @throws IllegalArgumentException if there is illegal argument found
43 - * @throws InstantiationException if instantiation is provoked for the 42 + * @throws InstantiationException if instantiation is provoked for the private constructor
44 - * private constructor 43 + * @throws IllegalAccessException if instance is provoked or a method is provoked
45 - * @throws IllegalAccessException if instance is provoked or a method is 44 + * @throws InvocationTargetException when an exception occurs by the method or constructor
46 - * provoked
47 - * @throws InvocationTargetException when an exception occurs by the method
48 - * or constructor
49 */ 45 */
50 @Test 46 @Test
51 - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, 47 + public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
52 - IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { 48 + InstantiationException, IllegalAccessException, InvocationTargetException {
53 - Class<?>[] classesToConstruct = { 49 + Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
54 - ClassDefinitionGenerator.class };
55 for (Class<?> clazz : classesToConstruct) { 50 for (Class<?> clazz : classesToConstruct) {
56 Constructor<?> constructor = clazz.getDeclaredConstructor(); 51 Constructor<?> constructor = clazz.getDeclaredConstructor();
57 constructor.setAccessible(true); 52 constructor.setAccessible(true);
...@@ -105,14 +100,14 @@ public final class ClassDefinitionGeneratorTest { ...@@ -105,14 +100,14 @@ public final class ClassDefinitionGeneratorTest {
105 } 100 }
106 101
107 /** 102 /**
108 - * Unit test for invalid generated type. 103 + * Unit test for typedef generated type.
109 */ 104 */
110 @Test 105 @Test
111 - public void generateInvalidDefinitionTest() { 106 + public void generateTypeDefTest() {
112 107
113 - // String invalidDefinition = ClassDefinitionGenerator 108 + String typeDef = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.GENERATE_TYPEDEF_CLASS,
114 - // .generateClassDefinition(GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER, "invalid"); 109 + "invalid");
115 - // assertThat(true, is(invalidDefinition == null)); 110 + assertThat(true, is(typeDef.contains(UtilConstants.CLASS)));
116 } 111 }
117 112
118 /** 113 /**
...@@ -123,5 +118,6 @@ public final class ClassDefinitionGeneratorTest { ...@@ -123,5 +118,6 @@ public final class ClassDefinitionGeneratorTest {
123 118
124 TraversalType.valueOf(TraversalType.CHILD.toString()); 119 TraversalType.valueOf(TraversalType.CHILD.toString());
125 GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString()); 120 GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString());
121 + TempDataStoreTypes.valueOf(TempDataStoreTypes.CONSTRUCTOR.toString());
126 } 122 }
127 } 123 }
......
...@@ -25,8 +25,12 @@ import org.onosproject.yangutils.translator.tojava.ImportInfo; ...@@ -25,8 +25,12 @@ import org.onosproject.yangutils.translator.tojava.ImportInfo;
25 import org.onosproject.yangutils.utils.UtilConstants; 25 import org.onosproject.yangutils.utils.UtilConstants;
26 26
27 import static org.hamcrest.MatcherAssert.assertThat; 27 import static org.hamcrest.MatcherAssert.assertThat;
28 +import static org.junit.Assert.assertNotNull;
28 import static org.hamcrest.core.Is.is; 29 import static org.hamcrest.core.Is.is;
29 30
31 +import java.lang.reflect.Constructor;
32 +import java.lang.reflect.InvocationTargetException;
33 +
30 /** 34 /**
31 * Unit test cases for java code snippet generator. 35 * Unit test cases for java code snippet generator.
32 */ 36 */
...@@ -40,6 +44,27 @@ public class JavaCodeSnippetGenTest { ...@@ -40,6 +44,27 @@ public class JavaCodeSnippetGenTest {
40 private static final String STRING = "String"; 44 private static final String STRING = "String";
41 45
42 /** 46 /**
47 + * Unit test for private constructor.
48 + *
49 + * @throws SecurityException if any security violation is observed
50 + * @throws NoSuchMethodException if when the method is not found
51 + * @throws IllegalArgumentException if there is illegal argument found
52 + * @throws InstantiationException if instantiation is provoked for the private constructor
53 + * @throws IllegalAccessException if instance is provoked or a method is provoked
54 + * @throws InvocationTargetException when an exception occurs by the method or constructor
55 + */
56 + @Test
57 + public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
58 + InstantiationException, IllegalAccessException, InvocationTargetException {
59 + Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
60 + for (Class<?> clazz : classesToConstruct) {
61 + Constructor<?> constructor = clazz.getDeclaredConstructor();
62 + constructor.setAccessible(true);
63 + assertNotNull(constructor.newInstance());
64 + }
65 + }
66 +
67 + /**
43 * Unit test case for import text. 68 * Unit test case for import text.
44 */ 69 */
45 @Test 70 @Test
...@@ -64,27 +89,6 @@ public class JavaCodeSnippetGenTest { ...@@ -64,27 +89,6 @@ public class JavaCodeSnippetGenTest {
64 is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE 89 is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE
65 + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET 90 + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
66 + UtilConstants.NEW_LINE))); 91 + UtilConstants.NEW_LINE)));
67 - }
68 -
69 - /**
70 - * Unit test case for java attribute info.
71 - */
72 - @SuppressWarnings("rawtypes")
73 - @Test
74 - public void testForJavaAttributeInfo() {
75 - // TODO: need to update for new framework
76 - // String attributeWithType
77 - // = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, getType());
78 - // assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE
79 - // + getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
80 - //
81 - // String attributeWithoutType
82 - // = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, null);
83 - // assertThat(true,
84 - // is(attributeWithoutType.equals(
85 - // UtilConstants.PRIVATE
86 - // + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
87 - // + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
88 92
89 } 93 }
90 94
...@@ -99,29 +103,62 @@ public class JavaCodeSnippetGenTest { ...@@ -99,29 +103,62 @@ public class JavaCodeSnippetGenTest {
99 } 103 }
100 104
101 /** 105 /**
102 - * Unit test case for java method info. 106 + * Unit test case for java class interface definition close.
103 */ 107 */
104 @Test 108 @Test
105 - public void testForJavaMethodInfo() { 109 + public void testForJavaClassDefInterfaceClose() {
106 - //TODO: update to new framework. 110 + String interfaceDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME);
107 - // String method 111 + assertThat(true, is(interfaceDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
108 - // = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType());
109 - // assertThat(true,
110 - // is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION
111 - // + JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName())
112 - // + UtilConstants.SPACE
113 - // + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
114 - // + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
115 - // + UtilConstants.SEMI_COLAN)));
116 } 112 }
117 113
118 /** 114 /**
119 - * Unit test case for java class definition close. 115 + * Unit test case for java class builder class definition close.
120 */ 116 */
121 @Test 117 @Test
122 - public void testForJavaClassDefClose() { 118 + public void testForJavaClassDefBuilderClassClose() {
123 - String classDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME); 119 + String builderClassDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.BUILDER_CLASS_MASK,
124 - assertThat(true, is(classDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); 120 + YANG_NAME);
121 + assertThat(true, is(builderClassDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
122 + }
123 +
124 + /**
125 + * Unit test case for java class typedef definition close.
126 + */
127 + @Test
128 + public void testForJavaClassDefTypeDefClose() {
129 + String typeDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.GENERATE_TYPEDEF_CLASS, YANG_NAME);
130 + assertThat(true, is(typeDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
131 + }
132 +
133 + /**
134 + * Unit test case for java attribute info.
135 + */
136 + @SuppressWarnings("rawtypes")
137 + @Test
138 + public void testForJavaAttributeInfo() {
139 +
140 + String attributeWithoutTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
141 + false);
142 + assertThat(true, is(attributeWithoutTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "String"
143 + + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
144 + String attributeWithTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
145 + false);
146 + assertThat(true, is(attributeWithTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "java.lang."
147 + + "String" + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
148 + String attributeWithListPkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
149 + true);
150 + assertThat(true,
151 + is(attributeWithListPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
152 + + UtilConstants.DIAMOND_OPEN_BRACKET + "java.lang."
153 + + "String" + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
154 + + UtilConstants.SEMI_COLAN)));
155 + String attributeWithListWithoutPkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
156 + true);
157 + assertThat(true,
158 + is(attributeWithListWithoutPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
159 + + UtilConstants.DIAMOND_OPEN_BRACKET + "String"
160 + + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
161 + + UtilConstants.SEMI_COLAN)));
125 } 162 }
126 163
127 /** 164 /**
......
...@@ -36,8 +36,8 @@ public final class JavaIdentifierSyntaxTest { ...@@ -36,8 +36,8 @@ public final class JavaIdentifierSyntaxTest {
36 public static final String DATE2 = "1992-01-25"; 36 public static final String DATE2 = "1992-01-25";
37 public static final String PARENT_WITH_PERIOD = "test5.test6.test7"; 37 public static final String PARENT_WITH_PERIOD = "test5.test6.test7";
38 public static final String CHILD_WITH_PERIOD = "test1.test2.test3"; 38 public static final String CHILD_WITH_PERIOD = "test1.test2.test3";
39 - public static final String DATE_WITH_REV1 = "rev000105"; 39 + public static final String DATE_WITH_REV1 = "rev20000105";
40 - public static final String DATE_WITH_REV2 = "rev920125"; 40 + public static final String DATE_WITH_REV2 = "rev19920125";
41 public static final String VERSION_NUMBER = "v1"; 41 public static final String VERSION_NUMBER = "v1";
42 public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; 42 public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
43 public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; 43 public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
......
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 -import java.lang.reflect.Constructor;
20 -import java.lang.reflect.InvocationTargetException;
21 -
22 import org.junit.Test; 19 import org.junit.Test;
23 -import org.onosproject.yangutils.datamodel.YangType;
24 -import org.onosproject.yangutils.translator.GeneratedFileType;
25 -import org.onosproject.yangutils.translator.tojava.AttributeInfo;
26 -
27 import static org.hamcrest.core.Is.is; 20 import static org.hamcrest.core.Is.is;
28 -import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertThat; 21 import static org.junit.Assert.assertThat;
22 +import static org.junit.Assert.assertNotNull;
23 +import org.onosproject.yangutils.datamodel.YangDataTypes;
24 +import org.onosproject.yangutils.datamodel.YangType;
25 +import org.onosproject.yangutils.translator.tojava.AttributeInfo;
26 +import org.onosproject.yangutils.translator.tojava.ImportInfo;
27 +import org.onosproject.yangutils.utils.UtilConstants;
28 +import java.lang.reflect.Constructor;
29 +import java.lang.reflect.InvocationTargetException;
30 30
31 /** 31 /**
32 * Unit tests for generated methods from the file type. 32 * Unit tests for generated methods from the file type.
...@@ -42,19 +42,15 @@ public final class MethodsGeneratorTest { ...@@ -42,19 +42,15 @@ public final class MethodsGeneratorTest {
42 * @throws SecurityException if any security violation is observed 42 * @throws SecurityException if any security violation is observed
43 * @throws NoSuchMethodException if when the method is not found 43 * @throws NoSuchMethodException if when the method is not found
44 * @throws IllegalArgumentException if there is illegal argument found 44 * @throws IllegalArgumentException if there is illegal argument found
45 - * @throws InstantiationException if instantiation is provoked for the 45 + * @throws InstantiationException if instantiation is provoked for the private constructor
46 - * private constructor 46 + * @throws IllegalAccessException if instance is provoked or a method is provoked
47 - * @throws IllegalAccessException if instance is provoked or a method is 47 + * @throws InvocationTargetException when an exception occurs by the method or constructor
48 - * provoked
49 - * @throws InvocationTargetException when an exception occurs by the method
50 - * or constructor
51 */ 48 */
52 @Test 49 @Test
53 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 50 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
54 InstantiationException, IllegalAccessException, InvocationTargetException { 51 InstantiationException, IllegalAccessException, InvocationTargetException {
55 52
56 - Class<?>[] classesToConstruct = { 53 + Class<?>[] classesToConstruct = {MethodsGenerator.class };
57 - MethodsGenerator.class };
58 for (Class<?> clazz : classesToConstruct) { 54 for (Class<?> clazz : classesToConstruct) {
59 Constructor<?> constructor = clazz.getDeclaredConstructor(); 55 Constructor<?> constructor = clazz.getDeclaredConstructor();
60 constructor.setAccessible(true); 56 constructor.setAccessible(true);
...@@ -63,27 +59,100 @@ public final class MethodsGeneratorTest { ...@@ -63,27 +59,100 @@ public final class MethodsGeneratorTest {
63 } 59 }
64 60
65 /** 61 /**
66 - * Unit test for checking the values received from constructor, default 62 + * Unit test case for checking the parse builder and typedef constructor.
67 - * constructor and build string formation. 63 + */
64 + @Test
65 + public void getParseBuilderInterfaceMethodConstructorTest() {
66 + ImportInfo forSetter = new ImportInfo();
67 + attrType.setDataTypeName("binary");
68 + attrType.getDataTypeName();
69 + attrType.setDataType(YangDataTypes.BINARY);
70 + attrType.getDataType();
71 + testAttr.setAttributeName("attributeTest");
72 + testAttr.setAttributeType(attrType);
73 + forSetter.setPkgInfo("test1/test3");
74 + forSetter.setClassInfo("This class contains");
75 + testAttr.setImportInfo(forSetter);
76 + String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
77 + assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("newTestName"),
78 + is(true));
79 + String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
80 + assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
81 + && parseBuilderInterfaceBuild.contains("testname7"), is(true));
82 + String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
83 + }
84 +
85 + /**
86 + * Unit test case for checking the values received from constructor, default constructor and build string formation.
68 */ 87 */
69 @Test 88 @Test
70 public void getValuesTest() { 89 public void getValuesTest() {
71 String stringConstructor = MethodsGenerator.getConstructorString("testname"); 90 String stringConstructor = MethodsGenerator.getConstructorString("testname");
72 - assertThat( 91 + assertThat(stringConstructor.contains(UtilConstants.JAVA_DOC_CONSTRUCTOR)
73 - stringConstructor.contains("Construct the object of testnameImpl.") 92 + && stringConstructor.contains(UtilConstants.JAVA_DOC_PARAM)
74 - && stringConstructor.contains("@param testnameObject builder object of testname") 93 + && stringConstructor.contains(UtilConstants.BUILDER_OBJECT), is(true));
75 - && stringConstructor.contains("public testnameImpl(testnameBuilder testnameObject) {"), 94 + String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString("testnameBuilder", "public");
76 - is(true)); 95 + assertThat(stringDefaultConstructor.contains(UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR)
77 - String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString( 96 + && stringDefaultConstructor.contains(UtilConstants.BUILDER)
78 - GeneratedFileType.BUILDER_CLASS_MASK, 97 + && stringDefaultConstructor.contains("testname"), is(true));
79 - "testname");
80 - assertThat(stringDefaultConstructor.contains("Default Constructor.")
81 - && stringDefaultConstructor.contains("public testnameBuilder() {")
82 - && stringDefaultConstructor.contains("}"), is(true));
83 String stringBuild = MethodsGenerator.getBuildString("testname"); 98 String stringBuild = MethodsGenerator.getBuildString("testname");
84 - assertThat( 99 + assertThat(stringBuild.contains(UtilConstants.OVERRIDE) && stringBuild.contains(UtilConstants.BUILD)
85 - stringBuild.contains("public testname build() {") 100 + && stringBuild.contains(UtilConstants.RETURN), is(true));
86 - && stringBuild.contains("return new testnameImpl(this);") && stringBuild.contains("}"), 101 +
102 + }
103 +
104 + /**
105 + * Unit test for checking the values received for class getter, class and typedef setters with list data type.
106 + */
107 + @Test
108 + public void getGetterSetterTest() {
109 +
110 + ImportInfo forGetterSetter = new ImportInfo();
111 + attrType.setDataTypeName("int");
112 + attrType.getDataTypeName();
113 + attrType.setDataType(YangDataTypes.UINT8);
114 + attrType.getDataType();
115 + testAttr.setAttributeName("AttributeTest1");
116 + testAttr.setAttributeType(attrType);
117 + forGetterSetter.setPkgInfo(null);
118 + forGetterSetter.setClassInfo("This class contains");
119 + testAttr.setImportInfo(forGetterSetter);
120 + testAttr.setListAttr(true);
121 + String getterForClass = MethodsGenerator.getGetterForClass(testAttr);
122 + assertThat(getterForClass.contains(UtilConstants.GET_METHOD_PREFIX) && getterForClass.contains("List<")
123 + && getterForClass.contains("attributeTest1"), is(true));
124 + String setterForClass = MethodsGenerator.getSetterForClass(testAttr, "TestThis");
125 + assertThat(setterForClass.contains(UtilConstants.SET_METHOD_PREFIX) && setterForClass.contains("List<")
126 + && setterForClass.contains("attributeTest1"), is(true));
127 + String typeDefSetter = MethodsGenerator.getSetterForTypeDefClass(testAttr);
128 + assertThat(typeDefSetter.contains(UtilConstants.SET_METHOD_PREFIX) && typeDefSetter.contains("List<")
129 + && typeDefSetter.contains("attributeTest1") && typeDefSetter.contains("this."), is(true));
130 + }
131 +
132 + /**
133 + * Unit test case for checking the parse builder and typedef constructor with list data type.
134 + */
135 + @Test
136 + public void getConstructorWithListTypeTest() {
137 + ImportInfo forSetter = new ImportInfo();
138 + attrType.setDataTypeName("binary");
139 + attrType.getDataTypeName();
140 + attrType.setDataType(YangDataTypes.BINARY);
141 + attrType.getDataType();
142 + testAttr.setAttributeName("attributeTest");
143 + testAttr.setAttributeType(attrType);
144 + forSetter.setPkgInfo(null);
145 + forSetter.setClassInfo("This class contains");
146 + testAttr.setImportInfo(forSetter);
147 + testAttr.setListAttr(true);
148 + String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
149 + assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("List<"),
87 is(true)); 150 is(true));
151 + String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
152 + assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
153 + && parseBuilderInterfaceBuild.contains("testname7"), is(true));
154 + String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
155 + assertThat(stringTypeDef.contains("(List<") && stringTypeDef.contains("Testname")
156 + && stringTypeDef.contains(UtilConstants.THIS), is(true));
88 } 157 }
89 } 158 }
......
...@@ -16,22 +16,25 @@ ...@@ -16,22 +16,25 @@
16 16
17 package org.onosproject.yangutils.utils.io.impl; 17 package org.onosproject.yangutils.utils.io.impl;
18 18
19 +import static org.slf4j.LoggerFactory.getLogger;
20 +
19 import org.junit.Test; 21 import org.junit.Test;
20 import org.junit.Rule; 22 import org.junit.Rule;
21 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
22 -import org.onosproject.yangutils.translator.GeneratedFileType; 24 +
23 -import org.onosproject.yangutils.utils.UtilConstants; 25 +import static org.junit.Assert.assertNotNull;
26 +import static org.junit.Assert.assertTrue;
27 +import static org.junit.Assert.assertFalse;
24 28
25 import java.io.File; 29 import java.io.File;
26 import java.io.IOException; 30 import java.io.IOException;
27 import java.lang.reflect.Constructor; 31 import java.lang.reflect.Constructor;
28 import java.lang.reflect.InvocationTargetException; 32 import java.lang.reflect.InvocationTargetException;
29 33
34 +import org.onosproject.yangutils.translator.GeneratedFileType;
35 +import org.onosproject.yangutils.utils.UtilConstants;
30 import org.slf4j.Logger; 36 import org.slf4j.Logger;
31 -import static org.slf4j.LoggerFactory.getLogger; 37 +
32 -import static org.junit.Assert.assertNotNull;
33 -import static org.junit.Assert.assertTrue;
34 -import static org.junit.Assert.assertFalse;
35 38
36 /** 39 /**
37 * Tests the file handle utilities. 40 * Tests the file handle utilities.
...@@ -50,12 +53,12 @@ public final class FileSystemUtilTest { ...@@ -50,12 +53,12 @@ public final class FileSystemUtilTest {
50 /** 53 /**
51 * A private constructor is tested. 54 * A private constructor is tested.
52 * 55 *
53 - * @throws SecurityException if any security violation is observed. 56 + * @throws SecurityException if any security violation is observed
54 - * @throws NoSuchMethodException if when the method is not found. 57 + * @throws NoSuchMethodException if when the method is not found
55 - * @throws IllegalArgumentException if there is illegal argument found. 58 + * @throws IllegalArgumentException if there is illegal argument found
56 - * @throws InstantiationException if instantiation is provoked for the private constructor. 59 + * @throws InstantiationException if instantiation is provoked for the private constructor
57 - * @throws IllegalAccessException if instance is provoked or a method is provoked. 60 + * @throws IllegalAccessException if instance is provoked or a method is provoked
58 - * @throws InvocationTargetException when an exception occurs by the method or constructor. 61 + * @throws InvocationTargetException when an exception occurs by the method or constructor
59 */ 62 */
60 @Test 63 @Test
61 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 64 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
...@@ -82,17 +85,18 @@ public final class FileSystemUtilTest { ...@@ -82,17 +85,18 @@ public final class FileSystemUtilTest {
82 * This test case checks the contents to be written in the file. 85 * This test case checks the contents to be written in the file.
83 */ 86 */
84 @Test 87 @Test
85 - public void insertStringInFileTest() throws IOException { 88 + public void updateFileHandleTest() throws IOException {
86 File dir = new File(baseDir + File.separator + "File1"); 89 File dir = new File(baseDir + File.separator + "File1");
87 dir.mkdirs(); 90 dir.mkdirs();
88 File createFile = new File(dir + "testFile"); 91 File createFile = new File(dir + "testFile");
89 createFile.createNewFile(); 92 createFile.createNewFile();
90 File createSourceFile = new File(dir + "sourceTestFile"); 93 File createSourceFile = new File(dir + "sourceTestFile");
91 createSourceFile.createNewFile(); 94 createSourceFile.createNewFile();
92 - FileSystemUtil.insertStringInFile(createFile, "This is to append a text to the file first1\n"); 95 + FileSystemUtil.updateFileHandle(createFile, "This is to append a text to the file first1\n", false);
93 - FileSystemUtil.insertStringInFile(createFile, "This is next second line\n"); 96 + FileSystemUtil.updateFileHandle(createFile, "This is next second line\n", false);
94 - FileSystemUtil.insertStringInFile(createFile, "This is next third line in the file"); 97 + FileSystemUtil.updateFileHandle(createFile, "This is next third line in the file", false);
95 FileSystemUtil.appendFileContents(createFile, createSourceFile); 98 FileSystemUtil.appendFileContents(createFile, createSourceFile);
99 + FileSystemUtil.updateFileHandle(createFile, null, true);
96 } 100 }
97 101
98 /** 102 /**
......
...@@ -41,7 +41,7 @@ public final class JavaDocGenTest { ...@@ -41,7 +41,7 @@ public final class JavaDocGenTest {
41 @Test 41 @Test
42 public void builderClassGenerationTest() { 42 public void builderClassGenerationTest() {
43 43
44 - String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1"); 44 + String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false);
45 assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of") 45 assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of")
46 && builderClassJavaDoc.contains(" */\n")); 46 && builderClassJavaDoc.contains(" */\n"));
47 } 47 }
...@@ -52,7 +52,7 @@ public final class JavaDocGenTest { ...@@ -52,7 +52,7 @@ public final class JavaDocGenTest {
52 @Test 52 @Test
53 public void builderInterfaceGenerationTest() { 53 public void builderInterfaceGenerationTest() {
54 54
55 - String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1"); 55 + String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false);
56 assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n")); 56 assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n"));
57 } 57 }
58 58
...@@ -62,19 +62,19 @@ public final class JavaDocGenTest { ...@@ -62,19 +62,19 @@ public final class JavaDocGenTest {
62 @Test 62 @Test
63 public void buildGenerationTest() { 63 public void buildGenerationTest() {
64 64
65 - String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1"); 65 + String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1", false);
66 assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); 66 assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n"));
67 } 67 }
68 68
69 /** 69 /**
70 * A private constructor is tested. 70 * A private constructor is tested.
71 * 71 *
72 - * @throws SecurityException if any security violation is observed. 72 + * @throws SecurityException if any security violation is observed
73 - * @throws NoSuchMethodException if when the method is not found. 73 + * @throws NoSuchMethodException if when the method is not found
74 - * @throws IllegalArgumentException if there is illegal argument found. 74 + * @throws IllegalArgumentException if there is illegal argument found
75 - * @throws InstantiationException if instantiation is provoked for the private constructor. 75 + * @throws InstantiationException if instantiation is provoked for the private constructor
76 - * @throws IllegalAccessException if instance is provoked or a method is provoked. 76 + * @throws IllegalAccessException if instance is provoked or a method is provoked
77 - * @throws InvocationTargetException when an exception occurs by the method or constructor. 77 + * @throws InvocationTargetException when an exception occurs by the method or constructor
78 */ 78 */
79 @Test 79 @Test
80 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 80 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
...@@ -94,7 +94,7 @@ public final class JavaDocGenTest { ...@@ -94,7 +94,7 @@ public final class JavaDocGenTest {
94 @Test 94 @Test
95 public void constructorGenerationTest() { 95 public void constructorGenerationTest() {
96 96
97 - String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1"); 97 + String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1", false);
98 assertTrue( 98 assertTrue(
99 constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of") 99 constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of")
100 && constructorDoc.contains("@param") && constructorDoc.contains("*/\n")); 100 && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"));
...@@ -107,7 +107,7 @@ public final class JavaDocGenTest { ...@@ -107,7 +107,7 @@ public final class JavaDocGenTest {
107 @Test 107 @Test
108 public void defaultConstructorGenerationTest() { 108 public void defaultConstructorGenerationTest() {
109 109
110 - String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1"); 110 + String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false);
111 assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n")); 111 assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n"));
112 } 112 }
113 113
...@@ -117,7 +117,7 @@ public final class JavaDocGenTest { ...@@ -117,7 +117,7 @@ public final class JavaDocGenTest {
117 @Test 117 @Test
118 public void getterGenerationTest() { 118 public void getterGenerationTest() {
119 119
120 - String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1"); 120 + String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1", false);
121 assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); 121 assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n"));
122 } 122 }
123 123
...@@ -126,7 +126,7 @@ public final class JavaDocGenTest { ...@@ -126,7 +126,7 @@ public final class JavaDocGenTest {
126 */ 126 */
127 @Test 127 @Test
128 public void implClassGenerationTest() { 128 public void implClassGenerationTest() {
129 - String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1"); 129 + String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false);
130 assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n")); 130 assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n"));
131 } 131 }
132 132
...@@ -136,7 +136,7 @@ public final class JavaDocGenTest { ...@@ -136,7 +136,7 @@ public final class JavaDocGenTest {
136 @Test 136 @Test
137 public void interfaceGenerationTest() { 137 public void interfaceGenerationTest() {
138 138
139 - String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1"); 139 + String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false);
140 assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of") 140 assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of")
141 && interfaceJavaDoc.contains(" */\n")); 141 && interfaceJavaDoc.contains(" */\n"));
142 } 142 }
...@@ -146,10 +146,9 @@ public final class JavaDocGenTest { ...@@ -146,10 +146,9 @@ public final class JavaDocGenTest {
146 */ 146 */
147 @Test 147 @Test
148 public void packageInfoGenerationTest() { 148 public void packageInfoGenerationTest() {
149 - // TODO: udpate to new framework. 149 +
150 - // String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1"); 150 + String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false);
151 - // assertTrue(packageInfo.contains( 151 + assertTrue(packageInfo.contains("Generated java code corresponding to YANG") && packageInfo.contains(" */\n"));
152 - // "Generated java code for the YANG file") && packageInfo.contains(" */\n"));
153 } 152 }
154 153
155 /** 154 /**
...@@ -158,7 +157,17 @@ public final class JavaDocGenTest { ...@@ -158,7 +157,17 @@ public final class JavaDocGenTest {
158 @Test 157 @Test
159 public void setterGenerationTest() { 158 public void setterGenerationTest() {
160 159
161 - String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1"); 160 + String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1", false);
162 assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); 161 assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n"));
163 } 162 }
163 +
164 + /**
165 + * This test case checks the content received for the typedef setter java doc.
166 + */
167 + @Test
168 + public void typeDefSetterGenerationTest() {
169 +
170 + String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, "testGeneration1", false);
171 + assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n"));
172 + }
164 } 173 }
...\ No newline at end of file ...\ No newline at end of file
......
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.utils.io.impl;
18 -
19 -import org.junit.Test;
20 -import org.junit.Rule;
21 -import org.junit.rules.ExpectedException;
22 -import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType;
23 -
24 -import java.io.FileNotFoundException;
25 -import java.io.IOException;
26 -import java.lang.reflect.Constructor;
27 -import java.lang.reflect.InvocationTargetException;
28 -import java.util.LinkedList;
29 -import java.util.List;
30 -
31 -import org.slf4j.Logger;
32 -import static org.slf4j.LoggerFactory.getLogger;
33 -
34 -import static org.hamcrest.core.Is.is;
35 -import static org.junit.Assert.assertThat;
36 -import static org.junit.Assert.assertNotNull;
37 -
38 -/**
39 - * Unit tests for the Tempd data store for its contents.
40 - */
41 -public final class TempDataStoreTest {
42 -
43 - private final Logger log = getLogger(getClass());
44 - private static final String CLASS_NAME = "YANG";
45 -
46 - @Rule
47 - public ExpectedException thrown = ExpectedException.none();
48 -
49 - /**
50 - * A private constructor is tested.
51 - *
52 - * @throws SecurityException if any security violation is observed.
53 - * @throws NoSuchMethodException if when the method is not found.
54 - * @throws IllegalArgumentException if there is illegal argument found.
55 - * @throws InstantiationException if instantiation is provoked for the private constructor.
56 - * @throws IllegalAccessException if instance is provoked or a method is provoked.
57 - * @throws InvocationTargetException when an exception occurs by the method or constructor.
58 - */
59 - @Test
60 - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
61 - InstantiationException, IllegalAccessException, InvocationTargetException {
62 -
63 - Class<?>[] classesToConstruct = {TempDataStore.class };
64 - for (Class<?> clazz : classesToConstruct) {
65 - Constructor<?> constructor = clazz.getDeclaredConstructor();
66 - constructor.setAccessible(true);
67 - assertNotNull(constructor.newInstance());
68 - }
69 - }
70 -
71 - /**
72 - * This test case checks the attribute info that is read and put into the list.
73 - */
74 - @Test
75 - public void insertAttributeDataTest() throws IOException, ClassNotFoundException, FileNotFoundException {
76 -
77 - String attributeData = "attribute content lists this";
78 - TempDataStore.setTempData(attributeData, TempDataStoreType.ATTRIBUTE, CLASS_NAME);
79 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, CLASS_NAME);
80 - List<String> expectedinfo = new LinkedList<>();
81 - expectedinfo.add(attributeData);
82 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
83 - TempDataStoreType.valueOf(TempDataStoreType.ATTRIBUTE.toString());
84 - }
85 -
86 - /**
87 - * This test case checks the builder interface that is read and put into the list.
88 - */
89 - @Test
90 - public void insertBuilderInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
91 -
92 - String builderInterfaceMethodsData = "builder interface methods content lists this";
93 - TempDataStore.setTempData(builderInterfaceMethodsData, TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
94 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
95 - List<String> expectedinfo = new LinkedList<>();
96 - expectedinfo.add(builderInterfaceMethodsData);
97 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
98 - }
99 -
100 - /**
101 - * This test case checks the builder methods that is read and put into the list.
102 - */
103 - @Test
104 - public void insertBuilderMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
105 -
106 - String builderMethodsData = "builder methods content lists this";
107 - TempDataStore.setTempData(builderMethodsData, TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
108 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
109 - List<String> expectedinfo = new LinkedList<>();
110 - expectedinfo.add(builderMethodsData);
111 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
112 - }
113 -
114 - /**
115 - * This test case checks the impl methods that is read and put into the list.
116 - */
117 - @Test
118 - public void insertImplMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
119 -
120 - String implMethodsData = "impl methods content lists this";
121 - TempDataStore.setTempData(implMethodsData, TempDataStoreType.IMPL_METHODS, CLASS_NAME);
122 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, CLASS_NAME);
123 - List<String> expectedinfo = new LinkedList<>();
124 - expectedinfo.add(implMethodsData);
125 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
126 - }
127 -
128 - /**
129 - * This test case checks the import methods that is read and put into the list.
130 - */
131 - @Test
132 - public void insertImportTest() throws IOException, ClassNotFoundException, FileNotFoundException {
133 -
134 - String importData = "interface methods content lists this";
135 - TempDataStore.setTempData(importData, TempDataStoreType.IMPORT, CLASS_NAME);
136 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPORT, CLASS_NAME);
137 - List<String> expectedinfo = new LinkedList<>();
138 - expectedinfo.add(importData);
139 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
140 - }
141 -
142 - /**
143 - * This test case checks the interface methods that is read and put into the list.
144 - */
145 - @Test
146 - public void insertInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
147 -
148 - String interfaceMethodsData = "interface methods content lists this";
149 - TempDataStore.setTempData(interfaceMethodsData, TempDataStoreType.GETTER_METHODS, CLASS_NAME);
150 - List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, CLASS_NAME);
151 - List<String> expectedinfo = new LinkedList<>();
152 - expectedinfo.add(interfaceMethodsData);
153 - assertThat(true, is(attributeInfo.equals(expectedinfo)));
154 - }
155 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -84,8 +84,8 @@ public final class YangFileScannerTest { ...@@ -84,8 +84,8 @@ public final class YangFileScannerTest {
84 /** 84 /**
85 * Method used for creating multiple directories inside the target file. 85 * Method used for creating multiple directories inside the target file.
86 * 86 *
87 - * @param path where directories should be created. 87 + * @param path where directories should be created
88 - * @return 88 + * @return the directory path that is created
89 */ 89 */
90 public File createDirectory(String path) { 90 public File createDirectory(String path) {
91 91
......
...@@ -37,7 +37,7 @@ import java.lang.reflect.Constructor; ...@@ -37,7 +37,7 @@ import java.lang.reflect.Constructor;
37 import java.lang.reflect.InvocationTargetException; 37 import java.lang.reflect.InvocationTargetException;
38 38
39 /** 39 /**
40 - * Unit tests for adding package-info, creating directories, cleaning the folder and to add sources. 40 + * Unit tests for YANG io utils.
41 */ 41 */
42 public final class YangIoUtilsTest { 42 public final class YangIoUtilsTest {
43 43
...@@ -65,6 +65,20 @@ public final class YangIoUtilsTest { ...@@ -65,6 +65,20 @@ public final class YangIoUtilsTest {
65 } 65 }
66 66
67 /** 67 /**
68 + * This test case checks with an additional info in the path.
69 + */
70 + @Test
71 + public void addPackageInfoWithPathTest() throws IOException {
72 +
73 + File dirPath = new File(createPath);
74 + dirPath.mkdirs();
75 + CopyrightHeader.parseCopyrightHeader();
76 + YangIoUtils.addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + createPath);
77 + File filePath = new File(dirPath + File.separator + "package-info.java");
78 + assertThat(filePath.isFile(), is(true));
79 + }
80 +
81 + /**
68 * This test case checks whether the package-info file is created when invalid path is given. 82 * This test case checks whether the package-info file is created when invalid path is given.
69 */ 83 */
70 @Test 84 @Test
...@@ -81,12 +95,12 @@ public final class YangIoUtilsTest { ...@@ -81,12 +95,12 @@ public final class YangIoUtilsTest {
81 /** 95 /**
82 * A private constructor is tested. 96 * A private constructor is tested.
83 * 97 *
84 - * @throws SecurityException if any security violation is observed. 98 + * @throws SecurityException if any security violation is observed
85 - * @throws NoSuchMethodException if when the method is not found. 99 + * @throws NoSuchMethodException if when the method is not found
86 - * @throws IllegalArgumentException if there is illegal argument found. 100 + * @throws IllegalArgumentException if there is illegal argument found
87 - * @throws InstantiationException if instantiation is provoked for the private constructor. 101 + * @throws InstantiationException if instantiation is provoked for the private constructor
88 - * @throws IllegalAccessException if instance is provoked or a method is provoked. 102 + * @throws IllegalAccessException if instance is provoked or a method is provoked
89 - * @throws InvocationTargetException when an exception occurs by the method or constructor. 103 + * @throws InvocationTargetException when an exception occurs by the method or constructor
90 */ 104 */
91 @Test 105 @Test
92 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, 106 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
......