Bharat saraswal
Committed by Thomas Vachuska

[ONOS-4411,ONOS-4413,ONOS-4526] Yang Enumeration Translator and Defect fixes.

Change-Id: Ie5b6b5d6d6df283a57ae06b1979f0d03022f3baf
Showing 33 changed files with 924 additions and 457 deletions
...@@ -78,6 +78,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp ...@@ -78,6 +78,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
78 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 78 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
79 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 79 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
80 import static org.onosproject.yangutils.utils.YangConstructType.ENUM_DATA; 80 import static org.onosproject.yangutils.utils.YangConstructType.ENUM_DATA;
81 +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
82 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
81 83
82 /** 84 /**
83 * Represents listener based call back function corresponding to the "enum" rule 85 * Represents listener based call back function corresponding to the "enum" rule
...@@ -104,10 +106,18 @@ public final class EnumListener { ...@@ -104,10 +106,18 @@ public final class EnumListener {
104 checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY); 106 checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY);
105 107
106 YangEnum enumNode = new YangEnum(); 108 YangEnum enumNode = new YangEnum();
107 - enumNode.setNamedValue(ctx.string().getText()); 109 + enumNode.setNamedValue(getValidNamedValue(ctx.string().getText()));
108 listener.getParsedDataStack().push(enumNode); 110 listener.getParsedDataStack().push(enumNode);
109 } 111 }
110 112
113 + /* Removes quotes from the enum name if present.*/
114 + private static String getValidNamedValue(String name) {
115 + if (name.contains(QUOTES)) {
116 + name = name.replace(QUOTES, EMPTY_STRING);
117 + }
118 + return name;
119 + }
120 +
111 /** 121 /**
112 * It is called when parser exits from grammar rule (enum), it perform 122 * It is called when parser exits from grammar rule (enum), it perform
113 * validations and update the data model tree. 123 * validations and update the data model tree.
...@@ -163,7 +173,8 @@ public final class EnumListener { ...@@ -163,7 +173,8 @@ public final class EnumListener {
163 } 173 }
164 } else { 174 } else {
165 throw new ParserException( 175 throw new ParserException(
166 - constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT)); 176 + constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(),
177 + EXIT));
167 } 178 }
168 } 179 }
169 } 180 }
......
...@@ -158,6 +158,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -158,6 +158,7 @@ public class YangUtilManager extends AbstractMojo {
158 logInfo = logInfo + NEW_LINE + e.getMessage(); 158 logInfo = logInfo + NEW_LINE + e.getMessage();
159 } 159 }
160 getLog().info(logInfo); 160 getLog().info(logInfo);
161 + throw e;
161 } 162 }
162 } 163 }
163 164
......
...@@ -147,7 +147,7 @@ public class JavaImportData { ...@@ -147,7 +147,7 @@ public class JavaImportData {
147 } 147 }
148 } 148 }
149 149
150 - if (isListToImport) { 150 + if (getIfListImported()) {
151 imports.add(getImportForList()); 151 imports.add(getImportForList());
152 } 152 }
153 153
......
...@@ -166,6 +166,7 @@ public class JavaQualifiedTypeInfo ...@@ -166,6 +166,7 @@ public class JavaQualifiedTypeInfo
166 * @return return the import info for this attribute 166 * @return return the import info for this attribute
167 */ 167 */
168 public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) { 168 public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) {
169 +
169 /* 170 /*
170 * Get the java qualified type information for the wrapper classes and 171 * Get the java qualified type information for the wrapper classes and
171 * set it in new java attribute information. 172 * set it in new java attribute information.
...@@ -178,7 +179,6 @@ public class JavaQualifiedTypeInfo ...@@ -178,7 +179,6 @@ public class JavaQualifiedTypeInfo
178 return qualifiedInfoOfFromString; 179 return qualifiedInfoOfFromString;
179 } 180 }
180 181
181 -
182 @Override 182 @Override
183 public int hashCode() { 183 public int hashCode() {
184 return Objects.hash(pkgInfo, classInfo); 184 return Objects.hash(pkgInfo, classInfo);
......
...@@ -51,7 +51,6 @@ public class TempJavaBeanFragmentFiles ...@@ -51,7 +51,6 @@ public class TempJavaBeanFragmentFiles
51 51
52 super(javaFileInfo); 52 super(javaFileInfo);
53 53
54 -
55 /* 54 /*
56 * Initialize getterImpl, attributes, constructor, hash code, equals and 55 * Initialize getterImpl, attributes, constructor, hash code, equals and
57 * to strings when generation file type matches to impl class mask. 56 * to strings when generation file type matches to impl class mask.
...@@ -98,6 +97,7 @@ public class TempJavaBeanFragmentFiles ...@@ -98,6 +97,7 @@ public class TempJavaBeanFragmentFiles
98 * files 97 * files
99 * @throws IOException IO operation fail 98 * @throws IOException IO operation fail
100 */ 99 */
100 + @Override
101 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) 101 void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
102 throws IOException { 102 throws IOException {
103 super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); 103 super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
...@@ -124,5 +124,4 @@ public class TempJavaBeanFragmentFiles ...@@ -124,5 +124,4 @@ public class TempJavaBeanFragmentFiles
124 super.freeTemporaryResources(isErrorOccurred); 124 super.freeTemporaryResources(isErrorOccurred);
125 } 125 }
126 126
127 -
128 } 127 }
......
...@@ -67,7 +67,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -67,7 +67,6 @@ public class TempJavaCodeFragmentFiles {
67 */ 67 */
68 private TempJavaEventListenerFragmentFiles eventListenerTempFiles; 68 private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
69 69
70 -
71 /** 70 /**
72 * Creates an instance of temporary java code fragment. 71 * Creates an instance of temporary java code fragment.
73 * 72 *
...@@ -126,7 +125,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -126,7 +125,6 @@ public class TempJavaCodeFragmentFiles {
126 this.beanTempFiles = beanTempFiles; 125 this.beanTempFiles = beanTempFiles;
127 } 126 }
128 127
129 -
130 /** 128 /**
131 * Retrieves the temp file handle for data type file generation. 129 * Retrieves the temp file handle for data type file generation.
132 * 130 *
...@@ -136,7 +134,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -136,7 +134,6 @@ public class TempJavaCodeFragmentFiles {
136 return typeTempFiles; 134 return typeTempFiles;
137 } 135 }
138 136
139 -
140 /** 137 /**
141 * Sets temp file handle for data type file generation. 138 * Sets temp file handle for data type file generation.
142 * 139 *
...@@ -234,23 +231,29 @@ public class TempJavaCodeFragmentFiles { ...@@ -234,23 +231,29 @@ public class TempJavaCodeFragmentFiles {
234 getBeanTempFiles().generateJavaFile(fileType, curNode); 231 getBeanTempFiles().generateJavaFile(fileType, curNode);
235 } 232 }
236 233
237 - /** 234 + /*
238 * Creates user defined data type class file. 235 * Creates user defined data type class file.
239 */ 236 */
240 if ((fileType & GENERATE_TYPE_CLASS) != 0) { 237 if ((fileType & GENERATE_TYPE_CLASS) != 0) {
241 getTypeTempFiles().generateJavaFile(fileType, curNode); 238 getTypeTempFiles().generateJavaFile(fileType, curNode);
242 } 239 }
243 240
244 - 241 + /*
242 + * Creats service and manager class file.
243 + */
245 if (fileType == GENERATE_SERVICE_AND_MANAGER) { 244 if (fileType == GENERATE_SERVICE_AND_MANAGER) {
246 -
247 getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); 245 getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
246 + }
248 247
249 - 248 + /*
249 + * Creats enumeration class file.
250 + */
251 + if (fileType == GENERATE_ENUM_CLASS) {
252 + getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
250 } 253 }
251 254
252 if ((fileType & GENERATE_EVENT_CLASS) != 0) { 255 if ((fileType & GENERATE_EVENT_CLASS) != 0) {
253 - /** 256 + /*
254 * Creates event class file. 257 * Creates event class file.
255 */ 258 */
256 if (getEventTempFiles() != null) { 259 if (getEventTempFiles() != null) {
...@@ -350,7 +353,6 @@ public class TempJavaCodeFragmentFiles { ...@@ -350,7 +353,6 @@ public class TempJavaCodeFragmentFiles {
350 throw new TranslatorException("default constructor should not be added"); 353 throw new TranslatorException("default constructor should not be added");
351 } 354 }
352 355
353 -
354 /** 356 /**
355 * Adds build method's implementation for class. 357 * Adds build method's implementation for class.
356 * 358 *
...@@ -397,22 +399,4 @@ public class TempJavaCodeFragmentFiles { ...@@ -397,22 +399,4 @@ public class TempJavaCodeFragmentFiles {
397 } 399 }
398 } 400 }
399 401
400 -
401 - /**
402 - * Adds enum attributes to temporary files.
403 - *
404 - * @param curNode current YANG node
405 - * @throws IOException when fails to do IO operations
406 - */
407 - public void addEnumAttributeToTempFiles(YangNode curNode)
408 - throws IOException {
409 -
410 - if (getEnumerationTempFiles() != null) {
411 - getEnumerationTempFiles().addEnumAttributeToTempFiles(curNode);
412 - return;
413 - }
414 -
415 - throw new TranslatorException("build should not be added");
416 - }
417 -
418 } 402 }
......
...@@ -15,14 +15,68 @@ ...@@ -15,14 +15,68 @@
15 */ 15 */
16 package org.onosproject.yangutils.translator.tojava; 16 package org.onosproject.yangutils.translator.tojava;
17 17
18 +import java.io.File;
18 import java.io.IOException; 19 import java.io.IOException;
20 +import java.util.ArrayList;
21 +import java.util.HashMap;
22 +import java.util.List;
23 +import java.util.Map;
24 +
25 +import org.onosproject.yangutils.datamodel.YangDataTypes;
26 +import org.onosproject.yangutils.datamodel.YangEnum;
27 +import org.onosproject.yangutils.datamodel.YangEnumeration;
28 +import org.onosproject.yangutils.datamodel.YangNode;
29 +import org.onosproject.yangutils.translator.exception.TranslatorException;
30 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
31 +
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
33 +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
34 +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
35 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
36 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
37 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
38 +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
19 39
20 /** 40 /**
21 * Represents implementation of java code fragments temporary implementations. 41 * Represents implementation of java code fragments temporary implementations.
22 * Maintains the temp files required specific for enumeration java snippet generation. 42 * Maintains the temp files required specific for enumeration java snippet generation.
23 */ 43 */
24 -public class TempJavaEnumerationFragmentFiles 44 +public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
25 - extends TempJavaFragmentFiles { 45 +
46 + /**
47 + * File name for temporary enum class.
48 + */
49 + private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
50 +
51 + /**
52 + * File name for enum class file name suffix.
53 + */
54 + private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
55 +
56 + /**
57 + * Current enum's value.
58 + */
59 + private int enumValue;
60 +
61 + /**
62 + * Contains data of enumSet.
63 + */
64 + private Map<String, Integer> enumStringMap = new HashMap<>();
65 +
66 + /**
67 + * Contains data of enumSet.
68 + */
69 + private List<String> enumStringList;
70 +
71 + /**
72 + * Temporary file handle for enum class file.
73 + */
74 + private File enumClassTempFileHandle;
75 +
76 + /**
77 + * Java file handle for enum class.
78 + */
79 + private File enumClassJavaFileHandle;
26 80
27 /** 81 /**
28 * Creates an instance of temporary java code fragment. 82 * Creates an instance of temporary java code fragment.
...@@ -32,6 +86,212 @@ public class TempJavaEnumerationFragmentFiles ...@@ -32,6 +86,212 @@ public class TempJavaEnumerationFragmentFiles
32 */ 86 */
33 public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo) 87 public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo)
34 throws IOException { 88 throws IOException {
89 +
35 super(javaFileInfo); 90 super(javaFileInfo);
91 + setEnumSetJavaMap(new HashMap<>());
92 + setEnumStringList(new ArrayList<>());
93 + /*
94 + * Initialize enum when generation file type matches to enum class mask.
95 + */
96 + addGeneratedTempFile(ENUM_IMPL_MASK);
97 + setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
98 + }
99 +
100 + /**
101 + * Returns enum class java file handle.
102 + *
103 + * @return enum class java file handle
104 + */
105 + public File getEnumClassJavaFileHandle() {
106 + return enumClassJavaFileHandle;
107 + }
108 +
109 + /**
110 + * Sets enum class java file handle.
111 + *
112 + * @param enumClassJavaFileHandle enum class java file handle
113 + */
114 + private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
115 + this.enumClassJavaFileHandle = enumClassJavaFileHandle;
116 + }
117 +
118 + /**
119 + * Returns enum's value.
120 + *
121 + * @return enum's value
122 + */
123 + private int getEnumValue() {
124 + return enumValue;
125 + }
126 +
127 + /**
128 + * Sets enum's value.
129 + *
130 + * @param enumValue enum's value
131 + */
132 + private void setEnumValue(int enumValue) {
133 + this.enumValue = enumValue;
134 + }
135 +
136 + /**
137 + * Returns enum set java map.
138 + *
139 + * @return the enum set java map
140 + */
141 + public Map<String, Integer> getEnumSetJavaMap() {
142 + return enumStringMap;
143 + }
144 +
145 + /**
146 + * Sets enum set java map.
147 + *
148 + * @param map the enum set java map to set
149 + */
150 + private void setEnumSetJavaMap(Map<String, Integer> map) {
151 + this.enumStringMap = map;
152 + }
153 +
154 + /**
155 + * Returns temporary file handle for enum class file.
156 + *
157 + * @return temporary file handle for enum class file
158 + */
159 + public File getEnumClassTempFileHandle() {
160 + return enumClassTempFileHandle;
161 + }
162 +
163 + /**
164 + * Sets temporary file handle for enum class file.
165 + *
166 + * @param enumClassTempFileHandle temporary file handle for enum class file
167 + */
168 + private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
169 + this.enumClassTempFileHandle = enumClassTempFileHandle;
170 + }
171 +
172 + /**
173 + * Adds enum class attributes to temporary file.
174 + *
175 + * @param curEnumInfo current YANG enum
176 + * @throws IOException when fails to do IO operations.
177 + */
178 + private void addAttributesForEnumClass(String curEnumName) throws IOException {
179 + appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue()));
180 + }
181 +
182 + /**
183 + * Adds enum attributes to temporary files.
184 + *
185 + * @param curNode current YANG node
186 + * @throws IOException when fails to do IO operations
187 + */
188 + public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
189 +
190 + super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum());
191 + if (curNode instanceof YangEnumeration) {
192 + YangEnumeration enumeration = (YangEnumeration) curNode;
193 + for (YangEnum curEnum : enumeration.getEnumSet()) {
194 + setEnumValue(curEnum.getValue());
195 + addToEnumStringList(curEnum.getNamedValue());
196 + addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue());
197 + addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue());
198 + }
199 + } else {
200 + throw new TranslatorException("current node should be of enumeration type.");
201 + }
202 + }
203 +
204 + /**
205 + * Returns java attribute for enum class.
206 + *
207 + * @return java attribute
208 + */
209 + public JavaAttributeInfo getJavaAttributeForEnum() {
210 + YangJavaType<?> javaType = new YangJavaType<>();
211 + javaType.setDataType(YangDataTypes.INT32);
212 + javaType.setDataTypeName("int");
213 + javaType.updateJavaQualifiedInfo();
214 + return getAttributeInfoForTheData(
215 + javaType.getJavaQualifiedInfo(),
216 + javaType.getDataTypeName(), javaType,
217 + getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
218 + false);
219 + }
220 +
221 + /**
222 + * Adds current enum name to java list.
223 + *
224 + * @param curEnumName current enum name
225 + */
226 + private void addToEnumSetJavaMap(String curEnumName, int value) {
227 + getEnumSetJavaMap().put(curEnumName.toUpperCase(), value);
228 + }
229 +
230 + /**
231 + * Adds the new attribute info to the target generated temporary files.
232 + *
233 + * @param curEnumName the attribute name that needs to be added to temporary
234 + * files
235 + * @throws IOException IO operation fail
236 + */
237 + void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException {
238 + addAttributesForEnumClass(curEnumName);
239 + }
240 +
241 + /**
242 + * Constructs java code exit.
243 + *
244 + * @param fileType generated file type
245 + * @param curNode current YANG node
246 + * @throws IOException when fails to generate java files
247 + */
248 + @Override
249 + public void generateJavaFile(int fileType, YangNode curNode) throws IOException {
250 + createPackage(curNode);
251 + setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
252 + setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
253 + freeTemporaryResources(false);
254 + }
255 +
256 + /**
257 + * Removes all temporary file handles.
258 + *
259 + * @param isErrorOccurred when translator fails to generate java files we
260 + * need to close all open file handles include temporary files
261 + * and java files.
262 + * @throws IOException when failed to delete the temporary files
263 + */
264 + @Override
265 + public void freeTemporaryResources(boolean isErrorOccurred) throws IOException {
266 + closeFile(getEnumClassJavaFileHandle(), isErrorOccurred);
267 + closeFile(getEnumClassTempFileHandle(), true);
268 + super.freeTemporaryResources(isErrorOccurred);
269 + }
270 +
271 + /**
272 + * Adds to enum string list.
273 + *
274 + * @param curEnumValue current enum value
275 + */
276 + private void addToEnumStringList(String curEnumValue) {
277 + getEnumStringList().add(curEnumValue.toUpperCase());
278 + }
279 +
280 + /**
281 + * Returns enum string list.
282 + *
283 + * @return the enumStringList
284 + */
285 + public List<String> getEnumStringList() {
286 + return enumStringList;
287 + }
288 +
289 + /**
290 + * Sets enum string list.
291 + *
292 + * @param enumStringList the enumStringList to set
293 + */
294 + public void setEnumStringList(List<String> enumStringList) {
295 + this.enumStringList = enumStringList;
36 } 296 }
37 } 297 }
......
...@@ -56,7 +56,7 @@ public class TempJavaEventFragmentFiles ...@@ -56,7 +56,7 @@ public class TempJavaEventFragmentFiles
56 setExtendsList(new ArrayList<>()); 56 setExtendsList(new ArrayList<>());
57 setJavaImportData(new JavaImportData()); 57 setJavaImportData(new JavaImportData());
58 setJavaFileInfo(javaFileInfo); 58 setJavaFileInfo(javaFileInfo);
59 - clearGeneratedTempFileMask(); 59 +
60 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), 60 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
61 getJavaFileInfo().getPackageFilePath())); 61 getJavaFileInfo().getPackageFilePath()));
62 62
...@@ -80,7 +80,6 @@ public class TempJavaEventFragmentFiles ...@@ -80,7 +80,6 @@ public class TempJavaEventFragmentFiles
80 this.eventJavaFileHandle = eventJavaFileHandle; 80 this.eventJavaFileHandle = eventJavaFileHandle;
81 } 81 }
82 82
83 -
84 /** 83 /**
85 * Constructs java code exit. 84 * Constructs java code exit.
86 * 85 *
...@@ -88,6 +87,7 @@ public class TempJavaEventFragmentFiles ...@@ -88,6 +87,7 @@ public class TempJavaEventFragmentFiles
88 * @param curNode current YANG node 87 * @param curNode current YANG node
89 * @throws IOException when fails to generate java files 88 * @throws IOException when fails to generate java files
90 */ 89 */
90 + @Override
91 public void generateJavaFile(int fileType, YangNode curNode) 91 public void generateJavaFile(int fileType, YangNode curNode)
92 throws IOException { 92 throws IOException {
93 93
...@@ -113,6 +113,7 @@ public class TempJavaEventFragmentFiles ...@@ -113,6 +113,7 @@ public class TempJavaEventFragmentFiles
113 * and java files. 113 * and java files.
114 * @throws IOException when failed to delete the temporary files 114 * @throws IOException when failed to delete the temporary files
115 */ 115 */
116 + @Override
116 public void freeTemporaryResources(boolean isErrorOccurred) 117 public void freeTemporaryResources(boolean isErrorOccurred)
117 throws IOException { 118 throws IOException {
118 boolean isError = isErrorOccurred; 119 boolean isError = isErrorOccurred;
...@@ -122,5 +123,6 @@ public class TempJavaEventFragmentFiles ...@@ -122,5 +123,6 @@ public class TempJavaEventFragmentFiles
122 closeFile(getEventJavaFileHandle(), isError); 123 closeFile(getEventJavaFileHandle(), isError);
123 124
124 super.freeTemporaryResources(isErrorOccurred); 125 super.freeTemporaryResources(isErrorOccurred);
126 +
125 } 127 }
126 } 128 }
......
...@@ -56,7 +56,6 @@ public class TempJavaEventListenerFragmentFiles ...@@ -56,7 +56,6 @@ public class TempJavaEventListenerFragmentFiles
56 setExtendsList(new ArrayList<>()); 56 setExtendsList(new ArrayList<>());
57 setJavaImportData(new JavaImportData()); 57 setJavaImportData(new JavaImportData());
58 setJavaFileInfo(javaFileInfo); 58 setJavaFileInfo(javaFileInfo);
59 - clearGeneratedTempFileMask();
60 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), 59 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
61 getJavaFileInfo().getPackageFilePath())); 60 getJavaFileInfo().getPackageFilePath()));
62 } 61 }
...@@ -79,7 +78,6 @@ public class TempJavaEventListenerFragmentFiles ...@@ -79,7 +78,6 @@ public class TempJavaEventListenerFragmentFiles
79 this.eventListenerJavaFileHandle = eventListenerJavaFileHandle; 78 this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
80 } 79 }
81 80
82 -
83 /** 81 /**
84 * Constructs java code exit. 82 * Constructs java code exit.
85 * 83 *
...@@ -87,6 +85,7 @@ public class TempJavaEventListenerFragmentFiles ...@@ -87,6 +85,7 @@ public class TempJavaEventListenerFragmentFiles
87 * @param curNode current YANG node 85 * @param curNode current YANG node
88 * @throws IOException when fails to generate java files 86 * @throws IOException when fails to generate java files
89 */ 87 */
88 + @Override
90 public void generateJavaFile(int fileType, YangNode curNode) 89 public void generateJavaFile(int fileType, YangNode curNode)
91 throws IOException { 90 throws IOException {
92 91
...@@ -112,6 +111,7 @@ public class TempJavaEventListenerFragmentFiles ...@@ -112,6 +111,7 @@ public class TempJavaEventListenerFragmentFiles
112 * and java files. 111 * and java files.
113 * @throws IOException when failed to delete the temporary files 112 * @throws IOException when failed to delete the temporary files
114 */ 113 */
114 + @Override
115 public void freeTemporaryResources(boolean isErrorOccurred) 115 public void freeTemporaryResources(boolean isErrorOccurred)
116 throws IOException { 116 throws IOException {
117 boolean isError = isErrorOccurred; 117 boolean isError = isErrorOccurred;
......
...@@ -19,12 +19,9 @@ import java.io.File; ...@@ -19,12 +19,9 @@ import java.io.File;
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ArrayList; 20 import java.util.ArrayList;
21 import java.util.List; 21 import java.util.List;
22 -import java.util.Set;
23 22
24 import org.onosproject.yangutils.datamodel.RpcNotificationContainer; 23 import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
25 import org.onosproject.yangutils.datamodel.YangCase; 24 import org.onosproject.yangutils.datamodel.YangCase;
26 -import org.onosproject.yangutils.datamodel.YangEnum;
27 -import org.onosproject.yangutils.datamodel.YangEnumeration;
28 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
29 import org.onosproject.yangutils.datamodel.YangLeafList; 26 import org.onosproject.yangutils.datamodel.YangLeafList;
30 import org.onosproject.yangutils.datamodel.YangLeavesHolder; 27 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
...@@ -41,8 +38,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -41,8 +38,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
44 -import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
42 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
...@@ -50,13 +47,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -50,13 +47,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
50 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
51 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
52 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; 49 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
50 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
53 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; 51 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
54 -import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
55 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; 52 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
56 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; 53 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
57 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; 54 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
58 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; 55 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
59 -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
60 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; 56 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
61 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; 57 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
62 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; 58 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
...@@ -68,6 +64,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy ...@@ -68,6 +64,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
68 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; 64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
69 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; 65 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
70 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; 66 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
67 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
71 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; 68 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
72 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; 69 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
73 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; 70 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
...@@ -81,11 +78,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFrag ...@@ -81,11 +78,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFrag
81 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; 78 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
82 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport; 79 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
83 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 80 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
81 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport;
84 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; 82 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
85 -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils 83 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
86 - .isHasAugmentationExtended; 84 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
87 -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils 85 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
88 - .prepareJavaFileGeneratorForExtendsList;
89 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 86 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
90 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 87 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
91 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 88 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
...@@ -98,9 +95,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; ...@@ -98,9 +95,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
98 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 95 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
99 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 96 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
100 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; 97 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
98 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
101 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; 99 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; 100 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.getAbsolutePackagePath; 101 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
105 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 102 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
106 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; 103 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
...@@ -110,35 +107,43 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles ...@@ -110,35 +107,43 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles
110 * Manages the common temp file required for Java file(s) generated. 107 * Manages the common temp file required for Java file(s) generated.
111 */ 108 */
112 public class TempJavaFragmentFiles { 109 public class TempJavaFragmentFiles {
110 +
113 /** 111 /**
114 * Information about the java files being generated. 112 * Information about the java files being generated.
115 */ 113 */
116 private JavaFileInfo javaFileInfo; 114 private JavaFileInfo javaFileInfo;
115 +
117 /** 116 /**
118 * Imported class info. 117 * Imported class info.
119 */ 118 */
120 private JavaImportData javaImportData; 119 private JavaImportData javaImportData;
120 +
121 /** 121 /**
122 * The variable which guides the types of temporary files generated using 122 * The variable which guides the types of temporary files generated using
123 * the temporary generated file types mask. 123 * the temporary generated file types mask.
124 */ 124 */
125 private int generatedTempFiles; 125 private int generatedTempFiles;
126 +
126 /** 127 /**
127 * Absolute path where the target java file needs to be generated. 128 * Absolute path where the target java file needs to be generated.
128 */ 129 */
129 private String absoluteDirPath; 130 private String absoluteDirPath;
131 +
130 /** 132 /**
131 * Contains all the interface(s)/class name which will be extended by generated files. 133 * Contains all the interface(s)/class name which will be extended by generated files.
132 */ 134 */
133 private List<String> extendsList = new ArrayList<>(); 135 private List<String> extendsList = new ArrayList<>();
136 +
134 /** 137 /**
135 * File type extension for java classes. 138 * File type extension for java classes.
136 */ 139 */
137 private static final String JAVA_FILE_EXTENSION = ".java"; 140 private static final String JAVA_FILE_EXTENSION = ".java";
141 +
138 /** 142 /**
139 * File type extension for temporary classes. 143 * File type extension for temporary classes.
140 */ 144 */
141 private static final String TEMP_FILE_EXTENSION = ".tmp"; 145 private static final String TEMP_FILE_EXTENSION = ".tmp";
146 +
142 /** 147 /**
143 * Folder suffix for temporary files folder. 148 * Folder suffix for temporary files folder.
144 */ 149 */
...@@ -168,58 +173,62 @@ public class TempJavaFragmentFiles { ...@@ -168,58 +173,62 @@ public class TempJavaFragmentFiles {
168 * File name for attributes. 173 * File name for attributes.
169 */ 174 */
170 private static final String ATTRIBUTE_FILE_NAME = "Attributes"; 175 private static final String ATTRIBUTE_FILE_NAME = "Attributes";
176 +
171 /** 177 /**
172 * File name for to string method. 178 * File name for to string method.
173 */ 179 */
174 private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; 180 private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
181 +
175 /** 182 /**
176 * File name for hash code method. 183 * File name for hash code method.
177 */ 184 */
178 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; 185 private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
186 +
179 /** 187 /**
180 * File name for equals method. 188 * File name for equals method.
181 */ 189 */
182 private static final String EQUALS_METHOD_FILE_NAME = "Equals"; 190 private static final String EQUALS_METHOD_FILE_NAME = "Equals";
183 191
184 /** 192 /**
185 - * File name for temporary enum class. 193 + * File name for from string method.
186 */ 194 */
187 - private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass"; 195 + private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
188 196
189 /** 197 /**
190 * File name for interface java file name suffix. 198 * File name for interface java file name suffix.
191 */ 199 */
192 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; 200 private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
201 +
193 /** 202 /**
194 * File name for builder interface file name suffix. 203 * File name for builder interface file name suffix.
195 */ 204 */
196 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; 205 private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
206 +
197 /** 207 /**
198 * File name for builder class file name suffix. 208 * File name for builder class file name suffix.
199 */ 209 */
200 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; 210 private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
211 +
201 /** 212 /**
202 * File name for impl class file name suffix. 213 * File name for impl class file name suffix.
203 */ 214 */
204 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL; 215 private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
205 216
206 /** 217 /**
207 - * File name for enum class file name suffix.
208 - */
209 - private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
210 -
211 - /**
212 * Java file handle for interface file. 218 * Java file handle for interface file.
213 */ 219 */
214 private File interfaceJavaFileHandle; 220 private File interfaceJavaFileHandle;
221 +
215 /** 222 /**
216 * Java file handle for builder interface file. 223 * Java file handle for builder interface file.
217 */ 224 */
218 private File builderInterfaceJavaFileHandle; 225 private File builderInterfaceJavaFileHandle;
226 +
219 /** 227 /**
220 * Java file handle for builder class file. 228 * Java file handle for builder class file.
221 */ 229 */
222 private File builderClassJavaFileHandle; 230 private File builderClassJavaFileHandle;
231 +
223 /** 232 /**
224 * Java file handle for impl class file. 233 * Java file handle for impl class file.
225 */ 234 */
...@@ -254,18 +263,21 @@ public class TempJavaFragmentFiles { ...@@ -254,18 +263,21 @@ public class TempJavaFragmentFiles {
254 * Temporary file handle for hash code method of class. 263 * Temporary file handle for hash code method of class.
255 */ 264 */
256 private File hashCodeImplTempFileHandle; 265 private File hashCodeImplTempFileHandle;
266 +
257 /** 267 /**
258 * Temporary file handle for equals method of class. 268 * Temporary file handle for equals method of class.
259 */ 269 */
260 private File equalsImplTempFileHandle; 270 private File equalsImplTempFileHandle;
271 +
261 /** 272 /**
262 * Temporary file handle for to string method of class. 273 * Temporary file handle for to string method of class.
263 */ 274 */
264 private File toStringImplTempFileHandle; 275 private File toStringImplTempFileHandle;
276 +
265 /** 277 /**
266 - * Temporary file handle for enum class file. 278 + * Temporary file handle for from string method of class.
267 */ 279 */
268 - private File enumClassTempFileHandle; 280 + private File fromStringImplTempFileHandle;
269 281
270 /** 282 /**
271 * Import info for case. 283 * Import info for case.
...@@ -275,53 +287,12 @@ public class TempJavaFragmentFiles { ...@@ -275,53 +287,12 @@ public class TempJavaFragmentFiles {
275 /** 287 /**
276 * Is attribute added. 288 * Is attribute added.
277 */ 289 */
278 - private boolean isAttributePresent = false; 290 + private boolean isAttributePresent;
279 - /**
280 - * Current enum's value.
281 - */
282 - private int enumValue;
283 - /*
284 - * Java file handle for enum class.
285 - */
286 - private File enumClassJavaFileHandle;
287 -
288 - public TempJavaFragmentFiles() {
289 - }
290 -
291 - /**
292 - * Returns enum class java file handle.
293 - *
294 - * @return enum class java file handle
295 - */
296 - private File getEnumClassJavaFileHandle() {
297 - return enumClassJavaFileHandle;
298 - }
299 -
300 - /**
301 - * Sets enum class java file handle.
302 - *
303 - * @param enumClassJavaFileHandle enum class java file handle
304 - */
305 - private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
306 - this.enumClassJavaFileHandle = enumClassJavaFileHandle;
307 - }
308 -
309 - /**
310 - * Returns enum's value.
311 - *
312 - * @return enum's value
313 - */
314 - private int getEnumValue() {
315 - return enumValue;
316 - }
317 291
318 /** 292 /**
319 - * Sets enum's value. 293 + * Creates an instance of temp java fragment files.
320 - *
321 - * @param enumValue enum's value
322 */ 294 */
323 - private void setEnumValue(int enumValue) { 295 + public TempJavaFragmentFiles() {
324 - this.enumValue = enumValue;
325 } 296 }
326 297
327 /** 298 /**
...@@ -378,12 +349,22 @@ public class TempJavaFragmentFiles { ...@@ -378,12 +349,22 @@ public class TempJavaFragmentFiles {
378 } 349 }
379 350
380 /** 351 /**
381 - * Sets generated file files. 352 + * Adds to generated temporary files.
382 * 353 *
383 * @param generatedTempFile generated file 354 * @param generatedTempFile generated file
384 */ 355 */
385 void addGeneratedTempFile(int generatedTempFile) { 356 void addGeneratedTempFile(int generatedTempFile) {
386 generatedTempFiles |= generatedTempFile; 357 generatedTempFiles |= generatedTempFile;
358 + setGeneratedTempFiles(generatedTempFiles);
359 + }
360 +
361 + /**
362 + * Sets generated file files.
363 + *
364 + * @param generatedTempFile generated file
365 + */
366 + void setGeneratedTempFiles(int fileType) {
367 + generatedTempFiles = fileType;
387 } 368 }
388 369
389 /** 370 /**
...@@ -495,6 +476,25 @@ public class TempJavaFragmentFiles { ...@@ -495,6 +476,25 @@ public class TempJavaFragmentFiles {
495 } 476 }
496 477
497 /** 478 /**
479 + * Returns from string method's temporary file handle.
480 + *
481 + * @return from string method's temporary file handle
482 + */
483 + public File getFromStringImplTempFileHandle() {
484 + return fromStringImplTempFileHandle;
485 + }
486 +
487 + /**
488 + * Sets from string method's temporary file handle.
489 + *
490 + * @param fromStringImplTempFileHandle from string method's temporary file
491 + * handle
492 + */
493 + private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
494 + this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
495 + }
496 +
497 + /**
498 * Creates an instance of temporary java code fragment. 498 * Creates an instance of temporary java code fragment.
499 * 499 *
500 * @param javaFileInfo generated java file information 500 * @param javaFileInfo generated java file information
...@@ -505,7 +505,6 @@ public class TempJavaFragmentFiles { ...@@ -505,7 +505,6 @@ public class TempJavaFragmentFiles {
505 setExtendsList(new ArrayList<>()); 505 setExtendsList(new ArrayList<>());
506 setJavaImportData(new JavaImportData()); 506 setJavaImportData(new JavaImportData());
507 setJavaFileInfo(javaFileInfo); 507 setJavaFileInfo(javaFileInfo);
508 - clearGeneratedTempFileMask();
509 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), 508 setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
510 getJavaFileInfo().getPackageFilePath())); 509 getJavaFileInfo().getPackageFilePath()));
511 510
...@@ -557,9 +556,16 @@ public class TempJavaFragmentFiles { ...@@ -557,9 +556,16 @@ public class TempJavaFragmentFiles {
557 addGeneratedTempFile(HASH_CODE_IMPL_MASK); 556 addGeneratedTempFile(HASH_CODE_IMPL_MASK);
558 addGeneratedTempFile(EQUALS_IMPL_MASK); 557 addGeneratedTempFile(EQUALS_IMPL_MASK);
559 addGeneratedTempFile(TO_STRING_IMPL_MASK); 558 addGeneratedTempFile(TO_STRING_IMPL_MASK);
559 + addGeneratedTempFile(FROM_STRING_IMPL_MASK);
560 } 560 }
561 561
562 /* 562 /*
563 + * Initialize temp files to generate enum class.
564 + */
565 + if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
566 + addGeneratedTempFile(FROM_STRING_IMPL_MASK);
567 + }
568 + /*
563 * Initialize getter and setter when generation file type matches to 569 * Initialize getter and setter when generation file type matches to
564 * builder interface mask. 570 * builder interface mask.
565 */ 571 */
...@@ -571,13 +577,6 @@ public class TempJavaFragmentFiles { ...@@ -571,13 +577,6 @@ public class TempJavaFragmentFiles {
571 } 577 }
572 578
573 /* 579 /*
574 - * Initialize enum when generation file type matches to enum class mask.
575 - */
576 - if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
577 - addGeneratedTempFile(ENUM_IMPL_MASK);
578 - }
579 -
580 - /*
581 * Set temporary file handles. 580 * Set temporary file handles.
582 */ 581 */
583 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { 582 if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
...@@ -609,9 +608,10 @@ public class TempJavaFragmentFiles { ...@@ -609,9 +608,10 @@ public class TempJavaFragmentFiles {
609 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { 608 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
610 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); 609 setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
611 } 610 }
612 - if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { 611 + if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
613 - setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME)); 612 + setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
614 } 613 }
614 +
615 } 615 }
616 616
617 /** 617 /**
...@@ -704,7 +704,6 @@ public class TempJavaFragmentFiles { ...@@ -704,7 +704,6 @@ public class TempJavaFragmentFiles {
704 attributesTempFileHandle = attributeForClass; 704 attributesTempFileHandle = attributeForClass;
705 } 705 }
706 706
707 -
708 /** 707 /**
709 * Returns getter method's impl's temporary file handle. 708 * Returns getter method's impl's temporary file handle.
710 * 709 *
...@@ -723,7 +722,6 @@ public class TempJavaFragmentFiles { ...@@ -723,7 +722,6 @@ public class TempJavaFragmentFiles {
723 getterImplTempFileHandle = getterImpl; 722 getterImplTempFileHandle = getterImpl;
724 } 723 }
725 724
726 -
727 /** 725 /**
728 * Returns hash code method's temporary file handle. 726 * Returns hash code method's temporary file handle.
729 * 727 *
...@@ -779,24 +777,6 @@ public class TempJavaFragmentFiles { ...@@ -779,24 +777,6 @@ public class TempJavaFragmentFiles {
779 } 777 }
780 778
781 /** 779 /**
782 - * Returns temporary file handle for enum class file.
783 - *
784 - * @return temporary file handle for enum class file
785 - */
786 - public File getEnumClassTempFileHandle() {
787 - return enumClassTempFileHandle;
788 - }
789 -
790 - /**
791 - * Sets temporary file handle for enum class file.
792 - *
793 - * @param enumClassTempFileHandle temporary file handle for enum class file
794 - */
795 - private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
796 - this.enumClassTempFileHandle = enumClassTempFileHandle;
797 - }
798 -
799 - /**
800 * Returns list of classes to be extended by generated files. 780 * Returns list of classes to be extended by generated files.
801 * 781 *
802 * @return list of classes to be extended by generated files 782 * @return list of classes to be extended by generated files
...@@ -842,7 +822,8 @@ public class TempJavaFragmentFiles { ...@@ -842,7 +822,8 @@ public class TempJavaFragmentFiles {
842 */ 822 */
843 private void addGetterForInterface(JavaAttributeInfo attr) 823 private void addGetterForInterface(JavaAttributeInfo attr)
844 throws IOException { 824 throws IOException {
845 - appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE); 825 + appendToFile(getGetterInterfaceTempFileHandle(),
826 + getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE);
846 } 827 }
847 828
848 /** 829 /**
...@@ -866,7 +847,8 @@ public class TempJavaFragmentFiles { ...@@ -866,7 +847,8 @@ public class TempJavaFragmentFiles {
866 private void addSetterImpl(JavaAttributeInfo attr) 847 private void addSetterImpl(JavaAttributeInfo attr)
867 throws IOException { 848 throws IOException {
868 appendToFile(getSetterImplTempFileHandle(), 849 appendToFile(getSetterImplTempFileHandle(),
869 - getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + 850 + getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
851 + +
870 NEW_LINE); 852 NEW_LINE);
871 } 853 }
872 854
...@@ -969,18 +951,19 @@ public class TempJavaFragmentFiles { ...@@ -969,18 +951,19 @@ public class TempJavaFragmentFiles {
969 } 951 }
970 952
971 /** 953 /**
972 - * Adds enum class attributes to temporary file. 954 + * Adds from string method for union class.
973 * 955 *
974 - * @param curEnumInfo current YANG enum 956 + * @param javaAttributeInfo type attribute info
975 - * @throws IOException when fails to do IO operations. 957 + * @param fromStringAttributeInfo from string attribute info
958 + * @throws IOException when fails to append to temporary file
976 */ 959 */
977 - private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) 960 + private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
961 + JavaAttributeInfo fromStringAttributeInfo)
978 throws IOException { 962 throws IOException {
979 - appendToFile(getEnumClassTempFileHandle(), 963 + appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
980 - generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue())); 964 + fromStringAttributeInfo) + NEW_LINE);
981 } 965 }
982 966
983 -
984 /** 967 /**
985 * Returns a temporary file handle for the specific file type. 968 * Returns a temporary file handle for the specific file type.
986 * 969 *
...@@ -1009,9 +992,7 @@ public class TempJavaFragmentFiles { ...@@ -1009,9 +992,7 @@ public class TempJavaFragmentFiles {
1009 * @return temporary file handle 992 * @return temporary file handle
1010 * @throws IOException when fails to create new file handle 993 * @throws IOException when fails to create new file handle
1011 */ 994 */
1012 - File getJavaFileHandle(String fileName) 995 + File getJavaFileHandle(String fileName) throws IOException {
1013 - throws IOException {
1014 -// createPackage(getAbsoluteDirPath(), getJavaFileInfo().getJavaName());
1015 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); 996 return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
1016 } 997 }
1017 998
...@@ -1055,7 +1036,8 @@ public class TempJavaFragmentFiles { ...@@ -1055,7 +1036,8 @@ public class TempJavaFragmentFiles {
1055 */ 1036 */
1056 String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null); 1037 String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
1057 if (attr.isQualifiedName()) { 1038 if (attr.isQualifiedName()) {
1058 - return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), 1039 + return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
1040 + attr.getImportInfo().getClassInfo(),
1059 attributeName, attr.isListAttr()); 1041 attributeName, attr.isListAttr());
1060 } else { 1042 } else {
1061 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName, 1043 return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
...@@ -1127,11 +1109,24 @@ public class TempJavaFragmentFiles { ...@@ -1127,11 +1109,24 @@ public class TempJavaFragmentFiles {
1127 throw new TranslatorException("Parent node does not have file info"); 1109 throw new TranslatorException("Parent node does not have file info");
1128 } 1110 }
1129 TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); 1111 TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode);
1112 + boolean isQualified = true;
1130 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); 1113 JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
1131 - boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo); 1114 + if (isListNode) {
1115 + parentImportData.setIfListImported(true);
1116 + }
1117 + if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) {
1118 + parentImportData.addImportInfo(qualifiedTypeInfo);
1119 + isQualified = false;
1120 + }
1132 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode); 1121 return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
1133 } 1122 }
1134 1123
1124 + /**
1125 + * Returns interface fragment files for node.
1126 + *
1127 + * @param node YANG node
1128 + * @return interface fragment files for node
1129 + */
1135 public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) { 1130 public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) {
1136 TempJavaFragmentFiles tempJavaFragmentFiles; 1131 TempJavaFragmentFiles tempJavaFragmentFiles;
1137 if (node instanceof RpcNotificationContainer) { 1132 if (node instanceof RpcNotificationContainer) {
...@@ -1211,6 +1206,7 @@ public class TempJavaFragmentFiles { ...@@ -1211,6 +1206,7 @@ public class TempJavaFragmentFiles {
1211 } 1206 }
1212 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; 1207 JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
1213 javaLeaf.updateJavaQualifiedInfo(); 1208 javaLeaf.updateJavaQualifiedInfo();
1209 + getJavaImportData().setIfListImported(true);
1214 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( 1210 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
1215 javaLeaf.getJavaQualifiedInfo(), 1211 javaLeaf.getJavaQualifiedInfo(),
1216 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), 1212 javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
...@@ -1242,33 +1238,6 @@ public class TempJavaFragmentFiles { ...@@ -1242,33 +1238,6 @@ public class TempJavaFragmentFiles {
1242 } 1238 }
1243 1239
1244 /** 1240 /**
1245 - * Adds enum attributes to temporary files.
1246 - *
1247 - * @param curNode current YANG node
1248 - * @throws IOException when fails to do IO operations
1249 - */
1250 - public void addEnumAttributeToTempFiles(YangNode curNode)
1251 - throws IOException {
1252 - if (curNode instanceof YangEnumeration) {
1253 - Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet();
1254 - /*
1255 - * Get the import info corresponding to the attribute for import in
1256 - * generated java files or qualified access
1257 - */
1258 - JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
1259 - getJavaFileInfo().getJavaName());
1260 - for (YangEnum curEnum : enumSet) {
1261 - JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo,
1262 - curEnum.getNamedValue(), null, false, false);
1263 - setEnumValue(curEnum.getValue());
1264 - addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1265 - }
1266 - } else {
1267 - throw new TranslatorException("current node should be of type enum.");
1268 - }
1269 - }
1270 -
1271 - /**
1272 * Adds the new attribute info to the target generated temporary files. 1241 * Adds the new attribute info to the target generated temporary files.
1273 * 1242 *
1274 * @param newAttrInfo the attribute info that needs to be added to temporary 1243 * @param newAttrInfo the attribute info that needs to be added to temporary
...@@ -1306,8 +1275,19 @@ public class TempJavaFragmentFiles { ...@@ -1306,8 +1275,19 @@ public class TempJavaFragmentFiles {
1306 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { 1275 if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
1307 addToStringMethod(newAttrInfo); 1276 addToStringMethod(newAttrInfo);
1308 } 1277 }
1309 - if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { 1278 +
1310 - addAttributesForEnumClass(newAttrInfo); 1279 + if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1280 + JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo);
1281 + /*
1282 + * Create a new java attribute info with qualified information of
1283 + * wrapper classes.
1284 + */
1285 + JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
1286 + newAttrInfo.getAttributeName(),
1287 + newAttrInfo.getAttributeType(),
1288 + getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
1289 +
1290 + addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
1311 } 1291 }
1312 } 1292 }
1313 1293
...@@ -1358,8 +1338,9 @@ public class TempJavaFragmentFiles { ...@@ -1358,8 +1338,9 @@ public class TempJavaFragmentFiles {
1358 * Adds import for case. 1338 * Adds import for case.
1359 */ 1339 */
1360 if (curNode instanceof YangCase) { 1340 if (curNode instanceof YangCase) {
1361 - List<String> importData = ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 1341 + List<String> importData =
1362 - .getBeanTempFiles().getJavaImportData().getImports(); 1342 + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
1343 + .getBeanTempFiles().getJavaImportData().getImports();
1363 for (String importInfo : importData) { 1344 for (String importInfo : importData) {
1364 if (!imports.contains(importInfo)) { 1345 if (!imports.contains(importInfo)) {
1365 imports.add(importInfo); 1346 imports.add(importInfo);
...@@ -1375,6 +1356,7 @@ public class TempJavaFragmentFiles { ...@@ -1375,6 +1356,7 @@ public class TempJavaFragmentFiles {
1375 if (isAugmentedInfoExtended(getExtendsList())) { 1356 if (isAugmentedInfoExtended(getExtendsList())) {
1376 addAugmentedInfoImport(curNode, imports, true); 1357 addAugmentedInfoImport(curNode, imports, true);
1377 } 1358 }
1359 + sortImports(imports);
1378 /* 1360 /*
1379 * Create interface file. 1361 * Create interface file.
1380 */ 1362 */
...@@ -1406,8 +1388,7 @@ public class TempJavaFragmentFiles { ...@@ -1406,8 +1388,7 @@ public class TempJavaFragmentFiles {
1406 removeCaseImport(imports); 1388 removeCaseImport(imports);
1407 } 1389 }
1408 } 1390 }
1409 - if (((fileType & GENERATE_SERVICE_AND_MANAGER) != 0) 1391 + if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
1410 - && ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0)) {
1411 if (isAttributePresent()) { 1392 if (isAttributePresent()) {
1412 addImportsToStringAndHasCodeMethods(curNode, imports); 1393 addImportsToStringAndHasCodeMethods(curNode, imports);
1413 } 1394 }
...@@ -1415,12 +1396,14 @@ public class TempJavaFragmentFiles { ...@@ -1415,12 +1396,14 @@ public class TempJavaFragmentFiles {
1415 addAugmentedInfoImport(curNode, imports, true); 1396 addAugmentedInfoImport(curNode, imports, true);
1416 addArrayListImport(curNode, imports, true); 1397 addArrayListImport(curNode, imports, true);
1417 } 1398 }
1399 + sortImports(imports);
1418 /* 1400 /*
1419 * Create builder class file. 1401 * Create builder class file.
1420 */ 1402 */
1421 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); 1403 setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
1422 setBuilderClassJavaFileHandle( 1404 setBuilderClassJavaFileHandle(
1423 - generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent())); 1405 + generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode,
1406 + isAttributePresent()));
1424 /* 1407 /*
1425 * Create impl class file. 1408 * Create impl class file.
1426 */ 1409 */
...@@ -1437,14 +1420,6 @@ public class TempJavaFragmentFiles { ...@@ -1437,14 +1420,6 @@ public class TempJavaFragmentFiles {
1437 } 1420 }
1438 1421
1439 /* 1422 /*
1440 - * Creates type enum class file.
1441 - */
1442 - if ((fileType & GENERATE_ENUM_CLASS) != 0) {
1443 - setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
1444 - setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
1445 - }
1446 -
1447 - /*
1448 * Close all the file handles. 1423 * Close all the file handles.
1449 */ 1424 */
1450 freeTemporaryResources(false); 1425 freeTemporaryResources(false);
...@@ -1505,10 +1480,6 @@ public class TempJavaFragmentFiles { ...@@ -1505,10 +1480,6 @@ public class TempJavaFragmentFiles {
1505 closeFile(getImplClassJavaFileHandle(), true); 1480 closeFile(getImplClassJavaFileHandle(), true);
1506 } 1481 }
1507 1482
1508 - if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
1509 - closeFile(getEnumClassJavaFileHandle(), isError);
1510 - }
1511 -
1512 /* 1483 /*
1513 * Close all temporary file handles and delete the files. 1484 * Close all temporary file handles and delete the files.
1514 */ 1485 */
...@@ -1527,8 +1498,8 @@ public class TempJavaFragmentFiles { ...@@ -1527,8 +1498,8 @@ public class TempJavaFragmentFiles {
1527 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { 1498 if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
1528 closeFile(getEqualsImplTempFileHandle(), true); 1499 closeFile(getEqualsImplTempFileHandle(), true);
1529 } 1500 }
1530 - if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) { 1501 + if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
1531 - closeFile(getEnumClassTempFileHandle(), true); 1502 + closeFile(getFromStringImplTempFileHandle(), true);
1532 } 1503 }
1533 } 1504 }
1534 1505
......
...@@ -33,9 +33,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -33,9 +33,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
33 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; 33 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
34 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; 34 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
35 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 35 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
36 -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils 36 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
37 - .isHasAugmentationExtended; 37 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
38 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 38 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
39 +import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
40 +import static org.onosproject.yangutils.utils.UtilConstants.VOID;
39 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; 41 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
40 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; 42 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
41 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 43 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
...@@ -180,12 +182,13 @@ public class TempJavaServiceFragmentFiles ...@@ -180,12 +182,13 @@ public class TempJavaServiceFragmentFiles
180 } 182 }
181 183
182 /** 184 /**
183 - * Constructs java code exit. 185 + * Generate java code.
184 * 186 *
185 * @param fileType generated file type 187 * @param fileType generated file type
186 * @param curNode current YANG node 188 * @param curNode current YANG node
187 * @throws IOException when fails to generate java files 189 * @throws IOException when fails to generate java files
188 */ 190 */
191 + @Override
189 public void generateJavaFile(int fileType, YangNode curNode) 192 public void generateJavaFile(int fileType, YangNode curNode)
190 throws IOException { 193 throws IOException {
191 List<String> imports = new ArrayList<>(); 194 List<String> imports = new ArrayList<>();
...@@ -199,9 +202,6 @@ public class TempJavaServiceFragmentFiles ...@@ -199,9 +202,6 @@ public class TempJavaServiceFragmentFiles
199 setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); 202 setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
200 generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); 203 generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
201 204
202 - if (isAttributePresent()) {
203 - addImportsToStringAndHasCodeMethods(curNode, imports);
204 - }
205 if (isHasAugmentationExtended(getExtendsList())) { 205 if (isHasAugmentationExtended(getExtendsList())) {
206 addAugmentedInfoImport(curNode, imports, true); 206 addAugmentedInfoImport(curNode, imports, true);
207 addArrayListImport(curNode, imports, true); 207 addArrayListImport(curNode, imports, true);
...@@ -229,21 +229,20 @@ public class TempJavaServiceFragmentFiles ...@@ -229,21 +229,20 @@ public class TempJavaServiceFragmentFiles
229 * @param rpcName name of the rpc function 229 * @param rpcName name of the rpc function
230 * @throws IOException IO operation fail 230 * @throws IOException IO operation fail
231 */ 231 */
232 - private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput, 232 + private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
233 - String rpcName) 233 + JavaAttributeInfo javaAttributeInfoOfOutput,
234 - throws IOException { 234 + String rpcName) throws IOException {
235 - String rpcInput = ""; 235 + String rpcInput = EMPTY_STRING;
236 - String rpcOutput = "void"; 236 + String rpcOutput = VOID;
237 if (javaAttributeInfoOfInput != null) { 237 if (javaAttributeInfoOfInput != null) {
238 rpcInput = javaAttributeInfoOfInput.getAttributeName(); 238 rpcInput = javaAttributeInfoOfInput.getAttributeName();
239 } 239 }
240 if (javaAttributeInfoOfOutput != null) { 240 if (javaAttributeInfoOfOutput != null) {
241 rpcOutput = javaAttributeInfoOfOutput.getAttributeName(); 241 rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
242 } 242 }
243 - appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) + 243 + appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput)
244 - getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); 244 + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
245 - appendToFile(getRpcImplTempFileHandle(), 245 + appendToFile(getRpcImplTempFileHandle(), getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
246 - getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
247 } 246 }
248 247
249 /** 248 /**
...@@ -269,12 +268,17 @@ public class TempJavaServiceFragmentFiles ...@@ -269,12 +268,17 @@ public class TempJavaServiceFragmentFiles
269 * and java files. 268 * and java files.
270 * @throws IOException when failed to delete the temporary files 269 * @throws IOException when failed to delete the temporary files
271 */ 270 */
271 + @Override
272 public void freeTemporaryResources(boolean isErrorOccurred) 272 public void freeTemporaryResources(boolean isErrorOccurred)
273 throws IOException { 273 throws IOException {
274 boolean isError = isErrorOccurred; 274 boolean isError = isErrorOccurred;
275 275
276 closeFile(getServiceInterfaceJavaFileHandle(), isError); 276 closeFile(getServiceInterfaceJavaFileHandle(), isError);
277 closeFile(getRpcInterfaceTempFileHandle(), true); 277 closeFile(getRpcInterfaceTempFileHandle(), true);
278 + closeFile(getRpcImplTempFileHandle(), true);
279 + closeFile(getGetterInterfaceTempFileHandle(), true);
280 + closeFile(getSetterInterfaceTempFileHandle(), true);
281 + closeFile(getSetterImplTempFileHandle(), true);
278 282
279 super.freeTemporaryResources(isErrorOccurred); 283 super.freeTemporaryResources(isErrorOccurred);
280 284
......
...@@ -21,6 +21,7 @@ import java.io.IOException; ...@@ -21,6 +21,7 @@ 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 23
24 +import org.onosproject.yangutils.datamodel.YangDataTypes;
24 import org.onosproject.yangutils.datamodel.YangNode; 25 import org.onosproject.yangutils.datamodel.YangNode;
25 import org.onosproject.yangutils.datamodel.YangType; 26 import org.onosproject.yangutils.datamodel.YangType;
26 import org.onosproject.yangutils.datamodel.YangTypeHolder; 27 import org.onosproject.yangutils.datamodel.YangTypeHolder;
...@@ -33,10 +34,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. ...@@ -33,10 +34,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
33 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
35 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; 36 import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
36 -import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
37 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; 37 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
38 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; 38 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
39 -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; 39 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
40 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; 40 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
41 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc; 41 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
42 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; 42 import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
...@@ -60,10 +60,6 @@ public class TempJavaTypeFragmentFiles ...@@ -60,10 +60,6 @@ public class TempJavaTypeFragmentFiles
60 * File name for construction for special type like union, typedef. 60 * File name for construction for special type like union, typedef.
61 */ 61 */
62 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; 62 private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
63 - /**
64 - * File name for from string method.
65 - */
66 - private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
67 63
68 /** 64 /**
69 * File name for typedef class file name suffix. 65 * File name for typedef class file name suffix.
...@@ -86,11 +82,6 @@ public class TempJavaTypeFragmentFiles ...@@ -86,11 +82,6 @@ public class TempJavaTypeFragmentFiles
86 private File constructorForTypeTempFileHandle; 82 private File constructorForTypeTempFileHandle;
87 83
88 /** 84 /**
89 - * Temporary file handle for from string method of class.
90 - */
91 - private File fromStringImplTempFileHandle;
92 -
93 - /**
94 * Java file handle for typedef class file. 85 * Java file handle for typedef class file.
95 */ 86 */
96 private File typedefClassJavaFileHandle; 87 private File typedefClassJavaFileHandle;
...@@ -118,10 +109,8 @@ public class TempJavaTypeFragmentFiles ...@@ -118,10 +109,8 @@ public class TempJavaTypeFragmentFiles
118 addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK); 109 addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK);
119 addGeneratedTempFile(FROM_STRING_IMPL_MASK); 110 addGeneratedTempFile(FROM_STRING_IMPL_MASK);
120 111
121 -
122 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); 112 setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
123 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); 113 setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
124 - setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
125 114
126 } 115 }
127 116
...@@ -146,25 +135,6 @@ public class TempJavaTypeFragmentFiles ...@@ -146,25 +135,6 @@ public class TempJavaTypeFragmentFiles
146 } 135 }
147 136
148 /** 137 /**
149 - * Returns from string method's temporary file handle.
150 - *
151 - * @return from string method's temporary file handle
152 - */
153 - public File getFromStringImplTempFileHandle() {
154 - return fromStringImplTempFileHandle;
155 - }
156 -
157 - /**
158 - * Sets from string method's temporary file handle.
159 - *
160 - * @param fromStringImplTempFileHandle from string method's temporary file
161 - * handle
162 - */
163 - private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
164 - this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
165 - }
166 -
167 - /**
168 * Returns java file handle for typedef class file. 138 * Returns java file handle for typedef class file.
169 * 139 *
170 * @return java file handle for typedef class file 140 * @return java file handle for typedef class file
...@@ -239,9 +209,14 @@ public class TempJavaTypeFragmentFiles ...@@ -239,9 +209,14 @@ public class TempJavaTypeFragmentFiles
239 } 209 }
240 YangJavaType<?> javaType = (YangJavaType<?>) yangType; 210 YangJavaType<?> javaType = (YangJavaType<?>) yangType;
241 javaType.updateJavaQualifiedInfo(); 211 javaType.updateJavaQualifiedInfo();
212 + String typeName = javaType.getDataTypeName();
213 +
214 + if (javaType.getDataType().equals(YangDataTypes.DERIVED)) {
215 + typeName = getCamelCase(typeName, null);
216 + }
242 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( 217 JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
243 javaType.getJavaQualifiedInfo(), 218 javaType.getJavaQualifiedInfo(),
244 - javaType.getDataTypeName(), javaType, 219 + typeName, javaType,
245 getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), 220 getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
246 false); 221 false);
247 addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo); 222 addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo);
...@@ -269,34 +244,6 @@ public class TempJavaTypeFragmentFiles ...@@ -269,34 +244,6 @@ public class TempJavaTypeFragmentFiles
269 if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { 244 if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
270 addTypeConstructor(javaAttributeInfo); 245 addTypeConstructor(javaAttributeInfo);
271 } 246 }
272 -
273 - JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(javaAttributeInfo);
274 - /*
275 - * Create a new java attribute info with qualified information of
276 - * wrapper classes.
277 - */
278 - JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
279 - javaAttributeInfo.getAttributeName(),
280 - javaAttributeInfo.getAttributeType(),
281 - getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
282 - if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
283 - addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
284 - }
285 - }
286 -
287 -
288 - /**
289 - * Adds from string method for union class.
290 - *
291 - * @param javaAttributeInfo type attribute info
292 - * @param fromStringAttributeInfo from string attribute info
293 - * @throws IOException when fails to append to temporary file
294 - */
295 - private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
296 - JavaAttributeInfo fromStringAttributeInfo)
297 - throws IOException {
298 - appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
299 - fromStringAttributeInfo) + NEW_LINE);
300 } 247 }
301 248
302 /** 249 /**
...@@ -324,7 +271,6 @@ public class TempJavaTypeFragmentFiles ...@@ -324,7 +271,6 @@ public class TempJavaTypeFragmentFiles
324 + NEW_LINE); 271 + NEW_LINE);
325 } 272 }
326 273
327 -
328 /** 274 /**
329 * Removes all temporary file handles. 275 * Removes all temporary file handles.
330 * 276 *
...@@ -333,6 +279,7 @@ public class TempJavaTypeFragmentFiles ...@@ -333,6 +279,7 @@ public class TempJavaTypeFragmentFiles
333 * and java files. 279 * and java files.
334 * @throws IOException when failed to delete the temporary files 280 * @throws IOException when failed to delete the temporary files
335 */ 281 */
282 + @Override
336 public void freeTemporaryResources(boolean isErrorOccurred) 283 public void freeTemporaryResources(boolean isErrorOccurred)
337 throws IOException { 284 throws IOException {
338 boolean isError = isErrorOccurred; 285 boolean isError = isErrorOccurred;
...@@ -356,6 +303,7 @@ public class TempJavaTypeFragmentFiles ...@@ -356,6 +303,7 @@ public class TempJavaTypeFragmentFiles
356 } 303 }
357 304
358 super.freeTemporaryResources(isErrorOccurred); 305 super.freeTemporaryResources(isErrorOccurred);
306 +
359 } 307 }
360 308
361 /** 309 /**
...@@ -365,6 +313,7 @@ public class TempJavaTypeFragmentFiles ...@@ -365,6 +313,7 @@ public class TempJavaTypeFragmentFiles
365 * @param curNode current YANG node 313 * @param curNode current YANG node
366 * @throws IOException when fails to generate java files 314 * @throws IOException when fails to generate java files
367 */ 315 */
316 + @Override
368 public void generateJavaFile(int fileType, YangNode curNode) 317 public void generateJavaFile(int fileType, YangNode curNode)
369 throws IOException { 318 throws IOException {
370 List<String> imports = new ArrayList<>(); 319 List<String> imports = new ArrayList<>();
......
...@@ -76,7 +76,6 @@ public class YangJavaEnumeration ...@@ -76,7 +76,6 @@ public class YangJavaEnumeration
76 */ 76 */
77 @Override 77 @Override
78 public void setJavaFileInfo(JavaFileInfo javaInfo) { 78 public void setJavaFileInfo(JavaFileInfo javaInfo) {
79 -
80 javaFileInfo = javaInfo; 79 javaFileInfo = javaInfo;
81 } 80 }
82 81
...@@ -87,7 +86,6 @@ public class YangJavaEnumeration ...@@ -87,7 +86,6 @@ public class YangJavaEnumeration
87 */ 86 */
88 @Override 87 @Override
89 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { 88 public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
90 -
91 return tempFileHandle; 89 return tempFileHandle;
92 } 90 }
93 91
...@@ -98,7 +96,6 @@ public class YangJavaEnumeration ...@@ -98,7 +96,6 @@ public class YangJavaEnumeration
98 */ 96 */
99 @Override 97 @Override
100 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { 98 public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
101 -
102 tempFileHandle = fileHandle; 99 tempFileHandle = fileHandle;
103 } 100 }
104 101
......
...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; ...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 27
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
30 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
30 31
31 /** 32 /**
32 * Represents module information extended to support java code generation. 33 * Represents module information extended to support java code generation.
...@@ -118,5 +119,7 @@ public class YangJavaModule ...@@ -118,5 +119,7 @@ public class YangJavaModule
118 public void generateCodeExit() 119 public void generateCodeExit()
119 throws IOException { 120 throws IOException {
120 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 121 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
122 + searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
123 + getJavaFileInfo().getPackageFilePath());
121 } 124 }
122 } 125 }
......
...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; ...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
28 28
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
31 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
31 32
32 /** 33 /**
33 * Represents sub module information extended to support java code generation. 34 * Represents sub module information extended to support java code generation.
...@@ -133,5 +134,7 @@ public class YangJavaSubModule ...@@ -133,5 +134,7 @@ public class YangJavaSubModule
133 public void generateCodeExit() 134 public void generateCodeExit()
134 throws IOException { 135 throws IOException {
135 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); 136 getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
137 + searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
138 + getJavaFileInfo().getPackageFilePath());
136 } 139 }
137 } 140 }
......
...@@ -68,6 +68,7 @@ public class YangJavaType<T> ...@@ -68,6 +68,7 @@ public class YangJavaType<T>
68 } 68 }
69 importInfo.setClassInfo(dataTypeName); 69 importInfo.setClassInfo(dataTypeName);
70 } 70 }
71 + setJavaQualifiedInfo(importInfo);
71 } 72 }
72 73
73 @Override 74 @Override
......
...@@ -38,6 +38,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; ...@@ -38,6 +38,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
38 import static org.onosproject.yangutils.utils.UtilConstants.BYTE; 38 import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
39 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; 39 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
40 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 40 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
41 +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
41 import static org.onosproject.yangutils.utils.UtilConstants.INT; 42 import static org.onosproject.yangutils.utils.UtilConstants.INT;
42 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; 43 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
43 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; 44 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
...@@ -45,7 +46,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; ...@@ -45,7 +46,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
45 import static org.onosproject.yangutils.utils.UtilConstants.LONG; 46 import static org.onosproject.yangutils.utils.UtilConstants.LONG;
46 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; 47 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
47 import static org.onosproject.yangutils.utils.UtilConstants.NEW; 48 import static org.onosproject.yangutils.utils.UtilConstants.NEW;
48 -import static org.onosproject.yangutils.utils.UtilConstants.OF;
49 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; 49 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
50 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; 50 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
51 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; 51 import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
...@@ -146,7 +146,7 @@ public final class AttributesJavaDataType { ...@@ -146,7 +146,7 @@ public final class AttributesJavaDataType {
146 case BINARY: 146 case BINARY:
147 //TODO:BINARY 147 //TODO:BINARY
148 case DERIVED: 148 case DERIVED:
149 - return targetDataType + PERIOD + OF; 149 + return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
150 default: 150 default:
151 throw new TranslatorException("given data type is not supported."); 151 throw new TranslatorException("given data type is not supported.");
152 } 152 }
...@@ -316,8 +316,7 @@ public final class AttributesJavaDataType { ...@@ -316,8 +316,7 @@ public final class AttributesJavaDataType {
316 } else { 316 } else {
317 switch (type) { 317 switch (type) {
318 case UINT64: 318 case UINT64:
319 - //TODO: BIGINTEGER. 319 + return JAVA_MATH;
320 - break;
321 case DECIMAL64: 320 case DECIMAL64:
322 //TODO: DECIMAL64 321 //TODO: DECIMAL64
323 break; 322 break;
......
...@@ -74,7 +74,7 @@ public final class ClassDefinitionGenerator { ...@@ -74,7 +74,7 @@ public final class ClassDefinitionGenerator {
74 if ((genFileTypes & INTERFACE_MASK) != 0) { 74 if ((genFileTypes & INTERFACE_MASK) != 0) {
75 return getInterfaceDefinition(yangName); 75 return getInterfaceDefinition(yangName);
76 } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { 76 } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
77 - return getBuilderClassDefinition(yangName, genFileTypes); 77 + return getBuilderClassDefinition(yangName);
78 } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { 78 } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
79 return getImplClassDefinition(yangName); 79 return getImplClassDefinition(yangName);
80 } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { 80 } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
...@@ -142,14 +142,9 @@ public final class ClassDefinitionGenerator { ...@@ -142,14 +142,9 @@ public final class ClassDefinitionGenerator {
142 * @param genFileTypes 142 * @param genFileTypes
143 * @return definition 143 * @return definition
144 */ 144 */
145 - private static String getBuilderClassDefinition(String yangName, int genFileTypes) { 145 + private static String getBuilderClassDefinition(String yangName) {
146 - if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) { 146 + return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
147 - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + 147 + + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
148 - SERVICE + PERIOD + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
149 - } else {
150 - return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
151 - + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
152 - }
153 } 148 }
154 149
155 /** 150 /**
...@@ -180,7 +175,11 @@ public final class ClassDefinitionGenerator { ...@@ -180,7 +175,11 @@ public final class ClassDefinitionGenerator {
180 * @return definition 175 * @return definition
181 */ 176 */
182 private static String getRpcInterfaceDefinition(String yangName) { 177 private static String getRpcInterfaceDefinition(String yangName) {
183 - return INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 178 + if (yangName.contains(SERVICE)) {
179 + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
180 + }
181 + return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + SERVICE
182 + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
184 } 183 }
185 184
186 /** 185 /**
...@@ -195,7 +194,7 @@ public final class ClassDefinitionGenerator { ...@@ -195,7 +194,7 @@ public final class ClassDefinitionGenerator {
195 if (classDef.length() < 5) { 194 if (classDef.length() < 5) {
196 throw new RuntimeException("Event class name is error"); 195 throw new RuntimeException("Event class name is error");
197 } 196 }
198 - classDef = classDef.substring(0, (classDef.length() - 5)); 197 + classDef = classDef.substring(0, classDef.length() - 5);
199 classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 198 classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
200 199
201 return classDef; 200 return classDef;
...@@ -213,7 +212,7 @@ public final class ClassDefinitionGenerator { ...@@ -213,7 +212,7 @@ public final class ClassDefinitionGenerator {
213 if (intfDef.length() < 8) { 212 if (intfDef.length() < 8) {
214 throw new RuntimeException("Event listener interface name is error"); 213 throw new RuntimeException("Event listener interface name is error");
215 } 214 }
216 - intfDef = intfDef.substring(0, (intfDef.length() - 8)); 215 + intfDef = intfDef.substring(0, intfDef.length() - 8);
217 intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 216 intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
218 217
219 return intfDef; 218 return intfDef;
......
...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 19 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;
23 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; 22 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
24 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 23 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
25 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; 24 import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
...@@ -87,11 +86,6 @@ public final class JavaCodeSnippetGen { ...@@ -87,11 +86,6 @@ public final class JavaCodeSnippetGen {
87 * @return corresponding textual java code information 86 * @return corresponding textual java code information
88 */ 87 */
89 public static String getJavaClassDefStart(int genFileTypes, String yangName) { 88 public static String getJavaClassDefStart(int genFileTypes, String yangName) {
90 -
91 - /*
92 - * get the camel case name for java class / interface.
93 - */
94 - yangName = getCamelCase(yangName, null);
95 return generateClassDefinition(genFileTypes, yangName); 89 return generateClassDefinition(genFileTypes, yangName);
96 } 90 }
97 91
...@@ -168,8 +162,9 @@ public final class JavaCodeSnippetGen { ...@@ -168,8 +162,9 @@ public final class JavaCodeSnippetGen {
168 * @return string for enum's attribute 162 * @return string for enum's attribute
169 */ 163 */
170 public static String generateEnumAttributeString(String name, int value) { 164 public static String generateEnumAttributeString(String name, int value) {
171 - return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION + getEnumJavaAttribute(name) 165 + return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION
172 - + OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; 166 + + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
167 + + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
173 } 168 }
174 169
175 } 170 }
......
...@@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
25 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 25 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; 26 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
27 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 27 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
28 +import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
28 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; 29 import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
29 30
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
...@@ -62,6 +63,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -62,6 +63,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
62 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; 63 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
63 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; 64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
64 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor; 65 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor;
66 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
65 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; 67 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
66 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; 68 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
67 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; 69 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
...@@ -84,7 +86,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; ...@@ -84,7 +86,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
84 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 86 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
85 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 87 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
86 import static org.onosproject.yangutils.utils.UtilConstants.INT; 88 import static org.onosproject.yangutils.utils.UtilConstants.INT;
87 -import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
88 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 89 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
89 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 90 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
90 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; 91 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
...@@ -164,7 +165,8 @@ public final class JavaFileGenerator { ...@@ -164,7 +165,8 @@ public final class JavaFileGenerator {
164 * @return interface file 165 * @return interface file
165 * @throws IOException when fails to write in file 166 * @throws IOException when fails to write in file
166 */ 167 */
167 - public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, boolean isAttrPresent) 168 + public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode,
169 + boolean isAttrPresent)
168 throws IOException { 170 throws IOException {
169 171
170 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 172 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
...@@ -311,7 +313,8 @@ public final class JavaFileGenerator { ...@@ -311,7 +313,8 @@ public final class JavaFileGenerator {
311 /** 313 /**
312 * Add default constructor and build method impl. 314 * Add default constructor and build method impl.
313 */ 315 */
314 - methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().addBuildMethodImpl()); 316 + methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
317 + .addBuildMethodImpl());
315 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 318 methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
316 .addDefaultConstructor(PUBLIC, BUILDER)); 319 .addDefaultConstructor(PUBLIC, BUILDER));
317 320
...@@ -340,42 +343,45 @@ public final class JavaFileGenerator { ...@@ -340,42 +343,45 @@ public final class JavaFileGenerator {
340 343
341 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); 344 JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
342 345
343 - String className = getCaptialCase(javaFileInfo.getJavaName()) + MANAGER; 346 + String className = getCaptialCase(javaFileInfo.getJavaName());
344 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); 347 String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
345 348
346 initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path); 349 initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
347 350
348 List<String> methods = new ArrayList<>(); 351 List<String> methods = new ArrayList<>();
349 352
350 - if (isAttrPresent) { 353 + try {
351 - 354 + if (isAttrPresent) {
352 - try {
353 /** 355 /**
354 * Getter methods. 356 * Getter methods.
355 */ 357 */
356 - methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, 358 + methods.add(
357 - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 359 + getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
358 - .getServiceTempFiles())); 360 + ((TempJavaCodeFragmentFilesContainer) curNode)
361 + .getTempJavaCodeFragmentFiles().getServiceTempFiles()));
359 /** 362 /**
360 * Setter methods. 363 * Setter methods.
361 */ 364 */
362 - methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, 365 + methods.add(
363 - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 366 + getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
364 - .getServiceTempFiles()) + 367 + ((TempJavaCodeFragmentFilesContainer) curNode)
365 - NEW_LINE); 368 + .getTempJavaCodeFragmentFiles().getServiceTempFiles())
369 + + NEW_LINE);
366 370
371 + }
372 + if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
367 JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; 373 JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
368 /** 374 /**
369 * Rpc methods 375 * Rpc methods
370 */ 376 */
371 - methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() 377 + methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK,
372 - .getServiceTempFiles())); 378 + javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
373 - } catch (IOException e) {
374 - throw new IOException("No data found in temporary java code fragment files for " + className
375 - + " while manager class file generation");
376 } 379 }
377 - } else {
378 insertDataIntoJavaFile(file, NEW_LINE); 380 insertDataIntoJavaFile(file, NEW_LINE);
381 +
382 + } catch (IOException e) {
383 + throw new IOException("No data found in temporary java code fragment files for " + className
384 + + " while manager class file generation");
379 } 385 }
380 386
381 /** 387 /**
...@@ -746,16 +752,34 @@ public final class JavaFileGenerator { ...@@ -746,16 +752,34 @@ public final class JavaFileGenerator {
746 /** 752 /**
747 * Add a constructor for enum. 753 * Add a constructor for enum.
748 */ 754 */
749 - insertDataIntoJavaFile(file, 755 + insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false)
750 - getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false) + getEnumsConstrcutor(className) 756 + + getEnumsConstrcutor(className) + NEW_LINE);
751 - + NEW_LINE); 757 +
758 + TempJavaEnumerationFragmentFiles enumFragFiles =
759 + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
760 + .getEnumerationTempFiles();
761 + insertDataIntoJavaFile(file, getEnumsOfMethod(className,
762 + enumFragFiles.getJavaAttributeForEnum(),
763 + enumFragFiles.getEnumSetJavaMap(),
764 + enumFragFiles.getEnumStringList())
765 + + NEW_LINE);
752 766
753 /** 767 /**
754 * Add a getter method for enum. 768 * Add a getter method for enum.
755 */ 769 */
756 - insertDataIntoJavaFile(file, 770 + insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, getSmallCase(className), false)
757 - getJavaDoc(GETTER_METHOD, getSmallCase(className), false) 771 + + getGetter(INT, getSmallCase(className), GENERATE_ENUM_CLASS) + NEW_LINE);
758 - + getGetter(INT, getSmallCase(className), GENERATE_SERVICE_AND_MANAGER) + NEW_LINE); 772 +
773 + try {
774 + insertDataIntoJavaFile(file, getFromStringMethodSignature(className)
775 + + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
776 + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
777 + .getEnumerationTempFiles())
778 + + getFromStringMethodClose());
779 + } catch (IOException e) {
780 + throw new IOException("No data found in temporary java code fragment files for " + className
781 + + " while enum class file generation");
782 + }
759 783
760 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); 784 insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
761 785
...@@ -785,33 +809,30 @@ public final class JavaFileGenerator { ...@@ -785,33 +809,30 @@ public final class JavaFileGenerator {
785 809
786 List<String> methods = new ArrayList<>(); 810 List<String> methods = new ArrayList<>();
787 811
788 -
789 try { 812 try {
790 if (isAttributePresent) { 813 if (isAttributePresent) {
791 814
792 /** 815 /**
793 * Getter methods. 816 * Getter methods.
794 */ 817 */
795 - methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, 818 + methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
796 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 819 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
797 .getServiceTempFiles())); 820 .getServiceTempFiles()));
798 /** 821 /**
799 * Setter methods. 822 * Setter methods.
800 */ 823 */
801 - methods.add(NEW_LINE); 824 + methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
802 - methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
803 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() 825 ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
804 .getServiceTempFiles())); 826 .getServiceTempFiles()));
805 } 827 }
806 - 828 + if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
807 - 829 + JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
808 - JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; 830 + /**
809 - /** 831 + * Rpc methods
810 - * Rpc methods 832 + */
811 - */ 833 + methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK,
812 - methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() 834 + javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
813 - .getServiceTempFiles())); 835 + }
814 -
815 } catch (IOException e) { 836 } catch (IOException e) {
816 throw new IOException("No data found in temporary java code fragment files for " + className 837 throw new IOException("No data found in temporary java code fragment files for " + className
817 + " while rpc class file generation"); 838 + " while rpc class file generation");
......
...@@ -23,6 +23,7 @@ import java.util.List; ...@@ -23,6 +23,7 @@ import java.util.List;
23 import org.onosproject.yangutils.translator.exception.TranslatorException; 23 import org.onosproject.yangutils.translator.exception.TranslatorException;
24 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 24 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
25 import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; 25 import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
26 +import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; 27 import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
27 import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; 28 import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
28 import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; 29 import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
...@@ -39,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -39,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
39 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
43 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
42 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;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; 46 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
...@@ -58,13 +60,16 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy ...@@ -58,13 +60,16 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
58 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; 60 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
59 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 61 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
60 import static org.onosproject.yangutils.utils.UtilConstants.INT; 62 import static org.onosproject.yangutils.utils.UtilConstants.INT;
63 +import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
61 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 64 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
62 import static org.onosproject.yangutils.utils.UtilConstants.ORG; 65 import static org.onosproject.yangutils.utils.UtilConstants.ORG;
63 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; 66 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
64 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; 67 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
65 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 68 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
69 +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
66 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 70 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
67 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 71 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
72 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
68 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; 73 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
69 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; 74 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
70 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; 75 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
...@@ -73,7 +78,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVE ...@@ -73,7 +78,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVE
73 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 78 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
74 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 79 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
75 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; 80 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
76 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; 81 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER;
77 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 82 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
78 83
79 /** 84 /**
...@@ -105,7 +110,6 @@ public final class JavaFileGeneratorUtils { ...@@ -105,7 +110,6 @@ public final class JavaFileGeneratorUtils {
105 * Returns data stored in temporary files. 110 * Returns data stored in temporary files.
106 * 111 *
107 * @param generatedTempFiles temporary file types 112 * @param generatedTempFiles temporary file types
108 - * @param generatedTempFiles temporary file types
109 * @param tempJavaFragmentFiles temp java fragment files 113 * @param tempJavaFragmentFiles temp java fragment files
110 * @return data stored in temporary files 114 * @return data stored in temporary files
111 * @throws IOException when failed to get the data from temporary file handle 115 * @throws IOException when failed to get the data from temporary file handle
...@@ -130,9 +134,10 @@ public final class JavaFileGeneratorUtils { ...@@ -130,9 +134,10 @@ public final class JavaFileGeneratorUtils {
130 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { 134 if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
131 serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; 135 serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
132 } 136 }
133 - 137 + if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
134 - 138 + return tempJavaFragmentFiles
135 - if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { 139 + .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
140 + } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
136 return tempJavaFragmentFiles 141 return tempJavaFragmentFiles
137 .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle()); 142 .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle());
138 } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { 143 } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
...@@ -172,14 +177,16 @@ public final class JavaFileGeneratorUtils { ...@@ -172,14 +177,16 @@ public final class JavaFileGeneratorUtils {
172 return typeFragmentFiles 177 return typeFragmentFiles
173 .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle()); 178 .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle());
174 } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { 179 } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
175 - if (typeFragmentFiles == null) {
176 - throw new TranslatorException("Required from string info is missing.");
177 - }
178 - return typeFragmentFiles
179 - .getTemporaryDataFromFileHandle(typeFragmentFiles.getFromStringImplTempFileHandle());
180 - } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
181 return tempJavaFragmentFiles 180 return tempJavaFragmentFiles
182 - .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEnumClassTempFileHandle()); 181 + .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle());
182 + } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
183 + if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) {
184 + throw new TranslatorException("Required enum info is missing.");
185 + }
186 + TempJavaEnumerationFragmentFiles enumFragmentFiles =
187 + (TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles;
188 + return enumFragmentFiles
189 + .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle());
183 } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) { 190 } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
184 if (serviceFragmentFiles == null) { 191 if (serviceFragmentFiles == null) {
185 throw new TranslatorException("Required rpc interface info is missing."); 192 throw new TranslatorException("Required rpc interface info is missing.");
...@@ -328,7 +335,15 @@ public final class JavaFileGeneratorUtils { ...@@ -328,7 +335,15 @@ public final class JavaFileGeneratorUtils {
328 */ 335 */
329 private static void write(File file, String fileName, int genType, JavaDocType javaDocType) 336 private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
330 throws IOException { 337 throws IOException {
331 - insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); 338 + if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
339 + if (!fileName.contains(SERVICE)) {
340 + insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false));
341 + } else {
342 + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
343 + }
344 + } else {
345 + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
346 + }
332 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); 347 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
333 } 348 }
334 349
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 +import java.util.List;
20 +import java.util.Map;
21 +
19 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
20 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 23 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
21 24
...@@ -31,12 +34,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; ...@@ -31,12 +34,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
31 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; 34 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
32 import static org.onosproject.yangutils.utils.UtilConstants.BUILD; 35 import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
33 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 36 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
37 +import static org.onosproject.yangutils.utils.UtilConstants.CASE;
34 import static org.onosproject.yangutils.utils.UtilConstants.CATCH; 38 import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
35 import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; 39 import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
36 import static org.onosproject.yangutils.utils.UtilConstants.CLEAR; 40 import static org.onosproject.yangutils.utils.UtilConstants.CLEAR;
37 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; 41 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
38 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 42 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
43 +import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
39 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 44 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
45 +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
40 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; 46 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
41 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; 47 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
42 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; 48 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
...@@ -82,6 +88,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; ...@@ -82,6 +88,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
82 import static org.onosproject.yangutils.utils.UtilConstants.STATIC; 88 import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
83 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 89 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
84 import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; 90 import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
91 +import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
85 import static org.onosproject.yangutils.utils.UtilConstants.THIS; 92 import static org.onosproject.yangutils.utils.UtilConstants.THIS;
86 import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; 93 import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
87 import static org.onosproject.yangutils.utils.UtilConstants.TO; 94 import static org.onosproject.yangutils.utils.UtilConstants.TO;
...@@ -494,10 +501,11 @@ public final class MethodsGenerator { ...@@ -494,10 +501,11 @@ public final class MethodsGenerator {
494 501
495 rpcName = getSmallCase(getCamelCase(rpcName, null)); 502 rpcName = getSmallCase(getCamelCase(rpcName, null));
496 inputName = getCaptialCase(inputName); 503 inputName = getCaptialCase(inputName);
497 - outputName = getCaptialCase(outputName); 504 + if (!outputName.equals(VOID)) {
498 - 505 + outputName = getCaptialCase(outputName);
499 - return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS 506 + }
500 - + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; 507 + return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName + SPACE
508 + + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
501 } 509 }
502 510
503 /** 511 /**
...@@ -512,12 +520,14 @@ public final class MethodsGenerator { ...@@ -512,12 +520,14 @@ public final class MethodsGenerator {
512 520
513 rpcName = getSmallCase(getCamelCase(rpcName, null)); 521 rpcName = getSmallCase(getCamelCase(rpcName, null));
514 inputName = getCaptialCase(inputName); 522 inputName = getCaptialCase(inputName);
515 - outputName = getCaptialCase(outputName); 523 + if (!outputName.equals(VOID)) {
524 + outputName = getCaptialCase(outputName);
525 + }
516 526
517 - String method = getOverRideString() + 527 + String method =
518 - FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS 528 + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
519 - + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET 529 + + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE
520 - + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; 530 + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
521 if (!outputName.contentEquals(VOID)) { 531 if (!outputName.contentEquals(VOID)) {
522 method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE; 532 method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE;
523 } 533 }
...@@ -601,7 +611,7 @@ public final class MethodsGenerator { ...@@ -601,7 +611,7 @@ public final class MethodsGenerator {
601 * @return from string method's open string 611 * @return from string method's open string
602 */ 612 */
603 public static String getFromStringMethodSignature(String className) { 613 public static String getFromStringMethodSignature(String className) {
604 - return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE 614 + return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
605 + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE 615 + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
606 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 616 + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
607 } 617 }
...@@ -677,7 +687,6 @@ public final class MethodsGenerator { ...@@ -677,7 +687,6 @@ public final class MethodsGenerator {
677 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; 687 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
678 } 688 }
679 689
680 -
681 /** 690 /**
682 * Returns hash code method open strings. 691 * Returns hash code method open strings.
683 * 692 *
...@@ -916,4 +925,38 @@ public final class MethodsGenerator { ...@@ -916,4 +925,38 @@ public final class MethodsGenerator {
916 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL 925 + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
917 + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; 926 + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
918 } 927 }
928 +
929 + /**
930 + * Returns of method for enum class.
931 + *
932 + * @param className class name
933 + * @param attr java attribute
934 + * @param enumMap enum's sets map
935 + * @param enumList enum's sets list
936 + * @return of method
937 + */
938 + public static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
939 + Map<String, Integer> enumMap, List<String> enumList) {
940 + String attrType = getReturnType(attr);
941 + String attrName = getSmallCase(attr.getAttributeName());
942 +
943 + String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF
944 + + OPEN_PARENTHESIS
945 + + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
946 + + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
947 + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
948 + int value = 0;
949 + for (String str : enumList) {
950 +
951 + value = enumMap.get(str);
952 + method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE
953 + + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + className + PERIOD
954 + + str + SEMI_COLAN + NEW_LINE;
955 + }
956 + method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION
957 + + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
958 + + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
959 +
960 + return getJavaDoc(OF_METHOD, className + " for type " + attrName, false) + method;
961 + }
919 } 962 }
......
...@@ -21,7 +21,11 @@ import java.io.IOException; ...@@ -21,7 +21,11 @@ import java.io.IOException;
21 import java.util.List; 21 import java.util.List;
22 22
23 import org.onosproject.yangutils.datamodel.YangNode; 23 import org.onosproject.yangutils.datamodel.YangNode;
24 +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
24 import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer; 25 import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer;
26 +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
27 +
28 +import static java.util.Collections.sort;
25 29
26 import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport; 30 import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport;
27 import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport; 31 import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport;
...@@ -31,8 +35,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; ...@@ -31,8 +35,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
31 import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; 35 import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
32 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; 36 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
33 37
34 -import static java.util.Collections.sort;
35 -
36 /** 38 /**
37 * Represents utilities for temporary java code fragments. 39 * Represents utilities for temporary java code fragments.
38 */ 40 */
...@@ -52,7 +54,8 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -52,7 +54,8 @@ public final class TempJavaCodeFragmentFilesUtils {
52 * @param operation add or delete import 54 * @param operation add or delete import
53 * @return import for HasAugmentation class 55 * @return import for HasAugmentation class
54 */ 56 */
55 - public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, boolean operation) { 57 + public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports,
58 + boolean operation) {
56 if (curNode instanceof JavaImportDataContainer) { 59 if (curNode instanceof JavaImportDataContainer) {
57 String thisImport = getHasAugmentationImport(); 60 String thisImport = getHasAugmentationImport();
58 performOperationOnImports(imports, thisImport, operation); 61 performOperationOnImports(imports, thisImport, operation);
...@@ -109,13 +112,14 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -109,13 +112,14 @@ public final class TempJavaCodeFragmentFilesUtils {
109 * @param operation add or remove 112 * @param operation add or remove
110 * @return import list 113 * @return import list
111 */ 114 */
112 - private static List<String> performOperationOnImports(List<String> imports, String curImport, boolean operation) { 115 + private static List<String> performOperationOnImports(List<String> imports, String curImport,
116 + boolean operation) {
113 if (operation) { 117 if (operation) {
114 imports.add(curImport); 118 imports.add(curImport);
115 } else { 119 } else {
116 imports.remove(curImport); 120 imports.remove(curImport);
117 } 121 }
118 - sort(imports); 122 + sortImports(imports);
119 return imports; 123 return imports;
120 } 124 }
121 125
...@@ -142,7 +146,7 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -142,7 +146,7 @@ public final class TempJavaCodeFragmentFilesUtils {
142 * @return true or false 146 * @return true or false
143 */ 147 */
144 public static boolean isHasAugmentationExtended(List<String> extendsList) { 148 public static boolean isHasAugmentationExtended(List<String> extendsList) {
145 - return (extendsList != null && extendsList.contains(HAS_AUGMENTATION)); 149 + return extendsList != null && extendsList.contains(HAS_AUGMENTATION);
146 } 150 }
147 151
148 /** 152 /**
...@@ -152,7 +156,7 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -152,7 +156,7 @@ public final class TempJavaCodeFragmentFilesUtils {
152 * @return true or false 156 * @return true or false
153 */ 157 */
154 public static boolean isAugmentedInfoExtended(List<String> extendsList) { 158 public static boolean isAugmentedInfoExtended(List<String> extendsList) {
155 - return (extendsList != null && extendsList.contains(AUGMENTED_INFO)); 159 + return extendsList != null && extendsList.contains(AUGMENTED_INFO);
156 } 160 }
157 161
158 /** 162 /**
...@@ -172,4 +176,37 @@ public final class TempJavaCodeFragmentFilesUtils { ...@@ -172,4 +176,37 @@ public final class TempJavaCodeFragmentFilesUtils {
172 } 176 }
173 } 177 }
174 } 178 }
179 +
180 + /**
181 + * Detects collision between parent and child node which have same name.
182 + * When parent and child node both have the same name in that case child node should be used with
183 + * qualified name.
184 + *
185 + * @param curNode current YANG node
186 + * @param qualifiedTypeInfo current node's qualified info
187 + * @return true if collision is detected
188 + */
189 + public static boolean detectCollisionBwParentAndChildForImport(YangNode curNode,
190 + JavaQualifiedTypeInfo qualifiedTypeInfo) {
191 +
192 + YangNode parent = curNode.getParent();
193 + String parentsClassInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
194 + String childsClassInfo = qualifiedTypeInfo.getClassInfo();
195 + if (childsClassInfo.equals(parentsClassInfo)) {
196 + return true;
197 + }
198 + return false;
199 + }
200 +
201 + /**
202 + * Returns sorted import list.
203 + *
204 + * @param imports import list
205 + * @return sorted import list
206 + */
207 + public static List<String> sortImports(List<String> imports) {
208 + sort(imports);
209 + return imports;
210 + }
211 +
175 } 212 }
......
...@@ -149,7 +149,7 @@ public final class YangJavaModelUtils { ...@@ -149,7 +149,7 @@ public final class YangJavaModelUtils {
149 /** 149 /**
150 * Enumeration 150 * Enumeration
151 */ 151 */
152 - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 152 + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
153 .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); 153 .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
154 } else if (javaCodeGeneratorInfo instanceof YangChoice) { 154 } else if (javaCodeGeneratorInfo instanceof YangChoice) {
155 /*Do nothing, only the interface needs to be generated*/ 155 /*Do nothing, only the interface needs to be generated*/
......
...@@ -41,7 +41,6 @@ public final class UtilConstants { ...@@ -41,7 +41,6 @@ public final class UtilConstants {
41 public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the" 41 public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
42 + " functionality of "; 42 + " functionality of ";
43 43
44 -
45 /** 44 /**
46 * JavaDocs for event. 45 * JavaDocs for event.
47 */ 46 */
...@@ -52,7 +51,6 @@ public final class UtilConstants { ...@@ -52,7 +51,6 @@ public final class UtilConstants {
52 */ 51 */
53 public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of "; 52 public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
54 53
55 -
56 /** 54 /**
57 * JavaDocs for builder interface class. 55 * JavaDocs for builder interface class.
58 */ 56 */
...@@ -169,6 +167,11 @@ public final class UtilConstants { ...@@ -169,6 +167,11 @@ public final class UtilConstants {
169 public static final String NEW_LINE = "\n"; 167 public static final String NEW_LINE = "\n";
170 168
171 /** 169 /**
170 + * Static attribute for default.
171 + */
172 + public static final String DEFAULT = "default";
173 +
174 + /**
172 * Static attribute for multiple new line. 175 * Static attribute for multiple new line.
173 */ 176 */
174 public static final String MULTIPLE_NEW_LINE = "\n\n"; 177 public static final String MULTIPLE_NEW_LINE = "\n\n";
...@@ -434,6 +437,16 @@ public final class UtilConstants { ...@@ -434,6 +437,16 @@ public final class UtilConstants {
434 public static final String CLEAR = "clear"; 437 public static final String CLEAR = "clear";
435 438
436 /** 439 /**
440 + * Static attribute for switch syntax.
441 + */
442 + public static final String SWITCH = "switch";
443 +
444 + /**
445 + * Static attribute for case syntax.
446 + */
447 + public static final String CASE = "case";
448 +
449 + /**
437 * Static attribute for temp val syntax. 450 * Static attribute for temp val syntax.
438 */ 451 */
439 public static final String TMP_VAL = "tmpVal"; 452 public static final String TMP_VAL = "tmpVal";
...@@ -703,7 +716,6 @@ public final class UtilConstants { ...@@ -703,7 +716,6 @@ public final class UtilConstants {
703 */ 716 */
704 public static final String SERVICE = "Service"; 717 public static final String SERVICE = "Service";
705 718
706 -
707 /** 719 /**
708 * Static attribute for interface syntax. 720 * Static attribute for interface syntax.
709 */ 721 */
...@@ -875,7 +887,7 @@ public final class UtilConstants { ...@@ -875,7 +887,7 @@ public final class UtilConstants {
875 public static final String ARRAY_LIST = "ArrayList"; 887 public static final String ARRAY_LIST = "ArrayList";
876 888
877 /** 889 /**
878 - * comment to be added for autogenerated impl methods. 890 + * Comment to be added for autogenerated impl methods.
879 */ 891 */
880 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; 892 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
881 893
......
...@@ -24,8 +24,9 @@ import java.io.IOException; ...@@ -24,8 +24,9 @@ import java.io.IOException;
24 import java.io.PrintWriter; 24 import java.io.PrintWriter;
25 25
26 import org.onosproject.yangutils.datamodel.YangNode; 26 import org.onosproject.yangutils.datamodel.YangNode;
27 -import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; 27 +import org.onosproject.yangutils.translator.exception.TranslatorException;
28 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 28 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
29 +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
29 30
30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; 31 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
31 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; 32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
...@@ -35,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; ...@@ -35,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
35 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 36 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
36 import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE; 37 import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE;
37 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 38 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
38 -import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
39 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 39 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
40 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 40 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
41 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; 41 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
...@@ -62,7 +62,7 @@ public final class FileSystemUtil { ...@@ -62,7 +62,7 @@ public final class FileSystemUtil {
62 public static boolean doesPackageExist(String pkg) { 62 public static boolean doesPackageExist(String pkg) {
63 File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); 63 File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
64 File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); 64 File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
65 - return (pkgDir.exists() && pkgWithFile.isFile()); 65 + return pkgDir.exists() && pkgWithFile.isFile();
66 } 66 }
67 67
68 /** 68 /**
...@@ -71,26 +71,24 @@ public final class FileSystemUtil { ...@@ -71,26 +71,24 @@ public final class FileSystemUtil {
71 * @param yangNode YANG node for which code is being generated 71 * @param yangNode YANG node for which code is being generated
72 * @throws IOException any IO exception 72 * @throws IOException any IO exception
73 */ 73 */
74 - public static void createPackage(YangNode yangNode) 74 + public static void createPackage(YangNode yangNode) throws IOException {
75 - throws IOException { 75 + if (!(yangNode instanceof JavaFileInfoContainer)) {
76 - 76 + throw new TranslatorException("current node must have java file info");
77 - YangNode parent = getParentNodeInGenCode(yangNode);
78 - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
79 - String absolutePath = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
80 - javaFileInfo.getPackageFilePath());
81 -
82 - String pkgInfo;
83 - if (parent != null) {
84 - pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()
85 - + PACKAGE_INFO_JAVADOC_OF_CHILD;
86 - } else {
87 - pkgInfo = javaFileInfo.getJavaName();
88 } 77 }
89 - 78 + String pkgInfo;
90 - if (!doesPackageExist(absolutePath)) { 79 + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
80 + String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), javaFileInfo.getPackageFilePath());
81 + if (!doesPackageExist(pkg)) {
91 try { 82 try {
92 - File pack = createDirectories(absolutePath); 83 + File pack = createDirectories(pkg);
93 - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(absolutePath)); 84 + YangNode parent = getParentNodeInGenCode(yangNode);
85 + if (parent != null) {
86 + pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
87 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true);
88 + } else {
89 + pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
90 + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false);
91 + }
94 } catch (IOException e) { 92 } catch (IOException e) {
95 throw new IOException("failed to create package-info file"); 93 throw new IOException("failed to create package-info file");
96 } 94 }
......
...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.utils.io.impl; ...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.utils.io.impl;
19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; 19 import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
20 20
21 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 21 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
22 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 22 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; 23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
25 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
...@@ -54,12 +53,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK; ...@@ -54,12 +53,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
54 import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; 53 import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
55 import static org.onosproject.yangutils.utils.UtilConstants.OF; 54 import static org.onosproject.yangutils.utils.UtilConstants.OF;
56 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; 55 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
56 +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
57 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 57 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
58 import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING; 58 import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING;
59 import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING; 59 import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING;
60 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 60 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
61 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 61 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
62 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 62 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
63 +import static org.onosproject.yangutils.utils.UtilConstants.VOID;
63 64
64 /** 65 /**
65 * Represents javadoc for the generated classes. 66 * Represents javadoc for the generated classes.
...@@ -108,11 +109,16 @@ public final class JavaDocGen { ...@@ -108,11 +109,16 @@ public final class JavaDocGen {
108 GETTER_METHOD, 109 GETTER_METHOD,
109 110
110 /** 111 /**
111 - * For rpc. 112 + * For rpc service.
112 */ 113 */
113 RPC_INTERFACE, 114 RPC_INTERFACE,
114 115
115 /** 116 /**
117 + * For rpc manager.
118 + */
119 + RPC_MANAGER,
120 +
121 + /**
116 * For event. 122 * For event.
117 */ 123 */
118 EVENT, 124 EVENT,
...@@ -203,7 +209,7 @@ public final class JavaDocGen { ...@@ -203,7 +209,7 @@ public final class JavaDocGen {
203 return generateForBuilderInterface(name); 209 return generateForBuilderInterface(name);
204 } 210 }
205 case PACKAGE_INFO: { 211 case PACKAGE_INFO: {
206 - return generateForPackage(name); 212 + return generateForPackage(name, isList);
207 } 213 }
208 case GETTER_METHOD: { 214 case GETTER_METHOD: {
209 return generateForGetters(name, isList); 215 return generateForGetters(name, isList);
...@@ -239,7 +245,10 @@ public final class JavaDocGen { ...@@ -239,7 +245,10 @@ public final class JavaDocGen {
239 return generateForEnumAttr(name); 245 return generateForEnumAttr(name);
240 } 246 }
241 case RPC_INTERFACE: { 247 case RPC_INTERFACE: {
242 - return generateForRpcInterface(name); 248 + return generateForRpcService(name);
249 + }
250 + case RPC_MANAGER: {
251 + return generateForImplClass(name);
243 } 252 }
244 case EVENT: { 253 case EVENT: {
245 return generateForEvent(name); 254 return generateForEvent(name);
...@@ -274,13 +283,14 @@ public final class JavaDocGen { ...@@ -274,13 +283,14 @@ public final class JavaDocGen {
274 */ 283 */
275 public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) { 284 public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) {
276 rpcName = getCamelCase(rpcName, null); 285 rpcName = getCamelCase(rpcName, null);
277 - inputName = getCaptialCase(inputName);
278 - outputName = getCaptialCase(outputName);
279 286
280 - return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC 287 + String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
281 + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK 288 + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
282 - + getInputString(inputName, rpcName) + getOutputString(outputName, rpcName) + FOUR_SPACE_INDENTATION 289 + + getInputString(inputName, rpcName);
283 - + JAVA_DOC_END_LINE; 290 + if (!outputName.equals(VOID)) {
291 + javadoc = javadoc + getOutputString(outputName, rpcName);
292 + }
293 + return javadoc + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
284 } 294 }
285 295
286 /** 296 /**
...@@ -315,7 +325,7 @@ public final class JavaDocGen { ...@@ -315,7 +325,7 @@ public final class JavaDocGen {
315 * @param interfaceName interface name 325 * @param interfaceName interface name
316 * @return javaDocs 326 * @return javaDocs
317 */ 327 */
318 - private static String generateForRpcInterface(String interfaceName) { 328 + private static String generateForRpcService(String interfaceName) {
319 return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE 329 return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
320 + JAVA_DOC_END_LINE; 330 + JAVA_DOC_END_LINE;
321 } 331 }
...@@ -436,7 +446,7 @@ public final class JavaDocGen { ...@@ -436,7 +446,7 @@ public final class JavaDocGen {
436 return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF 446 return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
437 + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD 447 + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
438 + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM 448 + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
439 - + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD + NEW_LINE 449 + + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + NEW_LINE
440 + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE 450 + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
441 + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; 451 + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
442 } 452 }
...@@ -512,10 +522,15 @@ public final class JavaDocGen { ...@@ -512,10 +522,15 @@ public final class JavaDocGen {
512 * Generates javaDocs for package-info. 522 * Generates javaDocs for package-info.
513 * 523 *
514 * @param packageName package name 524 * @param packageName package name
525 + * @param isChildNode is it child node
515 * @return javaDocs 526 * @return javaDocs
516 */ 527 */
517 - private static String generateForPackage(String packageName) { 528 + private static String generateForPackage(String packageName, boolean isChildNode) {
518 - return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; 529 + String javaDoc = JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName;
530 + if (isChildNode) {
531 + javaDoc = javaDoc + PACKAGE_INFO_JAVADOC_OF_CHILD;
532 + }
533 + return javaDoc + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
519 } 534 }
520 535
521 /** 536 /**
...@@ -536,11 +551,10 @@ public final class JavaDocGen { ...@@ -536,11 +551,10 @@ public final class JavaDocGen {
536 * @return javaDocs 551 * @return javaDocs
537 */ 552 */
538 private static String generateForConstructors(String className) { 553 private static String generateForConstructors(String className) {
539 - return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE 554 + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
540 - + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE 555 + + className + IMPL + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
541 - + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM 556 + + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT
542 - + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + className + NEW_LINE 557 + + className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
543 - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
544 } 558 }
545 559
546 /** 560 /**
......
...@@ -23,7 +23,9 @@ import java.io.IOException; ...@@ -23,7 +23,9 @@ import java.io.IOException;
23 import java.nio.file.Files; 23 import java.nio.file.Files;
24 import java.nio.file.StandardCopyOption; 24 import java.nio.file.StandardCopyOption;
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 +import java.util.LinkedList;
26 import java.util.List; 27 import java.util.List;
28 +import java.util.Stack;
27 29
28 import org.apache.commons.io.FileUtils; 30 import org.apache.commons.io.FileUtils;
29 import org.apache.maven.model.Resource; 31 import org.apache.maven.model.Resource;
...@@ -80,9 +82,11 @@ public final class YangIoUtils { ...@@ -80,9 +82,11 @@ public final class YangIoUtils {
80 * @param path directory path 82 * @param path directory path
81 * @param classInfo class info for the package 83 * @param classInfo class info for the package
82 * @param pack package of the directory 84 * @param pack package of the directory
85 + * @param isChildNode is it a child node
83 * @throws IOException when fails to create package info file 86 * @throws IOException when fails to create package info file
84 */ 87 */
85 - public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { 88 + public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode)
89 + throws IOException {
86 90
87 if (pack.contains(ORG)) { 91 if (pack.contains(ORG)) {
88 String[] strArray = pack.split(ORG); 92 String[] strArray = pack.split(ORG);
...@@ -97,7 +101,7 @@ public final class YangIoUtils { ...@@ -97,7 +101,7 @@ public final class YangIoUtils {
97 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); 101 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
98 102
99 bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); 103 bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
100 - bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, false)); 104 + bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode));
101 bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); 105 bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN);
102 106
103 bufferedWriter.close(); 107 bufferedWriter.close();
...@@ -119,8 +123,42 @@ public final class YangIoUtils { ...@@ -119,8 +123,42 @@ public final class YangIoUtils {
119 try { 123 try {
120 FileUtils.deleteDirectory(generatedDirectory); 124 FileUtils.deleteDirectory(generatedDirectory);
121 } catch (IOException e) { 125 } catch (IOException e) {
122 - throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory"); 126 + throw new IOException(
127 + "Failed to delete the generated files in " + generatedDirectory + " directory");
128 + }
129 + }
130 + }
131 +
132 + /**
133 + * Searches and deletes generated temporary directories.
134 + *
135 + * @param root root directory
136 + * @throws IOException when fails to do IO operations.
137 + */
138 + public static void searchAndDeleteTempDir(String root) throws IOException {
139 + List<File> store = new LinkedList<>();
140 + Stack<String> stack = new Stack<>();
141 + stack.push(root);
142 +
143 + while (!stack.empty()) {
144 + root = stack.pop();
145 + File file = new File(root);
146 + File[] filelist = file.listFiles();
147 + if (filelist == null || filelist.length == 0) {
148 + continue;
123 } 149 }
150 + for (File current : filelist) {
151 + if (current.isDirectory()) {
152 + stack.push(current.toString());
153 + if (current.getName().endsWith("-Temp")) {
154 + store.add(current);
155 + }
156 + }
157 + }
158 + }
159 +
160 + for (File dir : store) {
161 + dir.delete();
124 } 162 }
125 } 163 }
126 164
......
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.utils;
18 +
19 +import java.io.IOException;
20 +
21 +import org.junit.Test;
22 +import org.onosproject.yangutils.datamodel.YangNode;
23 +import org.onosproject.yangutils.parser.exceptions.ParserException;
24 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
25 +
26 +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
27 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
28 +
29 +/**
30 + * Unit test case for enum translator.
31 + */
32 +public final class EnumTranslatorTest {
33 +
34 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
35 +
36 + /**
37 + * Checks enum translation should not result in any exception.
38 + */
39 + @Test
40 + public void processEnumTranslator()
41 + throws IOException, ParserException {
42 +
43 + String userDir = System.getProperty("user.dir");
44 + YangNode node = manager.getDataModel("src/test/resources/EnumTranslator.yang");
45 +
46 + YangPluginConfig yangPluginConfig = new YangPluginConfig();
47 + yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
48 +
49 + generateJavaCode(node, yangPluginConfig);
50 +
51 + deleteDirectory(userDir + "/target/EnumTestGenFile/");
52 + }
53 + // TODO enhance the test cases, after having a framework of translator test.
54 +}
...@@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; ...@@ -22,6 +22,7 @@ import java.lang.reflect.Constructor;
22 import java.lang.reflect.InvocationTargetException; 22 import java.lang.reflect.InvocationTargetException;
23 23
24 import org.junit.Test; 24 import org.junit.Test;
25 +import org.onosproject.yangutils.datamodel.YangNode;
25 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
26 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; 27 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
27 28
...@@ -41,20 +42,23 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileH ...@@ -41,20 +42,23 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileH
41 public final class FileSystemUtilTest { 42 public final class FileSystemUtilTest {
42 43
43 private static final String BASE_DIR_PKG = "target.UnitTestCase."; 44 private static final String BASE_DIR_PKG = "target.UnitTestCase.";
44 - private static final String PKG_INFO_CONTENT = "testGeneration6";
45 private static final String BASE_PKG = "target/UnitTestCase"; 45 private static final String BASE_PKG = "target/UnitTestCase";
46 private static final String TEST_DATA_1 = "This is to append a text to the file first1\n"; 46 private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
47 private static final String TEST_DATA_2 = "This is next second line\n"; 47 private static final String TEST_DATA_2 = "This is next second line\n";
48 private static final String TEST_DATA_3 = "This is next third line in the file"; 48 private static final String TEST_DATA_3 = "This is next third line in the file";
49 + private static final String TEST_FILE = "testFile";
50 + private static final String SOURCE_TEST_FILE = "sourceTestFile";
51 + private static final String DIR_PATH = "exist1.exist2.exist3";
52 + private static final String PKG_INFO = "package-info.java";
49 53
50 /** 54 /**
51 * A private constructor is tested. 55 * A private constructor is tested.
52 * 56 *
53 - * @throws SecurityException if any security violation is observed 57 + * @throws SecurityException if any security violation is observed
54 - * @throws NoSuchMethodException if when the method is not found 58 + * @throws NoSuchMethodException if when the method is not found
55 - * @throws IllegalArgumentException if there is illegal argument found 59 + * @throws IllegalArgumentException if there is illegal argument found
56 - * @throws InstantiationException if instantiation is provoked for the private constructor 60 + * @throws InstantiationException if instantiation is provoked for the private constructor
57 - * @throws IllegalAccessException if instance is provoked or a method is provoked 61 + * @throws IllegalAccessException if instance is provoked or a method is provoked
58 * @throws InvocationTargetException when an exception occurs by the method or constructor 62 * @throws InvocationTargetException when an exception occurs by the method or constructor
59 */ 63 */
60 @Test 64 @Test
...@@ -62,7 +66,7 @@ public final class FileSystemUtilTest { ...@@ -62,7 +66,7 @@ public final class FileSystemUtilTest {
62 throws SecurityException, NoSuchMethodException, IllegalArgumentException, 66 throws SecurityException, NoSuchMethodException, IllegalArgumentException,
63 InstantiationException, IllegalAccessException, InvocationTargetException { 67 InstantiationException, IllegalAccessException, InvocationTargetException {
64 68
65 - Class<?>[] classesToConstruct = {FileSystemUtil.class}; 69 + Class<?>[] classesToConstruct = {FileSystemUtil.class };
66 for (Class<?> clazz : classesToConstruct) { 70 for (Class<?> clazz : classesToConstruct) {
67 Constructor<?> constructor = clazz.getDeclaredConstructor(); 71 Constructor<?> constructor = clazz.getDeclaredConstructor();
68 constructor.setAccessible(true); 72 constructor.setAccessible(true);
...@@ -76,14 +80,13 @@ public final class FileSystemUtilTest { ...@@ -76,14 +80,13 @@ public final class FileSystemUtilTest {
76 * @throws IOException when fails to create a test file 80 * @throws IOException when fails to create a test file
77 */ 81 */
78 @Test 82 @Test
79 - public void updateFileHandleTest() 83 + public void updateFileHandleTest() throws IOException {
80 - throws IOException {
81 84
82 - File dir = new File(BASE_PKG + SLASH + "File1"); 85 + File dir = new File(BASE_PKG + SLASH + TEST_FILE);
83 dir.mkdirs(); 86 dir.mkdirs();
84 - File createFile = new File(dir + "testFile"); 87 + File createFile = new File(dir + TEST_FILE);
85 createFile.createNewFile(); 88 createFile.createNewFile();
86 - File createSourceFile = new File(dir + "sourceTestFile"); 89 + File createSourceFile = new File(dir + SOURCE_TEST_FILE);
87 createSourceFile.createNewFile(); 90 createSourceFile.createNewFile();
88 updateFileHandle(createFile, TEST_DATA_1, false); 91 updateFileHandle(createFile, TEST_DATA_1, false);
89 updateFileHandle(createFile, TEST_DATA_2, false); 92 updateFileHandle(createFile, TEST_DATA_2, false);
...@@ -98,23 +101,31 @@ public final class FileSystemUtilTest { ...@@ -98,23 +101,31 @@ public final class FileSystemUtilTest {
98 * @throws IOException when failed to create a test file 101 * @throws IOException when failed to create a test file
99 */ 102 */
100 @Test 103 @Test
101 - public void packageExistTest() 104 + public void packageExistTest() throws IOException {
102 - throws IOException {
103 105
104 - String dirPath = "exist1.exist2.exist3"; 106 + String strPath = BASE_DIR_PKG + DIR_PATH;
105 - String strPath = BASE_DIR_PKG + dirPath;
106 File createDir = new File(strPath.replace(PERIOD, SLASH)); 107 File createDir = new File(strPath.replace(PERIOD, SLASH));
107 createDir.mkdirs(); 108 createDir.mkdirs();
108 - File createFile = new File(createDir + SLASH + "package-info.java"); 109 + File createFile = new File(createDir + SLASH + PKG_INFO);
109 createFile.createNewFile(); 110 createFile.createNewFile();
110 assertThat(true, is(doesPackageExist(strPath))); 111 assertThat(true, is(doesPackageExist(strPath)));
111 - JavaFileInfo javaFileInfo = new JavaFileInfo(); 112 + createPackage(getStubNode());
112 - javaFileInfo.setBaseCodeGenPath(BASE_DIR_PKG);
113 - javaFileInfo.setPackageFilePath(dirPath);
114 - YangJavaModule moduleNode = new YangJavaModule();
115 - moduleNode.setJavaFileInfo(javaFileInfo);
116 - createPackage(moduleNode);
117 createDir.delete(); 113 createDir.delete();
118 } 114 }
119 115
116 + /**
117 + * Returns stub YANG node.
118 + *
119 + * @return stub node
120 + */
121 + private YangNode getStubNode() {
122 + YangJavaModule module = new YangJavaModule();
123 + module.setName(TEST_DATA_1);
124 + JavaFileInfo javafileInfo = new JavaFileInfo();
125 + javafileInfo.setJavaName(TEST_DATA_1);
126 + javafileInfo.setBaseCodeGenPath("");
127 + javafileInfo.setPackageFilePath(BASE_PKG);
128 + module.setJavaFileInfo(javafileInfo);
129 + return module;
130 + }
120 } 131 }
......
...@@ -51,7 +51,7 @@ public final class JavaDocGenTest { ...@@ -51,7 +51,7 @@ public final class JavaDocGenTest {
51 public ExpectedException thrown = ExpectedException.none(); 51 public ExpectedException thrown = ExpectedException.none();
52 52
53 /** 53 /**
54 - * This test case checks the content recieved for the builder class java doc. 54 + * This test case checks the content received for the builder class java doc.
55 */ 55 */
56 @Test 56 @Test
57 public void builderClassGenerationTest() { 57 public void builderClassGenerationTest() {
...@@ -61,7 +61,7 @@ public final class JavaDocGenTest { ...@@ -61,7 +61,7 @@ public final class JavaDocGenTest {
61 } 61 }
62 62
63 /** 63 /**
64 - * This test case checks the content recieved for the builder interface ge java doc. 64 + * This test case checks the content received for the builder interface ge java doc.
65 */ 65 */
66 @Test 66 @Test
67 public void builderInterfaceGenerationTest() { 67 public void builderInterfaceGenerationTest() {
...@@ -71,7 +71,7 @@ public final class JavaDocGenTest { ...@@ -71,7 +71,7 @@ public final class JavaDocGenTest {
71 } 71 }
72 72
73 /** 73 /**
74 - * This test case checks the content recieved for the build java doc. 74 + * This test case checks the content received for the build java doc.
75 */ 75 */
76 @Test 76 @Test
77 public void buildGenerationTest() { 77 public void buildGenerationTest() {
...@@ -102,7 +102,7 @@ public final class JavaDocGenTest { ...@@ -102,7 +102,7 @@ public final class JavaDocGenTest {
102 } 102 }
103 103
104 /** 104 /**
105 - * This test case checks the content recieved for the constructor java doc. 105 + * This test case checks the content received for the constructor java doc.
106 */ 106 */
107 @Test 107 @Test
108 public void constructorGenerationTest() { 108 public void constructorGenerationTest() {
...@@ -113,7 +113,7 @@ public final class JavaDocGenTest { ...@@ -113,7 +113,7 @@ public final class JavaDocGenTest {
113 } 113 }
114 114
115 /** 115 /**
116 - * This test case checks the content recieved for the default constructor java doc. 116 + * This test case checks the content received for the default constructor java doc.
117 */ 117 */
118 @Test 118 @Test
119 public void defaultConstructorGenerationTest() { 119 public void defaultConstructorGenerationTest() {
...@@ -123,7 +123,7 @@ public final class JavaDocGenTest { ...@@ -123,7 +123,7 @@ public final class JavaDocGenTest {
123 } 123 }
124 124
125 /** 125 /**
126 - * This test case checks the content recieved for the getter java doc. 126 + * This test case checks the content received for the getter java doc.
127 */ 127 */
128 @Test 128 @Test
129 public void getterGenerationTest() { 129 public void getterGenerationTest() {
...@@ -132,7 +132,7 @@ public final class JavaDocGenTest { ...@@ -132,7 +132,7 @@ public final class JavaDocGenTest {
132 } 132 }
133 133
134 /** 134 /**
135 - * This test case checks the content recieved for the impl class java doc. 135 + * This test case checks the content received for the impl class java doc.
136 */ 136 */
137 @Test 137 @Test
138 public void implClassGenerationTest() { 138 public void implClassGenerationTest() {
...@@ -143,7 +143,7 @@ public final class JavaDocGenTest { ...@@ -143,7 +143,7 @@ public final class JavaDocGenTest {
143 } 143 }
144 144
145 /** 145 /**
146 - * This test case checks the content recieved for the interface java doc. 146 + * This test case checks the content received for the interface java doc.
147 */ 147 */
148 @Test 148 @Test
149 public void interfaceGenerationTest() { 149 public void interfaceGenerationTest() {
...@@ -154,7 +154,7 @@ public final class JavaDocGenTest { ...@@ -154,7 +154,7 @@ public final class JavaDocGenTest {
154 } 154 }
155 155
156 /** 156 /**
157 - * This test case checks the content recieved for the package info java doc. 157 + * This test case checks the content received for the package info java doc.
158 */ 158 */
159 @Test 159 @Test
160 public void packageInfoGenerationTest() { 160 public void packageInfoGenerationTest() {
...@@ -163,7 +163,17 @@ public final class JavaDocGenTest { ...@@ -163,7 +163,17 @@ public final class JavaDocGenTest {
163 } 163 }
164 164
165 /** 165 /**
166 - * This test case checks the content recieved for the setter java doc. 166 + * This test case checks the content received for the package info java doc.
167 + */
168 + @Test
169 + public void packageInfoGenerationForChildNodeTest() {
170 + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true);
171 + assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
172 + && packageInfo.contains(END_STRING)));
173 + }
174 +
175 + /**
176 + * This test case checks the content received for the setter java doc.
167 */ 177 */
168 @Test 178 @Test
169 public void setterGenerationTest() { 179 public void setterGenerationTest() {
......
...@@ -47,6 +47,10 @@ public final class YangIoUtilsTest { ...@@ -47,6 +47,10 @@ public final class YangIoUtilsTest {
47 private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/"; 47 private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/";
48 private static final String CHECK_STRING = "one, two, three, four, five, six"; 48 private static final String CHECK_STRING = "one, two, three, four, five, six";
49 private static final String TRIM_STRING = "one, two, three, four, five, "; 49 private static final String TRIM_STRING = "one, two, three, four, five, ";
50 + private static final String CHECK1 = "check1";
51 + private static final String PKG_INFO = "package-info.java";
52 + private static final String PATH = "src/main/yangmodel/";
53 + private static final String MSG = "Exception occured while creating package info file.";
50 54
51 /** 55 /**
52 * Expected exceptions. 56 * Expected exceptions.
...@@ -64,8 +68,8 @@ public final class YangIoUtilsTest { ...@@ -64,8 +68,8 @@ public final class YangIoUtilsTest {
64 68
65 File dirPath = new File(CREATE_PATH); 69 File dirPath = new File(CREATE_PATH);
66 dirPath.mkdirs(); 70 dirPath.mkdirs();
67 - addPackageInfo(dirPath, "check1", CREATE_PATH); 71 + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
68 - File filePath = new File(dirPath + File.separator + "package-info.java"); 72 + File filePath = new File(dirPath + File.separator + PKG_INFO);
69 assertThat(filePath.isFile(), is(true)); 73 assertThat(filePath.isFile(), is(true));
70 } 74 }
71 75
...@@ -79,8 +83,23 @@ public final class YangIoUtilsTest { ...@@ -79,8 +83,23 @@ public final class YangIoUtilsTest {
79 83
80 File dirPath = new File(CREATE_PATH); 84 File dirPath = new File(CREATE_PATH);
81 dirPath.mkdirs(); 85 dirPath.mkdirs();
82 - addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + CREATE_PATH); 86 + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false);
83 - File filePath = new File(dirPath + File.separator + "package-info.java"); 87 + File filePath = new File(dirPath + File.separator + PKG_INFO);
88 + assertThat(filePath.isFile(), is(true));
89 + }
90 +
91 + /**
92 + * This test case checks with a child node.
93 + *
94 + * @throws IOException when fails to do IO operations for test case
95 + */
96 + @Test
97 + public void addPackageInfoWithChildNode() throws IOException {
98 +
99 + File dirPath = new File(CREATE_PATH);
100 + dirPath.mkdirs();
101 + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true);
102 + File filePath = new File(dirPath + File.separator + PKG_INFO);
84 assertThat(filePath.isFile(), is(true)); 103 assertThat(filePath.isFile(), is(true));
85 } 104 }
86 105
...@@ -94,9 +113,9 @@ public final class YangIoUtilsTest { ...@@ -94,9 +113,9 @@ public final class YangIoUtilsTest {
94 113
95 File dirPath = new File("invalid/check"); 114 File dirPath = new File("invalid/check");
96 thrown.expect(IOException.class); 115 thrown.expect(IOException.class);
97 - thrown.expectMessage("Exception occured while creating package info file."); 116 + thrown.expectMessage(MSG);
98 - addPackageInfo(dirPath, "check1", CREATE_PATH); 117 + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
99 - File filePath1 = new File(dirPath + File.separator + "package-info.java"); 118 + File filePath1 = new File(dirPath + File.separator + PKG_INFO);
100 assertThat(filePath1.isFile(), is(false)); 119 assertThat(filePath1.isFile(), is(false));
101 } 120 }
102 121
......
1 +module Sfc {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf test{
6 + type string;
7 + }
8 + leaf myenum {
9 + type enumeration {
10 + enum zero;
11 + enum one;
12 + enum seven {
13 + value 7;
14 + }
15 + }
16 + }
17 +}