Committed by
Gerrit Code Review
ST defect fixes and review comments fixes
Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
Showing
40 changed files
with
733 additions
and
462 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 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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,25 +78,37 @@ public final class JavaCodeSnippetGen { | ... | @@ -78,25 +78,37 @@ 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 | ||
89 | - if (javaAttributeTypePkg != null) { | 90 | + if (!isList) { |
90 | - attributeDefination = attributeDefination | 91 | + if (javaAttributeTypePkg != null) { |
91 | - + javaAttributeTypePkg + "."; | 92 | + attributeDefination = attributeDefination |
92 | - } | 93 | + + javaAttributeTypePkg + "."; |
94 | + } | ||
93 | 95 | ||
94 | - attributeDefination = attributeDefination | 96 | + attributeDefination = attributeDefination |
95 | - + javaAttributeType | 97 | + + javaAttributeType |
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 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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) { | ... | ... |
This diff is collapsed. Click to expand it.
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); |
145 | - outputPrintWriter.write(contentTobeAdded); | 146 | + if (!isClose) { |
146 | - outputPrintWriter.flush(); | 147 | + outputPrintWriter.write(contentTobeAdded); |
147 | - outputPrintWriter.close(); | 148 | + outputPrintWriter.flush(); |
148 | - | 149 | + outputPrintWriter.close(); |
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,9 +67,8 @@ public final class YangFileScanner { | ... | @@ -67,9 +67,8 @@ 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<>(); |
74 | Stack<String> stack = new Stack<>(); | 73 | Stack<String> stack = new Stack<>(); |
75 | stack.push(root); | 74 | stack.push(root); | ... | ... |
... | @@ -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 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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 | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/TempDataStoreTest.java
deleted
100644 → 0
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, |
... | @@ -146,4 +160,4 @@ public final class YangIoUtilsTest { | ... | @@ -146,4 +160,4 @@ public final class YangIoUtilsTest { |
146 | sourceDir.mkdirs(); | 160 | sourceDir.mkdirs(); |
147 | YangIoUtils.addToSource(sourceDir.toString(), project, context); | 161 | YangIoUtils.addToSource(sourceDir.toString(), project, context); |
148 | } | 162 | } |
149 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
163 | +} | ... | ... |
-
Please register or login to post a comment