Bharat saraswal
Committed by Gerrit Code Review

[ONOS-4073] YANG enum translator implementation.

Change-Id: I129eaec0c8f81c674a994a579650f18499340052
Showing 24 changed files with 658 additions and 50 deletions
...@@ -35,6 +35,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; ...@@ -35,6 +35,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
35 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase; 35 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
36 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; 36 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
37 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer; 37 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
38 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
38 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; 39 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
39 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf; 40 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
40 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList; 41 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
...@@ -346,4 +347,22 @@ public final class YangDataModelFactory { ...@@ -346,4 +347,22 @@ public final class YangDataModelFactory {
346 } 347 }
347 } 348 }
348 } 349 }
350 +
351 + /**
352 + * Returns based on the target language generate the inherited data model node.
353 + *
354 + * @param targetLanguage target language in which YANG mapping needs to be
355 + * generated
356 + * @return the corresponding inherited node based on the target language
357 + */
358 + public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) {
359 + switch (targetLanguage) {
360 + case JAVA_GENERATION: {
361 + return new YangJavaEnumeration();
362 + }
363 + default: {
364 + throw new TranslatorException("Only YANG to Java is supported.");
365 + }
366 + }
367 + }
349 } 368 }
......
...@@ -55,6 +55,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -55,6 +55,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
55 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 55 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
56 import org.onosproject.yangutils.utils.YangConstructType; 56 import org.onosproject.yangutils.utils.YangConstructType;
57 57
58 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
59 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangEnumerationNode;
58 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 60 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
59 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 61 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
60 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 62 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
...@@ -99,7 +101,7 @@ public final class EnumerationListener { ...@@ -99,7 +101,7 @@ public final class EnumerationListener {
99 checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY); 101 checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY);
100 102
101 if (listener.getParsedDataStack().peek() instanceof YangType) { 103 if (listener.getParsedDataStack().peek() instanceof YangType) {
102 - YangEnumeration enumerationNode = new YangEnumeration(); 104 + YangEnumeration enumerationNode = getYangEnumerationNode(JAVA_GENERATION);
103 Parsable typeData = listener.getParsedDataStack().pop(); 105 Parsable typeData = listener.getParsedDataStack().pop();
104 106
105 // Check for stack to be non empty. 107 // Check for stack to be non empty.
......
...@@ -57,6 +57,11 @@ public final class GeneratedJavaFileType { ...@@ -57,6 +57,11 @@ public final class GeneratedJavaFileType {
57 public static final int GENERATE_UNION_CLASS = 32; 57 public static final int GENERATE_UNION_CLASS = 32;
58 58
59 /** 59 /**
60 + * Java class corresponding to YANG enumeration.
61 + */
62 + public static final int GENERATE_ENUM_CLASS = 64;
63 +
64 + /**
60 * Creates an instance of generate java file type. 65 * Creates an instance of generate java file type.
61 */ 66 */
62 private GeneratedJavaFileType() { 67 private GeneratedJavaFileType() {
......
...@@ -82,6 +82,11 @@ public final class GeneratedTempFileType { ...@@ -82,6 +82,11 @@ public final class GeneratedTempFileType {
82 public static final int UNION_FROM_STRING_IMPL_MASK = 2048; 82 public static final int UNION_FROM_STRING_IMPL_MASK = 2048;
83 83
84 /** 84 /**
85 + * Enum implementation of class.
86 + */
87 + public static final int ENUM_IMPL_MASK = 4096;
88 +
89 + /**
85 * Creates an instance of generated temp file type. 90 * Creates an instance of generated temp file type.
86 */ 91 */
87 private GeneratedTempFileType() { 92 private GeneratedTempFileType() {
......
...@@ -124,6 +124,29 @@ public final class JavaAttributeInfo { ...@@ -124,6 +124,29 @@ public final class JavaAttributeInfo {
124 } 124 }
125 125
126 /** 126 /**
127 + * Creates an attribute info object corresponding to the passed enumeration attribute
128 + * information and return it.
129 + *
130 + * @param curNode current data model node for which the java file is being
131 + * generated
132 + * @param attributeName attribute name
133 + * @return AttributeInfo attribute details required to add in temporary
134 + * files
135 + */
136 + public static JavaAttributeInfo getAttributeInfoOfEnumAttribute(YangNode curNode, String attributeName) {
137 +
138 + String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName();
139 +
140 + /*
141 + * Get the import info corresponding to the attribute for import in
142 + * generated java files or qualified access
143 + */
144 + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
145 + curNodeName, false);
146 +
147 + return getAttributeInfoForTheData(qualifiedTypeInfo, attributeName, null, curNode, false);
148 + }
149 + /**
127 * Returns the data type info of attribute. 150 * Returns the data type info of attribute.
128 * 151 *
129 * @return the data type info of attribute 152 * @return the data type info of attribute
......
...@@ -20,7 +20,11 @@ import java.io.File; ...@@ -20,7 +20,11 @@ import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.ArrayList; 21 import java.util.ArrayList;
22 import java.util.List; 22 import java.util.List;
23 +import java.util.Set;
24 +
23 import org.onosproject.yangutils.datamodel.HasType; 25 import org.onosproject.yangutils.datamodel.HasType;
26 +import org.onosproject.yangutils.datamodel.YangEnum;
27 +import org.onosproject.yangutils.datamodel.YangEnumeration;
24 import org.onosproject.yangutils.datamodel.YangLeaf; 28 import org.onosproject.yangutils.datamodel.YangLeaf;
25 import org.onosproject.yangutils.datamodel.YangLeafList; 29 import org.onosproject.yangutils.datamodel.YangLeafList;
26 import org.onosproject.yangutils.datamodel.YangLeavesHolder; 30 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
...@@ -28,8 +32,10 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -28,8 +32,10 @@ import org.onosproject.yangutils.datamodel.YangNode;
28 import org.onosproject.yangutils.datamodel.YangType; 32 import org.onosproject.yangutils.datamodel.YangType;
29 import org.onosproject.yangutils.translator.exception.TranslatorException; 33 import org.onosproject.yangutils.translator.exception.TranslatorException;
30 34
35 +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
38 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -37,6 +43,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -37,6 +43,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
46 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 49 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
...@@ -46,14 +53,17 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -46,14 +53,17 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 53 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 54 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; 55 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
56 +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute;
49 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; 57 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf;
50 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType; 58 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType;
51 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; 59 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent;
52 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo; 60 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo;
61 +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
53 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; 62 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
54 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; 63 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
55 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; 64 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
56 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; 65 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
66 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
57 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; 67 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
58 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; 68 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
59 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; 69 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
...@@ -94,13 +104,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATI ...@@ -94,13 +104,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATI
94 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 104 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
95 import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; 105 import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
96 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 106 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
107 +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
97 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 108 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
98 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 109 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
99 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 110 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
100 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; 111 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
112 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
101 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 113 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
102 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; 114 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
103 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
104 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; 115 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
105 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 116 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
106 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; 117 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
...@@ -203,6 +214,11 @@ public class TempJavaCodeFragmentFiles { ...@@ -203,6 +214,11 @@ public class TempJavaCodeFragmentFiles {
203 private static final String OF_STRING_METHOD_FILE_NAME = "OfString"; 214 private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
204 215
205 /** 216 /**
217 + * File name for temporary enum class.
218 + */
219 + private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
220 +
221 + /**
206 * File name for construction for special type like union, typedef. 222 * File name for construction for special type like union, typedef.
207 */ 223 */
208 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; 224 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
...@@ -238,6 +254,11 @@ public class TempJavaCodeFragmentFiles { ...@@ -238,6 +254,11 @@ public class TempJavaCodeFragmentFiles {
238 private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; 254 private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
239 255
240 /** 256 /**
257 + * File name for enum class file name suffix.
258 + */
259 + private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
260 +
261 + /**
241 * File name for generated class file for special type like union, typedef suffix. 262 * File name for generated class file for special type like union, typedef suffix.
242 */ 263 */
243 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; 264 private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
...@@ -318,6 +339,11 @@ public class TempJavaCodeFragmentFiles { ...@@ -318,6 +339,11 @@ public class TempJavaCodeFragmentFiles {
318 private File toStringImplTempFileHandle; 339 private File toStringImplTempFileHandle;
319 340
320 /** 341 /**
342 + * Temporary file handle for enum class file.
343 + */
344 + private File enumClassTempFileHandle;
345 +
346 + /**
321 * Temporary file handle for of string method of class. 347 * Temporary file handle for of string method of class.
322 */ 348 */
323 private File ofStringImplTempFileHandle; 349 private File ofStringImplTempFileHandle;
...@@ -343,10 +369,20 @@ public class TempJavaCodeFragmentFiles { ...@@ -343,10 +369,20 @@ public class TempJavaCodeFragmentFiles {
343 private YangNode curYangNode; 369 private YangNode curYangNode;
344 370
345 /** 371 /**
372 + * Current enum's value.
373 + */
374 + private int enumValue;
375 +
376 + /**
346 * Is attribute added. 377 * Is attribute added.
347 */ 378 */
348 private boolean isAttributePresent = false; 379 private boolean isAttributePresent = false;
349 380
381 + /*
382 + * Java file handle for enum class.
383 + */
384 + private File enumClassJavaFileHandle;
385 +
350 /** 386 /**
351 * Creates an instance of temporary java code fragment. 387 * Creates an instance of temporary java code fragment.
352 * 388 *
...@@ -432,7 +468,16 @@ public class TempJavaCodeFragmentFiles { ...@@ -432,7 +468,16 @@ public class TempJavaCodeFragmentFiles {
432 generatedTempFiles |= TO_STRING_IMPL_MASK; 468 generatedTempFiles |= TO_STRING_IMPL_MASK;
433 generatedTempFiles |= UNION_FROM_STRING_IMPL_MASK; 469 generatedTempFiles |= UNION_FROM_STRING_IMPL_MASK;
434 } 470 }
471 + /**
472 + * Initialize enum when generation file type matches to enum class mask.
473 + */
474 + if ((genFileType & GENERATE_ENUM_CLASS) != 0) {
475 + generatedTempFiles |= ENUM_IMPL_MASK;
476 + }
435 477
478 + /**
479 + * Set temporary file handles.
480 + */
436 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { 481 if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
437 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); 482 setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
438 } 483 }
...@@ -467,7 +512,9 @@ public class TempJavaCodeFragmentFiles { ...@@ -467,7 +512,9 @@ public class TempJavaCodeFragmentFiles {
467 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { 512 if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
468 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); 513 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
469 } 514 }
470 - 515 + if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
516 + setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
517 + }
471 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { 518 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
472 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); 519 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
473 } 520 }
...@@ -572,6 +619,25 @@ public class TempJavaCodeFragmentFiles { ...@@ -572,6 +619,25 @@ public class TempJavaCodeFragmentFiles {
572 } 619 }
573 620
574 /** 621 /**
622 + * Returns enum class java file handle.
623 + *
624 + * @return enum class java file handle
625 + */
626 + private File getEnumClassJavaFileHandle() {
627 + return enumClassJavaFileHandle;
628 + }
629 +
630 + /**
631 + * Sets enum class java file handle.
632 + *
633 + * @param enumClassJavaFileHandle enum class java file handle
634 + */
635 +
636 + private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
637 + this.enumClassJavaFileHandle = enumClassJavaFileHandle;
638 + }
639 +
640 + /**
575 * Returns java file handle for type class file. 641 * Returns java file handle for type class file.
576 * 642 *
577 * @return java file handle for type class file 643 * @return java file handle for type class file
...@@ -752,6 +818,25 @@ public class TempJavaCodeFragmentFiles { ...@@ -752,6 +818,25 @@ public class TempJavaCodeFragmentFiles {
752 } 818 }
753 819
754 /** 820 /**
821 + * Returns temporary file handle for enum class file.
822 + *
823 + * @return temporary file handle for enum class file
824 + */
825 + public File getEnumClassTempFileHandle() {
826 + return enumClassTempFileHandle;
827 + }
828 +
829 + /**
830 + * Sets temporary file handle for enum class file.
831 + *
832 + * @param enumClassTempFileHandle temporary file handle for enum class file
833 + */
834 +
835 + private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
836 + this.enumClassTempFileHandle = enumClassTempFileHandle;
837 + }
838 +
839 + /**
755 * Returns of string method's temporary file handle. 840 * Returns of string method's temporary file handle.
756 * 841 *
757 * @return of string method's temporary file handle 842 * @return of string method's temporary file handle
...@@ -846,6 +931,24 @@ public class TempJavaCodeFragmentFiles { ...@@ -846,6 +931,24 @@ public class TempJavaCodeFragmentFiles {
846 } 931 }
847 932
848 /** 933 /**
934 + * Returns enum's value.
935 + *
936 + * @return enum's value
937 + */
938 + public int getEnumValue() {
939 + return enumValue;
940 + }
941 +
942 + /**
943 + * Sets enum's value.
944 + *
945 + * @param enumValue enum's value
946 + */
947 + public void setEnumValue(int enumValue) {
948 + this.enumValue = enumValue;
949 + }
950 +
951 + /**
849 * Returns list of classes to be extended by generated files. 952 * Returns list of classes to be extended by generated files.
850 * 953 *
851 * @return list of classes to be extended by generated files 954 * @return list of classes to be extended by generated files
...@@ -1038,6 +1141,17 @@ public class TempJavaCodeFragmentFiles { ...@@ -1038,6 +1141,17 @@ public class TempJavaCodeFragmentFiles {
1038 } 1141 }
1039 1142
1040 /** 1143 /**
1144 + * Adds enum class attributes to temporary file.
1145 + *
1146 + * @param curEnum current YANG enum
1147 + * @throws IOException when fails to do IO operations.
1148 + */
1149 + private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) throws IOException {
1150 + appendToFile(getEnumClassTempFileHandle(),
1151 + generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue()));
1152 + }
1153 +
1154 + /**
1041 * Add from string method for union class. 1155 * Add from string method for union class.
1042 * 1156 *
1043 * @param javaAttributeInfo type attribute info 1157 * @param javaAttributeInfo type attribute info
...@@ -1080,7 +1194,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -1080,7 +1194,6 @@ public class TempJavaCodeFragmentFiles {
1080 * @throws IOException when fails to create new file handle 1194 * @throws IOException when fails to create new file handle
1081 */ 1195 */
1082 private File getJavaFileHandle(String fileName) throws IOException { 1196 private File getJavaFileHandle(String fileName) throws IOException {
1083 - createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
1084 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); 1197 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1085 } 1198 }
1086 1199
...@@ -1271,6 +1384,26 @@ public class TempJavaCodeFragmentFiles { ...@@ -1271,6 +1384,26 @@ public class TempJavaCodeFragmentFiles {
1271 } 1384 }
1272 1385
1273 /** 1386 /**
1387 + * Adds enum attributes to temporary files.
1388 + *
1389 + * @param curNode current YANG node
1390 + * @throws IOException when fails to do IO operations
1391 + */
1392 + public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
1393 +
1394 + if (curNode instanceof YangEnumeration) {
1395 + Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet();
1396 + for (YangEnum curEnum : enumSet) {
1397 + JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfEnumAttribute(curNode, curEnum.getNamedValue());
1398 + setEnumValue(curEnum.getValue());
1399 + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1400 + }
1401 + } else {
1402 + throw new TranslatorException("curnode should be of type enum.");
1403 + }
1404 + }
1405 +
1406 + /**
1274 * Adds the new attribute info to the target generated temporary files for union class. 1407 * Adds the new attribute info to the target generated temporary files for union class.
1275 * 1408 *
1276 * @param hasType the node for which the type is being added as an attribute 1409 * @param hasType the node for which the type is being added as an attribute
...@@ -1337,6 +1470,10 @@ public class TempJavaCodeFragmentFiles { ...@@ -1337,6 +1470,10 @@ public class TempJavaCodeFragmentFiles {
1337 addToStringMethod(newAttrInfo); 1470 addToStringMethod(newAttrInfo);
1338 } 1471 }
1339 1472
1473 + if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1474 + addAttributesForEnumClass(newAttrInfo);
1475 + }
1476 +
1340 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { 1477 if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
1341 addOfStringMethod(newAttrInfo); 1478 addOfStringMethod(newAttrInfo);
1342 } 1479 }
...@@ -1395,7 +1532,12 @@ public class TempJavaCodeFragmentFiles { ...@@ -1395,7 +1532,12 @@ public class TempJavaCodeFragmentFiles {
1395 * Prepares java file generator for extends list. 1532 * Prepares java file generator for extends list.
1396 */ 1533 */
1397 prepareJavaFileGeneratorForExtendsList(getExtendsList()); 1534 prepareJavaFileGeneratorForExtendsList(getExtendsList());
1398 - 1535 + if (curNode.getNodeType().equals(MODULE_NODE)) {
1536 + createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
1537 + } else {
1538 + createPackage(absoluteDirPath, ((HasJavaFileInfo) curNode.getParent()).getJavaFileInfo().getJavaName()
1539 + + PACKAGE_INFO_JAVADOC_OF_CHILD);
1540 + }
1399 /** 1541 /**
1400 * Generate java code. 1542 * Generate java code.
1401 */ 1543 */
...@@ -1492,6 +1634,14 @@ public class TempJavaCodeFragmentFiles { ...@@ -1492,6 +1634,14 @@ public class TempJavaCodeFragmentFiles {
1492 } 1634 }
1493 1635
1494 /** 1636 /**
1637 + * Creates type enum class file.
1638 + */
1639 + if ((fileType & GENERATE_ENUM_CLASS) != 0) {
1640 + setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
1641 + setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
1642 + }
1643 +
1644 + /**
1495 * Close all the file handles. 1645 * Close all the file handles.
1496 */ 1646 */
1497 close(false); 1647 close(false);
...@@ -1525,6 +1675,9 @@ public class TempJavaCodeFragmentFiles { ...@@ -1525,6 +1675,9 @@ public class TempJavaCodeFragmentFiles {
1525 if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) { 1675 if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) {
1526 closeFile(getTypedefClassJavaFileHandle(), isError); 1676 closeFile(getTypedefClassJavaFileHandle(), isError);
1527 } 1677 }
1678 + if ((generatedJavaFiles & GENERATE_ENUM_CLASS) != 0) {
1679 + closeFile(getEnumClassJavaFileHandle(), isError);
1680 + }
1528 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) { 1681 if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) {
1529 closeFile(getTypeClassJavaFileHandle(), isError); 1682 closeFile(getTypeClassJavaFileHandle(), isError);
1530 } 1683 }
...@@ -1559,6 +1712,9 @@ public class TempJavaCodeFragmentFiles { ...@@ -1559,6 +1712,9 @@ public class TempJavaCodeFragmentFiles {
1559 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { 1712 if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
1560 closeFile(getEqualsImplTempFileHandle(), true); 1713 closeFile(getEqualsImplTempFileHandle(), true);
1561 } 1714 }
1715 + if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
1716 + closeFile(getEnumClassTempFileHandle(), true);
1717 + }
1562 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { 1718 if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
1563 closeFile(getConstructorForTypeTempFileHandle(), true); 1719 closeFile(getConstructorForTypeTempFileHandle(), true);
1564 } 1720 }
......
1 +/*
2 + * Copyright 2016-present 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.javamodel;
18 +
19 +import java.io.IOException;
20 +
21 +import org.onosproject.yangutils.datamodel.YangEnumeration;
22 +import org.onosproject.yangutils.translator.exception.TranslatorException;
23 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
24 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
25 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
26 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
27 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 +
29 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
30 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
31 +
32 +/**
33 + * Represents YANG java enumeration information extended to support java code generation.
34 + */
35 +public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGenerator, JavaCodeGeneratorInfo {
36 +
37 + /**
38 + * Contains the information of the java file being generated.
39 + */
40 + private JavaFileInfo javaFileInfo;
41 +
42 + /**
43 + * Contains information of the imports to be inserted in the java file
44 + * generated.
45 + */
46 + private JavaImportData javaImportData;
47 +
48 + /**
49 + * File handle to maintain temporary java code fragments as per the code
50 + * snippet types.
51 + */
52 + private TempJavaCodeFragmentFiles tempFileHandle;
53 +
54 + /**
55 + * Creates YANG java enumeration object.
56 + */
57 + public YangJavaEnumeration() {
58 + super();
59 + setJavaFileInfo(new JavaFileInfo());
60 + setJavaImportData(new JavaImportData());
61 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
62 + }
63 +
64 + /**
65 + * Returns the generated java file information.
66 + *
67 + * @return generated java file information
68 + */
69 + @Override
70 + public JavaFileInfo getJavaFileInfo() {
71 +
72 + if (javaFileInfo == null) {
73 + throw new TranslatorException("Missing java info in java datamodel node");
74 + }
75 + return javaFileInfo;
76 + }
77 +
78 + /**
79 + * Sets the java file info object.
80 + *
81 + * @param javaInfo java file info object
82 + */
83 + @Override
84 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
85 +
86 + javaFileInfo = javaInfo;
87 + }
88 +
89 + /**
90 + * Returns the data of java imports to be included in generated file.
91 + *
92 + * @return data of java imports to be included in generated file
93 + */
94 + @Override
95 + public JavaImportData getJavaImportData() {
96 +
97 + return javaImportData;
98 + }
99 +
100 + /**
101 + * Sets the data of java imports to be included in generated file.
102 + *
103 + * @param javaImportData data of java imports to be included in generated
104 + * file
105 + */
106 + @Override
107 + public void setJavaImportData(JavaImportData javaImportData) {
108 +
109 + this.javaImportData = javaImportData;
110 + }
111 +
112 + /**
113 + * Returns the temporary file handle.
114 + *
115 + * @return temporary file handle
116 + */
117 + @Override
118 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
119 +
120 + return tempFileHandle;
121 + }
122 +
123 + /**
124 + * Sets temporary file handle.
125 + *
126 + * @param fileHandle temporary file handle
127 + */
128 + @Override
129 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
130 +
131 + tempFileHandle = fileHandle;
132 + }
133 +
134 + /**
135 + * Prepare the information for java code generation corresponding to YANG
136 + * enumeration info.
137 + *
138 + * @param yangPlugin YANG plugin config
139 + * @throws IOException IO operations fails
140 + */
141 + @Override
142 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
143 + generateCodeOfType(this, yangPlugin, false);
144 + }
145 +
146 + /**
147 + * Creates a java file using the YANG enumeration info.
148 + *
149 + * @throws IOException IO operation fail
150 + */
151 + @Override
152 + public void generateCodeExit() throws IOException {
153 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
154 + }
155 +
156 +}
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
20 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 20 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
21 +import org.onosproject.yangutils.datamodel.YangEnumeration;
21 import org.onosproject.yangutils.datamodel.YangNode; 22 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.datamodel.YangType; 23 import org.onosproject.yangutils.datamodel.YangType;
23 import org.onosproject.yangutils.datamodel.YangTypeDef; 24 import org.onosproject.yangutils.datamodel.YangTypeDef;
...@@ -25,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangUnion; ...@@ -25,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangUnion;
25 import org.onosproject.yangutils.translator.exception.TranslatorException; 26 import org.onosproject.yangutils.translator.exception.TranslatorException;
26 import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; 27 import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 28 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
29 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
28 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; 30 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
29 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion; 31 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
30 32
...@@ -186,7 +188,8 @@ public final class AttributesJavaDataType { ...@@ -186,7 +188,8 @@ public final class AttributesJavaDataType {
186 case BOOLEAN: 188 case BOOLEAN:
187 return BOOLEAN_WRAPPER; 189 return BOOLEAN_WRAPPER;
188 case ENUMERATION: 190 case ENUMERATION:
189 - //TODO: ENUMERATION. 191 + return getCaptialCase(
192 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
190 case BITS: 193 case BITS:
191 //TODO:BITS 194 //TODO:BITS
192 case BINARY: 195 case BINARY:
...@@ -205,7 +208,7 @@ public final class AttributesJavaDataType { ...@@ -205,7 +208,7 @@ public final class AttributesJavaDataType {
205 case DERIVED: 208 case DERIVED:
206 return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); 209 return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
207 default: 210 default:
208 - return null; 211 + throw new TranslatorException("given data type is not supported.");
209 } 212 }
210 } else { 213 } else {
211 switch (type) { 214 switch (type) {
...@@ -216,7 +219,8 @@ public final class AttributesJavaDataType { ...@@ -216,7 +219,8 @@ public final class AttributesJavaDataType {
216 case STRING: 219 case STRING:
217 return STRING_DATA_TYPE; 220 return STRING_DATA_TYPE;
218 case ENUMERATION: 221 case ENUMERATION:
219 - //TODO: ENUMERATION. 222 + return getCaptialCase(
223 + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
220 case BITS: 224 case BITS:
221 //TODO:BITS 225 //TODO:BITS
222 case BINARY: 226 case BINARY:
...@@ -269,7 +273,7 @@ public final class AttributesJavaDataType { ...@@ -269,7 +273,7 @@ public final class AttributesJavaDataType {
269 case DECIMAL64: 273 case DECIMAL64:
270 //TODO: DECIMAL64. 274 //TODO: DECIMAL64.
271 case ENUMERATION: 275 case ENUMERATION:
272 - //TODO: ENUMERATION. 276 + return getEnumsPackage(yangType);
273 case BITS: 277 case BITS:
274 //TODO:BITS 278 //TODO:BITS
275 case BINARY: 279 case BINARY:
...@@ -287,7 +291,7 @@ public final class AttributesJavaDataType { ...@@ -287,7 +291,7 @@ public final class AttributesJavaDataType {
287 case DERIVED: 291 case DERIVED:
288 return getTypDefsPackage(yangType); 292 return getTypDefsPackage(yangType);
289 default: 293 default:
290 - return null; 294 + throw new TranslatorException("given data type is not supported.");
291 } 295 }
292 } else { 296 } else {
293 switch (type) { 297 switch (type) {
...@@ -298,7 +302,7 @@ public final class AttributesJavaDataType { ...@@ -298,7 +302,7 @@ public final class AttributesJavaDataType {
298 case STRING: 302 case STRING:
299 return JAVA_LANG; 303 return JAVA_LANG;
300 case ENUMERATION: 304 case ENUMERATION:
301 - //TODO: ENUMERATION. 305 + return getEnumsPackage(yangType);
302 case BITS: 306 case BITS:
303 //TODO:BITS 307 //TODO:BITS
304 case BINARY: 308 case BINARY:
...@@ -364,6 +368,24 @@ public final class AttributesJavaDataType { ...@@ -364,6 +368,24 @@ public final class AttributesJavaDataType {
364 } 368 }
365 369
366 /** 370 /**
371 + * Returns YANG enumeration's java package.
372 + *
373 + * @param type YANG type
374 + * @return YANG enumeration's java package
375 + */
376 + private static String getEnumsPackage(YangType<?> type) {
377 +
378 + if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
379 + throw new TranslatorException("type should have been enumeration.");
380 + }
381 + YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo();
382 + if (enumeration.getJavaFileInfo().getPackage() == null) {
383 + return getPackageFromParent(enumeration.getParent());
384 + }
385 + return enumeration.getJavaFileInfo().getPackage();
386 + }
387 +
388 + /**
367 * Returns package from parent node. 389 * Returns package from parent node.
368 * 390 *
369 * @param parent parent YANG node 391 * @param parent parent YANG node
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
21 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
21 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 22 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
22 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 24 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -27,6 +28,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato ...@@ -27,6 +28,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
27 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 28 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
28 import static org.onosproject.yangutils.utils.UtilConstants.CLASS; 29 import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
29 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 30 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
31 +import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
30 import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; 32 import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
31 import static org.onosproject.yangutils.utils.UtilConstants.FINAL; 33 import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
32 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 34 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
...@@ -76,11 +78,23 @@ public final class ClassDefinitionGenerator { ...@@ -76,11 +78,23 @@ public final class ClassDefinitionGenerator {
76 return getTypeClassDefinition(yangName); 78 return getTypeClassDefinition(yangName);
77 } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) { 79 } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) {
78 return getTypeClassDefinition(yangName); 80 return getTypeClassDefinition(yangName);
81 + } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
82 + return getEnumClassDefinition(yangName);
79 } 83 }
80 return null; 84 return null;
81 } 85 }
82 86
83 /** 87 /**
88 + * Returns enum file class definition.
89 + *
90 + * @param yangName class name
91 + * @return enum file class definiton
92 + */
93 + private static String getEnumClassDefinition(String yangName) {
94 + return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
95 + }
96 +
97 + /**
84 * Returns interface file class definition. 98 * Returns interface file class definition.
85 * 99 *
86 * @param yangName file name 100 * @param yangName file name
......
...@@ -20,11 +20,13 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; ...@@ -20,11 +20,13 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
20 20
21 import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; 21 import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
22 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 22 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
23 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
23 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 24 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
24 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; 25 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
25 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; 26 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
26 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; 27 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
27 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 28 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
29 +import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
28 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; 30 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
29 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; 31 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
30 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; 32 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
...@@ -38,6 +40,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; ...@@ -38,6 +40,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
38 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 40 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
39 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 41 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
40 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 42 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
43 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
44 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
41 45
42 /** 46 /**
43 * Represents utility class to generate the java snippet. 47 * Represents utility class to generate the java snippet.
...@@ -155,4 +159,17 @@ public final class JavaCodeSnippetGen { ...@@ -155,4 +159,17 @@ public final class JavaCodeSnippetGen {
155 public static String getJavaClassDefClose() { 159 public static String getJavaClassDefClose() {
156 return CLOSE_CURLY_BRACKET; 160 return CLOSE_CURLY_BRACKET;
157 } 161 }
162 +
163 + /**
164 + * Returns string for enum's attribute.
165 + *
166 + * @param name name of attribute
167 + * @param value value of the enum
168 + * @return string for enum's attribute
169 + */
170 + public static String generateEnumAttributeString(String name, int value) {
171 + return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION + getEnumJavaAttribute(name)
172 + + OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
173 + }
174 +
158 } 175 }
......
...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; ...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 27
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
30 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
34 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
36 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
38 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
...@@ -45,15 +47,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -45,15 +47,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
46 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; 48 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute;
47 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; 49 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
50 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
48 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; 51 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
49 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; 52 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
53 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
50 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; 54 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
51 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; 55 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
52 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; 56 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
57 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor;
53 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; 58 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
54 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; 59 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
55 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; 60 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
56 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; 61 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
62 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
57 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; 63 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
58 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; 64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
59 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; 65 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
...@@ -63,14 +69,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -63,14 +69,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
63 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; 69 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
64 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 70 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
65 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; 71 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
72 +import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
66 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 73 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
67 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 74 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
68 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 75 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
76 +import static org.onosproject.yangutils.utils.UtilConstants.INT;
69 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 77 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
70 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 78 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
71 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 79 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
80 +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
81 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
82 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
83 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
72 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 84 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
73 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; 85 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString;
86 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
74 87
75 /** 88 /**
76 * Representation of java file generator. 89 * Representation of java file generator.
...@@ -384,7 +397,7 @@ public final class JavaFileGenerator { ...@@ -384,7 +397,7 @@ public final class JavaFileGenerator {
384 } 397 }
385 398
386 /** 399 /**
387 - * Generate class file for type def. 400 + * Generates class file for type def.
388 * 401 *
389 * @param file generated file 402 * @param file generated file
390 * @param curNode current YANG node 403 * @param curNode current YANG node
...@@ -469,7 +482,7 @@ public final class JavaFileGenerator { ...@@ -469,7 +482,7 @@ public final class JavaFileGenerator {
469 } 482 }
470 483
471 /** 484 /**
472 - * Generate class file for union type. 485 + * Generates class file for union type.
473 * 486 *
474 * @param file generated file 487 * @param file generated file
475 * @param curNode current YANG node 488 * @param curNode current YANG node
...@@ -559,4 +572,56 @@ public final class JavaFileGenerator { ...@@ -559,4 +572,56 @@ public final class JavaFileGenerator {
559 572
560 return file; 573 return file;
561 } 574 }
575 +
576 + /**
577 + * Generates class file for type enum.
578 + *
579 + * @param file generated file
580 + * @param curNode current YANG node
581 + * @return class file for type enum
582 + * @throws IOException when fails to generate class file
583 + */
584 + public static File generateEnumClassFile(File file, YangNode curNode) throws IOException {
585 +
586 + JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
587 +
588 + String className = getCaptialCase(javaFileInfo.getJavaName());
589 + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
590 +
591 + initiateJavaFileGeneration(file, className, GENERATE_ENUM_CLASS, null, path);
592 + /**
593 + * Add attribute strings.
594 + */
595 + try {
596 + insertDataIntoJavaFile(file,
597 + trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, curNode), COMMA), NEW_LINE)
598 + + SEMI_COLAN + NEW_LINE);
599 + } catch (IOException e) {
600 + throw new IOException("No data found in temporary java code fragment files for " + className
601 + + " while enum class file generation");
602 + }
603 +
604 + /**
605 + * Add an attribute to get the enum's values.
606 + */
607 + insertDataIntoJavaFile(file, getEnumsValueAttribute(className));
608 +
609 + /**
610 + * Add a constructor for enum.
611 + */
612 + insertDataIntoJavaFile(file,
613 + getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false) + getEnumsConstrcutor(className)
614 + + NEW_LINE);
615 +
616 + /**
617 + * Add a getter method for enum.
618 + */
619 + insertDataIntoJavaFile(file,
620 + getJavaDoc(GETTER_METHOD, getSmallCase(className), false) + getGetter(INT, getSmallCase(className))
621 + + NEW_LINE);
622 +
623 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
624 +
625 + return file;
626 + }
562 } 627 }
......
...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; ...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
28 28
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
31 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
...@@ -35,6 +36,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -35,6 +36,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
36 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
39 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
...@@ -46,17 +48,22 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -46,17 +48,22 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
47 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; 49 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
48 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; 50 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
51 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
52 +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
53 +import static org.onosproject.yangutils.utils.UtilConstants.INT;
49 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 54 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
50 import static org.onosproject.yangutils.utils.UtilConstants.ORG; 55 import static org.onosproject.yangutils.utils.UtilConstants.ORG;
51 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; 56 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
57 +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
52 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 58 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
53 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 59 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
54 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 60 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
61 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
55 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; 62 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
56 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; 63 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
64 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
57 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 65 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
58 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 66 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
59 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 67 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
61 68
62 /** 69 /**
...@@ -134,6 +141,9 @@ public final class JavaFileGeneratorUtils { ...@@ -134,6 +141,9 @@ public final class JavaFileGeneratorUtils {
134 } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { 141 } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) {
135 return tempJavaCodeFragmentFiles 142 return tempJavaCodeFragmentFiles
136 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle()); 143 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle());
144 + } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
145 + return tempJavaCodeFragmentFiles
146 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEnumClassTempFileHandle());
137 } 147 }
138 return null; 148 return null;
139 } 149 }
...@@ -190,6 +200,9 @@ public final class JavaFileGeneratorUtils { ...@@ -190,6 +200,9 @@ public final class JavaFileGeneratorUtils {
190 } else if ((type & GENERATE_UNION_CLASS) != 0) { 200 } else if ((type & GENERATE_UNION_CLASS) != 0) {
191 appendHeaderContents(file, pkgString, importsList); 201 appendHeaderContents(file, pkgString, importsList);
192 write(file, fileName, type, IMPL_CLASS); 202 write(file, fileName, type, IMPL_CLASS);
203 + } else if ((type & GENERATE_ENUM_CLASS) != 0) {
204 + appendHeaderContents(file, pkgString, importsList);
205 + write(file, fileName, type, ENUM_CLASS);
193 } 206 }
194 } 207 }
195 208
...@@ -259,4 +272,15 @@ public final class JavaFileGeneratorUtils { ...@@ -259,4 +272,15 @@ public final class JavaFileGeneratorUtils {
259 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); 272 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
260 } 273 }
261 274
275 + /**
276 + * Returns integer attribute for enum's class to get the values.
277 + *
278 + * @param className enum's class name
279 + * @return enum's attribute
280 + */
281 + public static String getEnumsValueAttribute(String className) {
282 + return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) + SEMI_COLAN
283 + + NEW_LINE;
284 + }
285 +
262 } 286 }
......
...@@ -381,6 +381,25 @@ public final class JavaIdentifierSyntax { ...@@ -381,6 +381,25 @@ public final class JavaIdentifierSyntax {
381 } 381 }
382 382
383 /** 383 /**
384 + * Returns enum's java name.
385 + *
386 + * @param name enum's name
387 + * @return enum's java name
388 + */
389 + public static String getEnumJavaAttribute(String name) {
390 +
391 + String[] strArray = name.split(HYPHEN);
392 + String output = EMPTY_STRING;
393 + for (int i = 0; i < strArray.length; i++) {
394 + output = output + strArray[i];
395 + if (i > 0 && i < strArray.length - 1) {
396 + output = output + UNDER_SCORE;
397 + }
398 + }
399 + return output;
400 + }
401 +
402 + /**
384 * Returns the directory path corresponding to java package. 403 * Returns the directory path corresponding to java package.
385 * 404 *
386 * @param packagePath package path 405 * @param packagePath package path
......
...@@ -87,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY; ...@@ -87,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY;
87 import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; 87 import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
88 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 88 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
89 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 89 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
90 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
90 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; 91 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
91 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; 92 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
92 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; 93 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
...@@ -95,7 +96,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_ ...@@ -95,7 +96,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_
95 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; 96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
96 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
97 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD; 98 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD;
98 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
99 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 99 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
100 100
101 /** 101 /**
...@@ -218,7 +218,7 @@ public final class MethodsGenerator { ...@@ -218,7 +218,7 @@ public final class MethodsGenerator {
218 * @param name attribute name 218 * @param name attribute name
219 * @return getter for attribute 219 * @return getter for attribute
220 */ 220 */
221 - private static String getGetter(String type, String name) { 221 + public static String getGetter(String type, String name) {
222 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) 222 return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name)
223 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION 223 + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
224 + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 224 + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
...@@ -803,4 +803,15 @@ public final class MethodsGenerator { ...@@ -803,4 +803,15 @@ public final class MethodsGenerator {
803 return method; 803 return method;
804 } 804 }
805 805
806 + /**
807 + * Returns enum's constructor.
808 + *
809 + * @param className enum's class name
810 + * @return enum's constructor
811 + */
812 + public static String getEnumsConstrcutor(String className) {
813 + return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
814 + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
815 + + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
816 + }
806 } 817 }
......
...@@ -31,6 +31,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; ...@@ -31,6 +31,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
31 import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; 31 import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
32 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; 32 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
33 33
34 +import static java.util.Collections.sort;
35 +
34 /** 36 /**
35 * Represents utilities for temporary java code fragments. 37 * Represents utilities for temporary java code fragments.
36 */ 38 */
...@@ -128,7 +130,7 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -128,7 +130,7 @@ public final class TempJavaCodeFragmentFilesUtils {
128 } else { 130 } else {
129 imports.remove(curImport); 131 imports.remove(curImport);
130 } 132 }
131 - java.util.Collections.sort(imports); 133 + sort(imports);
132 return imports; 134 return imports;
133 } 135 }
134 136
......
...@@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangNotification; ...@@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangNotification;
30 import org.onosproject.yangutils.datamodel.YangOutput; 30 import org.onosproject.yangutils.datamodel.YangOutput;
31 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 31 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
32 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; 32 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
33 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
33 34
34 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 35 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
35 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; 36 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
...@@ -116,6 +117,9 @@ public final class YangJavaModelUtils { ...@@ -116,6 +117,9 @@ public final class YangJavaModelUtils {
116 } else if (javaCodeGeneratorInfo instanceof HasType) { 117 } else if (javaCodeGeneratorInfo instanceof HasType) {
117 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 118 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
118 .addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo); 119 .addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo);
120 + } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
121 + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
122 + .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
119 } else { 123 } else {
120 //TODO throw exception 124 //TODO throw exception
121 } 125 }
......
...@@ -53,9 +53,24 @@ public final class UtilConstants { ...@@ -53,9 +53,24 @@ public final class UtilConstants {
53 public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for "; 53 public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for ";
54 54
55 /** 55 /**
56 + * JavaDocs for enum class.
57 + */
58 + public static final String ENUM_CLASS_JAVADOC = " * Represents ENUM data of ";
59 +
60 + /**
61 + * JavaDocs for enum attribute.
62 + */
63 + public static final String ENUM_ATTRIBUTE_JAVADOC = " * Represents ";
64 +
65 + /**
56 * JavaDocs for package info class. 66 * JavaDocs for package info class.
57 */ 67 */
58 - public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG file "; 68 + public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG node ";
69 +
70 + /**
71 + * JavaDocs for package info class.
72 + */
73 + public static final String PACKAGE_INFO_JAVADOC_OF_CHILD = "'s children nodes";
59 74
60 /** 75 /**
61 * JavaDocs's first line. 76 * JavaDocs's first line.
...@@ -283,6 +298,11 @@ public final class UtilConstants { ...@@ -283,6 +298,11 @@ public final class UtilConstants {
283 public static final String VALUE = "value"; 298 public static final String VALUE = "value";
284 299
285 /** 300 /**
301 + * Static attribute for enumValue syntax.
302 + */
303 + public static final String ENUM_VALUE = "enumValue";
304 +
305 + /**
286 * Static attribute for suffix s. 306 * Static attribute for suffix s.
287 */ 307 */
288 public static final String SUFFIX_S = "s"; 308 public static final String SUFFIX_S = "s";
......
...@@ -23,6 +23,7 @@ import java.io.FileReader; ...@@ -23,6 +23,7 @@ import java.io.FileReader;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.InputStream; 24 import java.io.InputStream;
25 import java.io.OutputStream; 25 import java.io.OutputStream;
26 +import java.util.Calendar;
26 27
27 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 28 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
28 29
...@@ -33,6 +34,8 @@ public final class CopyrightHeader { ...@@ -33,6 +34,8 @@ public final class CopyrightHeader {
33 34
34 private static final int EOF = -1; 35 private static final int EOF = -1;
35 private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt"; 36 private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt";
37 + private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR)
38 + + "-present Open Networking Laboratory\n";
36 private static final String TEMP_FILE = "temp.txt"; 39 private static final String TEMP_FILE = "temp.txt";
37 private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); 40 private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader();
38 41
...@@ -82,6 +85,7 @@ public final class CopyrightHeader { ...@@ -82,6 +85,7 @@ public final class CopyrightHeader {
82 OutputStream out = new FileOutputStream(temp); 85 OutputStream out = new FileOutputStream(temp);
83 86
84 int index; 87 int index;
88 + out.write(COPYRIGHTS_FIRST_LINE.getBytes());
85 while ((index = stream.read()) != EOF) { 89 while ((index = stream.read()) != EOF) {
86 out.write(index); 90 out.write(index);
87 } 91 }
......
...@@ -22,6 +22,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; ...@@ -22,6 +22,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; 22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
25 +import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
26 +import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
25 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 27 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
26 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; 28 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
27 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; 29 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
...@@ -135,7 +137,17 @@ public final class JavaDocGen { ...@@ -135,7 +137,17 @@ public final class JavaDocGen {
135 /** 137 /**
136 * For build. 138 * For build.
137 */ 139 */
138 - BUILD_METHOD 140 + BUILD_METHOD,
141 +
142 + /**
143 + * For enum.
144 + */
145 + ENUM_CLASS,
146 +
147 + /**
148 + * For enum's attributes.
149 + */
150 + ENUM_ATTRIBUTE
139 } 151 }
140 152
141 /** 153 /**
...@@ -176,6 +188,10 @@ public final class JavaDocGen { ...@@ -176,6 +188,10 @@ public final class JavaDocGen {
176 javaDoc = generateForTypeConstructor(name); 188 javaDoc = generateForTypeConstructor(name);
177 } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) { 189 } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) {
178 javaDoc = generateForUnionFrom(name); 190 javaDoc = generateForUnionFrom(name);
191 + } else if (type.equals(JavaDocType.ENUM_CLASS)) {
192 + javaDoc = generateForEnum(name);
193 + } else if (type.equals(JavaDocType.ENUM_ATTRIBUTE)) {
194 + javaDoc = generateForEnumAttr(name);
179 } else { 195 } else {
180 javaDoc = generateForConstructors(name); 196 javaDoc = generateForConstructors(name);
181 } 197 }
...@@ -183,7 +199,18 @@ public final class JavaDocGen { ...@@ -183,7 +199,18 @@ public final class JavaDocGen {
183 } 199 }
184 200
185 /** 201 /**
186 - * Generate javaDocs for getter method. 202 + * Generates javaDocs for enum's attributes.
203 + *
204 + * @param name attribute name
205 + * @return javaDocs
206 + */
207 + private static String generateForEnumAttr(String name) {
208 + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
209 + + name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
210 + }
211 +
212 + /**
213 + * Generates javaDocs for getter method.
187 * 214 *
188 * @param attribute attribute 215 * @param attribute attribute
189 * @param isList is list attribute 216 * @param isList is list attribute
...@@ -272,30 +299,28 @@ public final class JavaDocGen { ...@@ -272,30 +299,28 @@ public final class JavaDocGen {
272 } 299 }
273 300
274 /** 301 /**
275 - * Generates javaDocs for typedef constructor. 302 + * Generates javaDocs for the impl class.
276 * 303 *
277 - * @param attribute attribute 304 + * @param className class name
278 * @return javaDocs 305 * @return javaDocs
279 */ 306 */
280 - private static String generateForTypeDefConstructor(String attribute) { 307 + private static String generateForImplClass(String className) {
281 - return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR 308 + return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
282 - + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
283 - + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
284 - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
285 } 309 }
286 310
287 /** 311 /**
288 - * Generate javaDocs for the impl class. 312 + * Generates javaDocs for enum.
289 * 313 *
290 - * @param className class name 314 + * @param className enum class name
291 * @return javaDocs 315 * @return javaDocs
292 */ 316 */
293 - private static String generateForImplClass(String className) { 317 + private static String generateForEnum(String className) {
294 - return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; 318 + return NEW_LINE + NEW_LINE + JAVA_DOC_FIRST_LINE + ENUM_CLASS_JAVADOC + className + PERIOD + NEW_LINE
319 + + JAVA_DOC_END_LINE;
295 } 320 }
296 321
297 /** 322 /**
298 - * Generate javaDocs for the builder class. 323 + * Generates javaDocs for the builder class.
299 * 324 *
300 * @param className class name 325 * @param className class name
301 * @return javaDocs 326 * @return javaDocs
...@@ -306,7 +331,7 @@ public final class JavaDocGen { ...@@ -306,7 +331,7 @@ public final class JavaDocGen {
306 } 331 }
307 332
308 /** 333 /**
309 - * Generate javaDoc for the interface. 334 + * Generates javaDoc for the interface.
310 * 335 *
311 * @param interfaceName interface name 336 * @param interfaceName interface name
312 * @return javaDocs 337 * @return javaDocs
...@@ -317,7 +342,7 @@ public final class JavaDocGen { ...@@ -317,7 +342,7 @@ public final class JavaDocGen {
317 } 342 }
318 343
319 /** 344 /**
320 - * Generate javaDoc for the builder interface. 345 + * Generates javaDoc for the builder interface.
321 * 346 *
322 * @param builderforName builder for name 347 * @param builderforName builder for name
323 * @return javaDocs 348 * @return javaDocs
...@@ -328,7 +353,7 @@ public final class JavaDocGen { ...@@ -328,7 +353,7 @@ public final class JavaDocGen {
328 } 353 }
329 354
330 /** 355 /**
331 - * Generate javaDocs for package-info. 356 + * Generates javaDocs for package-info.
332 * 357 *
333 * @param packageName package name 358 * @param packageName package name
334 * @return javaDocs 359 * @return javaDocs
...@@ -338,7 +363,7 @@ public final class JavaDocGen { ...@@ -338,7 +363,7 @@ public final class JavaDocGen {
338 } 363 }
339 364
340 /** 365 /**
341 - * Generate javaDocs for default constructor. 366 + * Generates javaDocs for default constructor.
342 * 367 *
343 * @param className class name 368 * @param className class name
344 * @return javaDocs 369 * @return javaDocs
...@@ -349,7 +374,7 @@ public final class JavaDocGen { ...@@ -349,7 +374,7 @@ public final class JavaDocGen {
349 } 374 }
350 375
351 /** 376 /**
352 - * Generate javaDocs for constructor with parameters. 377 + * Generates javaDocs for constructor with parameters.
353 * 378 *
354 * @param className class name 379 * @param className class name
355 * @return javaDocs 380 * @return javaDocs
...@@ -363,7 +388,7 @@ public final class JavaDocGen { ...@@ -363,7 +388,7 @@ public final class JavaDocGen {
363 } 388 }
364 389
365 /** 390 /**
366 - * Generate javaDocs for build. 391 + * Generates javaDocs for build.
367 * 392 *
368 * @param buildName builder name 393 * @param buildName builder name
369 * @return javaDocs 394 * @return javaDocs
......
...@@ -44,6 +44,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA ...@@ -44,6 +44,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
44 import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES; 44 import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
45 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; 45 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
46 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; 46 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
47 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
47 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; 48 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
48 import static org.slf4j.LoggerFactory.getLogger; 49 import static org.slf4j.LoggerFactory.getLogger;
49 50
...@@ -96,7 +97,7 @@ public final class YangIoUtils { ...@@ -96,7 +97,7 @@ public final class YangIoUtils {
96 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); 97 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
97 98
98 bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); 99 bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
99 - bufferedWriter.write(JavaDocGen.getJavaDoc(PACKAGE_INFO, classInfo, false)); 100 + bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, false));
100 bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); 101 bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN);
101 102
102 bufferedWriter.close(); 103 bufferedWriter.close();
......
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 * 1 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 2 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 3 * you may not use this file except in compliance with the License.
......
...@@ -17,10 +17,13 @@ ...@@ -17,10 +17,13 @@
17 package org.onosproject.yangutils.utils.io.impl; 17 package org.onosproject.yangutils.utils.io.impl;
18 18
19 import java.io.File; 19 import java.io.File;
20 +import java.io.FileInputStream;
21 +import java.io.FileOutputStream;
20 import java.io.FileWriter; 22 import java.io.FileWriter;
21 import java.io.IOException; 23 import java.io.IOException;
22 import java.lang.reflect.Constructor; 24 import java.lang.reflect.Constructor;
23 import java.lang.reflect.InvocationTargetException; 25 import java.lang.reflect.InvocationTargetException;
26 +import java.util.Calendar;
24 27
25 import org.junit.Rule; 28 import org.junit.Rule;
26 import org.junit.Test; 29 import org.junit.Test;
...@@ -40,7 +43,8 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -40,7 +43,8 @@ import static org.slf4j.LoggerFactory.getLogger;
40 public final class CopyrightHeaderTest { 43 public final class CopyrightHeaderTest {
41 44
42 private final Logger log = getLogger(getClass()); 45 private final Logger log = getLogger(getClass());
43 - 46 + private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR)
47 + + "-present Open Networking Laboratory\n";
44 @Rule 48 @Rule
45 public ExpectedException thrown = ExpectedException.none(); 49 public ExpectedException thrown = ExpectedException.none();
46 50
...@@ -74,16 +78,30 @@ public final class CopyrightHeaderTest { ...@@ -74,16 +78,30 @@ public final class CopyrightHeaderTest {
74 @Test 78 @Test
75 public void testGetCopyrightHeader() throws IOException { 79 public void testGetCopyrightHeader() throws IOException {
76 80
77 - String baseDir = System.getProperty("basedir"); 81 + String path = "src/test/resources/CopyrightHeader.txt";
78 - String path = "/src/test/resources/CopyrightHeader.txt"; 82 +
83 + File testRsc = new File(path);
84 + FileInputStream in = new FileInputStream(testRsc);
85 +
86 + File testFile = new File("target/TestHeader.txt");
87 + FileOutputStream out = new FileOutputStream(testFile);
88 +
89 + out.write(COPYRIGHTS_FIRST_LINE.getBytes());
90 + int c = 0;
91 + while ((c = in.read()) != -1) {
92 + out.write(c);
93 + }
79 94
80 String licenseHeader = getCopyrightHeader(); 95 String licenseHeader = getCopyrightHeader();
81 File test = new File("target/TestCopyrightHeader.txt"); 96 File test = new File("target/TestCopyrightHeader.txt");
82 97
83 - FileWriter out = new FileWriter(test); 98 + FileWriter writer = new FileWriter(test);
84 - out.write(licenseHeader); 99 + writer.write(licenseHeader);
100 + writer.close();
85 out.close(); 101 out.close();
102 + out.flush();
103 + in.close();
86 104
87 - assertThat(true, is(contentEquals(test, new File(baseDir + path)))); 105 + assertThat(true, is(contentEquals(test, testFile)));
88 } 106 }
89 } 107 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -159,7 +159,7 @@ public final class JavaDocGenTest { ...@@ -159,7 +159,7 @@ public final class JavaDocGenTest {
159 @Test 159 @Test
160 public void packageInfoGenerationTest() { 160 public void packageInfoGenerationTest() {
161 String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); 161 String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
162 - assertThat(true, is(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(END_STRING))); 162 + assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
163 } 163 }
164 164
165 /** 165 /**
......
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 * 1 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 2 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 3 * you may not use this file except in compliance with the License.
......