Committed by
Gerrit Code Review
[ONOS-4149],[ONOS-3909] YANG list translator impl and bug fixes.
Change-Id: Ia1a94142a3a114815766f661ed850bf9cacde66f
Showing
29 changed files
with
1791 additions
and
1349 deletions
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | -import java.io.File; | ||
20 | import java.util.Iterator; | 19 | import java.util.Iterator; |
21 | import java.util.List; | 20 | import java.util.List; |
22 | 21 | ||
... | @@ -24,31 +23,34 @@ import org.apache.maven.plugin.AbstractMojo; | ... | @@ -24,31 +23,34 @@ import org.apache.maven.plugin.AbstractMojo; |
24 | import org.apache.maven.plugin.MojoExecutionException; | 23 | import org.apache.maven.plugin.MojoExecutionException; |
25 | import org.apache.maven.plugin.MojoFailureException; | 24 | import org.apache.maven.plugin.MojoFailureException; |
26 | import org.apache.maven.plugins.annotations.Component; | 25 | import org.apache.maven.plugins.annotations.Component; |
27 | -import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
28 | import org.apache.maven.plugins.annotations.Mojo; | 26 | import org.apache.maven.plugins.annotations.Mojo; |
29 | import org.apache.maven.plugins.annotations.Parameter; | 27 | import org.apache.maven.plugins.annotations.Parameter; |
30 | -import org.apache.maven.plugins.annotations.ResolutionScope; | ||
31 | import org.apache.maven.project.MavenProject; | 28 | import org.apache.maven.project.MavenProject; |
32 | import org.onosproject.yangutils.datamodel.YangNode; | 29 | import org.onosproject.yangutils.datamodel.YangNode; |
33 | import org.onosproject.yangutils.parser.YangUtilsParser; | 30 | import org.onosproject.yangutils.parser.YangUtilsParser; |
34 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 31 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
35 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 32 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
36 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
37 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 33 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
38 | import org.sonatype.plexus.build.incremental.BuildContext; | 34 | import org.sonatype.plexus.build.incremental.BuildContext; |
39 | 35 | ||
36 | +import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | ||
37 | +import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; | ||
40 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | 38 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
39 | +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
41 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; | 42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; |
42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; |
44 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; | 45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; |
44 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; | 46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; |
45 | 47 | ||
46 | /** | 48 | /** |
47 | - * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase | 49 | + * ONOS YANG utility maven plugin. |
48 | - * in generate-sources requiresDependencyResolution at compile time. | 50 | + * Goal of plugin is yang2java Execution phase in generate-sources requiresDependencyResolution at compile time. |
49 | */ | 51 | */ |
50 | -@Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES, | 52 | +@Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE, |
51 | - requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) | 53 | + requiresProject = true) |
52 | public class YangUtilManager extends AbstractMojo { | 54 | public class YangUtilManager extends AbstractMojo { |
53 | 55 | ||
54 | /** | 56 | /** |
... | @@ -87,8 +89,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -87,8 +89,7 @@ public class YangUtilManager extends AbstractMojo { |
87 | @Component | 89 | @Component |
88 | private BuildContext context; | 90 | private BuildContext context; |
89 | 91 | ||
90 | - private static final String DEFAULT_PKG = File.separator | 92 | + private static final String DEFAULT_PKG = SLASH + convertPkgToPath(DEFAULT_BASE_PKG); |
91 | - + UtilConstants.DEFAULT_BASE_PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH); | ||
92 | 93 | ||
93 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 94 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
94 | private String searchDir; | 95 | private String searchDir; |
... | @@ -116,7 +117,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -116,7 +117,7 @@ public class YangUtilManager extends AbstractMojo { |
116 | clean(getDirectory(baseDir, outputDirectory)); | 117 | clean(getDirectory(baseDir, outputDirectory)); |
117 | 118 | ||
118 | searchDir = getDirectory(baseDir, yangFilesDir); | 119 | searchDir = getDirectory(baseDir, yangFilesDir); |
119 | - codeGenDir = getDirectory(baseDir, genFilesDir) + File.separator; | 120 | + codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; |
120 | 121 | ||
121 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); | 122 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); |
122 | Iterator<String> yangFileIterator = yangFiles.iterator(); | 123 | Iterator<String> yangFileIterator = yangFiles.iterator(); |
... | @@ -133,7 +134,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -133,7 +134,7 @@ public class YangUtilManager extends AbstractMojo { |
133 | 134 | ||
134 | } | 135 | } |
135 | if (e.getMessage() != null) { | 136 | if (e.getMessage() != null) { |
136 | - logInfo = logInfo + UtilConstants.NEW_LINE + e.getMessage(); | 137 | + logInfo = logInfo + NEW_LINE + e.getMessage(); |
137 | } | 138 | } |
138 | getLog().info(logInfo); | 139 | getLog().info(logInfo); |
139 | } | 140 | } |
... | @@ -143,7 +144,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -143,7 +144,7 @@ public class YangUtilManager extends AbstractMojo { |
143 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); | 144 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); |
144 | } catch (Exception e) { | 145 | } catch (Exception e) { |
145 | getLog().info(e); | 146 | getLog().info(e); |
146 | - //throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); | 147 | + throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); |
147 | } | 148 | } |
148 | } | 149 | } |
149 | } | 150 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | import org.onosproject.yangutils.datamodel.YangNode; | 19 | import org.onosproject.yangutils.datamodel.YangNode; |
20 | import org.onosproject.yangutils.datamodel.YangType; | 20 | import org.onosproject.yangutils.datamodel.YangType; |
21 | +import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ||
21 | 22 | ||
22 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; | 23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; |
23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | 24 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
... | @@ -246,4 +247,40 @@ public final class JavaAttributeInfo { | ... | @@ -246,4 +247,40 @@ public final class JavaAttributeInfo { |
246 | 247 | ||
247 | return newAttr; | 248 | return newAttr; |
248 | } | 249 | } |
250 | + | ||
251 | + /** | ||
252 | + * Create an attribute info object corresponding to the passed type def attribute | ||
253 | + * information and return it. | ||
254 | + * | ||
255 | + * @param curNode current data model node for which the java file is being | ||
256 | + * generated | ||
257 | + * @param attributeType leaf data type | ||
258 | + * @param attributeName leaf name | ||
259 | + * @param isListAttribute is the current added attribute needs to be a list | ||
260 | + * @return AttributeInfo attribute details required to add in temporary | ||
261 | + * files | ||
262 | + */ | ||
263 | + public static JavaAttributeInfo getAttributeInfoOfTypeDef(YangNode curNode, | ||
264 | + YangType<?> attributeType, String attributeName, | ||
265 | + boolean isListAttribute) { | ||
266 | + | ||
267 | + JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
268 | + | ||
269 | + /* | ||
270 | + * Get the import info corresponding to the attribute for import in | ||
271 | + * generated java files or qualified access | ||
272 | + */ | ||
273 | + JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, | ||
274 | + attributeType, attributeName, isListAttribute); | ||
275 | + AttributesJavaDataType.addImportInfo(importInfo); | ||
276 | + newAttr.setImportInfo(importInfo); | ||
277 | + newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList( | ||
278 | + curNode, importInfo)); | ||
279 | + newAttr.setAttributeName(getCamelCase(attributeName)); | ||
280 | + newAttr.setListAttr(isListAttribute); | ||
281 | + newAttr.setImportInfo(importInfo); | ||
282 | + newAttr.setAttributeType(attributeType); | ||
283 | + | ||
284 | + return newAttr; | ||
285 | + } | ||
249 | } | 286 | } | ... | ... |
... | @@ -15,11 +15,26 @@ | ... | @@ -15,11 +15,26 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.yangutils.translator.tojava; | 16 | package org.onosproject.yangutils.translator.tojava; |
17 | 17 | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.List; | ||
18 | import java.util.SortedSet; | 20 | import java.util.SortedSet; |
19 | import java.util.TreeSet; | 21 | import java.util.TreeSet; |
20 | 22 | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | 24 | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
37 | + | ||
23 | /** | 38 | /** |
24 | * Generated Java file can contain imports. | 39 | * Generated Java file can contain imports. |
25 | */ | 40 | */ |
... | @@ -49,6 +64,7 @@ public class JavaImportData { | ... | @@ -49,6 +64,7 @@ public class JavaImportData { |
49 | * @return true if any of the attribute needs to be maintained as a list. | 64 | * @return true if any of the attribute needs to be maintained as a list. |
50 | */ | 65 | */ |
51 | public boolean getIfListImported() { | 66 | public boolean getIfListImported() { |
67 | + | ||
52 | return isListToImport; | 68 | return isListToImport; |
53 | } | 69 | } |
54 | 70 | ||
... | @@ -58,6 +74,7 @@ public class JavaImportData { | ... | @@ -58,6 +74,7 @@ public class JavaImportData { |
58 | * @param isList status to mention list is bing imported. | 74 | * @param isList status to mention list is bing imported. |
59 | */ | 75 | */ |
60 | public void setIfListImported(boolean isList) { | 76 | public void setIfListImported(boolean isList) { |
77 | + | ||
61 | isListToImport = isList; | 78 | isListToImport = isList; |
62 | } | 79 | } |
63 | 80 | ||
... | @@ -67,6 +84,7 @@ public class JavaImportData { | ... | @@ -67,6 +84,7 @@ public class JavaImportData { |
67 | * @return the set containing the imported class/interface info | 84 | * @return the set containing the imported class/interface info |
68 | */ | 85 | */ |
69 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { | 86 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { |
87 | + | ||
70 | return importSet; | 88 | return importSet; |
71 | } | 89 | } |
72 | 90 | ||
... | @@ -76,6 +94,7 @@ public class JavaImportData { | ... | @@ -76,6 +94,7 @@ public class JavaImportData { |
76 | * @param importSet the set containing the imported class/interface info | 94 | * @param importSet the set containing the imported class/interface info |
77 | */ | 95 | */ |
78 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { | 96 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { |
97 | + | ||
79 | this.importSet = importSet; | 98 | this.importSet = importSet; |
80 | } | 99 | } |
81 | 100 | ||
... | @@ -95,6 +114,7 @@ public class JavaImportData { | ... | @@ -95,6 +114,7 @@ public class JavaImportData { |
95 | * @return status of new addition of class/interface to the import set | 114 | * @return status of new addition of class/interface to the import set |
96 | */ | 115 | */ |
97 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { | 116 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { |
117 | + | ||
98 | if (!(curNode instanceof HasJavaImportData)) { | 118 | if (!(curNode instanceof HasJavaImportData)) { |
99 | throw new RuntimeException("missing import info in data model node"); | 119 | throw new RuntimeException("missing import info in data model node"); |
100 | } | 120 | } |
... | @@ -108,4 +128,62 @@ public class JavaImportData { | ... | @@ -108,4 +128,62 @@ public class JavaImportData { |
108 | ((HasJavaImportData) curNode).getJavaImportData().getImportSet().add(newImportInfo); | 128 | ((HasJavaImportData) curNode).getJavaImportData().getImportSet().add(newImportInfo); |
109 | return true; | 129 | return true; |
110 | } | 130 | } |
131 | + | ||
132 | + /** | ||
133 | + * Returns import for class. | ||
134 | + * | ||
135 | + * @param attr java attribute info | ||
136 | + * @return imports for class | ||
137 | + */ | ||
138 | + public List<String> getImports(JavaAttributeInfo attr) { | ||
139 | + | ||
140 | + String importString; | ||
141 | + List<String> imports = new ArrayList<>(); | ||
142 | + | ||
143 | + for (JavaQualifiedTypeInfo importInfo : getImportSet()) { | ||
144 | + importString = IMPORT; | ||
145 | + if (importInfo.getPkgInfo() != EMPTY_STRING && importInfo.getClassInfo() != null | ||
146 | + && importInfo.getPkgInfo() != JAVA_LANG) { | ||
147 | + importString = importString + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN | ||
148 | + + NEW_LINE; | ||
149 | + | ||
150 | + imports.add(importString); | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + if (attr.isListAttr()) { | ||
155 | + imports.add(setImportForList()); | ||
156 | + } | ||
157 | + | ||
158 | + java.util.Collections.sort(imports); | ||
159 | + return imports; | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * Gets import for hash and equals method. | ||
164 | + * | ||
165 | + * @return import for hash and equals method | ||
166 | + */ | ||
167 | + public String getImportForHashAndEquals() { | ||
168 | + | ||
169 | + return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Gets import for to string method. | ||
174 | + * | ||
175 | + * @return import for to string method | ||
176 | + */ | ||
177 | + public String getImportForToString() { | ||
178 | + | ||
179 | + return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * Sets import for to list. | ||
184 | + */ | ||
185 | + private static String setImportForList() { | ||
186 | + | ||
187 | + return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; | ||
188 | + } | ||
111 | } | 189 | } | ... | ... |
... | @@ -18,19 +18,25 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -18,19 +18,25 @@ package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | +import java.util.ArrayList; | ||
21 | import java.util.List; | 22 | import java.util.List; |
22 | 23 | ||
23 | import org.onosproject.yangutils.datamodel.YangLeaf; | 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
24 | import org.onosproject.yangutils.datamodel.YangLeafList; | 25 | import org.onosproject.yangutils.datamodel.YangLeafList; |
25 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
26 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
27 | -import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator; | 28 | +import org.onosproject.yangutils.datamodel.YangTypeDef; |
29 | +import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen; | ||
28 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; | 30 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
29 | import org.onosproject.yangutils.utils.UtilConstants; | 31 | import org.onosproject.yangutils.utils.UtilConstants; |
30 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | 32 | import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; |
33 | +import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | ||
34 | +import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
31 | 35 | ||
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
38 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
39 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | ||
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
... | @@ -43,8 +49,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -43,8 +49,15 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
45 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; | 51 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; |
52 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfTypeDef; | ||
46 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; | 53 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; |
47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
55 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; | ||
56 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; | ||
57 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; | ||
58 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; | ||
59 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; | ||
60 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; | ||
48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; | 61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
49 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; | 62 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; | 63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; |
... | @@ -53,11 +66,30 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -53,11 +66,30 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; | 66 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; | 67 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
69 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; | ||
56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; | 70 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
57 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; | 71 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
72 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForTypeDefClass; | ||
58 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
59 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; | 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
75 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor; | ||
60 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
77 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
78 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
79 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
80 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
81 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
82 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
83 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
84 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
85 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
86 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
87 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | ||
88 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_CONSTRUCTOR; | ||
89 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD; | ||
90 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | ||
91 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | ||
92 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; | ||
61 | 93 | ||
62 | /** | 94 | /** |
63 | * Provides implementation of java code fragments temporary implementations. | 95 | * Provides implementation of java code fragments temporary implementations. |
... | @@ -71,6 +103,12 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -71,6 +103,12 @@ public class TempJavaCodeFragmentFiles { |
71 | private int generatedTempFiles; | 103 | private int generatedTempFiles; |
72 | 104 | ||
73 | /** | 105 | /** |
106 | + * The variable which guides the types of files generated using | ||
107 | + * the generated file types mask. | ||
108 | + */ | ||
109 | + private int generatedJavaFiles; | ||
110 | + | ||
111 | + /** | ||
74 | * Absolute path where the target java file needs to be generated. | 112 | * Absolute path where the target java file needs to be generated. |
75 | */ | 113 | */ |
76 | private String absoluteDirPath; | 114 | private String absoluteDirPath; |
... | @@ -81,6 +119,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -81,6 +119,11 @@ public class TempJavaCodeFragmentFiles { |
81 | private String generatedJavaClassName; | 119 | private String generatedJavaClassName; |
82 | 120 | ||
83 | /** | 121 | /** |
122 | + * File type extension for java classes. | ||
123 | + */ | ||
124 | + private static final String JAVA_FILE_EXTENSION = ".java"; | ||
125 | + | ||
126 | + /** | ||
84 | * File type extension for temporary classes. | 127 | * File type extension for temporary classes. |
85 | */ | 128 | */ |
86 | private static final String TEMP_FILE_EXTENSION = ".tmp"; | 129 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
... | @@ -136,6 +179,56 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -136,6 +179,56 @@ public class TempJavaCodeFragmentFiles { |
136 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; | 179 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
137 | 180 | ||
138 | /** | 181 | /** |
182 | + * File name for interface java file name suffix. | ||
183 | + */ | ||
184 | + private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; | ||
185 | + | ||
186 | + /** | ||
187 | + * File name for builder interface file name suffix. | ||
188 | + */ | ||
189 | + private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; | ||
190 | + | ||
191 | + /** | ||
192 | + * File name for builder class file name suffix. | ||
193 | + */ | ||
194 | + private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; | ||
195 | + | ||
196 | + /** | ||
197 | + * File name for impl class file name suffix. | ||
198 | + */ | ||
199 | + private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL; | ||
200 | + | ||
201 | + /** | ||
202 | + * File name for typedef class file name suffix. | ||
203 | + */ | ||
204 | + private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; | ||
205 | + | ||
206 | + /** | ||
207 | + * Java file handle for interface file. | ||
208 | + */ | ||
209 | + private File interfaceJavaFileHandle; | ||
210 | + | ||
211 | + /** | ||
212 | + * Java file handle for builder interface file. | ||
213 | + */ | ||
214 | + private File builderInterfaceJavaFileHandle; | ||
215 | + | ||
216 | + /** | ||
217 | + * Java file handle for builder class file. | ||
218 | + */ | ||
219 | + private File builderClassJavaFileHandle; | ||
220 | + | ||
221 | + /** | ||
222 | + * Java file handle for impl class file. | ||
223 | + */ | ||
224 | + private File implClassJavaFileHandle; | ||
225 | + | ||
226 | + /** | ||
227 | + * Java file handle for typedef class file. | ||
228 | + */ | ||
229 | + private File typedefClassJavaFileHandle; | ||
230 | + | ||
231 | + /** | ||
139 | * Temporary file handle for attribute. | 232 | * Temporary file handle for attribute. |
140 | */ | 233 | */ |
141 | private File attributesTempFileHandle; | 234 | private File attributesTempFileHandle; |
... | @@ -181,6 +274,16 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -181,6 +274,16 @@ public class TempJavaCodeFragmentFiles { |
181 | private File toStringImplTempFileHandle; | 274 | private File toStringImplTempFileHandle; |
182 | 275 | ||
183 | /** | 276 | /** |
277 | + * Java attribute info. | ||
278 | + */ | ||
279 | + private JavaAttributeInfo newAttrInfo; | ||
280 | + | ||
281 | + /** | ||
282 | + * Current YANG node. | ||
283 | + */ | ||
284 | + private YangNode curYangNode; | ||
285 | + | ||
286 | + /** | ||
184 | * Construct an object of temporary java code fragment. | 287 | * Construct an object of temporary java code fragment. |
185 | * | 288 | * |
186 | * @param genFileType file generation type | 289 | * @param genFileType file generation type |
... | @@ -188,12 +291,13 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -188,12 +291,13 @@ public class TempJavaCodeFragmentFiles { |
188 | * @param className class name | 291 | * @param className class name |
189 | * @throws IOException when fails to create new file handle | 292 | * @throws IOException when fails to create new file handle |
190 | */ | 293 | */ |
191 | - public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) throws IOException { | 294 | + public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) |
295 | + throws IOException { | ||
192 | 296 | ||
193 | generatedTempFiles = 0; | 297 | generatedTempFiles = 0; |
194 | absoluteDirPath = genDir; | 298 | absoluteDirPath = genDir; |
195 | generatedJavaClassName = className; | 299 | generatedJavaClassName = className; |
196 | - | 300 | + generatedJavaFiles = genFileType; |
197 | /** | 301 | /** |
198 | * Initialize getter when generation file type matches to interface | 302 | * Initialize getter when generation file type matches to interface |
199 | * mask. | 303 | * mask. |
... | @@ -234,6 +338,18 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -234,6 +338,18 @@ public class TempJavaCodeFragmentFiles { |
234 | generatedTempFiles |= TO_STRING_IMPL_MASK; | 338 | generatedTempFiles |= TO_STRING_IMPL_MASK; |
235 | } | 339 | } |
236 | 340 | ||
341 | + /** | ||
342 | + * Initialize getterImpl, attributes, hash code, equals and | ||
343 | + * to strings when generation file type matches to typeDef class mask. | ||
344 | + */ | ||
345 | + if ((genFileType & GENERATE_TYPEDEF_CLASS) != 0) { | ||
346 | + generatedTempFiles |= ATTRIBUTES_MASK; | ||
347 | + generatedTempFiles |= GETTER_FOR_CLASS_MASK; | ||
348 | + generatedTempFiles |= HASH_CODE_IMPL_MASK; | ||
349 | + generatedTempFiles |= EQUALS_IMPL_MASK; | ||
350 | + generatedTempFiles |= TO_STRING_IMPL_MASK; | ||
351 | + } | ||
352 | + | ||
237 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | 353 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
238 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); | 354 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
239 | } | 355 | } |
... | @@ -272,6 +388,106 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -272,6 +388,106 @@ public class TempJavaCodeFragmentFiles { |
272 | } | 388 | } |
273 | 389 | ||
274 | /** | 390 | /** |
391 | + * Returns java file handle for interface file. | ||
392 | + * | ||
393 | + * @return java file handle for interface file | ||
394 | + */ | ||
395 | + public File getInterfaceJavaFileHandle() { | ||
396 | + | ||
397 | + return interfaceJavaFileHandle; | ||
398 | + } | ||
399 | + | ||
400 | + /** | ||
401 | + * Sets the java file handle for interface file. | ||
402 | + * | ||
403 | + * @param interfaceJavaFileHandle java file handle | ||
404 | + */ | ||
405 | + public void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { | ||
406 | + | ||
407 | + this.interfaceJavaFileHandle = interfaceJavaFileHandle; | ||
408 | + } | ||
409 | + | ||
410 | + /** | ||
411 | + * Returns java file handle for builder interface file. | ||
412 | + * | ||
413 | + * @return java file handle for builder interface file | ||
414 | + */ | ||
415 | + public File getBuilderInterfaceJavaFileHandle() { | ||
416 | + | ||
417 | + return builderInterfaceJavaFileHandle; | ||
418 | + } | ||
419 | + | ||
420 | + /** | ||
421 | + * Sets the java file handle for builder interface file. | ||
422 | + * | ||
423 | + * @param builderInterfaceJavaFileHandle java file handle | ||
424 | + */ | ||
425 | + public void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { | ||
426 | + | ||
427 | + this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; | ||
428 | + } | ||
429 | + | ||
430 | + /** | ||
431 | + * Returns java file handle for builder class file. | ||
432 | + * | ||
433 | + * @return java file handle for builder class file | ||
434 | + */ | ||
435 | + public File getBuilderClassJavaFileHandle() { | ||
436 | + | ||
437 | + return builderClassJavaFileHandle; | ||
438 | + } | ||
439 | + | ||
440 | + /** | ||
441 | + * Sets the java file handle for builder class file. | ||
442 | + * | ||
443 | + * @param builderClassJavaFileHandle java file handle | ||
444 | + */ | ||
445 | + public void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { | ||
446 | + | ||
447 | + this.builderClassJavaFileHandle = builderClassJavaFileHandle; | ||
448 | + } | ||
449 | + | ||
450 | + /** | ||
451 | + * Returns java file handle for impl class file. | ||
452 | + * | ||
453 | + * @return java file handle for impl class file | ||
454 | + */ | ||
455 | + public File getImplClassJavaFileHandle() { | ||
456 | + | ||
457 | + return implClassJavaFileHandle; | ||
458 | + } | ||
459 | + | ||
460 | + /** | ||
461 | + * Sets the java file handle for impl class file. | ||
462 | + * | ||
463 | + * @param implClassJavaFileHandle java file handle | ||
464 | + */ | ||
465 | + public void setImplClassJavaFileHandle(File implClassJavaFileHandle) { | ||
466 | + | ||
467 | + this.implClassJavaFileHandle = implClassJavaFileHandle; | ||
468 | + } | ||
469 | + | ||
470 | + /** | ||
471 | + * Returns java file handle for typedef class file. | ||
472 | + * | ||
473 | + * @return java file handle for typedef class file | ||
474 | + */ | ||
475 | + public File getTypedefClassJavaFileHandle() { | ||
476 | + | ||
477 | + return typedefClassJavaFileHandle; | ||
478 | + } | ||
479 | + | ||
480 | + /** | ||
481 | + * Sets the java file handle for typedef class file. | ||
482 | + * | ||
483 | + * @param typedefClassJavaFileHandle java file handle | ||
484 | + */ | ||
485 | + public void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) { | ||
486 | + | ||
487 | + this.typedefClassJavaFileHandle = typedefClassJavaFileHandle; | ||
488 | + } | ||
489 | + | ||
490 | + /** | ||
275 | * Returns attribute's temporary file handle. | 491 | * Returns attribute's temporary file handle. |
276 | * | 492 | * |
277 | * @return temporary file handle | 493 | * @return temporary file handle |
... | @@ -452,6 +668,46 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -452,6 +668,46 @@ public class TempJavaCodeFragmentFiles { |
452 | } | 668 | } |
453 | 669 | ||
454 | /** | 670 | /** |
671 | + * Returns java attribute info. | ||
672 | + * | ||
673 | + * @return java attribute info | ||
674 | + */ | ||
675 | + public JavaAttributeInfo getNewAttrInfo() { | ||
676 | + | ||
677 | + return newAttrInfo; | ||
678 | + } | ||
679 | + | ||
680 | + /** | ||
681 | + * Sets java attribute info. | ||
682 | + * | ||
683 | + * @param newAttrInfo java attribute info | ||
684 | + */ | ||
685 | + public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { | ||
686 | + | ||
687 | + this.newAttrInfo = newAttrInfo; | ||
688 | + } | ||
689 | + | ||
690 | + /** | ||
691 | + * Returns current YANG node. | ||
692 | + * | ||
693 | + * @return current YANG node | ||
694 | + */ | ||
695 | + public YangNode getCurYangNode() { | ||
696 | + | ||
697 | + return curYangNode; | ||
698 | + } | ||
699 | + | ||
700 | + /** | ||
701 | + * Sets current YANG node. | ||
702 | + * | ||
703 | + * @param curYangNode YANG node | ||
704 | + */ | ||
705 | + public void setCurYangNode(YangNode curYangNode) { | ||
706 | + | ||
707 | + this.curYangNode = curYangNode; | ||
708 | + } | ||
709 | + | ||
710 | + /** | ||
455 | * Adds attribute for class. | 711 | * Adds attribute for class. |
456 | * | 712 | * |
457 | * @param attr attribute info | 713 | * @param attr attribute info |
... | @@ -459,7 +715,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -459,7 +715,7 @@ public class TempJavaCodeFragmentFiles { |
459 | */ | 715 | */ |
460 | public void addAttribute(JavaAttributeInfo attr) throws IOException { | 716 | public void addAttribute(JavaAttributeInfo attr) throws IOException { |
461 | 717 | ||
462 | - appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + UtilConstants.FOUR_SPACE_INDENTATION); | 718 | + appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); |
463 | } | 719 | } |
464 | 720 | ||
465 | /** | 721 | /** |
... | @@ -470,20 +726,24 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -470,20 +726,24 @@ public class TempJavaCodeFragmentFiles { |
470 | */ | 726 | */ |
471 | public void addGetterForInterface(JavaAttributeInfo attr) throws IOException { | 727 | public void addGetterForInterface(JavaAttributeInfo attr) throws IOException { |
472 | 728 | ||
473 | - appendToFile(getGetterInterfaceTempFileHandle(), | 729 | + appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE); |
474 | - getGetterString(attr) + UtilConstants.NEW_LINE); | ||
475 | } | 730 | } |
476 | 731 | ||
477 | /** | 732 | /** |
478 | * Adds getter method's impl for class. | 733 | * Adds getter method's impl for class. |
479 | * | 734 | * |
480 | * @param attr attribute info | 735 | * @param attr attribute info |
736 | + * @param genFiletype generated file type | ||
481 | * @throws IOException when fails to append to temporary file | 737 | * @throws IOException when fails to append to temporary file |
482 | */ | 738 | */ |
483 | - public void addGetterImpl(JavaAttributeInfo attr) throws IOException { | 739 | + public void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException { |
484 | 740 | ||
485 | - appendToFile(getGetterImplTempFileHandle(), | 741 | + if ((genFiletype & BUILDER_CLASS_MASK) != 0) { |
486 | - getOverRideString() + getGetterForClass(attr) + UtilConstants.NEW_LINE); | 742 | + appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE); |
743 | + } else { | ||
744 | + appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false) | ||
745 | + + getGetterForClass(attr) + NEW_LINE); | ||
746 | + } | ||
487 | } | 747 | } |
488 | 748 | ||
489 | /** | 749 | /** |
... | @@ -495,7 +755,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -495,7 +755,7 @@ public class TempJavaCodeFragmentFiles { |
495 | public void addSetterForInterface(JavaAttributeInfo attr) throws IOException { | 755 | public void addSetterForInterface(JavaAttributeInfo attr) throws IOException { |
496 | 756 | ||
497 | appendToFile(getSetterInterfaceTempFileHandle(), | 757 | appendToFile(getSetterInterfaceTempFileHandle(), |
498 | - getSetterString(attr, generatedJavaClassName) + UtilConstants.NEW_LINE); | 758 | + getSetterString(attr, generatedJavaClassName) + NEW_LINE); |
499 | } | 759 | } |
500 | 760 | ||
501 | /** | 761 | /** |
... | @@ -507,7 +767,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -507,7 +767,7 @@ public class TempJavaCodeFragmentFiles { |
507 | public void addSetterImpl(JavaAttributeInfo attr) throws IOException { | 767 | public void addSetterImpl(JavaAttributeInfo attr) throws IOException { |
508 | 768 | ||
509 | appendToFile(getSetterImplTempFileHandle(), | 769 | appendToFile(getSetterImplTempFileHandle(), |
510 | - getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + UtilConstants.NEW_LINE); | 770 | + getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE); |
511 | } | 771 | } |
512 | 772 | ||
513 | /** | 773 | /** |
... | @@ -529,7 +789,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -529,7 +789,7 @@ public class TempJavaCodeFragmentFiles { |
529 | */ | 789 | */ |
530 | public String addBuildMethodImpl() throws IOException { | 790 | public String addBuildMethodImpl() throws IOException { |
531 | 791 | ||
532 | - return getBuildString(generatedJavaClassName) + UtilConstants.NEW_LINE; | 792 | + return getBuildString(generatedJavaClassName) + NEW_LINE; |
533 | } | 793 | } |
534 | 794 | ||
535 | /** | 795 | /** |
... | @@ -546,13 +806,50 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -546,13 +806,50 @@ public class TempJavaCodeFragmentFiles { |
546 | /** | 806 | /** |
547 | * Adds default constructor for class. | 807 | * Adds default constructor for class. |
548 | * | 808 | * |
809 | + * @param modifier modifier for constructor. | ||
810 | + * @param toAppend string which need to be appended with the class name | ||
811 | + * @return default constructor for class | ||
812 | + * @throws IOException when fails to append to file | ||
813 | + */ | ||
814 | + public String addDefaultConstructor(String modifier, String toAppend) throws IOException { | ||
815 | + | ||
816 | + return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier); | ||
817 | + } | ||
818 | + | ||
819 | + /** | ||
820 | + * Adds typedef constructor for class. | ||
821 | + * | ||
822 | + * @return typedef constructor for class | ||
823 | + * @throws IOException when fails to append to file | ||
824 | + */ | ||
825 | + public String addTypeDefConstructor() throws IOException { | ||
826 | + | ||
827 | + return NEW_LINE + getJavaDoc(TYPE_DEF_CONSTRUCTOR, generatedJavaClassName, false) | ||
828 | + + getTypeDefConstructor(newAttrInfo, generatedJavaClassName) + NEW_LINE; | ||
829 | + } | ||
830 | + | ||
831 | + /** | ||
832 | + * Adds default constructor for class. | ||
833 | + * | ||
834 | + * @return default constructor for class | ||
835 | + * @throws IOException when fails to append to file | ||
836 | + */ | ||
837 | + public String addTypeDefsSetter() throws IOException { | ||
838 | + | ||
839 | + return getJavaDoc(TYPE_DEF_SETTER_METHOD, generatedJavaClassName, false) + getSetterForTypeDefClass(newAttrInfo) | ||
840 | + + NEW_LINE; | ||
841 | + } | ||
842 | + | ||
843 | + /** | ||
844 | + * Adds default constructor for class. | ||
845 | + * | ||
549 | * @return default constructor for class | 846 | * @return default constructor for class |
550 | * @throws IOException when fails to append to file | 847 | * @throws IOException when fails to append to file |
551 | */ | 848 | */ |
552 | - public String addDefaultConstructor() throws IOException { | 849 | + public String addOfMethod() throws IOException { |
553 | 850 | ||
554 | - return UtilConstants.NEW_LINE + getDefaultConstructorString(generatedJavaClassName + UtilConstants.BUILDER, | 851 | + return JavaDocGen.getJavaDoc(JavaDocType.OF_METHOD, generatedJavaClassName, false) |
555 | - UtilConstants.PUBLIC); | 852 | + + getOfMethod(generatedJavaClassName, newAttrInfo); |
556 | } | 853 | } |
557 | 854 | ||
558 | /** | 855 | /** |
... | @@ -563,7 +860,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -563,7 +860,7 @@ public class TempJavaCodeFragmentFiles { |
563 | */ | 860 | */ |
564 | public void addHashCodeMethod(JavaAttributeInfo attr) throws IOException { | 861 | public void addHashCodeMethod(JavaAttributeInfo attr) throws IOException { |
565 | 862 | ||
566 | - appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + UtilConstants.NEW_LINE); | 863 | + appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
567 | } | 864 | } |
568 | 865 | ||
569 | /** | 866 | /** |
... | @@ -574,7 +871,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -574,7 +871,7 @@ public class TempJavaCodeFragmentFiles { |
574 | */ | 871 | */ |
575 | public void addEqualsMethod(JavaAttributeInfo attr) throws IOException { | 872 | public void addEqualsMethod(JavaAttributeInfo attr) throws IOException { |
576 | 873 | ||
577 | - appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + UtilConstants.NEW_LINE); | 874 | + appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
578 | } | 875 | } |
579 | 876 | ||
580 | /** | 877 | /** |
... | @@ -585,7 +882,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -585,7 +882,7 @@ public class TempJavaCodeFragmentFiles { |
585 | */ | 882 | */ |
586 | public void addToStringMethod(JavaAttributeInfo attr) throws IOException { | 883 | public void addToStringMethod(JavaAttributeInfo attr) throws IOException { |
587 | 884 | ||
588 | - appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + UtilConstants.NEW_LINE); | 885 | + appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
589 | } | 886 | } |
590 | 887 | ||
591 | /** | 888 | /** |
... | @@ -614,6 +911,20 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -614,6 +911,20 @@ public class TempJavaCodeFragmentFiles { |
614 | } | 911 | } |
615 | 912 | ||
616 | /** | 913 | /** |
914 | + * Returns a temporary file handle for the specific file type. | ||
915 | + * | ||
916 | + * @param fileName file name | ||
917 | + * @return temporary file handle | ||
918 | + * @throws IOException when fails to create new file handle | ||
919 | + */ | ||
920 | + private File getJavaFileHandle(String fileName) throws IOException { | ||
921 | + | ||
922 | + createPackage(absoluteDirPath, getJavaFileInfo().getJavaName()); | ||
923 | + | ||
924 | + return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); | ||
925 | + } | ||
926 | + | ||
927 | + /** | ||
617 | * Returns data from the temporary files. | 928 | * Returns data from the temporary files. |
618 | * | 929 | * |
619 | * @param file temporary file handle | 930 | * @param file temporary file handle |
... | @@ -624,11 +935,10 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -624,11 +935,10 @@ public class TempJavaCodeFragmentFiles { |
624 | 935 | ||
625 | String path = getTempDirPath(); | 936 | String path = getTempDirPath(); |
626 | if (new File(path + file.getName()).exists()) { | 937 | if (new File(path + file.getName()).exists()) { |
627 | - return FileSystemUtil.readAppendFile(path + file.getName(), UtilConstants.EMPTY_STRING); | 938 | + return FileSystemUtil.readAppendFile(path + file.getName(), EMPTY_STRING); |
628 | } else { | 939 | } else { |
629 | throw new IOException("Unable to get data from the given " | 940 | throw new IOException("Unable to get data from the given " |
630 | - + file.getName() + " file for " | 941 | + + file.getName() + " file for " + generatedJavaClassName + PERIOD); |
631 | - + generatedJavaClassName + UtilConstants.PERIOD); | ||
632 | } | 942 | } |
633 | } | 943 | } |
634 | 944 | ||
... | @@ -639,8 +949,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -639,8 +949,8 @@ public class TempJavaCodeFragmentFiles { |
639 | */ | 949 | */ |
640 | private String getTempDirPath() { | 950 | private String getTempDirPath() { |
641 | 951 | ||
642 | - return absoluteDirPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH) | 952 | + return absoluteDirPath.replace(PERIOD, UtilConstants.SLASH) |
643 | - + File.separator + generatedJavaClassName + TEMP_FOLDER_NAME_SUFIX + File.separator; | 953 | + + SLASH + generatedJavaClassName + TEMP_FOLDER_NAME_SUFIX + SLASH; |
644 | } | 954 | } |
645 | 955 | ||
646 | /** | 956 | /** |
... | @@ -654,7 +964,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -654,7 +964,8 @@ public class TempJavaCodeFragmentFiles { |
654 | /* | 964 | /* |
655 | * TODO: check if this utility needs to be called or move to the caller | 965 | * TODO: check if this utility needs to be called or move to the caller |
656 | */ | 966 | */ |
657 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 967 | + String attributeName = JavaIdentifierSyntax |
968 | + .getCamelCase(JavaIdentifierSyntax.getLowerCase(attr.getAttributeName())); | ||
658 | if (attr.isQualifiedName()) { | 969 | if (attr.isQualifiedName()) { |
659 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), | 970 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), |
660 | attributeName, attr.isListAttr()); | 971 | attributeName, attr.isListAttr()); |
... | @@ -674,7 +985,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -674,7 +985,7 @@ public class TempJavaCodeFragmentFiles { |
674 | private void appendToFile(File file, String data) throws IOException { | 985 | private void appendToFile(File file, String data) throws IOException { |
675 | 986 | ||
676 | try { | 987 | try { |
677 | - JavaFileGenerator.insert(file, data); | 988 | + insertDataIntoJavaFile(file, data); |
678 | } catch (IOException ex) { | 989 | } catch (IOException ex) { |
679 | throw new IOException("failed to write in temp file."); | 990 | throw new IOException("failed to write in temp file."); |
680 | } | 991 | } |
... | @@ -778,6 +1089,20 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -778,6 +1089,20 @@ public class TempJavaCodeFragmentFiles { |
778 | } | 1089 | } |
779 | 1090 | ||
780 | /** | 1091 | /** |
1092 | + * Adds leaf attributes in generated files. | ||
1093 | + * | ||
1094 | + * @param curNode current data model node | ||
1095 | + * @throws IOException IO operation fail | ||
1096 | + */ | ||
1097 | + public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException { | ||
1098 | + | ||
1099 | + JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode, | ||
1100 | + ((YangTypeDef) curNode).getDerivedType().getDataTypeExtendedInfo().getBaseType(), | ||
1101 | + ((YangTypeDef) curNode).getName(), false); | ||
1102 | + addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | ||
1103 | + } | ||
1104 | + | ||
1105 | + /** | ||
781 | * Add the new attribute info to the target generated temporary files. | 1106 | * Add the new attribute info to the target generated temporary files. |
782 | * | 1107 | * |
783 | * @param newAttrInfo the attribute info that needs to be added to temporary | 1108 | * @param newAttrInfo the attribute info that needs to be added to temporary |
... | @@ -787,6 +1112,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -787,6 +1112,7 @@ public class TempJavaCodeFragmentFiles { |
787 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) | 1112 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
788 | throws IOException { | 1113 | throws IOException { |
789 | 1114 | ||
1115 | + setNewAttrInfo(newAttrInfo); | ||
790 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | 1116 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
791 | addAttribute(newAttrInfo); | 1117 | addAttribute(newAttrInfo); |
792 | } | 1118 | } |
... | @@ -800,7 +1126,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -800,7 +1126,7 @@ public class TempJavaCodeFragmentFiles { |
800 | } | 1126 | } |
801 | 1127 | ||
802 | if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { | 1128 | if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { |
803 | - addGetterImpl(newAttrInfo); | 1129 | + addGetterImpl(newAttrInfo, generatedJavaFiles); |
804 | } | 1130 | } |
805 | 1131 | ||
806 | if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { | 1132 | if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { |
... | @@ -826,11 +1152,134 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -826,11 +1152,134 @@ public class TempJavaCodeFragmentFiles { |
826 | } | 1152 | } |
827 | 1153 | ||
828 | /** | 1154 | /** |
1155 | + * Return java file info. | ||
1156 | + * | ||
1157 | + * @return java file info | ||
1158 | + */ | ||
1159 | + private JavaFileInfo getJavaFileInfo() { | ||
1160 | + | ||
1161 | + return ((HasJavaFileInfo) getCurYangNode()).getJavaFileInfo(); | ||
1162 | + } | ||
1163 | + | ||
1164 | + /** | ||
1165 | + * Returns java class name. | ||
1166 | + * | ||
1167 | + * @param suffix for the class name based on the file type | ||
1168 | + * @return java class name | ||
1169 | + */ | ||
1170 | + private String getJavaClassName(String suffix) { | ||
1171 | + | ||
1172 | + return JavaIdentifierSyntax.getCaptialCase(getJavaFileInfo().getJavaName()) + suffix; | ||
1173 | + } | ||
1174 | + | ||
1175 | + /** | ||
1176 | + * Returns the directory path. | ||
1177 | + * | ||
1178 | + * @return directory path | ||
1179 | + */ | ||
1180 | + private String getDirPath() { | ||
1181 | + | ||
1182 | + return getJavaFileInfo().getPackageFilePath(); | ||
1183 | + } | ||
1184 | + | ||
1185 | + /** | ||
1186 | + * Construct java code exit. | ||
1187 | + * | ||
1188 | + * @param fileType generated file type | ||
1189 | + * @param curNode current YANG node | ||
1190 | + * @throws IOException when fails to generate java files | ||
1191 | + */ | ||
1192 | + public void generateJavaFile(int fileType, YangNode curNode) throws IOException { | ||
1193 | + | ||
1194 | + setCurYangNode(curNode); | ||
1195 | + List<String> imports = new ArrayList<>(); | ||
1196 | + if (curNode instanceof HasJavaImportData) { | ||
1197 | + imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); | ||
1198 | + } | ||
1199 | + /** | ||
1200 | + * Start generation of files. | ||
1201 | + */ | ||
1202 | + if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0 | ||
1203 | + | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
1204 | + | ||
1205 | + /** | ||
1206 | + * Create interface file. | ||
1207 | + */ | ||
1208 | + setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); | ||
1209 | + setInterfaceJavaFileHandle(generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode)); | ||
1210 | + /** | ||
1211 | + * Create builder interface file. | ||
1212 | + */ | ||
1213 | + setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); | ||
1214 | + setBuilderInterfaceJavaFileHandle( | ||
1215 | + generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode)); | ||
1216 | + /** | ||
1217 | + * Append builder interface file to interface file and close it. | ||
1218 | + */ | ||
1219 | + mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); | ||
1220 | + insertDataIntoJavaFile(getInterfaceJavaFileHandle(), JavaCodeSnippetGen.getJavaClassDefClose()); | ||
1221 | + | ||
1222 | + } | ||
1223 | + | ||
1224 | + if (curNode instanceof HasJavaImportData) { | ||
1225 | + imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals()); | ||
1226 | + imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString()); | ||
1227 | + java.util.Collections.sort(imports); | ||
1228 | + } | ||
1229 | + | ||
1230 | + if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0 | ||
1231 | + | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
1232 | + | ||
1233 | + /** | ||
1234 | + * Create builder class file. | ||
1235 | + */ | ||
1236 | + setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); | ||
1237 | + setBuilderClassJavaFileHandle(generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode)); | ||
1238 | + /** | ||
1239 | + * Create impl class file. | ||
1240 | + */ | ||
1241 | + setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); | ||
1242 | + setImplClassJavaFileHandle(generateImplClassFile(getImplClassJavaFileHandle(), curNode)); | ||
1243 | + /** | ||
1244 | + * Append impl class to builder class and close it. | ||
1245 | + */ | ||
1246 | + mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); | ||
1247 | + insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), JavaCodeSnippetGen.getJavaClassDefClose()); | ||
1248 | + | ||
1249 | + } | ||
1250 | + | ||
1251 | + /** | ||
1252 | + * Creates type def class file. | ||
1253 | + */ | ||
1254 | + if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { | ||
1255 | + setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX))); | ||
1256 | + setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports)); | ||
1257 | + } | ||
1258 | + | ||
1259 | + /** | ||
1260 | + * Close all the file handles. | ||
1261 | + */ | ||
1262 | + close(); | ||
1263 | + } | ||
1264 | + | ||
1265 | + /** | ||
829 | * Removes all temporary file handles. | 1266 | * Removes all temporary file handles. |
830 | * | 1267 | * |
831 | * @throws IOException when failed to delete the temporary files | 1268 | * @throws IOException when failed to delete the temporary files |
832 | */ | 1269 | */ |
833 | - public void close() throws IOException { | 1270 | + private void close() throws IOException { |
1271 | + | ||
1272 | + closeFile(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)); | ||
1273 | + | ||
1274 | + closeFile(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)); | ||
1275 | + getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)).delete(); | ||
1276 | + | ||
1277 | + closeFile(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)); | ||
1278 | + | ||
1279 | + closeFile(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)); | ||
1280 | + getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)).delete(); | ||
1281 | + | ||
1282 | + closeFile(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)); | ||
834 | 1283 | ||
835 | closeFile(GETTER_METHOD_FILE_NAME); | 1284 | closeFile(GETTER_METHOD_FILE_NAME); |
836 | getTemporaryFileHandle(GETTER_METHOD_FILE_NAME).delete(); | 1285 | getTemporaryFileHandle(GETTER_METHOD_FILE_NAME).delete(); |
... | @@ -859,6 +1308,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -859,6 +1308,7 @@ public class TempJavaCodeFragmentFiles { |
859 | closeFile(EQUALS_METHOD_FILE_NAME); | 1308 | closeFile(EQUALS_METHOD_FILE_NAME); |
860 | getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME).delete(); | 1309 | getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME).delete(); |
861 | 1310 | ||
1311 | + clean(getTempDirPath()); | ||
862 | } | 1312 | } |
863 | 1313 | ||
864 | /** | 1314 | /** | ... | ... |
... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | 28 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
35 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 34 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
37 | 35 | ||
38 | /** | 36 | /** |
... | @@ -162,7 +160,7 @@ public class YangJavaContainer extends YangContainer | ... | @@ -162,7 +160,7 @@ public class YangJavaContainer extends YangContainer |
162 | String absloutePath = getAbsolutePackagePath( | 160 | String absloutePath = getAbsolutePackagePath( |
163 | getJavaFileInfo().getBaseCodeGenPath(), | 161 | getJavaFileInfo().getBaseCodeGenPath(), |
164 | getJavaFileInfo().getPackageFilePath()); | 162 | getJavaFileInfo().getPackageFilePath()); |
165 | - createPackage(absloutePath, getName()); | 163 | + |
166 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | 164 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( |
167 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | 165 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, |
168 | getJavaFileInfo().getJavaName())); | 166 | getJavaFileInfo().getJavaName())); |
... | @@ -180,8 +178,8 @@ public class YangJavaContainer extends YangContainer | ... | @@ -180,8 +178,8 @@ public class YangJavaContainer extends YangContainer |
180 | @Override | 178 | @Override |
181 | public void generateCodeExit() throws IOException { | 179 | public void generateCodeExit() throws IOException { |
182 | 180 | ||
183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 181 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
184 | - getTempJavaCodeFragmentFiles().close(); | 182 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 183 | } |
186 | 184 | ||
187 | } | 185 | } | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | + | ||
20 | import org.onosproject.yangutils.datamodel.YangInput; | 21 | import org.onosproject.yangutils.datamodel.YangInput; |
21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | 29 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
... | @@ -180,7 +180,7 @@ public class YangJavaInput extends YangInput | ... | @@ -180,7 +180,7 @@ public class YangJavaInput extends YangInput |
180 | @Override | 180 | @Override |
181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
182 | 182 | ||
183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
184 | - getTempJavaCodeFragmentFiles().close(); | 184 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 185 | } |
186 | } | 186 | } | ... | ... |
... | @@ -27,7 +27,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +27,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | 28 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
... | @@ -155,9 +154,11 @@ public class YangJavaList extends YangList | ... | @@ -155,9 +154,11 @@ public class YangJavaList extends YangList |
155 | 154 | ||
156 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 155 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
157 | getJavaFileInfo().setPackage(getCurNodePackage(this)); | 156 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
157 | + | ||
158 | getJavaFileInfo().setPackageFilePath( | 158 | getJavaFileInfo().setPackageFilePath( |
159 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | 159 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
160 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | 160 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); |
161 | + | ||
161 | String absloutePath = getAbsolutePackagePath( | 162 | String absloutePath = getAbsolutePackagePath( |
162 | getJavaFileInfo().getBaseCodeGenPath(), | 163 | getJavaFileInfo().getBaseCodeGenPath(), |
163 | getJavaFileInfo().getPackageFilePath()); | 164 | getJavaFileInfo().getPackageFilePath()); |
... | @@ -180,7 +181,7 @@ public class YangJavaList extends YangList | ... | @@ -180,7 +181,7 @@ public class YangJavaList extends YangList |
180 | @Override | 181 | @Override |
181 | public void generateCodeExit() throws IOException { | 182 | public void generateCodeExit() throws IOException { |
182 | 183 | ||
183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 184 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
184 | - getTempJavaCodeFragmentFiles().close(); | 185 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 186 | } |
186 | } | 187 | } | ... | ... |
... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | 28 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
35 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 34 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
37 | 35 | ||
38 | /** | 36 | /** |
... | @@ -163,7 +161,6 @@ public class YangJavaModule extends YangModule | ... | @@ -163,7 +161,6 @@ public class YangJavaModule extends YangModule |
163 | getJavaFileInfo().getBaseCodeGenPath(), | 161 | getJavaFileInfo().getBaseCodeGenPath(), |
164 | getJavaFileInfo().getPackageFilePath()); | 162 | getJavaFileInfo().getPackageFilePath()); |
165 | 163 | ||
166 | - createPackage(absloutePath, getName()); | ||
167 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | 164 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( |
168 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | 165 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, |
169 | getJavaFileInfo().getJavaName())); | 166 | getJavaFileInfo().getJavaName())); |
... | @@ -174,8 +171,8 @@ public class YangJavaModule extends YangModule | ... | @@ -174,8 +171,8 @@ public class YangJavaModule extends YangModule |
174 | @Override | 171 | @Override |
175 | public void generateCodeExit() throws IOException { | 172 | public void generateCodeExit() throws IOException { |
176 | 173 | ||
177 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 174 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
178 | - getTempJavaCodeFragmentFiles().close(); | 175 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
179 | return; | 176 | return; |
180 | } | 177 | } |
181 | } | 178 | } | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | + | ||
20 | import org.onosproject.yangutils.datamodel.YangOutput; | 21 | import org.onosproject.yangutils.datamodel.YangOutput; |
21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
28 | 29 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
... | @@ -180,7 +180,7 @@ public class YangJavaOutput extends YangOutput | ... | @@ -180,7 +180,7 @@ public class YangJavaOutput extends YangOutput |
180 | @Override | 180 | @Override |
181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
182 | 182 | ||
183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
184 | - getTempJavaCodeFragmentFiles().close(); | 184 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 185 | } |
186 | } | 186 | } | ... | ... |
... | @@ -75,6 +75,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -75,6 +75,7 @@ public class YangJavaSubModule extends YangSubModule |
75 | */ | 75 | */ |
76 | @Override | 76 | @Override |
77 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
78 | + | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | throw new RuntimeException("Missing java info in java datamodel node"); | 80 | throw new RuntimeException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
... | @@ -88,6 +89,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -88,6 +89,7 @@ public class YangJavaSubModule extends YangSubModule |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
92 | + | ||
91 | javaFileInfo = javaInfo; | 93 | javaFileInfo = javaInfo; |
92 | } | 94 | } |
93 | 95 | ||
... | @@ -98,6 +100,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -98,6 +100,7 @@ public class YangJavaSubModule extends YangSubModule |
98 | */ | 100 | */ |
99 | @Override | 101 | @Override |
100 | public JavaImportData getJavaImportData() { | 102 | public JavaImportData getJavaImportData() { |
103 | + | ||
101 | return javaImportData; | 104 | return javaImportData; |
102 | } | 105 | } |
103 | 106 | ||
... | @@ -109,6 +112,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -109,6 +112,7 @@ public class YangJavaSubModule extends YangSubModule |
109 | */ | 112 | */ |
110 | @Override | 113 | @Override |
111 | public void setJavaImportData(JavaImportData javaImportData) { | 114 | public void setJavaImportData(JavaImportData javaImportData) { |
115 | + | ||
112 | this.javaImportData = javaImportData; | 116 | this.javaImportData = javaImportData; |
113 | } | 117 | } |
114 | 118 | ||
... | @@ -119,6 +123,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -119,6 +123,7 @@ public class YangJavaSubModule extends YangSubModule |
119 | */ | 123 | */ |
120 | @Override | 124 | @Override |
121 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 125 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
126 | + | ||
122 | if (tempFileHandle == null) { | 127 | if (tempFileHandle == null) { |
123 | throw new RuntimeException("missing temp file hand for current node " | 128 | throw new RuntimeException("missing temp file hand for current node " |
124 | + getJavaFileInfo().getJavaName()); | 129 | + getJavaFileInfo().getJavaName()); |
... | @@ -133,6 +138,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -133,6 +138,7 @@ public class YangJavaSubModule extends YangSubModule |
133 | */ | 138 | */ |
134 | @Override | 139 | @Override |
135 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 140 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
141 | + | ||
136 | tempFileHandle = fileHandle; | 142 | tempFileHandle = fileHandle; |
137 | } | 143 | } |
138 | 144 | ||
... | @@ -144,6 +150,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -144,6 +150,7 @@ public class YangJavaSubModule extends YangSubModule |
144 | * @return the name space string of the module. | 150 | * @return the name space string of the module. |
145 | */ | 151 | */ |
146 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { | 152 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { |
153 | + | ||
147 | // TODO Auto-generated method stub | 154 | // TODO Auto-generated method stub |
148 | return ""; | 155 | return ""; |
149 | } | 156 | } |
... | @@ -157,6 +164,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -157,6 +164,7 @@ public class YangJavaSubModule extends YangSubModule |
157 | */ | 164 | */ |
158 | @Override | 165 | @Override |
159 | public void generateCodeEntry(String codeGenDir) throws IOException { | 166 | public void generateCodeEntry(String codeGenDir) throws IOException { |
167 | + | ||
160 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 168 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
161 | getJavaFileInfo().setPackage(getRootPackage(getVersion(), | 169 | getJavaFileInfo().setPackage(getRootPackage(getVersion(), |
162 | getNameSpaceFromModule(getBelongsTo()), | 170 | getNameSpaceFromModule(getBelongsTo()), | ... | ... |
... | @@ -15,24 +15,29 @@ | ... | @@ -15,24 +15,29 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | +import java.io.IOException; | ||
19 | + | ||
18 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 20 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
19 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
20 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
23 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 24 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 26 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
27 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
24 | 28 | ||
25 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
26 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
27 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
34 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
30 | 35 | ||
31 | /** | 36 | /** |
32 | * Type define information extended to support java code generation. | 37 | * Type define information extended to support java code generation. |
33 | */ | 38 | */ |
34 | public class YangJavaTypeDef extends YangTypeDef | 39 | public class YangJavaTypeDef extends YangTypeDef |
35 | - implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData { | 40 | + implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData, HasTempJavaCodeFragmentFiles { |
36 | 41 | ||
37 | /** | 42 | /** |
38 | * Contains the information of the java file being generated. | 43 | * Contains the information of the java file being generated. |
... | @@ -46,13 +51,19 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -46,13 +51,19 @@ public class YangJavaTypeDef extends YangTypeDef |
46 | private JavaImportData javaImportData; | 51 | private JavaImportData javaImportData; |
47 | 52 | ||
48 | /** | 53 | /** |
54 | + * File handle to maintain temporary java code fragments as per the code | ||
55 | + * snippet types. | ||
56 | + */ | ||
57 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
58 | + | ||
59 | + /** | ||
49 | * Default constructor. | 60 | * Default constructor. |
50 | */ | 61 | */ |
51 | public YangJavaTypeDef() { | 62 | public YangJavaTypeDef() { |
52 | super(); | 63 | super(); |
53 | setJavaFileInfo(new JavaFileInfo()); | 64 | setJavaFileInfo(new JavaFileInfo()); |
54 | setJavaImportData(new JavaImportData()); | 65 | setJavaImportData(new JavaImportData()); |
55 | - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | 66 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_TYPEDEF_CLASS); |
56 | } | 67 | } |
57 | 68 | ||
58 | /** | 69 | /** |
... | @@ -62,6 +73,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -62,6 +73,7 @@ public class YangJavaTypeDef extends YangTypeDef |
62 | */ | 73 | */ |
63 | @Override | 74 | @Override |
64 | public JavaFileInfo getJavaFileInfo() { | 75 | public JavaFileInfo getJavaFileInfo() { |
76 | + | ||
65 | if (javaFileInfo == null) { | 77 | if (javaFileInfo == null) { |
66 | throw new RuntimeException("Missing java info in java datamodel node"); | 78 | throw new RuntimeException("Missing java info in java datamodel node"); |
67 | } | 79 | } |
... | @@ -75,6 +87,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -75,6 +87,7 @@ public class YangJavaTypeDef extends YangTypeDef |
75 | */ | 87 | */ |
76 | @Override | 88 | @Override |
77 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 89 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
90 | + | ||
78 | javaFileInfo = javaInfo; | 91 | javaFileInfo = javaInfo; |
79 | } | 92 | } |
80 | 93 | ||
... | @@ -85,6 +98,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -85,6 +98,7 @@ public class YangJavaTypeDef extends YangTypeDef |
85 | */ | 98 | */ |
86 | @Override | 99 | @Override |
87 | public JavaImportData getJavaImportData() { | 100 | public JavaImportData getJavaImportData() { |
101 | + | ||
88 | return javaImportData; | 102 | return javaImportData; |
89 | } | 103 | } |
90 | 104 | ||
... | @@ -96,32 +110,73 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -96,32 +110,73 @@ public class YangJavaTypeDef extends YangTypeDef |
96 | */ | 110 | */ |
97 | @Override | 111 | @Override |
98 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
113 | + | ||
99 | this.javaImportData = javaImportData; | 114 | this.javaImportData = javaImportData; |
100 | } | 115 | } |
101 | 116 | ||
102 | /** | 117 | /** |
118 | + * Get the temporary file handle. | ||
119 | + * | ||
120 | + * @return temporary file handle | ||
121 | + */ | ||
122 | + @Override | ||
123 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
124 | + | ||
125 | + if (tempFileHandle == null) { | ||
126 | + throw new RuntimeException("missing temp file hand for current node " | ||
127 | + + getJavaFileInfo().getJavaName()); | ||
128 | + } | ||
129 | + return tempFileHandle; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Set temporary file handle. | ||
134 | + * | ||
135 | + * @param fileHandle temporary file handle | ||
136 | + */ | ||
137 | + @Override | ||
138 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
139 | + | ||
140 | + tempFileHandle = fileHandle; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
103 | * Prepare the information for java code generation corresponding to YANG | 144 | * Prepare the information for java code generation corresponding to YANG |
104 | * container info. | 145 | * container info. |
105 | * | 146 | * |
106 | * @param codeGenDir code generation directory | 147 | * @param codeGenDir code generation directory |
148 | + * @throws IOException IO operations fails | ||
107 | */ | 149 | */ |
108 | @Override | 150 | @Override |
109 | - public void generateCodeEntry(String codeGenDir) { | 151 | + public void generateCodeEntry(String codeGenDir) throws IOException { |
152 | + | ||
110 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 153 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
111 | getJavaFileInfo().setPackage(getCurNodePackage(this)); | 154 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
155 | + | ||
112 | getJavaFileInfo().setPackageFilePath( | 156 | getJavaFileInfo().setPackageFilePath( |
113 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | 157 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
114 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | 158 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); |
115 | - // TODO: generate type define temporary files | 159 | + String absloutePath = getAbsolutePackagePath( |
160 | + getJavaFileInfo().getBaseCodeGenPath(), | ||
161 | + getJavaFileInfo().getPackageFilePath()); | ||
162 | + | ||
163 | + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
164 | + getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
165 | + getJavaFileInfo().getJavaName())); | ||
166 | + | ||
167 | + getTempJavaCodeFragmentFiles().addTypeDefAttributeToTempFiles(this); | ||
168 | + | ||
116 | } | 169 | } |
117 | 170 | ||
118 | /** | 171 | /** |
119 | * Create a java file using the YANG grouping info. | 172 | * Create a java file using the YANG grouping info. |
173 | + * @throws IOException IO operations fails | ||
120 | */ | 174 | */ |
121 | @Override | 175 | @Override |
122 | - public void generateCodeExit() { | 176 | + public void generateCodeExit() throws IOException { |
123 | - // TODO Auto-generated method stub | ||
124 | 177 | ||
178 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
179 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); | ||
125 | } | 180 | } |
126 | 181 | ||
127 | } | 182 | } | ... | ... |
... | @@ -22,7 +22,41 @@ import java.util.TreeSet; | ... | @@ -22,7 +22,41 @@ import java.util.TreeSet; |
22 | import org.onosproject.yangutils.datamodel.YangDataTypes; | 22 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
23 | import org.onosproject.yangutils.datamodel.YangType; | 23 | import org.onosproject.yangutils.datamodel.YangType; |
24 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 24 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
25 | -import org.onosproject.yangutils.utils.UtilConstants; | 25 | + |
26 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY; | ||
27 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS; | ||
28 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; | ||
29 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64; | ||
30 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
31 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY; | ||
32 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION; | ||
33 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF; | ||
34 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INSTANCE_IDENTIFIER; | ||
35 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16; | ||
36 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | ||
37 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64; | ||
38 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8; | ||
39 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF; | ||
40 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | ||
41 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16; | ||
42 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32; | ||
43 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64; | ||
44 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8; | ||
45 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION; | ||
46 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
47 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; | ||
50 | +import static org.onosproject.yangutils.utils.UtilConstants.BYTE; | ||
51 | +import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; | ||
52 | +import static org.onosproject.yangutils.utils.UtilConstants.INT; | ||
53 | +import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; | ||
54 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.LONG; | ||
56 | +import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; | ||
57 | +import static org.onosproject.yangutils.utils.UtilConstants.SHORT; | ||
58 | +import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; | ||
59 | +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ||
26 | 60 | ||
27 | /** | 61 | /** |
28 | * Provides java data types corresponding to YANG type. | 62 | * Provides java data types corresponding to YANG type. |
... | @@ -43,6 +77,7 @@ public final class AttributesJavaDataType { | ... | @@ -43,6 +77,7 @@ public final class AttributesJavaDataType { |
43 | * @return import info | 77 | * @return import info |
44 | */ | 78 | */ |
45 | public static Set<JavaQualifiedTypeInfo> getImportInfo() { | 79 | public static Set<JavaQualifiedTypeInfo> getImportInfo() { |
80 | + | ||
46 | return importInfo; | 81 | return importInfo; |
47 | } | 82 | } |
48 | 83 | ||
... | @@ -52,6 +87,7 @@ public final class AttributesJavaDataType { | ... | @@ -52,6 +87,7 @@ public final class AttributesJavaDataType { |
52 | * @param importData import info | 87 | * @param importData import info |
53 | */ | 88 | */ |
54 | public static void addImportInfo(JavaQualifiedTypeInfo importData) { | 89 | public static void addImportInfo(JavaQualifiedTypeInfo importData) { |
90 | + | ||
55 | getImportInfo().add(importData); | 91 | getImportInfo().add(importData); |
56 | } | 92 | } |
57 | 93 | ||
... | @@ -62,47 +98,48 @@ public final class AttributesJavaDataType { | ... | @@ -62,47 +98,48 @@ public final class AttributesJavaDataType { |
62 | * @return java type | 98 | * @return java type |
63 | */ | 99 | */ |
64 | public static String getJavaDataType(YangType<?> yangType) { | 100 | public static String getJavaDataType(YangType<?> yangType) { |
101 | + | ||
65 | YangDataTypes type = yangType.getDataType(); | 102 | YangDataTypes type = yangType.getDataType(); |
66 | 103 | ||
67 | - if (type.equals(YangDataTypes.INT8)) { | 104 | + if (type.equals(INT8)) { |
68 | - return UtilConstants.BYTE; | 105 | + return BYTE; |
69 | - } else if (type.equals(YangDataTypes.INT16)) { | 106 | + } else if (type.equals(INT16)) { |
70 | - return UtilConstants.SHORT; | 107 | + return SHORT; |
71 | - } else if (type.equals(YangDataTypes.INT32)) { | 108 | + } else if (type.equals(INT32)) { |
72 | - return UtilConstants.INT; | 109 | + return INT; |
73 | - } else if (type.equals(YangDataTypes.INT64)) { | 110 | + } else if (type.equals(INT64)) { |
74 | - return UtilConstants.LONG; | 111 | + return LONG; |
75 | - } else if (type.equals(YangDataTypes.UINT8)) { | 112 | + } else if (type.equals(UINT8)) { |
76 | - return UtilConstants.SHORT; | 113 | + return SHORT; |
77 | - } else if (type.equals(YangDataTypes.UINT16)) { | 114 | + } else if (type.equals(UINT16)) { |
78 | - return UtilConstants.INT; | 115 | + return INT; |
79 | - } else if (type.equals(YangDataTypes.UINT32)) { | 116 | + } else if (type.equals(UINT32)) { |
80 | - return UtilConstants.LONG; | 117 | + return LONG; |
81 | - } else if (type.equals(YangDataTypes.UINT64)) { | 118 | + } else if (type.equals(UINT64)) { |
82 | //TODO: BIGINTEGER. | 119 | //TODO: BIGINTEGER. |
83 | - } else if (type.equals(YangDataTypes.DECIMAL64)) { | 120 | + } else if (type.equals(DECIMAL64)) { |
84 | //TODO: DECIMAL64. | 121 | //TODO: DECIMAL64. |
85 | - } else if (type.equals(YangDataTypes.STRING)) { | 122 | + } else if (type.equals(STRING)) { |
86 | - return UtilConstants.STRING; | 123 | + return STRING_DATA_TYPE; |
87 | - } else if (type.equals(YangDataTypes.BOOLEAN)) { | 124 | + } else if (type.equals(BOOLEAN)) { |
88 | - return UtilConstants.BOOLEAN; | 125 | + return BOOLEAN_DATA_TYPE; |
89 | - } else if (type.equals(YangDataTypes.ENUMERATION)) { | 126 | + } else if (type.equals(ENUMERATION)) { |
90 | //TODO: ENUMERATION. | 127 | //TODO: ENUMERATION. |
91 | - } else if (type.equals(YangDataTypes.BITS)) { | 128 | + } else if (type.equals(BITS)) { |
92 | //TODO:BITS | 129 | //TODO:BITS |
93 | - } else if (type.equals(YangDataTypes.BINARY)) { | 130 | + } else if (type.equals(BINARY)) { |
94 | //TODO:BINARY | 131 | //TODO:BINARY |
95 | - } else if (type.equals(YangDataTypes.LEAFREF)) { | 132 | + } else if (type.equals(LEAFREF)) { |
96 | //TODO:LEAFREF | 133 | //TODO:LEAFREF |
97 | - } else if (type.equals(YangDataTypes.IDENTITYREF)) { | 134 | + } else if (type.equals(IDENTITYREF)) { |
98 | //TODO:IDENTITYREF | 135 | //TODO:IDENTITYREF |
99 | - } else if (type.equals(YangDataTypes.EMPTY)) { | 136 | + } else if (type.equals(EMPTY)) { |
100 | //TODO:EMPTY | 137 | //TODO:EMPTY |
101 | - } else if (type.equals(YangDataTypes.UNION)) { | 138 | + } else if (type.equals(UNION)) { |
102 | //TODO:UNION | 139 | //TODO:UNION |
103 | - } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | 140 | + } else if (type.equals(INSTANCE_IDENTIFIER)) { |
104 | //TODO:INSTANCE_IDENTIFIER | 141 | //TODO:INSTANCE_IDENTIFIER |
105 | - } else if (type.equals(YangDataTypes.DERIVED)) { | 142 | + } else if (type.equals(DERIVED)) { |
106 | return yangType.getDataTypeName(); | 143 | return yangType.getDataTypeName(); |
107 | } | 144 | } |
108 | return null; | 145 | return null; |
... | @@ -116,77 +153,76 @@ public final class AttributesJavaDataType { | ... | @@ -116,77 +153,76 @@ public final class AttributesJavaDataType { |
116 | * @return java import class | 153 | * @return java import class |
117 | */ | 154 | */ |
118 | public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) { | 155 | public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) { |
156 | + | ||
119 | YangDataTypes type = yangType.getDataType(); | 157 | YangDataTypes type = yangType.getDataType(); |
120 | 158 | ||
121 | if (isListAttr) { | 159 | if (isListAttr) { |
122 | - if (type.equals(YangDataTypes.INT8)) { | 160 | + if (type.equals(INT8)) { |
123 | - return UtilConstants.BYTE_WRAPPER; | 161 | + return BYTE_WRAPPER; |
124 | - } else if (type.equals(YangDataTypes.INT16)) { | 162 | + } else if (type.equals(INT16)) { |
125 | - return UtilConstants.SHORT_WRAPPER; | 163 | + return SHORT_WRAPPER; |
126 | - } else if (type.equals(YangDataTypes.INT32)) { | 164 | + } else if (type.equals(INT32)) { |
127 | - return UtilConstants.INTEGER_WRAPPER; | 165 | + return INTEGER_WRAPPER; |
128 | - } else if (type.equals(YangDataTypes.INT64)) { | 166 | + } else if (type.equals(INT64)) { |
129 | - return UtilConstants.LONG_WRAPPER; | 167 | + return LONG_WRAPPER; |
130 | - } else if (type.equals(YangDataTypes.UINT8)) { | 168 | + } else if (type.equals(UINT8)) { |
131 | - return UtilConstants.SHORT_WRAPPER; | 169 | + return SHORT_WRAPPER; |
132 | - } else if (type.equals(YangDataTypes.UINT16)) { | 170 | + } else if (type.equals(UINT16)) { |
133 | - return UtilConstants.INTEGER_WRAPPER; | 171 | + return INTEGER_WRAPPER; |
134 | - } else if (type.equals(YangDataTypes.UINT32)) { | 172 | + } else if (type.equals(UINT32)) { |
135 | - return UtilConstants.LONG_WRAPPER; | 173 | + return LONG_WRAPPER; |
136 | - } else if (type.equals(YangDataTypes.UINT64)) { | 174 | + } else if (type.equals(UINT64)) { |
137 | //TODO: BIGINTEGER. | 175 | //TODO: BIGINTEGER. |
138 | - } else if (type.equals(YangDataTypes.DECIMAL64)) { | 176 | + } else if (type.equals(DECIMAL64)) { |
139 | //TODO: DECIMAL64. | 177 | //TODO: DECIMAL64. |
140 | - } else if (type.equals(YangDataTypes.STRING)) { | 178 | + } else if (type.equals(STRING)) { |
141 | - return UtilConstants.STRING; | 179 | + return STRING_DATA_TYPE; |
142 | - } else if (type.equals(YangDataTypes.BOOLEAN)) { | 180 | + } else if (type.equals(BOOLEAN)) { |
143 | - return UtilConstants.BOOLEAN_WRAPPER; | 181 | + return BOOLEAN_WRAPPER; |
144 | - } else if (type.equals(YangDataTypes.ENUMERATION)) { | 182 | + } else if (type.equals(ENUMERATION)) { |
145 | //TODO: ENUMERATION. | 183 | //TODO: ENUMERATION. |
146 | - } else if (type.equals(YangDataTypes.BITS)) { | 184 | + } else if (type.equals(BITS)) { |
147 | //TODO:BITS | 185 | //TODO:BITS |
148 | - } else if (type.equals(YangDataTypes.BINARY)) { | 186 | + } else if (type.equals(BINARY)) { |
149 | //TODO:BINARY | 187 | //TODO:BINARY |
150 | - } else if (type.equals(YangDataTypes.LEAFREF)) { | 188 | + } else if (type.equals(LEAFREF)) { |
151 | //TODO:LEAFREF | 189 | //TODO:LEAFREF |
152 | - } else if (type.equals(YangDataTypes.IDENTITYREF)) { | 190 | + } else if (type.equals(IDENTITYREF)) { |
153 | //TODO:IDENTITYREF | 191 | //TODO:IDENTITYREF |
154 | - } else if (type.equals(YangDataTypes.EMPTY)) { | 192 | + } else if (type.equals(EMPTY)) { |
155 | //TODO:EMPTY | 193 | //TODO:EMPTY |
156 | - } else if (type.equals(YangDataTypes.UNION)) { | 194 | + } else if (type.equals(UNION)) { |
157 | //TODO:UNION | 195 | //TODO:UNION |
158 | - } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | 196 | + } else if (type.equals(INSTANCE_IDENTIFIER)) { |
159 | //TODO:INSTANCE_IDENTIFIER | 197 | //TODO:INSTANCE_IDENTIFIER |
160 | - } else if (type.equals(YangDataTypes.DERIVED)) { | 198 | + } else if (type.equals(DERIVED)) { |
161 | - return JavaIdentifierSyntax | 199 | + return getCaptialCase(getCamelCase(yangType.getDataTypeName())); |
162 | - .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName())); | ||
163 | } | 200 | } |
164 | } else { | 201 | } else { |
165 | - if (type.equals(YangDataTypes.UINT64)) { | 202 | + if (type.equals(UINT64)) { |
166 | //TODO: BIGINTEGER. | 203 | //TODO: BIGINTEGER. |
167 | - } else if (type.equals(YangDataTypes.DECIMAL64)) { | 204 | + } else if (type.equals(DECIMAL64)) { |
168 | //TODO: DECIMAL64. | 205 | //TODO: DECIMAL64. |
169 | - } else if (type.equals(YangDataTypes.STRING)) { | 206 | + } else if (type.equals(STRING)) { |
170 | - return UtilConstants.STRING; | 207 | + return STRING_DATA_TYPE; |
171 | - } else if (type.equals(YangDataTypes.ENUMERATION)) { | 208 | + } else if (type.equals(ENUMERATION)) { |
172 | //TODO: ENUMERATION. | 209 | //TODO: ENUMERATION. |
173 | - } else if (type.equals(YangDataTypes.BITS)) { | 210 | + } else if (type.equals(BITS)) { |
174 | //TODO:BITS | 211 | //TODO:BITS |
175 | - } else if (type.equals(YangDataTypes.BINARY)) { | 212 | + } else if (type.equals(BINARY)) { |
176 | //TODO:BINARY | 213 | //TODO:BINARY |
177 | - } else if (type.equals(YangDataTypes.LEAFREF)) { | 214 | + } else if (type.equals(LEAFREF)) { |
178 | //TODO:LEAFREF | 215 | //TODO:LEAFREF |
179 | - } else if (type.equals(YangDataTypes.IDENTITYREF)) { | 216 | + } else if (type.equals(IDENTITYREF)) { |
180 | //TODO:IDENTITYREF | 217 | //TODO:IDENTITYREF |
181 | - } else if (type.equals(YangDataTypes.EMPTY)) { | 218 | + } else if (type.equals(EMPTY)) { |
182 | //TODO:EMPTY | 219 | //TODO:EMPTY |
183 | - } else if (type.equals(YangDataTypes.UNION)) { | 220 | + } else if (type.equals(UNION)) { |
184 | //TODO:UNION | 221 | //TODO:UNION |
185 | - } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | 222 | + } else if (type.equals(INSTANCE_IDENTIFIER)) { |
186 | //TODO:INSTANCE_IDENTIFIER | 223 | //TODO:INSTANCE_IDENTIFIER |
187 | - } else if (type.equals(YangDataTypes.DERIVED)) { | 224 | + } else if (type.equals(DERIVED)) { |
188 | - return JavaIdentifierSyntax | 225 | + return getCaptialCase(getCamelCase(yangType.getDataTypeName())); |
189 | - .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName())); | ||
190 | } | 226 | } |
191 | } | 227 | } |
192 | return null; | 228 | return null; |
... | @@ -201,40 +237,41 @@ public final class AttributesJavaDataType { | ... | @@ -201,40 +237,41 @@ public final class AttributesJavaDataType { |
201 | * @return java import package | 237 | * @return java import package |
202 | */ | 238 | */ |
203 | public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { | 239 | public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { |
240 | + | ||
204 | YangDataTypes type = yangType.getDataType(); | 241 | YangDataTypes type = yangType.getDataType(); |
205 | 242 | ||
206 | if (isListAttr) { | 243 | if (isListAttr) { |
207 | - if (type.equals(YangDataTypes.INT8) | 244 | + if (type.equals(INT8) |
208 | - || type.equals(YangDataTypes.INT16) | 245 | + || type.equals(INT16) |
209 | - || type.equals(YangDataTypes.INT32) | 246 | + || type.equals(INT32) |
210 | - || type.equals(YangDataTypes.INT64) | 247 | + || type.equals(INT64) |
211 | - || type.equals(YangDataTypes.UINT8) | 248 | + || type.equals(UINT8) |
212 | - || type.equals(YangDataTypes.UINT16) | 249 | + || type.equals(UINT16) |
213 | - || type.equals(YangDataTypes.UINT32) | 250 | + || type.equals(UINT32) |
214 | - || type.equals(YangDataTypes.STRING) | 251 | + || type.equals(STRING) |
215 | - || type.equals(YangDataTypes.BOOLEAN)) { | 252 | + || type.equals(BOOLEAN)) { |
216 | - return UtilConstants.JAVA_LANG; | 253 | + return JAVA_LANG; |
217 | - } else if (type.equals(YangDataTypes.UINT64)) { | 254 | + } else if (type.equals(UINT64)) { |
218 | //TODO: BIGINTEGER. | 255 | //TODO: BIGINTEGER. |
219 | - } else if (type.equals(YangDataTypes.DECIMAL64)) { | 256 | + } else if (type.equals(DECIMAL64)) { |
220 | //TODO: DECIMAL64. | 257 | //TODO: DECIMAL64. |
221 | - } else if (type.equals(YangDataTypes.ENUMERATION)) { | 258 | + } else if (type.equals(ENUMERATION)) { |
222 | //TODO: ENUMERATION. | 259 | //TODO: ENUMERATION. |
223 | - } else if (type.equals(YangDataTypes.BITS)) { | 260 | + } else if (type.equals(BITS)) { |
224 | //TODO:BITS | 261 | //TODO:BITS |
225 | - } else if (type.equals(YangDataTypes.BINARY)) { | 262 | + } else if (type.equals(BINARY)) { |
226 | //TODO:BINARY | 263 | //TODO:BINARY |
227 | - } else if (type.equals(YangDataTypes.LEAFREF)) { | 264 | + } else if (type.equals(LEAFREF)) { |
228 | //TODO:LEAFREF | 265 | //TODO:LEAFREF |
229 | - } else if (type.equals(YangDataTypes.IDENTITYREF)) { | 266 | + } else if (type.equals(IDENTITYREF)) { |
230 | //TODO:IDENTITYREF | 267 | //TODO:IDENTITYREF |
231 | - } else if (type.equals(YangDataTypes.EMPTY)) { | 268 | + } else if (type.equals(EMPTY)) { |
232 | //TODO:EMPTY | 269 | //TODO:EMPTY |
233 | - } else if (type.equals(YangDataTypes.UNION)) { | 270 | + } else if (type.equals(UNION)) { |
234 | //TODO:UNION | 271 | //TODO:UNION |
235 | - } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | 272 | + } else if (type.equals(INSTANCE_IDENTIFIER)) { |
236 | //TODO:INSTANCE_IDENTIFIER | 273 | //TODO:INSTANCE_IDENTIFIER |
237 | - } else if (type.equals(YangDataTypes.DERIVED)) { | 274 | + } else if (type.equals(DERIVED)) { |
238 | for (JavaQualifiedTypeInfo imports : getImportInfo()) { | 275 | for (JavaQualifiedTypeInfo imports : getImportInfo()) { |
239 | if (imports.getClassInfo().equals(classInfo)) { | 276 | if (imports.getClassInfo().equals(classInfo)) { |
240 | return imports.getPkgInfo(); | 277 | return imports.getPkgInfo(); |
... | @@ -243,29 +280,29 @@ public final class AttributesJavaDataType { | ... | @@ -243,29 +280,29 @@ public final class AttributesJavaDataType { |
243 | } | 280 | } |
244 | } else { | 281 | } else { |
245 | 282 | ||
246 | - if (type.equals(YangDataTypes.UINT64)) { | 283 | + if (type.equals(UINT64)) { |
247 | //TODO: BIGINTEGER. | 284 | //TODO: BIGINTEGER. |
248 | - } else if (type.equals(YangDataTypes.DECIMAL64)) { | 285 | + } else if (type.equals(DECIMAL64)) { |
249 | //TODO: DECIMAL64. | 286 | //TODO: DECIMAL64. |
250 | - } else if (type.equals(YangDataTypes.STRING)) { | 287 | + } else if (type.equals(STRING)) { |
251 | - return UtilConstants.JAVA_LANG; | 288 | + return JAVA_LANG; |
252 | - } else if (type.equals(YangDataTypes.ENUMERATION)) { | 289 | + } else if (type.equals(ENUMERATION)) { |
253 | //TODO: ENUMERATION. | 290 | //TODO: ENUMERATION. |
254 | - } else if (type.equals(YangDataTypes.BITS)) { | 291 | + } else if (type.equals(BITS)) { |
255 | //TODO:BITS | 292 | //TODO:BITS |
256 | - } else if (type.equals(YangDataTypes.BINARY)) { | 293 | + } else if (type.equals(BINARY)) { |
257 | //TODO:BINARY | 294 | //TODO:BINARY |
258 | - } else if (type.equals(YangDataTypes.LEAFREF)) { | 295 | + } else if (type.equals(LEAFREF)) { |
259 | //TODO:LEAFREF | 296 | //TODO:LEAFREF |
260 | - } else if (type.equals(YangDataTypes.IDENTITYREF)) { | 297 | + } else if (type.equals(IDENTITYREF)) { |
261 | //TODO:IDENTITYREF | 298 | //TODO:IDENTITYREF |
262 | - } else if (type.equals(YangDataTypes.EMPTY)) { | 299 | + } else if (type.equals(EMPTY)) { |
263 | //TODO:EMPTY | 300 | //TODO:EMPTY |
264 | - } else if (type.equals(YangDataTypes.UNION)) { | 301 | + } else if (type.equals(UNION)) { |
265 | //TODO:UNION | 302 | //TODO:UNION |
266 | - } else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) { | 303 | + } else if (type.equals(INSTANCE_IDENTIFIER)) { |
267 | //TODO:INSTANCE_IDENTIFIER | 304 | //TODO:INSTANCE_IDENTIFIER |
268 | - } else if (type.equals(YangDataTypes.DERIVED)) { | 305 | + } else if (type.equals(DERIVED)) { |
269 | for (JavaQualifiedTypeInfo imports : getImportInfo()) { | 306 | for (JavaQualifiedTypeInfo imports : getImportInfo()) { |
270 | if (imports.getClassInfo().equals(classInfo)) { | 307 | if (imports.getClassInfo().equals(classInfo)) { |
271 | return imports.getPkgInfo(); | 308 | return imports.getPkgInfo(); | ... | ... |
... | @@ -16,8 +16,22 @@ | ... | @@ -16,8 +16,22 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType; | 19 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
20 | -import org.onosproject.yangutils.utils.UtilConstants; | 20 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
21 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | ||
22 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
23 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
24 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
21 | 35 | ||
22 | /** | 36 | /** |
23 | * Generates class definition for generated files. | 37 | * Generates class definition for generated files. |
... | @@ -44,19 +58,19 @@ public final class ClassDefinitionGenerator { | ... | @@ -44,19 +58,19 @@ public final class ClassDefinitionGenerator { |
44 | * based on the file type and the YANG name of the file, generate the | 58 | * based on the file type and the YANG name of the file, generate the |
45 | * class / interface definition start. | 59 | * class / interface definition start. |
46 | */ | 60 | */ |
47 | - if ((genFileTypes & GeneratedJavaFileType.INTERFACE_MASK) != 0) { | 61 | + if ((genFileTypes & INTERFACE_MASK) != 0) { |
48 | 62 | ||
49 | return getInterfaceDefinition(yangName); | 63 | return getInterfaceDefinition(yangName); |
50 | - } else if ((genFileTypes & GeneratedJavaFileType.BUILDER_CLASS_MASK) != 0) { | 64 | + } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { |
51 | 65 | ||
52 | return getBuilderClassDefinition(yangName); | 66 | return getBuilderClassDefinition(yangName); |
53 | - } else if ((genFileTypes & GeneratedJavaFileType.IMPL_CLASS_MASK) != 0) { | 67 | + } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { |
54 | 68 | ||
55 | return getImplClassDefinition(yangName); | 69 | return getImplClassDefinition(yangName); |
56 | - } else if ((genFileTypes & GeneratedJavaFileType.BUILDER_INTERFACE_MASK) != 0) { | 70 | + } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { |
57 | 71 | ||
58 | return getBuilderInterfaceDefinition(yangName); | 72 | return getBuilderInterfaceDefinition(yangName); |
59 | - } else if ((genFileTypes & GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS) != 0) { | 73 | + } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) { |
60 | 74 | ||
61 | return getTypeDefClassDefinition(yangName); | 75 | return getTypeDefClassDefinition(yangName); |
62 | } | 76 | } |
... | @@ -71,8 +85,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -71,8 +85,7 @@ public final class ClassDefinitionGenerator { |
71 | */ | 85 | */ |
72 | private static String getInterfaceDefinition(String yangName) { | 86 | private static String getInterfaceDefinition(String yangName) { |
73 | 87 | ||
74 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName | 88 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
75 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
76 | } | 89 | } |
77 | 90 | ||
78 | /** | 91 | /** |
... | @@ -83,8 +96,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -83,8 +96,8 @@ public final class ClassDefinitionGenerator { |
83 | * @return definition | 96 | * @return definition |
84 | */ | 97 | */ |
85 | private static String getBuilderInterfaceDefinition(String yangName) { | 98 | private static String getBuilderInterfaceDefinition(String yangName) { |
86 | - return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE | 99 | + |
87 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; | 100 | + return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE; |
88 | } | 101 | } |
89 | 102 | ||
90 | /** | 103 | /** |
... | @@ -95,10 +108,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -95,10 +108,8 @@ public final class ClassDefinitionGenerator { |
95 | */ | 108 | */ |
96 | private static String getBuilderClassDefinition(String yangName) { | 109 | private static String getBuilderClassDefinition(String yangName) { |
97 | 110 | ||
98 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName | 111 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD |
99 | - + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE | 112 | + + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
100 | - + yangName + UtilConstants.PERIOD + yangName + UtilConstants.BUILDER + UtilConstants.SPACE | ||
101 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
102 | } | 113 | } |
103 | 114 | ||
104 | /** | 115 | /** |
... | @@ -109,10 +120,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -109,10 +120,8 @@ public final class ClassDefinitionGenerator { |
109 | */ | 120 | */ |
110 | private static String getImplClassDefinition(String yangName) { | 121 | private static String getImplClassDefinition(String yangName) { |
111 | 122 | ||
112 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 123 | + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName |
113 | - + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE | 124 | + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
114 | - + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | ||
115 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
116 | } | 125 | } |
117 | 126 | ||
118 | /** | 127 | /** |
... | @@ -123,9 +132,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -123,9 +132,6 @@ public final class ClassDefinitionGenerator { |
123 | */ | 132 | */ |
124 | private static String getTypeDefClassDefinition(String yangName) { | 133 | private static String getTypeDefClassDefinition(String yangName) { |
125 | 134 | ||
126 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 135 | + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
127 | - + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | ||
128 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
129 | } | 136 | } |
130 | - | ||
131 | } | 137 | } | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.yangutils.translator.tojava.utils; | ||
18 | - | ||
19 | -import java.io.File; | ||
20 | -import java.io.IOException; | ||
21 | -import java.util.ArrayList; | ||
22 | -import java.util.List; | ||
23 | - | ||
24 | -import org.onosproject.yangutils.datamodel.YangNode; | ||
25 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
26 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
27 | -import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
28 | -import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
29 | -import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
30 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
31 | - | ||
32 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | ||
33 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | ||
34 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
35 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
36 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
37 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.appendFileContents; | ||
38 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.clean; | ||
39 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.closeFileHandles; | ||
40 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; | ||
41 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; | ||
42 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; | ||
43 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; | ||
44 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getFileObject; | ||
45 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.insert; | ||
46 | - | ||
47 | -/** | ||
48 | - * Provides generate java code exit. | ||
49 | - */ | ||
50 | -public final class GenerateJavaCodeExitBuilder { | ||
51 | - | ||
52 | - private static final String JAVA_FILE_EXTENSION = ".java"; | ||
53 | - | ||
54 | - /** | ||
55 | - * Default constructor. | ||
56 | - */ | ||
57 | - private GenerateJavaCodeExitBuilder() { | ||
58 | - } | ||
59 | - | ||
60 | - /** | ||
61 | - * Sets import for hash and equals method. | ||
62 | - * | ||
63 | - * @return import string for implementing hash and equals | ||
64 | - */ | ||
65 | - private static String setImportForHashAndEquals() { | ||
66 | - | ||
67 | - return UtilConstants.IMPORT + UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG + UtilConstants.PERIOD | ||
68 | - + UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
69 | - } | ||
70 | - | ||
71 | - /** | ||
72 | - * Sets import for to string method. | ||
73 | - * | ||
74 | - * @return import string for implementing to string | ||
75 | - */ | ||
76 | - private static String setImportForToString() { | ||
77 | - | ||
78 | - return UtilConstants.IMPORT + UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG + UtilConstants.PERIOD | ||
79 | - + UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
80 | - } | ||
81 | - | ||
82 | - /** | ||
83 | - * Sets import for to list. | ||
84 | - * | ||
85 | - * @return import string for list collection | ||
86 | - */ | ||
87 | - private static String setImportForList() { | ||
88 | - | ||
89 | - return UtilConstants.IMPORT + UtilConstants.COLLECTION_IMPORTS + UtilConstants.PERIOD | ||
90 | - + UtilConstants.LIST + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
91 | - } | ||
92 | - | ||
93 | - /** | ||
94 | - * Construct java code exit. | ||
95 | - * | ||
96 | - * @param fileType generated file type | ||
97 | - * @param curNode current YANG node | ||
98 | - * @throws IOException when fails to generate java files | ||
99 | - */ | ||
100 | - public static void generateJavaFile(int fileType, YangNode curNode) throws IOException { | ||
101 | - | ||
102 | - JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | ||
103 | - String className = JavaIdentifierSyntax.getCaptialCase(javaFileInfo.getJavaName()); | ||
104 | - String pkg = javaFileInfo.getPackageFilePath(); | ||
105 | - List<String> imports = getImports(((HasJavaImportData) curNode).getJavaImportData()); | ||
106 | - | ||
107 | - /** | ||
108 | - * Start generation of files. | ||
109 | - */ | ||
110 | - if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0 | ||
111 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
112 | - | ||
113 | - /** | ||
114 | - * Create interface file. | ||
115 | - */ | ||
116 | - String interfaceFileName = className; | ||
117 | - File interfaceFile = getFileObject(pkg, interfaceFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
118 | - interfaceFile = generateInterfaceFile(interfaceFile, imports, curNode); | ||
119 | - /** | ||
120 | - * Create temp builder interface file. | ||
121 | - */ | ||
122 | - String builderInterfaceFileName = className | ||
123 | - + UtilConstants.BUILDER + UtilConstants.INTERFACE; | ||
124 | - File builderInterfaceFile = getFileObject(pkg, builderInterfaceFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
125 | - builderInterfaceFile = generateBuilderInterfaceFile(builderInterfaceFile, curNode); | ||
126 | - /** | ||
127 | - * Append builder interface file to interface file and close it. | ||
128 | - */ | ||
129 | - appendFileContents(builderInterfaceFile, interfaceFile); | ||
130 | - insert(interfaceFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
131 | - /** | ||
132 | - * Close file handle for interface files. | ||
133 | - */ | ||
134 | - closeFileHandles(builderInterfaceFile); | ||
135 | - closeFileHandles(interfaceFile); | ||
136 | - | ||
137 | - /** | ||
138 | - * Remove temp files. | ||
139 | - */ | ||
140 | - clean(builderInterfaceFile); | ||
141 | - } | ||
142 | - | ||
143 | - imports.add(setImportForHashAndEquals()); | ||
144 | - imports.add(setImportForToString()); | ||
145 | - java.util.Collections.sort(imports); | ||
146 | - | ||
147 | - if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0 | ||
148 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
149 | - | ||
150 | - /** | ||
151 | - * Create builder class file. | ||
152 | - */ | ||
153 | - String builderFileName = className | ||
154 | - + UtilConstants.BUILDER; | ||
155 | - File builderFile = getFileObject(pkg, builderFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
156 | - builderFile = generateBuilderClassFile(builderFile, imports, curNode); | ||
157 | - /** | ||
158 | - * Create temp impl class file. | ||
159 | - */ | ||
160 | - | ||
161 | - String implFileName = className + UtilConstants.IMPL; | ||
162 | - File implTempFile = getFileObject(pkg, implFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
163 | - implTempFile = generateImplClassFile(implTempFile, curNode); | ||
164 | - /** | ||
165 | - * Append impl class to builder class and close it. | ||
166 | - */ | ||
167 | - appendFileContents(implTempFile, builderFile); | ||
168 | - insert(builderFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
169 | - | ||
170 | - /** | ||
171 | - * Close file handle for classes files. | ||
172 | - */ | ||
173 | - closeFileHandles(implTempFile); | ||
174 | - closeFileHandles(builderFile); | ||
175 | - | ||
176 | - /** | ||
177 | - * Remove temp files. | ||
178 | - */ | ||
179 | - clean(implTempFile); | ||
180 | - } | ||
181 | - | ||
182 | - /** | ||
183 | - * if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { | ||
184 | - * | ||
185 | - * /** Create builder class file. // | ||
186 | - */ | ||
187 | - //String typeDefFileName = className; | ||
188 | - //File typeDefFile = JavaFileGenerator.getFileObject(path, typeDefFileName, JAVA_FILE_EXTENSION, | ||
189 | - // ((HasJavaFileInfo) curNode).getJavaFileInfo()); | ||
190 | - //typeDefFile = JavaFileGenerator.generateTypeDefClassFile(typeDefFile, className, imports, | ||
191 | - // path.replace('/', '.'), attrList, ((HasJavaFileInfo) curNode).getJavaFileInfo()); | ||
192 | - // JavaFileGenerator.insert(typeDefFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
193 | - | ||
194 | - // /** | ||
195 | - // * Close file handle for classes files. | ||
196 | - // */ | ||
197 | - // JavaFileGenerator.closeFileHandles(typeDefFile); | ||
198 | - // } | ||
199 | - // | ||
200 | - } | ||
201 | - | ||
202 | - /** | ||
203 | - * Returns import for class. | ||
204 | - * | ||
205 | - * @param javaImportData import data | ||
206 | - * @return imports for class | ||
207 | - */ | ||
208 | - private static List<String> getImports(JavaImportData javaImportData) { | ||
209 | - | ||
210 | - String importString; | ||
211 | - List<String> imports = new ArrayList<>(); | ||
212 | - | ||
213 | - for (JavaQualifiedTypeInfo importInfo : javaImportData.getImportSet()) { | ||
214 | - importString = UtilConstants.IMPORT; | ||
215 | - if (importInfo.getPkgInfo() != "" && importInfo.getClassInfo() != null | ||
216 | - && importInfo.getPkgInfo() != UtilConstants.JAVA_LANG) { | ||
217 | - importString = importString + importInfo.getPkgInfo() + "."; | ||
218 | - importString = importString + importInfo.getClassInfo() + UtilConstants.SEMI_COLAN | ||
219 | - + UtilConstants.NEW_LINE; | ||
220 | - | ||
221 | - imports.add(importString); | ||
222 | - } | ||
223 | - } | ||
224 | - | ||
225 | - if (javaImportData.getIfListImported()) { | ||
226 | - imports.add(setImportForList()); | ||
227 | - } | ||
228 | - | ||
229 | - java.util.Collections.sort(imports); | ||
230 | - return imports; | ||
231 | - } | ||
232 | -} |
... | @@ -17,7 +17,19 @@ | ... | @@ -17,7 +17,19 @@ |
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
20 | -import org.onosproject.yangutils.utils.UtilConstants; | 20 | + |
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.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
24 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
21 | 33 | ||
22 | /** | 34 | /** |
23 | * Utility class to generate the java snippet. | 35 | * Utility class to generate the java snippet. |
... | @@ -52,8 +64,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -52,8 +64,7 @@ public final class JavaCodeSnippetGen { |
52 | */ | 64 | */ |
53 | public static String getImportText(JavaQualifiedTypeInfo importInfo) { | 65 | public static String getImportText(JavaQualifiedTypeInfo importInfo) { |
54 | 66 | ||
55 | - return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo() | 67 | + return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE; |
56 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
57 | } | 68 | } |
58 | 69 | ||
59 | /** | 70 | /** |
... | @@ -69,8 +80,8 @@ public final class JavaCodeSnippetGen { | ... | @@ -69,8 +80,8 @@ public final class JavaCodeSnippetGen { |
69 | /* | 80 | /* |
70 | * get the camel case name for java class / interface. | 81 | * get the camel case name for java class / interface. |
71 | */ | 82 | */ |
72 | - yangName = JavaIdentifierSyntax.getCamelCase(yangName); | 83 | + yangName = getCamelCase(yangName); |
73 | - return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName); | 84 | + return generateClassDefinition(genFileTypes, yangName); |
74 | } | 85 | } |
75 | 86 | ||
76 | /** | 87 | /** |
... | @@ -85,30 +96,23 @@ public final class JavaCodeSnippetGen { | ... | @@ -85,30 +96,23 @@ public final class JavaCodeSnippetGen { |
85 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, | 96 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, |
86 | String javaAttributeName, boolean isList) { | 97 | String javaAttributeName, boolean isList) { |
87 | 98 | ||
88 | - String attributeDefination = UtilConstants.PRIVATE | 99 | + String attributeDefination = PRIVATE + SPACE; |
89 | - + UtilConstants.SPACE; | ||
90 | 100 | ||
91 | if (!isList) { | 101 | if (!isList) { |
92 | if (javaAttributeTypePkg != null) { | 102 | if (javaAttributeTypePkg != null) { |
93 | - attributeDefination = attributeDefination | 103 | + attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD; |
94 | - + javaAttributeTypePkg + UtilConstants.PERIOD; | ||
95 | } | 104 | } |
96 | 105 | ||
97 | - attributeDefination = attributeDefination | 106 | + attributeDefination = attributeDefination + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN |
98 | - + javaAttributeType | 107 | + + NEW_LINE; |
99 | - + UtilConstants.SPACE | ||
100 | - + javaAttributeName | ||
101 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
102 | } else { | 108 | } else { |
103 | - attributeDefination = attributeDefination + UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET; | 109 | + attributeDefination = attributeDefination + LIST + DIAMOND_OPEN_BRACKET; |
104 | if (javaAttributeTypePkg != null) { | 110 | if (javaAttributeTypePkg != null) { |
105 | - attributeDefination = attributeDefination | 111 | + attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD; |
106 | - + javaAttributeTypePkg + UtilConstants.PERIOD; | ||
107 | } | 112 | } |
108 | 113 | ||
109 | - attributeDefination = attributeDefination | 114 | + attributeDefination = attributeDefination + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE |
110 | - + javaAttributeType + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE | 115 | + + javaAttributeName + SEMI_COLAN + NEW_LINE; |
111 | - + javaAttributeName + UtilConstants.SUFIX_S + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
112 | } | 116 | } |
113 | return attributeDefination; | 117 | return attributeDefination; |
114 | } | 118 | } |
... | @@ -121,7 +125,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -121,7 +125,7 @@ public final class JavaCodeSnippetGen { |
121 | */ | 125 | */ |
122 | public static String getListAttribute(String type) { | 126 | public static String getListAttribute(String type) { |
123 | 127 | ||
124 | - return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + type + UtilConstants.DIAMOND_CLOSE_BRACKET; | 128 | + return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; |
125 | } | 129 | } |
126 | 130 | ||
127 | /** | 131 | /** |
... | @@ -132,7 +136,6 @@ public final class JavaCodeSnippetGen { | ... | @@ -132,7 +136,6 @@ public final class JavaCodeSnippetGen { |
132 | */ | 136 | */ |
133 | public static String getJavaClassDefClose() { | 137 | public static String getJavaClassDefClose() { |
134 | 138 | ||
135 | - return UtilConstants.CLOSE_CURLY_BRACKET; | 139 | + return CLOSE_CURLY_BRACKET; |
136 | } | 140 | } |
137 | - | ||
138 | } | 141 | } | ... | ... |
... | @@ -21,17 +21,10 @@ import java.io.IOException; | ... | @@ -21,17 +21,10 @@ 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.apache.commons.io.FileUtils; | ||
25 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
26 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 26 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
28 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
29 | -import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
30 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
31 | -import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; | ||
32 | -import org.onosproject.yangutils.utils.io.impl.FileSystemUtil; | ||
33 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | ||
34 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
35 | 28 | ||
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
... | @@ -47,17 +40,25 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -47,17 +40,25 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
43 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; | ||
44 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; | ||
50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
51 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; | ||
52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
53 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; | ||
54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; | 47 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; | 48 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; | 49 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
57 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; | 50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
58 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; | 51 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
59 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; | 52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
60 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; | 53 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
54 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
56 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
57 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
58 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
59 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
60 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
61 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | ||
61 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; | 62 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; |
62 | 63 | ||
63 | /** | 64 | /** |
... | @@ -72,20 +73,6 @@ public final class JavaFileGenerator { | ... | @@ -72,20 +73,6 @@ public final class JavaFileGenerator { |
72 | } | 73 | } |
73 | 74 | ||
74 | /** | 75 | /** |
75 | - * Returns a file object for generated file. | ||
76 | - * | ||
77 | - * @param fileName file name | ||
78 | - * @param filePath file package path | ||
79 | - * @param extension file extension | ||
80 | - * @param handle cached file handle | ||
81 | - * @return file object | ||
82 | - */ | ||
83 | - public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) { | ||
84 | - | ||
85 | - return new File(handle.getBaseCodeGenPath() + filePath + File.separator + fileName + extension); | ||
86 | - } | ||
87 | - | ||
88 | - /** | ||
89 | * Returns generated interface file for current node. | 76 | * Returns generated interface file for current node. |
90 | * | 77 | * |
91 | * @param file file | 78 | * @param file file |
... | @@ -101,13 +88,16 @@ public final class JavaFileGenerator { | ... | @@ -101,13 +88,16 @@ public final class JavaFileGenerator { |
101 | String className = getCaptialCase(javaFileInfo.getJavaName()); | 88 | String className = getCaptialCase(javaFileInfo.getJavaName()); |
102 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 89 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
103 | 90 | ||
104 | - initiateFile(file, className, INTERFACE_MASK, imports, path); | 91 | + initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); |
105 | 92 | ||
106 | /** | 93 | /** |
107 | * Add getter methods to interface file. | 94 | * Add getter methods to interface file. |
108 | */ | 95 | */ |
109 | try { | 96 | try { |
110 | - appendMethod(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode)); | 97 | + /** |
98 | + * Getter methods. | ||
99 | + */ | ||
100 | + insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode)); | ||
111 | } catch (IOException e) { | 101 | } catch (IOException e) { |
112 | throw new IOException("No data found in temporary java code fragment files for " + className | 102 | throw new IOException("No data found in temporary java code fragment files for " + className |
113 | + " while interface file generation"); | 103 | + " while interface file generation"); |
... | @@ -130,15 +120,19 @@ public final class JavaFileGenerator { | ... | @@ -130,15 +120,19 @@ public final class JavaFileGenerator { |
130 | String className = getCaptialCase(javaFileInfo.getJavaName()); | 120 | String className = getCaptialCase(javaFileInfo.getJavaName()); |
131 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 121 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
132 | 122 | ||
133 | - initiateFile(file, className, BUILDER_INTERFACE_MASK, null, path); | 123 | + initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path); |
134 | List<String> methods = new ArrayList<>(); | 124 | List<String> methods = new ArrayList<>(); |
135 | 125 | ||
136 | try { | 126 | try { |
137 | - methods.add(UtilConstants.FOUR_SPACE_INDENTATION | 127 | + /** |
138 | - + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode)); | 128 | + * Getter methods. |
139 | - methods.add(UtilConstants.NEW_LINE); | 129 | + */ |
140 | - methods.add(UtilConstants.FOUR_SPACE_INDENTATION | 130 | + methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode)); |
141 | - + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, curNode)); | 131 | + /** |
132 | + * Setter methods. | ||
133 | + */ | ||
134 | + methods.add(NEW_LINE); | ||
135 | + methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, curNode)); | ||
142 | } catch (IOException e) { | 136 | } catch (IOException e) { |
143 | throw new IOException("No data found in temporary java code fragment files for " + className | 137 | throw new IOException("No data found in temporary java code fragment files for " + className |
144 | + " while builder interface file generation"); | 138 | + " while builder interface file generation"); |
... | @@ -147,16 +141,17 @@ public final class JavaFileGenerator { | ... | @@ -147,16 +141,17 @@ public final class JavaFileGenerator { |
147 | /** | 141 | /** |
148 | * Add build method to builder interface file. | 142 | * Add build method to builder interface file. |
149 | */ | 143 | */ |
150 | - methods.add(parseBuilderInterfaceBuildMethodString(className)); | 144 | + methods.add( |
145 | + ((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addBuildMethodForInterface()); | ||
151 | 146 | ||
152 | /** | 147 | /** |
153 | * Add getters and setters in builder interface. | 148 | * Add getters and setters in builder interface. |
154 | */ | 149 | */ |
155 | for (String method : methods) { | 150 | for (String method : methods) { |
156 | - appendMethod(file, method); | 151 | + insertDataIntoJavaFile(file, method); |
157 | } | 152 | } |
158 | 153 | ||
159 | - insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | 154 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
160 | return file; | 155 | return file; |
161 | } | 156 | } |
162 | 157 | ||
... | @@ -176,7 +171,7 @@ public final class JavaFileGenerator { | ... | @@ -176,7 +171,7 @@ public final class JavaFileGenerator { |
176 | String className = getCaptialCase(javaFileInfo.getJavaName()); | 171 | String className = getCaptialCase(javaFileInfo.getJavaName()); |
177 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 172 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
178 | 173 | ||
179 | - initiateFile(file, className, BUILDER_CLASS_MASK, imports, path); | 174 | + initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path); |
180 | 175 | ||
181 | List<String> methods = new ArrayList<>(); | 176 | List<String> methods = new ArrayList<>(); |
182 | 177 | ||
... | @@ -184,16 +179,22 @@ public final class JavaFileGenerator { | ... | @@ -184,16 +179,22 @@ public final class JavaFileGenerator { |
184 | * Add attribute strings. | 179 | * Add attribute strings. |
185 | */ | 180 | */ |
186 | try { | 181 | try { |
187 | - insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 182 | + insertDataIntoJavaFile(file, |
188 | - + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); | 183 | + NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); |
189 | } catch (IOException e) { | 184 | } catch (IOException e) { |
190 | throw new IOException("No data found in temporary java code fragment files for " + className | 185 | throw new IOException("No data found in temporary java code fragment files for " + className |
191 | + " while builder class file generation"); | 186 | + " while builder class file generation"); |
192 | } | 187 | } |
193 | 188 | ||
194 | try { | 189 | try { |
190 | + /** | ||
191 | + * Getter methods. | ||
192 | + */ | ||
195 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | 193 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
196 | - methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, curNode) + UtilConstants.NEW_LINE); | 194 | + /** |
195 | + * Setter methods. | ||
196 | + */ | ||
197 | + methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, curNode) + NEW_LINE); | ||
197 | } catch (IOException e) { | 198 | } catch (IOException e) { |
198 | throw new IOException("No data found in temporary java code fragment files for " + className | 199 | throw new IOException("No data found in temporary java code fragment files for " + className |
199 | + " while builder class file generation"); | 200 | + " while builder class file generation"); |
... | @@ -202,15 +203,15 @@ public final class JavaFileGenerator { | ... | @@ -202,15 +203,15 @@ public final class JavaFileGenerator { |
202 | /** | 203 | /** |
203 | * Add default constructor and build method impl. | 204 | * Add default constructor and build method impl. |
204 | */ | 205 | */ |
205 | - methods.add(getBuildString(className) + UtilConstants.NEW_LINE); | 206 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addBuildMethodImpl()); |
206 | - methods.add(UtilConstants.NEW_LINE | 207 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() |
207 | - + getDefaultConstructorString(className + UtilConstants.BUILDER, UtilConstants.PUBLIC)); | 208 | + .addDefaultConstructor(PUBLIC, BUILDER)); |
208 | 209 | ||
209 | /** | 210 | /** |
210 | * Add methods in builder class. | 211 | * Add methods in builder class. |
211 | */ | 212 | */ |
212 | for (String method : methods) { | 213 | for (String method : methods) { |
213 | - appendMethod(file, method); | 214 | + insertDataIntoJavaFile(file, method); |
214 | } | 215 | } |
215 | return file; | 216 | return file; |
216 | } | 217 | } |
... | @@ -231,7 +232,7 @@ public final class JavaFileGenerator { | ... | @@ -231,7 +232,7 @@ public final class JavaFileGenerator { |
231 | String className = getCaptialCase(javaFileInfo.getJavaName()); | 232 | String className = getCaptialCase(javaFileInfo.getJavaName()); |
232 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 233 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
233 | 234 | ||
234 | - initiateFile(file, className, IMPL_CLASS_MASK, null, path); | 235 | + initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); |
235 | 236 | ||
236 | List<String> methods = new ArrayList<>(); | 237 | List<String> methods = new ArrayList<>(); |
237 | 238 | ||
... | @@ -239,25 +240,32 @@ public final class JavaFileGenerator { | ... | @@ -239,25 +240,32 @@ public final class JavaFileGenerator { |
239 | * Add attribute strings. | 240 | * Add attribute strings. |
240 | */ | 241 | */ |
241 | try { | 242 | try { |
242 | - insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 243 | + insertDataIntoJavaFile(file, |
243 | - + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); | 244 | + NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); |
244 | } catch (IOException e) { | 245 | } catch (IOException e) { |
245 | throw new IOException("No data found in temporary java code fragment files for " + className | 246 | throw new IOException("No data found in temporary java code fragment files for " + className |
246 | + " while impl class file generation"); | 247 | + " while impl class file generation"); |
247 | } | 248 | } |
248 | 249 | ||
249 | - insert(file, UtilConstants.NEW_LINE); | 250 | + insertDataIntoJavaFile(file, NEW_LINE); |
250 | try { | 251 | try { |
251 | - | 252 | + /** |
253 | + * Getter methods. | ||
254 | + */ | ||
252 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | 255 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
253 | - | 256 | + /** |
257 | + * Hash code method. | ||
258 | + */ | ||
254 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | 259 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( |
255 | - getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(UtilConstants.NEW_LINE, | 260 | + getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(NEW_LINE, EMPTY_STRING)))); |
256 | - UtilConstants.EMPTY_STRING)))); | 261 | + /** |
257 | - | 262 | + * Equals method. |
258 | - methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + UtilConstants.IMPL) | 263 | + */ |
259 | - + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode))); | 264 | + methods.add(getEqualsMethodClose( |
260 | - | 265 | + getEqualsMethodOpen(className + IMPL) + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode))); |
266 | + /** | ||
267 | + * To string method. | ||
268 | + */ | ||
261 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) | 269 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) |
262 | + getToStringMethodClose()); | 270 | + getToStringMethodClose()); |
263 | 271 | ||
... | @@ -267,8 +275,11 @@ public final class JavaFileGenerator { | ... | @@ -267,8 +275,11 @@ public final class JavaFileGenerator { |
267 | } | 275 | } |
268 | 276 | ||
269 | try { | 277 | try { |
278 | + /** | ||
279 | + * Constructor. | ||
280 | + */ | ||
270 | methods.add(getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, curNode) | 281 | methods.add(getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK, curNode) |
271 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET); | 282 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET); |
272 | } catch (IOException e) { | 283 | } catch (IOException e) { |
273 | throw new IOException("No data found in temporary java code fragment files for " + className | 284 | throw new IOException("No data found in temporary java code fragment files for " + className |
274 | + " while impl class file generation"); | 285 | + " while impl class file generation"); |
... | @@ -277,262 +288,100 @@ public final class JavaFileGenerator { | ... | @@ -277,262 +288,100 @@ public final class JavaFileGenerator { |
277 | * Add methods in impl class. | 288 | * Add methods in impl class. |
278 | */ | 289 | */ |
279 | for (String method : methods) { | 290 | for (String method : methods) { |
280 | - appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE); | 291 | + insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + method + NEW_LINE); |
281 | } | 292 | } |
282 | - insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE); | 293 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
283 | 294 | ||
284 | return file; | 295 | return file; |
285 | } | 296 | } |
286 | 297 | ||
287 | /** | 298 | /** |
288 | - * Return data stored in temporary files. | 299 | + * Generate class file for type def. |
289 | - * | ||
290 | - * @param curNode current YANG node | ||
291 | - * @param generatedTempFiles mask for the types of files being generated | ||
292 | - * @return data stored in temporary files | ||
293 | - * @throws IOException when failed to get the data from temporary file | ||
294 | - * handle | ||
295 | - */ | ||
296 | - private static String getDataFromTempFileHandle(int generatedTempFiles, YangNode curNode) throws IOException { | ||
297 | - | ||
298 | - TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = ((HasTempJavaCodeFragmentFiles) curNode) | ||
299 | - .getTempJavaCodeFragmentFiles(); | ||
300 | - | ||
301 | - if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | ||
302 | - return tempJavaCodeFragmentFiles | ||
303 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getAttributesTempFileHandle()); | ||
304 | - } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { | ||
305 | - return tempJavaCodeFragmentFiles | ||
306 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getGetterInterfaceTempFileHandle()); | ||
307 | - } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { | ||
308 | - return tempJavaCodeFragmentFiles | ||
309 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getSetterInterfaceTempFileHandle()); | ||
310 | - } else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { | ||
311 | - return tempJavaCodeFragmentFiles | ||
312 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getGetterImplTempFileHandle()); | ||
313 | - } else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { | ||
314 | - return tempJavaCodeFragmentFiles | ||
315 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getSetterImplTempFileHandle()); | ||
316 | - } else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { | ||
317 | - return tempJavaCodeFragmentFiles | ||
318 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getConstructorImplTempFileHandle()); | ||
319 | - } else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { | ||
320 | - return tempJavaCodeFragmentFiles | ||
321 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getHashCodeImplTempFileHandle()); | ||
322 | - } else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { | ||
323 | - return tempJavaCodeFragmentFiles | ||
324 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEqualsImplTempFileHandle()); | ||
325 | - } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { | ||
326 | - return tempJavaCodeFragmentFiles | ||
327 | - .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getToStringImplTempFileHandle()); | ||
328 | - } | ||
329 | - return null; | ||
330 | - } | ||
331 | - | ||
332 | - /** | ||
333 | - * Initiate generation of file based on generated file type. | ||
334 | * | 300 | * |
335 | * @param file generated file | 301 | * @param file generated file |
336 | - * @param className generated file class name | 302 | + * @param curNode current YANG node |
337 | - * @param type generated file type | 303 | + * @param imports imports for file |
338 | - * @param imports imports for the file | 304 | + * @return type def class file |
339 | - * @param pkg generated file package | 305 | + * @throws IOException when fails to generate class file |
340 | - * @throws IOException when fails to generate a file | ||
341 | */ | 306 | */ |
342 | - private static void initiateFile(File file, String className, int type, List<String> imports, | 307 | + public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports) throws IOException { |
343 | - String pkg) throws IOException { | ||
344 | 308 | ||
345 | - try { | 309 | + JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
346 | - file.createNewFile(); | 310 | + |
347 | - appendContents(file, className, type, imports, pkg); | 311 | + String className = getCaptialCase(javaFileInfo.getJavaName()); |
348 | - } catch (IOException e) { | 312 | + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
349 | - throw new IOException("Failed to create " + file.getName() + " class file."); | 313 | + |
350 | - } | 314 | + initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path); |
351 | - } | 315 | + |
316 | + List<String> methods = new ArrayList<>(); | ||
352 | 317 | ||
353 | /** | 318 | /** |
354 | - * Appends the temp files to main files. | 319 | + * Add attribute strings. |
355 | - * | ||
356 | - * @param appendFile temp file | ||
357 | - * @param srcFile main file | ||
358 | - * @throws IOException when fails to append contents | ||
359 | */ | 320 | */ |
360 | - public static void appendFileContents(File appendFile, File srcFile) throws IOException { | ||
361 | - | ||
362 | try { | 321 | try { |
363 | - FileSystemUtil.appendFileContents(appendFile, srcFile); | 322 | + insertDataIntoJavaFile(file, |
323 | + NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); | ||
364 | } catch (IOException e) { | 324 | } catch (IOException e) { |
365 | - throw new IOException("Failed to append " + appendFile + " in " + srcFile); | 325 | + throw new IOException("No data found in temporary java code fragment files for " + className |
366 | - } | 326 | + + " while type def class file generation"); |
367 | } | 327 | } |
368 | 328 | ||
369 | /** | 329 | /** |
370 | - * Append methods to the generated files. | 330 | + * Default constructor. |
371 | - * | ||
372 | - * @param file file in which method needs to be appended | ||
373 | - * @param method method which needs to be appended | ||
374 | - * @throws IOException IO operation failure | ||
375 | */ | 331 | */ |
376 | - private static void appendMethod(File file, String method) throws IOException { | 332 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() |
377 | - | 333 | + .addDefaultConstructor(PRIVATE, EMPTY_STRING)); |
378 | - insert(file, method); | ||
379 | - } | ||
380 | 334 | ||
381 | /** | 335 | /** |
382 | - * Appends all the contents into a generated java file. | 336 | + * Constructor. |
383 | - * | ||
384 | - * @param file generated file | ||
385 | - * @param fileName generated file name | ||
386 | - * @param type generated file type | ||
387 | - * @param pkg generated file package | ||
388 | - * @param importsList list of java imports. | ||
389 | - * @throws IOException when fails to append contents | ||
390 | */ | 337 | */ |
391 | - private static void appendContents(File file, String fileName, int type, List<String> importsList, | 338 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() |
392 | - String pkg) throws IOException { | 339 | + .addTypeDefConstructor()); |
393 | - | ||
394 | - String pkgString = parsePackageString(pkg, importsList); | ||
395 | - | ||
396 | - if ((type & IMPL_CLASS_MASK) != 0) { | ||
397 | - | ||
398 | - write(file, fileName, type, JavaDocType.IMPL_CLASS); | ||
399 | - } else if ((type & BUILDER_INTERFACE_MASK) != 0) { | ||
400 | - | ||
401 | - write(file, fileName, type, JavaDocType.BUILDER_INTERFACE); | ||
402 | - } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) { | ||
403 | - appendHeaderContents(file, pkgString, importsList); | ||
404 | - write(file, fileName, type, JavaDocType.IMPL_CLASS); | ||
405 | - } else if ((type & INTERFACE_MASK) != 0) { | ||
406 | - | ||
407 | - appendHeaderContents(file, pkgString, importsList); | ||
408 | - write(file, fileName, type, JavaDocType.INTERFACE); | ||
409 | - } else if ((type & BUILDER_CLASS_MASK) != 0) { | ||
410 | - | ||
411 | - appendHeaderContents(file, pkgString, importsList); | ||
412 | - write(file, fileName, type, JavaDocType.BUILDER_CLASS); | ||
413 | - } | ||
414 | - } | ||
415 | 340 | ||
416 | /** | 341 | /** |
417 | - * Removes base directory path from package and generates package string for | 342 | + * Of method. |
418 | - * file. | ||
419 | - * | ||
420 | - * @param pkg generated package | ||
421 | - * @param importsList list of imports | ||
422 | - * @return package string | ||
423 | */ | 343 | */ |
424 | - private static String parsePackageString(String pkg, List<String> importsList) { | 344 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addOfMethod()); |
425 | - | 345 | + try { |
426 | - if (pkg.contains(UtilConstants.ORG)) { | ||
427 | - String[] strArray = pkg.split(UtilConstants.ORG); | ||
428 | - pkg = UtilConstants.ORG + strArray[1].replace(UtilConstants.SLASH, UtilConstants.PERIOD); | ||
429 | - } | ||
430 | - if (importsList != null) { | ||
431 | - if (!importsList.isEmpty()) { | ||
432 | - return UtilConstants.PACKAGE + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN | ||
433 | - + UtilConstants.NEW_LINE; | ||
434 | - } else { | ||
435 | - return UtilConstants.PACKAGE + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN; | ||
436 | - } | ||
437 | - } else { | ||
438 | - return UtilConstants.PACKAGE + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN; | ||
439 | - } | ||
440 | - } | ||
441 | 346 | ||
442 | /** | 347 | /** |
443 | - * Appends other contents to interface, builder and typedef classes. for | 348 | + * Getter method. |
444 | - * example : ONOS copyright, imports and package. | ||
445 | - * | ||
446 | - * @param file generated file | ||
447 | - * @param pkg generated package | ||
448 | - * @param importsList list of imports | ||
449 | - * @throws IOException when fails to append contents. | ||
450 | */ | 349 | */ |
451 | - private static void appendHeaderContents(File file, String pkg, List<String> importsList) throws IOException { | 350 | + methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
452 | - | ||
453 | - insert(file, CopyrightHeader.getCopyrightHeader()); | ||
454 | - insert(file, pkg); | ||
455 | 351 | ||
456 | - /* | 352 | + /** |
457 | - * TODO: add the file header using | 353 | + * Setter method. |
458 | - * JavaCodeSnippetGen.getFileHeaderComment | ||
459 | */ | 354 | */ |
460 | - | 355 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addTypeDefsSetter()); |
461 | - if (importsList != null) { | ||
462 | - insert(file, UtilConstants.NEW_LINE); | ||
463 | - for (String imports : importsList) { | ||
464 | - insert(file, imports); | ||
465 | - } | ||
466 | - } | ||
467 | - } | ||
468 | 356 | ||
469 | /** | 357 | /** |
470 | - * Write data to the specific generated file. | 358 | + * Hash code method. |
471 | - * | ||
472 | - * @param file generated file | ||
473 | - * @param fileName file name | ||
474 | - * @param genType generated file type | ||
475 | - * @param javaDocType java doc type | ||
476 | - * @throws IOException when fails to write into a file | ||
477 | */ | 359 | */ |
478 | - private static void write(File file, String fileName, int genType, JavaDocGen.JavaDocType javaDocType) | 360 | + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( |
479 | - throws IOException { | 361 | + getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(NEW_LINE, EMPTY_STRING)))); |
480 | - | ||
481 | - insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName, false)); | ||
482 | - insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName)); | ||
483 | - } | ||
484 | 362 | ||
485 | /** | 363 | /** |
486 | - * Insert in the generated file. | 364 | + * Equals method. |
487 | - * | ||
488 | - * @param file file in which need to be inserted | ||
489 | - * @param data data which need to be inserted | ||
490 | - * @throws IOException when fails to insert into file | ||
491 | */ | 365 | */ |
492 | - public static void insert(File file, String data) throws IOException { | 366 | + methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) |
493 | - | 367 | + + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode))); |
494 | - try { | ||
495 | - FileSystemUtil.updateFileHandle(file, data, false); | ||
496 | - } catch (IOException e) { | ||
497 | - throw new IOException("Failed to insert in " + file + "file"); | ||
498 | - } | ||
499 | - } | ||
500 | 368 | ||
501 | /** | 369 | /** |
502 | - * Closes the files handle for generate files. | 370 | + * To string method. |
503 | - * | ||
504 | - * @param file generate files | ||
505 | - * @throws IOException when failed to close the file handle | ||
506 | */ | 371 | */ |
507 | - public static void closeFileHandles(File file) throws IOException { | 372 | + methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) |
373 | + + getToStringMethodClose()); | ||
508 | 374 | ||
509 | - try { | ||
510 | - FileSystemUtil.updateFileHandle(file, null, true); | ||
511 | } catch (IOException e) { | 375 | } catch (IOException e) { |
512 | - throw new IOException("Failed to close file handle for " + file + "file"); | 376 | + throw new IOException("No data found in temporary java code fragment files for " + className |
513 | - } | 377 | + + " while tyoe def class file generation"); |
514 | } | 378 | } |
515 | 379 | ||
516 | - /** | 380 | + for (String method : methods) { |
517 | - * Removes temp files. | 381 | + insertDataIntoJavaFile(file, method); |
518 | - * | ||
519 | - * @param file file to be removed | ||
520 | - */ | ||
521 | - public static void clean(File file) { | ||
522 | - | ||
523 | - if (file.exists()) { | ||
524 | - file.delete(); | ||
525 | - } | ||
526 | } | 382 | } |
383 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | ||
527 | 384 | ||
528 | - /** | 385 | + return file; |
529 | - * Removes temp files. | ||
530 | - * | ||
531 | - * @param tempDir temp directory | ||
532 | - * @throws IOException when fails to delete the directory | ||
533 | - */ | ||
534 | - public static void cleanTempFiles(File tempDir) throws IOException { | ||
535 | - | ||
536 | - FileUtils.deleteDirectory(tempDir); | ||
537 | } | 386 | } |
538 | } | 387 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.translator.tojava.utils; | ||
18 | + | ||
19 | +import java.io.File; | ||
20 | +import java.io.IOException; | ||
21 | +import java.util.List; | ||
22 | + | ||
23 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
24 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
25 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
26 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
27 | +import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; | ||
28 | +import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
29 | + | ||
30 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | ||
32 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | ||
33 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
34 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
35 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | ||
36 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | ||
37 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | ||
38 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | ||
39 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | ||
40 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; | ||
41 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | ||
42 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | ||
43 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | ||
44 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.ORG; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
50 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
51 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
52 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; | ||
53 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | ||
54 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | ||
55 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | ||
56 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg; | ||
57 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | ||
58 | + | ||
59 | +/** | ||
60 | + * Provides utilities for java file generator. | ||
61 | + */ | ||
62 | +public final class JavaFileGeneratorUtils { | ||
63 | + | ||
64 | + /** | ||
65 | + * Default constructor. | ||
66 | + */ | ||
67 | + private JavaFileGeneratorUtils() { | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns a file object for generated file. | ||
72 | + * | ||
73 | + * @param fileName file name | ||
74 | + * @param filePath file package path | ||
75 | + * @param extension file extension | ||
76 | + * @param handle cached file handle | ||
77 | + * @return file object | ||
78 | + */ | ||
79 | + public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) { | ||
80 | + | ||
81 | + return new File(handle.getBaseCodeGenPath() + filePath + SLASH + fileName + extension); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Return data stored in temporary files. | ||
86 | + * | ||
87 | + * @param generatedTempFiles temporary file types | ||
88 | + * @param curNode current YANG node | ||
89 | + * @return data stored in temporary files | ||
90 | + * @throws IOException when failed to get the data from temporary file handle | ||
91 | + */ | ||
92 | + public static String getDataFromTempFileHandle(int generatedTempFiles, YangNode curNode) throws IOException { | ||
93 | + | ||
94 | + TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = ((HasTempJavaCodeFragmentFiles) curNode) | ||
95 | + .getTempJavaCodeFragmentFiles(); | ||
96 | + | ||
97 | + if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | ||
98 | + return tempJavaCodeFragmentFiles | ||
99 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getAttributesTempFileHandle()); | ||
100 | + } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { | ||
101 | + return tempJavaCodeFragmentFiles | ||
102 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getGetterInterfaceTempFileHandle()); | ||
103 | + } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { | ||
104 | + return tempJavaCodeFragmentFiles | ||
105 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getSetterInterfaceTempFileHandle()); | ||
106 | + } else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { | ||
107 | + return tempJavaCodeFragmentFiles | ||
108 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getGetterImplTempFileHandle()); | ||
109 | + } else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { | ||
110 | + return tempJavaCodeFragmentFiles | ||
111 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getSetterImplTempFileHandle()); | ||
112 | + } else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { | ||
113 | + return tempJavaCodeFragmentFiles | ||
114 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getConstructorImplTempFileHandle()); | ||
115 | + } else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { | ||
116 | + return tempJavaCodeFragmentFiles | ||
117 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getHashCodeImplTempFileHandle()); | ||
118 | + } else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { | ||
119 | + return tempJavaCodeFragmentFiles | ||
120 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEqualsImplTempFileHandle()); | ||
121 | + } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { | ||
122 | + return tempJavaCodeFragmentFiles | ||
123 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getToStringImplTempFileHandle()); | ||
124 | + } | ||
125 | + return null; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Initiate generation of file based on generated file type. | ||
130 | + * | ||
131 | + * @param file generated file | ||
132 | + * @param className generated file class name | ||
133 | + * @param type generated file type | ||
134 | + * @param imports imports for the file | ||
135 | + * @param pkg generated file package | ||
136 | + * @throws IOException when fails to generate a file | ||
137 | + */ | ||
138 | + public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports, | ||
139 | + String pkg) throws IOException { | ||
140 | + | ||
141 | + try { | ||
142 | + file.createNewFile(); | ||
143 | + appendContents(file, className, type, imports, pkg); | ||
144 | + } catch (IOException e) { | ||
145 | + throw new IOException("Failed to create " + file.getName() + " class file."); | ||
146 | + } | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Appends all the contents into a generated java file. | ||
151 | + * | ||
152 | + * @param file generated file | ||
153 | + * @param fileName generated file name | ||
154 | + * @param type generated file type | ||
155 | + * @param pkg generated file package | ||
156 | + * @param importsList list of java imports. | ||
157 | + * @throws IOException when fails to append contents | ||
158 | + */ | ||
159 | + private static void appendContents(File file, String fileName, int type, List<String> importsList, | ||
160 | + String pkg) throws IOException { | ||
161 | + | ||
162 | + String pkgString = parsePackageString(pkg, importsList); | ||
163 | + | ||
164 | + if ((type & IMPL_CLASS_MASK) != 0) { | ||
165 | + | ||
166 | + write(file, fileName, type, IMPL_CLASS); | ||
167 | + } else if ((type & BUILDER_INTERFACE_MASK) != 0) { | ||
168 | + | ||
169 | + write(file, fileName, type, BUILDER_INTERFACE); | ||
170 | + } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) { | ||
171 | + appendHeaderContents(file, pkgString, importsList); | ||
172 | + write(file, fileName, type, IMPL_CLASS); | ||
173 | + } else if ((type & INTERFACE_MASK) != 0) { | ||
174 | + | ||
175 | + appendHeaderContents(file, pkgString, importsList); | ||
176 | + write(file, fileName, type, INTERFACE); | ||
177 | + } else if ((type & BUILDER_CLASS_MASK) != 0) { | ||
178 | + | ||
179 | + appendHeaderContents(file, pkgString, importsList); | ||
180 | + write(file, fileName, type, BUILDER_CLASS); | ||
181 | + } | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Removes base directory path from package and generates package string for file. | ||
186 | + * | ||
187 | + * @param javaPkg generated java package | ||
188 | + * @param importsList list of imports | ||
189 | + * @return package string | ||
190 | + */ | ||
191 | + private static String parsePackageString(String javaPkg, List<String> importsList) { | ||
192 | + | ||
193 | + if (javaPkg.contains(ORG)) { | ||
194 | + String[] strArray = javaPkg.split(ORG); | ||
195 | + javaPkg = ORG + convertPathToPkg(strArray[1]); | ||
196 | + } | ||
197 | + if (importsList != null) { | ||
198 | + if (!importsList.isEmpty()) { | ||
199 | + return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE; | ||
200 | + } else { | ||
201 | + return PACKAGE + SPACE + javaPkg + SEMI_COLAN; | ||
202 | + } | ||
203 | + } else { | ||
204 | + return PACKAGE + SPACE + javaPkg + SEMI_COLAN; | ||
205 | + } | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Appends other contents to interface, builder and typedef classes. | ||
210 | + * for example : ONOS copyright, imports and package. | ||
211 | + * @param file generated file | ||
212 | + * @param pkg generated package | ||
213 | + * @param importsList list of imports | ||
214 | + * @throws IOException when fails to append contents. | ||
215 | + */ | ||
216 | + private static void appendHeaderContents(File file, String pkg, List<String> importsList) throws IOException { | ||
217 | + | ||
218 | + insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader()); | ||
219 | + insertDataIntoJavaFile(file, pkg); | ||
220 | + | ||
221 | + /* | ||
222 | + * TODO: add the file header using | ||
223 | + * JavaCodeSnippetGen.getFileHeaderComment | ||
224 | + */ | ||
225 | + | ||
226 | + if (importsList != null) { | ||
227 | + insertDataIntoJavaFile(file, NEW_LINE); | ||
228 | + for (String imports : importsList) { | ||
229 | + insertDataIntoJavaFile(file, imports); | ||
230 | + } | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Write data to the specific generated file. | ||
236 | + * | ||
237 | + * @param file generated file | ||
238 | + * @param fileName file name | ||
239 | + * @param genType generated file type | ||
240 | + * @param javaDocType java doc type | ||
241 | + * @throws IOException when fails to write into a file | ||
242 | + */ | ||
243 | + private static void write(File file, String fileName, int genType, JavaDocType javaDocType) | ||
244 | + throws IOException { | ||
245 | + | ||
246 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | ||
247 | + insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); | ||
248 | + } | ||
249 | + | ||
250 | +} |
... | @@ -16,14 +16,24 @@ | ... | @@ -16,14 +16,24 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import java.io.File; | ||
20 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
21 | 20 | ||
22 | import org.onosproject.yangutils.datamodel.YangNode; | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
23 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 22 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
24 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
26 | -import org.onosproject.yangutils.utils.UtilConstants; | 25 | + |
26 | +import static org.onosproject.yangutils.utils.UtilConstants.COLAN; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE; | ||
27 | 37 | ||
28 | /** | 38 | /** |
29 | * Utility Class for translating the name from YANG to java convention. | 39 | * Utility Class for translating the name from YANG to java convention. |
... | @@ -53,12 +63,12 @@ public final class JavaIdentifierSyntax { | ... | @@ -53,12 +63,12 @@ public final class JavaIdentifierSyntax { |
53 | public static String getRootPackage(byte version, String nameSpace, String revision) { | 63 | public static String getRootPackage(byte version, String nameSpace, String revision) { |
54 | 64 | ||
55 | String pkg; | 65 | String pkg; |
56 | - pkg = UtilConstants.DEFAULT_BASE_PKG; | 66 | + pkg = DEFAULT_BASE_PKG; |
57 | - pkg = pkg + UtilConstants.PERIOD; | 67 | + pkg = pkg + PERIOD; |
58 | pkg = pkg + getYangVersion(version); | 68 | pkg = pkg + getYangVersion(version); |
59 | - pkg = pkg + UtilConstants.PERIOD; | 69 | + pkg = pkg + PERIOD; |
60 | pkg = pkg + getPkgFromNameSpace(nameSpace); | 70 | pkg = pkg + getPkgFromNameSpace(nameSpace); |
61 | - pkg = pkg + UtilConstants.PERIOD; | 71 | + pkg = pkg + PERIOD; |
62 | pkg = pkg + getYangRevisionStr(revision); | 72 | pkg = pkg + getYangRevisionStr(revision); |
63 | 73 | ||
64 | return pkg.toLowerCase(); | 74 | return pkg.toLowerCase(); |
... | @@ -99,7 +109,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -99,7 +109,7 @@ public final class JavaIdentifierSyntax { |
99 | throw new RuntimeException("missing parent java node to get current node's package"); | 109 | throw new RuntimeException("missing parent java node to get current node's package"); |
100 | } | 110 | } |
101 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); | 111 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); |
102 | - pkg = parentJavaFileHandle.getPackage() + UtilConstants.PERIOD + parentJavaFileHandle.getJavaName(); | 112 | + pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName(); |
103 | return pkg.toLowerCase(); | 113 | return pkg.toLowerCase(); |
104 | } | 114 | } |
105 | 115 | ||
... | @@ -123,9 +133,9 @@ public final class JavaIdentifierSyntax { | ... | @@ -123,9 +133,9 @@ public final class JavaIdentifierSyntax { |
123 | public static String getPkgFromNameSpace(String nameSpace) { | 133 | public static String getPkgFromNameSpace(String nameSpace) { |
124 | 134 | ||
125 | ArrayList<String> pkgArr = new ArrayList<String>(); | 135 | ArrayList<String> pkgArr = new ArrayList<String>(); |
126 | - nameSpace = nameSpace.replace(UtilConstants.QUOTES, UtilConstants.EMPTY_STRING); | 136 | + nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); |
127 | - String properNameSpace = nameSpace.replaceAll(UtilConstants.REGEX_WITH_SPECIAL_CHAR, UtilConstants.COLAN); | 137 | + String properNameSpace = nameSpace.replaceAll(REGEX_WITH_SPECIAL_CHAR, COLAN); |
128 | - String[] nameSpaceArr = properNameSpace.split(UtilConstants.COLAN); | 138 | + String[] nameSpaceArr = properNameSpace.split(COLAN); |
129 | 139 | ||
130 | for (String nameSpaceString : nameSpaceArr) { | 140 | for (String nameSpaceString : nameSpaceArr) { |
131 | pkgArr.add(nameSpaceString); | 141 | pkgArr.add(nameSpaceString); |
... | @@ -142,7 +152,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -142,7 +152,7 @@ public final class JavaIdentifierSyntax { |
142 | */ | 152 | */ |
143 | public static String getYangRevisionStr(String date) throws TranslatorException { | 153 | public static String getYangRevisionStr(String date) throws TranslatorException { |
144 | 154 | ||
145 | - String[] revisionArr = date.split(UtilConstants.HYPHEN); | 155 | + String[] revisionArr = date.split(HYPHEN); |
146 | 156 | ||
147 | String rev = "rev"; | 157 | String rev = "rev"; |
148 | rev = rev + revisionArr[INDEX_ZERO]; | 158 | rev = rev + revisionArr[INDEX_ZERO]; |
... | @@ -172,17 +182,17 @@ public final class JavaIdentifierSyntax { | ... | @@ -172,17 +182,17 @@ public final class JavaIdentifierSyntax { |
172 | */ | 182 | */ |
173 | public static String getPkgFrmArr(ArrayList<String> pkgArr) { | 183 | public static String getPkgFrmArr(ArrayList<String> pkgArr) { |
174 | 184 | ||
175 | - String pkg = UtilConstants.EMPTY_STRING; | 185 | + String pkg = EMPTY_STRING; |
176 | int size = pkgArr.size(); | 186 | int size = pkgArr.size(); |
177 | int i = 0; | 187 | int i = 0; |
178 | for (String member : pkgArr) { | 188 | for (String member : pkgArr) { |
179 | - boolean presenceOfKeyword = UtilConstants.JAVA_KEY_WORDS.contains(member); | 189 | + boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member); |
180 | - if (presenceOfKeyword || member.matches(UtilConstants.REGEX_FOR_FIRST_DIGIT)) { | 190 | + if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { |
181 | - member = UtilConstants.UNDER_SCORE + member; | 191 | + member = UNDER_SCORE + member; |
182 | } | 192 | } |
183 | pkg = pkg + member; | 193 | pkg = pkg + member; |
184 | if (i != size - 1) { | 194 | if (i != size - 1) { |
185 | - pkg = pkg + UtilConstants.PERIOD; | 195 | + pkg = pkg + PERIOD; |
186 | } | 196 | } |
187 | i++; | 197 | i++; |
188 | } | 198 | } |
... | @@ -198,7 +208,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -198,7 +208,7 @@ public final class JavaIdentifierSyntax { |
198 | public static String getSubPkgFromName(String name) { | 208 | public static String getSubPkgFromName(String name) { |
199 | 209 | ||
200 | ArrayList<String> pkgArr = new ArrayList<String>(); | 210 | ArrayList<String> pkgArr = new ArrayList<String>(); |
201 | - String[] nameArr = name.split(UtilConstants.COLAN); | 211 | + String[] nameArr = name.split(COLAN); |
202 | 212 | ||
203 | for (String nameString : nameArr) { | 213 | for (String nameString : nameArr) { |
204 | pkgArr.add(nameString); | 214 | pkgArr.add(nameString); |
... | @@ -214,7 +224,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -214,7 +224,7 @@ public final class JavaIdentifierSyntax { |
214 | */ | 224 | */ |
215 | public static String getCamelCase(String yangIdentifier) { | 225 | public static String getCamelCase(String yangIdentifier) { |
216 | 226 | ||
217 | - String[] strArray = yangIdentifier.split(UtilConstants.HYPHEN); | 227 | + String[] strArray = yangIdentifier.split(HYPHEN); |
218 | String camelCase = strArray[0]; | 228 | String camelCase = strArray[0]; |
219 | for (int i = 1; i < strArray.length; i++) { | 229 | for (int i = 1; i < strArray.length; i++) { |
220 | camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1); | 230 | camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1); |
... | @@ -254,7 +264,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -254,7 +264,7 @@ public final class JavaIdentifierSyntax { |
254 | */ | 264 | */ |
255 | public static String getJavaPackageFromPackagePath(String packagePath) { | 265 | public static String getJavaPackageFromPackagePath(String packagePath) { |
256 | 266 | ||
257 | - return packagePath.replace(File.separator, UtilConstants.PERIOD); | 267 | + return packagePath.replace(SLASH, PERIOD); |
258 | } | 268 | } |
259 | 269 | ||
260 | /** | 270 | /** |
... | @@ -265,6 +275,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -265,6 +275,6 @@ public final class JavaIdentifierSyntax { |
265 | */ | 275 | */ |
266 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { | 276 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { |
267 | 277 | ||
268 | - return packagePath.replace(UtilConstants.PERIOD, File.separator); | 278 | + return packagePath.replace(PERIOD, SLASH); |
269 | } | 279 | } |
270 | } | 280 | } | ... | ... |
... | @@ -17,9 +17,70 @@ | ... | @@ -17,9 +17,70 @@ |
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
20 | -import org.onosproject.yangutils.utils.UtilConstants; | 20 | + |
21 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | 21 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
22 | -import org.onosproject.yangutils.utils.io.impl.YangIoUtils; | 22 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
23 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getLowerCase; | ||
24 | +import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.AND; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILD; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.HASH; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.IF; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.INT; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
50 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW; | ||
51 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
52 | +import static org.onosproject.yangutils.utils.UtilConstants.OBJ; | ||
53 | +import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; | ||
54 | +import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; | ||
55 | +import static org.onosproject.yangutils.utils.UtilConstants.OF; | ||
56 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
57 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | ||
58 | +import static org.onosproject.yangutils.utils.UtilConstants.OTHER; | ||
59 | +import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE; | ||
60 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
61 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
62 | +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
63 | +import static org.onosproject.yangutils.utils.UtilConstants.RETURN; | ||
64 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
65 | +import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX; | ||
66 | +import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION; | ||
67 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
68 | +import static org.onosproject.yangutils.utils.UtilConstants.STATIC; | ||
69 | +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ||
70 | +import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; | ||
71 | +import static org.onosproject.yangutils.utils.UtilConstants.THIS; | ||
72 | +import static org.onosproject.yangutils.utils.UtilConstants.TO; | ||
73 | +import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | ||
74 | +import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; | ||
75 | +import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | ||
76 | +import static org.onosproject.yangutils.utils.UtilConstants.VOID; | ||
77 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
78 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | ||
79 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | ||
80 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | ||
81 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | ||
82 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; | ||
83 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | ||
23 | 84 | ||
24 | /** | 85 | /** |
25 | * Generated methods for generated files based on the file type. | 86 | * Generated methods for generated files based on the file type. |
... | @@ -40,7 +101,7 @@ public final class MethodsGenerator { | ... | @@ -40,7 +101,7 @@ public final class MethodsGenerator { |
40 | */ | 101 | */ |
41 | public static String parseBuilderInterfaceBuildMethodString(String name) { | 102 | public static String parseBuilderInterfaceBuildMethodString(String name) { |
42 | 103 | ||
43 | - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name, false) + getBuildForInterface(name); | 104 | + return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); |
44 | } | 105 | } |
45 | 106 | ||
46 | /** | 107 | /** |
... | @@ -52,10 +113,10 @@ public final class MethodsGenerator { | ... | @@ -52,10 +113,10 @@ public final class MethodsGenerator { |
52 | public static String getGetterString(JavaAttributeInfo attr) { | 113 | public static String getGetterString(JavaAttributeInfo attr) { |
53 | 114 | ||
54 | String returnType = getReturnType(attr); | 115 | String returnType = getReturnType(attr); |
55 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 116 | + String attributeName = getLowerCase(attr.getAttributeName()); |
56 | 117 | ||
57 | - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.GETTER, attributeName, attr.isListAttr()) + | 118 | + return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) |
58 | - getGetterForInterface(attributeName, returnType, attr.isListAttr()); | 119 | + + getGetterForInterface(attributeName, returnType, attr.isListAttr()); |
59 | } | 120 | } |
60 | 121 | ||
61 | /** | 122 | /** |
... | @@ -68,9 +129,9 @@ public final class MethodsGenerator { | ... | @@ -68,9 +129,9 @@ public final class MethodsGenerator { |
68 | public static String getSetterString(JavaAttributeInfo attr, String className) { | 129 | public static String getSetterString(JavaAttributeInfo attr, String className) { |
69 | 130 | ||
70 | String attrType = getReturnType(attr); | 131 | String attrType = getReturnType(attr); |
71 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 132 | + String attributeName = getLowerCase(attr.getAttributeName()); |
72 | 133 | ||
73 | - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.SETTER, attributeName, attr.isListAttr()) | 134 | + return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr()) |
74 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr()); | 135 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr()); |
75 | } | 136 | } |
76 | 137 | ||
... | @@ -82,7 +143,7 @@ public final class MethodsGenerator { | ... | @@ -82,7 +143,7 @@ public final class MethodsGenerator { |
82 | */ | 143 | */ |
83 | public static String getConstructorString(String name) { | 144 | public static String getConstructorString(String name) { |
84 | 145 | ||
85 | - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name, false); | 146 | + return getJavaDoc(CONSTRUCTOR, name, false); |
86 | } | 147 | } |
87 | 148 | ||
88 | /** | 149 | /** |
... | @@ -94,8 +155,7 @@ public final class MethodsGenerator { | ... | @@ -94,8 +155,7 @@ public final class MethodsGenerator { |
94 | */ | 155 | */ |
95 | public static String getDefaultConstructorString(String name, String modifierType) { | 156 | public static String getDefaultConstructorString(String name, String modifierType) { |
96 | 157 | ||
97 | - return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR, name, false) | 158 | + return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType); |
98 | - + getDefaultConstructor(name, modifierType); | ||
99 | } | 159 | } |
100 | 160 | ||
101 | /** | 161 | /** |
... | @@ -108,12 +168,12 @@ public final class MethodsGenerator { | ... | @@ -108,12 +168,12 @@ public final class MethodsGenerator { |
108 | public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { | 168 | public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { |
109 | 169 | ||
110 | String attrQuaifiedType = getReturnType(attr); | 170 | String attrQuaifiedType = getReturnType(attr); |
111 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 171 | + String attributeName = getLowerCase(attr.getAttributeName()); |
112 | 172 | ||
113 | if (!attr.isListAttr()) { | 173 | if (!attr.isListAttr()) { |
114 | return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); | 174 | return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); |
115 | } | 175 | } |
116 | - String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET; | 176 | + String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
117 | return getTypeDefConstructorString(listAttr, attributeName, className); | 177 | return getTypeDefConstructorString(listAttr, attributeName, className); |
118 | } | 178 | } |
119 | 179 | ||
... | @@ -127,13 +187,10 @@ public final class MethodsGenerator { | ... | @@ -127,13 +187,10 @@ public final class MethodsGenerator { |
127 | */ | 187 | */ |
128 | private static String getTypeDefConstructorString(String type, String name, String className) { | 188 | private static String getTypeDefConstructorString(String type, String name, String className) { |
129 | 189 | ||
130 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 190 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
131 | - + className + UtilConstants.OPEN_PARENTHESIS + type + UtilConstants.SPACE + UtilConstants.VALUE | 191 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
132 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | 192 | + + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
133 | - + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS | 193 | + + CLOSE_CURLY_BRACKET; |
134 | - + UtilConstants.PERIOD + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE | ||
135 | - + UtilConstants.VALUE + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
136 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; | ||
137 | } | 194 | } |
138 | 195 | ||
139 | /** | 196 | /** |
... | @@ -144,9 +201,8 @@ public final class MethodsGenerator { | ... | @@ -144,9 +201,8 @@ public final class MethodsGenerator { |
144 | */ | 201 | */ |
145 | public static String getCheckNotNull(String name) { | 202 | public static String getCheckNotNull(String name) { |
146 | 203 | ||
147 | - return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.CHECK_NOT_NULL_STRING | 204 | + return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name |
148 | - + UtilConstants.OPEN_PARENTHESIS + name + UtilConstants.COMMA + UtilConstants.SPACE + name | 205 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
149 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
150 | } | 206 | } |
151 | 207 | ||
152 | /** | 208 | /** |
... | @@ -157,8 +213,7 @@ public final class MethodsGenerator { | ... | @@ -157,8 +213,7 @@ public final class MethodsGenerator { |
157 | */ | 213 | */ |
158 | public static String getBuildString(String name) { | 214 | public static String getBuildString(String name) { |
159 | 215 | ||
160 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE | 216 | + return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name); |
161 | - + getBuild(name); | ||
162 | } | 217 | } |
163 | 218 | ||
164 | /** | 219 | /** |
... | @@ -170,13 +225,13 @@ public final class MethodsGenerator { | ... | @@ -170,13 +225,13 @@ public final class MethodsGenerator { |
170 | public static String getGetterForClass(JavaAttributeInfo attr) { | 225 | public static String getGetterForClass(JavaAttributeInfo attr) { |
171 | 226 | ||
172 | String attrQuaifiedType = getReturnType(attr); | 227 | String attrQuaifiedType = getReturnType(attr); |
173 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 228 | + String attributeName = getLowerCase(attr.getAttributeName()); |
174 | 229 | ||
175 | if (!attr.isListAttr()) { | 230 | if (!attr.isListAttr()) { |
176 | return getGetter(attrQuaifiedType, attributeName); | 231 | return getGetter(attrQuaifiedType, attributeName); |
177 | } | 232 | } |
178 | - String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET; | 233 | + String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
179 | - return getGetter(listAttr, attributeName + UtilConstants.SUFIX_S); | 234 | + return getGetter(listAttr, attributeName); |
180 | } | 235 | } |
181 | 236 | ||
182 | /** | 237 | /** |
... | @@ -188,13 +243,9 @@ public final class MethodsGenerator { | ... | @@ -188,13 +243,9 @@ public final class MethodsGenerator { |
188 | */ | 243 | */ |
189 | private static String getGetter(String type, String name) { | 244 | private static String getGetter(String type, String name) { |
190 | 245 | ||
191 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 246 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) |
192 | - + type + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX | 247 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
193 | - + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS | 248 | + + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
194 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | ||
195 | - + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN | ||
196 | - + UtilConstants.SPACE + name + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
197 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; | ||
198 | } | 249 | } |
199 | 250 | ||
200 | /** | 251 | /** |
... | @@ -207,12 +258,12 @@ public final class MethodsGenerator { | ... | @@ -207,12 +258,12 @@ public final class MethodsGenerator { |
207 | public static String getSetterForClass(JavaAttributeInfo attr, String className) { | 258 | public static String getSetterForClass(JavaAttributeInfo attr, String className) { |
208 | 259 | ||
209 | String attrQuaifiedType = getReturnType(attr); | 260 | String attrQuaifiedType = getReturnType(attr); |
210 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 261 | + String attributeName = getLowerCase(attr.getAttributeName()); |
211 | if (!attr.isListAttr()) { | 262 | if (!attr.isListAttr()) { |
212 | return getSetter(className, attributeName, attrQuaifiedType); | 263 | return getSetter(className, attributeName, attrQuaifiedType); |
213 | } | 264 | } |
214 | - String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET; | 265 | + String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; |
215 | - return getSetter(className, attributeName + UtilConstants.SUFIX_S, listAttr); | 266 | + return getSetter(className, attributeName, listAttr); |
216 | } | 267 | } |
217 | 268 | ||
218 | /** | 269 | /** |
... | @@ -225,16 +276,11 @@ public final class MethodsGenerator { | ... | @@ -225,16 +276,11 @@ public final class MethodsGenerator { |
225 | */ | 276 | */ |
226 | private static String getSetter(String className, String name, String type) { | 277 | private static String getSetter(String className, String name, String type) { |
227 | 278 | ||
228 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 279 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX |
229 | - + className + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX | 280 | + + getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
230 | - + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS | 281 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE |
231 | - + type + UtilConstants.SPACE + name + UtilConstants.CLOSE_PARENTHESIS | 282 | + + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN |
232 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE | 283 | + + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
233 | - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD | ||
234 | - + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE | ||
235 | - + name + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION | ||
236 | - + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN | ||
237 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; | ||
238 | } | 284 | } |
239 | 285 | ||
240 | /** | 286 | /** |
... | @@ -246,14 +292,9 @@ public final class MethodsGenerator { | ... | @@ -246,14 +292,9 @@ public final class MethodsGenerator { |
246 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { | 292 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { |
247 | 293 | ||
248 | String attrQuaifiedType = getReturnType(attr); | 294 | String attrQuaifiedType = getReturnType(attr); |
249 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 295 | + String attributeName = getLowerCase(attr.getAttributeName()); |
250 | - | ||
251 | - if (!attr.isListAttr()) { | ||
252 | return getTypeDefSetter(attrQuaifiedType, attributeName); | 296 | return getTypeDefSetter(attrQuaifiedType, attributeName); |
253 | } | 297 | } |
254 | - String listAttr = getListString() + attrQuaifiedType + UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
255 | - return getTypeDefSetter(listAttr, attributeName + UtilConstants.SUFIX_S); | ||
256 | - } | ||
257 | 298 | ||
258 | /** | 299 | /** |
259 | * Returns type def's setter for attribute. | 300 | * Returns type def's setter for attribute. |
... | @@ -264,15 +305,10 @@ public final class MethodsGenerator { | ... | @@ -264,15 +305,10 @@ public final class MethodsGenerator { |
264 | */ | 305 | */ |
265 | private static String getTypeDefSetter(String type, String name) { | 306 | private static String getTypeDefSetter(String type, String name) { |
266 | 307 | ||
267 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 308 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(name) |
268 | - + UtilConstants.VOID + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX | 309 | + + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
269 | - + JavaIdentifierSyntax.getCaptialCase(name) + UtilConstants.OPEN_PARENTHESIS | 310 | + + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE |
270 | - + type + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.CLOSE_PARENTHESIS | 311 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
271 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE | ||
272 | - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD | ||
273 | - + name + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE | ||
274 | - + UtilConstants.VALUE + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
275 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET; | ||
276 | } | 312 | } |
277 | 313 | ||
278 | /** | 314 | /** |
... | @@ -282,8 +318,7 @@ public final class MethodsGenerator { | ... | @@ -282,8 +318,7 @@ public final class MethodsGenerator { |
282 | */ | 318 | */ |
283 | public static String getOverRideString() { | 319 | public static String getOverRideString() { |
284 | 320 | ||
285 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 321 | + return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; |
286 | - + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE; | ||
287 | } | 322 | } |
288 | 323 | ||
289 | /** | 324 | /** |
... | @@ -299,8 +334,8 @@ public final class MethodsGenerator { | ... | @@ -299,8 +334,8 @@ public final class MethodsGenerator { |
299 | if (!isList) { | 334 | if (!isList) { |
300 | return getGetterInterfaceString(returnType, yangName); | 335 | return getGetterInterfaceString(returnType, yangName); |
301 | } | 336 | } |
302 | - String listAttr = getListString() + returnType + UtilConstants.DIAMOND_CLOSE_BRACKET; | 337 | + String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET; |
303 | - return getGetterInterfaceString(listAttr, yangName + UtilConstants.SUFIX_S); | 338 | + return getGetterInterfaceString(listAttr, yangName); |
304 | } | 339 | } |
305 | 340 | ||
306 | /** | 341 | /** |
... | @@ -312,12 +347,8 @@ public final class MethodsGenerator { | ... | @@ -312,12 +347,8 @@ public final class MethodsGenerator { |
312 | */ | 347 | */ |
313 | private static String getGetterInterfaceString(String returnType, String yangName) { | 348 | private static String getGetterInterfaceString(String returnType, String yangName) { |
314 | 349 | ||
315 | - return UtilConstants.FOUR_SPACE_INDENTATION + returnType | 350 | + return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName) |
316 | - + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX | 351 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
317 | - + JavaIdentifierSyntax.getCaptialCase(yangName) | ||
318 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS | ||
319 | - + UtilConstants.SEMI_COLAN; | ||
320 | - | ||
321 | } | 352 | } |
322 | 353 | ||
323 | /** | 354 | /** |
... | @@ -334,8 +365,8 @@ public final class MethodsGenerator { | ... | @@ -334,8 +365,8 @@ public final class MethodsGenerator { |
334 | if (!isList) { | 365 | if (!isList) { |
335 | return getSetterInterfaceString(className, attrName, attrType); | 366 | return getSetterInterfaceString(className, attrName, attrType); |
336 | } | 367 | } |
337 | - String listAttr = getListString() + attrType + UtilConstants.DIAMOND_CLOSE_BRACKET; | 368 | + String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET; |
338 | - return getSetterInterfaceString(className, attrName + UtilConstants.SUFIX_S, listAttr); | 369 | + return getSetterInterfaceString(className, attrName, listAttr); |
339 | } | 370 | } |
340 | 371 | ||
341 | /** | 372 | /** |
... | @@ -348,11 +379,8 @@ public final class MethodsGenerator { | ... | @@ -348,11 +379,8 @@ public final class MethodsGenerator { |
348 | */ | 379 | */ |
349 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { | 380 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { |
350 | 381 | ||
351 | - return UtilConstants.FOUR_SPACE_INDENTATION + className + UtilConstants.BUILDER | 382 | + return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName) |
352 | - + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX | 383 | + + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
353 | - + JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS | ||
354 | - + attrType + UtilConstants.SPACE + attrName + UtilConstants.CLOSE_PARENTHESIS | ||
355 | - + UtilConstants.SEMI_COLAN; | ||
356 | } | 384 | } |
357 | 385 | ||
358 | /** | 386 | /** |
... | @@ -362,7 +390,7 @@ public final class MethodsGenerator { | ... | @@ -362,7 +390,7 @@ public final class MethodsGenerator { |
362 | */ | 390 | */ |
363 | private static String getListString() { | 391 | private static String getListString() { |
364 | 392 | ||
365 | - return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET; | 393 | + return LIST + DIAMOND_OPEN_BRACKET; |
366 | } | 394 | } |
367 | 395 | ||
368 | /** | 396 | /** |
... | @@ -373,9 +401,9 @@ public final class MethodsGenerator { | ... | @@ -373,9 +401,9 @@ public final class MethodsGenerator { |
373 | */ | 401 | */ |
374 | private static String getReturnType(JavaAttributeInfo attr) { | 402 | private static String getReturnType(JavaAttributeInfo attr) { |
375 | 403 | ||
376 | - String returnType = UtilConstants.EMPTY_STRING; | 404 | + String returnType = EMPTY_STRING; |
377 | if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) { | 405 | if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) { |
378 | - returnType = attr.getImportInfo().getPkgInfo() + UtilConstants.PERIOD; | 406 | + returnType = attr.getImportInfo().getPkgInfo() + PERIOD; |
379 | } | 407 | } |
380 | returnType = returnType + attr.getImportInfo().getClassInfo(); | 408 | returnType = returnType + attr.getImportInfo().getClassInfo(); |
381 | return returnType; | 409 | return returnType; |
... | @@ -389,9 +417,8 @@ public final class MethodsGenerator { | ... | @@ -389,9 +417,8 @@ public final class MethodsGenerator { |
389 | */ | 417 | */ |
390 | public static String getBuildForInterface(String yangName) { | 418 | public static String getBuildForInterface(String yangName) { |
391 | 419 | ||
392 | - return UtilConstants.FOUR_SPACE_INDENTATION + yangName + UtilConstants.SPACE + UtilConstants.BUILD | 420 | + return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
393 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN | 421 | + + NEW_LINE; |
394 | - + UtilConstants.NEW_LINE; | ||
395 | } | 422 | } |
396 | 423 | ||
397 | /** | 424 | /** |
... | @@ -402,12 +429,10 @@ public final class MethodsGenerator { | ... | @@ -402,12 +429,10 @@ public final class MethodsGenerator { |
402 | */ | 429 | */ |
403 | public static String getConstructorStart(String yangName) { | 430 | public static String getConstructorStart(String yangName) { |
404 | 431 | ||
405 | - String javadoc = MethodsGenerator.getConstructorString(yangName); | 432 | + String javadoc = getConstructorString(yangName); |
406 | - String constructor = UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 433 | + String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName |
407 | - + yangName + UtilConstants.IMPL + UtilConstants.OPEN_PARENTHESIS + yangName + UtilConstants.BUILDER | 434 | + + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
408 | - + UtilConstants.SPACE + UtilConstants.BUILDER.toLowerCase() + UtilConstants.OBJECT | 435 | + + NEW_LINE; |
409 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | ||
410 | - + UtilConstants.NEW_LINE; | ||
411 | return javadoc + constructor; | 436 | return javadoc + constructor; |
412 | } | 437 | } |
413 | 438 | ||
... | @@ -420,17 +445,12 @@ public final class MethodsGenerator { | ... | @@ -420,17 +445,12 @@ public final class MethodsGenerator { |
420 | */ | 445 | */ |
421 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { | 446 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { |
422 | 447 | ||
423 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 448 | + String attributeName = getLowerCase(attr.getAttributeName()); |
424 | - if (attr.isListAttr()) { | 449 | + |
425 | - attributeName = attributeName + UtilConstants.SUFIX_S; | 450 | + String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL |
426 | - } | 451 | + + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
427 | - String constructor = UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS | 452 | + + getCaptialCase(getCamelCase(attributeName)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
428 | - + UtilConstants.PERIOD + JavaIdentifierSyntax.getCamelCase(attributeName) | 453 | + + NEW_LINE; |
429 | - + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + UtilConstants.BUILDER.toLowerCase() | ||
430 | - + UtilConstants.OBJECT + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX | ||
431 | - + JavaIdentifierSyntax.getCaptialCase(JavaIdentifierSyntax.getCamelCase(attributeName)) | ||
432 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN | ||
433 | - + UtilConstants.NEW_LINE; | ||
434 | 454 | ||
435 | return constructor; | 455 | return constructor; |
436 | } | 456 | } |
... | @@ -443,14 +463,10 @@ public final class MethodsGenerator { | ... | @@ -443,14 +463,10 @@ public final class MethodsGenerator { |
443 | */ | 463 | */ |
444 | public static String getBuild(String yangName) { | 464 | public static String getBuild(String yangName) { |
445 | 465 | ||
446 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 466 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
447 | - + yangName + UtilConstants.SPACE + UtilConstants.BUILD + UtilConstants.OPEN_PARENTHESIS | 467 | + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE |
448 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | 468 | + + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
449 | - + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN | 469 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
450 | - + UtilConstants.SPACE + UtilConstants.NEW + UtilConstants.SPACE + yangName + UtilConstants.IMPL | ||
451 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.THIS + UtilConstants.CLOSE_PARENTHESIS | ||
452 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | ||
453 | - + UtilConstants.CLOSE_CURLY_BRACKET; | ||
454 | } | 470 | } |
455 | 471 | ||
456 | /** | 472 | /** |
... | @@ -462,10 +478,8 @@ public final class MethodsGenerator { | ... | @@ -462,10 +478,8 @@ public final class MethodsGenerator { |
462 | */ | 478 | */ |
463 | private static String getDefaultConstructor(String name, String modifierType) { | 479 | private static String getDefaultConstructor(String name, String modifierType) { |
464 | 480 | ||
465 | - return UtilConstants.FOUR_SPACE_INDENTATION + modifierType + UtilConstants.SPACE + name | 481 | + return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE |
466 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE | 482 | + + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
467 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | ||
468 | - + UtilConstants.CLOSE_CURLY_BRACKET; | ||
469 | } | 483 | } |
470 | 484 | ||
471 | /** | 485 | /** |
... | @@ -475,11 +489,9 @@ public final class MethodsGenerator { | ... | @@ -475,11 +489,9 @@ public final class MethodsGenerator { |
475 | */ | 489 | */ |
476 | public static String getToStringMethodOpen() { | 490 | public static String getToStringMethodOpen() { |
477 | 491 | ||
478 | - return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 492 | + return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
479 | - + UtilConstants.STRING + UtilConstants.SPACE + UtilConstants.TO + UtilConstants.STRING | 493 | + + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
480 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE | 494 | + + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; |
481 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION | ||
482 | - + UtilConstants.RETURN + UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING + UtilConstants.NEW_LINE; | ||
483 | } | 495 | } |
484 | 496 | ||
485 | /** | 497 | /** |
... | @@ -489,10 +501,8 @@ public final class MethodsGenerator { | ... | @@ -489,10 +501,8 @@ public final class MethodsGenerator { |
489 | */ | 501 | */ |
490 | public static String getToStringMethodClose() { | 502 | public static String getToStringMethodClose() { |
491 | 503 | ||
492 | - return UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.PERIOD + UtilConstants.TO + UtilConstants.STRING | 504 | + return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
493 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN | 505 | + + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
494 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | ||
495 | - + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
496 | } | 506 | } |
497 | 507 | ||
498 | /** | 508 | /** |
... | @@ -503,14 +513,10 @@ public final class MethodsGenerator { | ... | @@ -503,14 +513,10 @@ public final class MethodsGenerator { |
503 | */ | 513 | */ |
504 | public static String getToStringMethod(JavaAttributeInfo attr) { | 514 | public static String getToStringMethod(JavaAttributeInfo attr) { |
505 | 515 | ||
506 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 516 | + String attributeName = getLowerCase(attr.getAttributeName()); |
507 | - if (attr.isListAttr()) { | 517 | + |
508 | - attributeName = attributeName + UtilConstants.SUFIX_S; | 518 | + return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
509 | - } | 519 | + + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
510 | - return UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.PERIOD + UtilConstants.ADD_STRING | ||
511 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.QUOTES | ||
512 | - + attributeName + UtilConstants.QUOTES + UtilConstants.COMMA + UtilConstants.SPACE + attributeName | ||
513 | - + UtilConstants.CLOSE_PARENTHESIS; | ||
514 | 520 | ||
515 | } | 521 | } |
516 | 522 | ||
... | @@ -521,12 +527,9 @@ public final class MethodsGenerator { | ... | @@ -521,12 +527,9 @@ public final class MethodsGenerator { |
521 | */ | 527 | */ |
522 | public static String getHashCodeMethodOpen() { | 528 | public static String getHashCodeMethodOpen() { |
523 | 529 | ||
524 | - return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 530 | + return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING |
525 | - + UtilConstants.INT + UtilConstants.SPACE + UtilConstants.HASH_CODE_STRING | 531 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
526 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE | 532 | + + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; |
527 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION | ||
528 | - + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.OBJECT_STRING + UtilConstants.SUFIX_S | ||
529 | - + UtilConstants.PERIOD + UtilConstants.HASH + UtilConstants.OPEN_PARENTHESIS; | ||
530 | } | 533 | } |
531 | 534 | ||
532 | /** | 535 | /** |
... | @@ -537,10 +540,10 @@ public final class MethodsGenerator { | ... | @@ -537,10 +540,10 @@ public final class MethodsGenerator { |
537 | */ | 540 | */ |
538 | public static String getHashCodeMethodClose(String hashcodeString) { | 541 | public static String getHashCodeMethodClose(String hashcodeString) { |
539 | 542 | ||
540 | - hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.COMMA); | 543 | + hashcodeString = trimAtLast(hashcodeString, COMMA); |
541 | - hashcodeString = YangIoUtils.trimAtLast(hashcodeString, UtilConstants.SPACE); | 544 | + hashcodeString = trimAtLast(hashcodeString, SPACE); |
542 | - return hashcodeString + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | 545 | + return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
543 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; | 546 | + + NEW_LINE; |
544 | } | 547 | } |
545 | 548 | ||
546 | /** | 549 | /** |
... | @@ -551,13 +554,7 @@ public final class MethodsGenerator { | ... | @@ -551,13 +554,7 @@ public final class MethodsGenerator { |
551 | */ | 554 | */ |
552 | public static String getHashCodeMethod(JavaAttributeInfo attr) { | 555 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
553 | 556 | ||
554 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 557 | + return getLowerCase(attr.getAttributeName()) + COMMA + SPACE; |
555 | - if (attr.isListAttr()) { | ||
556 | - attributeName = attributeName + UtilConstants.SUFIX_S; | ||
557 | - } | ||
558 | - return attributeName | ||
559 | - + UtilConstants.COMMA + UtilConstants.SPACE; | ||
560 | - | ||
561 | } | 558 | } |
562 | 559 | ||
563 | /** | 560 | /** |
... | @@ -568,12 +565,9 @@ public final class MethodsGenerator { | ... | @@ -568,12 +565,9 @@ public final class MethodsGenerator { |
568 | */ | 565 | */ |
569 | public static String getEqualsMethodOpen(String className) { | 566 | public static String getEqualsMethodOpen(String className) { |
570 | 567 | ||
571 | - return getOverRideString() + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE | 568 | + return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING |
572 | - + UtilConstants.BOOLEAN + UtilConstants.SPACE + UtilConstants.EQUALS_STRING | 569 | + + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
573 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.OBJECT_STRING + UtilConstants.SPACE + UtilConstants.OBJ | 570 | + + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); |
574 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | ||
575 | - + UtilConstants.NEW_LINE + getEqualsMethodsCommonIfCondition() | ||
576 | - + getEqualsMethodsSpecificIfCondition(className); | ||
577 | } | 571 | } |
578 | 572 | ||
579 | /** | 573 | /** |
... | @@ -583,13 +577,9 @@ public final class MethodsGenerator { | ... | @@ -583,13 +577,9 @@ public final class MethodsGenerator { |
583 | */ | 577 | */ |
584 | private static String getEqualsMethodsCommonIfCondition() { | 578 | private static String getEqualsMethodsCommonIfCondition() { |
585 | 579 | ||
586 | - return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.IF + UtilConstants.SPACE | 580 | + return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ |
587 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.THIS + UtilConstants.SPACE + UtilConstants.EQUAL | 581 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE |
588 | - + UtilConstants.EQUAL + UtilConstants.SPACE + UtilConstants.OBJ + UtilConstants.CLOSE_PARENTHESIS | 582 | + + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
589 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE | ||
590 | - + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE | ||
591 | - + UtilConstants.TRUE + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
592 | - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
593 | } | 583 | } |
594 | 584 | ||
595 | /** | 585 | /** |
... | @@ -600,14 +590,10 @@ public final class MethodsGenerator { | ... | @@ -600,14 +590,10 @@ public final class MethodsGenerator { |
600 | */ | 590 | */ |
601 | private static String getEqualsMethodsSpecificIfCondition(String className) { | 591 | private static String getEqualsMethodsSpecificIfCondition(String className) { |
602 | 592 | ||
603 | - return UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.IF + UtilConstants.SPACE | 593 | + return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className |
604 | - + UtilConstants.OPEN_PARENTHESIS + UtilConstants.OBJ + UtilConstants.INSTANCE_OF + className | 594 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className |
605 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | 595 | + + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE |
606 | - + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION + className + UtilConstants.SPACE | 596 | + + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE; |
607 | - + UtilConstants.OTHER + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE | ||
608 | - + UtilConstants.OPEN_PARENTHESIS + className + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE | ||
609 | - + UtilConstants.OBJ + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
610 | - + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.NEW_LINE; | ||
611 | } | 597 | } |
612 | 598 | ||
613 | /** | 599 | /** |
... | @@ -618,17 +604,13 @@ public final class MethodsGenerator { | ... | @@ -618,17 +604,13 @@ public final class MethodsGenerator { |
618 | */ | 604 | */ |
619 | public static String getEqualsMethodClose(String equalMethodString) { | 605 | public static String getEqualsMethodClose(String equalMethodString) { |
620 | 606 | ||
621 | - equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.AND); | 607 | + equalMethodString = trimAtLast(equalMethodString, AND); |
622 | - equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.AND); | 608 | + equalMethodString = trimAtLast(equalMethodString, AND); |
623 | - equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.SPACE); | 609 | + equalMethodString = trimAtLast(equalMethodString, SPACE); |
624 | - equalMethodString = YangIoUtils.trimAtLast(equalMethodString, UtilConstants.NEW_LINE) + UtilConstants.SEMI_COLAN | 610 | + equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE; |
625 | - + UtilConstants.NEW_LINE; | 611 | + return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
626 | - return equalMethodString + UtilConstants.EIGHT_SPACE_INDENTATION | 612 | + + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
627 | - + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE | 613 | + + NEW_LINE; |
628 | - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE | ||
629 | - + UtilConstants.FALSE + UtilConstants.SEMI_COLAN | ||
630 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | ||
631 | - + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
632 | } | 614 | } |
633 | 615 | ||
634 | /** | 616 | /** |
... | @@ -639,15 +621,11 @@ public final class MethodsGenerator { | ... | @@ -639,15 +621,11 @@ public final class MethodsGenerator { |
639 | */ | 621 | */ |
640 | public static String getEqualsMethod(JavaAttributeInfo attr) { | 622 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
641 | 623 | ||
642 | - String attributeName = JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()); | 624 | + String attributeName = getLowerCase(attr.getAttributeName()); |
643 | - if (attr.isListAttr()) { | 625 | + |
644 | - attributeName = attributeName + UtilConstants.SUFIX_S; | 626 | + return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
645 | - } | 627 | + + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND |
646 | - return UtilConstants.SIXTEEN_SPACE_INDENTATION + UtilConstants.SPACE + UtilConstants.OBJECT_STRING | 628 | + + AND; |
647 | - + UtilConstants.SUFIX_S + UtilConstants.PERIOD + UtilConstants.EQUALS_STRING | ||
648 | - + UtilConstants.OPEN_PARENTHESIS + attributeName + UtilConstants.COMMA + UtilConstants.SPACE | ||
649 | - + UtilConstants.OTHER + UtilConstants.PERIOD + attributeName + UtilConstants.CLOSE_PARENTHESIS | ||
650 | - + UtilConstants.SPACE + UtilConstants.AND + UtilConstants.AND; | ||
651 | 629 | ||
652 | } | 630 | } |
653 | 631 | ||
... | @@ -662,14 +640,10 @@ public final class MethodsGenerator { | ... | @@ -662,14 +640,10 @@ public final class MethodsGenerator { |
662 | 640 | ||
663 | String attrQuaifiedType = getReturnType(attr); | 641 | String attrQuaifiedType = getReturnType(attr); |
664 | 642 | ||
665 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.STATIC | 643 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS |
666 | - + UtilConstants.SPACE + name + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.OPEN_PARENTHESIS | 644 | + + attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
667 | - + attrQuaifiedType + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.CLOSE_PARENTHESIS | 645 | + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
668 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE | 646 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
669 | - + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.NEW | ||
670 | - + UtilConstants.SPACE + name + UtilConstants.OPEN_PARENTHESIS + UtilConstants.VALUE | ||
671 | - + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE | ||
672 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
673 | } | 647 | } |
674 | 648 | ||
675 | } | 649 | } | ... | ... |
... | @@ -83,7 +83,7 @@ public final class UtilConstants { | ... | @@ -83,7 +83,7 @@ public final class UtilConstants { |
83 | public static final String INSTANCE_OF = " instanceof "; | 83 | public static final String INSTANCE_OF = " instanceof "; |
84 | 84 | ||
85 | public static final String VALUE = "value"; | 85 | public static final String VALUE = "value"; |
86 | - public static final String SUFIX_S = "s"; | 86 | + public static final String SUFFIX_S = "s"; |
87 | 87 | ||
88 | public static final String IF = "if"; | 88 | public static final String IF = "if"; |
89 | public static final String FOR = "for"; | 89 | public static final String FOR = "for"; |
... | @@ -152,7 +152,7 @@ public final class UtilConstants { | ... | @@ -152,7 +152,7 @@ public final class UtilConstants { |
152 | /** | 152 | /** |
153 | * String built in java type. | 153 | * String built in java type. |
154 | */ | 154 | */ |
155 | - public static final String STRING = "String"; | 155 | + public static final String STRING_DATA_TYPE = "String"; |
156 | /** | 156 | /** |
157 | * java.lang.* packages. | 157 | * java.lang.* packages. |
158 | */ | 158 | */ |
... | @@ -161,7 +161,7 @@ public final class UtilConstants { | ... | @@ -161,7 +161,7 @@ public final class UtilConstants { |
161 | /** | 161 | /** |
162 | * boolean built in java type. | 162 | * boolean built in java type. |
163 | */ | 163 | */ |
164 | - public static final String BOOLEAN = "boolean"; | 164 | + public static final String BOOLEAN_DATA_TYPE = "boolean"; |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * byte java built in type. | 167 | * byte java built in type. |
... | @@ -229,8 +229,7 @@ public final class UtilConstants { | ... | @@ -229,8 +229,7 @@ public final class UtilConstants { |
229 | public static final String DOUBLE_WRAPPER = "Double"; | 229 | public static final String DOUBLE_WRAPPER = "Double"; |
230 | 230 | ||
231 | /** | 231 | /** |
232 | - * List of keywords in java, this is used for checking if the input does not | 232 | + * List of keywords in java, this is used for checking if the input does not contain these keywords. |
233 | - * contain these keywords. | ||
234 | */ | 233 | */ |
235 | public static final List JAVA_KEY_WORDS = Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case", | 234 | public static final List JAVA_KEY_WORDS = Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case", |
236 | "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", | 235 | "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", | ... | ... |
... | @@ -24,12 +24,16 @@ import java.io.IOException; | ... | @@ -24,12 +24,16 @@ import java.io.IOException; |
24 | import java.io.InputStream; | 24 | import java.io.InputStream; |
25 | import java.io.OutputStream; | 25 | import java.io.OutputStream; |
26 | 26 | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
28 | + | ||
27 | /** | 29 | /** |
28 | * Provides the license header for the generated files. | 30 | * Provides the license header for the generated files. |
29 | */ | 31 | */ |
30 | public final class CopyrightHeader { | 32 | public final class CopyrightHeader { |
31 | 33 | ||
32 | private static final int EOF = -1; | 34 | private static final int EOF = -1; |
35 | + private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt"; | ||
36 | + private static final String TEMP_FILE = "temp.txt"; | ||
33 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); | 37 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); |
34 | 38 | ||
35 | private static String copyrightHeader; | 39 | private static String copyrightHeader; |
... | @@ -47,6 +51,7 @@ public final class CopyrightHeader { | ... | @@ -47,6 +51,7 @@ public final class CopyrightHeader { |
47 | * @throws IOException when fails to parse copyright header | 51 | * @throws IOException when fails to parse copyright header |
48 | */ | 52 | */ |
49 | public static String getCopyrightHeader() throws IOException { | 53 | public static String getCopyrightHeader() throws IOException { |
54 | + | ||
50 | if (copyrightHeader == null) { | 55 | if (copyrightHeader == null) { |
51 | parseCopyrightHeader(); | 56 | parseCopyrightHeader(); |
52 | } | 57 | } |
... | @@ -59,6 +64,7 @@ public final class CopyrightHeader { | ... | @@ -59,6 +64,7 @@ public final class CopyrightHeader { |
59 | * @param header copyright header | 64 | * @param header copyright header |
60 | */ | 65 | */ |
61 | private static void setCopyrightHeader(String header) { | 66 | private static void setCopyrightHeader(String header) { |
67 | + | ||
62 | copyrightHeader = header; | 68 | copyrightHeader = header; |
63 | } | 69 | } |
64 | 70 | ||
... | @@ -69,11 +75,12 @@ public final class CopyrightHeader { | ... | @@ -69,11 +75,12 @@ public final class CopyrightHeader { |
69 | */ | 75 | */ |
70 | public static void parseCopyrightHeader() throws IOException { | 76 | public static void parseCopyrightHeader() throws IOException { |
71 | 77 | ||
72 | - File temp = new File("temp.txt"); | 78 | + File temp = new File(TEMP_FILE); |
73 | 79 | ||
74 | try { | 80 | try { |
75 | - InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt"); | 81 | + InputStream stream = classLoader.getResourceAsStream(COPYRIGHT_HEADER_FILE); |
76 | OutputStream out = new FileOutputStream(temp); | 82 | OutputStream out = new FileOutputStream(temp); |
83 | + | ||
77 | int index; | 84 | int index; |
78 | while ((index = stream.read()) != EOF) { | 85 | while ((index = stream.read()) != EOF) { |
79 | out.write(index); | 86 | out.write(index); |
... | @@ -98,18 +105,20 @@ public final class CopyrightHeader { | ... | @@ -98,18 +105,20 @@ public final class CopyrightHeader { |
98 | */ | 105 | */ |
99 | private static String getStringFileContent(File toAppend) throws IOException { | 106 | private static String getStringFileContent(File toAppend) throws IOException { |
100 | 107 | ||
101 | - BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend)); | 108 | + FileReader fileReader = new FileReader(toAppend); |
109 | + BufferedReader bufferReader = new BufferedReader(fileReader); | ||
102 | try { | 110 | try { |
103 | StringBuilder stringBuilder = new StringBuilder(); | 111 | StringBuilder stringBuilder = new StringBuilder(); |
104 | String line = bufferReader.readLine(); | 112 | String line = bufferReader.readLine(); |
105 | 113 | ||
106 | while (line != null) { | 114 | while (line != null) { |
107 | stringBuilder.append(line); | 115 | stringBuilder.append(line); |
108 | - stringBuilder.append("\n"); | 116 | + stringBuilder.append(NEW_LINE); |
109 | line = bufferReader.readLine(); | 117 | line = bufferReader.readLine(); |
110 | } | 118 | } |
111 | return stringBuilder.toString(); | 119 | return stringBuilder.toString(); |
112 | } finally { | 120 | } finally { |
121 | + fileReader.close(); | ||
113 | bufferReader.close(); | 122 | bufferReader.close(); |
114 | } | 123 | } |
115 | } | 124 | } | ... | ... |
... | @@ -23,7 +23,17 @@ import java.io.FileWriter; | ... | @@ -23,7 +23,17 @@ import java.io.FileWriter; |
23 | import java.io.IOException; | 23 | import java.io.IOException; |
24 | import java.io.PrintWriter; | 24 | import java.io.PrintWriter; |
25 | 25 | ||
26 | -import org.onosproject.yangutils.utils.UtilConstants; | 26 | +import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
27 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
33 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | ||
34 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg; | ||
35 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
36 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories; | ||
27 | 37 | ||
28 | /** | 38 | /** |
29 | * Utility to handle file system operations. | 39 | * Utility to handle file system operations. |
... | @@ -44,8 +54,8 @@ public final class FileSystemUtil { | ... | @@ -44,8 +54,8 @@ public final class FileSystemUtil { |
44 | */ | 54 | */ |
45 | public static boolean doesPackageExist(String pkg) { | 55 | public static boolean doesPackageExist(String pkg) { |
46 | 56 | ||
47 | - File pkgDir = new File(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | 57 | + File pkgDir = new File(convertPkgToPath(pkg)); |
48 | - File pkgWithFile = new File(pkgDir + File.separator + "package-info.java"); | 58 | + File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); |
49 | if (pkgDir.exists() && pkgWithFile.isFile()) { | 59 | if (pkgDir.exists() && pkgWithFile.isFile()) { |
50 | return true; | 60 | return true; |
51 | } | 61 | } |
... | @@ -63,8 +73,8 @@ public final class FileSystemUtil { | ... | @@ -63,8 +73,8 @@ public final class FileSystemUtil { |
63 | 73 | ||
64 | if (!doesPackageExist(pkg)) { | 74 | if (!doesPackageExist(pkg)) { |
65 | try { | 75 | try { |
66 | - File pack = YangIoUtils.createDirectories(pkg); | 76 | + File pack = createDirectories(pkg); |
67 | - YangIoUtils.addPackageInfo(pack, pkgInfo, pkg.replace(UtilConstants.SLASH, UtilConstants.PERIOD)); | 77 | + addPackageInfo(pack, pkgInfo, convertPathToPkg(pkg)); |
68 | } catch (IOException e) { | 78 | } catch (IOException e) { |
69 | throw new IOException("failed to create package-info file"); | 79 | throw new IOException("failed to create package-info file"); |
70 | } | 80 | } |
... | @@ -83,9 +93,7 @@ public final class FileSystemUtil { | ... | @@ -83,9 +93,7 @@ public final class FileSystemUtil { |
83 | */ | 93 | */ |
84 | public static void appendFileContents(File toAppend, File srcFile) throws IOException { | 94 | public static void appendFileContents(File toAppend, File srcFile) throws IOException { |
85 | 95 | ||
86 | - updateFileHandle(srcFile, | 96 | + updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false); |
87 | - UtilConstants.NEW_LINE + readAppendFile(toAppend.toString(), UtilConstants.FOUR_SPACE_INDENTATION), | ||
88 | - false); | ||
89 | return; | 97 | return; |
90 | } | 98 | } |
91 | 99 | ||
... | @@ -106,15 +114,14 @@ public final class FileSystemUtil { | ... | @@ -106,15 +114,14 @@ public final class FileSystemUtil { |
106 | String line = bufferReader.readLine(); | 114 | String line = bufferReader.readLine(); |
107 | 115 | ||
108 | while (line != null) { | 116 | while (line != null) { |
109 | - if (line.equals(UtilConstants.SPACE) | line.equals(UtilConstants.EMPTY_STRING) | 117 | + if (line.equals(SPACE) | line.equals(EMPTY_STRING) | line.equals(EIGHT_SPACE_INDENTATION) |
110 | - | line.equals(UtilConstants.EIGHT_SPACE_INDENTATION) | 118 | + | line.equals(MULTIPLE_NEW_LINE)) { |
111 | - | line.equals(UtilConstants.MULTIPLE_NEW_LINE)) { | 119 | + stringBuilder.append(NEW_LINE); |
112 | - stringBuilder.append(UtilConstants.NEW_LINE); | 120 | + } else if (line.equals(FOUR_SPACE_INDENTATION)) { |
113 | - } else if (line.equals(UtilConstants.FOUR_SPACE_INDENTATION)) { | 121 | + stringBuilder.append(EMPTY_STRING); |
114 | - stringBuilder.append(UtilConstants.EMPTY_STRING); | ||
115 | } else { | 122 | } else { |
116 | stringBuilder.append(spaces + line); | 123 | stringBuilder.append(spaces + line); |
117 | - stringBuilder.append(UtilConstants.NEW_LINE); | 124 | + stringBuilder.append(NEW_LINE); |
118 | } | 125 | } |
119 | line = bufferReader.readLine(); | 126 | line = bufferReader.readLine(); |
120 | } | 127 | } |
... | @@ -131,9 +138,8 @@ public final class FileSystemUtil { | ... | @@ -131,9 +138,8 @@ public final class FileSystemUtil { |
131 | * @param inputFile input file | 138 | * @param inputFile input file |
132 | * @param contentTobeAdded content to be appended to the file | 139 | * @param contentTobeAdded content to be appended to the file |
133 | * @param isClose when close of file is called. | 140 | * @param isClose when close of file is called. |
134 | - * @throws IOException if the named file exists but is a directory rather | 141 | + * @throws IOException if the named file exists but is a directory rather than a regular file, |
135 | - * than a regular file, does not exist but cannot be created, or | 142 | + * does not exist but cannot be created, or cannot be opened for any other reason |
136 | - * cannot be opened for any other reason | ||
137 | */ | 143 | */ |
138 | public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { | 144 | public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { |
139 | 145 | ... | ... |
... | @@ -19,6 +19,36 @@ package org.onosproject.yangutils.utils.io.impl; | ... | @@ -19,6 +19,36 @@ 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 | import org.onosproject.yangutils.utils.UtilConstants; | 20 | import org.onosproject.yangutils.utils.UtilConstants; |
21 | 21 | ||
22 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
23 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; | ||
24 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN; | ||
32 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ESTRIC; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.OF; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
50 | +import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | ||
51 | + | ||
22 | /** | 52 | /** |
23 | * Provides javadoc for the generated classes. | 53 | * Provides javadoc for the generated classes. |
24 | */ | 54 | */ |
... | @@ -63,17 +93,17 @@ public final class JavaDocGen { | ... | @@ -63,17 +93,17 @@ public final class JavaDocGen { |
63 | /** | 93 | /** |
64 | * For getters. | 94 | * For getters. |
65 | */ | 95 | */ |
66 | - GETTER, | 96 | + GETTER_METHOD, |
67 | 97 | ||
68 | /** | 98 | /** |
69 | * For setters. | 99 | * For setters. |
70 | */ | 100 | */ |
71 | - SETTER, | 101 | + SETTER_METHOD, |
72 | 102 | ||
73 | /** | 103 | /** |
74 | * For type def's setters. | 104 | * For type def's setters. |
75 | */ | 105 | */ |
76 | - TYPE_DEF_SETTER, | 106 | + TYPE_DEF_SETTER_METHOD, |
77 | 107 | ||
78 | /** | 108 | /** |
79 | * For type def's constructor. | 109 | * For type def's constructor. |
... | @@ -83,7 +113,7 @@ public final class JavaDocGen { | ... | @@ -83,7 +113,7 @@ public final class JavaDocGen { |
83 | /** | 113 | /** |
84 | * For of method. | 114 | * For of method. |
85 | */ | 115 | */ |
86 | - OF, | 116 | + OF_METHOD, |
87 | 117 | ||
88 | /** | 118 | /** |
89 | * For default constructor. | 119 | * For default constructor. |
... | @@ -98,7 +128,7 @@ public final class JavaDocGen { | ... | @@ -98,7 +128,7 @@ public final class JavaDocGen { |
98 | /** | 128 | /** |
99 | * For build. | 129 | * For build. |
100 | */ | 130 | */ |
101 | - BUILD | 131 | + BUILD_METHOD |
102 | } | 132 | } |
103 | 133 | ||
104 | /** | 134 | /** |
... | @@ -110,8 +140,9 @@ public final class JavaDocGen { | ... | @@ -110,8 +140,9 @@ public final class JavaDocGen { |
110 | * @return javadocs. | 140 | * @return javadocs. |
111 | */ | 141 | */ |
112 | public static String getJavaDoc(JavaDocType type, String name, boolean isList) { | 142 | public static String getJavaDoc(JavaDocType type, String name, boolean isList) { |
143 | + | ||
113 | name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name)); | 144 | name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name)); |
114 | - String javaDoc = ""; | 145 | + String javaDoc = UtilConstants.EMPTY_STRING; |
115 | if (type.equals(JavaDocType.IMPL_CLASS)) { | 146 | if (type.equals(JavaDocType.IMPL_CLASS)) { |
116 | javaDoc = generateForImplClass(name); | 147 | javaDoc = generateForImplClass(name); |
117 | } else if (type.equals(JavaDocType.BUILDER_CLASS)) { | 148 | } else if (type.equals(JavaDocType.BUILDER_CLASS)) { |
... | @@ -122,19 +153,19 @@ public final class JavaDocGen { | ... | @@ -122,19 +153,19 @@ public final class JavaDocGen { |
122 | javaDoc = generateForBuilderInterface(name); | 153 | javaDoc = generateForBuilderInterface(name); |
123 | } else if (type.equals(JavaDocType.PACKAGE_INFO)) { | 154 | } else if (type.equals(JavaDocType.PACKAGE_INFO)) { |
124 | javaDoc = generateForPackage(name); | 155 | javaDoc = generateForPackage(name); |
125 | - } else if (type.equals(JavaDocType.GETTER)) { | 156 | + } else if (type.equals(JavaDocType.GETTER_METHOD)) { |
126 | javaDoc = generateForGetters(name, isList); | 157 | javaDoc = generateForGetters(name, isList); |
127 | - } else if (type.equals(JavaDocType.TYPE_DEF_SETTER)) { | 158 | + } else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) { |
128 | javaDoc = generateForTypeDefSetter(name); | 159 | javaDoc = generateForTypeDefSetter(name); |
129 | } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) { | 160 | } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) { |
130 | javaDoc = generateForTypeDefConstructor(name); | 161 | javaDoc = generateForTypeDefConstructor(name); |
131 | - } else if (type.equals(JavaDocType.SETTER)) { | 162 | + } else if (type.equals(JavaDocType.SETTER_METHOD)) { |
132 | javaDoc = generateForSetters(name, isList); | 163 | javaDoc = generateForSetters(name, isList); |
133 | - } else if (type.equals(JavaDocType.OF)) { | 164 | + } else if (type.equals(JavaDocType.OF_METHOD)) { |
134 | javaDoc = generateForOf(name); | 165 | javaDoc = generateForOf(name); |
135 | } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { | 166 | } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { |
136 | javaDoc = generateForDefaultConstructors(); | 167 | javaDoc = generateForDefaultConstructors(); |
137 | - } else if (type.equals(JavaDocType.BUILD)) { | 168 | + } else if (type.equals(JavaDocType.BUILD_METHOD)) { |
138 | javaDoc = generateForBuild(name); | 169 | javaDoc = generateForBuild(name); |
139 | } else { | 170 | } else { |
140 | javaDoc = generateForConstructors(name); | 171 | javaDoc = generateForConstructors(name); |
... | @@ -150,19 +181,18 @@ public final class JavaDocGen { | ... | @@ -150,19 +181,18 @@ public final class JavaDocGen { |
150 | * @return javaDocs | 181 | * @return javaDocs |
151 | */ | 182 | */ |
152 | private static String generateForGetters(String attribute, boolean isList) { | 183 | private static String generateForGetters(String attribute, boolean isList) { |
153 | - String getter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 184 | + |
154 | - + UtilConstants.JAVA_DOC_FIRST_LINE | 185 | + String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
155 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute | 186 | + + JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC |
156 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 187 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN; |
157 | - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN; | ||
158 | if (isList) { | 188 | if (isList) { |
159 | - String listAttribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF | 189 | + String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; |
160 | - + UtilConstants.SPACE; | ||
161 | getter = getter + listAttribute; | 190 | getter = getter + listAttribute; |
191 | + } else { | ||
192 | + getter = getter + VALUE + SPACE + OF + SPACE; | ||
162 | } | 193 | } |
163 | 194 | ||
164 | - getter = getter + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 195 | + getter = getter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
165 | - + UtilConstants.JAVA_DOC_END_LINE; | ||
166 | return getter; | 196 | return getter; |
167 | } | 197 | } |
168 | 198 | ||
... | @@ -174,23 +204,18 @@ public final class JavaDocGen { | ... | @@ -174,23 +204,18 @@ public final class JavaDocGen { |
174 | * @return javaDocs | 204 | * @return javaDocs |
175 | */ | 205 | */ |
176 | private static String generateForSetters(String attribute, boolean isList) { | 206 | private static String generateForSetters(String attribute, boolean isList) { |
177 | - String setter = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 207 | + |
178 | - + UtilConstants.JAVA_DOC_FIRST_LINE | 208 | + String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
179 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute | 209 | + + JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC |
180 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 210 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE; |
181 | - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM; | ||
182 | if (isList) { | 211 | if (isList) { |
183 | - setter = setter + attribute + UtilConstants.SUFIX_S + UtilConstants.SPACE; | 212 | + String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; |
184 | - String listAttribute = UtilConstants.LIST.toLowerCase() + UtilConstants.SPACE + UtilConstants.OF | ||
185 | - + UtilConstants.SPACE; | ||
186 | setter = setter + listAttribute; | 213 | setter = setter + listAttribute; |
187 | } else { | 214 | } else { |
188 | - setter = setter + attribute + UtilConstants.SPACE; | 215 | + setter = setter + VALUE + SPACE + OF + SPACE; |
189 | } | 216 | } |
190 | - | 217 | + setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT + attribute |
191 | - setter = setter + attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 218 | + + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
192 | - + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT + attribute + UtilConstants.NEW_LINE | ||
193 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
194 | return setter; | 219 | return setter; |
195 | } | 220 | } |
196 | 221 | ||
... | @@ -201,14 +226,12 @@ public final class JavaDocGen { | ... | @@ -201,14 +226,12 @@ public final class JavaDocGen { |
201 | * @return javaDocs | 226 | * @return javaDocs |
202 | */ | 227 | */ |
203 | private static String generateForOf(String attribute) { | 228 | private static String generateForOf(String attribute) { |
204 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 229 | + |
205 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_OF + attribute | 230 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF |
206 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 231 | + + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION |
207 | - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM | 232 | + + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
208 | - + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE | 233 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE |
209 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.OBJECT | 234 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
210 | - + UtilConstants.SPACE + UtilConstants.OF + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE | ||
211 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
212 | } | 235 | } |
213 | 236 | ||
214 | /** | 237 | /** |
... | @@ -218,12 +241,11 @@ public final class JavaDocGen { | ... | @@ -218,12 +241,11 @@ public final class JavaDocGen { |
218 | * @return javaDocs | 241 | * @return javaDocs |
219 | */ | 242 | */ |
220 | private static String generateForTypeDefSetter(String attribute) { | 243 | private static String generateForTypeDefSetter(String attribute) { |
221 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 244 | + |
222 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS_COMMON + attribute | 245 | + return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
223 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 246 | + + JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC |
224 | - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM | 247 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute |
225 | - + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE | 248 | + + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); |
226 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
227 | } | 249 | } |
228 | 250 | ||
229 | /** | 251 | /** |
... | @@ -233,12 +255,11 @@ public final class JavaDocGen { | ... | @@ -233,12 +255,11 @@ public final class JavaDocGen { |
233 | * @return javaDocs | 255 | * @return javaDocs |
234 | */ | 256 | */ |
235 | private static String generateForTypeDefConstructor(String attribute) { | 257 | private static String generateForTypeDefConstructor(String attribute) { |
236 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 258 | + |
237 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_CONSTRUCTOR + attribute | 259 | + return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR |
238 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION | 260 | + + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION |
239 | - + UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM | 261 | + + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
240 | - + UtilConstants.VALUE + UtilConstants.SPACE + UtilConstants.VALUE + UtilConstants.NEW_LINE | 262 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); |
241 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
242 | } | 263 | } |
243 | 264 | ||
244 | /** | 265 | /** |
... | @@ -248,8 +269,8 @@ public final class JavaDocGen { | ... | @@ -248,8 +269,8 @@ public final class JavaDocGen { |
248 | * @return javaDocs | 269 | * @return javaDocs |
249 | */ | 270 | */ |
250 | private static String generateForImplClass(String className) { | 271 | private static String generateForImplClass(String className) { |
251 | - return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC | 272 | + |
252 | - + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 273 | + return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
253 | } | 274 | } |
254 | 275 | ||
255 | /** | 276 | /** |
... | @@ -259,8 +280,9 @@ public final class JavaDocGen { | ... | @@ -259,8 +280,9 @@ public final class JavaDocGen { |
259 | * @return javaDocs | 280 | * @return javaDocs |
260 | */ | 281 | */ |
261 | private static String generateForBuilderClass(String className) { | 282 | private static String generateForBuilderClass(String className) { |
262 | - return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC | 283 | + |
263 | - + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 284 | + return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE |
285 | + + JAVA_DOC_END_LINE; | ||
264 | } | 286 | } |
265 | 287 | ||
266 | /** | 288 | /** |
... | @@ -270,8 +292,9 @@ public final class JavaDocGen { | ... | @@ -270,8 +292,9 @@ public final class JavaDocGen { |
270 | * @return javaDocs | 292 | * @return javaDocs |
271 | */ | 293 | */ |
272 | private static String generateForInterface(String interfaceName) { | 294 | private static String generateForInterface(String interfaceName) { |
273 | - return UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC | 295 | + |
274 | - + interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 296 | + return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE |
297 | + + JAVA_DOC_END_LINE; | ||
275 | } | 298 | } |
276 | 299 | ||
277 | /** | 300 | /** |
... | @@ -281,8 +304,9 @@ public final class JavaDocGen { | ... | @@ -281,8 +304,9 @@ public final class JavaDocGen { |
281 | * @return javaDocs | 304 | * @return javaDocs |
282 | */ | 305 | */ |
283 | private static String generateForBuilderInterface(String builderforName) { | 306 | private static String generateForBuilderInterface(String builderforName) { |
284 | - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_INTERFACE_JAVA_DOC + builderforName | 307 | + |
285 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 308 | + return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE |
309 | + + JAVA_DOC_END_LINE; | ||
286 | } | 310 | } |
287 | 311 | ||
288 | /** | 312 | /** |
... | @@ -292,8 +316,8 @@ public final class JavaDocGen { | ... | @@ -292,8 +316,8 @@ public final class JavaDocGen { |
292 | * @return javaDocs | 316 | * @return javaDocs |
293 | */ | 317 | */ |
294 | private static String generateForPackage(String packageName) { | 318 | private static String generateForPackage(String packageName) { |
295 | - return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.PACKAGE_INFO_JAVADOC + packageName | 319 | + |
296 | - + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE; | 320 | + return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
297 | } | 321 | } |
298 | 322 | ||
299 | /** | 323 | /** |
... | @@ -302,9 +326,9 @@ public final class JavaDocGen { | ... | @@ -302,9 +326,9 @@ public final class JavaDocGen { |
302 | * @return javaDocs | 326 | * @return javaDocs |
303 | */ | 327 | */ |
304 | private static String generateForDefaultConstructors() { | 328 | private static String generateForDefaultConstructors() { |
305 | - return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 329 | + |
306 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR | 330 | + return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_DEFAULT_CONSTRUCTOR |
307 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | 331 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
308 | } | 332 | } |
309 | 333 | ||
310 | /** | 334 | /** |
... | @@ -314,14 +338,12 @@ public final class JavaDocGen { | ... | @@ -314,14 +338,12 @@ public final class JavaDocGen { |
314 | * @return javaDocs | 338 | * @return javaDocs |
315 | */ | 339 | */ |
316 | private static String generateForConstructors(String className) { | 340 | private static String generateForConstructors(String className) { |
317 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 341 | + |
318 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_CONSTRUCTOR + className | 342 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE |
319 | - + UtilConstants.IMPL + UtilConstants.PERIOD + UtilConstants.NEW_LINE | 343 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE |
320 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC | 344 | + + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM |
321 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM | 345 | + + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + SPACE + className + NEW_LINE |
322 | - + UtilConstants.BUILDER.toLowerCase() + UtilConstants.OBJECT + UtilConstants.SPACE | 346 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
323 | - + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className + UtilConstants.NEW_LINE | ||
324 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
325 | } | 347 | } |
326 | 348 | ||
327 | /** | 349 | /** |
... | @@ -331,11 +353,10 @@ public final class JavaDocGen { | ... | @@ -331,11 +353,10 @@ public final class JavaDocGen { |
331 | * @return javaDocs | 353 | * @return javaDocs |
332 | */ | 354 | */ |
333 | private static String generateForBuild(String buildName) { | 355 | private static String generateForBuild(String buildName) { |
334 | - return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE | 356 | + |
335 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_BUILD + buildName + UtilConstants.PERIOD | 357 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD |
336 | - + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC | 358 | + + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION |
337 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN | 359 | + + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION |
338 | - + UtilConstants.JAVA_DOC_BUILD_RETURN + buildName + UtilConstants.PERIOD + UtilConstants.NEW_LINE | 360 | + + JAVA_DOC_END_LINE; |
339 | - + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE; | ||
340 | } | 361 | } |
341 | } | 362 | } | ... | ... |
... | @@ -23,10 +23,13 @@ import java.util.List; | ... | @@ -23,10 +23,13 @@ import java.util.List; |
23 | import java.util.Stack; | 23 | import java.util.Stack; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | - * Provides the IO services for Yangutils-maven-Plugin. | 26 | + * Provides utility for searching the files in a directory. |
27 | */ | 27 | */ |
28 | public final class YangFileScanner { | 28 | public final class YangFileScanner { |
29 | 29 | ||
30 | + private static final String JAVA_FILE_EXTENTION = ".java"; | ||
31 | + private static final String YANG_FILE_EXTENTION = ".yang"; | ||
32 | + | ||
30 | /** | 33 | /** |
31 | * Default constructor. | 34 | * Default constructor. |
32 | */ | 35 | */ |
... | @@ -44,7 +47,7 @@ public final class YangFileScanner { | ... | @@ -44,7 +47,7 @@ public final class YangFileScanner { |
44 | */ | 47 | */ |
45 | public static List<String> getJavaFiles(String root) throws NullPointerException, IOException { | 48 | public static List<String> getJavaFiles(String root) throws NullPointerException, IOException { |
46 | 49 | ||
47 | - return getFiles(root, ".java"); | 50 | + return getFiles(root, JAVA_FILE_EXTENTION); |
48 | } | 51 | } |
49 | 52 | ||
50 | /** | 53 | /** |
... | @@ -58,7 +61,7 @@ public final class YangFileScanner { | ... | @@ -58,7 +61,7 @@ public final class YangFileScanner { |
58 | */ | 61 | */ |
59 | public static List<String> getYangFiles(String root) throws NullPointerException, IOException { | 62 | public static List<String> getYangFiles(String root) throws NullPointerException, IOException { |
60 | 63 | ||
61 | - return getFiles(root, ".yang"); | 64 | + return getFiles(root, YANG_FILE_EXTENTION); |
62 | } | 65 | } |
63 | 66 | ||
64 | /** | 67 | /** |
... | @@ -68,8 +71,7 @@ public final class YangFileScanner { | ... | @@ -68,8 +71,7 @@ public final class YangFileScanner { |
68 | * @param extension file extension | 71 | * @param extension file extension |
69 | * @return list of required files | 72 | * @return list of required files |
70 | * @throws NullPointerException when no file is there | 73 | * @throws NullPointerException when no file is there |
71 | - * @throws IOException when files get deleted while performing the | 74 | + * @throws IOException when files get deleted while performing the operations |
72 | - * operations | ||
73 | */ | 75 | */ |
74 | public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { | 76 | public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { |
75 | 77 | ... | ... |
... | @@ -25,13 +25,27 @@ import java.nio.file.StandardCopyOption; | ... | @@ -25,13 +25,27 @@ import java.nio.file.StandardCopyOption; |
25 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
26 | import java.util.List; | 26 | import java.util.List; |
27 | 27 | ||
28 | -import org.apache.commons.io.FileUtils; | ||
29 | import org.apache.maven.model.Resource; | 28 | import org.apache.maven.model.Resource; |
30 | import org.apache.maven.project.MavenProject; | 29 | import org.apache.maven.project.MavenProject; |
31 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
32 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
33 | import org.sonatype.plexus.build.incremental.BuildContext; | 31 | import org.sonatype.plexus.build.incremental.BuildContext; |
34 | 32 | ||
33 | +import static org.apache.commons.io.FileUtils.deleteDirectory; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.ORG; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.TEMP; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES; | ||
46 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; | ||
47 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | ||
48 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; | ||
35 | import static org.slf4j.LoggerFactory.getLogger; | 49 | import static org.slf4j.LoggerFactory.getLogger; |
36 | 50 | ||
37 | /** | 51 | /** |
... | @@ -40,8 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -40,8 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
40 | public final class YangIoUtils { | 54 | public final class YangIoUtils { |
41 | 55 | ||
42 | private static final Logger log = getLogger(YangIoUtils.class); | 56 | private static final Logger log = getLogger(YangIoUtils.class); |
43 | - private static final String TARGET_RESOURCE_PATH = UtilConstants.SLASH + UtilConstants.TEMP + UtilConstants.SLASH | 57 | + private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH; |
44 | - + UtilConstants.YANG_RESOURCES + UtilConstants.SLASH; | ||
45 | 58 | ||
46 | /** | 59 | /** |
47 | * Default constructor. | 60 | * Default constructor. |
... | @@ -72,22 +85,24 @@ public final class YangIoUtils { | ... | @@ -72,22 +85,24 @@ public final class YangIoUtils { |
72 | */ | 85 | */ |
73 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { | 86 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { |
74 | 87 | ||
75 | - if (pack.contains(UtilConstants.ORG)) { | 88 | + if (pack.contains(ORG)) { |
76 | - String[] strArray = pack.split(UtilConstants.ORG); | 89 | + String[] strArray = pack.split(ORG); |
77 | - pack = UtilConstants.ORG + strArray[1]; | 90 | + pack = ORG + strArray[1]; |
78 | } | 91 | } |
79 | try { | 92 | try { |
80 | 93 | ||
81 | - File packageInfo = new File(path + File.separator + "package-info.java"); | 94 | + File packageInfo = new File(path + SLASH + "package-info.java"); |
82 | packageInfo.createNewFile(); | 95 | packageInfo.createNewFile(); |
83 | - FileWriter fileWriter = null; | 96 | + |
84 | - BufferedWriter bufferedWriter = null; | 97 | + FileWriter fileWriter = new FileWriter(packageInfo); |
85 | - fileWriter = new FileWriter(packageInfo); | 98 | + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); |
86 | - bufferedWriter = new BufferedWriter(fileWriter); | 99 | + |
87 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); | 100 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); |
88 | - bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo, false)); | 101 | + bufferedWriter.write(JavaDocGen.getJavaDoc(PACKAGE_INFO, classInfo, false)); |
89 | - bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN); | 102 | + bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); |
103 | + | ||
90 | bufferedWriter.close(); | 104 | bufferedWriter.close(); |
105 | + fileWriter.close(); | ||
91 | } catch (IOException e) { | 106 | } catch (IOException e) { |
92 | throw new IOException("Exception occured while creating package info file."); | 107 | throw new IOException("Exception occured while creating package info file."); |
93 | } | 108 | } |
... | @@ -97,15 +112,16 @@ public final class YangIoUtils { | ... | @@ -97,15 +112,16 @@ public final class YangIoUtils { |
97 | * Cleans the generated directory if already exist in source folder. | 112 | * Cleans the generated directory if already exist in source folder. |
98 | * | 113 | * |
99 | * @param dir generated directory in previous build | 114 | * @param dir generated directory in previous build |
115 | + * @throws IOException when failed to delete directory | ||
100 | */ | 116 | */ |
101 | - public static void clean(String dir) { | 117 | + public static void clean(String dir) throws IOException { |
102 | 118 | ||
103 | File generatedDirectory = new File(dir); | 119 | File generatedDirectory = new File(dir); |
104 | if (generatedDirectory.exists()) { | 120 | if (generatedDirectory.exists()) { |
105 | try { | 121 | try { |
106 | - FileUtils.deleteDirectory(generatedDirectory); | 122 | + deleteDirectory(generatedDirectory); |
107 | } catch (IOException e) { | 123 | } catch (IOException e) { |
108 | - log.info("Failed to delete the generated files in " + generatedDirectory + " directory"); | 124 | + throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory"); |
109 | } | 125 | } |
110 | } | 126 | } |
111 | } | 127 | } |
... | @@ -147,18 +163,17 @@ public final class YangIoUtils { | ... | @@ -147,18 +163,17 @@ public final class YangIoUtils { |
147 | */ | 163 | */ |
148 | public static String partString(String partString) { | 164 | public static String partString(String partString) { |
149 | 165 | ||
150 | - String[] strArray = partString.split(UtilConstants.COMMA); | 166 | + String[] strArray = partString.split(COMMA); |
151 | - String newString = ""; | 167 | + String newString = EMPTY_STRING; |
152 | for (int i = 0; i < strArray.length; i++) { | 168 | for (int i = 0; i < strArray.length; i++) { |
153 | if (i % 4 != 0 || i == 0) { | 169 | if (i % 4 != 0 || i == 0) { |
154 | - newString = newString + strArray[i] + UtilConstants.COMMA; | 170 | + newString = newString + strArray[i] + COMMA; |
155 | } else { | 171 | } else { |
156 | - newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION | 172 | + newString = newString + NEW_LINE + TWELVE_SPACE_INDENTATION |
157 | - + strArray[i] | 173 | + + strArray[i] + COMMA; |
158 | - + UtilConstants.COMMA; | ||
159 | } | 174 | } |
160 | } | 175 | } |
161 | - return trimAtLast(newString, UtilConstants.COMMA); | 176 | + return trimAtLast(newString, COMMA); |
162 | } | 177 | } |
163 | 178 | ||
164 | /** | 179 | /** |
... | @@ -183,13 +198,13 @@ public final class YangIoUtils { | ... | @@ -183,13 +198,13 @@ public final class YangIoUtils { |
183 | public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { | 198 | public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { |
184 | 199 | ||
185 | if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) { | 200 | if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) { |
186 | - pathOfJavaPkg = trimAtLast(pathOfJavaPkg, UtilConstants.SLASH); | 201 | + pathOfJavaPkg = trimAtLast(pathOfJavaPkg, SLASH); |
187 | } | 202 | } |
188 | - String[] strArray = pathOfJavaPkg.split(UtilConstants.SLASH); | 203 | + String[] strArray = pathOfJavaPkg.split(SLASH); |
189 | - if (strArray[0].equals(UtilConstants.EMPTY_STRING)) { | 204 | + if (strArray[0].equals(EMPTY_STRING)) { |
190 | return pathOfJavaPkg; | 205 | return pathOfJavaPkg; |
191 | } else { | 206 | } else { |
192 | - return baseCodeGenPath + File.separator + pathOfJavaPkg; | 207 | + return baseCodeGenPath + SLASH + pathOfJavaPkg; |
193 | } | 208 | } |
194 | } | 209 | } |
195 | 210 | ||
... | @@ -212,8 +227,7 @@ public final class YangIoUtils { | ... | @@ -212,8 +227,7 @@ public final class YangIoUtils { |
212 | * @param yangFiles list of YANG files | 227 | * @param yangFiles list of YANG files |
213 | * @param outputDir project's output directory | 228 | * @param outputDir project's output directory |
214 | * @param project maven project | 229 | * @param project maven project |
215 | - * @throws IOException when fails to copy files to destination resource | 230 | + * @throws IOException when fails to copy files to destination resource directory |
216 | - * directory | ||
217 | */ | 231 | */ |
218 | public static void copyYangFilesToTarget(List<String> yangFiles, String outputDir, MavenProject project) | 232 | public static void copyYangFilesToTarget(List<String> yangFiles, String outputDir, MavenProject project) |
219 | throws IOException { | 233 | throws IOException { |
... | @@ -226,11 +240,11 @@ public final class YangIoUtils { | ... | @@ -226,11 +240,11 @@ public final class YangIoUtils { |
226 | 240 | ||
227 | for (File file : files) { | 241 | for (File file : files) { |
228 | Files.copy(file.toPath(), | 242 | Files.copy(file.toPath(), |
229 | - new File(path + file.getName()).toPath(), | 243 | + (new File(path + file.getName())).toPath(), |
230 | StandardCopyOption.REPLACE_EXISTING); | 244 | StandardCopyOption.REPLACE_EXISTING); |
231 | } | 245 | } |
232 | Resource rsc = new Resource(); | 246 | Resource rsc = new Resource(); |
233 | - rsc.setDirectory(outputDir + UtilConstants.SLASH + UtilConstants.TEMP + UtilConstants.SLASH); | 247 | + rsc.setDirectory(outputDir + SLASH + TEMP + SLASH); |
234 | project.addResource(rsc); | 248 | project.addResource(rsc); |
235 | } | 249 | } |
236 | 250 | ||
... | @@ -248,4 +262,58 @@ public final class YangIoUtils { | ... | @@ -248,4 +262,58 @@ public final class YangIoUtils { |
248 | } | 262 | } |
249 | return files; | 263 | return files; |
250 | } | 264 | } |
265 | + | ||
266 | + /** | ||
267 | + * Merge the temp java files to main java files. | ||
268 | + * | ||
269 | + * @param appendFile temp file | ||
270 | + * @param srcFile main file | ||
271 | + * @throws IOException when fails to append contents | ||
272 | + */ | ||
273 | + public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException { | ||
274 | + | ||
275 | + try { | ||
276 | + appendFileContents(appendFile, srcFile); | ||
277 | + } catch (IOException e) { | ||
278 | + throw new IOException("Failed to append " + appendFile + " in " + srcFile); | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * Insert data in the generated file. | ||
284 | + * | ||
285 | + * @param file file in which need to be inserted | ||
286 | + * @param data data which need to be inserted | ||
287 | + * @throws IOException when fails to insert into file | ||
288 | + */ | ||
289 | + public static void insertDataIntoJavaFile(File file, String data) throws IOException { | ||
290 | + | ||
291 | + try { | ||
292 | + updateFileHandle(file, data, false); | ||
293 | + } catch (IOException e) { | ||
294 | + throw new IOException("Failed to insert in " + file + "file"); | ||
295 | + } | ||
296 | + } | ||
297 | + | ||
298 | + /** | ||
299 | + * Convert directory path in java package format. | ||
300 | + * | ||
301 | + * @param path directory path | ||
302 | + * @return java package | ||
303 | + */ | ||
304 | + public static String convertPathToPkg(String path) { | ||
305 | + | ||
306 | + return path.replace(SLASH, PERIOD); | ||
307 | + } | ||
308 | + | ||
309 | + /** | ||
310 | + * Convert java package in directory path format. | ||
311 | + * | ||
312 | + * @param pkg java package | ||
313 | + * @return directory path | ||
314 | + */ | ||
315 | + public static String convertPkgToPath(String pkg) { | ||
316 | + | ||
317 | + return pkg.replace(PERIOD, SLASH); | ||
318 | + } | ||
251 | } | 319 | } | ... | ... |
... | @@ -16,18 +16,36 @@ | ... | @@ -16,18 +16,36 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import static org.hamcrest.MatcherAssert.assertThat; | ||
20 | -import static org.hamcrest.core.Is.is; | ||
21 | -import static org.junit.Assert.assertNotNull; | ||
22 | - | ||
23 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
24 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
25 | 21 | ||
26 | import org.junit.Test; | 22 | import org.junit.Test; |
27 | -import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType; | ||
28 | -import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; | ||
29 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
30 | -import org.onosproject.yangutils.utils.UtilConstants; | 24 | + |
25 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
26 | +import static org.hamcrest.core.Is.is; | ||
27 | +import static org.junit.Assert.assertNotNull; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
29 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; | ||
30 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | ||
32 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | ||
33 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ||
31 | 49 | ||
32 | /** | 50 | /** |
33 | * Unit test cases for java code snippet generator. | 51 | * Unit test cases for java code snippet generator. |
... | @@ -36,10 +54,8 @@ public class JavaCodeSnippetGenTest { | ... | @@ -36,10 +54,8 @@ public class JavaCodeSnippetGenTest { |
36 | 54 | ||
37 | private static final String PKG_INFO = "org.onosproject.unittest"; | 55 | private static final String PKG_INFO = "org.onosproject.unittest"; |
38 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; | 56 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; |
39 | - private static final int FILE_GEN_TYPE = GeneratedJavaFileType.INTERFACE_MASK; | 57 | + private static final int FILE_GEN_TYPE = INTERFACE_MASK; |
40 | - private static final GeneratedMethodTypes METHOD_GEN_TYPE = GeneratedMethodTypes.GETTER; | ||
41 | private static final String YANG_NAME = "Test"; | 58 | private static final String YANG_NAME = "Test"; |
42 | - private static final String STRING = "String"; | ||
43 | 59 | ||
44 | /** | 60 | /** |
45 | * Unit test for private constructor. | 61 | * Unit test for private constructor. |
... | @@ -54,6 +70,7 @@ public class JavaCodeSnippetGenTest { | ... | @@ -54,6 +70,7 @@ public class JavaCodeSnippetGenTest { |
54 | @Test | 70 | @Test |
55 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 71 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
56 | InstantiationException, IllegalAccessException, InvocationTargetException { | 72 | InstantiationException, IllegalAccessException, InvocationTargetException { |
73 | + | ||
57 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; | 74 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; |
58 | for (Class<?> clazz : classesToConstruct) { | 75 | for (Class<?> clazz : classesToConstruct) { |
59 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 76 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
... | @@ -67,14 +84,14 @@ public class JavaCodeSnippetGenTest { | ... | @@ -67,14 +84,14 @@ public class JavaCodeSnippetGenTest { |
67 | */ | 84 | */ |
68 | @Test | 85 | @Test |
69 | public void testForImportText() { | 86 | public void testForImportText() { |
87 | + | ||
70 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); | 88 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); |
71 | importInfo.setPkgInfo(PKG_INFO); | 89 | importInfo.setPkgInfo(PKG_INFO); |
72 | importInfo.setClassInfo(CLASS_INFO); | 90 | importInfo.setClassInfo(CLASS_INFO); |
73 | 91 | ||
74 | - String imports = JavaCodeSnippetGen.getImportText(importInfo); | 92 | + String imports = getImportText(importInfo); |
75 | 93 | ||
76 | - assertThat(true, is(imports.equals(UtilConstants.IMPORT + PKG_INFO + UtilConstants.PERIOD + CLASS_INFO | 94 | + assertThat(true, is(imports.equals(IMPORT + PKG_INFO + PERIOD + CLASS_INFO + SEMI_COLAN + NEW_LINE))); |
77 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
78 | } | 95 | } |
79 | 96 | ||
80 | /** | 97 | /** |
... | @@ -82,11 +99,10 @@ public class JavaCodeSnippetGenTest { | ... | @@ -82,11 +99,10 @@ public class JavaCodeSnippetGenTest { |
82 | */ | 99 | */ |
83 | @Test | 100 | @Test |
84 | public void testForJavaClassDefStart() { | 101 | public void testForJavaClassDefStart() { |
85 | - String classDef = JavaCodeSnippetGen.getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); | 102 | + |
86 | - assertThat(true, | 103 | + String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); |
87 | - is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE | 104 | + assertThat(true, is(classDef |
88 | - + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | 105 | + .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
89 | - + UtilConstants.NEW_LINE))); | ||
90 | 106 | ||
91 | } | 107 | } |
92 | 108 | ||
... | @@ -95,36 +111,20 @@ public class JavaCodeSnippetGenTest { | ... | @@ -95,36 +111,20 @@ public class JavaCodeSnippetGenTest { |
95 | */ | 111 | */ |
96 | @Test | 112 | @Test |
97 | public void testForListAttribute() { | 113 | public void testForListAttribute() { |
98 | - String listAttribute = JavaCodeSnippetGen.getListAttribute(STRING); | ||
99 | - assertThat(true, is(listAttribute.equals(UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + STRING | ||
100 | - + UtilConstants.DIAMOND_CLOSE_BRACKET))); | ||
101 | - } | ||
102 | 114 | ||
103 | - /** | 115 | + String listAttribute = getListAttribute(STRING_DATA_TYPE); |
104 | - * Unit test case for java class interface definition close. | 116 | + assertThat(true, |
105 | - */ | 117 | + is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET))); |
106 | - @Test | ||
107 | - public void testForJavaClassDefInterfaceClose() { | ||
108 | - String interfaceDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
109 | - assertThat(true, is(interfaceDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
110 | } | 118 | } |
111 | 119 | ||
112 | /** | 120 | /** |
113 | - * Unit test case for java class builder class definition close. | 121 | + * Unit test case for java class interface definition close. |
114 | */ | 122 | */ |
115 | @Test | 123 | @Test |
116 | - public void testForJavaClassDefBuilderClassClose() { | 124 | + public void testForJavaClassDefClose() { |
117 | - String builderClassDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
118 | - assertThat(true, is(builderClassDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
119 | - } | ||
120 | 125 | ||
121 | - /** | 126 | + String interfaceDef = getJavaClassDefClose(); |
122 | - * Unit test case for java class typedef definition close. | 127 | + assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET))); |
123 | - */ | ||
124 | - @Test | ||
125 | - public void testForJavaClassDefTypeDefClose() { | ||
126 | - String typeDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
127 | - assertThat(true, is(typeDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
128 | } | 128 | } |
129 | 129 | ||
130 | /** | 130 | /** |
... | @@ -133,30 +133,22 @@ public class JavaCodeSnippetGenTest { | ... | @@ -133,30 +133,22 @@ public class JavaCodeSnippetGenTest { |
133 | @Test | 133 | @Test |
134 | public void testForJavaAttributeInfo() { | 134 | public void testForJavaAttributeInfo() { |
135 | 135 | ||
136 | - String attributeWithoutTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, UtilConstants.STRING, | 136 | + String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, false); |
137 | - YANG_NAME, false); | 137 | + assertThat(true, is(attributeWithoutTypePkg.equals( |
138 | - assertThat(true, | 138 | + PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
139 | - is(attributeWithoutTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.STRING | 139 | + |
140 | - + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | 140 | + String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, false); |
141 | - String attributeWithTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination( | 141 | + assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD |
142 | - UtilConstants.JAVA_LANG, UtilConstants.STRING, YANG_NAME, false); | 142 | + + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
143 | - assertThat(true, is(attributeWithTypePkg | 143 | + |
144 | - .equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.JAVA_LANG + UtilConstants.PERIOD | 144 | + String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, true); |
145 | - + UtilConstants.STRING + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN | 145 | + assertThat(true, is(attributeWithListPkg.equals( |
146 | - + UtilConstants.NEW_LINE))); | 146 | + PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE |
147 | - String attributeWithListPkg = JavaCodeSnippetGen.getJavaAttributeDefination( | 147 | + + DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
148 | - UtilConstants.JAVA_LANG, UtilConstants.STRING, YANG_NAME, true); | 148 | + |
149 | - assertThat(true, | 149 | + String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, true); |
150 | - is(attributeWithListPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST | 150 | + assertThat(true, is(attributeWithListWithoutPkg.equals( |
151 | - + UtilConstants.DIAMOND_OPEN_BRACKET + UtilConstants.JAVA_LANG + UtilConstants.PERIOD | 151 | + PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE |
152 | - + UtilConstants.STRING + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME | 152 | + + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
153 | - + UtilConstants.SUFIX_S + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
154 | - String attributeWithListWithoutPkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, UtilConstants.STRING, | ||
155 | - YANG_NAME, true); | ||
156 | - assertThat(true, | ||
157 | - is(attributeWithListWithoutPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST | ||
158 | - + UtilConstants.DIAMOND_OPEN_BRACKET + UtilConstants.STRING | ||
159 | - + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME + UtilConstants.SUFIX_S | ||
160 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
161 | } | 153 | } |
162 | } | 154 | } | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.yangutils.translator.tojava.utils; | ||
18 | - | ||
19 | -import java.lang.reflect.Constructor; | ||
20 | -import java.lang.reflect.InvocationTargetException; | ||
21 | - | ||
22 | -import org.junit.Test; | ||
23 | -import org.onosproject.yangutils.datamodel.YangType; | ||
24 | -import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | ||
25 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
26 | - | ||
27 | -import static org.hamcrest.core.Is.is; | ||
28 | -import static org.junit.Assert.assertNotNull; | ||
29 | -import static org.junit.Assert.assertThat; | ||
30 | - | ||
31 | -/** | ||
32 | - * Unit tests for generated methods from the file type. | ||
33 | - */ | ||
34 | -public final class MethodsGeneratorTest { | ||
35 | - | ||
36 | - public static JavaAttributeInfo testAttr; | ||
37 | - public static YangType<?> attrType = new YangType<>(); | ||
38 | - | ||
39 | - /** | ||
40 | - * Unit test for private constructor. | ||
41 | - * | ||
42 | - * @throws SecurityException if any security violation is observed | ||
43 | - * @throws NoSuchMethodException if when the method is not found | ||
44 | - * @throws IllegalArgumentException if there is illegal argument found | ||
45 | - * @throws InstantiationException if instantiation is provoked for the | ||
46 | - * private constructor | ||
47 | - * @throws IllegalAccessException if instance is provoked or a method is | ||
48 | - * provoked | ||
49 | - * @throws InvocationTargetException when an exception occurs by the method | ||
50 | - * or constructor | ||
51 | - */ | ||
52 | - @Test | ||
53 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
54 | - InstantiationException, IllegalAccessException, InvocationTargetException { | ||
55 | - | ||
56 | - Class<?>[] classesToConstruct = { | ||
57 | - MethodsGenerator.class | ||
58 | - }; | ||
59 | - for (Class<?> clazz : classesToConstruct) { | ||
60 | - Constructor<?> constructor = clazz.getDeclaredConstructor(); | ||
61 | - constructor.setAccessible(true); | ||
62 | - assertNotNull(constructor.newInstance()); | ||
63 | - } | ||
64 | - } | ||
65 | - | ||
66 | - // /** | ||
67 | - // * Unit test case for checking the parse builder and typedef constructor. | ||
68 | - // */ | ||
69 | - // @Test | ||
70 | - // public void getParseBuilderInterfaceMethodConstructorTest() { | ||
71 | - // | ||
72 | - // JavaQualifiedTypeInfo forSetter = new JavaQualifiedTypeInfo(); | ||
73 | - // attrType.setDataTypeName("binary"); | ||
74 | - // attrType.getDataTypeName(); | ||
75 | - // attrType.setDataType(YangDataTypes.BINARY); | ||
76 | - // attrType.getDataType(); | ||
77 | - // testAttr.setAttributeName("attributeTest"); | ||
78 | - // testAttr.setAttributeType(attrType); | ||
79 | - // forSetter.setPkgInfo("test1/test3"); | ||
80 | - // forSetter.setClassInfo("This class contains"); | ||
81 | - // testAttr.setImportInfo(forSetter); | ||
82 | - // String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname"); | ||
83 | - // } | ||
84 | - | ||
85 | - /** | ||
86 | - * Unit test case for checking the values received from constructor, default | ||
87 | - * constructor and build string formation. | ||
88 | - */ | ||
89 | - @Test | ||
90 | - public void getValuesTest() { | ||
91 | - | ||
92 | - String stringConstructor = MethodsGenerator.getConstructorString("testname"); | ||
93 | - assertThat(stringConstructor.contains(UtilConstants.JAVA_DOC_CONSTRUCTOR) | ||
94 | - && stringConstructor.contains(UtilConstants.JAVA_DOC_PARAM) | ||
95 | - && stringConstructor.contains(UtilConstants.BUILDER_OBJECT), is(true)); | ||
96 | - String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString("testnameBuilder", "public"); | ||
97 | - assertThat(stringDefaultConstructor.contains(UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR) | ||
98 | - && stringDefaultConstructor.contains(UtilConstants.BUILDER) | ||
99 | - && stringDefaultConstructor.contains("testname"), is(true)); | ||
100 | - String stringBuild = MethodsGenerator.getBuildString("testname"); | ||
101 | - assertThat(stringBuild.contains(UtilConstants.OVERRIDE) && stringBuild.contains(UtilConstants.BUILD) | ||
102 | - && stringBuild.contains(UtilConstants.RETURN), is(true)); | ||
103 | - | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * Unit test for checking the values received for class getter, class and | ||
108 | - * typedef setters with list data type. | ||
109 | - */ | ||
110 | - // @Test | ||
111 | - // public void getGetterSetterTest() { | ||
112 | - // | ||
113 | - // JavaQualifiedTypeInfo forGetterSetter = new JavaQualifiedTypeInfo(); | ||
114 | - // attrType.setDataTypeName("int"); | ||
115 | - // attrType.getDataTypeName(); | ||
116 | - // attrType.setDataType(YangDataTypes.UINT8); | ||
117 | - // attrType.getDataType(); | ||
118 | - // testAttr.setAttributeName("AttributeTest1"); | ||
119 | - // testAttr.setAttributeType(attrType); | ||
120 | - // forGetterSetter.setPkgInfo("null"); | ||
121 | - // forGetterSetter.setClassInfo("This class contains"); | ||
122 | - // testAttr.setImportInfo(forGetterSetter); | ||
123 | - // testAttr.setListAttr(true); | ||
124 | - // String getterForClass = MethodsGenerator.getGetterForClass(testAttr); | ||
125 | - // assertThat(getterForClass.contains(UtilConstants.GET_METHOD_PREFIX) && getterForClass.contains("List<") | ||
126 | - // && getterForClass.contains("attributeTest1"), is(true)); | ||
127 | - // String setterForClass = MethodsGenerator.getSetterForClass(testAttr, "TestThis"); | ||
128 | - // assertThat(setterForClass.contains(UtilConstants.SET_METHOD_PREFIX) && setterForClass.contains("List<") | ||
129 | - // && setterForClass.contains("attributeTest1"), is(true)); | ||
130 | - // String typeDefSetter = MethodsGenerator.getSetterForTypeDefClass(testAttr); | ||
131 | - // assertThat(typeDefSetter.contains(UtilConstants.SET_METHOD_PREFIX) && typeDefSetter.contains("List<") | ||
132 | - // && typeDefSetter.contains("attributeTest1") && typeDefSetter.contains("this."), is(true)); | ||
133 | - // } | ||
134 | - | ||
135 | - /** | ||
136 | - * Unit test case for checking the parse builder and typedef constructor | ||
137 | - * with list data type. | ||
138 | - */ | ||
139 | - // @Test | ||
140 | - // public void getConstructorWithListTypeTest() { | ||
141 | - // | ||
142 | - // JavaQualifiedTypeInfo forSetter = new JavaQualifiedTypeInfo(); | ||
143 | - // attrType.setDataTypeName("binary"); | ||
144 | - // attrType.getDataTypeName(); | ||
145 | - // attrType.setDataType(YangDataTypes.BINARY); | ||
146 | - // attrType.getDataType(); | ||
147 | - // testAttr.setAttributeName("attributeTest"); | ||
148 | - // testAttr.setAttributeType(attrType); | ||
149 | - // forSetter.setPkgInfo("null"); | ||
150 | - // forSetter.setClassInfo("This class contains"); | ||
151 | - // testAttr.setImportInfo(forSetter); | ||
152 | - // testAttr.setListAttr(true); | ||
153 | - // String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname"); | ||
154 | - // assertThat(stringTypeDef.contains("(List<") && stringTypeDef.contains("Testname") | ||
155 | - // && stringTypeDef.contains(UtilConstants.THIS), is(true)); | ||
156 | - // } | ||
157 | -} |
... | @@ -21,9 +21,7 @@ import java.io.IOException; | ... | @@ -21,9 +21,7 @@ import java.io.IOException; |
21 | import java.lang.reflect.Constructor; | 21 | import java.lang.reflect.Constructor; |
22 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
23 | 23 | ||
24 | -import org.junit.Rule; | ||
25 | import org.junit.Test; | 24 | import org.junit.Test; |
26 | -import org.junit.rules.ExpectedException; | ||
27 | import org.onosproject.yangutils.utils.UtilConstants; | 25 | import org.onosproject.yangutils.utils.UtilConstants; |
28 | 26 | ||
29 | import static org.junit.Assert.assertNotNull; | 27 | import static org.junit.Assert.assertNotNull; |
... | @@ -34,12 +32,12 @@ import static org.junit.Assert.assertTrue; | ... | @@ -34,12 +32,12 @@ import static org.junit.Assert.assertTrue; |
34 | */ | 32 | */ |
35 | public final class FileSystemUtilTest { | 33 | public final class FileSystemUtilTest { |
36 | 34 | ||
37 | - public static final String BASE_DIR_PKG = "target.UnitTestCase."; | 35 | + private static final String BASE_DIR_PKG = "target.UnitTestCase."; |
38 | - public static final String PKG_INFO_CONTENT = "testGeneration6"; | 36 | + private static final String PKG_INFO_CONTENT = "testGeneration6"; |
39 | - public static final String BASE_PKG = "target/UnitTestCase"; | 37 | + private static final String BASE_PKG = "target/UnitTestCase"; |
40 | - | 38 | + private static final String TEST_DATA_1 = "This is to append a text to the file first1\n"; |
41 | - @Rule | 39 | + private static final String TEST_DATA_2 = "This is next second line\n"; |
42 | - public ExpectedException thrown = ExpectedException.none(); | 40 | + private static final String TEST_DATA_3 = "This is next third line in the file"; |
43 | 41 | ||
44 | /** | 42 | /** |
45 | * A private constructor is tested. | 43 | * A private constructor is tested. |
... | @@ -47,20 +45,15 @@ public final class FileSystemUtilTest { | ... | @@ -47,20 +45,15 @@ public final class FileSystemUtilTest { |
47 | * @throws SecurityException if any security violation is observed | 45 | * @throws SecurityException if any security violation is observed |
48 | * @throws NoSuchMethodException if when the method is not found | 46 | * @throws NoSuchMethodException if when the method is not found |
49 | * @throws IllegalArgumentException if there is illegal argument found | 47 | * @throws IllegalArgumentException if there is illegal argument found |
50 | - * @throws InstantiationException if instantiation is provoked for the | 48 | + * @throws InstantiationException if instantiation is provoked for the private constructor |
51 | - * private constructor | 49 | + * @throws IllegalAccessException if instance is provoked or a method is provoked |
52 | - * @throws IllegalAccessException if instance is provoked or a method is | 50 | + * @throws InvocationTargetException when an exception occurs by the method or constructor |
53 | - * provoked | ||
54 | - * @throws InvocationTargetException when an exception occurs by the method | ||
55 | - * or constructor | ||
56 | */ | 51 | */ |
57 | @Test | 52 | @Test |
58 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 53 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
59 | InstantiationException, IllegalAccessException, InvocationTargetException { | 54 | InstantiationException, IllegalAccessException, InvocationTargetException { |
60 | 55 | ||
61 | - Class<?>[] classesToConstruct = { | 56 | + Class<?>[] classesToConstruct = {FileSystemUtil.class }; |
62 | - FileSystemUtil.class | ||
63 | - }; | ||
64 | for (Class<?> clazz : classesToConstruct) { | 57 | for (Class<?> clazz : classesToConstruct) { |
65 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 58 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
66 | constructor.setAccessible(true); | 59 | constructor.setAccessible(true); |
... | @@ -70,6 +63,8 @@ public final class FileSystemUtilTest { | ... | @@ -70,6 +63,8 @@ public final class FileSystemUtilTest { |
70 | 63 | ||
71 | /** | 64 | /** |
72 | * This test case checks the contents to be written in the file. | 65 | * This test case checks the contents to be written in the file. |
66 | + * | ||
67 | + * @throws IOException when fails to create a test file | ||
73 | */ | 68 | */ |
74 | @Test | 69 | @Test |
75 | public void updateFileHandleTest() throws IOException { | 70 | public void updateFileHandleTest() throws IOException { |
... | @@ -80,15 +75,17 @@ public final class FileSystemUtilTest { | ... | @@ -80,15 +75,17 @@ public final class FileSystemUtilTest { |
80 | createFile.createNewFile(); | 75 | createFile.createNewFile(); |
81 | File createSourceFile = new File(dir + "sourceTestFile"); | 76 | File createSourceFile = new File(dir + "sourceTestFile"); |
82 | createSourceFile.createNewFile(); | 77 | createSourceFile.createNewFile(); |
83 | - FileSystemUtil.updateFileHandle(createFile, "This is to append a text to the file first1\n", false); | 78 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_1, false); |
84 | - FileSystemUtil.updateFileHandle(createFile, "This is next second line\n", false); | 79 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_2, false); |
85 | - FileSystemUtil.updateFileHandle(createFile, "This is next third line in the file", false); | 80 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_3, false); |
86 | FileSystemUtil.appendFileContents(createFile, createSourceFile); | 81 | FileSystemUtil.appendFileContents(createFile, createSourceFile); |
87 | FileSystemUtil.updateFileHandle(createFile, null, true); | 82 | FileSystemUtil.updateFileHandle(createFile, null, true); |
88 | } | 83 | } |
89 | 84 | ||
90 | /** | 85 | /** |
91 | * This test case checks whether the package is existing. | 86 | * This test case checks whether the package is existing. |
87 | + * | ||
88 | + * @throws IOException when failed to create a test file | ||
92 | */ | 89 | */ |
93 | @Test | 90 | @Test |
94 | public void packageExistTest() throws IOException { | 91 | public void packageExistTest() throws IOException { |
... | @@ -104,21 +101,4 @@ public final class FileSystemUtilTest { | ... | @@ -104,21 +101,4 @@ public final class FileSystemUtilTest { |
104 | createDir.delete(); | 101 | createDir.delete(); |
105 | } | 102 | } |
106 | 103 | ||
107 | - /** | ||
108 | - * This test case checks the package does not exist. | ||
109 | - */ | ||
110 | - // @Test | ||
111 | - // public void packageNotExistTest() throws IOException { | ||
112 | - | ||
113 | - // String dirPath = "notexist1.notexist2"; | ||
114 | - // String strPath = BASE_DIR_PKG + dirPath; | ||
115 | - // File createDir = new File(strPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | ||
116 | - // assertFalse(FileSystemUtil.doesPackageExist(strPath)); | ||
117 | - // createDir.mkdirs(); | ||
118 | - // assertFalse(FileSystemUtil.doesPackageExist(strPath)); | ||
119 | - // CopyrightHeader.parseCopyrightHeader(); | ||
120 | - // FileSystemUtil.createPackage(strPath, PKG_INFO_CONTENT); | ||
121 | - // assertTrue(FileSystemUtil.doesPackageExist(strPath)); | ||
122 | - // createDir.delete(); | ||
123 | - // } | ||
124 | } | 104 | } | ... | ... |
... | @@ -62,7 +62,7 @@ public final class JavaDocGenTest { | ... | @@ -62,7 +62,7 @@ public final class JavaDocGenTest { |
62 | @Test | 62 | @Test |
63 | public void buildGenerationTest() { | 63 | public void buildGenerationTest() { |
64 | 64 | ||
65 | - String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1", false); | 65 | + String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD_METHOD, "testGeneration1", false); |
66 | assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); | 66 | assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); |
67 | } | 67 | } |
68 | 68 | ||
... | @@ -117,7 +117,7 @@ public final class JavaDocGenTest { | ... | @@ -117,7 +117,7 @@ public final class JavaDocGenTest { |
117 | @Test | 117 | @Test |
118 | public void getterGenerationTest() { | 118 | public void getterGenerationTest() { |
119 | 119 | ||
120 | - String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1", false); | 120 | + String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER_METHOD, "testGeneration1", false); |
121 | assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); | 121 | assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); |
122 | } | 122 | } |
123 | 123 | ||
... | @@ -157,7 +157,7 @@ public final class JavaDocGenTest { | ... | @@ -157,7 +157,7 @@ public final class JavaDocGenTest { |
157 | @Test | 157 | @Test |
158 | public void setterGenerationTest() { | 158 | public void setterGenerationTest() { |
159 | 159 | ||
160 | - String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1", false); | 160 | + String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER_METHOD, "testGeneration1", false); |
161 | assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); | 161 | assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); |
162 | } | 162 | } |
163 | 163 | ||
... | @@ -167,7 +167,7 @@ public final class JavaDocGenTest { | ... | @@ -167,7 +167,7 @@ public final class JavaDocGenTest { |
167 | @Test | 167 | @Test |
168 | public void typeDefSetterGenerationTest() { | 168 | public void typeDefSetterGenerationTest() { |
169 | 169 | ||
170 | - String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, "testGeneration1", false); | 170 | + String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER_METHOD, "testGeneration1", false); |
171 | assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); | 171 | assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); |
172 | } | 172 | } |
173 | } | 173 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment