Committed by
Gerrit Code Review
YANG translator error handler framework and UT fixes.
Change-Id: Icb4d65540ed7ea8d6ecbd8458d44d7d86df969fa
Showing
35 changed files
with
449 additions
and
462 deletions
... | @@ -43,6 +43,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificatio | ... | @@ -43,6 +43,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificatio |
43 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc; | 43 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc; |
44 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; | 44 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; |
45 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput; | 45 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput; |
46 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
46 | 47 | ||
47 | /** | 48 | /** |
48 | * Factory to create data model objects based on the target file type. | 49 | * Factory to create data model objects based on the target file type. |
... | @@ -68,7 +69,7 @@ public final class YangDataModelFactory { | ... | @@ -68,7 +69,7 @@ public final class YangDataModelFactory { |
68 | return new YangJavaModule(); | 69 | return new YangJavaModule(); |
69 | } | 70 | } |
70 | default: { | 71 | default: { |
71 | - throw new RuntimeException("Only YANG to Java is supported."); | 72 | + throw new TranslatorException("Only YANG to Java is supported."); |
72 | } | 73 | } |
73 | } | 74 | } |
74 | } | 75 | } |
... | @@ -86,7 +87,7 @@ public final class YangDataModelFactory { | ... | @@ -86,7 +87,7 @@ public final class YangDataModelFactory { |
86 | return new YangJavaAugment(); | 87 | return new YangJavaAugment(); |
87 | } | 88 | } |
88 | default: { | 89 | default: { |
89 | - throw new RuntimeException("Only YANG to Java is supported."); | 90 | + throw new TranslatorException("Only YANG to Java is supported."); |
90 | } | 91 | } |
91 | } | 92 | } |
92 | } | 93 | } |
... | @@ -104,7 +105,7 @@ public final class YangDataModelFactory { | ... | @@ -104,7 +105,7 @@ public final class YangDataModelFactory { |
104 | return new YangJavaCase(); | 105 | return new YangJavaCase(); |
105 | } | 106 | } |
106 | default: { | 107 | default: { |
107 | - throw new RuntimeException("Only YANG to Java is supported."); | 108 | + throw new TranslatorException("Only YANG to Java is supported."); |
108 | } | 109 | } |
109 | } | 110 | } |
110 | } | 111 | } |
... | @@ -122,7 +123,7 @@ public final class YangDataModelFactory { | ... | @@ -122,7 +123,7 @@ public final class YangDataModelFactory { |
122 | return new YangJavaChoice(); | 123 | return new YangJavaChoice(); |
123 | } | 124 | } |
124 | default: { | 125 | default: { |
125 | - throw new RuntimeException("Only YANG to Java is supported."); | 126 | + throw new TranslatorException("Only YANG to Java is supported."); |
126 | } | 127 | } |
127 | } | 128 | } |
128 | } | 129 | } |
... | @@ -140,7 +141,7 @@ public final class YangDataModelFactory { | ... | @@ -140,7 +141,7 @@ public final class YangDataModelFactory { |
140 | return new YangJavaContainer(); | 141 | return new YangJavaContainer(); |
141 | } | 142 | } |
142 | default: { | 143 | default: { |
143 | - throw new RuntimeException("Only YANG to Java is supported."); | 144 | + throw new TranslatorException("Only YANG to Java is supported."); |
144 | } | 145 | } |
145 | } | 146 | } |
146 | } | 147 | } |
... | @@ -158,7 +159,7 @@ public final class YangDataModelFactory { | ... | @@ -158,7 +159,7 @@ public final class YangDataModelFactory { |
158 | return new YangJavaGrouping(); | 159 | return new YangJavaGrouping(); |
159 | } | 160 | } |
160 | default: { | 161 | default: { |
161 | - throw new RuntimeException("Only YANG to Java is supported."); | 162 | + throw new TranslatorException("Only YANG to Java is supported."); |
162 | } | 163 | } |
163 | } | 164 | } |
164 | } | 165 | } |
... | @@ -176,7 +177,7 @@ public final class YangDataModelFactory { | ... | @@ -176,7 +177,7 @@ public final class YangDataModelFactory { |
176 | return new YangJavaList(); | 177 | return new YangJavaList(); |
177 | } | 178 | } |
178 | default: { | 179 | default: { |
179 | - throw new RuntimeException("Only YANG to Java is supported."); | 180 | + throw new TranslatorException("Only YANG to Java is supported."); |
180 | } | 181 | } |
181 | } | 182 | } |
182 | } | 183 | } |
... | @@ -194,7 +195,7 @@ public final class YangDataModelFactory { | ... | @@ -194,7 +195,7 @@ public final class YangDataModelFactory { |
194 | return new YangJavaSubModule(); | 195 | return new YangJavaSubModule(); |
195 | } | 196 | } |
196 | default: { | 197 | default: { |
197 | - throw new RuntimeException("Only YANG to Java is supported."); | 198 | + throw new TranslatorException("Only YANG to Java is supported."); |
198 | } | 199 | } |
199 | } | 200 | } |
200 | } | 201 | } |
... | @@ -212,7 +213,7 @@ public final class YangDataModelFactory { | ... | @@ -212,7 +213,7 @@ public final class YangDataModelFactory { |
212 | return new YangJavaTypeDef(); | 213 | return new YangJavaTypeDef(); |
213 | } | 214 | } |
214 | default: { | 215 | default: { |
215 | - throw new RuntimeException("Only YANG to Java is supported."); | 216 | + throw new TranslatorException("Only YANG to Java is supported."); |
216 | } | 217 | } |
217 | } | 218 | } |
218 | } | 219 | } |
... | @@ -230,7 +231,7 @@ public final class YangDataModelFactory { | ... | @@ -230,7 +231,7 @@ public final class YangDataModelFactory { |
230 | return new YangJavaUses(); | 231 | return new YangJavaUses(); |
231 | } | 232 | } |
232 | default: { | 233 | default: { |
233 | - throw new RuntimeException("Only YANG to Java is supported."); | 234 | + throw new TranslatorException("Only YANG to Java is supported."); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | } | 237 | } |
... | @@ -248,7 +249,7 @@ public final class YangDataModelFactory { | ... | @@ -248,7 +249,7 @@ public final class YangDataModelFactory { |
248 | return new YangJavaNotification(); | 249 | return new YangJavaNotification(); |
249 | } | 250 | } |
250 | default: { | 251 | default: { |
251 | - throw new RuntimeException("Only YANG to Java is supported."); | 252 | + throw new TranslatorException("Only YANG to Java is supported."); |
252 | } | 253 | } |
253 | } | 254 | } |
254 | } | 255 | } |
... | @@ -266,7 +267,7 @@ public final class YangDataModelFactory { | ... | @@ -266,7 +267,7 @@ public final class YangDataModelFactory { |
266 | return new YangJavaRpc(); | 267 | return new YangJavaRpc(); |
267 | } | 268 | } |
268 | default: { | 269 | default: { |
269 | - throw new RuntimeException("Only YANG to Java is supported."); | 270 | + throw new TranslatorException("Only YANG to Java is supported."); |
270 | } | 271 | } |
271 | } | 272 | } |
272 | } | 273 | } |
... | @@ -284,7 +285,7 @@ public final class YangDataModelFactory { | ... | @@ -284,7 +285,7 @@ public final class YangDataModelFactory { |
284 | return new YangJavaInput(); | 285 | return new YangJavaInput(); |
285 | } | 286 | } |
286 | default: { | 287 | default: { |
287 | - throw new RuntimeException("Only YANG to Java is supported."); | 288 | + throw new TranslatorException("Only YANG to Java is supported."); |
288 | } | 289 | } |
289 | } | 290 | } |
290 | } | 291 | } |
... | @@ -302,7 +303,7 @@ public final class YangDataModelFactory { | ... | @@ -302,7 +303,7 @@ public final class YangDataModelFactory { |
302 | return new YangJavaOutput(); | 303 | return new YangJavaOutput(); |
303 | } | 304 | } |
304 | default: { | 305 | default: { |
305 | - throw new RuntimeException("Only YANG to Java is supported."); | 306 | + throw new TranslatorException("Only YANG to Java is supported."); |
306 | } | 307 | } |
307 | } | 308 | } |
308 | } | 309 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
19 | import java.util.Iterator; | 20 | import java.util.Iterator; |
20 | import java.util.List; | 21 | import java.util.List; |
21 | 22 | ||
... | @@ -27,6 +28,7 @@ import org.apache.maven.plugins.annotations.Mojo; | ... | @@ -27,6 +28,7 @@ import org.apache.maven.plugins.annotations.Mojo; |
27 | import org.apache.maven.plugins.annotations.Parameter; | 28 | import org.apache.maven.plugins.annotations.Parameter; |
28 | import org.apache.maven.project.MavenProject; | 29 | import org.apache.maven.project.MavenProject; |
29 | import org.onosproject.yangutils.datamodel.YangNode; | 30 | import org.onosproject.yangutils.datamodel.YangNode; |
31 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
30 | import org.onosproject.yangutils.parser.YangUtilsParser; | 32 | import org.onosproject.yangutils.parser.YangUtilsParser; |
31 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 33 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
32 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 34 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
... | @@ -36,6 +38,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; | ... | @@ -36,6 +38,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; |
36 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | 38 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; |
37 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; | 39 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; |
38 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | 40 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
41 | +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler; | ||
39 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
... | @@ -94,16 +97,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -94,16 +97,7 @@ public class YangUtilManager extends AbstractMojo { |
94 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 97 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
95 | private String searchDir; | 98 | private String searchDir; |
96 | private String codeGenDir; | 99 | private String codeGenDir; |
97 | - | 100 | + private YangNode rootNode; |
98 | - /** | ||
99 | - * Set current project. | ||
100 | - * | ||
101 | - * @param curProject maven project | ||
102 | - */ | ||
103 | - public void setCurrentProject(final MavenProject curProject) { | ||
104 | - | ||
105 | - project = curProject; | ||
106 | - } | ||
107 | 101 | ||
108 | @Override | 102 | @Override |
109 | public void execute() throws MojoExecutionException, MojoFailureException { | 103 | public void execute() throws MojoExecutionException, MojoFailureException { |
... | @@ -125,6 +119,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -125,6 +119,7 @@ public class YangUtilManager extends AbstractMojo { |
125 | String yangFile = yangFileIterator.next(); | 119 | String yangFile = yangFileIterator.next(); |
126 | try { | 120 | try { |
127 | YangNode yangNode = yangUtilsParser.getDataModel(yangFile); | 121 | YangNode yangNode = yangUtilsParser.getDataModel(yangFile); |
122 | + setRootNode(yangNode); | ||
128 | generateJavaCode(yangNode, codeGenDir); | 123 | generateJavaCode(yangNode, codeGenDir); |
129 | } catch (ParserException e) { | 124 | } catch (ParserException e) { |
130 | String logInfo = "Error in file: " + e.getFileName(); | 125 | String logInfo = "Error in file: " + e.getFileName(); |
... | @@ -143,8 +138,52 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -143,8 +138,52 @@ public class YangUtilManager extends AbstractMojo { |
143 | addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); | 138 | addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); |
144 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); | 139 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); |
145 | } catch (Exception e) { | 140 | } catch (Exception e) { |
146 | - getLog().info(e); | 141 | + try { |
142 | + translatorErrorHandler(getRootNode()); | ||
143 | + clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); | ||
144 | + } catch (IOException | DataModelException ex) { | ||
145 | + throw new MojoExecutionException("Error handler failed to delete files for data model node."); | ||
146 | + } | ||
147 | throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); | 147 | throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); |
148 | } | 148 | } |
149 | } | 149 | } |
150 | + | ||
151 | + /** | ||
152 | + * Set current project. | ||
153 | + * | ||
154 | + * @param curProject maven project | ||
155 | + */ | ||
156 | + public void setCurrentProject(MavenProject curProject) { | ||
157 | + project = curProject; | ||
158 | + | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Returns current project. | ||
163 | + * | ||
164 | + * @return current project | ||
165 | + */ | ||
166 | + public MavenProject getCurrentProject() { | ||
167 | + return project; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Returns current root YANG node of data-model tree. | ||
172 | + * | ||
173 | + * @return current root YANG node of data-model tree | ||
174 | + */ | ||
175 | + public YangNode getRootNode() { | ||
176 | + return rootNode; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Sets current root YANG node of data-model tree. | ||
181 | + * | ||
182 | + * @param rootNode current root YANG node of data-model tree | ||
183 | + */ | ||
184 | + | ||
185 | + public void setRootNode(YangNode rootNode) { | ||
186 | + this.rootNode = rootNode; | ||
187 | + } | ||
188 | + | ||
150 | } | 189 | } | ... | ... |
... | @@ -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.exception.TranslatorException; | ||
21 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | 22 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; |
22 | 23 | ||
23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; | 24 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; |
... | @@ -63,7 +64,7 @@ public final class JavaAttributeInfo { | ... | @@ -63,7 +64,7 @@ public final class JavaAttributeInfo { |
63 | } | 64 | } |
64 | 65 | ||
65 | /** | 66 | /** |
66 | - * Construct object of java attribute info. | 67 | + * Creates object of java attribute info. |
67 | * | 68 | * |
68 | * @param attrType YANG type | 69 | * @param attrType YANG type |
69 | * @param name attribute name | 70 | * @param name attribute name |
... | @@ -85,7 +86,7 @@ public final class JavaAttributeInfo { | ... | @@ -85,7 +86,7 @@ public final class JavaAttributeInfo { |
85 | public YangType<?> getAttributeType() { | 86 | public YangType<?> getAttributeType() { |
86 | 87 | ||
87 | if (attrType == null) { | 88 | if (attrType == null) { |
88 | - throw new RuntimeException("Expected java attribute type is null"); | 89 | + throw new TranslatorException("Expected java attribute type is null"); |
89 | } | 90 | } |
90 | return attrType; | 91 | return attrType; |
91 | } | 92 | } |
... | @@ -96,7 +97,6 @@ public final class JavaAttributeInfo { | ... | @@ -96,7 +97,6 @@ public final class JavaAttributeInfo { |
96 | * @param type the data type info of attribute | 97 | * @param type the data type info of attribute |
97 | */ | 98 | */ |
98 | public void setAttributeType(YangType<?> type) { | 99 | public void setAttributeType(YangType<?> type) { |
99 | - | ||
100 | attrType = type; | 100 | attrType = type; |
101 | } | 101 | } |
102 | 102 | ||
... | @@ -108,7 +108,7 @@ public final class JavaAttributeInfo { | ... | @@ -108,7 +108,7 @@ public final class JavaAttributeInfo { |
108 | public String getAttributeName() { | 108 | public String getAttributeName() { |
109 | 109 | ||
110 | if (name == null) { | 110 | if (name == null) { |
111 | - throw new RuntimeException("Expected java attribute name is null"); | 111 | + throw new TranslatorException("Expected java attribute name is null"); |
112 | } | 112 | } |
113 | return name; | 113 | return name; |
114 | } | 114 | } |
... | @@ -119,7 +119,6 @@ public final class JavaAttributeInfo { | ... | @@ -119,7 +119,6 @@ public final class JavaAttributeInfo { |
119 | * @param attrName name of the attribute | 119 | * @param attrName name of the attribute |
120 | */ | 120 | */ |
121 | public void setAttributeName(String attrName) { | 121 | public void setAttributeName(String attrName) { |
122 | - | ||
123 | name = attrName; | 122 | name = attrName; |
124 | } | 123 | } |
125 | 124 | ||
... | @@ -129,7 +128,6 @@ public final class JavaAttributeInfo { | ... | @@ -129,7 +128,6 @@ public final class JavaAttributeInfo { |
129 | * @return the if the added attribute is a list of info | 128 | * @return the if the added attribute is a list of info |
130 | */ | 129 | */ |
131 | public boolean isListAttr() { | 130 | public boolean isListAttr() { |
132 | - | ||
133 | return isListAttr; | 131 | return isListAttr; |
134 | } | 132 | } |
135 | 133 | ||
... | @@ -139,7 +137,6 @@ public final class JavaAttributeInfo { | ... | @@ -139,7 +137,6 @@ public final class JavaAttributeInfo { |
139 | * @param isList if the added attribute is a list of info | 137 | * @param isList if the added attribute is a list of info |
140 | */ | 138 | */ |
141 | public void setListAttr(boolean isList) { | 139 | public void setListAttr(boolean isList) { |
142 | - | ||
143 | isListAttr = isList; | 140 | isListAttr = isList; |
144 | } | 141 | } |
145 | 142 | ||
... | @@ -151,7 +148,6 @@ public final class JavaAttributeInfo { | ... | @@ -151,7 +148,6 @@ public final class JavaAttributeInfo { |
151 | * qualified manner. | 148 | * qualified manner. |
152 | */ | 149 | */ |
153 | public boolean isQualifiedName() { | 150 | public boolean isQualifiedName() { |
154 | - | ||
155 | return isQualifiedName; | 151 | return isQualifiedName; |
156 | } | 152 | } |
157 | 153 | ||
... | @@ -163,7 +159,6 @@ public final class JavaAttributeInfo { | ... | @@ -163,7 +159,6 @@ public final class JavaAttributeInfo { |
163 | * qualified manner | 159 | * qualified manner |
164 | */ | 160 | */ |
165 | public void setIsQualifiedAccess(boolean isQualified) { | 161 | public void setIsQualifiedAccess(boolean isQualified) { |
166 | - | ||
167 | isQualifiedName = isQualified; | 162 | isQualifiedName = isQualified; |
168 | } | 163 | } |
169 | 164 | ||
... | @@ -174,7 +169,6 @@ public final class JavaAttributeInfo { | ... | @@ -174,7 +169,6 @@ public final class JavaAttributeInfo { |
174 | * @return import info | 169 | * @return import info |
175 | */ | 170 | */ |
176 | public JavaQualifiedTypeInfo getImportInfo() { | 171 | public JavaQualifiedTypeInfo getImportInfo() { |
177 | - | ||
178 | return importInfo; | 172 | return importInfo; |
179 | } | 173 | } |
180 | 174 | ||
... | @@ -184,7 +178,6 @@ public final class JavaAttributeInfo { | ... | @@ -184,7 +178,6 @@ public final class JavaAttributeInfo { |
184 | * @param importInfo import info for the attribute type | 178 | * @param importInfo import info for the attribute type |
185 | */ | 179 | */ |
186 | public void setImportInfo(JavaQualifiedTypeInfo importInfo) { | 180 | public void setImportInfo(JavaQualifiedTypeInfo importInfo) { |
187 | - | ||
188 | this.importInfo = importInfo; | 181 | this.importInfo = importInfo; |
189 | } | 182 | } |
190 | 183 | ||
... | @@ -204,23 +197,14 @@ public final class JavaAttributeInfo { | ... | @@ -204,23 +197,14 @@ public final class JavaAttributeInfo { |
204 | YangType<?> attributeType, String attributeName, | 197 | YangType<?> attributeType, String attributeName, |
205 | boolean isListAttribute) { | 198 | boolean isListAttribute) { |
206 | 199 | ||
207 | - JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
208 | - | ||
209 | /* | 200 | /* |
210 | * Get the import info corresponding to the attribute for import in | 201 | * Get the import info corresponding to the attribute for import in |
211 | * generated java files or qualified access | 202 | * generated java files or qualified access |
212 | */ | 203 | */ |
213 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, | 204 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, |
214 | attributeType, attributeName, isListAttribute); | 205 | attributeType, attributeName, isListAttribute); |
215 | - newAttr.setImportInfo(importInfo); | ||
216 | - newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList( | ||
217 | - curNode, importInfo)); | ||
218 | - newAttr.setAttributeName(getCamelCase(attributeName)); | ||
219 | - newAttr.setListAttr(isListAttribute); | ||
220 | - newAttr.setImportInfo(importInfo); | ||
221 | - newAttr.setAttributeType(attributeType); | ||
222 | 206 | ||
223 | - return newAttr; | 207 | + return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute); |
224 | } | 208 | } |
225 | 209 | ||
226 | /** | 210 | /** |
... | @@ -237,12 +221,6 @@ public final class JavaAttributeInfo { | ... | @@ -237,12 +221,6 @@ public final class JavaAttributeInfo { |
237 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( | 221 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( |
238 | YangNode curNode, YangNode parentNode, boolean isListNode) { | 222 | YangNode curNode, YangNode parentNode, boolean isListNode) { |
239 | 223 | ||
240 | - JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
241 | - | ||
242 | - // if (curNode instanceof HasJavaFileInfo) { | ||
243 | - // throw new RuntimeException("translator data model node does not have java info"); | ||
244 | - // } | ||
245 | - | ||
246 | String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName(); | 224 | String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName(); |
247 | 225 | ||
248 | /* | 226 | /* |
... | @@ -251,16 +229,8 @@ public final class JavaAttributeInfo { | ... | @@ -251,16 +229,8 @@ public final class JavaAttributeInfo { |
251 | */ | 229 | */ |
252 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, | 230 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, |
253 | curNodeName, isListNode); | 231 | curNodeName, isListNode); |
254 | - newAttr.setImportInfo(qualifiedTypeInfo); | ||
255 | - newAttr.setIsQualifiedAccess( | ||
256 | - getIsQualifiedAccessOrAddToImportList(parentNode, | ||
257 | - qualifiedTypeInfo)); | ||
258 | - newAttr.setAttributeName(getCamelCase(curNodeName)); | ||
259 | - newAttr.setListAttr(isListNode); | ||
260 | - newAttr.setImportInfo(qualifiedTypeInfo); | ||
261 | - newAttr.setAttributeType(null); | ||
262 | 232 | ||
263 | - return newAttr; | 233 | + return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, parentNode, isListNode); |
264 | } | 234 | } |
265 | 235 | ||
266 | /** | 236 | /** |
... | @@ -279,8 +249,6 @@ public final class JavaAttributeInfo { | ... | @@ -279,8 +249,6 @@ public final class JavaAttributeInfo { |
279 | YangType<?> attributeType, String attributeName, | 249 | YangType<?> attributeType, String attributeName, |
280 | boolean isListAttribute) { | 250 | boolean isListAttribute) { |
281 | 251 | ||
282 | - JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
283 | - | ||
284 | /* | 252 | /* |
285 | * Get the import info corresponding to the attribute for import in | 253 | * Get the import info corresponding to the attribute for import in |
286 | * generated java files or qualified access | 254 | * generated java files or qualified access |
... | @@ -288,9 +256,26 @@ public final class JavaAttributeInfo { | ... | @@ -288,9 +256,26 @@ public final class JavaAttributeInfo { |
288 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, | 256 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, |
289 | attributeType, attributeName, isListAttribute); | 257 | attributeType, attributeName, isListAttribute); |
290 | AttributesJavaDataType.addImportInfo(importInfo); | 258 | AttributesJavaDataType.addImportInfo(importInfo); |
259 | + | ||
260 | + return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute); | ||
261 | + } | ||
262 | + | ||
263 | + /** | ||
264 | + * Returns java attribute info. | ||
265 | + * | ||
266 | + * @param importInfo java qualified type info | ||
267 | + * @param attributeName attribute name | ||
268 | + * @param attributeType attribute type | ||
269 | + * @param curNode current YANG node | ||
270 | + * @param isListAttribute is list attribute | ||
271 | + * @return java attribute info. | ||
272 | + */ | ||
273 | + private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName, | ||
274 | + YangType<?> attributeType, YangNode curNode, boolean isListAttribute) { | ||
275 | + | ||
276 | + JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
291 | newAttr.setImportInfo(importInfo); | 277 | newAttr.setImportInfo(importInfo); |
292 | - newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList( | 278 | + newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo)); |
293 | - curNode, importInfo)); | ||
294 | newAttr.setAttributeName(getCamelCase(attributeName)); | 279 | newAttr.setAttributeName(getCamelCase(attributeName)); |
295 | newAttr.setListAttr(isListAttribute); | 280 | newAttr.setListAttr(isListAttribute); |
296 | newAttr.setImportInfo(importInfo); | 281 | newAttr.setImportInfo(importInfo); | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
... | @@ -19,6 +19,13 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -19,6 +19,13 @@ package org.onosproject.yangutils.translator.tojava; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
24 | + | ||
25 | +import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; | ||
26 | +import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT; | ||
27 | +import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING; | ||
22 | 29 | ||
23 | /** | 30 | /** |
24 | * Implementation of Java code generator based on application schema. | 31 | * Implementation of Java code generator based on application schema. |
... | @@ -26,12 +33,36 @@ import org.onosproject.yangutils.datamodel.YangNode; | ... | @@ -26,12 +33,36 @@ import org.onosproject.yangutils.datamodel.YangNode; |
26 | public final class JavaCodeGeneratorUtil { | 33 | public final class JavaCodeGeneratorUtil { |
27 | 34 | ||
28 | /** | 35 | /** |
36 | + * Current YANG node. | ||
37 | + */ | ||
38 | + private static YangNode curNode; | ||
39 | + | ||
40 | + /** | ||
29 | * Default constructor. | 41 | * Default constructor. |
30 | */ | 42 | */ |
31 | private JavaCodeGeneratorUtil() { | 43 | private JavaCodeGeneratorUtil() { |
32 | } | 44 | } |
33 | 45 | ||
34 | /** | 46 | /** |
47 | + * Returns current YANG node. | ||
48 | + * | ||
49 | + * @return current YANG node | ||
50 | + */ | ||
51 | + public static YangNode getCurNode() { | ||
52 | + return curNode; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Sets current YANG node. | ||
57 | + * | ||
58 | + * @param node current YANG node | ||
59 | + */ | ||
60 | + | ||
61 | + public static void setCurNode(YangNode node) { | ||
62 | + curNode = node; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
35 | * Generate Java code files corresponding to the YANG schema. | 66 | * Generate Java code files corresponding to the YANG schema. |
36 | * | 67 | * |
37 | * @param rootNode root node of the data model tree | 68 | * @param rootNode root node of the data model tree |
... | @@ -40,23 +71,25 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -40,23 +71,25 @@ public final class JavaCodeGeneratorUtil { |
40 | * node | 71 | * node |
41 | */ | 72 | */ |
42 | public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException { | 73 | public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException { |
74 | + | ||
43 | YangNode curNode = rootNode; | 75 | YangNode curNode = rootNode; |
44 | - TraversalType curTraversal = TraversalType.ROOT; | 76 | + TraversalType curTraversal = ROOT; |
45 | 77 | ||
46 | while (!(curNode == null)) { | 78 | while (!(curNode == null)) { |
47 | - if (curTraversal != TraversalType.PARENT) { | 79 | + if (curTraversal != PARENT) { |
80 | + setCurNode(curNode); | ||
48 | generateCodeEntry(curNode, codeGenDir); | 81 | generateCodeEntry(curNode, codeGenDir); |
49 | } | 82 | } |
50 | - if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) { | 83 | + if (curTraversal != PARENT && curNode.getChild() != null) { |
51 | - curTraversal = TraversalType.CHILD; | 84 | + curTraversal = CHILD; |
52 | curNode = curNode.getChild(); | 85 | curNode = curNode.getChild(); |
53 | } else if (curNode.getNextSibling() != null) { | 86 | } else if (curNode.getNextSibling() != null) { |
54 | generateCodeExit(curNode); | 87 | generateCodeExit(curNode); |
55 | - curTraversal = TraversalType.SIBILING; | 88 | + curTraversal = SIBILING; |
56 | curNode = curNode.getNextSibling(); | 89 | curNode = curNode.getNextSibling(); |
57 | } else { | 90 | } else { |
58 | generateCodeExit(curNode); | 91 | generateCodeExit(curNode); |
59 | - curTraversal = TraversalType.PARENT; | 92 | + curTraversal = PARENT; |
60 | curNode = curNode.getParent(); | 93 | curNode = curNode.getParent(); |
61 | } | 94 | } |
62 | } | 95 | } |
... | @@ -76,8 +109,8 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -76,8 +109,8 @@ public final class JavaCodeGeneratorUtil { |
76 | if (curNode instanceof JavaCodeGenerator) { | 109 | if (curNode instanceof JavaCodeGenerator) { |
77 | ((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir); | 110 | ((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir); |
78 | } else { | 111 | } else { |
79 | - throw new RuntimeException( | 112 | + throw new TranslatorException( |
80 | - "Gnenerated data model node cannot be translated to target language code"); | 113 | + "Generated data model node cannot be translated to target language code"); |
81 | } | 114 | } |
82 | } | 115 | } |
83 | 116 | ||
... | @@ -93,8 +126,113 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -93,8 +126,113 @@ public final class JavaCodeGeneratorUtil { |
93 | if (curNode instanceof JavaCodeGenerator) { | 126 | if (curNode instanceof JavaCodeGenerator) { |
94 | ((JavaCodeGenerator) curNode).generateCodeExit(); | 127 | ((JavaCodeGenerator) curNode).generateCodeExit(); |
95 | } else { | 128 | } else { |
96 | - throw new RuntimeException( | 129 | + throw new TranslatorException( |
97 | - "Gnenerated data model node cannot be translated to target language code"); | 130 | + "Generated data model node cannot be translated to target language code"); |
131 | + } | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Free other YANG nodes of data-model tree when error occurs while file generation of current node. | ||
136 | + * | ||
137 | + * @throws DataModelException when fails to do datamodel operations | ||
138 | + */ | ||
139 | + public static void freeRestResources() throws DataModelException { | ||
140 | + | ||
141 | + YangNode curNode = getCurNode(); | ||
142 | + YangNode tempNode = curNode; | ||
143 | + TraversalType curTraversal = ROOT; | ||
144 | + | ||
145 | + while (!(curNode == tempNode.getParent())) { | ||
146 | + | ||
147 | + if (curTraversal != PARENT && curNode.getChild() != null) { | ||
148 | + curTraversal = CHILD; | ||
149 | + curNode = curNode.getChild(); | ||
150 | + } else if (curNode.getNextSibling() != null) { | ||
151 | + curTraversal = SIBILING; | ||
152 | + if (curNode != tempNode) { | ||
153 | + free(curNode); | ||
154 | + } | ||
155 | + curNode = curNode.getNextSibling(); | ||
156 | + } else { | ||
157 | + curTraversal = PARENT; | ||
158 | + if (curNode != tempNode) { | ||
159 | + free(curNode); | ||
160 | + } | ||
161 | + curNode = curNode.getParent(); | ||
162 | + } | ||
163 | + } | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Free the current node. | ||
168 | + * | ||
169 | + * @param node YANG node | ||
170 | + * @throws DataModelException when fails to do datamodel operations | ||
171 | + */ | ||
172 | + private static void free(YangNode node) throws DataModelException { | ||
173 | + | ||
174 | + YangNode parent = node.getParent(); | ||
175 | + parent.setChild(null); | ||
176 | + if (node.getNextSibling() != null) { | ||
177 | + parent.setChild(node.getNextSibling()); | ||
178 | + } else if (node.getPreviousSibling() != null) { | ||
179 | + parent.setChild(node.getPreviousSibling()); | ||
180 | + } | ||
181 | + node = null; | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Delete Java code files corresponding to the YANG schema. | ||
186 | + * | ||
187 | + * @param rootNode root node of data-model tree | ||
188 | + * @throws IOException when fails to delete java code file the current node | ||
189 | + * @throws DataModelException when fails to do datamodel operations | ||
190 | + */ | ||
191 | + public static void translatorErrorHandler(YangNode rootNode) throws IOException, DataModelException { | ||
192 | + | ||
193 | + /** | ||
194 | + * Free other resources where translator has failed. | ||
195 | + */ | ||
196 | + freeRestResources(); | ||
197 | + | ||
198 | + /** | ||
199 | + * Start removing all open files. | ||
200 | + */ | ||
201 | + YangNode curNode = rootNode; | ||
202 | + setCurNode(curNode.getChild()); | ||
203 | + TraversalType curTraversal = ROOT; | ||
204 | + | ||
205 | + while (!(curNode == null)) { | ||
206 | + | ||
207 | + if (curTraversal != PARENT) { | ||
208 | + close(curNode); | ||
209 | + } | ||
210 | + if (curTraversal != PARENT && curNode.getChild() != null) { | ||
211 | + curTraversal = CHILD; | ||
212 | + curNode = curNode.getChild(); | ||
213 | + } else if (curNode.getNextSibling() != null) { | ||
214 | + curTraversal = SIBILING; | ||
215 | + curNode = curNode.getNextSibling(); | ||
216 | + } else { | ||
217 | + curTraversal = PARENT; | ||
218 | + curNode = curNode.getParent(); | ||
219 | + } | ||
220 | + } | ||
221 | + | ||
222 | + freeRestResources(); | ||
223 | + curNode = null; | ||
224 | + } | ||
225 | + | ||
226 | + /** | ||
227 | + * Closes all the current open file handles of node and delete all generated files. | ||
228 | + * | ||
229 | + * @param curNode current YANG node | ||
230 | + * @throws IOException when fails to do IO operations | ||
231 | + */ | ||
232 | + private static void close(YangNode curNode) throws IOException { | ||
233 | + | ||
234 | + if (((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() != null) { | ||
235 | + ((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().close(true); | ||
98 | } | 236 | } |
99 | } | 237 | } |
100 | } | 238 | } | ... | ... |
... | @@ -16,11 +16,14 @@ | ... | @@ -16,11 +16,14 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava; | 17 | package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
20 | + | ||
19 | /** | 21 | /** |
20 | * Cached java file handle, which supports the addition of member attributes and | 22 | * Cached java file handle, which supports the addition of member attributes and |
21 | * methods. | 23 | * methods. |
22 | */ | 24 | */ |
23 | public class JavaFileInfo { | 25 | public class JavaFileInfo { |
26 | + | ||
24 | /** | 27 | /** |
25 | * The type(s) of java source file(s) to be generated when the cached file | 28 | * The type(s) of java source file(s) to be generated when the cached file |
26 | * handle is closed. | 29 | * handle is closed. |
... | @@ -93,8 +96,9 @@ public class JavaFileInfo { | ... | @@ -93,8 +96,9 @@ public class JavaFileInfo { |
93 | * @return the java package | 96 | * @return the java package |
94 | */ | 97 | */ |
95 | public String getPackage() { | 98 | public String getPackage() { |
99 | + | ||
96 | if (pkg == null) { | 100 | if (pkg == null) { |
97 | - throw new RuntimeException("Referencing package of a generated java file which is not set"); | 101 | + throw new TranslatorException("Referencing package of a generated java file which is not set"); |
98 | } | 102 | } |
99 | return pkg; | 103 | return pkg; |
100 | } | 104 | } | ... | ... |
... | @@ -21,6 +21,7 @@ import java.util.SortedSet; | ... | @@ -21,6 +21,7 @@ import java.util.SortedSet; |
21 | import java.util.TreeSet; | 21 | import java.util.TreeSet; |
22 | 22 | ||
23 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
24 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
24 | 25 | ||
25 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | 26 | 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.EMPTY_STRING; |
... | @@ -64,7 +65,6 @@ public class JavaImportData { | ... | @@ -64,7 +65,6 @@ public class JavaImportData { |
64 | * @return true if any of the attribute needs to be maintained as a list. | 65 | * @return true if any of the attribute needs to be maintained as a list. |
65 | */ | 66 | */ |
66 | public boolean getIfListImported() { | 67 | public boolean getIfListImported() { |
67 | - | ||
68 | return isListToImport; | 68 | return isListToImport; |
69 | } | 69 | } |
70 | 70 | ||
... | @@ -74,7 +74,6 @@ public class JavaImportData { | ... | @@ -74,7 +74,6 @@ public class JavaImportData { |
74 | * @param isList status to mention list is bing imported. | 74 | * @param isList status to mention list is bing imported. |
75 | */ | 75 | */ |
76 | public void setIfListImported(boolean isList) { | 76 | public void setIfListImported(boolean isList) { |
77 | - | ||
78 | isListToImport = isList; | 77 | isListToImport = isList; |
79 | } | 78 | } |
80 | 79 | ||
... | @@ -84,7 +83,6 @@ public class JavaImportData { | ... | @@ -84,7 +83,6 @@ public class JavaImportData { |
84 | * @return the set containing the imported class/interface info | 83 | * @return the set containing the imported class/interface info |
85 | */ | 84 | */ |
86 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { | 85 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { |
87 | - | ||
88 | return importSet; | 86 | return importSet; |
89 | } | 87 | } |
90 | 88 | ||
... | @@ -94,7 +92,6 @@ public class JavaImportData { | ... | @@ -94,7 +92,6 @@ public class JavaImportData { |
94 | * @param importSet the set containing the imported class/interface info | 92 | * @param importSet the set containing the imported class/interface info |
95 | */ | 93 | */ |
96 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { | 94 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { |
97 | - | ||
98 | this.importSet = importSet; | 95 | this.importSet = importSet; |
99 | } | 96 | } |
100 | 97 | ||
... | @@ -116,7 +113,7 @@ public class JavaImportData { | ... | @@ -116,7 +113,7 @@ public class JavaImportData { |
116 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { | 113 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { |
117 | 114 | ||
118 | if (!(curNode instanceof HasJavaImportData)) { | 115 | if (!(curNode instanceof HasJavaImportData)) { |
119 | - throw new RuntimeException("missing import info in data model node"); | 116 | + throw new TranslatorException("missing import info in data model node"); |
120 | } | 117 | } |
121 | for (JavaQualifiedTypeInfo curImportInfo : ((HasJavaImportData) curNode).getJavaImportData().getImportSet()) { | 118 | for (JavaQualifiedTypeInfo curImportInfo : ((HasJavaImportData) curNode).getJavaImportData().getImportSet()) { |
122 | if (curImportInfo.getClassInfo() | 119 | if (curImportInfo.getClassInfo() |
... | @@ -165,7 +162,6 @@ public class JavaImportData { | ... | @@ -165,7 +162,6 @@ public class JavaImportData { |
165 | * @return import for hash and equals method | 162 | * @return import for hash and equals method |
166 | */ | 163 | */ |
167 | public String getImportForHashAndEquals() { | 164 | public String getImportForHashAndEquals() { |
168 | - | ||
169 | return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS; | 165 | return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS; |
170 | } | 166 | } |
171 | 167 | ||
... | @@ -175,15 +171,13 @@ public class JavaImportData { | ... | @@ -175,15 +171,13 @@ public class JavaImportData { |
175 | * @return import for to string method | 171 | * @return import for to string method |
176 | */ | 172 | */ |
177 | public String getImportForToString() { | 173 | public String getImportForToString() { |
178 | - | ||
179 | return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS; | 174 | return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS; |
180 | } | 175 | } |
181 | 176 | ||
182 | /** | 177 | /** |
183 | - * Sets import for to list. | 178 | + * Sets import for the list attribute. |
184 | */ | 179 | */ |
185 | private static String setImportForList() { | 180 | private static String setImportForList() { |
186 | - | ||
187 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; | 181 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; |
188 | } | 182 | } |
189 | } | 183 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -20,6 +20,7 @@ import java.util.Objects; | ... | @@ -20,6 +20,7 @@ import java.util.Objects; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.datamodel.YangType; | 22 | import org.onosproject.yangutils.datamodel.YangType; |
23 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
23 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | 24 | import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; |
24 | 25 | ||
25 | import com.google.common.base.MoreObjects; | 26 | import com.google.common.base.MoreObjects; |
... | @@ -51,7 +52,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -51,7 +52,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
51 | * @return the imported package info | 52 | * @return the imported package info |
52 | */ | 53 | */ |
53 | public String getPkgInfo() { | 54 | public String getPkgInfo() { |
54 | - | ||
55 | return pkgInfo; | 55 | return pkgInfo; |
56 | } | 56 | } |
57 | 57 | ||
... | @@ -61,7 +61,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -61,7 +61,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
61 | * @param pkgInfo the imported package info | 61 | * @param pkgInfo the imported package info |
62 | */ | 62 | */ |
63 | public void setPkgInfo(String pkgInfo) { | 63 | public void setPkgInfo(String pkgInfo) { |
64 | - | ||
65 | this.pkgInfo = pkgInfo; | 64 | this.pkgInfo = pkgInfo; |
66 | } | 65 | } |
67 | 66 | ||
... | @@ -71,7 +70,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -71,7 +70,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
71 | * @return the imported class/interface info | 70 | * @return the imported class/interface info |
72 | */ | 71 | */ |
73 | public String getClassInfo() { | 72 | public String getClassInfo() { |
74 | - | ||
75 | return classInfo; | 73 | return classInfo; |
76 | } | 74 | } |
77 | 75 | ||
... | @@ -81,7 +79,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -81,7 +79,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
81 | * @param classInfo the imported class/interface info | 79 | * @param classInfo the imported class/interface info |
82 | */ | 80 | */ |
83 | public void setClassInfo(String classInfo) { | 81 | public void setClassInfo(String classInfo) { |
84 | - | ||
85 | this.classInfo = classInfo; | 82 | this.classInfo = classInfo; |
86 | } | 83 | } |
87 | 84 | ||
... | @@ -105,7 +102,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -105,7 +102,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
105 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); | 102 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); |
106 | 103 | ||
107 | if (attrType == null) { | 104 | if (attrType == null) { |
108 | - throw new RuntimeException("missing data type of leaf " + attributeName); | 105 | + throw new TranslatorException("missing data type of leaf " + attributeName); |
109 | } | 106 | } |
110 | 107 | ||
111 | /* | 108 | /* |
... | @@ -121,7 +118,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -121,7 +118,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
121 | importInfo.setClassInfo(className); | 118 | importInfo.setClassInfo(className); |
122 | String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className); | 119 | String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className); |
123 | if (classPkg == null) { | 120 | if (classPkg == null) { |
124 | - throw new RuntimeException("import package cannot be null when the class is used"); | 121 | + throw new TranslatorException("import package cannot be null when the class is used"); |
125 | } | 122 | } |
126 | importInfo.setPkgInfo(classPkg); | 123 | importInfo.setPkgInfo(classPkg); |
127 | } else { | 124 | } else { |
... | @@ -131,7 +128,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -131,7 +128,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
131 | */ | 128 | */ |
132 | String dataTypeName = AttributesJavaDataType.getJavaDataType(attrType); | 129 | String dataTypeName = AttributesJavaDataType.getJavaDataType(attrType); |
133 | if (dataTypeName == null) { | 130 | if (dataTypeName == null) { |
134 | - throw new RuntimeException("not supported data type"); | 131 | + throw new TranslatorException("not supported data type"); |
135 | } | 132 | } |
136 | importInfo.setClassInfo(dataTypeName); | 133 | importInfo.setClassInfo(dataTypeName); |
137 | } | 134 | } |
... | @@ -155,7 +152,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -155,7 +152,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
155 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); | 152 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); |
156 | 153 | ||
157 | if (!(curNode instanceof HasJavaFileInfo)) { | 154 | if (!(curNode instanceof HasJavaFileInfo)) { |
158 | - throw new RuntimeException("missing java file information to get the package details " | 155 | + throw new TranslatorException("missing java file information to get the package details " |
159 | + "of attribute corresponding to child node"); | 156 | + "of attribute corresponding to child node"); |
160 | } | 157 | } |
161 | /* | 158 | /* |
... | @@ -184,7 +181,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -184,7 +181,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
184 | 181 | ||
185 | boolean isImportPkgEqualCurNodePkg; | 182 | boolean isImportPkgEqualCurNodePkg; |
186 | if (!(curNode instanceof HasJavaFileInfo)) { | 183 | if (!(curNode instanceof HasJavaFileInfo)) { |
187 | - throw new RuntimeException("missing java file info for getting the qualified access"); | 184 | + throw new TranslatorException("missing java file info for getting the qualified access"); |
188 | } | 185 | } |
189 | if (importInfo.getClassInfo().contentEquals( | 186 | if (importInfo.getClassInfo().contentEquals( |
190 | ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName())) { | 187 | ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName())) { |
... | @@ -211,7 +208,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -211,7 +208,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
211 | * If the current data model node is not supposed to import | 208 | * If the current data model node is not supposed to import |
212 | * data, then this is a usage issue and needs to be fixed. | 209 | * data, then this is a usage issue and needs to be fixed. |
213 | */ | 210 | */ |
214 | - throw new RuntimeException("Current node needs to support Imports"); | 211 | + throw new TranslatorException("Current node needs to support Imports"); |
215 | } | 212 | } |
216 | 213 | ||
217 | boolean isImportAdded = ((HasJavaImportData) curNode).getJavaImportData() | 214 | boolean isImportAdded = ((HasJavaImportData) curNode).getJavaImportData() |
... | @@ -241,7 +238,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -241,7 +238,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
241 | YangNode curNode, JavaQualifiedTypeInfo importInfo) { | 238 | YangNode curNode, JavaQualifiedTypeInfo importInfo) { |
242 | 239 | ||
243 | if (!(curNode instanceof HasJavaFileInfo)) { | 240 | if (!(curNode instanceof HasJavaFileInfo)) { |
244 | - throw new RuntimeException("missing java file info for the data model node"); | 241 | + throw new TranslatorException("missing java file info for the data model node"); |
245 | } | 242 | } |
246 | return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage() | 243 | return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage() |
247 | .contentEquals(importInfo.getPkgInfo() | 244 | .contentEquals(importInfo.getPkgInfo() |
... | @@ -250,7 +247,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -250,7 +247,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
250 | 247 | ||
251 | @Override | 248 | @Override |
252 | public int hashCode() { | 249 | public int hashCode() { |
253 | - | ||
254 | return Objects.hash(pkgInfo, classInfo); | 250 | return Objects.hash(pkgInfo, classInfo); |
255 | } | 251 | } |
256 | 252 | ||
... | @@ -275,7 +271,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -275,7 +271,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
275 | * @return if equal or not | 271 | * @return if equal or not |
276 | */ | 272 | */ |
277 | public boolean exactMatch(JavaQualifiedTypeInfo importInfo) { | 273 | public boolean exactMatch(JavaQualifiedTypeInfo importInfo) { |
278 | - | ||
279 | return equals(importInfo) | 274 | return equals(importInfo) |
280 | && Objects.equals(pkgInfo, importInfo.getPkgInfo()) | 275 | && Objects.equals(pkgInfo, importInfo.getPkgInfo()) |
281 | && Objects.equals(classInfo, importInfo.getClassInfo()); | 276 | && Objects.equals(classInfo, importInfo.getClassInfo()); |
... | @@ -283,7 +278,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -283,7 +278,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
283 | 278 | ||
284 | @Override | 279 | @Override |
285 | public String toString() { | 280 | public String toString() { |
286 | - | ||
287 | return MoreObjects.toStringHelper(getClass()) | 281 | return MoreObjects.toStringHelper(getClass()) |
288 | .add("pkgInfo", pkgInfo) | 282 | .add("pkgInfo", pkgInfo) |
289 | .add("classInfo", classInfo).toString(); | 283 | .add("classInfo", classInfo).toString(); |
... | @@ -296,7 +290,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -296,7 +290,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
296 | */ | 290 | */ |
297 | @Override | 291 | @Override |
298 | public int compareTo(JavaQualifiedTypeInfo other) { | 292 | public int compareTo(JavaQualifiedTypeInfo other) { |
299 | - | ||
300 | return getClassInfo().compareTo(other.getClassInfo()); | 293 | return getClassInfo().compareTo(other.getClassInfo()); |
301 | } | 294 | } |
302 | 295 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangAugment; | 20 | import org.onosproject.yangutils.datamodel.YangAugment; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaAugment extends YangAugment | ... | @@ -76,7 +77,7 @@ public class YangJavaAugment extends YangAugment |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaAugment extends YangAugment | ... | @@ -88,7 +89,6 @@ public class YangJavaAugment extends YangAugment |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaAugment extends YangAugment | ... | @@ -99,7 +99,6 @@ public class YangJavaAugment extends YangAugment |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaAugment extends YangAugment | ... | @@ -111,7 +110,6 @@ public class YangJavaAugment extends YangAugment |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaAugment extends YangAugment | ... | @@ -122,11 +120,6 @@ public class YangJavaAugment extends YangAugment |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("missing temp file hand for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaAugment extends YangAugment | ... | @@ -137,7 +130,6 @@ public class YangJavaAugment extends YangAugment |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangCase; | 20 | import org.onosproject.yangutils.datamodel.YangCase; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaCase extends YangCase | ... | @@ -76,7 +77,7 @@ public class YangJavaCase extends YangCase |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaCase extends YangCase | ... | @@ -88,7 +89,6 @@ public class YangJavaCase extends YangCase |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaCase extends YangCase | ... | @@ -99,7 +99,6 @@ public class YangJavaCase extends YangCase |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaCase extends YangCase | ... | @@ -111,7 +110,6 @@ public class YangJavaCase extends YangCase |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaCase extends YangCase | ... | @@ -122,11 +120,6 @@ public class YangJavaCase extends YangCase |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("missing temp file hand for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaCase extends YangCase | ... | @@ -137,7 +130,6 @@ public class YangJavaCase extends YangCase |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangChoice; | 20 | import org.onosproject.yangutils.datamodel.YangChoice; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaChoice extends YangChoice | ... | @@ -76,7 +77,7 @@ public class YangJavaChoice extends YangChoice |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -88,7 +89,6 @@ public class YangJavaChoice extends YangChoice |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -99,7 +99,6 @@ public class YangJavaChoice extends YangChoice |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -111,7 +110,6 @@ public class YangJavaChoice extends YangChoice |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -122,11 +120,6 @@ public class YangJavaChoice extends YangChoice |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("missing temp file hand for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaChoice extends YangChoice | ... | @@ -137,7 +130,6 @@ public class YangJavaChoice extends YangChoice |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangContainer; | 20 | import org.onosproject.yangutils.datamodel.YangContainer; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaContainer extends YangContainer | ... | @@ -76,7 +77,7 @@ public class YangJavaContainer extends YangContainer |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -88,7 +89,6 @@ public class YangJavaContainer extends YangContainer |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -99,7 +99,6 @@ public class YangJavaContainer extends YangContainer |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -111,7 +110,6 @@ public class YangJavaContainer extends YangContainer |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -122,11 +120,6 @@ public class YangJavaContainer extends YangContainer |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("Missing temp file handle for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -137,7 +130,6 @@ public class YangJavaContainer extends YangContainer |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ||
... | @@ -177,7 +169,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -177,7 +169,6 @@ public class YangJavaContainer extends YangContainer |
177 | */ | 169 | */ |
178 | @Override | 170 | @Override |
179 | public void generateCodeExit() throws IOException { | 171 | public void generateCodeExit() throws IOException { |
180 | - | ||
181 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 172 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
182 | } | 173 | } |
183 | 174 | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangGrouping; | 20 | import org.onosproject.yangutils.datamodel.YangGrouping; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -76,7 +77,7 @@ public class YangJavaGrouping extends YangGrouping |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -88,7 +89,6 @@ public class YangJavaGrouping extends YangGrouping |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -99,7 +99,6 @@ public class YangJavaGrouping extends YangGrouping |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -111,7 +110,6 @@ public class YangJavaGrouping extends YangGrouping |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -122,11 +120,6 @@ public class YangJavaGrouping extends YangGrouping |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("missing temp file hand for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaGrouping extends YangGrouping | ... | @@ -137,7 +130,6 @@ public class YangJavaGrouping extends YangGrouping |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangInput; | 21 | import org.onosproject.yangutils.datamodel.YangInput; |
22 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -78,7 +79,7 @@ public class YangJavaInput extends YangInput | ... | @@ -78,7 +79,7 @@ public class YangJavaInput extends YangInput |
78 | public JavaFileInfo getJavaFileInfo() { | 79 | public JavaFileInfo getJavaFileInfo() { |
79 | 80 | ||
80 | if (javaFileInfo == null) { | 81 | if (javaFileInfo == null) { |
81 | - throw new RuntimeException("Missing java info in java datamodel node"); | 82 | + throw new TranslatorException("Missing java info in java datamodel node"); |
82 | } | 83 | } |
83 | return javaFileInfo; | 84 | return javaFileInfo; |
84 | } | 85 | } |
... | @@ -90,7 +91,6 @@ public class YangJavaInput extends YangInput | ... | @@ -90,7 +91,6 @@ public class YangJavaInput extends YangInput |
90 | */ | 91 | */ |
91 | @Override | 92 | @Override |
92 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 93 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
93 | - | ||
94 | javaFileInfo = javaInfo; | 94 | javaFileInfo = javaInfo; |
95 | } | 95 | } |
96 | 96 | ||
... | @@ -101,7 +101,6 @@ public class YangJavaInput extends YangInput | ... | @@ -101,7 +101,6 @@ public class YangJavaInput extends YangInput |
101 | */ | 101 | */ |
102 | @Override | 102 | @Override |
103 | public JavaImportData getJavaImportData() { | 103 | public JavaImportData getJavaImportData() { |
104 | - | ||
105 | return javaImportData; | 104 | return javaImportData; |
106 | } | 105 | } |
107 | 106 | ||
... | @@ -113,7 +112,6 @@ public class YangJavaInput extends YangInput | ... | @@ -113,7 +112,6 @@ public class YangJavaInput extends YangInput |
113 | */ | 112 | */ |
114 | @Override | 113 | @Override |
115 | public void setJavaImportData(JavaImportData javaImportData) { | 114 | public void setJavaImportData(JavaImportData javaImportData) { |
116 | - | ||
117 | this.javaImportData = javaImportData; | 115 | this.javaImportData = javaImportData; |
118 | } | 116 | } |
119 | 117 | ||
... | @@ -124,11 +122,6 @@ public class YangJavaInput extends YangInput | ... | @@ -124,11 +122,6 @@ public class YangJavaInput extends YangInput |
124 | */ | 122 | */ |
125 | @Override | 123 | @Override |
126 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
127 | - | ||
128 | - if (tempFileHandle == null) { | ||
129 | - throw new RuntimeException("Missing temporary file handle for" + | ||
130 | - "current node " + getJavaFileInfo().getJavaName()); | ||
131 | - } | ||
132 | return tempFileHandle; | 125 | return tempFileHandle; |
133 | } | 126 | } |
134 | 127 | ||
... | @@ -139,7 +132,6 @@ public class YangJavaInput extends YangInput | ... | @@ -139,7 +132,6 @@ public class YangJavaInput extends YangInput |
139 | */ | 132 | */ |
140 | @Override | 133 | @Override |
141 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 134 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
142 | - | ||
143 | tempFileHandle = fileHandle; | 135 | tempFileHandle = fileHandle; |
144 | } | 136 | } |
145 | 137 | ||
... | @@ -179,7 +171,6 @@ public class YangJavaInput extends YangInput | ... | @@ -179,7 +171,6 @@ public class YangJavaInput extends YangInput |
179 | */ | 171 | */ |
180 | @Override | 172 | @Override |
181 | public void generateCodeExit() throws IOException { | 173 | public void generateCodeExit() throws IOException { |
182 | - | ||
183 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 174 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
184 | } | 175 | } |
185 | } | 176 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangList; | 20 | import org.onosproject.yangutils.datamodel.YangList; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -77,7 +78,7 @@ public class YangJavaList extends YangList | ... | @@ -77,7 +78,7 @@ public class YangJavaList extends YangList |
77 | public JavaFileInfo getJavaFileInfo() { | 78 | public JavaFileInfo getJavaFileInfo() { |
78 | 79 | ||
79 | if (javaFileInfo == null) { | 80 | if (javaFileInfo == null) { |
80 | - throw new RuntimeException("Missing java info in java datamodel node"); | 81 | + throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 82 | } |
82 | return javaFileInfo; | 83 | return javaFileInfo; |
83 | } | 84 | } |
... | @@ -89,7 +90,6 @@ public class YangJavaList extends YangList | ... | @@ -89,7 +90,6 @@ public class YangJavaList extends YangList |
89 | */ | 90 | */ |
90 | @Override | 91 | @Override |
91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 92 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
92 | - | ||
93 | javaFileInfo = javaInfo; | 93 | javaFileInfo = javaInfo; |
94 | } | 94 | } |
95 | 95 | ||
... | @@ -100,7 +100,6 @@ public class YangJavaList extends YangList | ... | @@ -100,7 +100,6 @@ public class YangJavaList extends YangList |
100 | */ | 100 | */ |
101 | @Override | 101 | @Override |
102 | public JavaImportData getJavaImportData() { | 102 | public JavaImportData getJavaImportData() { |
103 | - | ||
104 | return javaImportData; | 103 | return javaImportData; |
105 | } | 104 | } |
106 | 105 | ||
... | @@ -112,7 +111,6 @@ public class YangJavaList extends YangList | ... | @@ -112,7 +111,6 @@ public class YangJavaList extends YangList |
112 | */ | 111 | */ |
113 | @Override | 112 | @Override |
114 | public void setJavaImportData(JavaImportData javaImportData) { | 113 | public void setJavaImportData(JavaImportData javaImportData) { |
115 | - | ||
116 | this.javaImportData = javaImportData; | 114 | this.javaImportData = javaImportData; |
117 | } | 115 | } |
118 | 116 | ||
... | @@ -123,11 +121,6 @@ public class YangJavaList extends YangList | ... | @@ -123,11 +121,6 @@ public class YangJavaList extends YangList |
123 | */ | 121 | */ |
124 | @Override | 122 | @Override |
125 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 123 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
126 | - | ||
127 | - if (tempFileHandle == null) { | ||
128 | - throw new RuntimeException("missing temp file hand for current node " | ||
129 | - + getJavaFileInfo().getJavaName()); | ||
130 | - } | ||
131 | return tempFileHandle; | 124 | return tempFileHandle; |
132 | } | 125 | } |
133 | 126 | ||
... | @@ -138,7 +131,6 @@ public class YangJavaList extends YangList | ... | @@ -138,7 +131,6 @@ public class YangJavaList extends YangList |
138 | */ | 131 | */ |
139 | @Override | 132 | @Override |
140 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 133 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
141 | - | ||
142 | tempFileHandle = fileHandle; | 134 | tempFileHandle = fileHandle; |
143 | } | 135 | } |
144 | 136 | ||
... | @@ -180,7 +172,6 @@ public class YangJavaList extends YangList | ... | @@ -180,7 +172,6 @@ public class YangJavaList extends YangList |
180 | */ | 172 | */ |
181 | @Override | 173 | @Override |
182 | public void generateCodeExit() throws IOException { | 174 | public void generateCodeExit() throws IOException { |
183 | - | ||
184 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 175 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 176 | } |
186 | } | 177 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangModule; | 20 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -76,7 +77,7 @@ public class YangJavaModule extends YangModule | ... | @@ -76,7 +77,7 @@ public class YangJavaModule extends YangModule |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaModule extends YangModule | ... | @@ -88,7 +89,6 @@ public class YangJavaModule extends YangModule |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaModule extends YangModule | ... | @@ -99,7 +99,6 @@ public class YangJavaModule extends YangModule |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaModule extends YangModule | ... | @@ -111,7 +110,6 @@ public class YangJavaModule extends YangModule |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaModule extends YangModule | ... | @@ -122,11 +120,6 @@ public class YangJavaModule extends YangModule |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("missing temp file hand for current node " | ||
128 | - + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaModule extends YangModule | ... | @@ -137,7 +130,6 @@ public class YangJavaModule extends YangModule |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ||
... | @@ -170,7 +162,6 @@ public class YangJavaModule extends YangModule | ... | @@ -170,7 +162,6 @@ public class YangJavaModule extends YangModule |
170 | 162 | ||
171 | @Override | 163 | @Override |
172 | public void generateCodeExit() throws IOException { | 164 | public void generateCodeExit() throws IOException { |
173 | - | ||
174 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 165 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
175 | return; | 166 | return; |
176 | } | 167 | } | ... | ... |
... | @@ -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 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
20 | import org.onosproject.yangutils.datamodel.YangNotification; | 21 | import org.onosproject.yangutils.datamodel.YangNotification; |
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; |
... | @@ -76,7 +77,7 @@ public class YangJavaNotification extends YangNotification | ... | @@ -76,7 +77,7 @@ public class YangJavaNotification extends YangNotification |
76 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
77 | 78 | ||
78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node"); | 80 | + throw new TranslatorException("Missing java info in java datamodel node"); |
80 | } | 81 | } |
81 | return javaFileInfo; | 82 | return javaFileInfo; |
82 | } | 83 | } |
... | @@ -88,7 +89,6 @@ public class YangJavaNotification extends YangNotification | ... | @@ -88,7 +89,6 @@ public class YangJavaNotification extends YangNotification |
88 | */ | 89 | */ |
89 | @Override | 90 | @Override |
90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
91 | - | ||
92 | javaFileInfo = javaInfo; | 92 | javaFileInfo = javaInfo; |
93 | } | 93 | } |
94 | 94 | ||
... | @@ -99,7 +99,6 @@ public class YangJavaNotification extends YangNotification | ... | @@ -99,7 +99,6 @@ public class YangJavaNotification extends YangNotification |
99 | */ | 99 | */ |
100 | @Override | 100 | @Override |
101 | public JavaImportData getJavaImportData() { | 101 | public JavaImportData getJavaImportData() { |
102 | - | ||
103 | return javaImportData; | 102 | return javaImportData; |
104 | } | 103 | } |
105 | 104 | ||
... | @@ -111,7 +110,6 @@ public class YangJavaNotification extends YangNotification | ... | @@ -111,7 +110,6 @@ public class YangJavaNotification extends YangNotification |
111 | */ | 110 | */ |
112 | @Override | 111 | @Override |
113 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
114 | - | ||
115 | this.javaImportData = javaImportData; | 113 | this.javaImportData = javaImportData; |
116 | } | 114 | } |
117 | 115 | ||
... | @@ -122,11 +120,6 @@ public class YangJavaNotification extends YangNotification | ... | @@ -122,11 +120,6 @@ public class YangJavaNotification extends YangNotification |
122 | */ | 120 | */ |
123 | @Override | 121 | @Override |
124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 122 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
125 | - | ||
126 | - if (tempFileHandle == null) { | ||
127 | - throw new RuntimeException("Missing temporary file handle for" + | ||
128 | - "current node " + getJavaFileInfo().getJavaName()); | ||
129 | - } | ||
130 | return tempFileHandle; | 123 | return tempFileHandle; |
131 | } | 124 | } |
132 | 125 | ||
... | @@ -137,7 +130,6 @@ public class YangJavaNotification extends YangNotification | ... | @@ -137,7 +130,6 @@ public class YangJavaNotification extends YangNotification |
137 | */ | 130 | */ |
138 | @Override | 131 | @Override |
139 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 132 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
140 | - | ||
141 | tempFileHandle = fileHandle; | 133 | tempFileHandle = fileHandle; |
142 | } | 134 | } |
143 | 135 | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | import org.onosproject.yangutils.datamodel.YangOutput; | 21 | import org.onosproject.yangutils.datamodel.YangOutput; |
22 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -78,7 +79,7 @@ public class YangJavaOutput extends YangOutput | ... | @@ -78,7 +79,7 @@ public class YangJavaOutput extends YangOutput |
78 | public JavaFileInfo getJavaFileInfo() { | 79 | public JavaFileInfo getJavaFileInfo() { |
79 | 80 | ||
80 | if (javaFileInfo == null) { | 81 | if (javaFileInfo == null) { |
81 | - throw new RuntimeException("Missing java info in java datamodel node"); | 82 | + throw new TranslatorException("Missing java info in java datamodel node"); |
82 | } | 83 | } |
83 | return javaFileInfo; | 84 | return javaFileInfo; |
84 | } | 85 | } |
... | @@ -90,7 +91,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -90,7 +91,6 @@ public class YangJavaOutput extends YangOutput |
90 | */ | 91 | */ |
91 | @Override | 92 | @Override |
92 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 93 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
93 | - | ||
94 | javaFileInfo = javaInfo; | 94 | javaFileInfo = javaInfo; |
95 | } | 95 | } |
96 | 96 | ||
... | @@ -101,7 +101,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -101,7 +101,6 @@ public class YangJavaOutput extends YangOutput |
101 | */ | 101 | */ |
102 | @Override | 102 | @Override |
103 | public JavaImportData getJavaImportData() { | 103 | public JavaImportData getJavaImportData() { |
104 | - | ||
105 | return javaImportData; | 104 | return javaImportData; |
106 | } | 105 | } |
107 | 106 | ||
... | @@ -113,7 +112,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -113,7 +112,6 @@ public class YangJavaOutput extends YangOutput |
113 | */ | 112 | */ |
114 | @Override | 113 | @Override |
115 | public void setJavaImportData(JavaImportData javaImportData) { | 114 | public void setJavaImportData(JavaImportData javaImportData) { |
116 | - | ||
117 | this.javaImportData = javaImportData; | 115 | this.javaImportData = javaImportData; |
118 | } | 116 | } |
119 | 117 | ||
... | @@ -124,11 +122,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -124,11 +122,6 @@ public class YangJavaOutput extends YangOutput |
124 | */ | 122 | */ |
125 | @Override | 123 | @Override |
126 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 124 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
127 | - | ||
128 | - if (tempFileHandle == null) { | ||
129 | - throw new RuntimeException("Missing temporary file handle for" + | ||
130 | - "current node " + getJavaFileInfo().getJavaName()); | ||
131 | - } | ||
132 | return tempFileHandle; | 125 | return tempFileHandle; |
133 | } | 126 | } |
134 | 127 | ||
... | @@ -139,7 +132,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -139,7 +132,6 @@ public class YangJavaOutput extends YangOutput |
139 | */ | 132 | */ |
140 | @Override | 133 | @Override |
141 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 134 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
142 | - | ||
143 | tempFileHandle = fileHandle; | 135 | tempFileHandle = fileHandle; |
144 | } | 136 | } |
145 | 137 | ||
... | @@ -179,7 +171,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -179,7 +171,6 @@ public class YangJavaOutput extends YangOutput |
179 | */ | 171 | */ |
180 | @Override | 172 | @Override |
181 | public void generateCodeExit() throws IOException { | 173 | public void generateCodeExit() throws IOException { |
182 | - | ||
183 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 174 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
184 | } | 175 | } |
185 | } | 176 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import java.io.IOException; | ... | @@ -19,6 +19,7 @@ import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangBelongsTo; | 20 | import org.onosproject.yangutils.datamodel.YangBelongsTo; |
21 | import org.onosproject.yangutils.datamodel.YangSubModule; | 21 | import org.onosproject.yangutils.datamodel.YangSubModule; |
22 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 24 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -77,7 +78,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -77,7 +78,7 @@ public class YangJavaSubModule extends YangSubModule |
77 | public JavaFileInfo getJavaFileInfo() { | 78 | public JavaFileInfo getJavaFileInfo() { |
78 | 79 | ||
79 | if (javaFileInfo == null) { | 80 | if (javaFileInfo == null) { |
80 | - throw new RuntimeException("Missing java info in java datamodel node"); | 81 | + throw new TranslatorException("Missing java info in java datamodel node"); |
81 | } | 82 | } |
82 | return javaFileInfo; | 83 | return javaFileInfo; |
83 | } | 84 | } |
... | @@ -89,7 +90,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -89,7 +90,6 @@ public class YangJavaSubModule extends YangSubModule |
89 | */ | 90 | */ |
90 | @Override | 91 | @Override |
91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 92 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
92 | - | ||
93 | javaFileInfo = javaInfo; | 93 | javaFileInfo = javaInfo; |
94 | } | 94 | } |
95 | 95 | ||
... | @@ -100,7 +100,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -100,7 +100,6 @@ public class YangJavaSubModule extends YangSubModule |
100 | */ | 100 | */ |
101 | @Override | 101 | @Override |
102 | public JavaImportData getJavaImportData() { | 102 | public JavaImportData getJavaImportData() { |
103 | - | ||
104 | return javaImportData; | 103 | return javaImportData; |
105 | } | 104 | } |
106 | 105 | ||
... | @@ -112,7 +111,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -112,7 +111,6 @@ public class YangJavaSubModule extends YangSubModule |
112 | */ | 111 | */ |
113 | @Override | 112 | @Override |
114 | public void setJavaImportData(JavaImportData javaImportData) { | 113 | public void setJavaImportData(JavaImportData javaImportData) { |
115 | - | ||
116 | this.javaImportData = javaImportData; | 114 | this.javaImportData = javaImportData; |
117 | } | 115 | } |
118 | 116 | ||
... | @@ -123,11 +121,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -123,11 +121,6 @@ public class YangJavaSubModule extends YangSubModule |
123 | */ | 121 | */ |
124 | @Override | 122 | @Override |
125 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 123 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
126 | - | ||
127 | - if (tempFileHandle == null) { | ||
128 | - throw new RuntimeException("missing temp file hand for current node " | ||
129 | - + getJavaFileInfo().getJavaName()); | ||
130 | - } | ||
131 | return tempFileHandle; | 124 | return tempFileHandle; |
132 | } | 125 | } |
133 | 126 | ||
... | @@ -138,7 +131,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -138,7 +131,6 @@ public class YangJavaSubModule extends YangSubModule |
138 | */ | 131 | */ |
139 | @Override | 132 | @Override |
140 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 133 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
141 | - | ||
142 | tempFileHandle = fileHandle; | 134 | tempFileHandle = fileHandle; |
143 | } | 135 | } |
144 | 136 | ||
... | @@ -150,7 +142,6 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -150,7 +142,6 @@ public class YangJavaSubModule extends YangSubModule |
150 | * @return the name space string of the module. | 142 | * @return the name space string of the module. |
151 | */ | 143 | */ |
152 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { | 144 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { |
153 | - | ||
154 | // TODO Auto-generated method stub | 145 | // TODO Auto-generated method stub |
155 | return ""; | 146 | return ""; |
156 | } | 147 | } |
... | @@ -190,6 +181,5 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -190,6 +181,5 @@ public class YangJavaSubModule extends YangSubModule |
190 | @Override | 181 | @Override |
191 | public void generateCodeExit() { | 182 | public void generateCodeExit() { |
192 | // TODO Auto-generated method stub | 183 | // TODO Auto-generated method stub |
193 | - | ||
194 | } | 184 | } |
195 | } | 185 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; |
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 20 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
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; |
23 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -75,7 +76,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -75,7 +76,7 @@ public class YangJavaTypeDef extends YangTypeDef |
75 | public JavaFileInfo getJavaFileInfo() { | 76 | public JavaFileInfo getJavaFileInfo() { |
76 | 77 | ||
77 | if (javaFileInfo == null) { | 78 | if (javaFileInfo == null) { |
78 | - throw new RuntimeException("Missing java info in java datamodel node"); | 79 | + throw new TranslatorException("Missing java info in java datamodel node"); |
79 | } | 80 | } |
80 | return javaFileInfo; | 81 | return javaFileInfo; |
81 | } | 82 | } |
... | @@ -87,7 +88,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -87,7 +88,6 @@ public class YangJavaTypeDef extends YangTypeDef |
87 | */ | 88 | */ |
88 | @Override | 89 | @Override |
89 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
90 | - | ||
91 | javaFileInfo = javaInfo; | 91 | javaFileInfo = javaInfo; |
92 | } | 92 | } |
93 | 93 | ||
... | @@ -98,7 +98,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -98,7 +98,6 @@ public class YangJavaTypeDef extends YangTypeDef |
98 | */ | 98 | */ |
99 | @Override | 99 | @Override |
100 | public JavaImportData getJavaImportData() { | 100 | public JavaImportData getJavaImportData() { |
101 | - | ||
102 | return javaImportData; | 101 | return javaImportData; |
103 | } | 102 | } |
104 | 103 | ||
... | @@ -110,7 +109,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -110,7 +109,6 @@ public class YangJavaTypeDef extends YangTypeDef |
110 | */ | 109 | */ |
111 | @Override | 110 | @Override |
112 | public void setJavaImportData(JavaImportData javaImportData) { | 111 | public void setJavaImportData(JavaImportData javaImportData) { |
113 | - | ||
114 | this.javaImportData = javaImportData; | 112 | this.javaImportData = javaImportData; |
115 | } | 113 | } |
116 | 114 | ||
... | @@ -121,11 +119,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -121,11 +119,6 @@ public class YangJavaTypeDef extends YangTypeDef |
121 | */ | 119 | */ |
122 | @Override | 120 | @Override |
123 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 121 | 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; | 122 | return tempFileHandle; |
130 | } | 123 | } |
131 | 124 | ||
... | @@ -136,7 +129,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -136,7 +129,6 @@ public class YangJavaTypeDef extends YangTypeDef |
136 | */ | 129 | */ |
137 | @Override | 130 | @Override |
138 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 131 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
139 | - | ||
140 | tempFileHandle = fileHandle; | 132 | tempFileHandle = fileHandle; |
141 | } | 133 | } |
142 | 134 | ||
... | @@ -170,11 +162,11 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -170,11 +162,11 @@ public class YangJavaTypeDef extends YangTypeDef |
170 | 162 | ||
171 | /** | 163 | /** |
172 | * Create a java file using the YANG grouping info. | 164 | * Create a java file using the YANG grouping info. |
165 | + * | ||
173 | * @throws IOException IO operations fails | 166 | * @throws IOException IO operations fails |
174 | */ | 167 | */ |
175 | @Override | 168 | @Override |
176 | public void generateCodeExit() throws IOException { | 169 | public void generateCodeExit() throws IOException { |
177 | - | ||
178 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); | 170 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); |
179 | } | 171 | } |
180 | 172 | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | import org.onosproject.yangutils.datamodel.YangUses; | 18 | import org.onosproject.yangutils.datamodel.YangUses; |
19 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
19 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 20 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
20 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 21 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
... | @@ -61,8 +62,9 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava | ... | @@ -61,8 +62,9 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava |
61 | */ | 62 | */ |
62 | @Override | 63 | @Override |
63 | public JavaFileInfo getJavaFileInfo() { | 64 | public JavaFileInfo getJavaFileInfo() { |
65 | + | ||
64 | if (javaFileInfo == null) { | 66 | if (javaFileInfo == null) { |
65 | - throw new RuntimeException("Missing java info in java datamodel node"); | 67 | + throw new TranslatorException("Missing java info in java datamodel node"); |
66 | } | 68 | } |
67 | return javaFileInfo; | 69 | return javaFileInfo; |
68 | } | 70 | } |
... | @@ -106,6 +108,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava | ... | @@ -106,6 +108,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava |
106 | */ | 108 | */ |
107 | @Override | 109 | @Override |
108 | public void generateCodeEntry(String codeGenDir) { | 110 | public void generateCodeEntry(String codeGenDir) { |
111 | + | ||
109 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 112 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
110 | getJavaFileInfo().setPackage(getCurNodePackage(this)); | 113 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
111 | getJavaFileInfo().setPackageFilePath( | 114 | getJavaFileInfo().setPackageFilePath( | ... | ... |
... | @@ -47,6 +47,8 @@ public final class JavaIdentifierSyntax { | ... | @@ -47,6 +47,8 @@ public final class JavaIdentifierSyntax { |
47 | private static final int INDEX_ZERO = 0; | 47 | private static final int INDEX_ZERO = 0; |
48 | private static final int INDEX_ONE = 1; | 48 | private static final int INDEX_ONE = 1; |
49 | private static final int INDEX_TWO = 2; | 49 | private static final int INDEX_TWO = 2; |
50 | + private static final int VALUE_CHECK = 10; | ||
51 | + private static final String ZERO = "0"; | ||
50 | 52 | ||
51 | /** | 53 | /** |
52 | * Default constructor. | 54 | * Default constructor. |
... | @@ -103,12 +105,12 @@ public final class JavaIdentifierSyntax { | ... | @@ -103,12 +105,12 @@ public final class JavaIdentifierSyntax { |
103 | String pkg; | 105 | String pkg; |
104 | if (!(curNode instanceof HasJavaFileInfo) | 106 | if (!(curNode instanceof HasJavaFileInfo) |
105 | || curNode.getParent() == null) { | 107 | || curNode.getParent() == null) { |
106 | - throw new RuntimeException("missing parent node to get current node's package"); | 108 | + throw new TranslatorException("missing parent node to get current node's package"); |
107 | } | 109 | } |
108 | 110 | ||
109 | YangNode parentNode = getParentNodeInGenCode(curNode); | 111 | YangNode parentNode = getParentNodeInGenCode(curNode); |
110 | if (!(parentNode instanceof HasJavaFileInfo)) { | 112 | if (!(parentNode instanceof HasJavaFileInfo)) { |
111 | - throw new RuntimeException("missing parent java node to get current node's package"); | 113 | + throw new TranslatorException("missing parent java node to get current node's package"); |
112 | } | 114 | } |
113 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); | 115 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); |
114 | pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName(); | 116 | pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName(); |
... | @@ -122,7 +124,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -122,7 +124,6 @@ public final class JavaIdentifierSyntax { |
122 | * @return version | 124 | * @return version |
123 | */ | 125 | */ |
124 | private static String getYangVersion(byte ver) { | 126 | private static String getYangVersion(byte ver) { |
125 | - | ||
126 | return VERSION_PREFIX + ver; | 127 | return VERSION_PREFIX + ver; |
127 | } | 128 | } |
128 | 129 | ||
... | @@ -164,8 +165,8 @@ public final class JavaIdentifierSyntax { | ... | @@ -164,8 +165,8 @@ public final class JavaIdentifierSyntax { |
164 | for (int i = INDEX_ONE; i < revisionArr.length; i++) { | 165 | for (int i = INDEX_ONE; i < revisionArr.length; i++) { |
165 | 166 | ||
166 | Integer val = Integer.parseInt(revisionArr[i]); | 167 | Integer val = Integer.parseInt(revisionArr[i]); |
167 | - if (val < 10) { | 168 | + if (val < VALUE_CHECK) { |
168 | - rev = rev + "0"; | 169 | + rev = rev + ZERO; |
169 | } | 170 | } |
170 | rev = rev + val; | 171 | rev = rev + val; |
171 | } | 172 | } |
... | @@ -242,7 +243,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -242,7 +243,6 @@ public final class JavaIdentifierSyntax { |
242 | * @return corresponding java identifier | 243 | * @return corresponding java identifier |
243 | */ | 244 | */ |
244 | public static String getCaptialCase(String yangIdentifier) { | 245 | public static String getCaptialCase(String yangIdentifier) { |
245 | - | ||
246 | return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1); | 246 | return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1); |
247 | } | 247 | } |
248 | 248 | ||
... | @@ -254,7 +254,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -254,7 +254,6 @@ public final class JavaIdentifierSyntax { |
254 | * @return corresponding java identifier | 254 | * @return corresponding java identifier |
255 | */ | 255 | */ |
256 | public static String getSmallCase(String yangIdentifier) { | 256 | public static String getSmallCase(String yangIdentifier) { |
257 | - | ||
258 | return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1); | 257 | return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1); |
259 | } | 258 | } |
260 | 259 | ||
... | @@ -265,7 +264,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -265,7 +264,6 @@ public final class JavaIdentifierSyntax { |
265 | * @return java package | 264 | * @return java package |
266 | */ | 265 | */ |
267 | public static String getJavaPackageFromPackagePath(String packagePath) { | 266 | public static String getJavaPackageFromPackagePath(String packagePath) { |
268 | - | ||
269 | return packagePath.replace(SLASH, PERIOD); | 267 | return packagePath.replace(SLASH, PERIOD); |
270 | } | 268 | } |
271 | 269 | ||
... | @@ -276,7 +274,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -276,7 +274,6 @@ public final class JavaIdentifierSyntax { |
276 | * @return java package | 274 | * @return java package |
277 | */ | 275 | */ |
278 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { | 276 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { |
279 | - | ||
280 | return packagePath.replace(PERIOD, SLASH); | 277 | return packagePath.replace(PERIOD, SLASH); |
281 | } | 278 | } |
282 | } | 279 | } | ... | ... |
... | @@ -34,17 +34,18 @@ public final class UtilConstants { | ... | @@ -34,17 +34,18 @@ public final class UtilConstants { |
34 | /** | 34 | /** |
35 | * JavaDocs for impl class. | 35 | * JavaDocs for impl class. |
36 | */ | 36 | */ |
37 | - public static final String IMPL_CLASS_JAVA_DOC = " * Provides the implementation of "; | 37 | + public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of "; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * JavaDocs for builder class. | 40 | * JavaDocs for builder class. |
41 | */ | 41 | */ |
42 | - public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of "; | 42 | + public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of "; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * JavaDocs for interface class. | 45 | * JavaDocs for interface class. |
46 | */ | 46 | */ |
47 | - public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of "; | 47 | + public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the" |
48 | + + " functionalities of "; | ||
48 | 49 | ||
49 | /** | 50 | /** |
50 | * JavaDocs for builder interface class. | 51 | * JavaDocs for builder interface class. |
... | @@ -102,14 +103,9 @@ public final class UtilConstants { | ... | @@ -102,14 +103,9 @@ public final class UtilConstants { |
102 | public static final String JAVA_DOC_GETTERS = " * Returns the attribute "; | 103 | public static final String JAVA_DOC_GETTERS = " * Returns the attribute "; |
103 | 104 | ||
104 | /** | 105 | /** |
105 | - * JavaDocs's description for default constructor. | ||
106 | - */ | ||
107 | - public static final String JAVA_DOC_DEFAULT_CONSTRUCTOR = " * Default Constructor.\n"; | ||
108 | - | ||
109 | - /** | ||
110 | * JavaDocs's description for constructor. | 106 | * JavaDocs's description for constructor. |
111 | */ | 107 | */ |
112 | - public static final String JAVA_DOC_CONSTRUCTOR = " * Construct the object of "; | 108 | + public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of "; |
113 | 109 | ||
114 | /** | 110 | /** |
115 | * JavaDocs's description for build method. | 111 | * JavaDocs's description for build method. | ... | ... |
... | @@ -30,7 +30,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC; | ... | @@ -30,7 +30,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR; | 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; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS; |
... | @@ -164,7 +163,7 @@ public final class JavaDocGen { | ... | @@ -164,7 +163,7 @@ public final class JavaDocGen { |
164 | } else if (type.equals(JavaDocType.OF_METHOD)) { | 163 | } else if (type.equals(JavaDocType.OF_METHOD)) { |
165 | javaDoc = generateForOf(name); | 164 | javaDoc = generateForOf(name); |
166 | } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { | 165 | } else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) { |
167 | - javaDoc = generateForDefaultConstructors(); | 166 | + javaDoc = generateForDefaultConstructors(name); |
168 | } else if (type.equals(JavaDocType.BUILD_METHOD)) { | 167 | } else if (type.equals(JavaDocType.BUILD_METHOD)) { |
169 | javaDoc = generateForBuild(name); | 168 | javaDoc = generateForBuild(name); |
170 | } else { | 169 | } else { |
... | @@ -226,7 +225,6 @@ public final class JavaDocGen { | ... | @@ -226,7 +225,6 @@ public final class JavaDocGen { |
226 | * @return javaDocs | 225 | * @return javaDocs |
227 | */ | 226 | */ |
228 | private static String generateForOf(String attribute) { | 227 | private static String generateForOf(String attribute) { |
229 | - | ||
230 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF | 228 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF |
231 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION | 229 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION |
232 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE | 230 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
... | @@ -241,7 +239,6 @@ public final class JavaDocGen { | ... | @@ -241,7 +239,6 @@ public final class JavaDocGen { |
241 | * @return javaDocs | 239 | * @return javaDocs |
242 | */ | 240 | */ |
243 | private static String generateForTypeDefSetter(String attribute) { | 241 | private static String generateForTypeDefSetter(String attribute) { |
244 | - | ||
245 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 242 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
246 | + JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK | 243 | + JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
247 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute | 244 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute |
... | @@ -255,7 +252,6 @@ public final class JavaDocGen { | ... | @@ -255,7 +252,6 @@ public final class JavaDocGen { |
255 | * @return javaDocs | 252 | * @return javaDocs |
256 | */ | 253 | */ |
257 | private static String generateForTypeDefConstructor(String attribute) { | 254 | private static String generateForTypeDefConstructor(String attribute) { |
258 | - | ||
259 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR | 255 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR |
260 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION | 256 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION |
261 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE | 257 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
... | @@ -269,7 +265,6 @@ public final class JavaDocGen { | ... | @@ -269,7 +265,6 @@ public final class JavaDocGen { |
269 | * @return javaDocs | 265 | * @return javaDocs |
270 | */ | 266 | */ |
271 | private static String generateForImplClass(String className) { | 267 | private static String generateForImplClass(String className) { |
272 | - | ||
273 | return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; | 268 | return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
274 | } | 269 | } |
275 | 270 | ||
... | @@ -280,7 +275,6 @@ public final class JavaDocGen { | ... | @@ -280,7 +275,6 @@ public final class JavaDocGen { |
280 | * @return javaDocs | 275 | * @return javaDocs |
281 | */ | 276 | */ |
282 | private static String generateForBuilderClass(String className) { | 277 | private static String generateForBuilderClass(String className) { |
283 | - | ||
284 | return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE | 278 | return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE |
285 | + JAVA_DOC_END_LINE; | 279 | + JAVA_DOC_END_LINE; |
286 | } | 280 | } |
... | @@ -292,7 +286,6 @@ public final class JavaDocGen { | ... | @@ -292,7 +286,6 @@ public final class JavaDocGen { |
292 | * @return javaDocs | 286 | * @return javaDocs |
293 | */ | 287 | */ |
294 | private static String generateForInterface(String interfaceName) { | 288 | private static String generateForInterface(String interfaceName) { |
295 | - | ||
296 | return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE | 289 | return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE |
297 | + JAVA_DOC_END_LINE; | 290 | + JAVA_DOC_END_LINE; |
298 | } | 291 | } |
... | @@ -304,7 +297,6 @@ public final class JavaDocGen { | ... | @@ -304,7 +297,6 @@ public final class JavaDocGen { |
304 | * @return javaDocs | 297 | * @return javaDocs |
305 | */ | 298 | */ |
306 | private static String generateForBuilderInterface(String builderforName) { | 299 | private static String generateForBuilderInterface(String builderforName) { |
307 | - | ||
308 | return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE | 300 | return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE |
309 | + JAVA_DOC_END_LINE; | 301 | + JAVA_DOC_END_LINE; |
310 | } | 302 | } |
... | @@ -316,19 +308,18 @@ public final class JavaDocGen { | ... | @@ -316,19 +308,18 @@ public final class JavaDocGen { |
316 | * @return javaDocs | 308 | * @return javaDocs |
317 | */ | 309 | */ |
318 | private static String generateForPackage(String packageName) { | 310 | private static String generateForPackage(String packageName) { |
319 | - | ||
320 | return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; | 311 | return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
321 | } | 312 | } |
322 | 313 | ||
323 | /** | 314 | /** |
324 | * Generate javaDocs for default constructor. | 315 | * Generate javaDocs for default constructor. |
325 | * | 316 | * |
317 | + * @param className class name | ||
326 | * @return javaDocs | 318 | * @return javaDocs |
327 | */ | 319 | */ |
328 | - private static String generateForDefaultConstructors() { | 320 | + private static String generateForDefaultConstructors(String className) { |
329 | - | 321 | + return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className |
330 | - return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_DEFAULT_CONSTRUCTOR | 322 | + + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
331 | - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | ||
332 | } | 323 | } |
333 | 324 | ||
334 | /** | 325 | /** |
... | @@ -338,7 +329,6 @@ public final class JavaDocGen { | ... | @@ -338,7 +329,6 @@ public final class JavaDocGen { |
338 | * @return javaDocs | 329 | * @return javaDocs |
339 | */ | 330 | */ |
340 | private static String generateForConstructors(String className) { | 331 | private static String generateForConstructors(String className) { |
341 | - | ||
342 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE | 332 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE |
343 | + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE | 333 | + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE |
344 | + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM | 334 | + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM |
... | @@ -353,7 +343,6 @@ public final class JavaDocGen { | ... | @@ -353,7 +343,6 @@ public final class JavaDocGen { |
353 | * @return javaDocs | 343 | * @return javaDocs |
354 | */ | 344 | */ |
355 | private static String generateForBuild(String buildName) { | 345 | private static String generateForBuild(String buildName) { |
356 | - | ||
357 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD | 346 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD |
358 | + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION | 347 | + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION |
359 | + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION | 348 | + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION | ... | ... |
... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.datamodel.YangDataTypes; | ... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.datamodel.YangDataTypes; |
24 | import org.onosproject.yangutils.datamodel.YangType; | 24 | import org.onosproject.yangutils.datamodel.YangType; |
25 | 25 | ||
26 | import static org.hamcrest.core.Is.is; | 26 | import static org.hamcrest.core.Is.is; |
27 | -import static org.junit.Assert.assertNotNull; | 27 | +import static org.hamcrest.core.IsNot.not; |
28 | import static org.junit.Assert.assertThat; | 28 | import static org.junit.Assert.assertThat; |
29 | import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; | 29 | import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; |
30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | 30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; |
... | @@ -69,7 +69,7 @@ public class AttributesJavaDataTypeTest { | ... | @@ -69,7 +69,7 @@ public class AttributesJavaDataTypeTest { |
69 | for (Class<?> clazz : classesToConstruct) { | 69 | for (Class<?> clazz : classesToConstruct) { |
70 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 70 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
71 | constructor.setAccessible(true); | 71 | constructor.setAccessible(true); |
72 | - assertNotNull(constructor.newInstance()); | 72 | + assertThat(null, not(constructor.newInstance())); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
... | @@ -78,7 +78,6 @@ public class AttributesJavaDataTypeTest { | ... | @@ -78,7 +78,6 @@ public class AttributesJavaDataTypeTest { |
78 | */ | 78 | */ |
79 | @Test | 79 | @Test |
80 | public void testgetJavaClassInfo() { | 80 | public void testgetJavaClassInfo() { |
81 | - | ||
82 | test = getJavaImportClass(getStubYangType(TYPE1), false); | 81 | test = getJavaImportClass(getStubYangType(TYPE1), false); |
83 | assertThat(true, is(test.equals(CLASS_INFO1))); | 82 | assertThat(true, is(test.equals(CLASS_INFO1))); |
84 | 83 | ||
... | @@ -97,7 +96,6 @@ public class AttributesJavaDataTypeTest { | ... | @@ -97,7 +96,6 @@ public class AttributesJavaDataTypeTest { |
97 | */ | 96 | */ |
98 | @Test | 97 | @Test |
99 | public void testgetJavaDataType() { | 98 | public void testgetJavaDataType() { |
100 | - | ||
101 | test = getJavaDataType(getStubYangType(TYPE1)); | 99 | test = getJavaDataType(getStubYangType(TYPE1)); |
102 | assertThat(true, is(test.equals(CLASS_INFO1))); | 100 | assertThat(true, is(test.equals(CLASS_INFO1))); |
103 | 101 | ||
... | @@ -116,7 +114,6 @@ public class AttributesJavaDataTypeTest { | ... | @@ -116,7 +114,6 @@ public class AttributesJavaDataTypeTest { |
116 | */ | 114 | */ |
117 | @Test | 115 | @Test |
118 | public void testgetJavaPkgInfo() { | 116 | public void testgetJavaPkgInfo() { |
119 | - | ||
120 | test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1); | 117 | test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1); |
121 | assertThat(true, is(test.equals(JAVA_LANG))); | 118 | assertThat(true, is(test.equals(JAVA_LANG))); |
122 | 119 | ||
... | @@ -137,7 +134,6 @@ public class AttributesJavaDataTypeTest { | ... | @@ -137,7 +134,6 @@ public class AttributesJavaDataTypeTest { |
137 | * @return YANG type | 134 | * @return YANG type |
138 | */ | 135 | */ |
139 | private YangType<?> getStubYangType(YangDataTypes dataTypes) { | 136 | private YangType<?> getStubYangType(YangDataTypes dataTypes) { |
140 | - | ||
141 | YangType<?> type = new YangType(); | 137 | YangType<?> type = new YangType(); |
142 | type.setDataType(dataTypes); | 138 | type.setDataType(dataTypes); |
143 | return type; | 139 | return type; | ... | ... |
... | @@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException; | ... | @@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | 23 | ||
24 | import static org.hamcrest.core.Is.is; | 24 | import static org.hamcrest.core.Is.is; |
25 | -import static org.junit.Assert.assertNotNull; | 25 | +import static org.hamcrest.core.IsNot.not; |
26 | import static org.junit.Assert.assertThat; | 26 | import static org.junit.Assert.assertThat; |
27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 27 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
... | @@ -62,7 +62,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -62,7 +62,7 @@ public final class ClassDefinitionGeneratorTest { |
62 | for (Class<?> clazz : classesToConstruct) { | 62 | for (Class<?> clazz : classesToConstruct) { |
63 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 63 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
64 | constructor.setAccessible(true); | 64 | constructor.setAccessible(true); |
65 | - assertNotNull(constructor.newInstance()); | 65 | + assertThat(null, not(constructor.newInstance())); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
... | @@ -71,7 +71,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -71,7 +71,6 @@ public final class ClassDefinitionGeneratorTest { |
71 | */ | 71 | */ |
72 | @Test | 72 | @Test |
73 | public void generateBuilderClassDefinitionTest() { | 73 | public void generateBuilderClassDefinitionTest() { |
74 | - | ||
75 | String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME); | 74 | String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME); |
76 | assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF))); | 75 | assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF))); |
77 | } | 76 | } |
... | @@ -81,7 +80,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -81,7 +80,6 @@ public final class ClassDefinitionGeneratorTest { |
81 | */ | 80 | */ |
82 | @Test | 81 | @Test |
83 | public void generateBuilderInterfaceDefinitionTest() { | 82 | public void generateBuilderInterfaceDefinitionTest() { |
84 | - | ||
85 | String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME); | 83 | String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME); |
86 | assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF))); | 84 | assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF))); |
87 | } | 85 | } |
... | @@ -91,7 +89,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -91,7 +89,6 @@ public final class ClassDefinitionGeneratorTest { |
91 | */ | 89 | */ |
92 | @Test | 90 | @Test |
93 | public void generateImplDefinitionTest() { | 91 | public void generateImplDefinitionTest() { |
94 | - | ||
95 | String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME); | 92 | String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME); |
96 | assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF))); | 93 | assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF))); |
97 | } | 94 | } |
... | @@ -101,7 +98,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -101,7 +98,6 @@ public final class ClassDefinitionGeneratorTest { |
101 | */ | 98 | */ |
102 | @Test | 99 | @Test |
103 | public void generateinterfaceDefinitionTest() { | 100 | public void generateinterfaceDefinitionTest() { |
104 | - | ||
105 | String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); | 101 | String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); |
106 | assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF))); | 102 | assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF))); |
107 | } | 103 | } |
... | @@ -111,7 +107,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -111,7 +107,6 @@ public final class ClassDefinitionGeneratorTest { |
111 | */ | 107 | */ |
112 | @Test | 108 | @Test |
113 | public void generateTypeDefTest() { | 109 | public void generateTypeDefTest() { |
114 | - | ||
115 | String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME); | 110 | String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME); |
116 | assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF))); | 111 | assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF))); |
117 | } | 112 | } | ... | ... |
... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
24 | 24 | ||
25 | import static org.hamcrest.MatcherAssert.assertThat; | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
26 | import static org.hamcrest.core.Is.is; | 26 | import static org.hamcrest.core.Is.is; |
27 | -import static org.junit.Assert.assertNotNull; | 27 | +import static org.hamcrest.core.IsNot.not; |
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; |
30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
... | @@ -75,7 +75,7 @@ public class JavaCodeSnippetGenTest { | ... | @@ -75,7 +75,7 @@ public class JavaCodeSnippetGenTest { |
75 | for (Class<?> clazz : classesToConstruct) { | 75 | for (Class<?> clazz : classesToConstruct) { |
76 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 76 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
77 | constructor.setAccessible(true); | 77 | constructor.setAccessible(true); |
78 | - assertNotNull(constructor.newInstance()); | 78 | + assertThat(null, not(constructor.newInstance())); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
... | @@ -84,7 +84,6 @@ public class JavaCodeSnippetGenTest { | ... | @@ -84,7 +84,6 @@ public class JavaCodeSnippetGenTest { |
84 | */ | 84 | */ |
85 | @Test | 85 | @Test |
86 | public void testForImportText() { | 86 | public void testForImportText() { |
87 | - | ||
88 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); | 87 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); |
89 | importInfo.setPkgInfo(PKG_INFO); | 88 | importInfo.setPkgInfo(PKG_INFO); |
90 | importInfo.setClassInfo(CLASS_INFO); | 89 | importInfo.setClassInfo(CLASS_INFO); |
... | @@ -99,11 +98,9 @@ public class JavaCodeSnippetGenTest { | ... | @@ -99,11 +98,9 @@ public class JavaCodeSnippetGenTest { |
99 | */ | 98 | */ |
100 | @Test | 99 | @Test |
101 | public void testForJavaClassDefStart() { | 100 | public void testForJavaClassDefStart() { |
102 | - | ||
103 | String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); | 101 | String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); |
104 | assertThat(true, is(classDef | 102 | assertThat(true, is(classDef |
105 | .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | 103 | .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
106 | - | ||
107 | } | 104 | } |
108 | 105 | ||
109 | /** | 106 | /** |
... | @@ -111,7 +108,6 @@ public class JavaCodeSnippetGenTest { | ... | @@ -111,7 +108,6 @@ public class JavaCodeSnippetGenTest { |
111 | */ | 108 | */ |
112 | @Test | 109 | @Test |
113 | public void testForListAttribute() { | 110 | public void testForListAttribute() { |
114 | - | ||
115 | String listAttribute = getListAttribute(STRING_DATA_TYPE); | 111 | String listAttribute = getListAttribute(STRING_DATA_TYPE); |
116 | assertThat(true, | 112 | assertThat(true, |
117 | is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET))); | 113 | is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET))); |
... | @@ -122,7 +118,6 @@ public class JavaCodeSnippetGenTest { | ... | @@ -122,7 +118,6 @@ public class JavaCodeSnippetGenTest { |
122 | */ | 118 | */ |
123 | @Test | 119 | @Test |
124 | public void testForJavaClassDefClose() { | 120 | public void testForJavaClassDefClose() { |
125 | - | ||
126 | String interfaceDef = getJavaClassDefClose(); | 121 | String interfaceDef = getJavaClassDefClose(); |
127 | assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET))); | 122 | assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET))); |
128 | } | 123 | } | ... | ... |
... | @@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException; | ... | @@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | 23 | ||
24 | import static org.hamcrest.core.Is.is; | 24 | import static org.hamcrest.core.Is.is; |
25 | -import static org.junit.Assert.assertNotNull; | 25 | +import static org.hamcrest.core.IsNot.not; |
26 | import static org.junit.Assert.assertThat; | 26 | import static org.junit.Assert.assertThat; |
27 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 27 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
... | @@ -30,7 +30,6 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -30,7 +30,6 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
33 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getYangRevisionStr; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
36 | 35 | ||
... | @@ -79,7 +78,7 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -79,7 +78,7 @@ public final class JavaIdentifierSyntaxTest { |
79 | for (Class<?> clazz : classesToConstruct) { | 78 | for (Class<?> clazz : classesToConstruct) { |
80 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 79 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
81 | constructor.setAccessible(true); | 80 | constructor.setAccessible(true); |
82 | - assertNotNull(constructor.newInstance()); | 81 | + assertThat(null, not(constructor.newInstance())); |
83 | } | 82 | } |
84 | } | 83 | } |
85 | 84 | ||
... | @@ -88,7 +87,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -88,7 +87,6 @@ public final class JavaIdentifierSyntaxTest { |
88 | */ | 87 | */ |
89 | @Test | 88 | @Test |
90 | public void getRootPackageTest() { | 89 | public void getRootPackageTest() { |
91 | - | ||
92 | String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1); | 90 | String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1); |
93 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 91 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
94 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); | 92 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); |
... | @@ -99,7 +97,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -99,7 +97,6 @@ public final class JavaIdentifierSyntaxTest { |
99 | */ | 97 | */ |
100 | @Test | 98 | @Test |
101 | public void getRootPackageWithSpecialCharactersTest() { | 99 | public void getRootPackageWithSpecialCharactersTest() { |
102 | - | ||
103 | String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1); | 100 | String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1); |
104 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 101 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
105 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); | 102 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); |
... | @@ -113,7 +110,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -113,7 +110,6 @@ public final class JavaIdentifierSyntaxTest { |
113 | */ | 110 | */ |
114 | @Test | 111 | @Test |
115 | public void getRootPackageWithRevTest() { | 112 | public void getRootPackageWithRevTest() { |
116 | - | ||
117 | String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2); | 113 | String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2); |
118 | assertThat(rootPkgWithRev.equals( | 114 | assertThat(rootPkgWithRev.equals( |
119 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), | 115 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), |
... | @@ -125,7 +121,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -125,7 +121,6 @@ public final class JavaIdentifierSyntaxTest { |
125 | */ | 121 | */ |
126 | @Test | 122 | @Test |
127 | public void getCapitalCaseTest() { | 123 | public void getCapitalCaseTest() { |
128 | - | ||
129 | String capitalCase = getCaptialCase(WITHOUT_CAPITAL); | 124 | String capitalCase = getCaptialCase(WITHOUT_CAPITAL); |
130 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); | 125 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); |
131 | } | 126 | } |
... | @@ -135,7 +130,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -135,7 +130,6 @@ public final class JavaIdentifierSyntaxTest { |
135 | */ | 130 | */ |
136 | @Test | 131 | @Test |
137 | public void getCamelCaseTest() { | 132 | public void getCamelCaseTest() { |
138 | - | ||
139 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE); | 133 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE); |
140 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); | 134 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); |
141 | } | 135 | } |
... | @@ -145,7 +139,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -145,7 +139,6 @@ public final class JavaIdentifierSyntaxTest { |
145 | */ | 139 | */ |
146 | @Test | 140 | @Test |
147 | public void getSmallCaseTest() { | 141 | public void getSmallCaseTest() { |
148 | - | ||
149 | String smallCase = getSmallCase(WITHOUT_CAPITAL); | 142 | String smallCase = getSmallCase(WITHOUT_CAPITAL); |
150 | assertThat(smallCase.equals(WITH_SMALL), is(true)); | 143 | assertThat(smallCase.equals(WITH_SMALL), is(true)); |
151 | } | 144 | } |
... | @@ -155,7 +148,6 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -155,7 +148,6 @@ public final class JavaIdentifierSyntaxTest { |
155 | */ | 148 | */ |
156 | @Test | 149 | @Test |
157 | public void getPackageFromPathTest() { | 150 | public void getPackageFromPathTest() { |
158 | - | ||
159 | String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE); | 151 | String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE); |
160 | assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true)); | 152 | assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true)); |
161 | } | 153 | } |
... | @@ -165,18 +157,7 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -165,18 +157,7 @@ public final class JavaIdentifierSyntaxTest { |
165 | */ | 157 | */ |
166 | @Test | 158 | @Test |
167 | public void getPathFromPackageTest() { | 159 | public void getPathFromPackageTest() { |
168 | - | ||
169 | String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD); | 160 | String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD); |
170 | assertThat(path.equals(PARENT_PACKAGE), is(true)); | 161 | assertThat(path.equals(PARENT_PACKAGE), is(true)); |
171 | } | 162 | } |
172 | - | ||
173 | - /** | ||
174 | - * Unit test for getting the camel case for the received string. | ||
175 | - */ | ||
176 | - @Test | ||
177 | - public void getYangRevTest() { | ||
178 | - | ||
179 | - String rev = getYangRevisionStr(DATE1); | ||
180 | - assertThat(rev.equals(DATE_WITH_REV1), is(true)); | ||
181 | - } | ||
182 | } | 163 | } | ... | ... |
... | @@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | ... | @@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
25 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
26 | 26 | ||
27 | import static org.hamcrest.core.Is.is; | 27 | import static org.hamcrest.core.Is.is; |
28 | -import static org.junit.Assert.assertNotNull; | 28 | +import static org.hamcrest.core.IsNot.not; |
29 | import static org.junit.Assert.assertThat; | 29 | import static org.junit.Assert.assertThat; |
30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | 30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; |
31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
... | @@ -108,7 +108,7 @@ public final class MethodsGeneratorTest { | ... | @@ -108,7 +108,7 @@ public final class MethodsGeneratorTest { |
108 | for (Class<?> clazz : classesToConstruct) { | 108 | for (Class<?> clazz : classesToConstruct) { |
109 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 109 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
110 | constructor.setAccessible(true); | 110 | constructor.setAccessible(true); |
111 | - assertNotNull(constructor.newInstance()); | 111 | + assertThat(null, not(constructor.newInstance())); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
... | @@ -117,7 +117,6 @@ public final class MethodsGeneratorTest { | ... | @@ -117,7 +117,6 @@ public final class MethodsGeneratorTest { |
117 | */ | 117 | */ |
118 | @Test | 118 | @Test |
119 | public void getTypeDefConstructorTest() { | 119 | public void getTypeDefConstructorTest() { |
120 | - | ||
121 | JavaAttributeInfo testAttr = getTestAttribute(); | 120 | JavaAttributeInfo testAttr = getTestAttribute(); |
122 | String test = getTypeDefConstructor(testAttr, CLASS_NAME); | 121 | String test = getTypeDefConstructor(testAttr, CLASS_NAME); |
123 | assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); | 122 | assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); |
... | @@ -128,7 +127,6 @@ public final class MethodsGeneratorTest { | ... | @@ -128,7 +127,6 @@ public final class MethodsGeneratorTest { |
128 | */ | 127 | */ |
129 | @Test | 128 | @Test |
130 | public void getBuildTest() { | 129 | public void getBuildTest() { |
131 | - | ||
132 | String method = getBuild(CLASS_NAME); | 130 | String method = getBuild(CLASS_NAME); |
133 | assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD | 131 | assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD |
134 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | 132 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
... | @@ -142,7 +140,6 @@ public final class MethodsGeneratorTest { | ... | @@ -142,7 +140,6 @@ public final class MethodsGeneratorTest { |
142 | */ | 140 | */ |
143 | @Test | 141 | @Test |
144 | public void getBuildForInterfaceTest() { | 142 | public void getBuildForInterfaceTest() { |
145 | - | ||
146 | String method = getBuildForInterface(CLASS_NAME); | 143 | String method = getBuildForInterface(CLASS_NAME); |
147 | assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + CLASS_NAME + SPACE + BUILD + | 144 | assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + CLASS_NAME + SPACE + BUILD + |
148 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE))); | 145 | OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE))); |
... | @@ -153,7 +150,6 @@ public final class MethodsGeneratorTest { | ... | @@ -153,7 +150,6 @@ public final class MethodsGeneratorTest { |
153 | */ | 150 | */ |
154 | @Test | 151 | @Test |
155 | public void getCheckNotNullTest() { | 152 | public void getCheckNotNullTest() { |
156 | - | ||
157 | String method = getCheckNotNull(CLASS_NAME); | 153 | String method = getCheckNotNull(CLASS_NAME); |
158 | assertThat(true, is(method.equals(EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS | 154 | assertThat(true, is(method.equals(EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS |
159 | + CLASS_NAME + COMMA + SPACE + CLASS_NAME + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE))); | 155 | + CLASS_NAME + COMMA + SPACE + CLASS_NAME + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE))); |
... | @@ -164,7 +160,6 @@ public final class MethodsGeneratorTest { | ... | @@ -164,7 +160,6 @@ public final class MethodsGeneratorTest { |
164 | */ | 160 | */ |
165 | @Test | 161 | @Test |
166 | public void getConstructorTest() { | 162 | public void getConstructorTest() { |
167 | - | ||
168 | JavaAttributeInfo testAttr = getTestAttribute(); | 163 | JavaAttributeInfo testAttr = getTestAttribute(); |
169 | String method = getConstructor(CLASS_NAME, testAttr); | 164 | String method = getConstructor(CLASS_NAME, testAttr); |
170 | assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT | 165 | assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT |
... | @@ -176,7 +171,6 @@ public final class MethodsGeneratorTest { | ... | @@ -176,7 +171,6 @@ public final class MethodsGeneratorTest { |
176 | */ | 171 | */ |
177 | @Test | 172 | @Test |
178 | public void getConstructorStartTest() { | 173 | public void getConstructorStartTest() { |
179 | - | ||
180 | String method = getConstructorStart(CLASS_NAME); | 174 | String method = getConstructorStart(CLASS_NAME); |
181 | assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME | 175 | assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME |
182 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE | 176 | + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE |
... | @@ -188,7 +182,6 @@ public final class MethodsGeneratorTest { | ... | @@ -188,7 +182,6 @@ public final class MethodsGeneratorTest { |
188 | */ | 182 | */ |
189 | @Test | 183 | @Test |
190 | public void getEqualsMethodTest() { | 184 | public void getEqualsMethodTest() { |
191 | - | ||
192 | JavaAttributeInfo testAttr = getTestAttribute(); | 185 | JavaAttributeInfo testAttr = getTestAttribute(); |
193 | String method = getEqualsMethod(testAttr); | 186 | String method = getEqualsMethod(testAttr); |
194 | assertThat(true, is(method.contains(SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD | 187 | assertThat(true, is(method.contains(SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD |
... | @@ -200,7 +193,6 @@ public final class MethodsGeneratorTest { | ... | @@ -200,7 +193,6 @@ public final class MethodsGeneratorTest { |
200 | */ | 193 | */ |
201 | @Test | 194 | @Test |
202 | public void getToStringMethodTest() { | 195 | public void getToStringMethodTest() { |
203 | - | ||
204 | JavaAttributeInfo testAttr = getTestAttribute(); | 196 | JavaAttributeInfo testAttr = getTestAttribute(); |
205 | String method = getToStringMethod(testAttr); | 197 | String method = getToStringMethod(testAttr); |
206 | assertThat(true, is(method.equals( | 198 | assertThat(true, is(method.equals( |
... | @@ -213,7 +205,6 @@ public final class MethodsGeneratorTest { | ... | @@ -213,7 +205,6 @@ public final class MethodsGeneratorTest { |
213 | */ | 205 | */ |
214 | @Test | 206 | @Test |
215 | public void getGetterForClassTest() { | 207 | public void getGetterForClassTest() { |
216 | - | ||
217 | JavaAttributeInfo testAttr = getTestAttribute(); | 208 | JavaAttributeInfo testAttr = getTestAttribute(); |
218 | String method = getGetterForClass(testAttr); | 209 | String method = getGetterForClass(testAttr); |
219 | assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX))); | 210 | assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX))); |
... | @@ -224,7 +215,6 @@ public final class MethodsGeneratorTest { | ... | @@ -224,7 +215,6 @@ public final class MethodsGeneratorTest { |
224 | */ | 215 | */ |
225 | @Test | 216 | @Test |
226 | public void getGetterForInterfaceTest() { | 217 | public void getGetterForInterfaceTest() { |
227 | - | ||
228 | String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false); | 218 | String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false); |
229 | assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX))); | 219 | assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX))); |
230 | } | 220 | } |
... | @@ -234,7 +224,6 @@ public final class MethodsGeneratorTest { | ... | @@ -234,7 +224,6 @@ public final class MethodsGeneratorTest { |
234 | */ | 224 | */ |
235 | @Test | 225 | @Test |
236 | public void getSetterForClassTest() { | 226 | public void getSetterForClassTest() { |
237 | - | ||
238 | JavaAttributeInfo testAttr = getTestAttribute(); | 227 | JavaAttributeInfo testAttr = getTestAttribute(); |
239 | String method = getSetterForClass(testAttr, CLASS_NAME); | 228 | String method = getSetterForClass(testAttr, CLASS_NAME); |
240 | assertThat(true, is( | 229 | assertThat(true, is( |
... | @@ -248,7 +237,6 @@ public final class MethodsGeneratorTest { | ... | @@ -248,7 +237,6 @@ public final class MethodsGeneratorTest { |
248 | */ | 237 | */ |
249 | @Test | 238 | @Test |
250 | public void getSetterForInterfaceTest() { | 239 | public void getSetterForInterfaceTest() { |
251 | - | ||
252 | String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false); | 240 | String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false); |
253 | assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname"))); | 241 | assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname"))); |
254 | } | 242 | } |
... | @@ -258,7 +246,6 @@ public final class MethodsGeneratorTest { | ... | @@ -258,7 +246,6 @@ public final class MethodsGeneratorTest { |
258 | */ | 246 | */ |
259 | @Test | 247 | @Test |
260 | public void getOfMethodest() { | 248 | public void getOfMethodest() { |
261 | - | ||
262 | JavaAttributeInfo testAttr = getTestAttribute(); | 249 | JavaAttributeInfo testAttr = getTestAttribute(); |
263 | String method = getOfMethod(CLASS_NAME, testAttr); | 250 | String method = getOfMethod(CLASS_NAME, testAttr); |
264 | assertThat(true, is(method.contains(PUBLIC + SPACE + STATIC + SPACE + CLASS_NAME + SPACE + OF + OPEN_PARENTHESIS | 251 | assertThat(true, is(method.contains(PUBLIC + SPACE + STATIC + SPACE + CLASS_NAME + SPACE + OF + OPEN_PARENTHESIS |
... | @@ -270,7 +257,6 @@ public final class MethodsGeneratorTest { | ... | @@ -270,7 +257,6 @@ public final class MethodsGeneratorTest { |
270 | */ | 257 | */ |
271 | @Test | 258 | @Test |
272 | public void getSetterForTypeDefClassTest() { | 259 | public void getSetterForTypeDefClassTest() { |
273 | - | ||
274 | JavaAttributeInfo testAttr = getTestAttribute(); | 260 | JavaAttributeInfo testAttr = getTestAttribute(); |
275 | String method = getSetterForTypeDefClass(testAttr); | 261 | String method = getSetterForTypeDefClass(testAttr); |
276 | assertThat(true, is(method.contains(PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX))); | 262 | assertThat(true, is(method.contains(PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX))); |
... | @@ -281,7 +267,6 @@ public final class MethodsGeneratorTest { | ... | @@ -281,7 +267,6 @@ public final class MethodsGeneratorTest { |
281 | */ | 267 | */ |
282 | @Test | 268 | @Test |
283 | public void getOverRideStringTest() { | 269 | public void getOverRideStringTest() { |
284 | - | ||
285 | String method = getOverRideString(); | 270 | String method = getOverRideString(); |
286 | assertThat(true, is(method.contains(OVERRIDE))); | 271 | assertThat(true, is(method.contains(OVERRIDE))); |
287 | } | 272 | } |
... | @@ -292,7 +277,6 @@ public final class MethodsGeneratorTest { | ... | @@ -292,7 +277,6 @@ public final class MethodsGeneratorTest { |
292 | * @return java attribute | 277 | * @return java attribute |
293 | */ | 278 | */ |
294 | private JavaAttributeInfo getTestAttribute() { | 279 | private JavaAttributeInfo getTestAttribute() { |
295 | - | ||
296 | JavaAttributeInfo testAttr = new JavaAttributeInfo(getTestYangType(), ATTRIBUTE_NAME, false, false); | 280 | JavaAttributeInfo testAttr = new JavaAttributeInfo(getTestYangType(), ATTRIBUTE_NAME, false, false); |
297 | testAttr.setAttributeName(ATTRIBUTE_NAME); | 281 | testAttr.setAttributeName(ATTRIBUTE_NAME); |
298 | testAttr.setAttributeType(getTestYangType()); | 282 | testAttr.setAttributeType(getTestYangType()); |
... | @@ -306,7 +290,6 @@ public final class MethodsGeneratorTest { | ... | @@ -306,7 +290,6 @@ public final class MethodsGeneratorTest { |
306 | * @return java qualified info | 290 | * @return java qualified info |
307 | */ | 291 | */ |
308 | private JavaQualifiedTypeInfo getTestJavaQualifiedTypeInfo() { | 292 | private JavaQualifiedTypeInfo getTestJavaQualifiedTypeInfo() { |
309 | - | ||
310 | JavaQualifiedTypeInfo info = new JavaQualifiedTypeInfo(); | 293 | JavaQualifiedTypeInfo info = new JavaQualifiedTypeInfo(); |
311 | info.setPkgInfo(JAVA_LANG); | 294 | info.setPkgInfo(JAVA_LANG); |
312 | info.setClassInfo(STRING_DATA_TYPE); | 295 | info.setClassInfo(STRING_DATA_TYPE); |
... | @@ -319,7 +302,6 @@ public final class MethodsGeneratorTest { | ... | @@ -319,7 +302,6 @@ public final class MethodsGeneratorTest { |
319 | * @return test YANG type | 302 | * @return test YANG type |
320 | */ | 303 | */ |
321 | private YangType<?> getTestYangType() { | 304 | private YangType<?> getTestYangType() { |
322 | - | ||
323 | YangType<?> attrType = new YangType<>(); | 305 | YangType<?> attrType = new YangType<>(); |
324 | attrType.setDataTypeName(STRING_DATA_TYPE); | 306 | attrType.setDataTypeName(STRING_DATA_TYPE); |
325 | attrType.setDataType(STRING); | 307 | attrType.setDataType(STRING); | ... | ... |
... | @@ -16,12 +16,15 @@ | ... | @@ -16,12 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.utils; | 17 | package org.onosproject.yangutils.utils; |
18 | 18 | ||
19 | -import org.junit.Test; | ||
20 | -import org.junit.Rule; | ||
21 | -import org.junit.rules.ExpectedException; | ||
22 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
23 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
24 | -import static org.junit.Assert.assertNotNull; | 21 | + |
22 | +import org.junit.Rule; | ||
23 | +import org.junit.Test; | ||
24 | +import org.junit.rules.ExpectedException; | ||
25 | + | ||
26 | +import static org.hamcrest.core.IsNot.not; | ||
27 | +import static org.junit.Assert.assertThat; | ||
25 | 28 | ||
26 | /** | 29 | /** |
27 | * Test case for testing the util constants. | 30 | * Test case for testing the util constants. |
... | @@ -45,11 +48,11 @@ public final class UtilConstantsTest { | ... | @@ -45,11 +48,11 @@ public final class UtilConstantsTest { |
45 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 48 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
46 | InstantiationException, IllegalAccessException, InvocationTargetException { | 49 | InstantiationException, IllegalAccessException, InvocationTargetException { |
47 | 50 | ||
48 | - Class<?>[] classesToConstruct = {UtilConstants.class}; | 51 | + Class<?>[] classesToConstruct = {UtilConstants.class }; |
49 | for (Class<?> clazz : classesToConstruct) { | 52 | for (Class<?> clazz : classesToConstruct) { |
50 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 53 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
51 | constructor.setAccessible(true); | 54 | constructor.setAccessible(true); |
52 | - assertNotNull(constructor.newInstance()); | 55 | + assertThat(null, not(constructor.newInstance())); |
53 | } | 56 | } |
54 | } | 57 | } |
55 | } | 58 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,27 +16,24 @@ | ... | @@ -16,27 +16,24 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.utils.io.impl; | 17 | package org.onosproject.yangutils.utils.io.impl; |
18 | 18 | ||
19 | -import org.junit.Test; | 19 | +import java.io.File; |
20 | +import java.io.FileWriter; | ||
21 | +import java.io.IOException; | ||
22 | +import java.lang.reflect.Constructor; | ||
23 | +import java.lang.reflect.InvocationTargetException; | ||
24 | + | ||
20 | import org.junit.Rule; | 25 | import org.junit.Rule; |
26 | +import org.junit.Test; | ||
21 | import org.junit.rules.ExpectedException; | 27 | import org.junit.rules.ExpectedException; |
28 | +import org.slf4j.Logger; | ||
22 | 29 | ||
30 | +import static org.apache.commons.io.FileUtils.contentEquals; | ||
23 | import static org.hamcrest.core.Is.is; | 31 | import static org.hamcrest.core.Is.is; |
32 | +import static org.hamcrest.core.IsNot.not; | ||
24 | import static org.junit.Assert.assertThat; | 33 | import static org.junit.Assert.assertThat; |
25 | -import static org.junit.Assert.assertNotNull; | 34 | +import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader; |
26 | -import org.slf4j.Logger; | ||
27 | import static org.slf4j.LoggerFactory.getLogger; | 35 | import static org.slf4j.LoggerFactory.getLogger; |
28 | 36 | ||
29 | -import java.io.BufferedReader; | ||
30 | -import java.io.File; | ||
31 | -import java.io.FileOutputStream; | ||
32 | -import java.io.FileReader; | ||
33 | -import java.io.FileWriter; | ||
34 | -import java.io.IOException; | ||
35 | -import java.io.InputStream; | ||
36 | -import java.io.OutputStream; | ||
37 | -import java.lang.reflect.Constructor; | ||
38 | -import java.lang.reflect.InvocationTargetException; | ||
39 | - | ||
40 | /** | 37 | /** |
41 | * Unit Tests for the CopyrightHeader contents. | 38 | * Unit Tests for the CopyrightHeader contents. |
42 | */ | 39 | */ |
... | @@ -65,41 +62,28 @@ public final class CopyrightHeaderTest { | ... | @@ -65,41 +62,28 @@ public final class CopyrightHeaderTest { |
65 | for (Class<?> clazz : classesToConstruct) { | 62 | for (Class<?> clazz : classesToConstruct) { |
66 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 63 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
67 | constructor.setAccessible(true); | 64 | constructor.setAccessible(true); |
68 | - assertNotNull(constructor.newInstance()); | 65 | + assertThat(null, not(constructor.newInstance())); |
69 | } | 66 | } |
70 | } | 67 | } |
71 | 68 | ||
72 | /** | 69 | /** |
73 | * This test case checks the received copyright header contents. | 70 | * This test case checks the received copyright header contents. |
71 | + * | ||
72 | + * @throws IOException when fails to do IO operations | ||
74 | */ | 73 | */ |
75 | @Test | 74 | @Test |
76 | public void testGetCopyrightHeader() throws IOException { | 75 | public void testGetCopyrightHeader() throws IOException { |
77 | 76 | ||
78 | - CopyrightHeader.parseCopyrightHeader(); | 77 | + String baseDir = System.getProperty("basedir"); |
79 | - String licenseHeader = CopyrightHeader.getCopyrightHeader(); | 78 | + String path = "/src/test/resources/CopyrightHeader.txt"; |
80 | - ClassLoader classLoader = CopyrightHeaderTest.class.getClassLoader(); | 79 | + |
80 | + String licenseHeader = getCopyrightHeader(); | ||
81 | File test = new File("target/TestCopyrightHeader.txt"); | 81 | File test = new File("target/TestCopyrightHeader.txt"); |
82 | 82 | ||
83 | FileWriter out = new FileWriter(test); | 83 | FileWriter out = new FileWriter(test); |
84 | out.write(licenseHeader); | 84 | out.write(licenseHeader); |
85 | out.close(); | 85 | out.close(); |
86 | 86 | ||
87 | - File temp = new File("target/temp.txt"); | 87 | + assertThat(true, is(contentEquals(test, new File(baseDir + path)))); |
88 | - InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt"); | ||
89 | - OutputStream outStream = new FileOutputStream(temp); | ||
90 | - int i; | ||
91 | - while ((i = stream.read()) != -1) { | ||
92 | - outStream.write(i); | ||
93 | - } | ||
94 | - outStream.close(); | ||
95 | - stream.close(); | ||
96 | - | ||
97 | - BufferedReader br1 = new BufferedReader(new FileReader(test)); | ||
98 | - BufferedReader br2 = new BufferedReader(new FileReader(temp)); | ||
99 | - while (br1.readLine() != null && br2.readLine() != null) { | ||
100 | - assertThat(true, is((br1.readLine()).equals(br2.readLine()))); | ||
101 | - } | ||
102 | - br1.close(); | ||
103 | - br2.close(); | ||
104 | } | 88 | } |
105 | } | 89 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -22,10 +22,16 @@ import java.lang.reflect.Constructor; | ... | @@ -22,10 +22,16 @@ import java.lang.reflect.Constructor; |
22 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
23 | 23 | ||
24 | import org.junit.Test; | 24 | import org.junit.Test; |
25 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
26 | 25 | ||
27 | -import static org.junit.Assert.assertNotNull; | 26 | +import static org.hamcrest.core.Is.is; |
28 | -import static org.junit.Assert.assertTrue; | 27 | +import static org.hamcrest.core.IsNot.not; |
28 | +import static org.junit.Assert.assertThat; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
31 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; | ||
32 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
33 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.doesPackageExist; | ||
34 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | ||
29 | 35 | ||
30 | /** | 36 | /** |
31 | * Tests the file handle utilities. | 37 | * Tests the file handle utilities. |
... | @@ -57,7 +63,7 @@ public final class FileSystemUtilTest { | ... | @@ -57,7 +63,7 @@ public final class FileSystemUtilTest { |
57 | for (Class<?> clazz : classesToConstruct) { | 63 | for (Class<?> clazz : classesToConstruct) { |
58 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 64 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
59 | constructor.setAccessible(true); | 65 | constructor.setAccessible(true); |
60 | - assertNotNull(constructor.newInstance()); | 66 | + assertThat(null, not(constructor.newInstance())); |
61 | } | 67 | } |
62 | } | 68 | } |
63 | 69 | ||
... | @@ -69,17 +75,17 @@ public final class FileSystemUtilTest { | ... | @@ -69,17 +75,17 @@ public final class FileSystemUtilTest { |
69 | @Test | 75 | @Test |
70 | public void updateFileHandleTest() throws IOException { | 76 | public void updateFileHandleTest() throws IOException { |
71 | 77 | ||
72 | - File dir = new File(BASE_PKG + File.separator + "File1"); | 78 | + File dir = new File(BASE_PKG + SLASH + "File1"); |
73 | dir.mkdirs(); | 79 | dir.mkdirs(); |
74 | File createFile = new File(dir + "testFile"); | 80 | File createFile = new File(dir + "testFile"); |
75 | createFile.createNewFile(); | 81 | createFile.createNewFile(); |
76 | File createSourceFile = new File(dir + "sourceTestFile"); | 82 | File createSourceFile = new File(dir + "sourceTestFile"); |
77 | createSourceFile.createNewFile(); | 83 | createSourceFile.createNewFile(); |
78 | - FileSystemUtil.updateFileHandle(createFile, TEST_DATA_1, false); | 84 | + updateFileHandle(createFile, TEST_DATA_1, false); |
79 | - FileSystemUtil.updateFileHandle(createFile, TEST_DATA_2, false); | 85 | + updateFileHandle(createFile, TEST_DATA_2, false); |
80 | - FileSystemUtil.updateFileHandle(createFile, TEST_DATA_3, false); | 86 | + updateFileHandle(createFile, TEST_DATA_3, false); |
81 | - FileSystemUtil.appendFileContents(createFile, createSourceFile); | 87 | + appendFileContents(createFile, createSourceFile); |
82 | - FileSystemUtil.updateFileHandle(createFile, null, true); | 88 | + updateFileHandle(createFile, null, true); |
83 | } | 89 | } |
84 | 90 | ||
85 | /** | 91 | /** |
... | @@ -92,12 +98,12 @@ public final class FileSystemUtilTest { | ... | @@ -92,12 +98,12 @@ public final class FileSystemUtilTest { |
92 | 98 | ||
93 | String dirPath = "exist1.exist2.exist3"; | 99 | String dirPath = "exist1.exist2.exist3"; |
94 | String strPath = BASE_DIR_PKG + dirPath; | 100 | String strPath = BASE_DIR_PKG + dirPath; |
95 | - File createDir = new File(strPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | 101 | + File createDir = new File(strPath.replace(PERIOD, SLASH)); |
96 | createDir.mkdirs(); | 102 | createDir.mkdirs(); |
97 | - File createFile = new File(createDir + File.separator + "package-info.java"); | 103 | + File createFile = new File(createDir + SLASH + "package-info.java"); |
98 | createFile.createNewFile(); | 104 | createFile.createNewFile(); |
99 | - assertTrue(FileSystemUtil.doesPackageExist(strPath)); | 105 | + assertThat(true, is(doesPackageExist(strPath))); |
100 | - FileSystemUtil.createPackage(strPath, PKG_INFO_CONTENT); | 106 | + createPackage(strPath, PKG_INFO_CONTENT); |
101 | createDir.delete(); | 107 | createDir.delete(); |
102 | } | 108 | } |
103 | 109 | ... | ... |
... | @@ -16,22 +16,37 @@ | ... | @@ -16,22 +16,37 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.utils.io.impl; | 17 | package org.onosproject.yangutils.utils.io.impl; |
18 | 18 | ||
19 | -import org.junit.Test; | ||
20 | -import org.junit.Rule; | ||
21 | -import org.junit.rules.ExpectedException; | ||
22 | -import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ||
23 | - | ||
24 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
25 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
26 | 21 | ||
27 | -import static org.junit.Assert.assertTrue; | 22 | +import org.junit.Rule; |
28 | -import static org.junit.Assert.assertNotNull; | 23 | +import org.junit.Test; |
24 | +import org.junit.rules.ExpectedException; | ||
25 | + | ||
26 | +import static org.hamcrest.core.Is.is; | ||
27 | +import static org.hamcrest.core.IsNot.not; | ||
28 | +import static org.junit.Assert.assertThat; | ||
29 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
30 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; | ||
31 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | ||
32 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | ||
33 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | ||
34 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | ||
35 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | ||
36 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | ||
37 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | ||
38 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; | ||
39 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; | ||
40 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD; | ||
29 | 41 | ||
30 | /** | 42 | /** |
31 | * Tests the java doc that is generated. | 43 | * Tests the java doc that is generated. |
32 | */ | 44 | */ |
33 | public final class JavaDocGenTest { | 45 | public final class JavaDocGenTest { |
34 | 46 | ||
47 | + private static final String TEST_NAME = "testName"; | ||
48 | + private static final String END_STRING = " */\n"; | ||
49 | + | ||
35 | @Rule | 50 | @Rule |
36 | public ExpectedException thrown = ExpectedException.none(); | 51 | public ExpectedException thrown = ExpectedException.none(); |
37 | 52 | ||
... | @@ -40,10 +55,9 @@ public final class JavaDocGenTest { | ... | @@ -40,10 +55,9 @@ public final class JavaDocGenTest { |
40 | */ | 55 | */ |
41 | @Test | 56 | @Test |
42 | public void builderClassGenerationTest() { | 57 | public void builderClassGenerationTest() { |
43 | - | 58 | + String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false); |
44 | - String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false); | 59 | + assertThat(true, is(builderClassJavaDoc.contains("Reperesents the builder implementation of") |
45 | - assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of") | 60 | + && builderClassJavaDoc.contains(END_STRING))); |
46 | - && builderClassJavaDoc.contains(" */\n")); | ||
47 | } | 61 | } |
48 | 62 | ||
49 | /** | 63 | /** |
... | @@ -51,9 +65,9 @@ public final class JavaDocGenTest { | ... | @@ -51,9 +65,9 @@ public final class JavaDocGenTest { |
51 | */ | 65 | */ |
52 | @Test | 66 | @Test |
53 | public void builderInterfaceGenerationTest() { | 67 | public void builderInterfaceGenerationTest() { |
54 | - | 68 | + String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false); |
55 | - String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false); | 69 | + assertThat(true, |
56 | - assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n")); | 70 | + is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING))); |
57 | } | 71 | } |
58 | 72 | ||
59 | /** | 73 | /** |
... | @@ -61,9 +75,8 @@ public final class JavaDocGenTest { | ... | @@ -61,9 +75,8 @@ public final class JavaDocGenTest { |
61 | */ | 75 | */ |
62 | @Test | 76 | @Test |
63 | public void buildGenerationTest() { | 77 | public void buildGenerationTest() { |
64 | - | 78 | + String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false); |
65 | - String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD_METHOD, "testGeneration1", false); | 79 | + assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING))); |
66 | - assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); | ||
67 | } | 80 | } |
68 | 81 | ||
69 | /** | 82 | /** |
... | @@ -84,7 +97,7 @@ public final class JavaDocGenTest { | ... | @@ -84,7 +97,7 @@ public final class JavaDocGenTest { |
84 | for (Class<?> clazz : classesToConstruct) { | 97 | for (Class<?> clazz : classesToConstruct) { |
85 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 98 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
86 | constructor.setAccessible(true); | 99 | constructor.setAccessible(true); |
87 | - assertNotNull(constructor.newInstance()); | 100 | + assertThat(null, not(constructor.newInstance())); |
88 | } | 101 | } |
89 | } | 102 | } |
90 | 103 | ||
... | @@ -93,12 +106,10 @@ public final class JavaDocGenTest { | ... | @@ -93,12 +106,10 @@ public final class JavaDocGenTest { |
93 | */ | 106 | */ |
94 | @Test | 107 | @Test |
95 | public void constructorGenerationTest() { | 108 | public void constructorGenerationTest() { |
96 | - | 109 | + String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false); |
97 | - String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1", false); | 110 | + assertThat(true, |
98 | - assertTrue( | 111 | + is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of") |
99 | - constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of") | 112 | + && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"))); |
100 | - && constructorDoc.contains("@param") && constructorDoc.contains("*/\n")); | ||
101 | - JavaDocType.valueOf(JavaDocType.CONSTRUCTOR.toString()); | ||
102 | } | 113 | } |
103 | 114 | ||
104 | /** | 115 | /** |
... | @@ -106,9 +117,9 @@ public final class JavaDocGenTest { | ... | @@ -106,9 +117,9 @@ public final class JavaDocGenTest { |
106 | */ | 117 | */ |
107 | @Test | 118 | @Test |
108 | public void defaultConstructorGenerationTest() { | 119 | public void defaultConstructorGenerationTest() { |
109 | - | 120 | + String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false); |
110 | - String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false); | 121 | + assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ") |
111 | - assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n")); | 122 | + && defaultConstructorDoc.contains(END_STRING))); |
112 | } | 123 | } |
113 | 124 | ||
114 | /** | 125 | /** |
... | @@ -116,9 +127,8 @@ public final class JavaDocGenTest { | ... | @@ -116,9 +127,8 @@ public final class JavaDocGenTest { |
116 | */ | 127 | */ |
117 | @Test | 128 | @Test |
118 | public void getterGenerationTest() { | 129 | public void getterGenerationTest() { |
119 | - | 130 | + String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false); |
120 | - String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER_METHOD, "testGeneration1", false); | 131 | + assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING))); |
121 | - assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); | ||
122 | } | 132 | } |
123 | 133 | ||
124 | /** | 134 | /** |
... | @@ -126,8 +136,10 @@ public final class JavaDocGenTest { | ... | @@ -126,8 +136,10 @@ public final class JavaDocGenTest { |
126 | */ | 136 | */ |
127 | @Test | 137 | @Test |
128 | public void implClassGenerationTest() { | 138 | public void implClassGenerationTest() { |
129 | - String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false); | 139 | + String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false); |
130 | - assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n")); | 140 | + assertThat(true, |
141 | + is(implClassJavaDoc.contains("Reperesents the implementation of") | ||
142 | + && implClassJavaDoc.contains(END_STRING))); | ||
131 | } | 143 | } |
132 | 144 | ||
133 | /** | 145 | /** |
... | @@ -135,10 +147,10 @@ public final class JavaDocGenTest { | ... | @@ -135,10 +147,10 @@ public final class JavaDocGenTest { |
135 | */ | 147 | */ |
136 | @Test | 148 | @Test |
137 | public void interfaceGenerationTest() { | 149 | public void interfaceGenerationTest() { |
138 | - | 150 | + String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false); |
139 | - String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false); | 151 | + assertThat(true, |
140 | - assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of") | 152 | + is(interfaceJavaDoc.contains("Abstraction of an entity which Reperesents the functionalities of") |
141 | - && interfaceJavaDoc.contains(" */\n")); | 153 | + && interfaceJavaDoc.contains(END_STRING))); |
142 | } | 154 | } |
143 | 155 | ||
144 | /** | 156 | /** |
... | @@ -146,9 +158,8 @@ public final class JavaDocGenTest { | ... | @@ -146,9 +158,8 @@ public final class JavaDocGenTest { |
146 | */ | 158 | */ |
147 | @Test | 159 | @Test |
148 | public void packageInfoGenerationTest() { | 160 | public void packageInfoGenerationTest() { |
149 | - | 161 | + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); |
150 | - String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false); | 162 | + assertThat(true, is(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(END_STRING))); |
151 | - assertTrue(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(" */\n")); | ||
152 | } | 163 | } |
153 | 164 | ||
154 | /** | 165 | /** |
... | @@ -156,9 +167,9 @@ public final class JavaDocGenTest { | ... | @@ -156,9 +167,9 @@ public final class JavaDocGenTest { |
156 | */ | 167 | */ |
157 | @Test | 168 | @Test |
158 | public void setterGenerationTest() { | 169 | public void setterGenerationTest() { |
159 | - | 170 | + String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false); |
160 | - String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER_METHOD, "testGeneration1", false); | 171 | + assertThat(true, |
161 | - assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); | 172 | + is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING))); |
162 | } | 173 | } |
163 | 174 | ||
164 | /** | 175 | /** |
... | @@ -166,8 +177,7 @@ public final class JavaDocGenTest { | ... | @@ -166,8 +177,7 @@ public final class JavaDocGenTest { |
166 | */ | 177 | */ |
167 | @Test | 178 | @Test |
168 | public void typeDefSetterGenerationTest() { | 179 | public void typeDefSetterGenerationTest() { |
169 | - | 180 | + String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false); |
170 | - String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER_METHOD, "testGeneration1", false); | 181 | + assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING))); |
171 | - assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); | ||
172 | } | 182 | } |
173 | } | 183 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -28,10 +28,15 @@ import org.junit.Test; | ... | @@ -28,10 +28,15 @@ import org.junit.Test; |
28 | import org.junit.rules.ExpectedException; | 28 | import org.junit.rules.ExpectedException; |
29 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
30 | 30 | ||
31 | -import static org.junit.Assert.assertEquals; | 31 | +import static org.hamcrest.core.Is.is; |
32 | -import static org.junit.Assert.assertNotNull; | 32 | +import static org.hamcrest.core.IsNot.not; |
33 | +import static org.junit.Assert.assertThat; | ||
34 | +import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles; | ||
35 | +import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles; | ||
33 | import static org.slf4j.LoggerFactory.getLogger; | 36 | import static org.slf4j.LoggerFactory.getLogger; |
34 | 37 | ||
38 | +import static java.io.File.separator; | ||
39 | + | ||
35 | /** | 40 | /** |
36 | * Test the file scanner service. | 41 | * Test the file scanner service. |
37 | */ | 42 | */ |
... | @@ -62,23 +67,25 @@ public final class YangFileScannerTest { | ... | @@ -62,23 +67,25 @@ public final class YangFileScannerTest { |
62 | for (Class<?> clazz : classesToConstruct) { | 67 | for (Class<?> clazz : classesToConstruct) { |
63 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 68 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
64 | constructor.setAccessible(true); | 69 | constructor.setAccessible(true); |
65 | - assertNotNull(constructor.newInstance()); | 70 | + assertThat(null, not(constructor.newInstance())); |
66 | } | 71 | } |
67 | } | 72 | } |
68 | 73 | ||
69 | /** | 74 | /** |
70 | * This test case checks for a .java file inside the specified dir. | 75 | * This test case checks for a .java file inside the specified dir. |
76 | + * | ||
77 | + * @throws IOException when fails to do IO operations | ||
71 | */ | 78 | */ |
72 | @Test | 79 | @Test |
73 | public void checkJavaFileInsideDirTest() throws IOException { | 80 | public void checkJavaFileInsideDirTest() throws IOException { |
74 | 81 | ||
75 | - String dir = baseDir + File.separator + "scanner2"; | 82 | + String dir = baseDir + separator + "scanner2"; |
76 | File path = createDirectory(dir); | 83 | File path = createDirectory(dir); |
77 | createFile(path, "testScanner.java"); | 84 | createFile(path, "testScanner.java"); |
78 | - List<String> dirContents = YangFileScanner.getJavaFiles(path.toString()); | 85 | + List<String> dirContents = getJavaFiles(path.toString()); |
79 | List<String> expectedContents = new LinkedList<>(); | 86 | List<String> expectedContents = new LinkedList<>(); |
80 | - expectedContents.add(path.getCanonicalPath() + File.separator + "testScanner.java"); | 87 | + expectedContents.add(path.getCanonicalPath() + separator + "testScanner.java"); |
81 | - assertEquals(dirContents, expectedContents); | 88 | + assertThat(true, is(dirContents.equals(expectedContents))); |
82 | } | 89 | } |
83 | 90 | ||
84 | /** | 91 | /** |
... | @@ -87,7 +94,7 @@ public final class YangFileScannerTest { | ... | @@ -87,7 +94,7 @@ public final class YangFileScannerTest { |
87 | * @param path where directories should be created | 94 | * @param path where directories should be created |
88 | * @return the directory path that is created | 95 | * @return the directory path that is created |
89 | */ | 96 | */ |
90 | - public File createDirectory(String path) { | 97 | + private File createDirectory(String path) { |
91 | 98 | ||
92 | File myDir = new File(path); | 99 | File myDir = new File(path); |
93 | myDir.mkdirs(); | 100 | myDir.mkdirs(); |
... | @@ -100,67 +107,59 @@ public final class YangFileScannerTest { | ... | @@ -100,67 +107,59 @@ public final class YangFileScannerTest { |
100 | * @param myDir the path where file has to be created inside | 107 | * @param myDir the path where file has to be created inside |
101 | * @param fileName the name of the file to be created | 108 | * @param fileName the name of the file to be created |
102 | */ | 109 | */ |
103 | - public void createFile(File myDir, String fileName) throws IOException { | 110 | + private void createFile(File myDir, String fileName) throws IOException { |
104 | 111 | ||
105 | File file = null; | 112 | File file = null; |
106 | - file = new File(myDir + File.separator + fileName); | 113 | + file = new File(myDir + separator + fileName); |
107 | file.createNewFile(); | 114 | file.createNewFile(); |
108 | } | 115 | } |
109 | 116 | ||
110 | /** | 117 | /** |
111 | * This testcase checks for a java file inside an empty directory. | 118 | * This testcase checks for a java file inside an empty directory. |
119 | + * | ||
120 | + * @throws IOException when fails to do IO operations | ||
112 | */ | 121 | */ |
113 | @Test | 122 | @Test |
114 | public void emptyDirJavaScannerTest() throws IOException { | 123 | public void emptyDirJavaScannerTest() throws IOException { |
115 | 124 | ||
116 | - String emptyDir = baseDir + File.separator + "scanner1"; | 125 | + String emptyDir = baseDir + separator + "scanner1"; |
117 | File path = createDirectory(emptyDir); | 126 | File path = createDirectory(emptyDir); |
118 | - List<String> emptyDirContents = YangFileScanner.getJavaFiles(path.toString()); | 127 | + List<String> emptyDirContents = getJavaFiles(path.toString()); |
119 | List<String> expectedContents = new LinkedList<>(); | 128 | List<String> expectedContents = new LinkedList<>(); |
120 | - assertEquals(emptyDirContents, expectedContents); | 129 | + assertThat(true, is(emptyDirContents.equals(expectedContents))); |
121 | } | 130 | } |
122 | 131 | ||
123 | /** | 132 | /** |
124 | * This testcase checks for a yang file inside an empty directory. | 133 | * This testcase checks for a yang file inside an empty directory. |
134 | + * | ||
135 | + * @throws IOException when fails to do IO operations | ||
125 | */ | 136 | */ |
126 | @Test | 137 | @Test |
127 | public void emptyDirYangScannerTest() throws IOException { | 138 | public void emptyDirYangScannerTest() throws IOException { |
128 | 139 | ||
129 | - String emptyYangDir = baseDir + File.separator + "scanner1"; | 140 | + String emptyYangDir = baseDir + separator + "scanner1"; |
130 | File path = createDirectory(emptyYangDir); | 141 | File path = createDirectory(emptyYangDir); |
131 | - List<String> emptyDirContents = YangFileScanner.getYangFiles(path.toString()); | 142 | + List<String> emptyDirContents = getYangFiles(path.toString()); |
132 | List<String> expectedContents = new LinkedList<>(); | 143 | List<String> expectedContents = new LinkedList<>(); |
133 | - assertEquals(emptyDirContents, expectedContents); | 144 | + assertThat(true, is(emptyDirContents.equals(expectedContents))); |
134 | } | 145 | } |
135 | 146 | ||
136 | /** | 147 | /** |
137 | * This test case checks with the sub directories in the given path for java files. | 148 | * This test case checks with the sub directories in the given path for java files. |
149 | + * | ||
150 | + * @throws IOException when fails to do IO operations | ||
138 | */ | 151 | */ |
139 | @Test | 152 | @Test |
140 | public void emptySubDirScannerTest() throws IOException { | 153 | public void emptySubDirScannerTest() throws IOException { |
141 | 154 | ||
142 | - String dir = baseDir + File.separator + "scanner3"; | 155 | + String dir = baseDir + separator + "scanner3"; |
143 | File path = createDirectory(dir); | 156 | File path = createDirectory(dir); |
144 | - String subDir = path.toString() + File.separator + "subDir1"; | 157 | + String subDir = path.toString() + separator + "subDir1"; |
145 | createDirectory(subDir); | 158 | createDirectory(subDir); |
146 | createFile(path, "invalidFile.txt"); | 159 | createFile(path, "invalidFile.txt"); |
147 | - List<String> emptySubDirContents = YangFileScanner.getJavaFiles(path.toString()); | 160 | + List<String> emptySubDirContents = getJavaFiles(path.toString()); |
148 | List<String> expectedContents = new LinkedList<>(); | 161 | List<String> expectedContents = new LinkedList<>(); |
149 | - assertEquals(emptySubDirContents, expectedContents); | 162 | + assertThat(true, is(emptySubDirContents.equals(expectedContents))); |
150 | } | 163 | } |
151 | 164 | ||
152 | - /** | ||
153 | - * This test case checks with the sub directories in the given path for java files. | ||
154 | - | ||
155 | - @Test | ||
156 | - public void exceptionHandleTest() throws IOException { | ||
157 | - | ||
158 | - String dir = baseDir + File.separator + "scanner4"; | ||
159 | - thrown.expect(IOException.class); | ||
160 | - List<String> invalidContents = YangFileScanner.getJavaFiles(dir); | ||
161 | - File path = createDirectory(dir); | ||
162 | - createFile(path, "except.java"); | ||
163 | - List<String> dirWithFileName = YangFileScanner | ||
164 | - .getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5"); | ||
165 | - }*/ | ||
166 | } | 165 | } | ... | ... |
1 | - | ||
2 | /* | 1 | /* |
3 | * Copyright 2016 Open Networking Laboratory | 2 | * Copyright 2016 Open Networking Laboratory |
4 | * | 3 | * |
... | @@ -31,7 +30,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; | ... | @@ -31,7 +30,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; |
31 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; | 30 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; |
32 | 31 | ||
33 | import static org.hamcrest.core.Is.is; | 32 | import static org.hamcrest.core.Is.is; |
34 | -import static org.junit.Assert.assertNotNull; | 33 | +import static org.hamcrest.core.IsNot.not; |
35 | import static org.junit.Assert.assertThat; | 34 | import static org.junit.Assert.assertThat; |
36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | 35 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; |
37 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; | 36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; |
... | @@ -40,7 +39,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirector | ... | @@ -40,7 +39,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirector |
40 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 39 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
41 | 40 | ||
42 | /** | 41 | /** |
43 | - * Unit tests for YANG io utils. | 42 | + * Unit tests for YANG IO utils. |
44 | */ | 43 | */ |
45 | public final class YangIoUtilsTest { | 44 | public final class YangIoUtilsTest { |
46 | 45 | ||
... | @@ -119,7 +118,7 @@ public final class YangIoUtilsTest { | ... | @@ -119,7 +118,7 @@ public final class YangIoUtilsTest { |
119 | for (Class<?> clazz : classesToConstruct) { | 118 | for (Class<?> clazz : classesToConstruct) { |
120 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 119 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
121 | constructor.setAccessible(true); | 120 | constructor.setAccessible(true); |
122 | - assertNotNull(constructor.newInstance()); | 121 | + assertThat(null, not(constructor.newInstance())); |
123 | } | 122 | } |
124 | } | 123 | } |
125 | 124 | ||
... | @@ -183,4 +182,5 @@ public final class YangIoUtilsTest { | ... | @@ -183,4 +182,5 @@ public final class YangIoUtilsTest { |
183 | String test = trimAtLast(CHECK_STRING, "six"); | 182 | String test = trimAtLast(CHECK_STRING, "six"); |
184 | assertThat(test.contains(TRIM_STRING), is(true)); | 183 | assertThat(test.contains(TRIM_STRING), is(true)); |
185 | } | 184 | } |
185 | + | ||
186 | } | 186 | } | ... | ... |
-
Please register or login to post a comment