Committed by
Gerrit Code Review
[ONOS-4149],[ONOS-3909] YANG list translator impl and bug fixes.
Change-Id: Ia1a94142a3a114815766f661ed850bf9cacde66f
Showing
29 changed files
with
526 additions
and
665 deletions
| ... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
| 18 | 18 | ||
| 19 | -import java.io.File; | ||
| 20 | import java.util.Iterator; | 19 | import java.util.Iterator; |
| 21 | import java.util.List; | 20 | import java.util.List; |
| 22 | 21 | ||
| ... | @@ -24,31 +23,34 @@ import org.apache.maven.plugin.AbstractMojo; | ... | @@ -24,31 +23,34 @@ import org.apache.maven.plugin.AbstractMojo; |
| 24 | import org.apache.maven.plugin.MojoExecutionException; | 23 | import org.apache.maven.plugin.MojoExecutionException; |
| 25 | import org.apache.maven.plugin.MojoFailureException; | 24 | import org.apache.maven.plugin.MojoFailureException; |
| 26 | import org.apache.maven.plugins.annotations.Component; | 25 | import org.apache.maven.plugins.annotations.Component; |
| 27 | -import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
| 28 | import org.apache.maven.plugins.annotations.Mojo; | 26 | import org.apache.maven.plugins.annotations.Mojo; |
| 29 | import org.apache.maven.plugins.annotations.Parameter; | 27 | import org.apache.maven.plugins.annotations.Parameter; |
| 30 | -import org.apache.maven.plugins.annotations.ResolutionScope; | ||
| 31 | import org.apache.maven.project.MavenProject; | 28 | import org.apache.maven.project.MavenProject; |
| 32 | import org.onosproject.yangutils.datamodel.YangNode; | 29 | import org.onosproject.yangutils.datamodel.YangNode; |
| 33 | import org.onosproject.yangutils.parser.YangUtilsParser; | 30 | import org.onosproject.yangutils.parser.YangUtilsParser; |
| 34 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 31 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 35 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 32 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 36 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
| 37 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 33 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
| 38 | import org.sonatype.plexus.build.incremental.BuildContext; | 34 | import org.sonatype.plexus.build.incremental.BuildContext; |
| 39 | 35 | ||
| 36 | +import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | ||
| 37 | +import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; | ||
| 40 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | 38 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
| 39 | +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | ||
| 40 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 41 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
| 41 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; | 42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; |
| 42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; |
| 44 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
| 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; | 45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; |
| 44 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; | 46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; |
| 45 | 47 | ||
| 46 | /** | 48 | /** |
| 47 | - * ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase | 49 | + * ONOS YANG utility maven plugin. |
| 48 | - * in generate-sources requiresDependencyResolution at compile time. | 50 | + * Goal of plugin is yang2java Execution phase in generate-sources requiresDependencyResolution at compile time. |
| 49 | */ | 51 | */ |
| 50 | -@Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES, | 52 | +@Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE, |
| 51 | - requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true) | 53 | + requiresProject = true) |
| 52 | public class YangUtilManager extends AbstractMojo { | 54 | public class YangUtilManager extends AbstractMojo { |
| 53 | 55 | ||
| 54 | /** | 56 | /** |
| ... | @@ -87,8 +89,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -87,8 +89,7 @@ public class YangUtilManager extends AbstractMojo { |
| 87 | @Component | 89 | @Component |
| 88 | private BuildContext context; | 90 | private BuildContext context; |
| 89 | 91 | ||
| 90 | - private static final String DEFAULT_PKG = File.separator | 92 | + private static final String DEFAULT_PKG = SLASH + convertPkgToPath(DEFAULT_BASE_PKG); |
| 91 | - + UtilConstants.DEFAULT_BASE_PKG.replace(UtilConstants.PERIOD, UtilConstants.SLASH); | ||
| 92 | 93 | ||
| 93 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 94 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
| 94 | private String searchDir; | 95 | private String searchDir; |
| ... | @@ -116,7 +117,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -116,7 +117,7 @@ public class YangUtilManager extends AbstractMojo { |
| 116 | clean(getDirectory(baseDir, outputDirectory)); | 117 | clean(getDirectory(baseDir, outputDirectory)); |
| 117 | 118 | ||
| 118 | searchDir = getDirectory(baseDir, yangFilesDir); | 119 | searchDir = getDirectory(baseDir, yangFilesDir); |
| 119 | - codeGenDir = getDirectory(baseDir, genFilesDir) + File.separator; | 120 | + codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; |
| 120 | 121 | ||
| 121 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); | 122 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); |
| 122 | Iterator<String> yangFileIterator = yangFiles.iterator(); | 123 | Iterator<String> yangFileIterator = yangFiles.iterator(); |
| ... | @@ -133,7 +134,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -133,7 +134,7 @@ public class YangUtilManager extends AbstractMojo { |
| 133 | 134 | ||
| 134 | } | 135 | } |
| 135 | if (e.getMessage() != null) { | 136 | if (e.getMessage() != null) { |
| 136 | - logInfo = logInfo + UtilConstants.NEW_LINE + e.getMessage(); | 137 | + logInfo = logInfo + NEW_LINE + e.getMessage(); |
| 137 | } | 138 | } |
| 138 | getLog().info(logInfo); | 139 | getLog().info(logInfo); |
| 139 | } | 140 | } |
| ... | @@ -143,7 +144,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -143,7 +144,7 @@ public class YangUtilManager extends AbstractMojo { |
| 143 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); | 144 | copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); |
| 144 | } catch (Exception e) { | 145 | } catch (Exception e) { |
| 145 | getLog().info(e); | 146 | getLog().info(e); |
| 146 | - //throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); | 147 | + throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage()); |
| 147 | } | 148 | } |
| 148 | } | 149 | } |
| 149 | } | 150 | } | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava; |
| 18 | 18 | ||
| 19 | import org.onosproject.yangutils.datamodel.YangNode; | 19 | import org.onosproject.yangutils.datamodel.YangNode; |
| 20 | import org.onosproject.yangutils.datamodel.YangType; | 20 | import org.onosproject.yangutils.datamodel.YangType; |
| 21 | +import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ||
| 21 | 22 | ||
| 22 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; | 23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; |
| 23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | 24 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
| ... | @@ -246,4 +247,40 @@ public final class JavaAttributeInfo { | ... | @@ -246,4 +247,40 @@ public final class JavaAttributeInfo { |
| 246 | 247 | ||
| 247 | return newAttr; | 248 | return newAttr; |
| 248 | } | 249 | } |
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * Create an attribute info object corresponding to the passed type def attribute | ||
| 253 | + * information and return it. | ||
| 254 | + * | ||
| 255 | + * @param curNode current data model node for which the java file is being | ||
| 256 | + * generated | ||
| 257 | + * @param attributeType leaf data type | ||
| 258 | + * @param attributeName leaf name | ||
| 259 | + * @param isListAttribute is the current added attribute needs to be a list | ||
| 260 | + * @return AttributeInfo attribute details required to add in temporary | ||
| 261 | + * files | ||
| 262 | + */ | ||
| 263 | + public static JavaAttributeInfo getAttributeInfoOfTypeDef(YangNode curNode, | ||
| 264 | + YangType<?> attributeType, String attributeName, | ||
| 265 | + boolean isListAttribute) { | ||
| 266 | + | ||
| 267 | + JavaAttributeInfo newAttr = new JavaAttributeInfo(); | ||
| 268 | + | ||
| 269 | + /* | ||
| 270 | + * Get the import info corresponding to the attribute for import in | ||
| 271 | + * generated java files or qualified access | ||
| 272 | + */ | ||
| 273 | + JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, | ||
| 274 | + attributeType, attributeName, isListAttribute); | ||
| 275 | + AttributesJavaDataType.addImportInfo(importInfo); | ||
| 276 | + newAttr.setImportInfo(importInfo); | ||
| 277 | + newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList( | ||
| 278 | + curNode, importInfo)); | ||
| 279 | + newAttr.setAttributeName(getCamelCase(attributeName)); | ||
| 280 | + newAttr.setListAttr(isListAttribute); | ||
| 281 | + newAttr.setImportInfo(importInfo); | ||
| 282 | + newAttr.setAttributeType(attributeType); | ||
| 283 | + | ||
| 284 | + return newAttr; | ||
| 285 | + } | ||
| 249 | } | 286 | } | ... | ... |
| ... | @@ -15,11 +15,26 @@ | ... | @@ -15,11 +15,26 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.yangutils.translator.tojava; | 16 | package org.onosproject.yangutils.translator.tojava; |
| 17 | 17 | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 18 | import java.util.SortedSet; | 20 | import java.util.SortedSet; |
| 19 | import java.util.TreeSet; | 21 | import java.util.TreeSet; |
| 20 | 22 | ||
| 21 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | 24 | ||
| 25 | +import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | ||
| 26 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
| 28 | +import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; | ||
| 29 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
| 30 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
| 31 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
| 32 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; | ||
| 33 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
| 34 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 35 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 36 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
| 37 | + | ||
| 23 | /** | 38 | /** |
| 24 | * Generated Java file can contain imports. | 39 | * Generated Java file can contain imports. |
| 25 | */ | 40 | */ |
| ... | @@ -49,6 +64,7 @@ public class JavaImportData { | ... | @@ -49,6 +64,7 @@ public class JavaImportData { |
| 49 | * @return true if any of the attribute needs to be maintained as a list. | 64 | * @return true if any of the attribute needs to be maintained as a list. |
| 50 | */ | 65 | */ |
| 51 | public boolean getIfListImported() { | 66 | public boolean getIfListImported() { |
| 67 | + | ||
| 52 | return isListToImport; | 68 | return isListToImport; |
| 53 | } | 69 | } |
| 54 | 70 | ||
| ... | @@ -58,6 +74,7 @@ public class JavaImportData { | ... | @@ -58,6 +74,7 @@ public class JavaImportData { |
| 58 | * @param isList status to mention list is bing imported. | 74 | * @param isList status to mention list is bing imported. |
| 59 | */ | 75 | */ |
| 60 | public void setIfListImported(boolean isList) { | 76 | public void setIfListImported(boolean isList) { |
| 77 | + | ||
| 61 | isListToImport = isList; | 78 | isListToImport = isList; |
| 62 | } | 79 | } |
| 63 | 80 | ||
| ... | @@ -67,6 +84,7 @@ public class JavaImportData { | ... | @@ -67,6 +84,7 @@ public class JavaImportData { |
| 67 | * @return the set containing the imported class/interface info | 84 | * @return the set containing the imported class/interface info |
| 68 | */ | 85 | */ |
| 69 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { | 86 | public SortedSet<JavaQualifiedTypeInfo> getImportSet() { |
| 87 | + | ||
| 70 | return importSet; | 88 | return importSet; |
| 71 | } | 89 | } |
| 72 | 90 | ||
| ... | @@ -76,6 +94,7 @@ public class JavaImportData { | ... | @@ -76,6 +94,7 @@ public class JavaImportData { |
| 76 | * @param importSet the set containing the imported class/interface info | 94 | * @param importSet the set containing the imported class/interface info |
| 77 | */ | 95 | */ |
| 78 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { | 96 | private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) { |
| 97 | + | ||
| 79 | this.importSet = importSet; | 98 | this.importSet = importSet; |
| 80 | } | 99 | } |
| 81 | 100 | ||
| ... | @@ -95,6 +114,7 @@ public class JavaImportData { | ... | @@ -95,6 +114,7 @@ public class JavaImportData { |
| 95 | * @return status of new addition of class/interface to the import set | 114 | * @return status of new addition of class/interface to the import set |
| 96 | */ | 115 | */ |
| 97 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { | 116 | public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) { |
| 117 | + | ||
| 98 | if (!(curNode instanceof HasJavaImportData)) { | 118 | if (!(curNode instanceof HasJavaImportData)) { |
| 99 | throw new RuntimeException("missing import info in data model node"); | 119 | throw new RuntimeException("missing import info in data model node"); |
| 100 | } | 120 | } |
| ... | @@ -108,4 +128,62 @@ public class JavaImportData { | ... | @@ -108,4 +128,62 @@ public class JavaImportData { |
| 108 | ((HasJavaImportData) curNode).getJavaImportData().getImportSet().add(newImportInfo); | 128 | ((HasJavaImportData) curNode).getJavaImportData().getImportSet().add(newImportInfo); |
| 109 | return true; | 129 | return true; |
| 110 | } | 130 | } |
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * Returns import for class. | ||
| 134 | + * | ||
| 135 | + * @param attr java attribute info | ||
| 136 | + * @return imports for class | ||
| 137 | + */ | ||
| 138 | + public List<String> getImports(JavaAttributeInfo attr) { | ||
| 139 | + | ||
| 140 | + String importString; | ||
| 141 | + List<String> imports = new ArrayList<>(); | ||
| 142 | + | ||
| 143 | + for (JavaQualifiedTypeInfo importInfo : getImportSet()) { | ||
| 144 | + importString = IMPORT; | ||
| 145 | + if (importInfo.getPkgInfo() != EMPTY_STRING && importInfo.getClassInfo() != null | ||
| 146 | + && importInfo.getPkgInfo() != JAVA_LANG) { | ||
| 147 | + importString = importString + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN | ||
| 148 | + + NEW_LINE; | ||
| 149 | + | ||
| 150 | + imports.add(importString); | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + if (attr.isListAttr()) { | ||
| 155 | + imports.add(setImportForList()); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + java.util.Collections.sort(imports); | ||
| 159 | + return imports; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Gets import for hash and equals method. | ||
| 164 | + * | ||
| 165 | + * @return import for hash and equals method | ||
| 166 | + */ | ||
| 167 | + public String getImportForHashAndEquals() { | ||
| 168 | + | ||
| 169 | + return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Gets import for to string method. | ||
| 174 | + * | ||
| 175 | + * @return import for to string method | ||
| 176 | + */ | ||
| 177 | + public String getImportForToString() { | ||
| 178 | + | ||
| 179 | + return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Sets import for to list. | ||
| 184 | + */ | ||
| 185 | + private static String setImportForList() { | ||
| 186 | + | ||
| 187 | + return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; | ||
| 188 | + } | ||
| 111 | } | 189 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 35 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
| 36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 34 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 37 | 35 | ||
| 38 | /** | 36 | /** |
| ... | @@ -162,7 +160,7 @@ public class YangJavaContainer extends YangContainer | ... | @@ -162,7 +160,7 @@ public class YangJavaContainer extends YangContainer |
| 162 | String absloutePath = getAbsolutePackagePath( | 160 | String absloutePath = getAbsolutePackagePath( |
| 163 | getJavaFileInfo().getBaseCodeGenPath(), | 161 | getJavaFileInfo().getBaseCodeGenPath(), |
| 164 | getJavaFileInfo().getPackageFilePath()); | 162 | getJavaFileInfo().getPackageFilePath()); |
| 165 | - createPackage(absloutePath, getName()); | 163 | + |
| 166 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | 164 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( |
| 167 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | 165 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, |
| 168 | getJavaFileInfo().getJavaName())); | 166 | getJavaFileInfo().getJavaName())); |
| ... | @@ -180,8 +178,8 @@ public class YangJavaContainer extends YangContainer | ... | @@ -180,8 +178,8 @@ public class YangJavaContainer extends YangContainer |
| 180 | @Override | 178 | @Override |
| 181 | public void generateCodeExit() throws IOException { | 179 | public void generateCodeExit() throws IOException { |
| 182 | 180 | ||
| 183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 181 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
| 184 | - getTempJavaCodeFragmentFiles().close(); | 182 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 185 | } | 183 | } |
| 186 | 184 | ||
| 187 | } | 185 | } | ... | ... |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | + | ||
| 20 | import org.onosproject.yangutils.datamodel.YangInput; | 21 | import org.onosproject.yangutils.datamodel.YangInput; |
| 21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
| ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 28 | 29 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| ... | @@ -180,7 +180,7 @@ public class YangJavaInput extends YangInput | ... | @@ -180,7 +180,7 @@ public class YangJavaInput extends YangInput |
| 180 | @Override | 180 | @Override |
| 181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
| 182 | 182 | ||
| 183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
| 184 | - getTempJavaCodeFragmentFiles().close(); | 184 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 185 | } | 185 | } |
| 186 | } | 186 | } | ... | ... |
| ... | @@ -27,7 +27,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +27,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| ... | @@ -155,9 +154,11 @@ public class YangJavaList extends YangList | ... | @@ -155,9 +154,11 @@ public class YangJavaList extends YangList |
| 155 | 154 | ||
| 156 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 155 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
| 157 | getJavaFileInfo().setPackage(getCurNodePackage(this)); | 156 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
| 157 | + | ||
| 158 | getJavaFileInfo().setPackageFilePath( | 158 | getJavaFileInfo().setPackageFilePath( |
| 159 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | 159 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
| 160 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | 160 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); |
| 161 | + | ||
| 161 | String absloutePath = getAbsolutePackagePath( | 162 | String absloutePath = getAbsolutePackagePath( |
| 162 | getJavaFileInfo().getBaseCodeGenPath(), | 163 | getJavaFileInfo().getBaseCodeGenPath(), |
| 163 | getJavaFileInfo().getPackageFilePath()); | 164 | getJavaFileInfo().getPackageFilePath()); |
| ... | @@ -180,7 +181,7 @@ public class YangJavaList extends YangList | ... | @@ -180,7 +181,7 @@ public class YangJavaList extends YangList |
| 180 | @Override | 181 | @Override |
| 181 | public void generateCodeExit() throws IOException { | 182 | public void generateCodeExit() throws IOException { |
| 182 | 183 | ||
| 183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 184 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
| 184 | - getTempJavaCodeFragmentFiles().close(); | 185 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 185 | } | 186 | } |
| 186 | } | 187 | } | ... | ... |
| ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,12 +27,10 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
| 35 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
| 36 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 34 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 37 | 35 | ||
| 38 | /** | 36 | /** |
| ... | @@ -163,7 +161,6 @@ public class YangJavaModule extends YangModule | ... | @@ -163,7 +161,6 @@ public class YangJavaModule extends YangModule |
| 163 | getJavaFileInfo().getBaseCodeGenPath(), | 161 | getJavaFileInfo().getBaseCodeGenPath(), |
| 164 | getJavaFileInfo().getPackageFilePath()); | 162 | getJavaFileInfo().getPackageFilePath()); |
| 165 | 163 | ||
| 166 | - createPackage(absloutePath, getName()); | ||
| 167 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | 164 | setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( |
| 168 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | 165 | getJavaFileInfo().getGeneratedFileTypes(), absloutePath, |
| 169 | getJavaFileInfo().getJavaName())); | 166 | getJavaFileInfo().getJavaName())); |
| ... | @@ -174,8 +171,8 @@ public class YangJavaModule extends YangModule | ... | @@ -174,8 +171,8 @@ public class YangJavaModule extends YangModule |
| 174 | @Override | 171 | @Override |
| 175 | public void generateCodeExit() throws IOException { | 172 | public void generateCodeExit() throws IOException { |
| 176 | 173 | ||
| 177 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 174 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
| 178 | - getTempJavaCodeFragmentFiles().close(); | 175 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 179 | return; | 176 | return; |
| 180 | } | 177 | } |
| 181 | } | 178 | } | ... | ... |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | package org.onosproject.yangutils.translator.tojava.javamodel; | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | + | ||
| 20 | import org.onosproject.yangutils.datamodel.YangOutput; | 21 | import org.onosproject.yangutils.datamodel.YangOutput; |
| 21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
| ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -27,7 +28,6 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 28 | 29 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
| 30 | -import static org.onosproject.yangutils.translator.tojava.utils.GenerateJavaCodeExitBuilder.generateJavaFile; | ||
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| ... | @@ -180,7 +180,7 @@ public class YangJavaOutput extends YangOutput | ... | @@ -180,7 +180,7 @@ public class YangJavaOutput extends YangOutput |
| 180 | @Override | 180 | @Override |
| 181 | public void generateCodeExit() throws IOException { | 181 | public void generateCodeExit() throws IOException { |
| 182 | 182 | ||
| 183 | - generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 183 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); |
| 184 | - getTempJavaCodeFragmentFiles().close(); | 184 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 185 | } | 185 | } |
| 186 | } | 186 | } | ... | ... |
| ... | @@ -75,6 +75,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -75,6 +75,7 @@ public class YangJavaSubModule extends YangSubModule |
| 75 | */ | 75 | */ |
| 76 | @Override | 76 | @Override |
| 77 | public JavaFileInfo getJavaFileInfo() { | 77 | public JavaFileInfo getJavaFileInfo() { |
| 78 | + | ||
| 78 | if (javaFileInfo == null) { | 79 | if (javaFileInfo == null) { |
| 79 | throw new RuntimeException("Missing java info in java datamodel node"); | 80 | throw new RuntimeException("Missing java info in java datamodel node"); |
| 80 | } | 81 | } |
| ... | @@ -88,6 +89,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -88,6 +89,7 @@ public class YangJavaSubModule extends YangSubModule |
| 88 | */ | 89 | */ |
| 89 | @Override | 90 | @Override |
| 90 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 91 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
| 92 | + | ||
| 91 | javaFileInfo = javaInfo; | 93 | javaFileInfo = javaInfo; |
| 92 | } | 94 | } |
| 93 | 95 | ||
| ... | @@ -98,6 +100,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -98,6 +100,7 @@ public class YangJavaSubModule extends YangSubModule |
| 98 | */ | 100 | */ |
| 99 | @Override | 101 | @Override |
| 100 | public JavaImportData getJavaImportData() { | 102 | public JavaImportData getJavaImportData() { |
| 103 | + | ||
| 101 | return javaImportData; | 104 | return javaImportData; |
| 102 | } | 105 | } |
| 103 | 106 | ||
| ... | @@ -109,6 +112,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -109,6 +112,7 @@ public class YangJavaSubModule extends YangSubModule |
| 109 | */ | 112 | */ |
| 110 | @Override | 113 | @Override |
| 111 | public void setJavaImportData(JavaImportData javaImportData) { | 114 | public void setJavaImportData(JavaImportData javaImportData) { |
| 115 | + | ||
| 112 | this.javaImportData = javaImportData; | 116 | this.javaImportData = javaImportData; |
| 113 | } | 117 | } |
| 114 | 118 | ||
| ... | @@ -119,6 +123,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -119,6 +123,7 @@ public class YangJavaSubModule extends YangSubModule |
| 119 | */ | 123 | */ |
| 120 | @Override | 124 | @Override |
| 121 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 125 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
| 126 | + | ||
| 122 | if (tempFileHandle == null) { | 127 | if (tempFileHandle == null) { |
| 123 | throw new RuntimeException("missing temp file hand for current node " | 128 | throw new RuntimeException("missing temp file hand for current node " |
| 124 | + getJavaFileInfo().getJavaName()); | 129 | + getJavaFileInfo().getJavaName()); |
| ... | @@ -133,6 +138,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -133,6 +138,7 @@ public class YangJavaSubModule extends YangSubModule |
| 133 | */ | 138 | */ |
| 134 | @Override | 139 | @Override |
| 135 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 140 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
| 141 | + | ||
| 136 | tempFileHandle = fileHandle; | 142 | tempFileHandle = fileHandle; |
| 137 | } | 143 | } |
| 138 | 144 | ||
| ... | @@ -144,6 +150,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -144,6 +150,7 @@ public class YangJavaSubModule extends YangSubModule |
| 144 | * @return the name space string of the module. | 150 | * @return the name space string of the module. |
| 145 | */ | 151 | */ |
| 146 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { | 152 | private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { |
| 153 | + | ||
| 147 | // TODO Auto-generated method stub | 154 | // TODO Auto-generated method stub |
| 148 | return ""; | 155 | return ""; |
| 149 | } | 156 | } |
| ... | @@ -157,6 +164,7 @@ public class YangJavaSubModule extends YangSubModule | ... | @@ -157,6 +164,7 @@ public class YangJavaSubModule extends YangSubModule |
| 157 | */ | 164 | */ |
| 158 | @Override | 165 | @Override |
| 159 | public void generateCodeEntry(String codeGenDir) throws IOException { | 166 | public void generateCodeEntry(String codeGenDir) throws IOException { |
| 167 | + | ||
| 160 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 168 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
| 161 | getJavaFileInfo().setPackage(getRootPackage(getVersion(), | 169 | getJavaFileInfo().setPackage(getRootPackage(getVersion(), |
| 162 | getNameSpaceFromModule(getBelongsTo()), | 170 | getNameSpaceFromModule(getBelongsTo()), | ... | ... |
| ... | @@ -15,24 +15,29 @@ | ... | @@ -15,24 +15,29 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
| 17 | 17 | ||
| 18 | +import java.io.IOException; | ||
| 19 | + | ||
| 18 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 20 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 19 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 21 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 20 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | 22 | import org.onosproject.yangutils.translator.tojava.HasJavaImportData; |
| 23 | +import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | ||
| 21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 24 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
| 22 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 23 | import org.onosproject.yangutils.translator.tojava.JavaImportData; | 26 | import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 27 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
| 24 | 28 | ||
| 25 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
| 26 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 27 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
| 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 34 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | ||
| 30 | 35 | ||
| 31 | /** | 36 | /** |
| 32 | * Type define information extended to support java code generation. | 37 | * Type define information extended to support java code generation. |
| 33 | */ | 38 | */ |
| 34 | public class YangJavaTypeDef extends YangTypeDef | 39 | public class YangJavaTypeDef extends YangTypeDef |
| 35 | - implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData { | 40 | + implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData, HasTempJavaCodeFragmentFiles { |
| 36 | 41 | ||
| 37 | /** | 42 | /** |
| 38 | * Contains the information of the java file being generated. | 43 | * Contains the information of the java file being generated. |
| ... | @@ -46,13 +51,19 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -46,13 +51,19 @@ public class YangJavaTypeDef extends YangTypeDef |
| 46 | private JavaImportData javaImportData; | 51 | private JavaImportData javaImportData; |
| 47 | 52 | ||
| 48 | /** | 53 | /** |
| 54 | + * File handle to maintain temporary java code fragments as per the code | ||
| 55 | + * snippet types. | ||
| 56 | + */ | ||
| 57 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
| 58 | + | ||
| 59 | + /** | ||
| 49 | * Default constructor. | 60 | * Default constructor. |
| 50 | */ | 61 | */ |
| 51 | public YangJavaTypeDef() { | 62 | public YangJavaTypeDef() { |
| 52 | super(); | 63 | super(); |
| 53 | setJavaFileInfo(new JavaFileInfo()); | 64 | setJavaFileInfo(new JavaFileInfo()); |
| 54 | setJavaImportData(new JavaImportData()); | 65 | setJavaImportData(new JavaImportData()); |
| 55 | - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | 66 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_TYPEDEF_CLASS); |
| 56 | } | 67 | } |
| 57 | 68 | ||
| 58 | /** | 69 | /** |
| ... | @@ -62,6 +73,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -62,6 +73,7 @@ public class YangJavaTypeDef extends YangTypeDef |
| 62 | */ | 73 | */ |
| 63 | @Override | 74 | @Override |
| 64 | public JavaFileInfo getJavaFileInfo() { | 75 | public JavaFileInfo getJavaFileInfo() { |
| 76 | + | ||
| 65 | if (javaFileInfo == null) { | 77 | if (javaFileInfo == null) { |
| 66 | throw new RuntimeException("Missing java info in java datamodel node"); | 78 | throw new RuntimeException("Missing java info in java datamodel node"); |
| 67 | } | 79 | } |
| ... | @@ -75,6 +87,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -75,6 +87,7 @@ public class YangJavaTypeDef extends YangTypeDef |
| 75 | */ | 87 | */ |
| 76 | @Override | 88 | @Override |
| 77 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 89 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
| 90 | + | ||
| 78 | javaFileInfo = javaInfo; | 91 | javaFileInfo = javaInfo; |
| 79 | } | 92 | } |
| 80 | 93 | ||
| ... | @@ -85,6 +98,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -85,6 +98,7 @@ public class YangJavaTypeDef extends YangTypeDef |
| 85 | */ | 98 | */ |
| 86 | @Override | 99 | @Override |
| 87 | public JavaImportData getJavaImportData() { | 100 | public JavaImportData getJavaImportData() { |
| 101 | + | ||
| 88 | return javaImportData; | 102 | return javaImportData; |
| 89 | } | 103 | } |
| 90 | 104 | ||
| ... | @@ -96,32 +110,73 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -96,32 +110,73 @@ public class YangJavaTypeDef extends YangTypeDef |
| 96 | */ | 110 | */ |
| 97 | @Override | 111 | @Override |
| 98 | public void setJavaImportData(JavaImportData javaImportData) { | 112 | public void setJavaImportData(JavaImportData javaImportData) { |
| 113 | + | ||
| 99 | this.javaImportData = javaImportData; | 114 | this.javaImportData = javaImportData; |
| 100 | } | 115 | } |
| 101 | 116 | ||
| 102 | /** | 117 | /** |
| 118 | + * Get the temporary file handle. | ||
| 119 | + * | ||
| 120 | + * @return temporary file handle | ||
| 121 | + */ | ||
| 122 | + @Override | ||
| 123 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
| 124 | + | ||
| 125 | + if (tempFileHandle == null) { | ||
| 126 | + throw new RuntimeException("missing temp file hand for current node " | ||
| 127 | + + getJavaFileInfo().getJavaName()); | ||
| 128 | + } | ||
| 129 | + return tempFileHandle; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * Set temporary file handle. | ||
| 134 | + * | ||
| 135 | + * @param fileHandle temporary file handle | ||
| 136 | + */ | ||
| 137 | + @Override | ||
| 138 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
| 139 | + | ||
| 140 | + tempFileHandle = fileHandle; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + /** | ||
| 103 | * Prepare the information for java code generation corresponding to YANG | 144 | * Prepare the information for java code generation corresponding to YANG |
| 104 | * container info. | 145 | * container info. |
| 105 | * | 146 | * |
| 106 | * @param codeGenDir code generation directory | 147 | * @param codeGenDir code generation directory |
| 148 | + * @throws IOException IO operations fails | ||
| 107 | */ | 149 | */ |
| 108 | @Override | 150 | @Override |
| 109 | - public void generateCodeEntry(String codeGenDir) { | 151 | + public void generateCodeEntry(String codeGenDir) throws IOException { |
| 152 | + | ||
| 110 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); | 153 | getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); |
| 111 | getJavaFileInfo().setPackage(getCurNodePackage(this)); | 154 | getJavaFileInfo().setPackage(getCurNodePackage(this)); |
| 155 | + | ||
| 112 | getJavaFileInfo().setPackageFilePath( | 156 | getJavaFileInfo().setPackageFilePath( |
| 113 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); | 157 | getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); |
| 114 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); | 158 | getJavaFileInfo().setBaseCodeGenPath(codeGenDir); |
| 115 | - // TODO: generate type define temporary files | 159 | + String absloutePath = getAbsolutePackagePath( |
| 160 | + getJavaFileInfo().getBaseCodeGenPath(), | ||
| 161 | + getJavaFileInfo().getPackageFilePath()); | ||
| 162 | + | ||
| 163 | + setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles( | ||
| 164 | + getJavaFileInfo().getGeneratedFileTypes(), absloutePath, | ||
| 165 | + getJavaFileInfo().getJavaName())); | ||
| 166 | + | ||
| 167 | + getTempJavaCodeFragmentFiles().addTypeDefAttributeToTempFiles(this); | ||
| 168 | + | ||
| 116 | } | 169 | } |
| 117 | 170 | ||
| 118 | /** | 171 | /** |
| 119 | * Create a java file using the YANG grouping info. | 172 | * Create a java file using the YANG grouping info. |
| 173 | + * @throws IOException IO operations fails | ||
| 120 | */ | 174 | */ |
| 121 | @Override | 175 | @Override |
| 122 | - public void generateCodeExit() { | 176 | + public void generateCodeExit() throws IOException { |
| 123 | - // TODO Auto-generated method stub | ||
| 124 | 177 | ||
| 178 | + getTempJavaCodeFragmentFiles().setCurYangNode(this); | ||
| 179 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this); | ||
| 125 | } | 180 | } |
| 126 | 181 | ||
| 127 | } | 182 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -16,8 +16,22 @@ | ... | @@ -16,8 +16,22 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | 18 | ||
| 19 | -import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType; | 19 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 20 | -import org.onosproject.yangutils.utils.UtilConstants; | 20 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
| 21 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | ||
| 22 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
| 23 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
| 24 | +import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
| 25 | +import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | ||
| 26 | +import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | ||
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
| 28 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | ||
| 29 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
| 30 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 31 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
| 32 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 33 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
| 34 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 21 | 35 | ||
| 22 | /** | 36 | /** |
| 23 | * Generates class definition for generated files. | 37 | * Generates class definition for generated files. |
| ... | @@ -44,19 +58,19 @@ public final class ClassDefinitionGenerator { | ... | @@ -44,19 +58,19 @@ public final class ClassDefinitionGenerator { |
| 44 | * based on the file type and the YANG name of the file, generate the | 58 | * based on the file type and the YANG name of the file, generate the |
| 45 | * class / interface definition start. | 59 | * class / interface definition start. |
| 46 | */ | 60 | */ |
| 47 | - if ((genFileTypes & GeneratedJavaFileType.INTERFACE_MASK) != 0) { | 61 | + if ((genFileTypes & INTERFACE_MASK) != 0) { |
| 48 | 62 | ||
| 49 | return getInterfaceDefinition(yangName); | 63 | return getInterfaceDefinition(yangName); |
| 50 | - } else if ((genFileTypes & GeneratedJavaFileType.BUILDER_CLASS_MASK) != 0) { | 64 | + } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { |
| 51 | 65 | ||
| 52 | return getBuilderClassDefinition(yangName); | 66 | return getBuilderClassDefinition(yangName); |
| 53 | - } else if ((genFileTypes & GeneratedJavaFileType.IMPL_CLASS_MASK) != 0) { | 67 | + } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { |
| 54 | 68 | ||
| 55 | return getImplClassDefinition(yangName); | 69 | return getImplClassDefinition(yangName); |
| 56 | - } else if ((genFileTypes & GeneratedJavaFileType.BUILDER_INTERFACE_MASK) != 0) { | 70 | + } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { |
| 57 | 71 | ||
| 58 | return getBuilderInterfaceDefinition(yangName); | 72 | return getBuilderInterfaceDefinition(yangName); |
| 59 | - } else if ((genFileTypes & GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS) != 0) { | 73 | + } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) { |
| 60 | 74 | ||
| 61 | return getTypeDefClassDefinition(yangName); | 75 | return getTypeDefClassDefinition(yangName); |
| 62 | } | 76 | } |
| ... | @@ -71,8 +85,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -71,8 +85,7 @@ public final class ClassDefinitionGenerator { |
| 71 | */ | 85 | */ |
| 72 | private static String getInterfaceDefinition(String yangName) { | 86 | private static String getInterfaceDefinition(String yangName) { |
| 73 | 87 | ||
| 74 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName | 88 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 75 | - + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
| 76 | } | 89 | } |
| 77 | 90 | ||
| 78 | /** | 91 | /** |
| ... | @@ -83,8 +96,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -83,8 +96,8 @@ public final class ClassDefinitionGenerator { |
| 83 | * @return definition | 96 | * @return definition |
| 84 | */ | 97 | */ |
| 85 | private static String getBuilderInterfaceDefinition(String yangName) { | 98 | private static String getBuilderInterfaceDefinition(String yangName) { |
| 86 | - return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE | 99 | + |
| 87 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.NEW_LINE; | 100 | + return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE; |
| 88 | } | 101 | } |
| 89 | 102 | ||
| 90 | /** | 103 | /** |
| ... | @@ -95,10 +108,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -95,10 +108,8 @@ public final class ClassDefinitionGenerator { |
| 95 | */ | 108 | */ |
| 96 | private static String getBuilderClassDefinition(String yangName) { | 109 | private static String getBuilderClassDefinition(String yangName) { |
| 97 | 110 | ||
| 98 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName | 111 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD |
| 99 | - + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE | 112 | + + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 100 | - + yangName + UtilConstants.PERIOD + yangName + UtilConstants.BUILDER + UtilConstants.SPACE | ||
| 101 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
| 102 | } | 113 | } |
| 103 | 114 | ||
| 104 | /** | 115 | /** |
| ... | @@ -109,10 +120,8 @@ public final class ClassDefinitionGenerator { | ... | @@ -109,10 +120,8 @@ public final class ClassDefinitionGenerator { |
| 109 | */ | 120 | */ |
| 110 | private static String getImplClassDefinition(String yangName) { | 121 | private static String getImplClassDefinition(String yangName) { |
| 111 | 122 | ||
| 112 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 123 | + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName |
| 113 | - + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE | 124 | + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 114 | - + UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | ||
| 115 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
| 116 | } | 125 | } |
| 117 | 126 | ||
| 118 | /** | 127 | /** |
| ... | @@ -123,9 +132,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -123,9 +132,6 @@ public final class ClassDefinitionGenerator { |
| 123 | */ | 132 | */ |
| 124 | private static String getTypeDefClassDefinition(String yangName) { | 133 | private static String getTypeDefClassDefinition(String yangName) { |
| 125 | 134 | ||
| 126 | - return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE | 135 | + return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 127 | - + UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.SPACE | ||
| 128 | - + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE; | ||
| 129 | } | 136 | } |
| 130 | - | ||
| 131 | } | 137 | } | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2016 Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | - | ||
| 17 | -package org.onosproject.yangutils.translator.tojava.utils; | ||
| 18 | - | ||
| 19 | -import java.io.File; | ||
| 20 | -import java.io.IOException; | ||
| 21 | -import java.util.ArrayList; | ||
| 22 | -import java.util.List; | ||
| 23 | - | ||
| 24 | -import org.onosproject.yangutils.datamodel.YangNode; | ||
| 25 | -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
| 26 | -import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
| 27 | -import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
| 28 | -import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
| 29 | -import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
| 30 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
| 31 | - | ||
| 32 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | ||
| 33 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | ||
| 34 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
| 35 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | ||
| 36 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
| 37 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.appendFileContents; | ||
| 38 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.clean; | ||
| 39 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.closeFileHandles; | ||
| 40 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; | ||
| 41 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; | ||
| 42 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; | ||
| 43 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; | ||
| 44 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getFileObject; | ||
| 45 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.insert; | ||
| 46 | - | ||
| 47 | -/** | ||
| 48 | - * Provides generate java code exit. | ||
| 49 | - */ | ||
| 50 | -public final class GenerateJavaCodeExitBuilder { | ||
| 51 | - | ||
| 52 | - private static final String JAVA_FILE_EXTENSION = ".java"; | ||
| 53 | - | ||
| 54 | - /** | ||
| 55 | - * Default constructor. | ||
| 56 | - */ | ||
| 57 | - private GenerateJavaCodeExitBuilder() { | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - /** | ||
| 61 | - * Sets import for hash and equals method. | ||
| 62 | - * | ||
| 63 | - * @return import string for implementing hash and equals | ||
| 64 | - */ | ||
| 65 | - private static String setImportForHashAndEquals() { | ||
| 66 | - | ||
| 67 | - return UtilConstants.IMPORT + UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG + UtilConstants.PERIOD | ||
| 68 | - + UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - /** | ||
| 72 | - * Sets import for to string method. | ||
| 73 | - * | ||
| 74 | - * @return import string for implementing to string | ||
| 75 | - */ | ||
| 76 | - private static String setImportForToString() { | ||
| 77 | - | ||
| 78 | - return UtilConstants.IMPORT + UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG + UtilConstants.PERIOD | ||
| 79 | - + UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - /** | ||
| 83 | - * Sets import for to list. | ||
| 84 | - * | ||
| 85 | - * @return import string for list collection | ||
| 86 | - */ | ||
| 87 | - private static String setImportForList() { | ||
| 88 | - | ||
| 89 | - return UtilConstants.IMPORT + UtilConstants.COLLECTION_IMPORTS + UtilConstants.PERIOD | ||
| 90 | - + UtilConstants.LIST + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - /** | ||
| 94 | - * Construct java code exit. | ||
| 95 | - * | ||
| 96 | - * @param fileType generated file type | ||
| 97 | - * @param curNode current YANG node | ||
| 98 | - * @throws IOException when fails to generate java files | ||
| 99 | - */ | ||
| 100 | - public static void generateJavaFile(int fileType, YangNode curNode) throws IOException { | ||
| 101 | - | ||
| 102 | - JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | ||
| 103 | - String className = JavaIdentifierSyntax.getCaptialCase(javaFileInfo.getJavaName()); | ||
| 104 | - String pkg = javaFileInfo.getPackageFilePath(); | ||
| 105 | - List<String> imports = getImports(((HasJavaImportData) curNode).getJavaImportData()); | ||
| 106 | - | ||
| 107 | - /** | ||
| 108 | - * Start generation of files. | ||
| 109 | - */ | ||
| 110 | - if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0 | ||
| 111 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
| 112 | - | ||
| 113 | - /** | ||
| 114 | - * Create interface file. | ||
| 115 | - */ | ||
| 116 | - String interfaceFileName = className; | ||
| 117 | - File interfaceFile = getFileObject(pkg, interfaceFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
| 118 | - interfaceFile = generateInterfaceFile(interfaceFile, imports, curNode); | ||
| 119 | - /** | ||
| 120 | - * Create temp builder interface file. | ||
| 121 | - */ | ||
| 122 | - String builderInterfaceFileName = className | ||
| 123 | - + UtilConstants.BUILDER + UtilConstants.INTERFACE; | ||
| 124 | - File builderInterfaceFile = getFileObject(pkg, builderInterfaceFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
| 125 | - builderInterfaceFile = generateBuilderInterfaceFile(builderInterfaceFile, curNode); | ||
| 126 | - /** | ||
| 127 | - * Append builder interface file to interface file and close it. | ||
| 128 | - */ | ||
| 129 | - appendFileContents(builderInterfaceFile, interfaceFile); | ||
| 130 | - insert(interfaceFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
| 131 | - /** | ||
| 132 | - * Close file handle for interface files. | ||
| 133 | - */ | ||
| 134 | - closeFileHandles(builderInterfaceFile); | ||
| 135 | - closeFileHandles(interfaceFile); | ||
| 136 | - | ||
| 137 | - /** | ||
| 138 | - * Remove temp files. | ||
| 139 | - */ | ||
| 140 | - clean(builderInterfaceFile); | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - imports.add(setImportForHashAndEquals()); | ||
| 144 | - imports.add(setImportForToString()); | ||
| 145 | - java.util.Collections.sort(imports); | ||
| 146 | - | ||
| 147 | - if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0 | ||
| 148 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | ||
| 149 | - | ||
| 150 | - /** | ||
| 151 | - * Create builder class file. | ||
| 152 | - */ | ||
| 153 | - String builderFileName = className | ||
| 154 | - + UtilConstants.BUILDER; | ||
| 155 | - File builderFile = getFileObject(pkg, builderFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
| 156 | - builderFile = generateBuilderClassFile(builderFile, imports, curNode); | ||
| 157 | - /** | ||
| 158 | - * Create temp impl class file. | ||
| 159 | - */ | ||
| 160 | - | ||
| 161 | - String implFileName = className + UtilConstants.IMPL; | ||
| 162 | - File implTempFile = getFileObject(pkg, implFileName, JAVA_FILE_EXTENSION, javaFileInfo); | ||
| 163 | - implTempFile = generateImplClassFile(implTempFile, curNode); | ||
| 164 | - /** | ||
| 165 | - * Append impl class to builder class and close it. | ||
| 166 | - */ | ||
| 167 | - appendFileContents(implTempFile, builderFile); | ||
| 168 | - insert(builderFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
| 169 | - | ||
| 170 | - /** | ||
| 171 | - * Close file handle for classes files. | ||
| 172 | - */ | ||
| 173 | - closeFileHandles(implTempFile); | ||
| 174 | - closeFileHandles(builderFile); | ||
| 175 | - | ||
| 176 | - /** | ||
| 177 | - * Remove temp files. | ||
| 178 | - */ | ||
| 179 | - clean(implTempFile); | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - /** | ||
| 183 | - * if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { | ||
| 184 | - * | ||
| 185 | - * /** Create builder class file. // | ||
| 186 | - */ | ||
| 187 | - //String typeDefFileName = className; | ||
| 188 | - //File typeDefFile = JavaFileGenerator.getFileObject(path, typeDefFileName, JAVA_FILE_EXTENSION, | ||
| 189 | - // ((HasJavaFileInfo) curNode).getJavaFileInfo()); | ||
| 190 | - //typeDefFile = JavaFileGenerator.generateTypeDefClassFile(typeDefFile, className, imports, | ||
| 191 | - // path.replace('/', '.'), attrList, ((HasJavaFileInfo) curNode).getJavaFileInfo()); | ||
| 192 | - // JavaFileGenerator.insert(typeDefFile, JavaCodeSnippetGen.getJavaClassDefClose()); | ||
| 193 | - | ||
| 194 | - // /** | ||
| 195 | - // * Close file handle for classes files. | ||
| 196 | - // */ | ||
| 197 | - // JavaFileGenerator.closeFileHandles(typeDefFile); | ||
| 198 | - // } | ||
| 199 | - // | ||
| 200 | - } | ||
| 201 | - | ||
| 202 | - /** | ||
| 203 | - * Returns import for class. | ||
| 204 | - * | ||
| 205 | - * @param javaImportData import data | ||
| 206 | - * @return imports for class | ||
| 207 | - */ | ||
| 208 | - private static List<String> getImports(JavaImportData javaImportData) { | ||
| 209 | - | ||
| 210 | - String importString; | ||
| 211 | - List<String> imports = new ArrayList<>(); | ||
| 212 | - | ||
| 213 | - for (JavaQualifiedTypeInfo importInfo : javaImportData.getImportSet()) { | ||
| 214 | - importString = UtilConstants.IMPORT; | ||
| 215 | - if (importInfo.getPkgInfo() != "" && importInfo.getClassInfo() != null | ||
| 216 | - && importInfo.getPkgInfo() != UtilConstants.JAVA_LANG) { | ||
| 217 | - importString = importString + importInfo.getPkgInfo() + "."; | ||
| 218 | - importString = importString + importInfo.getClassInfo() + UtilConstants.SEMI_COLAN | ||
| 219 | - + UtilConstants.NEW_LINE; | ||
| 220 | - | ||
| 221 | - imports.add(importString); | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | - if (javaImportData.getIfListImported()) { | ||
| 226 | - imports.add(setImportForList()); | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - java.util.Collections.sort(imports); | ||
| 230 | - return imports; | ||
| 231 | - } | ||
| 232 | -} |
| ... | @@ -17,7 +17,19 @@ | ... | @@ -17,7 +17,19 @@ |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | 18 | ||
| 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
| 20 | -import org.onosproject.yangutils.utils.UtilConstants; | 20 | + |
| 21 | +import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | ||
| 22 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
| 23 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
| 24 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
| 25 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
| 26 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
| 28 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 29 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 30 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
| 31 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
| 32 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 21 | 33 | ||
| 22 | /** | 34 | /** |
| 23 | * Utility class to generate the java snippet. | 35 | * Utility class to generate the java snippet. |
| ... | @@ -52,8 +64,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -52,8 +64,7 @@ public final class JavaCodeSnippetGen { |
| 52 | */ | 64 | */ |
| 53 | public static String getImportText(JavaQualifiedTypeInfo importInfo) { | 65 | public static String getImportText(JavaQualifiedTypeInfo importInfo) { |
| 54 | 66 | ||
| 55 | - return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo() | 67 | + return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE; |
| 56 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
| 57 | } | 68 | } |
| 58 | 69 | ||
| 59 | /** | 70 | /** |
| ... | @@ -69,8 +80,8 @@ public final class JavaCodeSnippetGen { | ... | @@ -69,8 +80,8 @@ public final class JavaCodeSnippetGen { |
| 69 | /* | 80 | /* |
| 70 | * get the camel case name for java class / interface. | 81 | * get the camel case name for java class / interface. |
| 71 | */ | 82 | */ |
| 72 | - yangName = JavaIdentifierSyntax.getCamelCase(yangName); | 83 | + yangName = getCamelCase(yangName); |
| 73 | - return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName); | 84 | + return generateClassDefinition(genFileTypes, yangName); |
| 74 | } | 85 | } |
| 75 | 86 | ||
| 76 | /** | 87 | /** |
| ... | @@ -85,30 +96,23 @@ public final class JavaCodeSnippetGen { | ... | @@ -85,30 +96,23 @@ public final class JavaCodeSnippetGen { |
| 85 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, | 96 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, |
| 86 | String javaAttributeName, boolean isList) { | 97 | String javaAttributeName, boolean isList) { |
| 87 | 98 | ||
| 88 | - String attributeDefination = UtilConstants.PRIVATE | 99 | + String attributeDefination = PRIVATE + SPACE; |
| 89 | - + UtilConstants.SPACE; | ||
| 90 | 100 | ||
| 91 | if (!isList) { | 101 | if (!isList) { |
| 92 | if (javaAttributeTypePkg != null) { | 102 | if (javaAttributeTypePkg != null) { |
| 93 | - attributeDefination = attributeDefination | 103 | + attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD; |
| 94 | - + javaAttributeTypePkg + UtilConstants.PERIOD; | ||
| 95 | } | 104 | } |
| 96 | 105 | ||
| 97 | - attributeDefination = attributeDefination | 106 | + attributeDefination = attributeDefination + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN |
| 98 | - + javaAttributeType | 107 | + + NEW_LINE; |
| 99 | - + UtilConstants.SPACE | ||
| 100 | - + javaAttributeName | ||
| 101 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
| 102 | } else { | 108 | } else { |
| 103 | - attributeDefination = attributeDefination + UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET; | 109 | + attributeDefination = attributeDefination + LIST + DIAMOND_OPEN_BRACKET; |
| 104 | if (javaAttributeTypePkg != null) { | 110 | if (javaAttributeTypePkg != null) { |
| 105 | - attributeDefination = attributeDefination | 111 | + attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD; |
| 106 | - + javaAttributeTypePkg + UtilConstants.PERIOD; | ||
| 107 | } | 112 | } |
| 108 | 113 | ||
| 109 | - attributeDefination = attributeDefination | 114 | + attributeDefination = attributeDefination + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE |
| 110 | - + javaAttributeType + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE | 115 | + + javaAttributeName + SEMI_COLAN + NEW_LINE; |
| 111 | - + javaAttributeName + UtilConstants.SUFIX_S + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE; | ||
| 112 | } | 116 | } |
| 113 | return attributeDefination; | 117 | return attributeDefination; |
| 114 | } | 118 | } |
| ... | @@ -121,7 +125,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -121,7 +125,7 @@ public final class JavaCodeSnippetGen { |
| 121 | */ | 125 | */ |
| 122 | public static String getListAttribute(String type) { | 126 | public static String getListAttribute(String type) { |
| 123 | 127 | ||
| 124 | - return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + type + UtilConstants.DIAMOND_CLOSE_BRACKET; | 128 | + return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; |
| 125 | } | 129 | } |
| 126 | 130 | ||
| 127 | /** | 131 | /** |
| ... | @@ -132,7 +136,6 @@ public final class JavaCodeSnippetGen { | ... | @@ -132,7 +136,6 @@ public final class JavaCodeSnippetGen { |
| 132 | */ | 136 | */ |
| 133 | public static String getJavaClassDefClose() { | 137 | public static String getJavaClassDefClose() { |
| 134 | 138 | ||
| 135 | - return UtilConstants.CLOSE_CURLY_BRACKET; | 139 | + return CLOSE_CURLY_BRACKET; |
| 136 | } | 140 | } |
| 137 | - | ||
| 138 | } | 141 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -16,14 +16,24 @@ | ... | @@ -16,14 +16,24 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | 18 | ||
| 19 | -import java.io.File; | ||
| 20 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
| 21 | 20 | ||
| 22 | import org.onosproject.yangutils.datamodel.YangNode; | 21 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 22 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 24 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 23 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
| 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 26 | -import org.onosproject.yangutils.utils.UtilConstants; | 25 | + |
| 26 | +import static org.onosproject.yangutils.utils.UtilConstants.COLAN; | ||
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; | ||
| 28 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 29 | +import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; | ||
| 30 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS; | ||
| 31 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 32 | +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
| 33 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; | ||
| 34 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR; | ||
| 35 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
| 36 | +import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE; | ||
| 27 | 37 | ||
| 28 | /** | 38 | /** |
| 29 | * Utility Class for translating the name from YANG to java convention. | 39 | * Utility Class for translating the name from YANG to java convention. |
| ... | @@ -53,12 +63,12 @@ public final class JavaIdentifierSyntax { | ... | @@ -53,12 +63,12 @@ public final class JavaIdentifierSyntax { |
| 53 | public static String getRootPackage(byte version, String nameSpace, String revision) { | 63 | public static String getRootPackage(byte version, String nameSpace, String revision) { |
| 54 | 64 | ||
| 55 | String pkg; | 65 | String pkg; |
| 56 | - pkg = UtilConstants.DEFAULT_BASE_PKG; | 66 | + pkg = DEFAULT_BASE_PKG; |
| 57 | - pkg = pkg + UtilConstants.PERIOD; | 67 | + pkg = pkg + PERIOD; |
| 58 | pkg = pkg + getYangVersion(version); | 68 | pkg = pkg + getYangVersion(version); |
| 59 | - pkg = pkg + UtilConstants.PERIOD; | 69 | + pkg = pkg + PERIOD; |
| 60 | pkg = pkg + getPkgFromNameSpace(nameSpace); | 70 | pkg = pkg + getPkgFromNameSpace(nameSpace); |
| 61 | - pkg = pkg + UtilConstants.PERIOD; | 71 | + pkg = pkg + PERIOD; |
| 62 | pkg = pkg + getYangRevisionStr(revision); | 72 | pkg = pkg + getYangRevisionStr(revision); |
| 63 | 73 | ||
| 64 | return pkg.toLowerCase(); | 74 | return pkg.toLowerCase(); |
| ... | @@ -99,7 +109,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -99,7 +109,7 @@ public final class JavaIdentifierSyntax { |
| 99 | throw new RuntimeException("missing parent java node to get current node's package"); | 109 | throw new RuntimeException("missing parent java node to get current node's package"); |
| 100 | } | 110 | } |
| 101 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); | 111 | JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo(); |
| 102 | - pkg = parentJavaFileHandle.getPackage() + UtilConstants.PERIOD + parentJavaFileHandle.getJavaName(); | 112 | + pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName(); |
| 103 | return pkg.toLowerCase(); | 113 | return pkg.toLowerCase(); |
| 104 | } | 114 | } |
| 105 | 115 | ||
| ... | @@ -123,9 +133,9 @@ public final class JavaIdentifierSyntax { | ... | @@ -123,9 +133,9 @@ public final class JavaIdentifierSyntax { |
| 123 | public static String getPkgFromNameSpace(String nameSpace) { | 133 | public static String getPkgFromNameSpace(String nameSpace) { |
| 124 | 134 | ||
| 125 | ArrayList<String> pkgArr = new ArrayList<String>(); | 135 | ArrayList<String> pkgArr = new ArrayList<String>(); |
| 126 | - nameSpace = nameSpace.replace(UtilConstants.QUOTES, UtilConstants.EMPTY_STRING); | 136 | + nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); |
| 127 | - String properNameSpace = nameSpace.replaceAll(UtilConstants.REGEX_WITH_SPECIAL_CHAR, UtilConstants.COLAN); | 137 | + String properNameSpace = nameSpace.replaceAll(REGEX_WITH_SPECIAL_CHAR, COLAN); |
| 128 | - String[] nameSpaceArr = properNameSpace.split(UtilConstants.COLAN); | 138 | + String[] nameSpaceArr = properNameSpace.split(COLAN); |
| 129 | 139 | ||
| 130 | for (String nameSpaceString : nameSpaceArr) { | 140 | for (String nameSpaceString : nameSpaceArr) { |
| 131 | pkgArr.add(nameSpaceString); | 141 | pkgArr.add(nameSpaceString); |
| ... | @@ -142,7 +152,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -142,7 +152,7 @@ public final class JavaIdentifierSyntax { |
| 142 | */ | 152 | */ |
| 143 | public static String getYangRevisionStr(String date) throws TranslatorException { | 153 | public static String getYangRevisionStr(String date) throws TranslatorException { |
| 144 | 154 | ||
| 145 | - String[] revisionArr = date.split(UtilConstants.HYPHEN); | 155 | + String[] revisionArr = date.split(HYPHEN); |
| 146 | 156 | ||
| 147 | String rev = "rev"; | 157 | String rev = "rev"; |
| 148 | rev = rev + revisionArr[INDEX_ZERO]; | 158 | rev = rev + revisionArr[INDEX_ZERO]; |
| ... | @@ -172,17 +182,17 @@ public final class JavaIdentifierSyntax { | ... | @@ -172,17 +182,17 @@ public final class JavaIdentifierSyntax { |
| 172 | */ | 182 | */ |
| 173 | public static String getPkgFrmArr(ArrayList<String> pkgArr) { | 183 | public static String getPkgFrmArr(ArrayList<String> pkgArr) { |
| 174 | 184 | ||
| 175 | - String pkg = UtilConstants.EMPTY_STRING; | 185 | + String pkg = EMPTY_STRING; |
| 176 | int size = pkgArr.size(); | 186 | int size = pkgArr.size(); |
| 177 | int i = 0; | 187 | int i = 0; |
| 178 | for (String member : pkgArr) { | 188 | for (String member : pkgArr) { |
| 179 | - boolean presenceOfKeyword = UtilConstants.JAVA_KEY_WORDS.contains(member); | 189 | + boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member); |
| 180 | - if (presenceOfKeyword || member.matches(UtilConstants.REGEX_FOR_FIRST_DIGIT)) { | 190 | + if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { |
| 181 | - member = UtilConstants.UNDER_SCORE + member; | 191 | + member = UNDER_SCORE + member; |
| 182 | } | 192 | } |
| 183 | pkg = pkg + member; | 193 | pkg = pkg + member; |
| 184 | if (i != size - 1) { | 194 | if (i != size - 1) { |
| 185 | - pkg = pkg + UtilConstants.PERIOD; | 195 | + pkg = pkg + PERIOD; |
| 186 | } | 196 | } |
| 187 | i++; | 197 | i++; |
| 188 | } | 198 | } |
| ... | @@ -198,7 +208,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -198,7 +208,7 @@ public final class JavaIdentifierSyntax { |
| 198 | public static String getSubPkgFromName(String name) { | 208 | public static String getSubPkgFromName(String name) { |
| 199 | 209 | ||
| 200 | ArrayList<String> pkgArr = new ArrayList<String>(); | 210 | ArrayList<String> pkgArr = new ArrayList<String>(); |
| 201 | - String[] nameArr = name.split(UtilConstants.COLAN); | 211 | + String[] nameArr = name.split(COLAN); |
| 202 | 212 | ||
| 203 | for (String nameString : nameArr) { | 213 | for (String nameString : nameArr) { |
| 204 | pkgArr.add(nameString); | 214 | pkgArr.add(nameString); |
| ... | @@ -214,7 +224,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -214,7 +224,7 @@ public final class JavaIdentifierSyntax { |
| 214 | */ | 224 | */ |
| 215 | public static String getCamelCase(String yangIdentifier) { | 225 | public static String getCamelCase(String yangIdentifier) { |
| 216 | 226 | ||
| 217 | - String[] strArray = yangIdentifier.split(UtilConstants.HYPHEN); | 227 | + String[] strArray = yangIdentifier.split(HYPHEN); |
| 218 | String camelCase = strArray[0]; | 228 | String camelCase = strArray[0]; |
| 219 | for (int i = 1; i < strArray.length; i++) { | 229 | for (int i = 1; i < strArray.length; i++) { |
| 220 | camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1); | 230 | camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1); |
| ... | @@ -254,7 +264,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -254,7 +264,7 @@ public final class JavaIdentifierSyntax { |
| 254 | */ | 264 | */ |
| 255 | public static String getJavaPackageFromPackagePath(String packagePath) { | 265 | public static String getJavaPackageFromPackagePath(String packagePath) { |
| 256 | 266 | ||
| 257 | - return packagePath.replace(File.separator, UtilConstants.PERIOD); | 267 | + return packagePath.replace(SLASH, PERIOD); |
| 258 | } | 268 | } |
| 259 | 269 | ||
| 260 | /** | 270 | /** |
| ... | @@ -265,6 +275,6 @@ public final class JavaIdentifierSyntax { | ... | @@ -265,6 +275,6 @@ public final class JavaIdentifierSyntax { |
| 265 | */ | 275 | */ |
| 266 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { | 276 | public static String getPackageDirPathFromJavaJPackage(String packagePath) { |
| 267 | 277 | ||
| 268 | - return packagePath.replace(UtilConstants.PERIOD, File.separator); | 278 | + return packagePath.replace(PERIOD, SLASH); |
| 269 | } | 279 | } |
| 270 | } | 280 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -83,7 +83,7 @@ public final class UtilConstants { | ... | @@ -83,7 +83,7 @@ public final class UtilConstants { |
| 83 | public static final String INSTANCE_OF = " instanceof "; | 83 | public static final String INSTANCE_OF = " instanceof "; |
| 84 | 84 | ||
| 85 | public static final String VALUE = "value"; | 85 | public static final String VALUE = "value"; |
| 86 | - public static final String SUFIX_S = "s"; | 86 | + public static final String SUFFIX_S = "s"; |
| 87 | 87 | ||
| 88 | public static final String IF = "if"; | 88 | public static final String IF = "if"; |
| 89 | public static final String FOR = "for"; | 89 | public static final String FOR = "for"; |
| ... | @@ -152,7 +152,7 @@ public final class UtilConstants { | ... | @@ -152,7 +152,7 @@ public final class UtilConstants { |
| 152 | /** | 152 | /** |
| 153 | * String built in java type. | 153 | * String built in java type. |
| 154 | */ | 154 | */ |
| 155 | - public static final String STRING = "String"; | 155 | + public static final String STRING_DATA_TYPE = "String"; |
| 156 | /** | 156 | /** |
| 157 | * java.lang.* packages. | 157 | * java.lang.* packages. |
| 158 | */ | 158 | */ |
| ... | @@ -161,7 +161,7 @@ public final class UtilConstants { | ... | @@ -161,7 +161,7 @@ public final class UtilConstants { |
| 161 | /** | 161 | /** |
| 162 | * boolean built in java type. | 162 | * boolean built in java type. |
| 163 | */ | 163 | */ |
| 164 | - public static final String BOOLEAN = "boolean"; | 164 | + public static final String BOOLEAN_DATA_TYPE = "boolean"; |
| 165 | 165 | ||
| 166 | /** | 166 | /** |
| 167 | * byte java built in type. | 167 | * byte java built in type. |
| ... | @@ -229,8 +229,7 @@ public final class UtilConstants { | ... | @@ -229,8 +229,7 @@ public final class UtilConstants { |
| 229 | public static final String DOUBLE_WRAPPER = "Double"; | 229 | public static final String DOUBLE_WRAPPER = "Double"; |
| 230 | 230 | ||
| 231 | /** | 231 | /** |
| 232 | - * List of keywords in java, this is used for checking if the input does not | 232 | + * List of keywords in java, this is used for checking if the input does not contain these keywords. |
| 233 | - * contain these keywords. | ||
| 234 | */ | 233 | */ |
| 235 | public static final List JAVA_KEY_WORDS = Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case", | 234 | public static final List JAVA_KEY_WORDS = Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case", |
| 236 | "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", | 235 | "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", | ... | ... |
| ... | @@ -24,12 +24,16 @@ import java.io.IOException; | ... | @@ -24,12 +24,16 @@ import java.io.IOException; |
| 24 | import java.io.InputStream; | 24 | import java.io.InputStream; |
| 25 | import java.io.OutputStream; | 25 | import java.io.OutputStream; |
| 26 | 26 | ||
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 28 | + | ||
| 27 | /** | 29 | /** |
| 28 | * Provides the license header for the generated files. | 30 | * Provides the license header for the generated files. |
| 29 | */ | 31 | */ |
| 30 | public final class CopyrightHeader { | 32 | public final class CopyrightHeader { |
| 31 | 33 | ||
| 32 | private static final int EOF = -1; | 34 | private static final int EOF = -1; |
| 35 | + private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt"; | ||
| 36 | + private static final String TEMP_FILE = "temp.txt"; | ||
| 33 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); | 37 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); |
| 34 | 38 | ||
| 35 | private static String copyrightHeader; | 39 | private static String copyrightHeader; |
| ... | @@ -47,6 +51,7 @@ public final class CopyrightHeader { | ... | @@ -47,6 +51,7 @@ public final class CopyrightHeader { |
| 47 | * @throws IOException when fails to parse copyright header | 51 | * @throws IOException when fails to parse copyright header |
| 48 | */ | 52 | */ |
| 49 | public static String getCopyrightHeader() throws IOException { | 53 | public static String getCopyrightHeader() throws IOException { |
| 54 | + | ||
| 50 | if (copyrightHeader == null) { | 55 | if (copyrightHeader == null) { |
| 51 | parseCopyrightHeader(); | 56 | parseCopyrightHeader(); |
| 52 | } | 57 | } |
| ... | @@ -59,6 +64,7 @@ public final class CopyrightHeader { | ... | @@ -59,6 +64,7 @@ public final class CopyrightHeader { |
| 59 | * @param header copyright header | 64 | * @param header copyright header |
| 60 | */ | 65 | */ |
| 61 | private static void setCopyrightHeader(String header) { | 66 | private static void setCopyrightHeader(String header) { |
| 67 | + | ||
| 62 | copyrightHeader = header; | 68 | copyrightHeader = header; |
| 63 | } | 69 | } |
| 64 | 70 | ||
| ... | @@ -69,11 +75,12 @@ public final class CopyrightHeader { | ... | @@ -69,11 +75,12 @@ public final class CopyrightHeader { |
| 69 | */ | 75 | */ |
| 70 | public static void parseCopyrightHeader() throws IOException { | 76 | public static void parseCopyrightHeader() throws IOException { |
| 71 | 77 | ||
| 72 | - File temp = new File("temp.txt"); | 78 | + File temp = new File(TEMP_FILE); |
| 73 | 79 | ||
| 74 | try { | 80 | try { |
| 75 | - InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt"); | 81 | + InputStream stream = classLoader.getResourceAsStream(COPYRIGHT_HEADER_FILE); |
| 76 | OutputStream out = new FileOutputStream(temp); | 82 | OutputStream out = new FileOutputStream(temp); |
| 83 | + | ||
| 77 | int index; | 84 | int index; |
| 78 | while ((index = stream.read()) != EOF) { | 85 | while ((index = stream.read()) != EOF) { |
| 79 | out.write(index); | 86 | out.write(index); |
| ... | @@ -98,18 +105,20 @@ public final class CopyrightHeader { | ... | @@ -98,18 +105,20 @@ public final class CopyrightHeader { |
| 98 | */ | 105 | */ |
| 99 | private static String getStringFileContent(File toAppend) throws IOException { | 106 | private static String getStringFileContent(File toAppend) throws IOException { |
| 100 | 107 | ||
| 101 | - BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend)); | 108 | + FileReader fileReader = new FileReader(toAppend); |
| 109 | + BufferedReader bufferReader = new BufferedReader(fileReader); | ||
| 102 | try { | 110 | try { |
| 103 | StringBuilder stringBuilder = new StringBuilder(); | 111 | StringBuilder stringBuilder = new StringBuilder(); |
| 104 | String line = bufferReader.readLine(); | 112 | String line = bufferReader.readLine(); |
| 105 | 113 | ||
| 106 | while (line != null) { | 114 | while (line != null) { |
| 107 | stringBuilder.append(line); | 115 | stringBuilder.append(line); |
| 108 | - stringBuilder.append("\n"); | 116 | + stringBuilder.append(NEW_LINE); |
| 109 | line = bufferReader.readLine(); | 117 | line = bufferReader.readLine(); |
| 110 | } | 118 | } |
| 111 | return stringBuilder.toString(); | 119 | return stringBuilder.toString(); |
| 112 | } finally { | 120 | } finally { |
| 121 | + fileReader.close(); | ||
| 113 | bufferReader.close(); | 122 | bufferReader.close(); |
| 114 | } | 123 | } |
| 115 | } | 124 | } | ... | ... |
| ... | @@ -23,7 +23,17 @@ import java.io.FileWriter; | ... | @@ -23,7 +23,17 @@ import java.io.FileWriter; |
| 23 | import java.io.IOException; | 23 | import java.io.IOException; |
| 24 | import java.io.PrintWriter; | 24 | import java.io.PrintWriter; |
| 25 | 25 | ||
| 26 | -import org.onosproject.yangutils.utils.UtilConstants; | 26 | +import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
| 27 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 28 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
| 29 | +import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE; | ||
| 30 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 31 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
| 32 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 33 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | ||
| 34 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg; | ||
| 35 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath; | ||
| 36 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories; | ||
| 27 | 37 | ||
| 28 | /** | 38 | /** |
| 29 | * Utility to handle file system operations. | 39 | * Utility to handle file system operations. |
| ... | @@ -44,8 +54,8 @@ public final class FileSystemUtil { | ... | @@ -44,8 +54,8 @@ public final class FileSystemUtil { |
| 44 | */ | 54 | */ |
| 45 | public static boolean doesPackageExist(String pkg) { | 55 | public static boolean doesPackageExist(String pkg) { |
| 46 | 56 | ||
| 47 | - File pkgDir = new File(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | 57 | + File pkgDir = new File(convertPkgToPath(pkg)); |
| 48 | - File pkgWithFile = new File(pkgDir + File.separator + "package-info.java"); | 58 | + File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); |
| 49 | if (pkgDir.exists() && pkgWithFile.isFile()) { | 59 | if (pkgDir.exists() && pkgWithFile.isFile()) { |
| 50 | return true; | 60 | return true; |
| 51 | } | 61 | } |
| ... | @@ -63,8 +73,8 @@ public final class FileSystemUtil { | ... | @@ -63,8 +73,8 @@ public final class FileSystemUtil { |
| 63 | 73 | ||
| 64 | if (!doesPackageExist(pkg)) { | 74 | if (!doesPackageExist(pkg)) { |
| 65 | try { | 75 | try { |
| 66 | - File pack = YangIoUtils.createDirectories(pkg); | 76 | + File pack = createDirectories(pkg); |
| 67 | - YangIoUtils.addPackageInfo(pack, pkgInfo, pkg.replace(UtilConstants.SLASH, UtilConstants.PERIOD)); | 77 | + addPackageInfo(pack, pkgInfo, convertPathToPkg(pkg)); |
| 68 | } catch (IOException e) { | 78 | } catch (IOException e) { |
| 69 | throw new IOException("failed to create package-info file"); | 79 | throw new IOException("failed to create package-info file"); |
| 70 | } | 80 | } |
| ... | @@ -83,9 +93,7 @@ public final class FileSystemUtil { | ... | @@ -83,9 +93,7 @@ public final class FileSystemUtil { |
| 83 | */ | 93 | */ |
| 84 | public static void appendFileContents(File toAppend, File srcFile) throws IOException { | 94 | public static void appendFileContents(File toAppend, File srcFile) throws IOException { |
| 85 | 95 | ||
| 86 | - updateFileHandle(srcFile, | 96 | + updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false); |
| 87 | - UtilConstants.NEW_LINE + readAppendFile(toAppend.toString(), UtilConstants.FOUR_SPACE_INDENTATION), | ||
| 88 | - false); | ||
| 89 | return; | 97 | return; |
| 90 | } | 98 | } |
| 91 | 99 | ||
| ... | @@ -106,15 +114,14 @@ public final class FileSystemUtil { | ... | @@ -106,15 +114,14 @@ public final class FileSystemUtil { |
| 106 | String line = bufferReader.readLine(); | 114 | String line = bufferReader.readLine(); |
| 107 | 115 | ||
| 108 | while (line != null) { | 116 | while (line != null) { |
| 109 | - if (line.equals(UtilConstants.SPACE) | line.equals(UtilConstants.EMPTY_STRING) | 117 | + if (line.equals(SPACE) | line.equals(EMPTY_STRING) | line.equals(EIGHT_SPACE_INDENTATION) |
| 110 | - | line.equals(UtilConstants.EIGHT_SPACE_INDENTATION) | 118 | + | line.equals(MULTIPLE_NEW_LINE)) { |
| 111 | - | line.equals(UtilConstants.MULTIPLE_NEW_LINE)) { | 119 | + stringBuilder.append(NEW_LINE); |
| 112 | - stringBuilder.append(UtilConstants.NEW_LINE); | 120 | + } else if (line.equals(FOUR_SPACE_INDENTATION)) { |
| 113 | - } else if (line.equals(UtilConstants.FOUR_SPACE_INDENTATION)) { | 121 | + stringBuilder.append(EMPTY_STRING); |
| 114 | - stringBuilder.append(UtilConstants.EMPTY_STRING); | ||
| 115 | } else { | 122 | } else { |
| 116 | stringBuilder.append(spaces + line); | 123 | stringBuilder.append(spaces + line); |
| 117 | - stringBuilder.append(UtilConstants.NEW_LINE); | 124 | + stringBuilder.append(NEW_LINE); |
| 118 | } | 125 | } |
| 119 | line = bufferReader.readLine(); | 126 | line = bufferReader.readLine(); |
| 120 | } | 127 | } |
| ... | @@ -131,9 +138,8 @@ public final class FileSystemUtil { | ... | @@ -131,9 +138,8 @@ public final class FileSystemUtil { |
| 131 | * @param inputFile input file | 138 | * @param inputFile input file |
| 132 | * @param contentTobeAdded content to be appended to the file | 139 | * @param contentTobeAdded content to be appended to the file |
| 133 | * @param isClose when close of file is called. | 140 | * @param isClose when close of file is called. |
| 134 | - * @throws IOException if the named file exists but is a directory rather | 141 | + * @throws IOException if the named file exists but is a directory rather than a regular file, |
| 135 | - * than a regular file, does not exist but cannot be created, or | 142 | + * does not exist but cannot be created, or cannot be opened for any other reason |
| 136 | - * cannot be opened for any other reason | ||
| 137 | */ | 143 | */ |
| 138 | public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { | 144 | public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException { |
| 139 | 145 | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -23,10 +23,13 @@ import java.util.List; | ... | @@ -23,10 +23,13 @@ import java.util.List; |
| 23 | import java.util.Stack; | 23 | import java.util.Stack; |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | - * Provides the IO services for Yangutils-maven-Plugin. | 26 | + * Provides utility for searching the files in a directory. |
| 27 | */ | 27 | */ |
| 28 | public final class YangFileScanner { | 28 | public final class YangFileScanner { |
| 29 | 29 | ||
| 30 | + private static final String JAVA_FILE_EXTENTION = ".java"; | ||
| 31 | + private static final String YANG_FILE_EXTENTION = ".yang"; | ||
| 32 | + | ||
| 30 | /** | 33 | /** |
| 31 | * Default constructor. | 34 | * Default constructor. |
| 32 | */ | 35 | */ |
| ... | @@ -44,7 +47,7 @@ public final class YangFileScanner { | ... | @@ -44,7 +47,7 @@ public final class YangFileScanner { |
| 44 | */ | 47 | */ |
| 45 | public static List<String> getJavaFiles(String root) throws NullPointerException, IOException { | 48 | public static List<String> getJavaFiles(String root) throws NullPointerException, IOException { |
| 46 | 49 | ||
| 47 | - return getFiles(root, ".java"); | 50 | + return getFiles(root, JAVA_FILE_EXTENTION); |
| 48 | } | 51 | } |
| 49 | 52 | ||
| 50 | /** | 53 | /** |
| ... | @@ -58,7 +61,7 @@ public final class YangFileScanner { | ... | @@ -58,7 +61,7 @@ public final class YangFileScanner { |
| 58 | */ | 61 | */ |
| 59 | public static List<String> getYangFiles(String root) throws NullPointerException, IOException { | 62 | public static List<String> getYangFiles(String root) throws NullPointerException, IOException { |
| 60 | 63 | ||
| 61 | - return getFiles(root, ".yang"); | 64 | + return getFiles(root, YANG_FILE_EXTENTION); |
| 62 | } | 65 | } |
| 63 | 66 | ||
| 64 | /** | 67 | /** |
| ... | @@ -68,8 +71,7 @@ public final class YangFileScanner { | ... | @@ -68,8 +71,7 @@ public final class YangFileScanner { |
| 68 | * @param extension file extension | 71 | * @param extension file extension |
| 69 | * @return list of required files | 72 | * @return list of required files |
| 70 | * @throws NullPointerException when no file is there | 73 | * @throws NullPointerException when no file is there |
| 71 | - * @throws IOException when files get deleted while performing the | 74 | + * @throws IOException when files get deleted while performing the operations |
| 72 | - * operations | ||
| 73 | */ | 75 | */ |
| 74 | public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { | 76 | public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException { |
| 75 | 77 | ... | ... |
| ... | @@ -25,13 +25,27 @@ import java.nio.file.StandardCopyOption; | ... | @@ -25,13 +25,27 @@ import java.nio.file.StandardCopyOption; |
| 25 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
| 26 | import java.util.List; | 26 | import java.util.List; |
| 27 | 27 | ||
| 28 | -import org.apache.commons.io.FileUtils; | ||
| 29 | import org.apache.maven.model.Resource; | 28 | import org.apache.maven.model.Resource; |
| 30 | import org.apache.maven.project.MavenProject; | 29 | import org.apache.maven.project.MavenProject; |
| 31 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
| 32 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
| 33 | import org.sonatype.plexus.build.incremental.BuildContext; | 31 | import org.sonatype.plexus.build.incremental.BuildContext; |
| 34 | 32 | ||
| 33 | +import static org.apache.commons.io.FileUtils.deleteDirectory; | ||
| 34 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
| 35 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 36 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 37 | +import static org.onosproject.yangutils.utils.UtilConstants.ORG; | ||
| 38 | +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | ||
| 39 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 40 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
| 41 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
| 42 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 43 | +import static org.onosproject.yangutils.utils.UtilConstants.TEMP; | ||
| 44 | +import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; | ||
| 45 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES; | ||
| 46 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; | ||
| 47 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | ||
| 48 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; | ||
| 35 | import static org.slf4j.LoggerFactory.getLogger; | 49 | import static org.slf4j.LoggerFactory.getLogger; |
| 36 | 50 | ||
| 37 | /** | 51 | /** |
| ... | @@ -40,8 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -40,8 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 40 | public final class YangIoUtils { | 54 | public final class YangIoUtils { |
| 41 | 55 | ||
| 42 | private static final Logger log = getLogger(YangIoUtils.class); | 56 | private static final Logger log = getLogger(YangIoUtils.class); |
| 43 | - private static final String TARGET_RESOURCE_PATH = UtilConstants.SLASH + UtilConstants.TEMP + UtilConstants.SLASH | 57 | + private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH; |
| 44 | - + UtilConstants.YANG_RESOURCES + UtilConstants.SLASH; | ||
| 45 | 58 | ||
| 46 | /** | 59 | /** |
| 47 | * Default constructor. | 60 | * Default constructor. |
| ... | @@ -72,22 +85,24 @@ public final class YangIoUtils { | ... | @@ -72,22 +85,24 @@ public final class YangIoUtils { |
| 72 | */ | 85 | */ |
| 73 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { | 86 | public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { |
| 74 | 87 | ||
| 75 | - if (pack.contains(UtilConstants.ORG)) { | 88 | + if (pack.contains(ORG)) { |
| 76 | - String[] strArray = pack.split(UtilConstants.ORG); | 89 | + String[] strArray = pack.split(ORG); |
| 77 | - pack = UtilConstants.ORG + strArray[1]; | 90 | + pack = ORG + strArray[1]; |
| 78 | } | 91 | } |
| 79 | try { | 92 | try { |
| 80 | 93 | ||
| 81 | - File packageInfo = new File(path + File.separator + "package-info.java"); | 94 | + File packageInfo = new File(path + SLASH + "package-info.java"); |
| 82 | packageInfo.createNewFile(); | 95 | packageInfo.createNewFile(); |
| 83 | - FileWriter fileWriter = null; | 96 | + |
| 84 | - BufferedWriter bufferedWriter = null; | 97 | + FileWriter fileWriter = new FileWriter(packageInfo); |
| 85 | - fileWriter = new FileWriter(packageInfo); | 98 | + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); |
| 86 | - bufferedWriter = new BufferedWriter(fileWriter); | 99 | + |
| 87 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); | 100 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); |
| 88 | - bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo, false)); | 101 | + bufferedWriter.write(JavaDocGen.getJavaDoc(PACKAGE_INFO, classInfo, false)); |
| 89 | - bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN); | 102 | + bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); |
| 103 | + | ||
| 90 | bufferedWriter.close(); | 104 | bufferedWriter.close(); |
| 105 | + fileWriter.close(); | ||
| 91 | } catch (IOException e) { | 106 | } catch (IOException e) { |
| 92 | throw new IOException("Exception occured while creating package info file."); | 107 | throw new IOException("Exception occured while creating package info file."); |
| 93 | } | 108 | } |
| ... | @@ -97,15 +112,16 @@ public final class YangIoUtils { | ... | @@ -97,15 +112,16 @@ public final class YangIoUtils { |
| 97 | * Cleans the generated directory if already exist in source folder. | 112 | * Cleans the generated directory if already exist in source folder. |
| 98 | * | 113 | * |
| 99 | * @param dir generated directory in previous build | 114 | * @param dir generated directory in previous build |
| 115 | + * @throws IOException when failed to delete directory | ||
| 100 | */ | 116 | */ |
| 101 | - public static void clean(String dir) { | 117 | + public static void clean(String dir) throws IOException { |
| 102 | 118 | ||
| 103 | File generatedDirectory = new File(dir); | 119 | File generatedDirectory = new File(dir); |
| 104 | if (generatedDirectory.exists()) { | 120 | if (generatedDirectory.exists()) { |
| 105 | try { | 121 | try { |
| 106 | - FileUtils.deleteDirectory(generatedDirectory); | 122 | + deleteDirectory(generatedDirectory); |
| 107 | } catch (IOException e) { | 123 | } catch (IOException e) { |
| 108 | - log.info("Failed to delete the generated files in " + generatedDirectory + " directory"); | 124 | + throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory"); |
| 109 | } | 125 | } |
| 110 | } | 126 | } |
| 111 | } | 127 | } |
| ... | @@ -147,18 +163,17 @@ public final class YangIoUtils { | ... | @@ -147,18 +163,17 @@ public final class YangIoUtils { |
| 147 | */ | 163 | */ |
| 148 | public static String partString(String partString) { | 164 | public static String partString(String partString) { |
| 149 | 165 | ||
| 150 | - String[] strArray = partString.split(UtilConstants.COMMA); | 166 | + String[] strArray = partString.split(COMMA); |
| 151 | - String newString = ""; | 167 | + String newString = EMPTY_STRING; |
| 152 | for (int i = 0; i < strArray.length; i++) { | 168 | for (int i = 0; i < strArray.length; i++) { |
| 153 | if (i % 4 != 0 || i == 0) { | 169 | if (i % 4 != 0 || i == 0) { |
| 154 | - newString = newString + strArray[i] + UtilConstants.COMMA; | 170 | + newString = newString + strArray[i] + COMMA; |
| 155 | } else { | 171 | } else { |
| 156 | - newString = newString + UtilConstants.NEW_LINE + UtilConstants.TWELVE_SPACE_INDENTATION | 172 | + newString = newString + NEW_LINE + TWELVE_SPACE_INDENTATION |
| 157 | - + strArray[i] | 173 | + + strArray[i] + COMMA; |
| 158 | - + UtilConstants.COMMA; | ||
| 159 | } | 174 | } |
| 160 | } | 175 | } |
| 161 | - return trimAtLast(newString, UtilConstants.COMMA); | 176 | + return trimAtLast(newString, COMMA); |
| 162 | } | 177 | } |
| 163 | 178 | ||
| 164 | /** | 179 | /** |
| ... | @@ -183,13 +198,13 @@ public final class YangIoUtils { | ... | @@ -183,13 +198,13 @@ public final class YangIoUtils { |
| 183 | public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { | 198 | public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { |
| 184 | 199 | ||
| 185 | if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) { | 200 | if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) { |
| 186 | - pathOfJavaPkg = trimAtLast(pathOfJavaPkg, UtilConstants.SLASH); | 201 | + pathOfJavaPkg = trimAtLast(pathOfJavaPkg, SLASH); |
| 187 | } | 202 | } |
| 188 | - String[] strArray = pathOfJavaPkg.split(UtilConstants.SLASH); | 203 | + String[] strArray = pathOfJavaPkg.split(SLASH); |
| 189 | - if (strArray[0].equals(UtilConstants.EMPTY_STRING)) { | 204 | + if (strArray[0].equals(EMPTY_STRING)) { |
| 190 | return pathOfJavaPkg; | 205 | return pathOfJavaPkg; |
| 191 | } else { | 206 | } else { |
| 192 | - return baseCodeGenPath + File.separator + pathOfJavaPkg; | 207 | + return baseCodeGenPath + SLASH + pathOfJavaPkg; |
| 193 | } | 208 | } |
| 194 | } | 209 | } |
| 195 | 210 | ||
| ... | @@ -212,8 +227,7 @@ public final class YangIoUtils { | ... | @@ -212,8 +227,7 @@ public final class YangIoUtils { |
| 212 | * @param yangFiles list of YANG files | 227 | * @param yangFiles list of YANG files |
| 213 | * @param outputDir project's output directory | 228 | * @param outputDir project's output directory |
| 214 | * @param project maven project | 229 | * @param project maven project |
| 215 | - * @throws IOException when fails to copy files to destination resource | 230 | + * @throws IOException when fails to copy files to destination resource directory |
| 216 | - * directory | ||
| 217 | */ | 231 | */ |
| 218 | public static void copyYangFilesToTarget(List<String> yangFiles, String outputDir, MavenProject project) | 232 | public static void copyYangFilesToTarget(List<String> yangFiles, String outputDir, MavenProject project) |
| 219 | throws IOException { | 233 | throws IOException { |
| ... | @@ -226,11 +240,11 @@ public final class YangIoUtils { | ... | @@ -226,11 +240,11 @@ public final class YangIoUtils { |
| 226 | 240 | ||
| 227 | for (File file : files) { | 241 | for (File file : files) { |
| 228 | Files.copy(file.toPath(), | 242 | Files.copy(file.toPath(), |
| 229 | - new File(path + file.getName()).toPath(), | 243 | + (new File(path + file.getName())).toPath(), |
| 230 | StandardCopyOption.REPLACE_EXISTING); | 244 | StandardCopyOption.REPLACE_EXISTING); |
| 231 | } | 245 | } |
| 232 | Resource rsc = new Resource(); | 246 | Resource rsc = new Resource(); |
| 233 | - rsc.setDirectory(outputDir + UtilConstants.SLASH + UtilConstants.TEMP + UtilConstants.SLASH); | 247 | + rsc.setDirectory(outputDir + SLASH + TEMP + SLASH); |
| 234 | project.addResource(rsc); | 248 | project.addResource(rsc); |
| 235 | } | 249 | } |
| 236 | 250 | ||
| ... | @@ -248,4 +262,58 @@ public final class YangIoUtils { | ... | @@ -248,4 +262,58 @@ public final class YangIoUtils { |
| 248 | } | 262 | } |
| 249 | return files; | 263 | return files; |
| 250 | } | 264 | } |
| 265 | + | ||
| 266 | + /** | ||
| 267 | + * Merge the temp java files to main java files. | ||
| 268 | + * | ||
| 269 | + * @param appendFile temp file | ||
| 270 | + * @param srcFile main file | ||
| 271 | + * @throws IOException when fails to append contents | ||
| 272 | + */ | ||
| 273 | + public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException { | ||
| 274 | + | ||
| 275 | + try { | ||
| 276 | + appendFileContents(appendFile, srcFile); | ||
| 277 | + } catch (IOException e) { | ||
| 278 | + throw new IOException("Failed to append " + appendFile + " in " + srcFile); | ||
| 279 | + } | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + /** | ||
| 283 | + * Insert data in the generated file. | ||
| 284 | + * | ||
| 285 | + * @param file file in which need to be inserted | ||
| 286 | + * @param data data which need to be inserted | ||
| 287 | + * @throws IOException when fails to insert into file | ||
| 288 | + */ | ||
| 289 | + public static void insertDataIntoJavaFile(File file, String data) throws IOException { | ||
| 290 | + | ||
| 291 | + try { | ||
| 292 | + updateFileHandle(file, data, false); | ||
| 293 | + } catch (IOException e) { | ||
| 294 | + throw new IOException("Failed to insert in " + file + "file"); | ||
| 295 | + } | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + /** | ||
| 299 | + * Convert directory path in java package format. | ||
| 300 | + * | ||
| 301 | + * @param path directory path | ||
| 302 | + * @return java package | ||
| 303 | + */ | ||
| 304 | + public static String convertPathToPkg(String path) { | ||
| 305 | + | ||
| 306 | + return path.replace(SLASH, PERIOD); | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * Convert java package in directory path format. | ||
| 311 | + * | ||
| 312 | + * @param pkg java package | ||
| 313 | + * @return directory path | ||
| 314 | + */ | ||
| 315 | + public static String convertPkgToPath(String pkg) { | ||
| 316 | + | ||
| 317 | + return pkg.replace(PERIOD, SLASH); | ||
| 318 | + } | ||
| 251 | } | 319 | } | ... | ... |
| ... | @@ -16,18 +16,36 @@ | ... | @@ -16,18 +16,36 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | 18 | ||
| 19 | -import static org.hamcrest.MatcherAssert.assertThat; | ||
| 20 | -import static org.hamcrest.core.Is.is; | ||
| 21 | -import static org.junit.Assert.assertNotNull; | ||
| 22 | - | ||
| 23 | import java.lang.reflect.Constructor; | 19 | import java.lang.reflect.Constructor; |
| 24 | import java.lang.reflect.InvocationTargetException; | 20 | import java.lang.reflect.InvocationTargetException; |
| 25 | 21 | ||
| 26 | import org.junit.Test; | 22 | import org.junit.Test; |
| 27 | -import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType; | ||
| 28 | -import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; | ||
| 29 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 23 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
| 30 | -import org.onosproject.yangutils.utils.UtilConstants; | 24 | + |
| 25 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 26 | +import static org.hamcrest.core.Is.is; | ||
| 27 | +import static org.junit.Assert.assertNotNull; | ||
| 28 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | ||
| 29 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText; | ||
| 30 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | ||
| 31 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | ||
| 32 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | ||
| 33 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute; | ||
| 34 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | ||
| 35 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | ||
| 36 | +import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | ||
| 37 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
| 38 | +import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
| 39 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
| 40 | +import static org.onosproject.yangutils.utils.UtilConstants.LIST; | ||
| 41 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 42 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
| 43 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 44 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
| 45 | +import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
| 46 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
| 47 | +import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 48 | +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ||
| 31 | 49 | ||
| 32 | /** | 50 | /** |
| 33 | * Unit test cases for java code snippet generator. | 51 | * Unit test cases for java code snippet generator. |
| ... | @@ -36,10 +54,8 @@ public class JavaCodeSnippetGenTest { | ... | @@ -36,10 +54,8 @@ public class JavaCodeSnippetGenTest { |
| 36 | 54 | ||
| 37 | private static final String PKG_INFO = "org.onosproject.unittest"; | 55 | private static final String PKG_INFO = "org.onosproject.unittest"; |
| 38 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; | 56 | private static final String CLASS_INFO = "JavaCodeSnippetGenTest"; |
| 39 | - private static final int FILE_GEN_TYPE = GeneratedJavaFileType.INTERFACE_MASK; | 57 | + private static final int FILE_GEN_TYPE = INTERFACE_MASK; |
| 40 | - private static final GeneratedMethodTypes METHOD_GEN_TYPE = GeneratedMethodTypes.GETTER; | ||
| 41 | private static final String YANG_NAME = "Test"; | 58 | private static final String YANG_NAME = "Test"; |
| 42 | - private static final String STRING = "String"; | ||
| 43 | 59 | ||
| 44 | /** | 60 | /** |
| 45 | * Unit test for private constructor. | 61 | * Unit test for private constructor. |
| ... | @@ -54,6 +70,7 @@ public class JavaCodeSnippetGenTest { | ... | @@ -54,6 +70,7 @@ public class JavaCodeSnippetGenTest { |
| 54 | @Test | 70 | @Test |
| 55 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 71 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 56 | InstantiationException, IllegalAccessException, InvocationTargetException { | 72 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 73 | + | ||
| 57 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; | 74 | Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class }; |
| 58 | for (Class<?> clazz : classesToConstruct) { | 75 | for (Class<?> clazz : classesToConstruct) { |
| 59 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 76 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| ... | @@ -67,14 +84,14 @@ public class JavaCodeSnippetGenTest { | ... | @@ -67,14 +84,14 @@ public class JavaCodeSnippetGenTest { |
| 67 | */ | 84 | */ |
| 68 | @Test | 85 | @Test |
| 69 | public void testForImportText() { | 86 | public void testForImportText() { |
| 87 | + | ||
| 70 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); | 88 | JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); |
| 71 | importInfo.setPkgInfo(PKG_INFO); | 89 | importInfo.setPkgInfo(PKG_INFO); |
| 72 | importInfo.setClassInfo(CLASS_INFO); | 90 | importInfo.setClassInfo(CLASS_INFO); |
| 73 | 91 | ||
| 74 | - String imports = JavaCodeSnippetGen.getImportText(importInfo); | 92 | + String imports = getImportText(importInfo); |
| 75 | 93 | ||
| 76 | - assertThat(true, is(imports.equals(UtilConstants.IMPORT + PKG_INFO + UtilConstants.PERIOD + CLASS_INFO | 94 | + assertThat(true, is(imports.equals(IMPORT + PKG_INFO + PERIOD + CLASS_INFO + SEMI_COLAN + NEW_LINE))); |
| 77 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
| 78 | } | 95 | } |
| 79 | 96 | ||
| 80 | /** | 97 | /** |
| ... | @@ -82,11 +99,10 @@ public class JavaCodeSnippetGenTest { | ... | @@ -82,11 +99,10 @@ public class JavaCodeSnippetGenTest { |
| 82 | */ | 99 | */ |
| 83 | @Test | 100 | @Test |
| 84 | public void testForJavaClassDefStart() { | 101 | public void testForJavaClassDefStart() { |
| 85 | - String classDef = JavaCodeSnippetGen.getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); | 102 | + |
| 86 | - assertThat(true, | 103 | + String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME); |
| 87 | - is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE | 104 | + assertThat(true, is(classDef |
| 88 | - + UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET | 105 | + .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); |
| 89 | - + UtilConstants.NEW_LINE))); | ||
| 90 | 106 | ||
| 91 | } | 107 | } |
| 92 | 108 | ||
| ... | @@ -95,36 +111,20 @@ public class JavaCodeSnippetGenTest { | ... | @@ -95,36 +111,20 @@ public class JavaCodeSnippetGenTest { |
| 95 | */ | 111 | */ |
| 96 | @Test | 112 | @Test |
| 97 | public void testForListAttribute() { | 113 | public void testForListAttribute() { |
| 98 | - String listAttribute = JavaCodeSnippetGen.getListAttribute(STRING); | ||
| 99 | - assertThat(true, is(listAttribute.equals(UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + STRING | ||
| 100 | - + UtilConstants.DIAMOND_CLOSE_BRACKET))); | ||
| 101 | - } | ||
| 102 | 114 | ||
| 103 | - /** | 115 | + String listAttribute = getListAttribute(STRING_DATA_TYPE); |
| 104 | - * Unit test case for java class interface definition close. | 116 | + assertThat(true, |
| 105 | - */ | 117 | + is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET))); |
| 106 | - @Test | ||
| 107 | - public void testForJavaClassDefInterfaceClose() { | ||
| 108 | - String interfaceDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
| 109 | - assertThat(true, is(interfaceDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
| 110 | } | 118 | } |
| 111 | 119 | ||
| 112 | /** | 120 | /** |
| 113 | - * Unit test case for java class builder class definition close. | 121 | + * Unit test case for java class interface definition close. |
| 114 | */ | 122 | */ |
| 115 | @Test | 123 | @Test |
| 116 | - public void testForJavaClassDefBuilderClassClose() { | 124 | + public void testForJavaClassDefClose() { |
| 117 | - String builderClassDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
| 118 | - assertThat(true, is(builderClassDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
| 119 | - } | ||
| 120 | 125 | ||
| 121 | - /** | 126 | + String interfaceDef = getJavaClassDefClose(); |
| 122 | - * Unit test case for java class typedef definition close. | 127 | + assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET))); |
| 123 | - */ | ||
| 124 | - @Test | ||
| 125 | - public void testForJavaClassDefTypeDefClose() { | ||
| 126 | - String typeDef = JavaCodeSnippetGen.getJavaClassDefClose(); | ||
| 127 | - assertThat(true, is(typeDef.equals(UtilConstants.CLOSE_CURLY_BRACKET))); | ||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /** | 130 | /** |
| ... | @@ -133,30 +133,22 @@ public class JavaCodeSnippetGenTest { | ... | @@ -133,30 +133,22 @@ public class JavaCodeSnippetGenTest { |
| 133 | @Test | 133 | @Test |
| 134 | public void testForJavaAttributeInfo() { | 134 | public void testForJavaAttributeInfo() { |
| 135 | 135 | ||
| 136 | - String attributeWithoutTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, UtilConstants.STRING, | 136 | + String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, false); |
| 137 | - YANG_NAME, false); | 137 | + assertThat(true, is(attributeWithoutTypePkg.equals( |
| 138 | - assertThat(true, | 138 | + PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
| 139 | - is(attributeWithoutTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.STRING | 139 | + |
| 140 | - + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | 140 | + String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, false); |
| 141 | - String attributeWithTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination( | 141 | + assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD |
| 142 | - UtilConstants.JAVA_LANG, UtilConstants.STRING, YANG_NAME, false); | 142 | + + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
| 143 | - assertThat(true, is(attributeWithTypePkg | 143 | + |
| 144 | - .equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.JAVA_LANG + UtilConstants.PERIOD | 144 | + String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME, true); |
| 145 | - + UtilConstants.STRING + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN | 145 | + assertThat(true, is(attributeWithListPkg.equals( |
| 146 | - + UtilConstants.NEW_LINE))); | 146 | + PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE |
| 147 | - String attributeWithListPkg = JavaCodeSnippetGen.getJavaAttributeDefination( | 147 | + + DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
| 148 | - UtilConstants.JAVA_LANG, UtilConstants.STRING, YANG_NAME, true); | 148 | + |
| 149 | - assertThat(true, | 149 | + String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME, true); |
| 150 | - is(attributeWithListPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST | 150 | + assertThat(true, is(attributeWithListWithoutPkg.equals( |
| 151 | - + UtilConstants.DIAMOND_OPEN_BRACKET + UtilConstants.JAVA_LANG + UtilConstants.PERIOD | 151 | + PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE |
| 152 | - + UtilConstants.STRING + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME | 152 | + + YANG_NAME + SEMI_COLAN + NEW_LINE))); |
| 153 | - + UtilConstants.SUFIX_S + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
| 154 | - String attributeWithListWithoutPkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, UtilConstants.STRING, | ||
| 155 | - YANG_NAME, true); | ||
| 156 | - assertThat(true, | ||
| 157 | - is(attributeWithListWithoutPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST | ||
| 158 | - + UtilConstants.DIAMOND_OPEN_BRACKET + UtilConstants.STRING | ||
| 159 | - + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME + UtilConstants.SUFIX_S | ||
| 160 | - + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE))); | ||
| 161 | } | 153 | } |
| 162 | } | 154 | } | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2016 Open Networking Laboratory | ||
| 3 | - * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | - * you may not use this file except in compliance with the License. | ||
| 6 | - * You may obtain a copy of the License at | ||
| 7 | - * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | - * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | - * See the License for the specific language governing permissions and | ||
| 14 | - * limitations under the License. | ||
| 15 | - */ | ||
| 16 | - | ||
| 17 | -package org.onosproject.yangutils.translator.tojava.utils; | ||
| 18 | - | ||
| 19 | -import java.lang.reflect.Constructor; | ||
| 20 | -import java.lang.reflect.InvocationTargetException; | ||
| 21 | - | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onosproject.yangutils.datamodel.YangType; | ||
| 24 | -import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | ||
| 25 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
| 26 | - | ||
| 27 | -import static org.hamcrest.core.Is.is; | ||
| 28 | -import static org.junit.Assert.assertNotNull; | ||
| 29 | -import static org.junit.Assert.assertThat; | ||
| 30 | - | ||
| 31 | -/** | ||
| 32 | - * Unit tests for generated methods from the file type. | ||
| 33 | - */ | ||
| 34 | -public final class MethodsGeneratorTest { | ||
| 35 | - | ||
| 36 | - public static JavaAttributeInfo testAttr; | ||
| 37 | - public static YangType<?> attrType = new YangType<>(); | ||
| 38 | - | ||
| 39 | - /** | ||
| 40 | - * Unit test for private constructor. | ||
| 41 | - * | ||
| 42 | - * @throws SecurityException if any security violation is observed | ||
| 43 | - * @throws NoSuchMethodException if when the method is not found | ||
| 44 | - * @throws IllegalArgumentException if there is illegal argument found | ||
| 45 | - * @throws InstantiationException if instantiation is provoked for the | ||
| 46 | - * private constructor | ||
| 47 | - * @throws IllegalAccessException if instance is provoked or a method is | ||
| 48 | - * provoked | ||
| 49 | - * @throws InvocationTargetException when an exception occurs by the method | ||
| 50 | - * or constructor | ||
| 51 | - */ | ||
| 52 | - @Test | ||
| 53 | - public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
| 54 | - InstantiationException, IllegalAccessException, InvocationTargetException { | ||
| 55 | - | ||
| 56 | - Class<?>[] classesToConstruct = { | ||
| 57 | - MethodsGenerator.class | ||
| 58 | - }; | ||
| 59 | - for (Class<?> clazz : classesToConstruct) { | ||
| 60 | - Constructor<?> constructor = clazz.getDeclaredConstructor(); | ||
| 61 | - constructor.setAccessible(true); | ||
| 62 | - assertNotNull(constructor.newInstance()); | ||
| 63 | - } | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - // /** | ||
| 67 | - // * Unit test case for checking the parse builder and typedef constructor. | ||
| 68 | - // */ | ||
| 69 | - // @Test | ||
| 70 | - // public void getParseBuilderInterfaceMethodConstructorTest() { | ||
| 71 | - // | ||
| 72 | - // JavaQualifiedTypeInfo forSetter = new JavaQualifiedTypeInfo(); | ||
| 73 | - // attrType.setDataTypeName("binary"); | ||
| 74 | - // attrType.getDataTypeName(); | ||
| 75 | - // attrType.setDataType(YangDataTypes.BINARY); | ||
| 76 | - // attrType.getDataType(); | ||
| 77 | - // testAttr.setAttributeName("attributeTest"); | ||
| 78 | - // testAttr.setAttributeType(attrType); | ||
| 79 | - // forSetter.setPkgInfo("test1/test3"); | ||
| 80 | - // forSetter.setClassInfo("This class contains"); | ||
| 81 | - // testAttr.setImportInfo(forSetter); | ||
| 82 | - // String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname"); | ||
| 83 | - // } | ||
| 84 | - | ||
| 85 | - /** | ||
| 86 | - * Unit test case for checking the values received from constructor, default | ||
| 87 | - * constructor and build string formation. | ||
| 88 | - */ | ||
| 89 | - @Test | ||
| 90 | - public void getValuesTest() { | ||
| 91 | - | ||
| 92 | - String stringConstructor = MethodsGenerator.getConstructorString("testname"); | ||
| 93 | - assertThat(stringConstructor.contains(UtilConstants.JAVA_DOC_CONSTRUCTOR) | ||
| 94 | - && stringConstructor.contains(UtilConstants.JAVA_DOC_PARAM) | ||
| 95 | - && stringConstructor.contains(UtilConstants.BUILDER_OBJECT), is(true)); | ||
| 96 | - String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString("testnameBuilder", "public"); | ||
| 97 | - assertThat(stringDefaultConstructor.contains(UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR) | ||
| 98 | - && stringDefaultConstructor.contains(UtilConstants.BUILDER) | ||
| 99 | - && stringDefaultConstructor.contains("testname"), is(true)); | ||
| 100 | - String stringBuild = MethodsGenerator.getBuildString("testname"); | ||
| 101 | - assertThat(stringBuild.contains(UtilConstants.OVERRIDE) && stringBuild.contains(UtilConstants.BUILD) | ||
| 102 | - && stringBuild.contains(UtilConstants.RETURN), is(true)); | ||
| 103 | - | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - /** | ||
| 107 | - * Unit test for checking the values received for class getter, class and | ||
| 108 | - * typedef setters with list data type. | ||
| 109 | - */ | ||
| 110 | - // @Test | ||
| 111 | - // public void getGetterSetterTest() { | ||
| 112 | - // | ||
| 113 | - // JavaQualifiedTypeInfo forGetterSetter = new JavaQualifiedTypeInfo(); | ||
| 114 | - // attrType.setDataTypeName("int"); | ||
| 115 | - // attrType.getDataTypeName(); | ||
| 116 | - // attrType.setDataType(YangDataTypes.UINT8); | ||
| 117 | - // attrType.getDataType(); | ||
| 118 | - // testAttr.setAttributeName("AttributeTest1"); | ||
| 119 | - // testAttr.setAttributeType(attrType); | ||
| 120 | - // forGetterSetter.setPkgInfo("null"); | ||
| 121 | - // forGetterSetter.setClassInfo("This class contains"); | ||
| 122 | - // testAttr.setImportInfo(forGetterSetter); | ||
| 123 | - // testAttr.setListAttr(true); | ||
| 124 | - // String getterForClass = MethodsGenerator.getGetterForClass(testAttr); | ||
| 125 | - // assertThat(getterForClass.contains(UtilConstants.GET_METHOD_PREFIX) && getterForClass.contains("List<") | ||
| 126 | - // && getterForClass.contains("attributeTest1"), is(true)); | ||
| 127 | - // String setterForClass = MethodsGenerator.getSetterForClass(testAttr, "TestThis"); | ||
| 128 | - // assertThat(setterForClass.contains(UtilConstants.SET_METHOD_PREFIX) && setterForClass.contains("List<") | ||
| 129 | - // && setterForClass.contains("attributeTest1"), is(true)); | ||
| 130 | - // String typeDefSetter = MethodsGenerator.getSetterForTypeDefClass(testAttr); | ||
| 131 | - // assertThat(typeDefSetter.contains(UtilConstants.SET_METHOD_PREFIX) && typeDefSetter.contains("List<") | ||
| 132 | - // && typeDefSetter.contains("attributeTest1") && typeDefSetter.contains("this."), is(true)); | ||
| 133 | - // } | ||
| 134 | - | ||
| 135 | - /** | ||
| 136 | - * Unit test case for checking the parse builder and typedef constructor | ||
| 137 | - * with list data type. | ||
| 138 | - */ | ||
| 139 | - // @Test | ||
| 140 | - // public void getConstructorWithListTypeTest() { | ||
| 141 | - // | ||
| 142 | - // JavaQualifiedTypeInfo forSetter = new JavaQualifiedTypeInfo(); | ||
| 143 | - // attrType.setDataTypeName("binary"); | ||
| 144 | - // attrType.getDataTypeName(); | ||
| 145 | - // attrType.setDataType(YangDataTypes.BINARY); | ||
| 146 | - // attrType.getDataType(); | ||
| 147 | - // testAttr.setAttributeName("attributeTest"); | ||
| 148 | - // testAttr.setAttributeType(attrType); | ||
| 149 | - // forSetter.setPkgInfo("null"); | ||
| 150 | - // forSetter.setClassInfo("This class contains"); | ||
| 151 | - // testAttr.setImportInfo(forSetter); | ||
| 152 | - // testAttr.setListAttr(true); | ||
| 153 | - // String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname"); | ||
| 154 | - // assertThat(stringTypeDef.contains("(List<") && stringTypeDef.contains("Testname") | ||
| 155 | - // && stringTypeDef.contains(UtilConstants.THIS), is(true)); | ||
| 156 | - // } | ||
| 157 | -} |
| ... | @@ -21,9 +21,7 @@ import java.io.IOException; | ... | @@ -21,9 +21,7 @@ import java.io.IOException; |
| 21 | import java.lang.reflect.Constructor; | 21 | import java.lang.reflect.Constructor; |
| 22 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
| 23 | 23 | ||
| 24 | -import org.junit.Rule; | ||
| 25 | import org.junit.Test; | 24 | import org.junit.Test; |
| 26 | -import org.junit.rules.ExpectedException; | ||
| 27 | import org.onosproject.yangutils.utils.UtilConstants; | 25 | import org.onosproject.yangutils.utils.UtilConstants; |
| 28 | 26 | ||
| 29 | import static org.junit.Assert.assertNotNull; | 27 | import static org.junit.Assert.assertNotNull; |
| ... | @@ -34,12 +32,12 @@ import static org.junit.Assert.assertTrue; | ... | @@ -34,12 +32,12 @@ import static org.junit.Assert.assertTrue; |
| 34 | */ | 32 | */ |
| 35 | public final class FileSystemUtilTest { | 33 | public final class FileSystemUtilTest { |
| 36 | 34 | ||
| 37 | - public static final String BASE_DIR_PKG = "target.UnitTestCase."; | 35 | + private static final String BASE_DIR_PKG = "target.UnitTestCase."; |
| 38 | - public static final String PKG_INFO_CONTENT = "testGeneration6"; | 36 | + private static final String PKG_INFO_CONTENT = "testGeneration6"; |
| 39 | - public static final String BASE_PKG = "target/UnitTestCase"; | 37 | + private static final String BASE_PKG = "target/UnitTestCase"; |
| 40 | - | 38 | + private static final String TEST_DATA_1 = "This is to append a text to the file first1\n"; |
| 41 | - @Rule | 39 | + private static final String TEST_DATA_2 = "This is next second line\n"; |
| 42 | - public ExpectedException thrown = ExpectedException.none(); | 40 | + private static final String TEST_DATA_3 = "This is next third line in the file"; |
| 43 | 41 | ||
| 44 | /** | 42 | /** |
| 45 | * A private constructor is tested. | 43 | * A private constructor is tested. |
| ... | @@ -47,20 +45,15 @@ public final class FileSystemUtilTest { | ... | @@ -47,20 +45,15 @@ public final class FileSystemUtilTest { |
| 47 | * @throws SecurityException if any security violation is observed | 45 | * @throws SecurityException if any security violation is observed |
| 48 | * @throws NoSuchMethodException if when the method is not found | 46 | * @throws NoSuchMethodException if when the method is not found |
| 49 | * @throws IllegalArgumentException if there is illegal argument found | 47 | * @throws IllegalArgumentException if there is illegal argument found |
| 50 | - * @throws InstantiationException if instantiation is provoked for the | 48 | + * @throws InstantiationException if instantiation is provoked for the private constructor |
| 51 | - * private constructor | 49 | + * @throws IllegalAccessException if instance is provoked or a method is provoked |
| 52 | - * @throws IllegalAccessException if instance is provoked or a method is | 50 | + * @throws InvocationTargetException when an exception occurs by the method or constructor |
| 53 | - * provoked | ||
| 54 | - * @throws InvocationTargetException when an exception occurs by the method | ||
| 55 | - * or constructor | ||
| 56 | */ | 51 | */ |
| 57 | @Test | 52 | @Test |
| 58 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 53 | public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 59 | InstantiationException, IllegalAccessException, InvocationTargetException { | 54 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 60 | 55 | ||
| 61 | - Class<?>[] classesToConstruct = { | 56 | + Class<?>[] classesToConstruct = {FileSystemUtil.class }; |
| 62 | - FileSystemUtil.class | ||
| 63 | - }; | ||
| 64 | for (Class<?> clazz : classesToConstruct) { | 57 | for (Class<?> clazz : classesToConstruct) { |
| 65 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 58 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 66 | constructor.setAccessible(true); | 59 | constructor.setAccessible(true); |
| ... | @@ -70,6 +63,8 @@ public final class FileSystemUtilTest { | ... | @@ -70,6 +63,8 @@ public final class FileSystemUtilTest { |
| 70 | 63 | ||
| 71 | /** | 64 | /** |
| 72 | * This test case checks the contents to be written in the file. | 65 | * This test case checks the contents to be written in the file. |
| 66 | + * | ||
| 67 | + * @throws IOException when fails to create a test file | ||
| 73 | */ | 68 | */ |
| 74 | @Test | 69 | @Test |
| 75 | public void updateFileHandleTest() throws IOException { | 70 | public void updateFileHandleTest() throws IOException { |
| ... | @@ -80,15 +75,17 @@ public final class FileSystemUtilTest { | ... | @@ -80,15 +75,17 @@ public final class FileSystemUtilTest { |
| 80 | createFile.createNewFile(); | 75 | createFile.createNewFile(); |
| 81 | File createSourceFile = new File(dir + "sourceTestFile"); | 76 | File createSourceFile = new File(dir + "sourceTestFile"); |
| 82 | createSourceFile.createNewFile(); | 77 | createSourceFile.createNewFile(); |
| 83 | - FileSystemUtil.updateFileHandle(createFile, "This is to append a text to the file first1\n", false); | 78 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_1, false); |
| 84 | - FileSystemUtil.updateFileHandle(createFile, "This is next second line\n", false); | 79 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_2, false); |
| 85 | - FileSystemUtil.updateFileHandle(createFile, "This is next third line in the file", false); | 80 | + FileSystemUtil.updateFileHandle(createFile, TEST_DATA_3, false); |
| 86 | FileSystemUtil.appendFileContents(createFile, createSourceFile); | 81 | FileSystemUtil.appendFileContents(createFile, createSourceFile); |
| 87 | FileSystemUtil.updateFileHandle(createFile, null, true); | 82 | FileSystemUtil.updateFileHandle(createFile, null, true); |
| 88 | } | 83 | } |
| 89 | 84 | ||
| 90 | /** | 85 | /** |
| 91 | * This test case checks whether the package is existing. | 86 | * This test case checks whether the package is existing. |
| 87 | + * | ||
| 88 | + * @throws IOException when failed to create a test file | ||
| 92 | */ | 89 | */ |
| 93 | @Test | 90 | @Test |
| 94 | public void packageExistTest() throws IOException { | 91 | public void packageExistTest() throws IOException { |
| ... | @@ -104,21 +101,4 @@ public final class FileSystemUtilTest { | ... | @@ -104,21 +101,4 @@ public final class FileSystemUtilTest { |
| 104 | createDir.delete(); | 101 | createDir.delete(); |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | - /** | ||
| 108 | - * This test case checks the package does not exist. | ||
| 109 | - */ | ||
| 110 | - // @Test | ||
| 111 | - // public void packageNotExistTest() throws IOException { | ||
| 112 | - | ||
| 113 | - // String dirPath = "notexist1.notexist2"; | ||
| 114 | - // String strPath = BASE_DIR_PKG + dirPath; | ||
| 115 | - // File createDir = new File(strPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH)); | ||
| 116 | - // assertFalse(FileSystemUtil.doesPackageExist(strPath)); | ||
| 117 | - // createDir.mkdirs(); | ||
| 118 | - // assertFalse(FileSystemUtil.doesPackageExist(strPath)); | ||
| 119 | - // CopyrightHeader.parseCopyrightHeader(); | ||
| 120 | - // FileSystemUtil.createPackage(strPath, PKG_INFO_CONTENT); | ||
| 121 | - // assertTrue(FileSystemUtil.doesPackageExist(strPath)); | ||
| 122 | - // createDir.delete(); | ||
| 123 | - // } | ||
| 124 | } | 104 | } | ... | ... |
| ... | @@ -62,7 +62,7 @@ public final class JavaDocGenTest { | ... | @@ -62,7 +62,7 @@ public final class JavaDocGenTest { |
| 62 | @Test | 62 | @Test |
| 63 | public void buildGenerationTest() { | 63 | public void buildGenerationTest() { |
| 64 | 64 | ||
| 65 | - String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1", false); | 65 | + String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD_METHOD, "testGeneration1", false); |
| 66 | assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); | 66 | assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n")); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| ... | @@ -117,7 +117,7 @@ public final class JavaDocGenTest { | ... | @@ -117,7 +117,7 @@ public final class JavaDocGenTest { |
| 117 | @Test | 117 | @Test |
| 118 | public void getterGenerationTest() { | 118 | public void getterGenerationTest() { |
| 119 | 119 | ||
| 120 | - String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1", false); | 120 | + String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER_METHOD, "testGeneration1", false); |
| 121 | assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); | 121 | assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n")); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| ... | @@ -157,7 +157,7 @@ public final class JavaDocGenTest { | ... | @@ -157,7 +157,7 @@ public final class JavaDocGenTest { |
| 157 | @Test | 157 | @Test |
| 158 | public void setterGenerationTest() { | 158 | public void setterGenerationTest() { |
| 159 | 159 | ||
| 160 | - String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1", false); | 160 | + String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER_METHOD, "testGeneration1", false); |
| 161 | assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); | 161 | assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n")); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| ... | @@ -167,7 +167,7 @@ public final class JavaDocGenTest { | ... | @@ -167,7 +167,7 @@ public final class JavaDocGenTest { |
| 167 | @Test | 167 | @Test |
| 168 | public void typeDefSetterGenerationTest() { | 168 | public void typeDefSetterGenerationTest() { |
| 169 | 169 | ||
| 170 | - String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, "testGeneration1", false); | 170 | + String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER_METHOD, "testGeneration1", false); |
| 171 | assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); | 171 | assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n")); |
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment