Defect Fixes and optimization for YANG translator.
Change-Id: I974a968f3c41e1abea9f2567aceb3d523645d0ae
Showing
22 changed files
with
257 additions
and
328 deletions
... | @@ -36,12 +36,12 @@ import org.sonatype.plexus.build.incremental.BuildContext; | ... | @@ -36,12 +36,12 @@ import org.sonatype.plexus.build.incremental.BuildContext; |
36 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | 36 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; |
37 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; | 37 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; |
38 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | 38 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
39 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
39 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; |
43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | 44 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; |
44 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; | 45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; |
46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; | 46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; |
47 | 47 | ||
... | @@ -89,7 +89,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -89,7 +89,7 @@ public class YangUtilManager extends AbstractMojo { |
89 | @Component | 89 | @Component |
90 | private BuildContext context; | 90 | private BuildContext context; |
91 | 91 | ||
92 | - private static final String DEFAULT_PKG = SLASH + convertPkgToPath(DEFAULT_BASE_PKG); | 92 | + private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); |
93 | 93 | ||
94 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 94 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
95 | private String searchDir; | 95 | private String searchDir; | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.yangutils.translator.tojava; | ||
18 | - | ||
19 | -/** | ||
20 | - * Type of method generated. | ||
21 | - */ | ||
22 | -public enum GeneratedMethodTypes { | ||
23 | - /** | ||
24 | - * getter method. | ||
25 | - */ | ||
26 | - GETTER, | ||
27 | - | ||
28 | - /** | ||
29 | - * setter method. | ||
30 | - */ | ||
31 | - SETTER, | ||
32 | - | ||
33 | - /** | ||
34 | - * Constructor. | ||
35 | - */ | ||
36 | - CONSTRUCTOR, | ||
37 | - | ||
38 | - /** | ||
39 | - * Build. | ||
40 | - */ | ||
41 | - BUILD, | ||
42 | - | ||
43 | - /** | ||
44 | - * Default Constructor. | ||
45 | - */ | ||
46 | - DEFAULT_CONSTRUCTOR | ||
47 | -} |
... | @@ -284,6 +284,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -284,6 +284,11 @@ public class TempJavaCodeFragmentFiles { |
284 | private YangNode curYangNode; | 284 | private YangNode curYangNode; |
285 | 285 | ||
286 | /** | 286 | /** |
287 | + * Is attribute added. | ||
288 | + */ | ||
289 | + private boolean isAttributePresent = false; | ||
290 | + | ||
291 | + /** | ||
287 | * Construct an object of temporary java code fragment. | 292 | * Construct an object of temporary java code fragment. |
288 | * | 293 | * |
289 | * @param genFileType file generation type | 294 | * @param genFileType file generation type |
... | @@ -684,6 +689,9 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -684,6 +689,9 @@ public class TempJavaCodeFragmentFiles { |
684 | */ | 689 | */ |
685 | public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { | 690 | public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { |
686 | 691 | ||
692 | + if (newAttrInfo != null) { | ||
693 | + isAttributePresent = true; | ||
694 | + } | ||
687 | this.newAttrInfo = newAttrInfo; | 695 | this.newAttrInfo = newAttrInfo; |
688 | } | 696 | } |
689 | 697 | ||
... | @@ -903,9 +911,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -903,9 +911,6 @@ public class TempJavaCodeFragmentFiles { |
903 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); | 911 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
904 | if (!file.exists()) { | 912 | if (!file.exists()) { |
905 | file.createNewFile(); | 913 | file.createNewFile(); |
906 | - } else { | ||
907 | - file.delete(); | ||
908 | - file.createNewFile(); | ||
909 | } | 914 | } |
910 | return file; | 915 | return file; |
911 | } | 916 | } |
... | @@ -965,7 +970,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -965,7 +970,7 @@ public class TempJavaCodeFragmentFiles { |
965 | * TODO: check if this utility needs to be called or move to the caller | 970 | * TODO: check if this utility needs to be called or move to the caller |
966 | */ | 971 | */ |
967 | String attributeName = JavaIdentifierSyntax | 972 | String attributeName = JavaIdentifierSyntax |
968 | - .getCamelCase(JavaIdentifierSyntax.getLowerCase(attr.getAttributeName())); | 973 | + .getCamelCase(JavaIdentifierSyntax.getSmallCase(attr.getAttributeName())); |
969 | if (attr.isQualifiedName()) { | 974 | if (attr.isQualifiedName()) { |
970 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), | 975 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), |
971 | attributeName, attr.isListAttr()); | 976 | attributeName, attr.isListAttr()); |
... | @@ -1113,6 +1118,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1113,6 +1118,7 @@ public class TempJavaCodeFragmentFiles { |
1113 | throws IOException { | 1118 | throws IOException { |
1114 | 1119 | ||
1115 | setNewAttrInfo(newAttrInfo); | 1120 | setNewAttrInfo(newAttrInfo); |
1121 | + if (isAttributePresent) { | ||
1116 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | 1122 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
1117 | addAttribute(newAttrInfo); | 1123 | addAttribute(newAttrInfo); |
1118 | } | 1124 | } |
... | @@ -1148,6 +1154,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1148,6 +1154,7 @@ public class TempJavaCodeFragmentFiles { |
1148 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { | 1154 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
1149 | addToStringMethod(newAttrInfo); | 1155 | addToStringMethod(newAttrInfo); |
1150 | } | 1156 | } |
1157 | + } | ||
1151 | return; | 1158 | return; |
1152 | } | 1159 | } |
1153 | 1160 | ||
... | @@ -1193,7 +1200,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1193,7 +1200,7 @@ public class TempJavaCodeFragmentFiles { |
1193 | 1200 | ||
1194 | setCurYangNode(curNode); | 1201 | setCurYangNode(curNode); |
1195 | List<String> imports = new ArrayList<>(); | 1202 | List<String> imports = new ArrayList<>(); |
1196 | - if (curNode instanceof HasJavaImportData) { | 1203 | + if (curNode instanceof HasJavaImportData && isAttributePresent) { |
1197 | imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); | 1204 | imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); |
1198 | } | 1205 | } |
1199 | /** | 1206 | /** |
... | @@ -1206,13 +1213,14 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1206,13 +1213,14 @@ public class TempJavaCodeFragmentFiles { |
1206 | * Create interface file. | 1213 | * Create interface file. |
1207 | */ | 1214 | */ |
1208 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); | 1215 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
1209 | - setInterfaceJavaFileHandle(generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode)); | 1216 | + setInterfaceJavaFileHandle( |
1217 | + generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent)); | ||
1210 | /** | 1218 | /** |
1211 | * Create builder interface file. | 1219 | * Create builder interface file. |
1212 | */ | 1220 | */ |
1213 | setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); | 1221 | setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
1214 | setBuilderInterfaceJavaFileHandle( | 1222 | setBuilderInterfaceJavaFileHandle( |
1215 | - generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode)); | 1223 | + generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent)); |
1216 | /** | 1224 | /** |
1217 | * Append builder interface file to interface file and close it. | 1225 | * Append builder interface file to interface file and close it. |
1218 | */ | 1226 | */ |
... | @@ -1221,7 +1229,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1221,7 +1229,7 @@ public class TempJavaCodeFragmentFiles { |
1221 | 1229 | ||
1222 | } | 1230 | } |
1223 | 1231 | ||
1224 | - if (curNode instanceof HasJavaImportData) { | 1232 | + if (curNode instanceof HasJavaImportData && isAttributePresent) { |
1225 | imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals()); | 1233 | imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals()); |
1226 | imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString()); | 1234 | imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString()); |
1227 | java.util.Collections.sort(imports); | 1235 | java.util.Collections.sort(imports); |
... | @@ -1234,12 +1242,14 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1234,12 +1242,14 @@ public class TempJavaCodeFragmentFiles { |
1234 | * Create builder class file. | 1242 | * Create builder class file. |
1235 | */ | 1243 | */ |
1236 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); | 1244 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
1237 | - setBuilderClassJavaFileHandle(generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode)); | 1245 | + setBuilderClassJavaFileHandle( |
1246 | + generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent)); | ||
1238 | /** | 1247 | /** |
1239 | * Create impl class file. | 1248 | * Create impl class file. |
1240 | */ | 1249 | */ |
1241 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); | 1250 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); |
1242 | - setImplClassJavaFileHandle(generateImplClassFile(getImplClassJavaFileHandle(), curNode)); | 1251 | + setImplClassJavaFileHandle( |
1252 | + generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent)); | ||
1243 | /** | 1253 | /** |
1244 | * Append impl class to builder class and close it. | 1254 | * Append impl class to builder class and close it. |
1245 | */ | 1255 | */ |
... | @@ -1269,46 +1279,38 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1269,46 +1279,38 @@ public class TempJavaCodeFragmentFiles { |
1269 | */ | 1279 | */ |
1270 | private void close() throws IOException { | 1280 | private void close() throws IOException { |
1271 | 1281 | ||
1272 | - closeFile(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)); | 1282 | + if ((generatedJavaFiles & INTERFACE_MASK) != 0) { |
1273 | - | 1283 | + closeFile(getInterfaceJavaFileHandle(), false); |
1274 | - closeFile(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)); | 1284 | + } |
1275 | - getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)).delete(); | ||
1276 | - | ||
1277 | - closeFile(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)); | ||
1278 | - | ||
1279 | - closeFile(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)); | ||
1280 | - getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)).delete(); | ||
1281 | - | ||
1282 | - closeFile(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)); | ||
1283 | - | ||
1284 | - closeFile(GETTER_METHOD_FILE_NAME); | ||
1285 | - getTemporaryFileHandle(GETTER_METHOD_FILE_NAME).delete(); | ||
1286 | - | ||
1287 | - closeFile(GETTER_METHOD_IMPL_FILE_NAME); | ||
1288 | - getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME).delete(); | ||
1289 | - | ||
1290 | - closeFile(SETTER_METHOD_FILE_NAME); | ||
1291 | - getTemporaryFileHandle(SETTER_METHOD_FILE_NAME).delete(); | ||
1292 | - | ||
1293 | - closeFile(SETTER_METHOD_IMPL_FILE_NAME); | ||
1294 | - getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME).delete(); | ||
1295 | - | ||
1296 | - closeFile(CONSTRUCTOR_FILE_NAME); | ||
1297 | - getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME).delete(); | ||
1298 | 1285 | ||
1299 | - closeFile(ATTRIBUTE_FILE_NAME); | 1286 | + if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) { |
1300 | - getTemporaryFileHandle(ATTRIBUTE_FILE_NAME).delete(); | 1287 | + closeFile(getBuilderClassJavaFileHandle(), false); |
1288 | + } | ||
1301 | 1289 | ||
1302 | - closeFile(HASH_CODE_METHOD_FILE_NAME); | 1290 | + if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) { |
1303 | - getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME).delete(); | 1291 | + closeFile(getBuilderInterfaceJavaFileHandle(), true); |
1292 | + } | ||
1304 | 1293 | ||
1305 | - closeFile(TO_STRING_METHOD_FILE_NAME); | 1294 | + if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) { |
1306 | - getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME).delete(); | 1295 | + closeFile(getImplClassJavaFileHandle(), true); |
1296 | + } | ||
1307 | 1297 | ||
1308 | - closeFile(EQUALS_METHOD_FILE_NAME); | 1298 | + if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) { |
1309 | - getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME).delete(); | 1299 | + closeFile(getTypedefClassJavaFileHandle(), false); |
1300 | + } | ||
1310 | 1301 | ||
1311 | - clean(getTempDirPath()); | 1302 | + /** |
1303 | + * Close all temporary file handles and delete the files. | ||
1304 | + */ | ||
1305 | + closeFile(getGetterInterfaceTempFileHandle(), true); | ||
1306 | + closeFile(getGetterImplTempFileHandle(), true); | ||
1307 | + closeFile(getSetterInterfaceTempFileHandle(), true); | ||
1308 | + closeFile(getSetterImplTempFileHandle(), true); | ||
1309 | + closeFile(getConstructorImplTempFileHandle(), true); | ||
1310 | + closeFile(getAttributesTempFileHandle(), true); | ||
1311 | + closeFile(getHashCodeImplTempFileHandle(), true); | ||
1312 | + closeFile(getToStringImplTempFileHandle(), true); | ||
1313 | + closeFile(getEqualsImplTempFileHandle(), true); | ||
1312 | } | 1314 | } |
1313 | 1315 | ||
1314 | /** | 1316 | /** |
... | @@ -1317,8 +1319,14 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1317,8 +1319,14 @@ public class TempJavaCodeFragmentFiles { |
1317 | * @param fileName temporary file's name | 1319 | * @param fileName temporary file's name |
1318 | * @throws IOException when failed to close the file handle | 1320 | * @throws IOException when failed to close the file handle |
1319 | */ | 1321 | */ |
1320 | - private void closeFile(String fileName) throws IOException { | 1322 | + private void closeFile(File file, boolean toBeDeleted) throws IOException { |
1321 | 1323 | ||
1322 | - FileSystemUtil.updateFileHandle(new File(fileName), null, true); | 1324 | + if (file.exists()) { |
1325 | + FileSystemUtil.updateFileHandle(file, null, true); | ||
1326 | + if (toBeDeleted) { | ||
1327 | + file.delete(); | ||
1328 | + } | ||
1329 | + clean(getTempDirPath()); | ||
1330 | + } | ||
1323 | } | 1331 | } |
1324 | } | 1332 | } | ... | ... |
... | @@ -178,7 +178,6 @@ public class YangJavaContainer extends YangContainer | ... | @@ -178,7 +178,6 @@ public class YangJavaContainer extends YangContainer |
178 | @Override | 178 | @Override |
179 | public void generateCodeExit() throws IOException { | 179 | public void generateCodeExit() throws IOException { |
180 | 180 | ||
181 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
182 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 181 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
183 | } | 182 | } |
184 | 183 | ... | ... |
... | @@ -180,7 +180,6 @@ public class YangJavaInput extends YangInput | ... | @@ -180,7 +180,6 @@ public class YangJavaInput extends YangInput |
180 | @Override | 180 | @Override |
181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
182 | 182 | ||
183 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
184 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 184 | } |
186 | } | 185 | } | ... | ... |
... | @@ -181,7 +181,6 @@ public class YangJavaList extends YangList | ... | @@ -181,7 +181,6 @@ public class YangJavaList extends YangList |
181 | @Override | 181 | @Override |
182 | public void generateCodeExit() throws IOException { | 182 | public void generateCodeExit() throws IOException { |
183 | 183 | ||
184 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
185 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 184 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
186 | } | 185 | } |
187 | } | 186 | } | ... | ... |
... | @@ -37,8 +37,8 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePac | ... | @@ -37,8 +37,8 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePac |
37 | * Module information extended to support java code generation. | 37 | * Module information extended to support java code generation. |
38 | */ | 38 | */ |
39 | public class YangJavaModule extends YangModule | 39 | public class YangJavaModule extends YangModule |
40 | -implements JavaCodeGenerator, HasJavaFileInfo, | 40 | + implements JavaCodeGenerator, HasJavaFileInfo, |
41 | -HasJavaImportData, HasTempJavaCodeFragmentFiles { | 41 | + HasJavaImportData, HasTempJavaCodeFragmentFiles { |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Contains the information of the java file being generated. | 44 | * Contains the information of the java file being generated. |
... | @@ -76,7 +76,7 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles { | ... | @@ -76,7 +76,7 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles { |
76 | public JavaFileInfo getJavaFileInfo() { | 76 | public JavaFileInfo getJavaFileInfo() { |
77 | 77 | ||
78 | if (javaFileInfo == null) { | 78 | if (javaFileInfo == null) { |
79 | - throw new RuntimeException("Missing java info in java datamodel node."); | 79 | + throw new RuntimeException("Missing java info in java datamodel node"); |
80 | } | 80 | } |
81 | return javaFileInfo; | 81 | return javaFileInfo; |
82 | } | 82 | } |
... | @@ -171,7 +171,6 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles { | ... | @@ -171,7 +171,6 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles { |
171 | @Override | 171 | @Override |
172 | public void generateCodeExit() throws IOException { | 172 | public void generateCodeExit() throws IOException { |
173 | 173 | ||
174 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
175 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 174 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
176 | return; | 175 | return; |
177 | } | 176 | } | ... | ... |
... | @@ -180,7 +180,6 @@ public class YangJavaOutput extends YangOutput | ... | @@ -180,7 +180,6 @@ public class YangJavaOutput extends YangOutput |
180 | @Override | 180 | @Override |
181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
182 | 182 | ||
183 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
184 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
185 | } | 184 | } |
186 | } | 185 | } | ... | ... |
... | @@ -175,7 +175,6 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -175,7 +175,6 @@ public class YangJavaTypeDef extends YangTypeDef |
175 | @Override | 175 | @Override |
176 | public void generateCodeExit() throws IOException { | 176 | public void generateCodeExit() throws IOException { |
177 | 177 | ||
178 | - getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
179 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); | 178 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); |
180 | } | 179 | } |
181 | 180 | ... | ... |
... | @@ -78,10 +78,12 @@ public final class JavaFileGenerator { | ... | @@ -78,10 +78,12 @@ public final class JavaFileGenerator { |
78 | * @param file file | 78 | * @param file file |
79 | * @param imports imports for the file | 79 | * @param imports imports for the file |
80 | * @param curNode current YANG node | 80 | * @param curNode current YANG node |
81 | + * @param isAttrPresent if any attribute is present or not | ||
81 | * @return interface file | 82 | * @return interface file |
82 | * @throws IOException when fails to write in file | 83 | * @throws IOException when fails to write in file |
83 | */ | 84 | */ |
84 | - public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode) throws IOException { | 85 | + public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, boolean isAttrPresent) |
86 | + throws IOException { | ||
85 | 87 | ||
86 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 88 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
87 | 89 | ||
... | @@ -89,7 +91,7 @@ public final class JavaFileGenerator { | ... | @@ -89,7 +91,7 @@ public final class JavaFileGenerator { |
89 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 91 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
90 | 92 | ||
91 | initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); | 93 | initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); |
92 | - | 94 | + if (isAttrPresent) { |
93 | /** | 95 | /** |
94 | * Add getter methods to interface file. | 96 | * Add getter methods to interface file. |
95 | */ | 97 | */ |
... | @@ -102,6 +104,7 @@ public final class JavaFileGenerator { | ... | @@ -102,6 +104,7 @@ public final class JavaFileGenerator { |
102 | throw new IOException("No data found in temporary java code fragment files for " + className | 104 | throw new IOException("No data found in temporary java code fragment files for " + className |
103 | + " while interface file generation"); | 105 | + " while interface file generation"); |
104 | } | 106 | } |
107 | + } | ||
105 | return file; | 108 | return file; |
106 | } | 109 | } |
107 | 110 | ||
... | @@ -110,10 +113,12 @@ public final class JavaFileGenerator { | ... | @@ -110,10 +113,12 @@ public final class JavaFileGenerator { |
110 | * | 113 | * |
111 | * @param file file | 114 | * @param file file |
112 | * @param curNode current YANG node | 115 | * @param curNode current YANG node |
116 | + * @param isAttrPresent if any attribute is present or not | ||
113 | * @return builder interface file | 117 | * @return builder interface file |
114 | * @throws IOException when fails to write in file | 118 | * @throws IOException when fails to write in file |
115 | */ | 119 | */ |
116 | - public static File generateBuilderInterfaceFile(File file, YangNode curNode) throws IOException { | 120 | + public static File generateBuilderInterfaceFile(File file, YangNode curNode, boolean isAttrPresent) |
121 | + throws IOException { | ||
117 | 122 | ||
118 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 123 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
119 | 124 | ||
... | @@ -122,7 +127,7 @@ public final class JavaFileGenerator { | ... | @@ -122,7 +127,7 @@ public final class JavaFileGenerator { |
122 | 127 | ||
123 | initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path); | 128 | initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path); |
124 | List<String> methods = new ArrayList<>(); | 129 | List<String> methods = new ArrayList<>(); |
125 | - | 130 | + if (isAttrPresent) { |
126 | try { | 131 | try { |
127 | /** | 132 | /** |
128 | * Getter methods. | 133 | * Getter methods. |
... | @@ -137,7 +142,7 @@ public final class JavaFileGenerator { | ... | @@ -137,7 +142,7 @@ public final class JavaFileGenerator { |
137 | throw new IOException("No data found in temporary java code fragment files for " + className | 142 | throw new IOException("No data found in temporary java code fragment files for " + className |
138 | + " while builder interface file generation"); | 143 | + " while builder interface file generation"); |
139 | } | 144 | } |
140 | - | 145 | + } |
141 | /** | 146 | /** |
142 | * Add build method to builder interface file. | 147 | * Add build method to builder interface file. |
143 | */ | 148 | */ |
... | @@ -161,10 +166,12 @@ public final class JavaFileGenerator { | ... | @@ -161,10 +166,12 @@ public final class JavaFileGenerator { |
161 | * @param file file | 166 | * @param file file |
162 | * @param imports imports for the file | 167 | * @param imports imports for the file |
163 | * @param curNode current YANG node | 168 | * @param curNode current YANG node |
169 | + * @param isAttrPresent if any attribute is present or not | ||
164 | * @return builder class file | 170 | * @return builder class file |
165 | * @throws IOException when fails to write in file | 171 | * @throws IOException when fails to write in file |
166 | */ | 172 | */ |
167 | - public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode) throws IOException { | 173 | + public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode, |
174 | + boolean isAttrPresent) throws IOException { | ||
168 | 175 | ||
169 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 176 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
170 | 177 | ||
... | @@ -175,6 +182,7 @@ public final class JavaFileGenerator { | ... | @@ -175,6 +182,7 @@ public final class JavaFileGenerator { |
175 | 182 | ||
176 | List<String> methods = new ArrayList<>(); | 183 | List<String> methods = new ArrayList<>(); |
177 | 184 | ||
185 | + if (isAttrPresent) { | ||
178 | /** | 186 | /** |
179 | * Add attribute strings. | 187 | * Add attribute strings. |
180 | */ | 188 | */ |
... | @@ -199,7 +207,9 @@ public final class JavaFileGenerator { | ... | @@ -199,7 +207,9 @@ public final class JavaFileGenerator { |
199 | throw new IOException("No data found in temporary java code fragment files for " + className | 207 | throw new IOException("No data found in temporary java code fragment files for " + className |
200 | + " while builder class file generation"); | 208 | + " while builder class file generation"); |
201 | } | 209 | } |
202 | - | 210 | + } else { |
211 | + insertDataIntoJavaFile(file, NEW_LINE); | ||
212 | + } | ||
203 | /** | 213 | /** |
204 | * Add default constructor and build method impl. | 214 | * Add default constructor and build method impl. |
205 | */ | 215 | */ |
... | @@ -221,10 +231,11 @@ public final class JavaFileGenerator { | ... | @@ -221,10 +231,11 @@ public final class JavaFileGenerator { |
221 | * | 231 | * |
222 | * @param file file | 232 | * @param file file |
223 | * @param curNode current YANG node | 233 | * @param curNode current YANG node |
234 | + * @param isAttrPresent if any attribute is present or not | ||
224 | * @return impl class file | 235 | * @return impl class file |
225 | * @throws IOException when fails to write in file | 236 | * @throws IOException when fails to write in file |
226 | */ | 237 | */ |
227 | - public static File generateImplClassFile(File file, YangNode curNode) | 238 | + public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent) |
228 | throws IOException { | 239 | throws IOException { |
229 | 240 | ||
230 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 241 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
... | @@ -235,7 +246,7 @@ public final class JavaFileGenerator { | ... | @@ -235,7 +246,7 @@ public final class JavaFileGenerator { |
235 | initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); | 246 | initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path); |
236 | 247 | ||
237 | List<String> methods = new ArrayList<>(); | 248 | List<String> methods = new ArrayList<>(); |
238 | - | 249 | + if (isAttrPresent) { |
239 | /** | 250 | /** |
240 | * Add attribute strings. | 251 | * Add attribute strings. |
241 | */ | 252 | */ |
... | @@ -253,6 +264,7 @@ public final class JavaFileGenerator { | ... | @@ -253,6 +264,7 @@ public final class JavaFileGenerator { |
253 | * Getter methods. | 264 | * Getter methods. |
254 | */ | 265 | */ |
255 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | 266 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
267 | + | ||
256 | /** | 268 | /** |
257 | * Hash code method. | 269 | * Hash code method. |
258 | */ | 270 | */ |
... | @@ -273,7 +285,9 @@ public final class JavaFileGenerator { | ... | @@ -273,7 +285,9 @@ public final class JavaFileGenerator { |
273 | throw new IOException("No data found in temporary java code fragment files for " + className | 285 | throw new IOException("No data found in temporary java code fragment files for " + className |
274 | + " while impl class file generation"); | 286 | + " while impl class file generation"); |
275 | } | 287 | } |
276 | - | 288 | + } else { |
289 | + insertDataIntoJavaFile(file, NEW_LINE); | ||
290 | + } | ||
277 | try { | 291 | try { |
278 | /** | 292 | /** |
279 | * Constructor. | 293 | * Constructor. | ... | ... |
... | @@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; |
45 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | ||
45 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
46 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; |
47 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
... | @@ -53,7 +54,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUI | ... | @@ -53,7 +54,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUI |
53 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | 54 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; |
54 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | 55 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; |
55 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | 56 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; |
56 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg; | ||
57 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 57 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
58 | 58 | ||
59 | /** | 59 | /** |
... | @@ -192,7 +192,7 @@ public final class JavaFileGeneratorUtils { | ... | @@ -192,7 +192,7 @@ public final class JavaFileGeneratorUtils { |
192 | 192 | ||
193 | if (javaPkg.contains(ORG)) { | 193 | if (javaPkg.contains(ORG)) { |
194 | String[] strArray = javaPkg.split(ORG); | 194 | String[] strArray = javaPkg.split(ORG); |
195 | - javaPkg = ORG + convertPathToPkg(strArray[1]); | 195 | + javaPkg = ORG + getJavaPackageFromPackagePath(strArray[1]); |
196 | } | 196 | } |
197 | if (importsList != null) { | 197 | if (importsList != null) { |
198 | if (!importsList.isEmpty()) { | 198 | if (!importsList.isEmpty()) { | ... | ... |
... | @@ -32,8 +32,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ... | @@ -32,8 +32,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR; |
35 | +import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX; | ||
35 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE; |
38 | +import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX; | ||
37 | 39 | ||
38 | /** | 40 | /** |
39 | * Utility Class for translating the name from YANG to java convention. | 41 | * Utility Class for translating the name from YANG to java convention. |
... | @@ -121,7 +123,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -121,7 +123,7 @@ public final class JavaIdentifierSyntax { |
121 | */ | 123 | */ |
122 | private static String getYangVersion(byte ver) { | 124 | private static String getYangVersion(byte ver) { |
123 | 125 | ||
124 | - return "v" + ver; | 126 | + return VERSION_PREFIX + ver; |
125 | } | 127 | } |
126 | 128 | ||
127 | /** | 129 | /** |
... | @@ -154,7 +156,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -154,7 +156,7 @@ public final class JavaIdentifierSyntax { |
154 | 156 | ||
155 | String[] revisionArr = date.split(HYPHEN); | 157 | String[] revisionArr = date.split(HYPHEN); |
156 | 158 | ||
157 | - String rev = "rev"; | 159 | + String rev = REVISION_PREFIX; |
158 | rev = rev + revisionArr[INDEX_ZERO]; | 160 | rev = rev + revisionArr[INDEX_ZERO]; |
159 | 161 | ||
160 | if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS | 162 | if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS |
... | @@ -251,7 +253,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -251,7 +253,7 @@ public final class JavaIdentifierSyntax { |
251 | * @param yangIdentifier identifier in YANG file. | 253 | * @param yangIdentifier identifier in YANG file. |
252 | * @return corresponding java identifier | 254 | * @return corresponding java identifier |
253 | */ | 255 | */ |
254 | - public static String getLowerCase(String yangIdentifier) { | 256 | + public static String getSmallCase(String yangIdentifier) { |
255 | 257 | ||
256 | return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1); | 258 | return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1); |
257 | } | 259 | } | ... | ... |
... | @@ -20,7 +20,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | ... | @@ -20,7 +20,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
20 | 20 | ||
21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
23 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getLowerCase; | 23 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
24 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.AND; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
26 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
... | @@ -113,7 +113,7 @@ public final class MethodsGenerator { | ... | @@ -113,7 +113,7 @@ public final class MethodsGenerator { |
113 | public static String getGetterString(JavaAttributeInfo attr) { | 113 | public static String getGetterString(JavaAttributeInfo attr) { |
114 | 114 | ||
115 | String returnType = getReturnType(attr); | 115 | String returnType = getReturnType(attr); |
116 | - String attributeName = getLowerCase(attr.getAttributeName()); | 116 | + String attributeName = getSmallCase(attr.getAttributeName()); |
117 | 117 | ||
118 | return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) | 118 | return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr()) |
119 | + getGetterForInterface(attributeName, returnType, attr.isListAttr()); | 119 | + getGetterForInterface(attributeName, returnType, attr.isListAttr()); |
... | @@ -129,7 +129,7 @@ public final class MethodsGenerator { | ... | @@ -129,7 +129,7 @@ public final class MethodsGenerator { |
129 | public static String getSetterString(JavaAttributeInfo attr, String className) { | 129 | public static String getSetterString(JavaAttributeInfo attr, String className) { |
130 | 130 | ||
131 | String attrType = getReturnType(attr); | 131 | String attrType = getReturnType(attr); |
132 | - String attributeName = getLowerCase(attr.getAttributeName()); | 132 | + String attributeName = getSmallCase(attr.getAttributeName()); |
133 | 133 | ||
134 | return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr()) | 134 | return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr()) |
135 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr()); | 135 | + getSetterForInterface(attributeName, attrType, className, attr.isListAttr()); |
... | @@ -168,7 +168,7 @@ public final class MethodsGenerator { | ... | @@ -168,7 +168,7 @@ public final class MethodsGenerator { |
168 | public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { | 168 | public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { |
169 | 169 | ||
170 | String attrQuaifiedType = getReturnType(attr); | 170 | String attrQuaifiedType = getReturnType(attr); |
171 | - String attributeName = getLowerCase(attr.getAttributeName()); | 171 | + String attributeName = getSmallCase(attr.getAttributeName()); |
172 | 172 | ||
173 | if (!attr.isListAttr()) { | 173 | if (!attr.isListAttr()) { |
174 | return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); | 174 | return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); |
... | @@ -225,7 +225,7 @@ public final class MethodsGenerator { | ... | @@ -225,7 +225,7 @@ public final class MethodsGenerator { |
225 | public static String getGetterForClass(JavaAttributeInfo attr) { | 225 | public static String getGetterForClass(JavaAttributeInfo attr) { |
226 | 226 | ||
227 | String attrQuaifiedType = getReturnType(attr); | 227 | String attrQuaifiedType = getReturnType(attr); |
228 | - String attributeName = getLowerCase(attr.getAttributeName()); | 228 | + String attributeName = getSmallCase(attr.getAttributeName()); |
229 | 229 | ||
230 | if (!attr.isListAttr()) { | 230 | if (!attr.isListAttr()) { |
231 | return getGetter(attrQuaifiedType, attributeName); | 231 | return getGetter(attrQuaifiedType, attributeName); |
... | @@ -258,7 +258,7 @@ public final class MethodsGenerator { | ... | @@ -258,7 +258,7 @@ public final class MethodsGenerator { |
258 | public static String getSetterForClass(JavaAttributeInfo attr, String className) { | 258 | public static String getSetterForClass(JavaAttributeInfo attr, String className) { |
259 | 259 | ||
260 | String attrQuaifiedType = getReturnType(attr); | 260 | String attrQuaifiedType = getReturnType(attr); |
261 | - String attributeName = getLowerCase(attr.getAttributeName()); | 261 | + String attributeName = getSmallCase(attr.getAttributeName()); |
262 | if (!attr.isListAttr()) { | 262 | if (!attr.isListAttr()) { |
263 | return getSetter(className, attributeName, attrQuaifiedType); | 263 | return getSetter(className, attributeName, attrQuaifiedType); |
264 | } | 264 | } |
... | @@ -292,7 +292,7 @@ public final class MethodsGenerator { | ... | @@ -292,7 +292,7 @@ public final class MethodsGenerator { |
292 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { | 292 | public static String getSetterForTypeDefClass(JavaAttributeInfo attr) { |
293 | 293 | ||
294 | String attrQuaifiedType = getReturnType(attr); | 294 | String attrQuaifiedType = getReturnType(attr); |
295 | - String attributeName = getLowerCase(attr.getAttributeName()); | 295 | + String attributeName = getSmallCase(attr.getAttributeName()); |
296 | return getTypeDefSetter(attrQuaifiedType, attributeName); | 296 | return getTypeDefSetter(attrQuaifiedType, attributeName); |
297 | } | 297 | } |
298 | 298 | ||
... | @@ -445,7 +445,7 @@ public final class MethodsGenerator { | ... | @@ -445,7 +445,7 @@ public final class MethodsGenerator { |
445 | */ | 445 | */ |
446 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { | 446 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { |
447 | 447 | ||
448 | - String attributeName = getLowerCase(attr.getAttributeName()); | 448 | + String attributeName = getSmallCase(attr.getAttributeName()); |
449 | 449 | ||
450 | String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL | 450 | String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL |
451 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX | 451 | + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX |
... | @@ -513,7 +513,7 @@ public final class MethodsGenerator { | ... | @@ -513,7 +513,7 @@ public final class MethodsGenerator { |
513 | */ | 513 | */ |
514 | public static String getToStringMethod(JavaAttributeInfo attr) { | 514 | public static String getToStringMethod(JavaAttributeInfo attr) { |
515 | 515 | ||
516 | - String attributeName = getLowerCase(attr.getAttributeName()); | 516 | + String attributeName = getSmallCase(attr.getAttributeName()); |
517 | 517 | ||
518 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES | 518 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
519 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; | 519 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
... | @@ -554,7 +554,7 @@ public final class MethodsGenerator { | ... | @@ -554,7 +554,7 @@ public final class MethodsGenerator { |
554 | */ | 554 | */ |
555 | public static String getHashCodeMethod(JavaAttributeInfo attr) { | 555 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
556 | 556 | ||
557 | - return getLowerCase(attr.getAttributeName()) + COMMA + SPACE; | 557 | + return getSmallCase(attr.getAttributeName()) + COMMA + SPACE; |
558 | } | 558 | } |
559 | 559 | ||
560 | /** | 560 | /** |
... | @@ -621,7 +621,7 @@ public final class MethodsGenerator { | ... | @@ -621,7 +621,7 @@ public final class MethodsGenerator { |
621 | */ | 621 | */ |
622 | public static String getEqualsMethod(JavaAttributeInfo attr) { | 622 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
623 | 623 | ||
624 | - String attributeName = getLowerCase(attr.getAttributeName()); | 624 | + String attributeName = getSmallCase(attr.getAttributeName()); |
625 | 625 | ||
626 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS | 626 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
627 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND | 627 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.yangutils.translator.tojava.utils; | ||
18 | - | ||
19 | -/** | ||
20 | - * Data Store types. | ||
21 | - */ | ||
22 | -public enum TempDataStoreTypes { | ||
23 | - | ||
24 | - /** | ||
25 | - * Getter methods for interfaces. | ||
26 | - */ | ||
27 | - GETTER_METHODS, | ||
28 | - | ||
29 | - /** | ||
30 | - * Getter methods impl for classes. | ||
31 | - */ | ||
32 | - GETTER_METHODS_IMPL, | ||
33 | - | ||
34 | - /** | ||
35 | - * Setter methods for interfaces. | ||
36 | - */ | ||
37 | - SETTER_METHODS, | ||
38 | - | ||
39 | - /** | ||
40 | - * Setter methods impl for classes. | ||
41 | - */ | ||
42 | - SETTER_METHODS_IMPL, | ||
43 | - | ||
44 | - /** | ||
45 | - * Constructor for impl class. | ||
46 | - */ | ||
47 | - CONSTRUCTOR, | ||
48 | - | ||
49 | - /** | ||
50 | - * Attributes. | ||
51 | - */ | ||
52 | - ATTRIBUTE, | ||
53 | - | ||
54 | - /** | ||
55 | - * TypeDef. | ||
56 | - */ | ||
57 | - TYPE_DEF, | ||
58 | - | ||
59 | - /** | ||
60 | - * ToString method. | ||
61 | - */ | ||
62 | - TO_STRING, | ||
63 | - | ||
64 | - /** | ||
65 | - * HashCode method. | ||
66 | - */ | ||
67 | - HASH_CODE, | ||
68 | - | ||
69 | - /** | ||
70 | - * Equals method. | ||
71 | - */ | ||
72 | - EQUALS | ||
73 | -} |
This diff is collapsed. Click to expand it.
... | @@ -23,6 +23,8 @@ import java.io.FileWriter; | ... | @@ -23,6 +23,8 @@ import java.io.FileWriter; |
23 | import java.io.IOException; | 23 | import java.io.IOException; |
24 | import java.io.PrintWriter; | 24 | import java.io.PrintWriter; |
25 | 25 | ||
26 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | ||
27 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
26 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
... | @@ -31,8 +33,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ... | @@ -31,8 +33,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
33 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | 35 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; |
34 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg; | ||
35 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories; | 36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories; |
37 | 37 | ||
38 | /** | 38 | /** |
... | @@ -54,7 +54,7 @@ public final class FileSystemUtil { | ... | @@ -54,7 +54,7 @@ public final class FileSystemUtil { |
54 | */ | 54 | */ |
55 | public static boolean doesPackageExist(String pkg) { | 55 | public static boolean doesPackageExist(String pkg) { |
56 | 56 | ||
57 | - File pkgDir = new File(convertPkgToPath(pkg)); | 57 | + File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); |
58 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); | 58 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); |
59 | if (pkgDir.exists() && pkgWithFile.isFile()) { | 59 | if (pkgDir.exists() && pkgWithFile.isFile()) { |
60 | return true; | 60 | return true; |
... | @@ -74,7 +74,7 @@ public final class FileSystemUtil { | ... | @@ -74,7 +74,7 @@ public final class FileSystemUtil { |
74 | if (!doesPackageExist(pkg)) { | 74 | if (!doesPackageExist(pkg)) { |
75 | try { | 75 | try { |
76 | File pack = createDirectories(pkg); | 76 | File pack = createDirectories(pkg); |
77 | - addPackageInfo(pack, pkgInfo, convertPathToPkg(pkg)); | 77 | + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg)); |
78 | } catch (IOException e) { | 78 | } catch (IOException e) { |
79 | throw new IOException("failed to create package-info file"); | 79 | throw new IOException("failed to create package-info file"); |
80 | } | 80 | } | ... | ... |
... | @@ -41,7 +41,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS; | ... | @@ -41,7 +41,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
43 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
44 | -import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ESTRIC; | 44 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK; |
45 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; | 45 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
46 | import static org.onosproject.yangutils.utils.UtilConstants.OF; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
47 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; |
... | @@ -141,7 +141,7 @@ public final class JavaDocGen { | ... | @@ -141,7 +141,7 @@ public final class JavaDocGen { |
141 | */ | 141 | */ |
142 | public static String getJavaDoc(JavaDocType type, String name, boolean isList) { | 142 | public static String getJavaDoc(JavaDocType type, String name, boolean isList) { |
143 | 143 | ||
144 | - name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name)); | 144 | + name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name)); |
145 | String javaDoc = UtilConstants.EMPTY_STRING; | 145 | String javaDoc = UtilConstants.EMPTY_STRING; |
146 | if (type.equals(JavaDocType.IMPL_CLASS)) { | 146 | if (type.equals(JavaDocType.IMPL_CLASS)) { |
147 | javaDoc = generateForImplClass(name); | 147 | javaDoc = generateForImplClass(name); |
... | @@ -183,7 +183,7 @@ public final class JavaDocGen { | ... | @@ -183,7 +183,7 @@ public final class JavaDocGen { |
183 | private static String generateForGetters(String attribute, boolean isList) { | 183 | private static String generateForGetters(String attribute, boolean isList) { |
184 | 184 | ||
185 | String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 185 | String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
186 | - + JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC | 186 | + + JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
187 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN; | 187 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN; |
188 | if (isList) { | 188 | if (isList) { |
189 | String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; | 189 | String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; |
... | @@ -206,7 +206,7 @@ public final class JavaDocGen { | ... | @@ -206,7 +206,7 @@ public final class JavaDocGen { |
206 | private static String generateForSetters(String attribute, boolean isList) { | 206 | private static String generateForSetters(String attribute, boolean isList) { |
207 | 207 | ||
208 | String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 208 | String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
209 | - + JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC | 209 | + + JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
210 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE; | 210 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE; |
211 | if (isList) { | 211 | if (isList) { |
212 | String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; | 212 | String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE; |
... | @@ -228,7 +228,7 @@ public final class JavaDocGen { | ... | @@ -228,7 +228,7 @@ public final class JavaDocGen { |
228 | private static String generateForOf(String attribute) { | 228 | private static String generateForOf(String attribute) { |
229 | 229 | ||
230 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF | 230 | 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_ESTRIC + FOUR_SPACE_INDENTATION | 231 | + + 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 | 232 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
233 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE | 233 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE |
234 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | 234 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
... | @@ -243,7 +243,7 @@ public final class JavaDocGen { | ... | @@ -243,7 +243,7 @@ public final class JavaDocGen { |
243 | private static String generateForTypeDefSetter(String attribute) { | 243 | private static String generateForTypeDefSetter(String attribute) { |
244 | 244 | ||
245 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 245 | 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_ESTRIC | 246 | + + 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 | 247 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute |
248 | + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); | 248 | + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); |
249 | } | 249 | } |
... | @@ -257,7 +257,7 @@ public final class JavaDocGen { | ... | @@ -257,7 +257,7 @@ public final class JavaDocGen { |
257 | private static String generateForTypeDefConstructor(String attribute) { | 257 | private static String generateForTypeDefConstructor(String attribute) { |
258 | 258 | ||
259 | return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR | 259 | 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_ESTRIC + FOUR_SPACE_INDENTATION | 260 | + + 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 | 261 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
262 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); | 262 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); |
263 | } | 263 | } |
... | @@ -341,8 +341,8 @@ public final class JavaDocGen { | ... | @@ -341,8 +341,8 @@ public final class JavaDocGen { |
341 | 341 | ||
342 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE | 342 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE |
343 | + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE | 343 | + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE |
344 | - + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM | 344 | + + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM |
345 | - + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + SPACE + className + NEW_LINE | 345 | + + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + className + NEW_LINE |
346 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | 346 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
347 | } | 347 | } |
348 | 348 | ||
... | @@ -355,7 +355,7 @@ public final class JavaDocGen { | ... | @@ -355,7 +355,7 @@ public final class JavaDocGen { |
355 | private static String generateForBuild(String buildName) { | 355 | private static String generateForBuild(String buildName) { |
356 | 356 | ||
357 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD | 357 | 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_ESTRIC + FOUR_SPACE_INDENTATION | 358 | + + 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 | 359 | + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION |
360 | + JAVA_DOC_END_LINE; | 360 | + JAVA_DOC_END_LINE; |
361 | } | 361 | } | ... | ... |
... | @@ -45,7 +45,7 @@ public final class YangFileScanner { | ... | @@ -45,7 +45,7 @@ public final class YangFileScanner { |
45 | * @throws IOException when files get deleted while performing the | 45 | * @throws IOException when files get deleted while performing the |
46 | * operations | 46 | * operations |
47 | */ | 47 | */ |
48 | - public static List<String> getJavaFiles(String root) throws NullPointerException, IOException { | 48 | + public static List<String> getJavaFiles(String root) throws IOException { |
49 | 49 | ||
50 | return getFiles(root, JAVA_FILE_EXTENTION); | 50 | return getFiles(root, JAVA_FILE_EXTENTION); |
51 | } | 51 | } |
... | @@ -59,7 +59,7 @@ public final class YangFileScanner { | ... | @@ -59,7 +59,7 @@ public final class YangFileScanner { |
59 | * @throws IOException when files get deleted while performing the | 59 | * @throws IOException when files get deleted while performing the |
60 | * operations | 60 | * operations |
61 | */ | 61 | */ |
62 | - public static List<String> getYangFiles(String root) throws NullPointerException, IOException { | 62 | + public static List<String> getYangFiles(String root) throws IOException { |
63 | 63 | ||
64 | return getFiles(root, YANG_FILE_EXTENTION); | 64 | return getFiles(root, YANG_FILE_EXTENTION); |
65 | } | 65 | } |
... | @@ -73,7 +73,7 @@ public final class YangFileScanner { | ... | @@ -73,7 +73,7 @@ public final class YangFileScanner { |
73 | * @throws NullPointerException when no file is there | 73 | * @throws NullPointerException when no file is there |
74 | * @throws IOException when files get deleted while performing the operations | 74 | * @throws IOException when files get deleted while performing the operations |
75 | */ | 75 | */ |
76 | - public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { | 76 | + public static List<String> getFiles(String root, String extension) throws IOException { |
77 | 77 | ||
78 | List<String> store = new LinkedList<>(); | 78 | List<String> store = new LinkedList<>(); |
79 | Stack<String> stack = new Stack<>(); | 79 | Stack<String> stack = new Stack<>(); |
... | @@ -100,8 +100,8 @@ public final class YangFileScanner { | ... | @@ -100,8 +100,8 @@ public final class YangFileScanner { |
100 | } | 100 | } |
101 | } | 101 | } |
102 | return store; | 102 | return store; |
103 | - } catch (NullPointerException e) { | 103 | + } catch (IOException e) { |
104 | - throw new IOException("NullPointerException occured"); | 104 | + throw new IOException("No File found of " + extension + " extension in " + root + " directory."); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | } | 107 | } | ... | ... |
... | @@ -36,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ... | @@ -36,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
37 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
39 | -import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
40 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
... | @@ -294,26 +293,4 @@ public final class YangIoUtils { | ... | @@ -294,26 +293,4 @@ public final class YangIoUtils { |
294 | throw new IOException("Failed to insert in " + file + "file"); | 293 | throw new IOException("Failed to insert in " + file + "file"); |
295 | } | 294 | } |
296 | } | 295 | } |
297 | - | ||
298 | - /** | ||
299 | - * Convert directory path in java package format. | ||
300 | - * | ||
301 | - * @param path directory path | ||
302 | - * @return java package | ||
303 | - */ | ||
304 | - public static String convertPathToPkg(String path) { | ||
305 | - | ||
306 | - return path.replace(SLASH, PERIOD); | ||
307 | - } | ||
308 | - | ||
309 | - /** | ||
310 | - * Convert java package in directory path format. | ||
311 | - * | ||
312 | - * @param pkg java package | ||
313 | - * @return directory path | ||
314 | - */ | ||
315 | - public static String convertPkgToPath(String pkg) { | ||
316 | - | ||
317 | - return pkg.replace(PERIOD, SLASH); | ||
318 | - } | ||
319 | } | 296 | } | ... | ... |
... | @@ -16,24 +16,39 @@ | ... | @@ -16,24 +16,39 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import static org.hamcrest.core.Is.is; | ||
20 | -import static org.junit.Assert.assertNotNull; | ||
21 | -import static org.junit.Assert.assertThat; | ||
22 | - | ||
23 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
24 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
25 | 21 | ||
26 | import org.junit.Test; | 22 | import org.junit.Test; |
27 | -import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType; | 23 | + |
28 | -import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; | 24 | +import static org.hamcrest.core.Is.is; |
29 | -import org.onosproject.yangutils.translator.tojava.TraversalType; | 25 | +import static org.junit.Assert.assertNotNull; |
30 | -import org.onosproject.yangutils.utils.UtilConstants; | 26 | +import static org.junit.Assert.assertThat; |
27 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | ||
29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | ||
30 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
32 | +import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | ||
33 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
34 | +import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | ||
36 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
40 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
31 | 44 | ||
32 | /** | 45 | /** |
33 | * Unit tests for class definition generator for generated files. | 46 | * Unit tests for class definition generator for generated files. |
34 | */ | 47 | */ |
35 | public final class ClassDefinitionGeneratorTest { | 48 | public final class ClassDefinitionGeneratorTest { |
36 | 49 | ||
50 | + private static final String CLASS_NAME = "testclass"; | ||
51 | + | ||
37 | /** | 52 | /** |
38 | * Unit test for private constructor. | 53 | * Unit test for private constructor. |
39 | * | 54 | * |
... | @@ -62,10 +77,10 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -62,10 +77,10 @@ public final class ClassDefinitionGeneratorTest { |
62 | @Test | 77 | @Test |
63 | public void generateBuilderClassDefinitionTest() { | 78 | public void generateBuilderClassDefinitionTest() { |
64 | 79 | ||
65 | - String builderClassDefinition = ClassDefinitionGenerator | 80 | + String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME); |
66 | - .generateClassDefinition(GeneratedJavaFileType.BUILDER_CLASS_MASK, "BuilderClass"); | 81 | + assertThat(true, is(builderClassDefinition.equals( |
67 | - assertThat(true, is(builderClassDefinition.contains(UtilConstants.BUILDER))); | 82 | + PUBLIC + SPACE + CLASS + SPACE + CLASS_NAME + BUILDER + SPACE + IMPLEMENTS + SPACE + CLASS_NAME + PERIOD |
68 | - assertThat(true, is(builderClassDefinition.contains(UtilConstants.CLASS))); | 83 | + + CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
69 | } | 84 | } |
70 | 85 | ||
71 | /** | 86 | /** |
... | @@ -74,9 +89,9 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -74,9 +89,9 @@ public final class ClassDefinitionGeneratorTest { |
74 | @Test | 89 | @Test |
75 | public void generateBuilderInterfaceDefinitionTest() { | 90 | public void generateBuilderInterfaceDefinitionTest() { |
76 | 91 | ||
77 | - String builderInterfaceDefinition = ClassDefinitionGenerator | 92 | + String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME); |
78 | - .generateClassDefinition(GeneratedJavaFileType.BUILDER_INTERFACE_MASK, "BuilderInterfaceClass"); | 93 | + assertThat(true, is(builderInterfaceDefinition |
79 | - assertThat(true, is(builderInterfaceDefinition.contains(UtilConstants.BUILDER))); | 94 | + .equals(INTERFACE + SPACE + CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE))); |
80 | } | 95 | } |
81 | 96 | ||
82 | /** | 97 | /** |
... | @@ -85,9 +100,10 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -85,9 +100,10 @@ public final class ClassDefinitionGeneratorTest { |
85 | @Test | 100 | @Test |
86 | public void generateImplDefinitionTest() { | 101 | public void generateImplDefinitionTest() { |
87 | 102 | ||
88 | - String implDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedJavaFileType.IMPL_CLASS_MASK, | 103 | + String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME); |
89 | - "ImplClass"); | 104 | + assertThat(true, is(implDefinition.equals( |
90 | - assertThat(true, is(implDefinition.contains(UtilConstants.IMPL))); | 105 | + PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + IMPL + SPACE + IMPLEMENTS + SPACE |
106 | + + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
91 | } | 107 | } |
92 | 108 | ||
93 | /** | 109 | /** |
... | @@ -96,10 +112,9 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -96,10 +112,9 @@ public final class ClassDefinitionGeneratorTest { |
96 | @Test | 112 | @Test |
97 | public void generateinterfaceDefinitionTest() { | 113 | public void generateinterfaceDefinitionTest() { |
98 | 114 | ||
99 | - String interfaceDefinition = ClassDefinitionGenerator.generateClassDefinition( | 115 | + String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); |
100 | - GeneratedJavaFileType.INTERFACE_MASK, | 116 | + assertThat(true, is(interfaceDefinition |
101 | - "InterfaceClass"); | 117 | + .equals(PUBLIC + SPACE + INTERFACE + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
102 | - assertThat(true, is(interfaceDefinition.contains(UtilConstants.INTERFACE))); | ||
103 | } | 118 | } |
104 | 119 | ||
105 | /** | 120 | /** |
... | @@ -108,19 +123,8 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -108,19 +123,8 @@ public final class ClassDefinitionGeneratorTest { |
108 | @Test | 123 | @Test |
109 | public void generateTypeDefTest() { | 124 | public void generateTypeDefTest() { |
110 | 125 | ||
111 | - String typeDef = ClassDefinitionGenerator.generateClassDefinition(GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS, | 126 | + String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME); |
112 | - "invalid"); | 127 | + assertThat(true, is(typeDef.equals( |
113 | - assertThat(true, is(typeDef.contains(UtilConstants.CLASS))); | 128 | + PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
114 | - } | ||
115 | - | ||
116 | - /** | ||
117 | - * Unit test for enum data types. | ||
118 | - */ | ||
119 | - @Test | ||
120 | - public void enumDataTypesTest() { | ||
121 | - | ||
122 | - TraversalType.valueOf(TraversalType.CHILD.toString()); | ||
123 | - GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString()); | ||
124 | - TempDataStoreTypes.valueOf(TempDataStoreTypes.CONSTRUCTOR.toString()); | ||
125 | } | 129 | } |
126 | } | 130 | } | ... | ... |
... | @@ -16,38 +16,47 @@ | ... | @@ -16,38 +16,47 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import static org.hamcrest.core.Is.is; | ||
20 | -import static org.junit.Assert.assertNotNull; | ||
21 | -import static org.junit.Assert.assertThat; | ||
22 | - | ||
23 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
24 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
25 | 21 | ||
26 | import org.junit.Test; | 22 | import org.junit.Test; |
27 | -import org.onosproject.yangutils.utils.UtilConstants; | 23 | + |
24 | +import static org.hamcrest.core.Is.is; | ||
25 | +import static org.junit.Assert.assertNotNull; | ||
26 | +import static org.junit.Assert.assertThat; | ||
27 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
29 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | ||
30 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | ||
31 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | ||
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; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
28 | 36 | ||
29 | /** | 37 | /** |
30 | * Unit tests for java identifier syntax. | 38 | * Unit tests for java identifier syntax. |
31 | */ | 39 | */ |
32 | public final class JavaIdentifierSyntaxTest { | 40 | public final class JavaIdentifierSyntaxTest { |
33 | 41 | ||
34 | - public static final String PARENT_PACKAGE = "test5.test6.test7"; | 42 | + private static final String PARENT_PACKAGE = "test5/test6/test7"; |
35 | - public static final String CHILD_PACKAGE = "test1:test2:test3"; | 43 | + private static final String CHILD_PACKAGE = "test1:test2:test3"; |
36 | - public static final String DATE1 = "2000-1-5"; | 44 | + private static final String DATE1 = "2000-1-5"; |
37 | - public static final String DATE2 = "1992-01-25"; | 45 | + private static final String DATE2 = "1992-01-25"; |
38 | - public static final String PARENT_WITH_PERIOD = "test5.test6.test7"; | 46 | + private static final String PARENT_WITH_PERIOD = "test5.test6.test7"; |
39 | - public static final String CHILD_WITH_PERIOD = "test1.test2.test3"; | 47 | + private static final String CHILD_WITH_PERIOD = "test1.test2.test3"; |
40 | - public static final String DATE_WITH_REV1 = "rev20000105"; | 48 | + private static final String DATE_WITH_REV1 = "rev20000105"; |
41 | - public static final String DATE_WITH_REV2 = "rev19920125"; | 49 | + private static final String DATE_WITH_REV2 = "rev19920125"; |
42 | - public static final String VERSION_NUMBER = "v1"; | 50 | + private static final String VERSION_NUMBER = "v1"; |
43 | - public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; | 51 | + private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; |
44 | - public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; | 52 | + private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; |
45 | - public static final String VALID_NAME_SPACE1 = "_byte.test2._9test3"; | 53 | + private static final String VALID_NAME_SPACE1 = "_byte.test2._9test3"; |
46 | - public static final String VALID_NAME_SPACE2 = "_const.test2._9test3"; | 54 | + private static final String VALID_NAME_SPACE2 = "_const.test2._9test3"; |
47 | - public static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; | 55 | + private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; |
48 | - public static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; | 56 | + private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; |
49 | - public static final String WITHOUT_CAPITAL = "test_this"; | 57 | + private static final String WITHOUT_CAPITAL = "test_this"; |
50 | - public static final String WITH_CAPITAL = "Test_this"; | 58 | + private static final String WITH_CAPITAL = "Test_this"; |
59 | + private static final String WITH_SMALL = "test_this"; | ||
51 | 60 | ||
52 | /** | 61 | /** |
53 | * Unit test for private constructor. | 62 | * Unit test for private constructor. |
... | @@ -65,6 +74,7 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -65,6 +74,7 @@ public final class JavaIdentifierSyntaxTest { |
65 | @Test | 74 | @Test |
66 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 75 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
67 | InstantiationException, IllegalAccessException, InvocationTargetException { | 76 | InstantiationException, IllegalAccessException, InvocationTargetException { |
77 | + | ||
68 | Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class }; | 78 | Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class }; |
69 | for (Class<?> clazz : classesToConstruct) { | 79 | for (Class<?> clazz : classesToConstruct) { |
70 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 80 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
... | @@ -79,9 +89,9 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -79,9 +89,9 @@ public final class JavaIdentifierSyntaxTest { |
79 | @Test | 89 | @Test |
80 | public void getRootPackageTest() { | 90 | public void getRootPackageTest() { |
81 | 91 | ||
82 | - String rootPackage = JavaIdentifierSyntax.getRootPackage((byte) 1, CHILD_PACKAGE, DATE1); | 92 | + String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1); |
83 | - assertThat(rootPackage.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER | 93 | + assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
84 | - + UtilConstants.PERIOD + CHILD_WITH_PERIOD + UtilConstants.PERIOD + DATE_WITH_REV1), is(true)); | 94 | + + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); |
85 | } | 95 | } |
86 | 96 | ||
87 | /** | 97 | /** |
... | @@ -90,12 +100,12 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -90,12 +100,12 @@ public final class JavaIdentifierSyntaxTest { |
90 | @Test | 100 | @Test |
91 | public void getRootPackageWithSpecialCharactersTest() { | 101 | public void getRootPackageWithSpecialCharactersTest() { |
92 | 102 | ||
93 | - String rootPackage = JavaIdentifierSyntax.getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1); | 103 | + String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1); |
94 | - assertThat(rootPackage.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER | 104 | + assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
95 | - + UtilConstants.PERIOD + VALID_NAME_SPACE1 + UtilConstants.PERIOD + DATE_WITH_REV1), is(true)); | 105 | + + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); |
96 | - String rootPackage1 = JavaIdentifierSyntax.getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1); | 106 | + String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1); |
97 | - assertThat(rootPackage1.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER | 107 | + assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
98 | - + UtilConstants.PERIOD + VALID_NAME_SPACE2 + UtilConstants.PERIOD + DATE_WITH_REV1), is(true)); | 108 | + + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); |
99 | } | 109 | } |
100 | 110 | ||
101 | /** | 111 | /** |
... | @@ -104,9 +114,9 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -104,9 +114,9 @@ public final class JavaIdentifierSyntaxTest { |
104 | @Test | 114 | @Test |
105 | public void getRootPackageWithRevTest() { | 115 | public void getRootPackageWithRevTest() { |
106 | 116 | ||
107 | - String rootPkgWithRev = JavaIdentifierSyntax.getRootPackage((byte) 1, CHILD_PACKAGE, DATE2); | 117 | + String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2); |
108 | - assertThat(rootPkgWithRev.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD | 118 | + assertThat(rootPkgWithRev.equals( |
109 | - + VERSION_NUMBER + UtilConstants.PERIOD + CHILD_WITH_PERIOD + UtilConstants.PERIOD + DATE_WITH_REV2), | 119 | + DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), |
110 | is(true)); | 120 | is(true)); |
111 | } | 121 | } |
112 | 122 | ||
... | @@ -116,7 +126,7 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -116,7 +126,7 @@ public final class JavaIdentifierSyntaxTest { |
116 | @Test | 126 | @Test |
117 | public void getCapitalCaseTest() { | 127 | public void getCapitalCaseTest() { |
118 | 128 | ||
119 | - String capitalCase = JavaIdentifierSyntax.getCaptialCase(WITHOUT_CAPITAL); | 129 | + String capitalCase = getCaptialCase(WITHOUT_CAPITAL); |
120 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); | 130 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); |
121 | } | 131 | } |
122 | 132 | ||
... | @@ -125,7 +135,48 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -125,7 +135,48 @@ public final class JavaIdentifierSyntaxTest { |
125 | */ | 135 | */ |
126 | @Test | 136 | @Test |
127 | public void getCamelCaseTest() { | 137 | public void getCamelCaseTest() { |
128 | - String camelCase = JavaIdentifierSyntax.getCamelCase(WITHOUT_CAMEL_CASE); | 138 | + |
139 | + String camelCase = getCamelCase(WITHOUT_CAMEL_CASE); | ||
129 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); | 140 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); |
130 | } | 141 | } |
142 | + | ||
143 | + /** | ||
144 | + * Unit test for getting the camel case for the received string. | ||
145 | + */ | ||
146 | + @Test | ||
147 | + public void getSmallCaseTest() { | ||
148 | + | ||
149 | + String smallCase = getSmallCase(WITHOUT_CAPITAL); | ||
150 | + assertThat(smallCase.equals(WITH_SMALL), is(true)); | ||
151 | + } | ||
152 | + | ||
153 | + /** | ||
154 | + * Unit test for getting the camel case for the received string. | ||
155 | + */ | ||
156 | + @Test | ||
157 | + public void getPackageFromPathTest() { | ||
158 | + | ||
159 | + String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE); | ||
160 | + assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true)); | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * Unit test for getting the camel case for the received string. | ||
165 | + */ | ||
166 | + @Test | ||
167 | + public void getPathFromPackageTest() { | ||
168 | + | ||
169 | + String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD); | ||
170 | + assertThat(path.equals(PARENT_PACKAGE), is(true)); | ||
171 | + } | ||
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 | + } | ||
131 | } | 182 | } | ... | ... |
... | @@ -16,20 +16,20 @@ | ... | @@ -16,20 +16,20 @@ |
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 static org.junit.Assert.assertNotNull; | ||
23 | -import static org.junit.Assert.assertEquals; | ||
24 | - | ||
25 | import java.io.File; | 19 | import java.io.File; |
20 | +import java.io.IOException; | ||
26 | import java.lang.reflect.Constructor; | 21 | import java.lang.reflect.Constructor; |
27 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
28 | import java.util.LinkedList; | 23 | import java.util.LinkedList; |
29 | import java.util.List; | 24 | import java.util.List; |
30 | -import java.io.IOException; | ||
31 | 25 | ||
26 | +import org.junit.Rule; | ||
27 | +import org.junit.Test; | ||
28 | +import org.junit.rules.ExpectedException; | ||
32 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
30 | + | ||
31 | +import static org.junit.Assert.assertEquals; | ||
32 | +import static org.junit.Assert.assertNotNull; | ||
33 | import static org.slf4j.LoggerFactory.getLogger; | 33 | import static org.slf4j.LoggerFactory.getLogger; |
34 | 34 | ||
35 | /** | 35 | /** |
... | @@ -151,17 +151,16 @@ public final class YangFileScannerTest { | ... | @@ -151,17 +151,16 @@ public final class YangFileScannerTest { |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * This test case checks with the sub directories in the given path for java files. | 153 | * This test case checks with the sub directories in the given path for java files. |
154 | - */ | 154 | + |
155 | @Test | 155 | @Test |
156 | public void exceptionHandleTest() throws IOException { | 156 | public void exceptionHandleTest() throws IOException { |
157 | 157 | ||
158 | String dir = baseDir + File.separator + "scanner4"; | 158 | String dir = baseDir + File.separator + "scanner4"; |
159 | thrown.expect(IOException.class); | 159 | thrown.expect(IOException.class); |
160 | - thrown.expectMessage("NullPointerException occured"); | ||
161 | List<String> invalidContents = YangFileScanner.getJavaFiles(dir); | 160 | List<String> invalidContents = YangFileScanner.getJavaFiles(dir); |
162 | File path = createDirectory(dir); | 161 | File path = createDirectory(dir); |
163 | createFile(path, "except.java"); | 162 | createFile(path, "except.java"); |
164 | List<String> dirWithFileName = YangFileScanner | 163 | List<String> dirWithFileName = YangFileScanner |
165 | .getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5"); | 164 | .getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5"); |
166 | - } | 165 | + }*/ |
167 | } | 166 | } | ... | ... |
-
Please register or login to post a comment