Committed by
Gerrit Code Review
[ONOS-3908] YANG container translator.
Change-Id: I4e239509df747238905ca0995f41019679093627
Showing
19 changed files
with
1042 additions
and
461 deletions
... | @@ -26,6 +26,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; | ... | @@ -26,6 +26,7 @@ import org.onosproject.yangutils.parser.ParsableDataType; |
26 | import org.onosproject.yangutils.translator.CachedFileHandle; | 26 | import org.onosproject.yangutils.translator.CachedFileHandle; |
27 | import org.onosproject.yangutils.translator.GeneratedFileType; | 27 | import org.onosproject.yangutils.translator.GeneratedFileType; |
28 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; | 28 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
29 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
29 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | 30 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; |
30 | /*- | 31 | /*- |
31 | * Reference RFC 6020. | 32 | * Reference RFC 6020. |
... | @@ -472,17 +473,21 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom | ... | @@ -472,17 +473,21 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom |
472 | @Override | 473 | @Override |
473 | public void generateJavaCodeEntry() throws IOException { | 474 | public void generateJavaCodeEntry() throws IOException { |
474 | YangNode parent = getParent(); | 475 | YangNode parent = getParent(); |
475 | - String modPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), getName()); | 476 | + String contPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), parent.getName()); |
476 | - setPackage(modPkg); | 477 | + setPackage(contPkg); |
477 | 478 | ||
478 | CachedFileHandle handle = null; | 479 | CachedFileHandle handle = null; |
479 | try { | 480 | try { |
480 | - FileSystemUtil.createPackage(getPackage(), getName()); | 481 | + FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName()); |
481 | handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL); | 482 | handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL); |
483 | + handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/")); | ||
482 | } catch (IOException e) { | 484 | } catch (IOException e) { |
483 | throw new IOException("Failed to create the source files."); | 485 | throw new IOException("Failed to create the source files."); |
484 | } | 486 | } |
485 | setFileHandle(handle); | 487 | setFileHandle(handle); |
488 | + | ||
489 | + addLeavesAttributes(); | ||
490 | + addLeafListAttributes(); | ||
486 | addAttributeInParent(); | 491 | addAttributeInParent(); |
487 | } | 492 | } |
488 | 493 | ||
... | @@ -498,8 +503,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom | ... | @@ -498,8 +503,6 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom |
498 | 503 | ||
499 | @Override | 504 | @Override |
500 | public void generateJavaCodeExit() throws IOException { | 505 | public void generateJavaCodeExit() throws IOException { |
501 | - addLeavesAttributes(); | ||
502 | - addLeafListAttributes(); | ||
503 | getFileHandle().close(); | 506 | getFileHandle().close(); |
504 | return; | 507 | return; |
505 | } | 508 | } | ... | ... |
... | @@ -26,6 +26,7 @@ import org.onosproject.yangutils.translator.CachedFileHandle; | ... | @@ -26,6 +26,7 @@ import org.onosproject.yangutils.translator.CachedFileHandle; |
26 | import org.onosproject.yangutils.translator.CodeGenerator; | 26 | import org.onosproject.yangutils.translator.CodeGenerator; |
27 | import org.onosproject.yangutils.translator.GeneratedFileType; | 27 | import org.onosproject.yangutils.translator.GeneratedFileType; |
28 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; | 28 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
29 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
29 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | 30 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; |
30 | 31 | ||
31 | /*- | 32 | /*- |
... | @@ -558,18 +559,19 @@ public class YangModule extends YangNode | ... | @@ -558,18 +559,19 @@ public class YangModule extends YangNode |
558 | 559 | ||
559 | CachedFileHandle handle = null; | 560 | CachedFileHandle handle = null; |
560 | try { | 561 | try { |
561 | - FileSystemUtil.createPackage(getPackage(), getName()); | 562 | + FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName()); |
562 | handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL); | 563 | handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL); |
564 | + handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/")); | ||
563 | } catch (IOException e) { | 565 | } catch (IOException e) { |
564 | throw new IOException("Failed to create the source files."); | 566 | throw new IOException("Failed to create the source files."); |
565 | } | 567 | } |
566 | setFileHandle(handle); | 568 | setFileHandle(handle); |
569 | + addLeavesAttributes(); | ||
570 | + addLeafListAttributes(); | ||
567 | } | 571 | } |
568 | 572 | ||
569 | @Override | 573 | @Override |
570 | public void generateJavaCodeExit() throws IOException { | 574 | public void generateJavaCodeExit() throws IOException { |
571 | - addLeavesAttributes(); | ||
572 | - addLeafListAttributes(); | ||
573 | getFileHandle().close(); | 575 | getFileHandle().close(); |
574 | return; | 576 | return; |
575 | } | 577 | } | ... | ... |
... | @@ -49,4 +49,11 @@ public interface CachedFileHandle { | ... | @@ -49,4 +49,11 @@ public interface CachedFileHandle { |
49 | * @param pkg child's package path | 49 | * @param pkg child's package path |
50 | */ | 50 | */ |
51 | void setChildsPackage(String pkg); | 51 | void setChildsPackage(String pkg); |
52 | + | ||
53 | + /** | ||
54 | + * Sets directory package path for code generation. | ||
55 | + * | ||
56 | + * @param filePath directory package path for code generation | ||
57 | + */ | ||
58 | + void setFilePath(String filePath); | ||
52 | } | 59 | } | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava; |
19 | import java.io.Serializable; | 19 | import java.io.Serializable; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangType; | 21 | import org.onosproject.yangutils.datamodel.YangType; |
22 | +import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ||
22 | 23 | ||
23 | /** | 24 | /** |
24 | * Maintains the attribute info corresponding to class/interface generated. | 25 | * Maintains the attribute info corresponding to class/interface generated. |
... | @@ -71,7 +72,10 @@ public class AttributeInfo implements Serializable { | ... | @@ -71,7 +72,10 @@ public class AttributeInfo implements Serializable { |
71 | * @param type the data type info of attribute. | 72 | * @param type the data type info of attribute. |
72 | */ | 73 | */ |
73 | public void setAttributeType(YangType<?> type) { | 74 | public void setAttributeType(YangType<?> type) { |
74 | - attrType = type; | 75 | + |
76 | + if (type != null) { | ||
77 | + attrType = AttributesJavaDataType.getJavaDataType(type); | ||
78 | + } | ||
75 | } | 79 | } |
76 | 80 | ||
77 | /** | 81 | /** | ... | ... |
... | @@ -27,26 +27,18 @@ import java.util.TreeSet; | ... | @@ -27,26 +27,18 @@ import java.util.TreeSet; |
27 | import org.onosproject.yangutils.datamodel.YangType; | 27 | import org.onosproject.yangutils.datamodel.YangType; |
28 | import org.onosproject.yangutils.translator.CachedFileHandle; | 28 | import org.onosproject.yangutils.translator.CachedFileHandle; |
29 | import org.onosproject.yangutils.translator.GeneratedFileType; | 29 | import org.onosproject.yangutils.translator.GeneratedFileType; |
30 | +import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ||
30 | import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen; | 31 | import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen; |
32 | +import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator; | ||
31 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; | 33 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
32 | import org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator; | 34 | import org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator; |
33 | import org.onosproject.yangutils.utils.UtilConstants; | 35 | import org.onosproject.yangutils.utils.UtilConstants; |
34 | -import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | ||
35 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | ||
36 | -import org.onosproject.yangutils.utils.io.impl.SerializedDataStore; | ||
37 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
38 | -import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; | ||
39 | - | ||
40 | -import static org.slf4j.LoggerFactory.getLogger; | ||
41 | -import org.slf4j.Logger; | ||
42 | 36 | ||
43 | /** | 37 | /** |
44 | * Maintain the information about the java file to be generated. | 38 | * Maintain the information about the java file to be generated. |
45 | */ | 39 | */ |
46 | public class CachedJavaFileHandle implements CachedFileHandle { | 40 | public class CachedJavaFileHandle implements CachedFileHandle { |
47 | 41 | ||
48 | - private static final Logger log = getLogger(CachedJavaFileHandle.class); | ||
49 | - | ||
50 | private static final int MAX_CACHABLE_ATTR = 64; | 42 | private static final int MAX_CACHABLE_ATTR = 64; |
51 | private static final String JAVA_FILE_EXTENSION = ".java"; | 43 | private static final String JAVA_FILE_EXTENSION = ".java"; |
52 | private static final String TEMP_FILE_EXTENSION = ".tmp"; | 44 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
... | @@ -58,12 +50,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -58,12 +50,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
58 | private GeneratedFileType genFileTypes; | 50 | private GeneratedFileType genFileTypes; |
59 | 51 | ||
60 | /** | 52 | /** |
61 | - * The type(s) of java method to be generated when the cached file handle is | ||
62 | - * closed. | ||
63 | - */ | ||
64 | - private GeneratedMethodTypes genMethodTypes; | ||
65 | - | ||
66 | - /** | ||
67 | * Java package in which the class/interface needs to be generated. | 53 | * Java package in which the class/interface needs to be generated. |
68 | */ | 54 | */ |
69 | private String pkg; | 55 | private String pkg; |
... | @@ -90,9 +76,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -90,9 +76,14 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
90 | private List<AttributeInfo> attributeList; | 76 | private List<AttributeInfo> attributeList; |
91 | 77 | ||
92 | /** | 78 | /** |
79 | + * File generation directory path. | ||
80 | + */ | ||
81 | + private String filePath; | ||
82 | + | ||
83 | + /** | ||
93 | * Prevent invoking default constructor. | 84 | * Prevent invoking default constructor. |
94 | */ | 85 | */ |
95 | - private CachedJavaFileHandle() { | 86 | + public CachedJavaFileHandle() { |
96 | setCachedAttributeList(new LinkedList<AttributeInfo>()); | 87 | setCachedAttributeList(new LinkedList<AttributeInfo>()); |
97 | } | 88 | } |
98 | 89 | ||
... | @@ -106,16 +97,9 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -106,16 +97,9 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
106 | * @throws IOException file IO exception. | 97 | * @throws IOException file IO exception. |
107 | */ | 98 | */ |
108 | public CachedJavaFileHandle(String pcg, String yangName, GeneratedFileType types) throws IOException { | 99 | public CachedJavaFileHandle(String pcg, String yangName, GeneratedFileType types) throws IOException { |
109 | - if ((new File(pcg).exists())) { | ||
110 | setGeneratedFileTypes(types); | 100 | setGeneratedFileTypes(types); |
111 | setPackage(pcg); | 101 | setPackage(pcg); |
112 | setYangName(yangName); | 102 | setYangName(yangName); |
113 | - } else { | ||
114 | - FileSystemUtil.createPackage(pcg, yangName); | ||
115 | - setGeneratedFileTypes(types); | ||
116 | - setPackage(pcg); | ||
117 | - setYangName(yangName); | ||
118 | - } | ||
119 | } | 103 | } |
120 | 104 | ||
121 | /** | 105 | /** |
... | @@ -185,11 +169,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -185,11 +169,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
185 | return childsPkg; | 169 | return childsPkg; |
186 | } | 170 | } |
187 | 171 | ||
188 | - /** | ||
189 | - * Set the java package. | ||
190 | - * | ||
191 | - * @param pcg the package to set | ||
192 | - */ | ||
193 | @Override | 172 | @Override |
194 | public void setChildsPackage(String pcg) { | 173 | public void setChildsPackage(String pcg) { |
195 | childsPkg = pcg; | 174 | childsPkg = pcg; |
... | @@ -251,13 +230,27 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -251,13 +230,27 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
251 | attributeList = attrList; | 230 | attributeList = attrList; |
252 | } | 231 | } |
253 | 232 | ||
233 | + @Override | ||
234 | + public void setFilePath(String path) { | ||
235 | + filePath = path; | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Set the cached attribute list. | ||
240 | + * | ||
241 | + * @param attrList attribute list. | ||
242 | + */ | ||
243 | + private String getFilePath() { | ||
244 | + return filePath; | ||
245 | + } | ||
246 | + | ||
254 | /** | 247 | /** |
255 | * Flush the cached attribute list to the serialized file. | 248 | * Flush the cached attribute list to the serialized file. |
256 | */ | 249 | */ |
257 | - private void flushCacheAttrToSerFile() { | 250 | + private void flushCacheAttrToSerFile(String className) { |
258 | 251 | ||
259 | for (AttributeInfo attr : getCachedAttributeList()) { | 252 | for (AttributeInfo attr : getCachedAttributeList()) { |
260 | - parseAttributeInfo(attr); | 253 | + JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), className); |
261 | } | 254 | } |
262 | 255 | ||
263 | /* | 256 | /* |
... | @@ -279,10 +272,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -279,10 +272,6 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
279 | 272 | ||
280 | AttributeInfo newAttr = new AttributeInfo(); | 273 | AttributeInfo newAttr = new AttributeInfo(); |
281 | if (attrType != null) { | 274 | if (attrType != null) { |
282 | - attrType.setDataTypeName(attrType.getDataTypeName().replace("\"", "")); | ||
283 | - if (attrType.getDataTypeName().equals("string")) { | ||
284 | - attrType.setDataTypeName(JavaIdentifierSyntax.getCaptialCase(attrType.getDataTypeName())); | ||
285 | - } | ||
286 | newAttr.setAttributeType(attrType); | 275 | newAttr.setAttributeType(attrType); |
287 | } else { | 276 | } else { |
288 | ImportInfo importInfo = new ImportInfo(); | 277 | ImportInfo importInfo = new ImportInfo(); |
... | @@ -301,6 +290,10 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -301,6 +290,10 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
301 | newAttr.setAttributeName(name); | 290 | newAttr.setAttributeName(name); |
302 | newAttr.setListAttr(isListAttr); | 291 | newAttr.setListAttr(isListAttr); |
303 | 292 | ||
293 | + if (newAttr.isListAttr()) { | ||
294 | + newAttr.setAttributeType(AttributesJavaDataType.getListString(newAttr)); | ||
295 | + } | ||
296 | + | ||
304 | if (isListAttr) { | 297 | if (isListAttr) { |
305 | String listImport = UtilConstants.COLLECTION_IMPORTS + UtilConstants.LIST + UtilConstants.SEMI_COLAN | 298 | String listImport = UtilConstants.COLLECTION_IMPORTS + UtilConstants.LIST + UtilConstants.SEMI_COLAN |
306 | + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; | 299 | + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; |
... | @@ -317,7 +310,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -317,7 +310,7 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
317 | 310 | ||
318 | if (getCachedAttributeList() != null) { | 311 | if (getCachedAttributeList() != null) { |
319 | if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) { | 312 | if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) { |
320 | - flushCacheAttrToSerFile(); | 313 | + flushCacheAttrToSerFile(getYangName()); |
321 | } | 314 | } |
322 | getCachedAttributeList().add(newAttr); | 315 | getCachedAttributeList().add(newAttr); |
323 | } else { | 316 | } else { |
... | @@ -361,89 +354,19 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -361,89 +354,19 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
361 | 354 | ||
362 | String className = getYangName(); | 355 | String className = getYangName(); |
363 | className = JavaIdentifierSyntax.getCaptialCase(className); | 356 | className = JavaIdentifierSyntax.getCaptialCase(className); |
364 | - String packagePath = getPackage(); | 357 | + String filePath = getFilePath(); |
365 | - String filePath = UtilConstants.YANG_GEN_DIR + packagePath.replace(".", "/"); | ||
366 | GeneratedFileType fileType = getGeneratedFileTypes(); | 358 | GeneratedFileType fileType = getGeneratedFileTypes(); |
367 | 359 | ||
368 | - /** | ||
369 | - * Create interface file. | ||
370 | - */ | ||
371 | - String interfaceFileName = className + JAVA_FILE_EXTENSION; | ||
372 | - File interfaceFile = new File(filePath + File.separator + interfaceFileName); | ||
373 | - | ||
374 | - /** | ||
375 | - * Create temp builder interface file. | ||
376 | - */ | ||
377 | - String builderInterfaceFileName = interfaceFileName + TEMP_FILE_EXTENSION; | ||
378 | - File builderInterfaceFile = new File(filePath + File.separator + builderInterfaceFileName); | ||
379 | - | ||
380 | - /** | ||
381 | - * Create builder class file. | ||
382 | - */ | ||
383 | - String builderFileName = className + UtilConstants.BUILDER + JAVA_FILE_EXTENSION; | ||
384 | - File builderFile = new File(filePath + File.separator + builderFileName); | ||
385 | - MethodsGenerator.setBuilderClassName(className + UtilConstants.BUILDER); | ||
386 | - | ||
387 | - /** | ||
388 | - * Create temp impl class file. | ||
389 | - */ | ||
390 | - | ||
391 | - String implFileName = className + UtilConstants.IMPL + TEMP_FILE_EXTENSION; | ||
392 | - File implTempFile = new File(filePath + File.separator + implFileName); | ||
393 | - | ||
394 | /* | 360 | /* |
395 | * TODO: add the file header using | 361 | * TODO: add the file header using |
396 | * JavaCodeSnippetGen.getFileHeaderComment | 362 | * JavaCodeSnippetGen.getFileHeaderComment |
397 | */ | 363 | */ |
398 | 364 | ||
399 | - List<String> attributes = new LinkedList<>(); | ||
400 | - List<String> interfaceMethods = new LinkedList<>(); | ||
401 | - List<String> builderInterfaceMethods = new LinkedList<>(); | ||
402 | - List<String> builderClassMethods = new LinkedList<>(); | ||
403 | - List<String> implClassMethods = new LinkedList<>(); | ||
404 | List<String> imports = new LinkedList<>(); | 365 | List<String> imports = new LinkedList<>(); |
405 | 366 | ||
406 | - try { | ||
407 | - attributes = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.ATTRIBUTE); | ||
408 | - | ||
409 | - interfaceMethods = SerializedDataStore | ||
410 | - .getSerializeData(SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS); | ||
411 | - | ||
412 | - builderInterfaceMethods = SerializedDataStore | ||
413 | - .getSerializeData(SerializedDataStore.SerializedDataStoreType.BUILDER_INTERFACE_METHODS); | ||
414 | - | ||
415 | - builderClassMethods = SerializedDataStore | ||
416 | - .getSerializeData(SerializedDataStore.SerializedDataStoreType.BUILDER_METHODS); | ||
417 | - | ||
418 | - implClassMethods = SerializedDataStore | ||
419 | - .getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPL_METHODS); | ||
420 | - | ||
421 | - imports = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPORT); | ||
422 | - } catch (ClassNotFoundException | IOException e) { | ||
423 | - log.info("There is no attribute info of " + className + " YANG file in the serialized files."); | ||
424 | - } | ||
425 | - | ||
426 | if (getCachedAttributeList() != null) { | 367 | if (getCachedAttributeList() != null) { |
427 | MethodsGenerator.setAttrInfo(getCachedAttributeList()); | 368 | MethodsGenerator.setAttrInfo(getCachedAttributeList()); |
428 | for (AttributeInfo attr : getCachedAttributeList()) { | 369 | for (AttributeInfo attr : getCachedAttributeList()) { |
429 | - if (attr.isListAttr()) { | ||
430 | - String listString = JavaCodeSnippetGen.getListAttribute(attr.getAttributeType().getDataTypeName()); | ||
431 | - @SuppressWarnings("rawtypes") | ||
432 | - YangType<?> type = new YangType(); | ||
433 | - type.setDataTypeName(listString); | ||
434 | - attr.setAttributeType(type); | ||
435 | - } | ||
436 | - | ||
437 | - attributes.add(getAttributeString(attr)); | ||
438 | - | ||
439 | - interfaceMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE)); | ||
440 | - | ||
441 | - builderClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS)); | ||
442 | - | ||
443 | - builderInterfaceMethods | ||
444 | - .add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE)); | ||
445 | - | ||
446 | - implClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL)); | ||
447 | 370 | ||
448 | if (getImportSet() != null) { | 371 | if (getImportSet() != null) { |
449 | imports = new ArrayList<>(getImportSet()); | 372 | imports = new ArrayList<>(getImportSet()); |
... | @@ -451,288 +374,73 @@ public class CachedJavaFileHandle implements CachedFileHandle { | ... | @@ -451,288 +374,73 @@ public class CachedJavaFileHandle implements CachedFileHandle { |
451 | } | 374 | } |
452 | } | 375 | } |
453 | 376 | ||
454 | - builderInterfaceMethods.add(MethodsGenerator.parseBuilderInterfaceBuildMethodString(className)); | ||
455 | - builderClassMethods.add(UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | ||
456 | - + MethodsGenerator.getDefaultConstructorString(GeneratedFileType.BUILDER_CLASS, className)); | ||
457 | - builderClassMethods.add(MethodsGenerator.getBuildString(className)); | ||
458 | - | ||
459 | - implClassMethods.add(UtilConstants.JAVA_DOC_FIRST_LINE | ||
460 | - + MethodsGenerator.getDefaultConstructorString(GeneratedFileType.IMPL, className)); | ||
461 | - implClassMethods.add(MethodsGenerator.getConstructorString(className)); | ||
462 | - | ||
463 | /** | 377 | /** |
464 | * Start generation of files. | 378 | * Start generation of files. |
465 | */ | 379 | */ |
466 | if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) { | 380 | if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) { |
467 | - initiateFile(interfaceFile, className, GeneratedFileType.INTERFACE, imports); | ||
468 | - } | ||
469 | - | ||
470 | - if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) { | ||
471 | - initiateFile(builderFile, className, GeneratedFileType.BUILDER_CLASS, imports); | ||
472 | - } | ||
473 | - | ||
474 | - if (fileType.equals(GeneratedFileType.IMPL) || fileType.equals(GeneratedFileType.ALL)) { | ||
475 | - initiateFile(implTempFile, className, GeneratedFileType.IMPL, imports); | ||
476 | - } | ||
477 | - | ||
478 | - if (fileType.equals(GeneratedFileType.BUILDER_INTERFACE) || fileType.equals(GeneratedFileType.ALL)) { | ||
479 | - initiateFile(builderInterfaceFile, className, GeneratedFileType.BUILDER_INTERFACE, imports); | ||
480 | - } | ||
481 | - | ||
482 | - /** | ||
483 | - * Add attributes to the file. | ||
484 | - */ | ||
485 | - for (String attribute : attributes) { | ||
486 | - insert(builderFile, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute); | ||
487 | - insert(implTempFile, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute); | ||
488 | - } | ||
489 | - | ||
490 | - insert(builderFile, UtilConstants.NEW_LINE); | ||
491 | - insert(implTempFile, UtilConstants.NEW_LINE); | ||
492 | - | ||
493 | - /** | ||
494 | - * Add getter methods to interface file. | ||
495 | - */ | ||
496 | - for (String method : interfaceMethods) { | ||
497 | - appendMethod(interfaceFile, method + UtilConstants.NEW_LINE); | ||
498 | - } | ||
499 | 381 | ||
500 | /** | 382 | /** |
501 | - * Add getters and setters in builder interface. | 383 | + * Create interface file. |
502 | - */ | ||
503 | - for (String method : builderInterfaceMethods) { | ||
504 | - appendMethod(builderInterfaceFile, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); | ||
505 | - } | ||
506 | - | ||
507 | - insert(builderInterfaceFile, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | ||
508 | - /** | ||
509 | - * Add methods in builder class. | ||
510 | */ | 384 | */ |
511 | - for (String method : builderClassMethods) { | 385 | + String interfaceFileName = className; |
512 | - appendMethod(builderFile, method + UtilConstants.NEW_LINE); | 386 | + File interfaceFile = new File(filePath + File.separator + interfaceFileName + JAVA_FILE_EXTENSION); |
513 | - } | 387 | + interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports, |
388 | + getCachedAttributeList(), getPackage()); | ||
514 | 389 | ||
515 | /** | 390 | /** |
516 | - * Add methods in impl class. | 391 | + * Create temp builder interface file. |
517 | */ | 392 | */ |
518 | - for (String method : implClassMethods) { | 393 | + String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE; |
519 | - appendMethod(implTempFile, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); | 394 | + File builderInterfaceFile = new File( |
520 | - } | 395 | + filePath + File.separator + builderInterfaceFileName + TEMP_FILE_EXTENSION); |
521 | - | 396 | + builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className, |
522 | - insert(implTempFile, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | 397 | + getPackage(), getCachedAttributeList()); |
523 | 398 | ||
524 | /** | 399 | /** |
525 | * Append builder interface file to interface file and close it. | 400 | * Append builder interface file to interface file and close it. |
526 | */ | 401 | */ |
527 | - appendFileContents(builderInterfaceFile, interfaceFile); | 402 | + JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile); |
528 | - insert(interfaceFile, closeFile(GeneratedFileType.INTERFACE, interfaceFileName)); | 403 | + JavaFileGenerator.insert(interfaceFile, |
529 | - | 404 | + JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE, interfaceFileName)); |
530 | - /** | ||
531 | - * Append impl class to builder class and close it. | ||
532 | - */ | ||
533 | - appendFileContents(implTempFile, builderFile); | ||
534 | - insert(builderFile, closeFile(GeneratedFileType.BUILDER_CLASS, builderFileName)); | ||
535 | 405 | ||
536 | /** | 406 | /** |
537 | * Remove temp files. | 407 | * Remove temp files. |
538 | */ | 408 | */ |
539 | - clean(implTempFile); | 409 | + JavaFileGenerator.clean(builderInterfaceFile); |
540 | - clean(builderInterfaceFile); | ||
541 | - } | ||
542 | - | ||
543 | - /** | ||
544 | - * Initiate generation of file based on generated file type. | ||
545 | - * | ||
546 | - * @param file generated file | ||
547 | - * @param className generated file class name | ||
548 | - * @param type generated file type | ||
549 | - * @param imports imports for the file | ||
550 | - * @throws IOException when fails to generate a file | ||
551 | - */ | ||
552 | - private void initiateFile(File file, String className, GeneratedFileType type, List<String> imports) | ||
553 | - throws IOException { | ||
554 | - try { | ||
555 | - file.createNewFile(); | ||
556 | - appendContents(file, className, type, imports); | ||
557 | - } catch (IOException e) { | ||
558 | - throw new IOException("Failed to create " + file.getName() + " class file."); | ||
559 | - } | ||
560 | - } | ||
561 | - | ||
562 | - /** | ||
563 | - * Appends the temp files to main files. | ||
564 | - * | ||
565 | - * @param appendFile temp file | ||
566 | - * @param srcFile main file | ||
567 | - */ | ||
568 | - private static void appendFileContents(File appendFile, File srcFile) throws IOException { | ||
569 | - try { | ||
570 | - FileSystemUtil.appendFileContents(appendFile, srcFile); | ||
571 | - } catch (IOException e) { | ||
572 | - throw new IOException("Failed to append " + appendFile + " in " + srcFile); | ||
573 | - } | ||
574 | - } | ||
575 | - | ||
576 | - /** | ||
577 | - * Append methods to the generated files. | ||
578 | - * | ||
579 | - * @param file file in which method needs to be appended. | ||
580 | - * @param method method which needs to be appended. | ||
581 | - */ | ||
582 | - private static void appendMethod(File file, String method) throws IOException { | ||
583 | - insert(file, method); | ||
584 | - } | ||
585 | - | ||
586 | - /** | ||
587 | - * Closes the current generated file. | ||
588 | - * | ||
589 | - * @param fileType generate file type | ||
590 | - * @param yangName file name | ||
591 | - * @return end of class definition string. | ||
592 | - */ | ||
593 | - private static String closeFile(GeneratedFileType fileType, String yangName) { | ||
594 | - return JavaCodeSnippetGen.getJavaClassDefClose(fileType, yangName); | ||
595 | - } | ||
596 | - | ||
597 | - /** | ||
598 | - * Parses attribute info and fetch specific data and creates serialized | ||
599 | - * files of it. | ||
600 | - * | ||
601 | - * @param attr attribute info. | ||
602 | - */ | ||
603 | - private void parseAttributeInfo(AttributeInfo attr) { | ||
604 | - | ||
605 | - String attrString = ""; | ||
606 | - String methodString = ""; | ||
607 | - String getterString = ""; | ||
608 | - | ||
609 | - try { | ||
610 | - /* | ||
611 | - * Serialize attributes. | ||
612 | - */ | ||
613 | - attrString = getAttributeString(attr); | ||
614 | - attrString = attrString.replace("\"", ""); | ||
615 | - SerializedDataStore.setSerializeData(attrString, SerializedDataStore.SerializedDataStoreType.ATTRIBUTE); | ||
616 | - | ||
617 | - if (getGeneratedFileTypes().equals(GeneratedFileType.ALL)) { | ||
618 | - | ||
619 | - methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE); | ||
620 | - SerializedDataStore.setSerializeData(methodString, | ||
621 | - SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS); | ||
622 | - | ||
623 | - methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS); | ||
624 | - SerializedDataStore.setSerializeData(methodString, | ||
625 | - SerializedDataStore.SerializedDataStoreType.BUILDER_METHODS); | ||
626 | - | ||
627 | - methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE); | ||
628 | - SerializedDataStore.setSerializeData(methodString, | ||
629 | - SerializedDataStore.SerializedDataStoreType.BUILDER_INTERFACE_METHODS); | ||
630 | - | ||
631 | - methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL); | ||
632 | - SerializedDataStore.setSerializeData(methodString, | ||
633 | - SerializedDataStore.SerializedDataStoreType.IMPL_METHODS); | ||
634 | - | ||
635 | - } else if (getGeneratedFileTypes().equals(GeneratedFileType.INTERFACE)) { | ||
636 | - | ||
637 | - getterString = MethodsGenerator.getGetterString(attr); | ||
638 | - SerializedDataStore.setSerializeData(methodString, | ||
639 | - SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS); | ||
640 | - } | ||
641 | - } catch (IOException e) { | ||
642 | - log.info("Failed to get data for " + attr.getAttributeName() + " from serialized files."); | ||
643 | - } | ||
644 | } | 410 | } |
645 | 411 | ||
646 | - /** | 412 | + if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) { |
647 | - * Returns attribute string. | ||
648 | - * | ||
649 | - * @param attr attribute info | ||
650 | - * @return attribute string | ||
651 | - */ | ||
652 | - private String getAttributeString(AttributeInfo attr) { | ||
653 | - return JavaCodeSnippetGen.getJavaAttributeInfo(getGeneratedFileTypes(), attr.getAttributeName(), | ||
654 | - attr.getAttributeType()); | ||
655 | - } | ||
656 | 413 | ||
657 | /** | 414 | /** |
658 | - * Appends all the contents into a generated java file. | 415 | + * Create builder class file. |
659 | - * | ||
660 | - * @param file generated file | ||
661 | - * @param fileName generated file name | ||
662 | - * @param type generated file type | ||
663 | */ | 416 | */ |
664 | - private void appendContents(File file, String fileName, GeneratedFileType type, List<String> importsList) | 417 | + String builderFileName = className + UtilConstants.BUILDER; |
665 | - throws IOException { | 418 | + File builderFile = new File(filePath + File.separator + builderFileName + JAVA_FILE_EXTENSION); |
666 | - | 419 | + MethodsGenerator.setBuilderClassName(className + UtilConstants.BUILDER); |
667 | - if (type.equals(GeneratedFileType.IMPL)) { | ||
668 | - | ||
669 | - write(file, fileName, type, JavaDocType.IMPL_CLASS); | ||
670 | - } else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) { | ||
671 | - | ||
672 | - write(file, fileName, type, JavaDocType.BUILDER_INTERFACE); | ||
673 | - } else { | ||
674 | - | ||
675 | - // TODO: handle imports for attributes. | ||
676 | 420 | ||
677 | - if (type.equals(GeneratedFileType.INTERFACE)) { | 421 | + builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, getPackage(), |
678 | - insert(file, CopyrightHeader.getCopyrightHeader()); | 422 | + getCachedAttributeList()); |
679 | - insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN | ||
680 | - + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE); | ||
681 | - for (String imports : importsList) { | ||
682 | - insert(file, imports); | ||
683 | - } | ||
684 | - insert(file, UtilConstants.NEW_LINE); | ||
685 | - write(file, fileName, type, JavaDocType.INTERFACE); | ||
686 | - } else if (type.equals(GeneratedFileType.BUILDER_CLASS)) { | ||
687 | - insert(file, CopyrightHeader.getCopyrightHeader()); | ||
688 | - insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN | ||
689 | - + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE); | ||
690 | - for (String imports : importsList) { | ||
691 | - insert(file, imports); | ||
692 | - } | ||
693 | - insert(file, UtilConstants.NEW_LINE); | ||
694 | - write(file, fileName, type, JavaDocType.BUILDER_CLASS); | ||
695 | - } | ||
696 | - } | ||
697 | - } | ||
698 | 423 | ||
699 | /** | 424 | /** |
700 | - * Write data to the specific generated file. | 425 | + * Create temp impl class file. |
701 | - * | ||
702 | - * @param file generated file | ||
703 | - * @param fileName file name | ||
704 | - * @param genType generated file type | ||
705 | - * @param javaDocType java doc type | ||
706 | */ | 426 | */ |
707 | - private static void write(File file, String fileName, GeneratedFileType genType, JavaDocGen.JavaDocType javaDocType) | ||
708 | - throws IOException { | ||
709 | 427 | ||
710 | - insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName)); | 428 | + String implFileName = className + UtilConstants.IMPL; |
711 | - insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName)); | 429 | + File implTempFile = new File(filePath + File.separator + implFileName + TEMP_FILE_EXTENSION); |
712 | - } | 430 | + implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, getPackage(), |
431 | + getCachedAttributeList()); | ||
713 | 432 | ||
714 | /** | 433 | /** |
715 | - * Insert in the generated file. | 434 | + * Append impl class to builder class and close it. |
716 | - * | ||
717 | - * @param file file in which need to be inserted. | ||
718 | - * @param data data which need to be inserted. | ||
719 | */ | 435 | */ |
720 | - private static void insert(File file, String data) throws IOException { | 436 | + JavaFileGenerator.appendFileContents(implTempFile, builderFile); |
721 | - try { | 437 | + JavaFileGenerator.insert(builderFile, |
722 | - FileSystemUtil.insertStringInFile(file, data); | 438 | + JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS, builderFileName)); |
723 | - } catch (IOException e) { | ||
724 | - throw new IOException("Failed to insert in " + file + "file"); | ||
725 | - } | ||
726 | - } | ||
727 | 439 | ||
728 | /** | 440 | /** |
729 | - * Removes temp files. | 441 | + * Remove temp files. |
730 | - * | ||
731 | - * @param file file to be removed. | ||
732 | */ | 442 | */ |
733 | - private static void clean(File file) { | 443 | + JavaFileGenerator.clean(implTempFile); |
734 | - if (file.exists()) { | ||
735 | - file.delete(); | ||
736 | } | 444 | } |
737 | } | 445 | } |
738 | } | 446 | } | ... | ... |
... | @@ -42,21 +42,22 @@ public final class JavaCodeGenerator { | ... | @@ -42,21 +42,22 @@ public final class JavaCodeGenerator { |
42 | TraversalType curTraversal = TraversalType.ROOT; | 42 | TraversalType curTraversal = TraversalType.ROOT; |
43 | 43 | ||
44 | while (!(curNode == null)) { | 44 | while (!(curNode == null)) { |
45 | - if (curTraversal != TraversalType.PARENT || curTraversal == TraversalType.SIBILING) { | 45 | + if (curTraversal != TraversalType.PARENT) { |
46 | curNode.generateJavaCodeEntry(); | 46 | curNode.generateJavaCodeEntry(); |
47 | } | 47 | } |
48 | - if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) { | 48 | + if (curTraversal != TraversalType.PARENT && (curNode.getChild() != null)) { |
49 | curTraversal = TraversalType.CHILD; | 49 | curTraversal = TraversalType.CHILD; |
50 | curNode = curNode.getChild(); | 50 | curNode = curNode.getChild(); |
51 | - } else if (curTraversal == TraversalType.PARENT && !(curNode.getNextSibling() == null)) { | 51 | + } else if ((curNode.getNextSibling() != null)) { |
52 | curNode.generateJavaCodeExit(); | 52 | curNode.generateJavaCodeExit(); |
53 | curTraversal = TraversalType.SIBILING; | 53 | curTraversal = TraversalType.SIBILING; |
54 | curNode = curNode.getNextSibling(); | 54 | curNode = curNode.getNextSibling(); |
55 | } else { | 55 | } else { |
56 | - curNode.generateJavaCodeExit(); | ||
57 | curTraversal = TraversalType.PARENT; | 56 | curTraversal = TraversalType.PARENT; |
57 | + curNode.generateJavaCodeExit(); | ||
58 | curNode = curNode.getParent(); | 58 | curNode = curNode.getParent(); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | + | ||
61 | } | 62 | } |
62 | } | 63 | } | ... | ... |
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 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
20 | +import org.onosproject.yangutils.datamodel.YangType; | ||
21 | +import org.onosproject.yangutils.translator.tojava.AttributeInfo; | ||
22 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
23 | + | ||
24 | +/** | ||
25 | + * Provides java data types corresponding to YANG type. | ||
26 | + */ | ||
27 | +public final class AttributesJavaDataType { | ||
28 | + | ||
29 | + /** | ||
30 | + * Default constructor. | ||
31 | + */ | ||
32 | + private AttributesJavaDataType() { | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Returns YANG type. | ||
37 | + * | ||
38 | + * @param yangType YANG type | ||
39 | + * @return YANG type | ||
40 | + */ | ||
41 | + public static YangType<?> getJavaDataType(YangType<?> yangType) { | ||
42 | + yangType.setDataTypeName(yangType.getDataTypeName().replace("\"", "")); | ||
43 | + if (yangType.getDataType() != null) { | ||
44 | + yangType.setDataTypeName(parseYangDataType(yangType.getDataType())); | ||
45 | + } | ||
46 | + return yangType; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns list string as attribute name when attribute is a list. | ||
51 | + * | ||
52 | + * @param attr attribute info. | ||
53 | + * @return list attribute | ||
54 | + */ | ||
55 | + @SuppressWarnings("rawtypes") | ||
56 | + public static YangType<?> getListString(AttributeInfo attr) { | ||
57 | + String listString = JavaCodeSnippetGen.getListAttribute(attr.getAttributeType().getDataTypeName()); | ||
58 | + YangType<?> type = new YangType(); | ||
59 | + type.setDataTypeName(listString); | ||
60 | + attr.setAttributeType(type); | ||
61 | + return type; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Parses YANG data type and returns corresponding java data type. | ||
66 | + * | ||
67 | + * @param type YANG data type | ||
68 | + * @return java data type | ||
69 | + */ | ||
70 | + private static String parseYangDataType(YangDataTypes type) { | ||
71 | + if (type.equals(YangDataTypes.INT8)) { | ||
72 | + return UtilConstants.BYTE; | ||
73 | + } else if (type.equals(YangDataTypes.INT16)) { | ||
74 | + return UtilConstants.SHORT; | ||
75 | + } else if (type.equals(YangDataTypes.INT32)) { | ||
76 | + return UtilConstants.INT; | ||
77 | + } else if (type.equals(YangDataTypes.INT64)) { | ||
78 | + return UtilConstants.LONG; | ||
79 | + } else if (type.equals(YangDataTypes.UINT8)) { | ||
80 | + return UtilConstants.SHORT; | ||
81 | + } else if (type.equals(YangDataTypes.UINT16)) { | ||
82 | + return UtilConstants.INT; | ||
83 | + } else if (type.equals(YangDataTypes.UINT32)) { | ||
84 | + return UtilConstants.LONG; | ||
85 | + } else if (type.equals(YangDataTypes.UINT64)) { | ||
86 | + //TODO: BIGINTEGER. | ||
87 | + } else if (type.equals(YangDataTypes.DECIMAL64)) { | ||
88 | + //TODO: DECIMAL64. | ||
89 | + } else if (type.equals(YangDataTypes.STRING)) { | ||
90 | + return UtilConstants.STRING; | ||
91 | + } else if (type.equals(YangDataTypes.BOOLEAN)) { | ||
92 | + return UtilConstants.BOOLEAN; | ||
93 | + } else if (type.equals(YangDataTypes.ENUMERATION)) { | ||
94 | + //TODO: ENUMERATION. | ||
95 | + } else if (type.equals(YangDataTypes.BITS)) { | ||
96 | + //TODO:BITS | ||
97 | + } else if (type.equals(YangDataTypes.BINARY)) { | ||
98 | + //TODO:BINARY | ||
99 | + } else if (type.equals(YangDataTypes.LEAFREF)) { | ||
100 | + //TODO:LEAFREF | ||
101 | + } else if (type.equals(YangDataTypes.IDENTITYREF)) { | ||
102 | + //TODO:IDENTITYREF | ||
103 | + } else if (type.equals(YangDataTypes.EMPTY)) { | ||
104 | + //TODO:EMPTY | ||
105 | + } else if (type.equals(YangDataTypes.UNION)) { | ||
106 | + //TODO:UNION | ||
107 | + } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | ||
108 | + //TODO:INSTANCE_IDENTIFIER | ||
109 | + } else if (type.equals(YangDataTypes.DERIVED)) { | ||
110 | + //TODO:DERIVED | ||
111 | + } | ||
112 | + return null; | ||
113 | + } | ||
114 | +} |
... | @@ -16,9 +16,6 @@ | ... | @@ -16,9 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import java.util.List; | ||
20 | -import java.util.SortedSet; | ||
21 | - | ||
22 | import org.onosproject.yangutils.datamodel.YangType; | 19 | import org.onosproject.yangutils.datamodel.YangType; |
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; |
... | @@ -50,17 +47,6 @@ public final class JavaCodeSnippetGen { | ... | @@ -50,17 +47,6 @@ public final class JavaCodeSnippetGen { |
50 | } | 47 | } |
51 | 48 | ||
52 | /** | 49 | /** |
53 | - * reorder the import list based on the ONOS import rules. | ||
54 | - * | ||
55 | - * @param importInfo the set of classes/interfaces to be imported. | ||
56 | - * @return string of import info. | ||
57 | - */ | ||
58 | - public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) { | ||
59 | - /* TODO: reorder the import list based on the ONOS import rules. */ | ||
60 | - return null; | ||
61 | - } | ||
62 | - | ||
63 | - /** | ||
64 | * Get the textual java code information corresponding to the import list. | 50 | * Get the textual java code information corresponding to the import list. |
65 | * | 51 | * |
66 | * @param importInfo import info. | 52 | * @param importInfo import info. | ... | ... |
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 | +import java.io.File; | ||
20 | +import java.io.IOException; | ||
21 | +import java.util.LinkedList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +import org.onosproject.yangutils.translator.GeneratedFileType; | ||
25 | +import org.onosproject.yangutils.translator.tojava.AttributeInfo; | ||
26 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
27 | +import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; | ||
28 | +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | ||
29 | +import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | ||
30 | +import org.onosproject.yangutils.utils.io.impl.TempDataStore; | ||
31 | +import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
32 | +import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType; | ||
33 | + | ||
34 | +import static org.slf4j.LoggerFactory.getLogger; | ||
35 | +import org.slf4j.Logger; | ||
36 | + | ||
37 | +public final class JavaFileGenerator { | ||
38 | + | ||
39 | + private static final Logger log = getLogger(JavaFileGenerator.class); | ||
40 | + | ||
41 | + /** | ||
42 | + * Default constructor. | ||
43 | + */ | ||
44 | + private JavaFileGenerator() { | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Returns generated interface file for current node. | ||
49 | + * @param file file | ||
50 | + * @param className class name | ||
51 | + * @param imports imports for the file | ||
52 | + * @param attrList attribute info | ||
53 | + * @param pkg generated file package | ||
54 | + * @return interface file | ||
55 | + * @throws IOException when fails to write in file. | ||
56 | + */ | ||
57 | + public static File generateInterfaceFile(File file, String className, List<String> imports, | ||
58 | + List<AttributeInfo> attrList, String pkg) throws IOException { | ||
59 | + | ||
60 | + initiateFile(file, className, GeneratedFileType.INTERFACE, imports, pkg); | ||
61 | + List<String> methods = getMethodStrings(TempDataStoreType.GETTER_METHODS, GeneratedFileType.INTERFACE, | ||
62 | + className, file, attrList); | ||
63 | + | ||
64 | + /** | ||
65 | + * Add getter methods to interface file. | ||
66 | + */ | ||
67 | + for (String method : methods) { | ||
68 | + appendMethod(file, method); | ||
69 | + } | ||
70 | + return file; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Return generated builder interface file for current node. | ||
75 | + * @param file file | ||
76 | + * @param className class name | ||
77 | + * @param pkg generated file package | ||
78 | + * @param attrList attribute info | ||
79 | + * @return builder interface file | ||
80 | + * @throws IOException when fails to write in file. | ||
81 | + */ | ||
82 | + public static File generateBuilderInterfaceFile(File file, String className, String pkg, | ||
83 | + List<AttributeInfo> attrList) throws IOException { | ||
84 | + | ||
85 | + initiateFile(file, className, GeneratedFileType.BUILDER_INTERFACE, null, pkg); | ||
86 | + List<String> methods = getMethodStrings(TempDataStoreType.BUILDER_INTERFACE_METHODS, | ||
87 | + GeneratedFileType.BUILDER_INTERFACE, className, file, attrList); | ||
88 | + | ||
89 | + /** | ||
90 | + * Add build method to builder interface file. | ||
91 | + */ | ||
92 | + methods.add(MethodsGenerator.parseBuilderInterfaceBuildMethodString(className)); | ||
93 | + | ||
94 | + /** | ||
95 | + * Add getters and setters in builder interface. | ||
96 | + */ | ||
97 | + for (String method : methods) { | ||
98 | + appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); | ||
99 | + } | ||
100 | + | ||
101 | + insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | ||
102 | + return file; | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Returns generated builder class file for current node. | ||
107 | + * @param file file | ||
108 | + * @param className class name | ||
109 | + * @param imports imports for the file | ||
110 | + * @param pkg generated file package | ||
111 | + * @param attrList attribute info | ||
112 | + * @return builder class file | ||
113 | + * @throws IOException when fails to write in file. | ||
114 | + */ | ||
115 | + public static File generateBuilderClassFile(File file, String className, List<String> imports, String pkg, | ||
116 | + List<AttributeInfo> attrList) throws IOException { | ||
117 | + | ||
118 | + initiateFile(file, className, GeneratedFileType.BUILDER_CLASS, imports, pkg); | ||
119 | + List<String> methods = getMethodStrings(TempDataStoreType.BUILDER_METHODS, GeneratedFileType.BUILDER_CLASS, | ||
120 | + className, file, attrList); | ||
121 | + | ||
122 | + /** | ||
123 | + * Add default constructor and build method impl. | ||
124 | + */ | ||
125 | + methods.add(UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | ||
126 | + + MethodsGenerator.getDefaultConstructorString(GeneratedFileType.BUILDER_CLASS, className)); | ||
127 | + methods.add(MethodsGenerator.getBuildString(className)); | ||
128 | + | ||
129 | + /** | ||
130 | + * Add attribute strings. | ||
131 | + */ | ||
132 | + addAttributeSring(file, className, attrList, GeneratedFileType.BUILDER_CLASS); | ||
133 | + | ||
134 | + /** | ||
135 | + * Add methods in builder class. | ||
136 | + */ | ||
137 | + for (String method : methods) { | ||
138 | + appendMethod(file, method + UtilConstants.NEW_LINE); | ||
139 | + } | ||
140 | + return file; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Returns generated impl class file for current node. | ||
145 | + * @param file file | ||
146 | + * @param className class name | ||
147 | + * @param pkg generated file package | ||
148 | + * @param attrList attribute's info | ||
149 | + * @return impl class file | ||
150 | + * @throws IOException when fails to write in file. | ||
151 | + */ | ||
152 | + public static File generateImplClassFile(File file, String className, String pkg, List<AttributeInfo> attrList) | ||
153 | + throws IOException { | ||
154 | + | ||
155 | + initiateFile(file, className, GeneratedFileType.IMPL, null, pkg); | ||
156 | + List<String> methods = getMethodStrings(TempDataStoreType.IMPL_METHODS, GeneratedFileType.IMPL, className, file, | ||
157 | + attrList); | ||
158 | + | ||
159 | + /** | ||
160 | + * Add attributes. | ||
161 | + */ | ||
162 | + addAttributeSring(file, className, attrList, GeneratedFileType.IMPL); | ||
163 | + | ||
164 | + /** | ||
165 | + * Add default constructor and constructor methods. | ||
166 | + */ | ||
167 | + methods.add(UtilConstants.JAVA_DOC_FIRST_LINE | ||
168 | + + MethodsGenerator.getDefaultConstructorString(GeneratedFileType.IMPL, className)); | ||
169 | + methods.add(MethodsGenerator.getConstructorString(className)); | ||
170 | + | ||
171 | + /** | ||
172 | + * Add methods in impl class. | ||
173 | + */ | ||
174 | + for (String method : methods) { | ||
175 | + appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); | ||
176 | + } | ||
177 | + insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | ||
178 | + | ||
179 | + return file; | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Adds attribute string for generated files. | ||
184 | + * | ||
185 | + * @param className class name | ||
186 | + * @param file generated file | ||
187 | + * @param attrList attribute info | ||
188 | + * @param genFileType generated file type | ||
189 | + * @param IOException when fails to add attributes in files. | ||
190 | + */ | ||
191 | + private static void addAttributeSring(File file, String className, List<AttributeInfo> attrList, | ||
192 | + GeneratedFileType genFileType) throws IOException { | ||
193 | + List<String> attributes = new LinkedList<>(); | ||
194 | + try { | ||
195 | + attributes = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, className); | ||
196 | + } catch (ClassNotFoundException | IOException e) { | ||
197 | + log.info("There is no attribute info of " + className + " YANG file in the serialized files."); | ||
198 | + } | ||
199 | + | ||
200 | + if (attrList != null) { | ||
201 | + MethodsGenerator.setAttrInfo(attrList); | ||
202 | + for (AttributeInfo attr : attrList) { | ||
203 | + if (attr.isListAttr()) { | ||
204 | + attr.setAttributeType(AttributesJavaDataType.getListString(attr)); | ||
205 | + } | ||
206 | + attributes.add(getAttributeString(attr, genFileType)); | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Add attributes to the file. | ||
212 | + */ | ||
213 | + for (String attribute : attributes) { | ||
214 | + insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute); | ||
215 | + } | ||
216 | + insert(file, UtilConstants.NEW_LINE); | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * Returns method strings for generated files. | ||
221 | + * | ||
222 | + * @param dataStoreType temp data store file type. | ||
223 | + * @param genFileType generated file type | ||
224 | + * @param className generated file name | ||
225 | + * @param attrList attribute info | ||
226 | + * @return method strings | ||
227 | + */ | ||
228 | + private static List<String> getMethodStrings(TempDataStoreType dataStoreType, GeneratedFileType genFileType, | ||
229 | + String className, File file, List<AttributeInfo> attrList) { | ||
230 | + | ||
231 | + List<String> methods = new LinkedList<>(); | ||
232 | + try { | ||
233 | + methods = TempDataStore.getTempData(dataStoreType, className); | ||
234 | + } catch (ClassNotFoundException | IOException e) { | ||
235 | + log.info("There is no attribute info of " + className + " YANG file in the serialized files."); | ||
236 | + } | ||
237 | + | ||
238 | + if (attrList != null) { | ||
239 | + MethodsGenerator.setAttrInfo(attrList); | ||
240 | + for (AttributeInfo attr : attrList) { | ||
241 | + if (attr.isListAttr()) { | ||
242 | + attr.setAttributeType(AttributesJavaDataType.getListString(attr)); | ||
243 | + } | ||
244 | + methods.add(MethodsGenerator.getMethodString(attr, genFileType)); | ||
245 | + } | ||
246 | + } | ||
247 | + return methods; | ||
248 | + } | ||
249 | + | ||
250 | + /** | ||
251 | + * Initiate generation of file based on generated file type. | ||
252 | + * | ||
253 | + * @param file generated file | ||
254 | + * @param className generated file class name | ||
255 | + * @param type generated file type | ||
256 | + * @param imports imports for the file | ||
257 | + * @param pkg generated file package | ||
258 | + * @throws IOException when fails to generate a file | ||
259 | + */ | ||
260 | + private static void initiateFile(File file, String className, GeneratedFileType type, List<String> imports, | ||
261 | + String pkg) throws IOException { | ||
262 | + try { | ||
263 | + file.createNewFile(); | ||
264 | + appendContents(file, className, type, imports, pkg); | ||
265 | + } catch (IOException e) { | ||
266 | + throw new IOException("Failed to create " + file.getName() + " class file."); | ||
267 | + } | ||
268 | + } | ||
269 | + | ||
270 | + /** | ||
271 | + * Appends the temp files to main files. | ||
272 | + * | ||
273 | + * @param appendFile temp file | ||
274 | + * @param srcFile main file | ||
275 | + * @throws IOException when fails to append contents. | ||
276 | + */ | ||
277 | + public static void appendFileContents(File appendFile, File srcFile) throws IOException { | ||
278 | + try { | ||
279 | + FileSystemUtil.appendFileContents(appendFile, srcFile); | ||
280 | + } catch (IOException e) { | ||
281 | + throw new IOException("Failed to append " + appendFile + " in " + srcFile); | ||
282 | + } | ||
283 | + } | ||
284 | + | ||
285 | + /** | ||
286 | + * Append methods to the generated files. | ||
287 | + * | ||
288 | + * @param file file in which method needs to be appended. | ||
289 | + * @param method method which needs to be appended. | ||
290 | + */ | ||
291 | + private static void appendMethod(File file, String method) throws IOException { | ||
292 | + insert(file, method); | ||
293 | + } | ||
294 | + | ||
295 | + /** | ||
296 | + * Closes the current generated file. | ||
297 | + * | ||
298 | + * @param fileType generate file type | ||
299 | + * @param yangName file name | ||
300 | + * @return end of class definition string. | ||
301 | + */ | ||
302 | + public static String closeFile(GeneratedFileType fileType, String yangName) { | ||
303 | + return JavaCodeSnippetGen.getJavaClassDefClose(fileType, yangName); | ||
304 | + } | ||
305 | + | ||
306 | + /** | ||
307 | + * Parses attribute info and fetch specific data and creates serialized | ||
308 | + * files of it. | ||
309 | + * | ||
310 | + * @param attr attribute info. | ||
311 | + * @param genFileType generated file type | ||
312 | + * @param className class name | ||
313 | + */ | ||
314 | + public static void parseAttributeInfo(AttributeInfo attr, GeneratedFileType genFileType, String className) { | ||
315 | + | ||
316 | + String attrString = ""; | ||
317 | + String methodString = ""; | ||
318 | + String getterString = ""; | ||
319 | + | ||
320 | + try { | ||
321 | + /* | ||
322 | + * Serialize attributes. | ||
323 | + */ | ||
324 | + attrString = getAttributeString(attr, genFileType); | ||
325 | + attrString = attrString.replace("\"", ""); | ||
326 | + TempDataStore.setTempData(attrString, TempDataStore.TempDataStoreType.ATTRIBUTE, className); | ||
327 | + | ||
328 | + if (genFileType.equals(GeneratedFileType.ALL)) { | ||
329 | + | ||
330 | + methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE); | ||
331 | + TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.GETTER_METHODS, className); | ||
332 | + | ||
333 | + methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS); | ||
334 | + TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.BUILDER_METHODS, className); | ||
335 | + | ||
336 | + methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE); | ||
337 | + TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.BUILDER_INTERFACE_METHODS, | ||
338 | + className); | ||
339 | + | ||
340 | + methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL); | ||
341 | + TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.IMPL_METHODS, className); | ||
342 | + | ||
343 | + } else if (genFileType.equals(GeneratedFileType.INTERFACE)) { | ||
344 | + | ||
345 | + getterString = MethodsGenerator.getGetterString(attr); | ||
346 | + TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.GETTER_METHODS, className); | ||
347 | + } | ||
348 | + } catch (IOException e) { | ||
349 | + log.info("Failed to get data for " + attr.getAttributeName() + " from serialized files."); | ||
350 | + } | ||
351 | + } | ||
352 | + | ||
353 | + /** | ||
354 | + * Returns attribute string. | ||
355 | + * | ||
356 | + * @param attr attribute info | ||
357 | + * @param genFileType generated file type | ||
358 | + * @return attribute string | ||
359 | + */ | ||
360 | + private static String getAttributeString(AttributeInfo attr, GeneratedFileType genFileType) { | ||
361 | + return JavaCodeSnippetGen.getJavaAttributeInfo(genFileType, attr.getAttributeName(), attr.getAttributeType()); | ||
362 | + } | ||
363 | + | ||
364 | + /** | ||
365 | + * Appends all the contents into a generated java file. | ||
366 | + * | ||
367 | + * @param file generated file | ||
368 | + * @param fileName generated file name | ||
369 | + * @param type generated file type | ||
370 | + * @param pkg generated file package | ||
371 | + * @throws IOException when fails to append contents. | ||
372 | + */ | ||
373 | + private static void appendContents(File file, String fileName, GeneratedFileType type, List<String> importsList, | ||
374 | + String pkg) throws IOException { | ||
375 | + | ||
376 | + if (type.equals(GeneratedFileType.IMPL)) { | ||
377 | + | ||
378 | + write(file, fileName, type, JavaDocType.IMPL_CLASS); | ||
379 | + } else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) { | ||
380 | + | ||
381 | + write(file, fileName, type, JavaDocType.BUILDER_INTERFACE); | ||
382 | + } else { | ||
383 | + | ||
384 | + if (type.equals(GeneratedFileType.INTERFACE)) { | ||
385 | + insert(file, CopyrightHeader.getCopyrightHeader()); | ||
386 | + insert(file, "package" + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE); | ||
387 | + if (importsList != null) { | ||
388 | + insert(file, UtilConstants.NEW_LINE); | ||
389 | + for (String imports : importsList) { | ||
390 | + insert(file, imports); | ||
391 | + } | ||
392 | + insert(file, UtilConstants.NEW_LINE); | ||
393 | + } | ||
394 | + insert(file, UtilConstants.NEW_LINE); | ||
395 | + write(file, fileName, type, JavaDocType.INTERFACE); | ||
396 | + } else if (type.equals(GeneratedFileType.BUILDER_CLASS)) { | ||
397 | + insert(file, CopyrightHeader.getCopyrightHeader()); | ||
398 | + insert(file, "package" + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE); | ||
399 | + if (importsList != null) { | ||
400 | + insert(file, UtilConstants.NEW_LINE); | ||
401 | + for (String imports : importsList) { | ||
402 | + insert(file, imports); | ||
403 | + } | ||
404 | + insert(file, UtilConstants.NEW_LINE); | ||
405 | + } | ||
406 | + insert(file, UtilConstants.NEW_LINE); | ||
407 | + write(file, fileName, type, JavaDocType.BUILDER_CLASS); | ||
408 | + } | ||
409 | + } | ||
410 | + } | ||
411 | + | ||
412 | + /** | ||
413 | + * Write data to the specific generated file. | ||
414 | + * | ||
415 | + * @param file generated file | ||
416 | + * @param fileName file name | ||
417 | + * @param genType generated file type | ||
418 | + * @param javaDocType java doc type | ||
419 | + * @throws IOException when fails to write into a file. | ||
420 | + */ | ||
421 | + private static void write(File file, String fileName, GeneratedFileType genType, JavaDocGen.JavaDocType javaDocType) | ||
422 | + throws IOException { | ||
423 | + | ||
424 | + insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName)); | ||
425 | + insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName)); | ||
426 | + } | ||
427 | + | ||
428 | + /** | ||
429 | + * Insert in the generated file. | ||
430 | + * | ||
431 | + * @param file file in which need to be inserted. | ||
432 | + * @param data data which need to be inserted. | ||
433 | + * @throws IOException when fails to insert into file | ||
434 | + */ | ||
435 | + public static void insert(File file, String data) throws IOException { | ||
436 | + try { | ||
437 | + FileSystemUtil.insertStringInFile(file, data); | ||
438 | + } catch (IOException e) { | ||
439 | + throw new IOException("Failed to insert in " + file + "file"); | ||
440 | + } | ||
441 | + } | ||
442 | + | ||
443 | + /** | ||
444 | + * Removes temp files. | ||
445 | + * | ||
446 | + * @param file file to be removed. | ||
447 | + */ | ||
448 | + public static void clean(File file) { | ||
449 | + if (file.exists()) { | ||
450 | + file.delete(); | ||
451 | + } | ||
452 | + } | ||
453 | +} |
... | @@ -50,7 +50,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -50,7 +50,7 @@ public final class JavaIdentifierSyntax { |
50 | pkg = pkg + UtilConstants.PERIOD; | 50 | pkg = pkg + UtilConstants.PERIOD; |
51 | pkg = pkg + getYangRevisionStr(revision); | 51 | pkg = pkg + getYangRevisionStr(revision); |
52 | 52 | ||
53 | - return pkg; | 53 | + return pkg.toLowerCase(); |
54 | } | 54 | } |
55 | 55 | ||
56 | /** | 56 | /** |
... | @@ -126,11 +126,11 @@ public final class JavaIdentifierSyntax { | ... | @@ -126,11 +126,11 @@ public final class JavaIdentifierSyntax { |
126 | * Get the package from parent's package and string. | 126 | * Get the package from parent's package and string. |
127 | * | 127 | * |
128 | * @param parentPkg parent's package. | 128 | * @param parentPkg parent's package. |
129 | - * @param childName child's name. | 129 | + * @param parentName parent's name. |
130 | * @return package string. | 130 | * @return package string. |
131 | */ | 131 | */ |
132 | - public static String getPackageFromParent(String parentPkg, String childName) { | 132 | + public static String getPackageFromParent(String parentPkg, String parentName) { |
133 | - return parentPkg + UtilConstants.PERIOD + getSubPkgFromName(childName); | 133 | + return (parentPkg + UtilConstants.PERIOD + getSubPkgFromName(parentName)).toLowerCase(); |
134 | } | 134 | } |
135 | 135 | ||
136 | /** | 136 | /** | ... | ... |
... | @@ -109,6 +109,7 @@ public final class MethodsGenerator { | ... | @@ -109,6 +109,7 @@ public final class MethodsGenerator { |
109 | * @param returnType return type of method | 109 | * @param returnType return type of method |
110 | * @return constructed method impl | 110 | * @return constructed method impl |
111 | */ | 111 | */ |
112 | + @SuppressWarnings("rawtypes") | ||
112 | public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName, | 113 | public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName, |
113 | GeneratedMethodTypes methodTypes, YangType<?> returnType) { | 114 | GeneratedMethodTypes methodTypes, YangType<?> returnType) { |
114 | 115 | ||
... | @@ -187,8 +188,7 @@ public final class MethodsGenerator { | ... | @@ -187,8 +188,7 @@ public final class MethodsGenerator { |
187 | attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType()); | 188 | attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType()); |
188 | String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, | 189 | String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, |
189 | attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType()); | 190 | attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType()); |
190 | - return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString | 191 | + return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString; |
191 | - + UtilConstants.NEW_LINE; | ||
192 | } | 192 | } |
193 | 193 | ||
194 | /** | 194 | /** |
... | @@ -201,8 +201,7 @@ public final class MethodsGenerator { | ... | @@ -201,8 +201,7 @@ public final class MethodsGenerator { |
201 | 201 | ||
202 | return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE | 202 | return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE |
203 | + UtilConstants.NEW_LINE + JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, | 203 | + UtilConstants.NEW_LINE + JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, |
204 | - attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType()) | 204 | + attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType()); |
205 | - + UtilConstants.NEW_LINE; | ||
206 | } | 205 | } |
207 | 206 | ||
208 | /** | 207 | /** |
... | @@ -400,8 +399,7 @@ public final class MethodsGenerator { | ... | @@ -400,8 +399,7 @@ public final class MethodsGenerator { |
400 | } | 399 | } |
401 | getAttrInfo().clear(); | 400 | getAttrInfo().clear(); |
402 | } | 401 | } |
403 | - return constructor + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET | 402 | + return constructor + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; |
404 | - + UtilConstants.NEW_LINE; | ||
405 | } | 403 | } |
406 | 404 | ||
407 | /** | 405 | /** | ... | ... |
... | @@ -54,7 +54,6 @@ public final class FileSystemUtil { | ... | @@ -54,7 +54,6 @@ public final class FileSystemUtil { |
54 | return false; | 54 | return false; |
55 | } | 55 | } |
56 | 56 | ||
57 | - | ||
58 | /** | 57 | /** |
59 | * Create a package structure with package info java file if not present. | 58 | * Create a package structure with package info java file if not present. |
60 | * | 59 | * | ... | ... |
... | @@ -170,8 +170,8 @@ public final class JavaDocGen { | ... | @@ -170,8 +170,8 @@ public final class JavaDocGen { |
170 | * @return javaDocs. | 170 | * @return javaDocs. |
171 | */ | 171 | */ |
172 | private static String generateForBuilderClass(String className) { | 172 | private static String generateForBuilderClass(String className) { |
173 | - return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC | 173 | + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC + className |
174 | - + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE); | 174 | + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE); |
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /** |
... | @@ -181,8 +181,8 @@ public final class JavaDocGen { | ... | @@ -181,8 +181,8 @@ public final class JavaDocGen { |
181 | * @return javaDocs. | 181 | * @return javaDocs. |
182 | */ | 182 | */ |
183 | private static String generateForInterface(String interfaceName) { | 183 | private static String generateForInterface(String interfaceName) { |
184 | - return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC | 184 | + return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC + interfaceName |
185 | - + interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE); | 185 | + + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE); |
186 | } | 186 | } |
187 | 187 | ||
188 | /** | 188 | /** | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.utils.io.impl; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.utils.io.impl; |
18 | 18 | ||
19 | import java.io.BufferedInputStream; | 19 | import java.io.BufferedInputStream; |
20 | import java.io.BufferedOutputStream; | 20 | import java.io.BufferedOutputStream; |
21 | +import java.io.File; | ||
21 | import java.io.FileInputStream; | 22 | import java.io.FileInputStream; |
22 | import java.io.FileNotFoundException; | 23 | import java.io.FileNotFoundException; |
23 | import java.io.FileOutputStream; | 24 | import java.io.FileOutputStream; |
... | @@ -32,19 +33,19 @@ import java.util.ArrayList; | ... | @@ -32,19 +33,19 @@ import java.util.ArrayList; |
32 | import java.util.List; | 33 | import java.util.List; |
33 | 34 | ||
34 | /** | 35 | /** |
35 | - * Provides storage for serialized data while traversing data model tree for code generation. | 36 | + * Provides storage for Temp data while traversing data model tree for code generation. |
36 | */ | 37 | */ |
37 | -public final class SerializedDataStore { | 38 | +public final class TempDataStore { |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * Data Store types. | 41 | * Data Store types. |
41 | */ | 42 | */ |
42 | - public static enum SerializedDataStoreType { | 43 | + public static enum TempDataStoreType { |
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Methods. | 46 | * Methods. |
46 | */ | 47 | */ |
47 | - INTERFACE_METHODS, | 48 | + GETTER_METHODS, |
48 | 49 | ||
49 | /** | 50 | /** |
50 | * Methods. | 51 | * Methods. |
... | @@ -73,42 +74,42 @@ public final class SerializedDataStore { | ... | @@ -73,42 +74,42 @@ public final class SerializedDataStore { |
73 | } | 74 | } |
74 | 75 | ||
75 | /** | 76 | /** |
76 | - * File name string for serialized files of methods. | 77 | + * File name string for Temp files of methods. |
77 | */ | 78 | */ |
78 | - private static final String INTERFACE_METHOD_FILE_NAME = "SerializedInterfaceMethodDataStore"; | 79 | + private static final String GETTER_METHOD_FILE_NAME = "TempGetterMethodDataStore"; |
79 | 80 | ||
80 | /** | 81 | /** |
81 | - * File name string for serialized files of methods. | 82 | + * File name string for Temp files of methods. |
82 | */ | 83 | */ |
83 | - private static final String BUILDER_METHOD_FILE_NAME = "SerializedBuilderMethodDataStore"; | 84 | + private static final String BUILDER_METHOD_FILE_NAME = "TempBuilderMethodDataStore"; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | - * File name string for serialized files of methods. | 87 | + * File name string for Temp files of methods. |
87 | */ | 88 | */ |
88 | - private static final String BUILDER_INTERFACE_METHOD_FILE_NAME = "SerializedBuilderInterfaceMethodDataStore"; | 89 | + private static final String BUILDER_INTERFACE_METHOD_FILE_NAME = "TempBuilderInterfaceMethodDataStore"; |
89 | 90 | ||
90 | /** | 91 | /** |
91 | - * File name string for serialized files of methods. | 92 | + * File name string for Temp files of methods. |
92 | */ | 93 | */ |
93 | - private static final String IMPL_METHOD_FILE_NAME = "SerializedImplMethodDataStore"; | 94 | + private static final String IMPL_METHOD_FILE_NAME = "TempImplMethodDataStore"; |
94 | 95 | ||
95 | /** | 96 | /** |
96 | - * File name string for serialized files of attributes. | 97 | + * File name string for Temp files of attributes. |
97 | */ | 98 | */ |
98 | - private static final String ATTRIBUTE_FILE_NAME = "SerializedAttributeDataStore"; | 99 | + private static final String ATTRIBUTE_FILE_NAME = "TempAttributeDataStore"; |
99 | 100 | ||
100 | /** | 101 | /** |
101 | - * File name string for serialized files of imports. | 102 | + * File name string for Temp files of imports. |
102 | */ | 103 | */ |
103 | - private static final String IMPORT_FILE_NAME = "SerializedImportDataStore"; | 104 | + private static final String IMPORT_FILE_NAME = "TempImportDataStore"; |
104 | 105 | ||
105 | /** | 106 | /** |
106 | - * File extension of serialized files. | 107 | + * File extension of Temp files. |
107 | */ | 108 | */ |
108 | - private static final String SERIALIZE_FILE_EXTENSION = ".ser"; | 109 | + private static final String FILE_EXTENSION = ".tmp"; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | - * Directory for generating Serialized files. | 112 | + * Directory for generating Temp files. |
112 | */ | 113 | */ |
113 | private static final String GEN_DIR = "target/"; | 114 | private static final String GEN_DIR = "target/"; |
114 | 115 | ||
... | @@ -120,35 +121,38 @@ public final class SerializedDataStore { | ... | @@ -120,35 +121,38 @@ public final class SerializedDataStore { |
120 | /** | 121 | /** |
121 | * Default constructor. | 122 | * Default constructor. |
122 | */ | 123 | */ |
123 | - private SerializedDataStore() { | 124 | + private TempDataStore() { |
124 | } | 125 | } |
125 | 126 | ||
126 | /** | 127 | /** |
127 | - * Writes specific info to a serialized file. | 128 | + * Writes specific info to a Temp file. |
128 | * | 129 | * |
129 | * @param data data to be stored | 130 | * @param data data to be stored |
130 | - * @param type type of serialized data store | 131 | + * @param type type of Temp data store |
131 | - * @throws IOException when fails to create a serialized data file. | 132 | + * @param className class name |
133 | + * @throws IOException when fails to create a Temp data file. | ||
132 | */ | 134 | */ |
133 | - public static void setSerializeData(String data, SerializedDataStoreType type) throws IOException { | 135 | + public static void setTempData(String data, TempDataStoreType type, String className) throws IOException { |
134 | 136 | ||
135 | String fileName = ""; | 137 | String fileName = ""; |
136 | - if (type.equals(SerializedDataStoreType.ATTRIBUTE)) { | 138 | + if (type.equals(TempDataStoreType.ATTRIBUTE)) { |
137 | fileName = ATTRIBUTE_FILE_NAME; | 139 | fileName = ATTRIBUTE_FILE_NAME; |
138 | - } else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) { | 140 | + } else if (type.equals(TempDataStoreType.GETTER_METHODS)) { |
139 | - fileName = INTERFACE_METHOD_FILE_NAME; | 141 | + fileName = GETTER_METHOD_FILE_NAME; |
140 | - } else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) { | 142 | + } else if (type.equals(TempDataStoreType.BUILDER_INTERFACE_METHODS)) { |
141 | fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; | 143 | fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; |
142 | - } else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) { | 144 | + } else if (type.equals(TempDataStoreType.BUILDER_METHODS)) { |
143 | fileName = BUILDER_METHOD_FILE_NAME; | 145 | fileName = BUILDER_METHOD_FILE_NAME; |
144 | - } else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) { | 146 | + } else if (type.equals(TempDataStoreType.IMPL_METHODS)) { |
145 | fileName = IMPL_METHOD_FILE_NAME; | 147 | fileName = IMPL_METHOD_FILE_NAME; |
146 | } else { | 148 | } else { |
147 | fileName = IMPORT_FILE_NAME; | 149 | fileName = IMPORT_FILE_NAME; |
148 | } | 150 | } |
149 | 151 | ||
152 | + File dir = new File(GEN_DIR + className + File.separator); | ||
153 | + dir.mkdirs(); | ||
150 | try { | 154 | try { |
151 | - OutputStream file = new FileOutputStream(GEN_DIR + fileName + SERIALIZE_FILE_EXTENSION); | 155 | + OutputStream file = new FileOutputStream(GEN_DIR + className + File.separator + fileName + FILE_EXTENSION); |
152 | OutputStream buffer = new BufferedOutputStream(file, BUFFER_SIZE); | 156 | OutputStream buffer = new BufferedOutputStream(file, BUFFER_SIZE); |
153 | 157 | ||
154 | ObjectOutput output = new ObjectOutputStream(buffer); | 158 | ObjectOutput output = new ObjectOutputStream(buffer); |
... | @@ -163,33 +167,34 @@ public final class SerializedDataStore { | ... | @@ -163,33 +167,34 @@ public final class SerializedDataStore { |
163 | } | 167 | } |
164 | 168 | ||
165 | /** | 169 | /** |
166 | - * Get the serialized data. | 170 | + * Get the Temp data. |
167 | * | 171 | * |
168 | - * @param type type of serialized data store | 172 | + * @param type type of Temp data store |
173 | + * @param className name of the class. | ||
169 | * @return list of attribute info. | 174 | * @return list of attribute info. |
170 | * @throws IOException when fails to read from the file. | 175 | * @throws IOException when fails to read from the file. |
171 | * @throws ClassNotFoundException when class is missing. | 176 | * @throws ClassNotFoundException when class is missing. |
172 | * @throws FileNotFoundException when file is missing. | 177 | * @throws FileNotFoundException when file is missing. |
173 | */ | 178 | */ |
174 | - public static List<String> getSerializeData(SerializedDataStoreType type) | 179 | + public static List<String> getTempData(TempDataStoreType type, String className) |
175 | throws IOException, FileNotFoundException, ClassNotFoundException { | 180 | throws IOException, FileNotFoundException, ClassNotFoundException { |
176 | 181 | ||
177 | String fileName = ""; | 182 | String fileName = ""; |
178 | - if (type.equals(SerializedDataStoreType.ATTRIBUTE)) { | 183 | + if (type.equals(TempDataStoreType.ATTRIBUTE)) { |
179 | fileName = ATTRIBUTE_FILE_NAME; | 184 | fileName = ATTRIBUTE_FILE_NAME; |
180 | - } else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) { | 185 | + } else if (type.equals(TempDataStoreType.GETTER_METHODS)) { |
181 | - fileName = INTERFACE_METHOD_FILE_NAME; | 186 | + fileName = GETTER_METHOD_FILE_NAME; |
182 | - } else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) { | 187 | + } else if (type.equals(TempDataStoreType.BUILDER_INTERFACE_METHODS)) { |
183 | fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; | 188 | fileName = BUILDER_INTERFACE_METHOD_FILE_NAME; |
184 | - } else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) { | 189 | + } else if (type.equals(TempDataStoreType.BUILDER_METHODS)) { |
185 | fileName = BUILDER_METHOD_FILE_NAME; | 190 | fileName = BUILDER_METHOD_FILE_NAME; |
186 | - } else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) { | 191 | + } else if (type.equals(TempDataStoreType.IMPL_METHODS)) { |
187 | fileName = IMPL_METHOD_FILE_NAME; | 192 | fileName = IMPL_METHOD_FILE_NAME; |
188 | } else { | 193 | } else { |
189 | fileName = IMPORT_FILE_NAME; | 194 | fileName = IMPORT_FILE_NAME; |
190 | } | 195 | } |
191 | try { | 196 | try { |
192 | - InputStream file = new FileInputStream(GEN_DIR + fileName + SERIALIZE_FILE_EXTENSION); | 197 | + InputStream file = new FileInputStream(GEN_DIR + className + File.separator + fileName + FILE_EXTENSION); |
193 | InputStream buffer = new BufferedInputStream(file); | 198 | InputStream buffer = new BufferedInputStream(file); |
194 | ObjectInput input = new ObjectInputStream(buffer); | 199 | ObjectInput input = new ObjectInputStream(buffer); |
195 | try { | 200 | try { |
... | @@ -204,7 +209,7 @@ public final class SerializedDataStore { | ... | @@ -204,7 +209,7 @@ public final class SerializedDataStore { |
204 | } catch (FileNotFoundException ex) { | 209 | } catch (FileNotFoundException ex) { |
205 | throw new FileNotFoundException("No such file or directory."); | 210 | throw new FileNotFoundException("No such file or directory."); |
206 | } catch (ClassNotFoundException ex) { | 211 | } catch (ClassNotFoundException ex) { |
207 | - throw new ClassNotFoundException("failed to fetch the serialized data file."); | 212 | + throw new ClassNotFoundException("failed to fetch the Temp data file."); |
208 | } | 213 | } |
209 | } | 214 | } |
210 | } | 215 | } | ... | ... |
... | @@ -33,7 +33,6 @@ public final class YangFileScanner { | ... | @@ -33,7 +33,6 @@ public final class YangFileScanner { |
33 | private YangFileScanner() { | 33 | private YangFileScanner() { |
34 | } | 34 | } |
35 | 35 | ||
36 | - | ||
37 | /** | 36 | /** |
38 | * Returns the list of java files. | 37 | * Returns the list of java files. |
39 | * | 38 | * | ... | ... |
... | @@ -69,10 +69,9 @@ public final class YangIoUtils { | ... | @@ -69,10 +69,9 @@ public final class YangIoUtils { |
69 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { | 69 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { |
70 | 70 | ||
71 | if (pack.contains(UtilConstants.YANG_GEN_DIR)) { | 71 | if (pack.contains(UtilConstants.YANG_GEN_DIR)) { |
72 | - String[] strArray = pack.split(UtilConstants.YANG_GEN_DIR + UtilConstants.SLASH); | 72 | + String[] strArray = pack.split(UtilConstants.YANG_GEN_DIR); |
73 | pack = strArray[1]; | 73 | pack = strArray[1]; |
74 | } | 74 | } |
75 | - | ||
76 | try { | 75 | try { |
77 | 76 | ||
78 | File packageInfo = new File(path + File.separator + "package-info.java"); | 77 | File packageInfo = new File(path + File.separator + "package-info.java"); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.translator.tojava; | ||
18 | + | ||
19 | +import java.io.File; | ||
20 | +import java.io.IOException; | ||
21 | + | ||
22 | +import org.junit.Test; | ||
23 | + | ||
24 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
25 | +import static org.hamcrest.core.Is.is; | ||
26 | + | ||
27 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
28 | +import org.onosproject.yangutils.datamodel.YangType; | ||
29 | +import org.onosproject.yangutils.translator.CachedFileHandle; | ||
30 | +import org.onosproject.yangutils.translator.GeneratedFileType; | ||
31 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
32 | +import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; | ||
33 | +import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | ||
34 | + | ||
35 | +/** | ||
36 | + * Unit test case for cached java file handle. | ||
37 | + */ | ||
38 | +public class CachedJavaFileHandleTest { | ||
39 | + | ||
40 | + private static final String DIR_PKG = "target/unit/cachedfile/"; | ||
41 | + private static final String PKG = "org.onosproject.unittest"; | ||
42 | + private static final String CHILD_PKG = "target/unit/cachedfile/child"; | ||
43 | + private static final String YANG_NAME = "Test1"; | ||
44 | + private static final GeneratedFileType GEN_TYPE = GeneratedFileType.ALL; | ||
45 | + | ||
46 | + /** | ||
47 | + * Unit test case for add attribute info. | ||
48 | + * | ||
49 | + * @throws IOException when fails to add an attribute. | ||
50 | + */ | ||
51 | + @Test | ||
52 | + public void testForAddAttributeInfo() throws IOException { | ||
53 | + | ||
54 | + AttributeInfo attr = getAttr(); | ||
55 | + attr.setListAttr(false); | ||
56 | + getFileHandle().addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr()); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Unit test case for close of cached files. | ||
61 | + * | ||
62 | + * @throws IOException when fails to generate files. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void testForClose() throws IOException { | ||
66 | + | ||
67 | + CopyrightHeader.parseCopyrightHeader(); | ||
68 | + | ||
69 | + AttributeInfo attr = getAttr(); | ||
70 | + attr.setListAttr(false); | ||
71 | + CachedFileHandle handle = getFileHandle(); | ||
72 | + handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr()); | ||
73 | + handle.close(); | ||
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())); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Unit test case for setting child's package. | ||
83 | + * | ||
84 | + * @throws IOException when fails to add child's package | ||
85 | + */ | ||
86 | + @Test | ||
87 | + public void testForSetChildsPackage() throws IOException { | ||
88 | + | ||
89 | + AttributeInfo attr = getAttr(); | ||
90 | + attr.setListAttr(false); | ||
91 | + CachedFileHandle handle = getFileHandle(); | ||
92 | + handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr()); | ||
93 | + | ||
94 | + handle.setChildsPackage(CHILD_PKG); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Returns attribute info. | ||
99 | + * | ||
100 | + * @return attribute info | ||
101 | + */ | ||
102 | + @SuppressWarnings("rawtypes") | ||
103 | + private AttributeInfo getAttr() { | ||
104 | + YangType<?> type = new YangType(); | ||
105 | + YangDataTypes dataType = YangDataTypes.STRING; | ||
106 | + | ||
107 | + type.setDataTypeName("string"); | ||
108 | + type.setDataType(dataType); | ||
109 | + | ||
110 | + AttributeInfo attr = new AttributeInfo(); | ||
111 | + | ||
112 | + attr.setAttributeName("testAttr"); | ||
113 | + attr.setAttributeType(type); | ||
114 | + return attr; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Returns cached java file handle. | ||
119 | + * | ||
120 | + * @return java file handle. | ||
121 | + */ | ||
122 | + private CachedFileHandle getFileHandle() throws IOException { | ||
123 | + CopyrightHeader.parseCopyrightHeader(); | ||
124 | + FileSystemUtil.createPackage(DIR_PKG + File.separator + PKG, YANG_NAME); | ||
125 | + CachedFileHandle fileHandle = FileSystemUtil.createSourceFiles(PKG, YANG_NAME, GEN_TYPE); | ||
126 | + fileHandle.setFilePath(DIR_PKG + PKG.replace(".", "/")); | ||
127 | + | ||
128 | + return fileHandle; | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Returns stub directory file object. | ||
133 | + * | ||
134 | + * @return stub directory file | ||
135 | + */ | ||
136 | + private File getStubDir() { | ||
137 | + return new File(DIR_PKG); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * Returns stub package-info file object. | ||
142 | + * | ||
143 | + * @return stub package-info file | ||
144 | + */ | ||
145 | + private File getStubPkgInfo() { | ||
146 | + return new File(DIR_PKG + PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH) + File.separator | ||
147 | + + "package-info.java"); | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * Returns stub interface file object. | ||
152 | + * | ||
153 | + * @return stub interface file | ||
154 | + */ | ||
155 | + private File getStubInterfaceFile() { | ||
156 | + return new File(DIR_PKG + PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH) + File.separator + YANG_NAME | ||
157 | + + ".java"); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Returns stub builder file. | ||
162 | + * | ||
163 | + * @return stub builder file | ||
164 | + */ | ||
165 | + private File getStubBuilderFile() { | ||
166 | + return new File(DIR_PKG + PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH) + File.separator + YANG_NAME | ||
167 | + + "Builder.java"); | ||
168 | + } | ||
169 | + | ||
170 | +} |
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 | +import org.junit.Test; | ||
20 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
21 | +import org.onosproject.yangutils.datamodel.YangType; | ||
22 | +import org.onosproject.yangutils.translator.GeneratedFileType; | ||
23 | +import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; | ||
24 | +import org.onosproject.yangutils.translator.tojava.ImportInfo; | ||
25 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
26 | + | ||
27 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
28 | +import static org.hamcrest.core.Is.is; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test cases for java code snippet generator. | ||
32 | + */ | ||
33 | +public class JavaCodeSnippetGenTest { | ||
34 | + | ||
35 | + private static final String PKG_INFO = "org.onosproject.unittest"; | ||
36 | + private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; | ||
37 | + private static final GeneratedFileType FILE_GEN_TYPE = GeneratedFileType.INTERFACE; | ||
38 | + private static final GeneratedMethodTypes METHOD_GEN_TYPE = GeneratedMethodTypes.GETTER; | ||
39 | + private static final String YANG_NAME = "Test"; | ||
40 | + private static final String STRING = "String"; | ||
41 | + | ||
42 | + /** | ||
43 | + * Unit test case for import text. | ||
44 | + */ | ||
45 | + @Test | ||
46 | + public void testForImportText() { | ||
47 | + ImportInfo importInfo = new ImportInfo(); | ||
48 | + importInfo.setPkgInfo(PKG_INFO); | ||
49 | + importInfo.setClassInfo(CLASS_INFO); | ||
50 | + | ||
51 | + String imports = JavaCodeSnippetGen.getImportText(importInfo); | ||
52 | + | ||
53 | + assertThat(true, is(imports.equals(UtilConstants.IMPORT + PKG_INFO + UtilConstants.PERIOD + CLASS_INFO | ||
54 | + + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Unit test case for java class definition start. | ||
59 | + */ | ||
60 | + @Test | ||
61 | + public void testForJavaClassDefStart() { | ||
62 | + String classDef = JavaCodeSnippetGen.getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); | ||
63 | + assertThat(true, | ||
64 | + is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE | ||
65 | + + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | ||
66 | + + 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 | + | ||
76 | + String attributeWithType = JavaCodeSnippetGen.getJavaAttributeInfo(FILE_GEN_TYPE, YANG_NAME, getType()); | ||
77 | + assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE | ||
78 | + + getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN))); | ||
79 | + | ||
80 | + String attributeWithoutType = JavaCodeSnippetGen.getJavaAttributeInfo(FILE_GEN_TYPE, YANG_NAME, null); | ||
81 | + assertThat(true, | ||
82 | + is(attributeWithoutType.equals( | ||
83 | + UtilConstants.PRIVATE + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME) | ||
84 | + + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN))); | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Unit test case for list attribute. | ||
90 | + */ | ||
91 | + @Test | ||
92 | + public void testForListAttribute() { | ||
93 | + String listAttribute = JavaCodeSnippetGen.getListAttribute(STRING); | ||
94 | + assertThat(true, is(listAttribute.equals(UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + STRING | ||
95 | + + UtilConstants.DIAMOND_CLOSE_BRACKET))); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Unit test case for java method info. | ||
100 | + */ | ||
101 | + @Test | ||
102 | + public void testForJavaMethodInfo() { | ||
103 | + | ||
104 | + String method = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType()); | ||
105 | + assertThat(true, | ||
106 | + is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION | ||
107 | + + JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName()) + UtilConstants.SPACE | ||
108 | + + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME) | ||
109 | + + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS | ||
110 | + + UtilConstants.SEMI_COLAN))); | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * Unit test case for java class definition close. | ||
115 | + */ | ||
116 | + @Test | ||
117 | + public void testForJavaClassDefClose() { | ||
118 | + String classDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME); | ||
119 | + assertThat(true, is(classDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Returns YANG type. | ||
124 | + * | ||
125 | + * @return type | ||
126 | + */ | ||
127 | + @SuppressWarnings("rawtypes") | ||
128 | + private YangType<?> getType() { | ||
129 | + YangType<?> type = new YangType(); | ||
130 | + type.setDataTypeName(STRING); | ||
131 | + type.setDataType(YangDataTypes.STRING); | ||
132 | + return type; | ||
133 | + } | ||
134 | +} |
... | @@ -19,7 +19,7 @@ package org.onosproject.yangutils.utils.io.impl; | ... | @@ -19,7 +19,7 @@ package org.onosproject.yangutils.utils.io.impl; |
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | import org.junit.Rule; | 20 | import org.junit.Rule; |
21 | import org.junit.rules.ExpectedException; | 21 | import org.junit.rules.ExpectedException; |
22 | -import org.onosproject.yangutils.utils.io.impl.SerializedDataStore.SerializedDataStoreType; | 22 | +import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType; |
23 | 23 | ||
24 | import java.io.FileNotFoundException; | 24 | import java.io.FileNotFoundException; |
25 | import java.io.IOException; | 25 | import java.io.IOException; |
... | @@ -36,11 +36,12 @@ import static org.junit.Assert.assertThat; | ... | @@ -36,11 +36,12 @@ import static org.junit.Assert.assertThat; |
36 | import static org.junit.Assert.assertNotNull; | 36 | import static org.junit.Assert.assertNotNull; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | - * Unit tests for the serialized data store for its contents. | 39 | + * Unit tests for the Tempd data store for its contents. |
40 | */ | 40 | */ |
41 | -public final class SerializedDataStoreTest { | 41 | +public final class TempDataStoreTest { |
42 | 42 | ||
43 | private final Logger log = getLogger(getClass()); | 43 | private final Logger log = getLogger(getClass()); |
44 | + private static final String CLASS_NAME = "YANG"; | ||
44 | 45 | ||
45 | @Rule | 46 | @Rule |
46 | public ExpectedException thrown = ExpectedException.none(); | 47 | public ExpectedException thrown = ExpectedException.none(); |
... | @@ -59,7 +60,7 @@ public final class SerializedDataStoreTest { | ... | @@ -59,7 +60,7 @@ public final class SerializedDataStoreTest { |
59 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 60 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
60 | InstantiationException, IllegalAccessException, InvocationTargetException { | 61 | InstantiationException, IllegalAccessException, InvocationTargetException { |
61 | 62 | ||
62 | - Class<?>[] classesToConstruct = {SerializedDataStore.class }; | 63 | + Class<?>[] classesToConstruct = {TempDataStore.class }; |
63 | for (Class<?> clazz : classesToConstruct) { | 64 | for (Class<?> clazz : classesToConstruct) { |
64 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 65 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
65 | constructor.setAccessible(true); | 66 | constructor.setAccessible(true); |
... | @@ -74,12 +75,12 @@ public final class SerializedDataStoreTest { | ... | @@ -74,12 +75,12 @@ public final class SerializedDataStoreTest { |
74 | public void insertAttributeDataTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 75 | public void insertAttributeDataTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
75 | 76 | ||
76 | String attributeData = "attribute content lists this"; | 77 | String attributeData = "attribute content lists this"; |
77 | - SerializedDataStore.setSerializeData(attributeData, SerializedDataStoreType.ATTRIBUTE); | 78 | + TempDataStore.setTempData(attributeData, TempDataStoreType.ATTRIBUTE, CLASS_NAME); |
78 | - List<String> attributeInfo = SerializedDataStore.getSerializeData(SerializedDataStoreType.ATTRIBUTE); | 79 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, CLASS_NAME); |
79 | List<String> expectedinfo = new LinkedList<>(); | 80 | List<String> expectedinfo = new LinkedList<>(); |
80 | expectedinfo.add(attributeData); | 81 | expectedinfo.add(attributeData); |
81 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 82 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
82 | - SerializedDataStoreType.valueOf(SerializedDataStoreType.ATTRIBUTE.toString()); | 83 | + TempDataStoreType.valueOf(TempDataStoreType.ATTRIBUTE.toString()); |
83 | } | 84 | } |
84 | 85 | ||
85 | /** | 86 | /** |
... | @@ -89,10 +90,8 @@ public final class SerializedDataStoreTest { | ... | @@ -89,10 +90,8 @@ public final class SerializedDataStoreTest { |
89 | public void insertBuilderInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 90 | public void insertBuilderInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
90 | 91 | ||
91 | String builderInterfaceMethodsData = "builder interface methods content lists this"; | 92 | String builderInterfaceMethodsData = "builder interface methods content lists this"; |
92 | - SerializedDataStore.setSerializeData(builderInterfaceMethodsData, | 93 | + TempDataStore.setTempData(builderInterfaceMethodsData, TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME); |
93 | - SerializedDataStoreType.BUILDER_INTERFACE_METHODS); | 94 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME); |
94 | - List<String> attributeInfo = SerializedDataStore | ||
95 | - .getSerializeData(SerializedDataStoreType.BUILDER_INTERFACE_METHODS); | ||
96 | List<String> expectedinfo = new LinkedList<>(); | 95 | List<String> expectedinfo = new LinkedList<>(); |
97 | expectedinfo.add(builderInterfaceMethodsData); | 96 | expectedinfo.add(builderInterfaceMethodsData); |
98 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 97 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
... | @@ -105,8 +104,8 @@ public final class SerializedDataStoreTest { | ... | @@ -105,8 +104,8 @@ public final class SerializedDataStoreTest { |
105 | public void insertBuilderMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 104 | public void insertBuilderMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
106 | 105 | ||
107 | String builderMethodsData = "builder methods content lists this"; | 106 | String builderMethodsData = "builder methods content lists this"; |
108 | - SerializedDataStore.setSerializeData(builderMethodsData, SerializedDataStoreType.BUILDER_METHODS); | 107 | + TempDataStore.setTempData(builderMethodsData, TempDataStoreType.BUILDER_METHODS, CLASS_NAME); |
109 | - List<String> attributeInfo = SerializedDataStore.getSerializeData(SerializedDataStoreType.BUILDER_METHODS); | 108 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, CLASS_NAME); |
110 | List<String> expectedinfo = new LinkedList<>(); | 109 | List<String> expectedinfo = new LinkedList<>(); |
111 | expectedinfo.add(builderMethodsData); | 110 | expectedinfo.add(builderMethodsData); |
112 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 111 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
... | @@ -119,8 +118,8 @@ public final class SerializedDataStoreTest { | ... | @@ -119,8 +118,8 @@ public final class SerializedDataStoreTest { |
119 | public void insertImplMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 118 | public void insertImplMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
120 | 119 | ||
121 | String implMethodsData = "impl methods content lists this"; | 120 | String implMethodsData = "impl methods content lists this"; |
122 | - SerializedDataStore.setSerializeData(implMethodsData, SerializedDataStoreType.IMPL_METHODS); | 121 | + TempDataStore.setTempData(implMethodsData, TempDataStoreType.IMPL_METHODS, CLASS_NAME); |
123 | - List<String> attributeInfo = SerializedDataStore.getSerializeData(SerializedDataStoreType.IMPL_METHODS); | 122 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, CLASS_NAME); |
124 | List<String> expectedinfo = new LinkedList<>(); | 123 | List<String> expectedinfo = new LinkedList<>(); |
125 | expectedinfo.add(implMethodsData); | 124 | expectedinfo.add(implMethodsData); |
126 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 125 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
... | @@ -133,8 +132,8 @@ public final class SerializedDataStoreTest { | ... | @@ -133,8 +132,8 @@ public final class SerializedDataStoreTest { |
133 | public void insertImportTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 132 | public void insertImportTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
134 | 133 | ||
135 | String importData = "interface methods content lists this"; | 134 | String importData = "interface methods content lists this"; |
136 | - SerializedDataStore.setSerializeData(importData, SerializedDataStoreType.IMPORT); | 135 | + TempDataStore.setTempData(importData, TempDataStoreType.IMPORT, CLASS_NAME); |
137 | - List<String> attributeInfo = SerializedDataStore.getSerializeData(SerializedDataStoreType.IMPORT); | 136 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPORT, CLASS_NAME); |
138 | List<String> expectedinfo = new LinkedList<>(); | 137 | List<String> expectedinfo = new LinkedList<>(); |
139 | expectedinfo.add(importData); | 138 | expectedinfo.add(importData); |
140 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 139 | assertThat(true, is(attributeInfo.equals(expectedinfo))); |
... | @@ -147,8 +146,8 @@ public final class SerializedDataStoreTest { | ... | @@ -147,8 +146,8 @@ public final class SerializedDataStoreTest { |
147 | public void insertInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { | 146 | public void insertInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException { |
148 | 147 | ||
149 | String interfaceMethodsData = "interface methods content lists this"; | 148 | String interfaceMethodsData = "interface methods content lists this"; |
150 | - SerializedDataStore.setSerializeData(interfaceMethodsData, SerializedDataStoreType.INTERFACE_METHODS); | 149 | + TempDataStore.setTempData(interfaceMethodsData, TempDataStoreType.GETTER_METHODS, CLASS_NAME); |
151 | - List<String> attributeInfo = SerializedDataStore.getSerializeData(SerializedDataStoreType.INTERFACE_METHODS); | 150 | + List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, CLASS_NAME); |
152 | List<String> expectedinfo = new LinkedList<>(); | 151 | List<String> expectedinfo = new LinkedList<>(); |
153 | expectedinfo.add(interfaceMethodsData); | 152 | expectedinfo.add(interfaceMethodsData); |
154 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | 153 | assertThat(true, is(attributeInfo.equals(expectedinfo))); | ... | ... |
-
Please register or login to post a comment