Committed by
Gerrit Code Review
[ONOS-4583] Union defect fix.
Change-Id: Ic31866b9a1b7bd5d8209d5d22f4292ab9c79a118
Showing
36 changed files
with
926 additions
and
179 deletions
| ... | @@ -75,7 +75,7 @@ public class YangXpathLinker<T> { | ... | @@ -75,7 +75,7 @@ public class YangXpathLinker<T> { |
| 75 | * | 75 | * |
| 76 | * @return prefix resolver list | 76 | * @return prefix resolver list |
| 77 | */ | 77 | */ |
| 78 | - public Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() { | 78 | + private Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() { |
| 79 | return prefixResolverTypes; | 79 | return prefixResolverTypes; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| ... | @@ -84,7 +84,7 @@ public class YangXpathLinker<T> { | ... | @@ -84,7 +84,7 @@ public class YangXpathLinker<T> { |
| 84 | * | 84 | * |
| 85 | * @param prefixResolverTypes prefix resolver list. | 85 | * @param prefixResolverTypes prefix resolver list. |
| 86 | */ | 86 | */ |
| 87 | - public void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) { | 87 | + private void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) { |
| 88 | this.prefixResolverTypes = prefixResolverTypes; | 88 | this.prefixResolverTypes = prefixResolverTypes; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| ... | @@ -188,7 +188,7 @@ public class YangXpathLinker<T> { | ... | @@ -188,7 +188,7 @@ public class YangXpathLinker<T> { |
| 188 | * @param leafref instance of YANG leafref | 188 | * @param leafref instance of YANG leafref |
| 189 | * @return linked target node | 189 | * @return linked target node |
| 190 | */ | 190 | */ |
| 191 | - public T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) { | 191 | + T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) { |
| 192 | 192 | ||
| 193 | YangNode targetNode; | 193 | YangNode targetNode; |
| 194 | setRootNode(root); | 194 | setRootNode(root); | ... | ... |
| ... | @@ -17,9 +17,12 @@ | ... | @@ -17,9 +17,12 @@ |
| 17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | +import java.util.Collections; | ||
| 20 | import java.util.HashSet; | 21 | import java.util.HashSet; |
| 22 | +import java.util.LinkedList; | ||
| 21 | import java.util.List; | 23 | import java.util.List; |
| 22 | import java.util.Set; | 24 | import java.util.Set; |
| 25 | + | ||
| 23 | import org.apache.maven.artifact.repository.ArtifactRepository; | 26 | import org.apache.maven.artifact.repository.ArtifactRepository; |
| 24 | import org.apache.maven.plugin.AbstractMojo; | 27 | import org.apache.maven.plugin.AbstractMojo; |
| 25 | import org.apache.maven.plugin.MojoExecutionException; | 28 | import org.apache.maven.plugin.MojoExecutionException; |
| ... | @@ -42,7 +45,6 @@ import org.sonatype.plexus.build.incremental.BuildContext; | ... | @@ -42,7 +45,6 @@ import org.sonatype.plexus.build.incremental.BuildContext; |
| 42 | 45 | ||
| 43 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | 46 | import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; |
| 44 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; | 47 | import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE; |
| 45 | -import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority; | ||
| 46 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot; | 48 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot; |
| 47 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget; | 49 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget; |
| 48 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies; | 50 | import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies; |
| ... | @@ -68,6 +70,7 @@ public class YangUtilManager | ... | @@ -68,6 +70,7 @@ public class YangUtilManager |
| 68 | extends AbstractMojo { | 70 | extends AbstractMojo { |
| 69 | 71 | ||
| 70 | private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); | 72 | private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); |
| 73 | + YangPluginConfig yangPlugin = new YangPluginConfig(); | ||
| 71 | private YangNode rootNode; | 74 | private YangNode rootNode; |
| 72 | // YANG file information set. | 75 | // YANG file information set. |
| 73 | private Set<YangFileInfo> yangFileInfoSet = new HashSet<>(); | 76 | private Set<YangFileInfo> yangFileInfoSet = new HashSet<>(); |
| ... | @@ -181,7 +184,6 @@ public class YangUtilManager | ... | @@ -181,7 +184,6 @@ public class YangUtilManager |
| 181 | conflictResolver.setReplacementForHyphen(replacementForHyphen); | 184 | conflictResolver.setReplacementForHyphen(replacementForHyphen); |
| 182 | conflictResolver.setReplacementForUnderscore(replacementForUnderscore); | 185 | conflictResolver.setReplacementForUnderscore(replacementForUnderscore); |
| 183 | conflictResolver.setPrefixForIdentifier(prefixForIdentifier); | 186 | conflictResolver.setPrefixForIdentifier(prefixForIdentifier); |
| 184 | - YangPluginConfig yangPlugin = new YangPluginConfig(); | ||
| 185 | yangPlugin.setCodeGenDir(codeGenDir); | 187 | yangPlugin.setCodeGenDir(codeGenDir); |
| 186 | yangPlugin.setManagerCodeGenDir(managerCodeGenDir); | 188 | yangPlugin.setManagerCodeGenDir(managerCodeGenDir); |
| 187 | yangPlugin.setConflictResolver(conflictResolver); | 189 | yangPlugin.setConflictResolver(conflictResolver); |
| ... | @@ -223,7 +225,7 @@ public class YangUtilManager | ... | @@ -223,7 +225,7 @@ public class YangUtilManager |
| 223 | fileName = getCurYangFileInfo().getYangFileName(); | 225 | fileName = getCurYangFileInfo().getYangFileName(); |
| 224 | } | 226 | } |
| 225 | try { | 227 | try { |
| 226 | - translatorErrorHandler(getRootNode()); | 228 | + translatorErrorHandler(getRootNode(), yangPlugin); |
| 227 | deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG); | 229 | deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG); |
| 228 | } catch (IOException ex) { | 230 | } catch (IOException ex) { |
| 229 | throw new MojoExecutionException( | 231 | throw new MojoExecutionException( |
| ... | @@ -348,8 +350,10 @@ public class YangUtilManager | ... | @@ -348,8 +350,10 @@ public class YangUtilManager |
| 348 | */ | 350 | */ |
| 349 | public void translateToJava(YangPluginConfig yangPlugin) | 351 | public void translateToJava(YangPluginConfig yangPlugin) |
| 350 | throws IOException { | 352 | throws IOException { |
| 351 | - updateFilePriority(getYangNodeSet()); | 353 | + List<YangNode> yangNodeSortedList = new LinkedList<>(); |
| 352 | - for (YangNode node : getYangNodeSet()) { | 354 | + yangNodeSortedList.addAll(getYangNodeSet()); |
| 355 | + Collections.sort(yangNodeSortedList); | ||
| 356 | + for (YangNode node : yangNodeSortedList) { | ||
| 353 | if (node.isToTranslate()) { | 357 | if (node.isToTranslate()) { |
| 354 | generateJavaCode(node, yangPlugin); | 358 | generateJavaCode(node, yangPlugin); |
| 355 | } | 359 | } | ... | ... |
| ... | @@ -122,11 +122,6 @@ public final class GeneratedTempFileType { | ... | @@ -122,11 +122,6 @@ public final class GeneratedTempFileType { |
| 122 | public static final int EVENT_SUBJECT_SETTER_MASK = 524288; | 122 | public static final int EVENT_SUBJECT_SETTER_MASK = 524288; |
| 123 | 123 | ||
| 124 | /** | 124 | /** |
| 125 | - * Event subject setter implementation of class. | ||
| 126 | - */ | ||
| 127 | - public static final int AUGMENTE_CLASS_CONSTRUCTOR_MASK = 1048576; | ||
| 128 | - | ||
| 129 | - /** | ||
| 130 | * Creates an instance of generated temp file type. | 125 | * Creates an instance of generated temp file type. |
| 131 | */ | 126 | */ |
| 132 | private GeneratedTempFileType() { | 127 | private GeneratedTempFileType() { | ... | ... |
| ... | @@ -51,6 +51,16 @@ public final class JavaAttributeInfo { | ... | @@ -51,6 +51,16 @@ public final class JavaAttributeInfo { |
| 51 | private JavaQualifiedTypeInfo importInfo; | 51 | private JavaQualifiedTypeInfo importInfo; |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 54 | + * If conflict occurs. | ||
| 55 | + */ | ||
| 56 | + private boolean isIntConflict; | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * If conflict occurs. | ||
| 60 | + */ | ||
| 61 | + private boolean isLongConflict; | ||
| 62 | + | ||
| 63 | + /** | ||
| 54 | * Creates a java attribute info object. | 64 | * Creates a java attribute info object. |
| 55 | */ | 65 | */ |
| 56 | private JavaAttributeInfo() { | 66 | private JavaAttributeInfo() { |
| ... | @@ -175,6 +185,42 @@ public final class JavaAttributeInfo { | ... | @@ -175,6 +185,42 @@ public final class JavaAttributeInfo { |
| 175 | } | 185 | } |
| 176 | 186 | ||
| 177 | /** | 187 | /** |
| 188 | + * Returns true if conflict between int and uint. | ||
| 189 | + * | ||
| 190 | + * @return true if conflict between int and uint | ||
| 191 | + */ | ||
| 192 | + public boolean isIntConflict() { | ||
| 193 | + return isIntConflict; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * Sets true if conflict between int and uint. | ||
| 198 | + * | ||
| 199 | + * @param intConflict true if conflict between int and uint | ||
| 200 | + */ | ||
| 201 | + public void setIntConflict(boolean intConflict) { | ||
| 202 | + isIntConflict = intConflict; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * Returns true if conflict between long and ulong. | ||
| 207 | + * | ||
| 208 | + * @return true if conflict between long and ulong | ||
| 209 | + */ | ||
| 210 | + public boolean isLongConflict() { | ||
| 211 | + return isLongConflict; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + /** | ||
| 215 | + * Sets true if conflict between long and ulong. | ||
| 216 | + * | ||
| 217 | + * @param longConflict true if conflict between long and ulong | ||
| 218 | + */ | ||
| 219 | + public void setLongConflict(boolean longConflict) { | ||
| 220 | + isLongConflict = longConflict; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + /** | ||
| 178 | * Returns java attribute info. | 224 | * Returns java attribute info. |
| 179 | * | 225 | * |
| 180 | * @param importInfo java qualified type info | 226 | * @param importInfo java qualified type info | ... | ... |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | package org.onosproject.yangutils.translator.tojava; | 17 | package org.onosproject.yangutils.translator.tojava; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | + | ||
| 20 | import org.onosproject.yangutils.datamodel.TraversalType; | 21 | import org.onosproject.yangutils.datamodel.TraversalType; |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException; | 23 | import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException; |
| ... | @@ -27,6 +28,7 @@ import static org.onosproject.yangutils.datamodel.TraversalType.CHILD; | ... | @@ -27,6 +28,7 @@ import static org.onosproject.yangutils.datamodel.TraversalType.CHILD; |
| 27 | import static org.onosproject.yangutils.datamodel.TraversalType.PARENT; | 28 | import static org.onosproject.yangutils.datamodel.TraversalType.PARENT; |
| 28 | import static org.onosproject.yangutils.datamodel.TraversalType.ROOT; | 29 | import static org.onosproject.yangutils.datamodel.TraversalType.ROOT; |
| 29 | import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING; | 30 | import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING; |
| 31 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | ||
| 30 | 32 | ||
| 31 | /** | 33 | /** |
| 32 | * Representation of java code generator based on application schema. | 34 | * Representation of java code generator based on application schema. |
| ... | @@ -39,6 +41,11 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -39,6 +41,11 @@ public final class JavaCodeGeneratorUtil { |
| 39 | private static YangNode curNode; | 41 | private static YangNode curNode; |
| 40 | 42 | ||
| 41 | /** | 43 | /** |
| 44 | + * Root node. | ||
| 45 | + */ | ||
| 46 | + private static YangNode rootNode; | ||
| 47 | + | ||
| 48 | + /** | ||
| 42 | * Creates a java code generator utility object. | 49 | * Creates a java code generator utility object. |
| 43 | */ | 50 | */ |
| 44 | private JavaCodeGeneratorUtil() { | 51 | private JavaCodeGeneratorUtil() { |
| ... | @@ -67,13 +74,14 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -67,13 +74,14 @@ public final class JavaCodeGeneratorUtil { |
| 67 | * | 74 | * |
| 68 | * @param rootNode root node of the data model tree | 75 | * @param rootNode root node of the data model tree |
| 69 | * @param yangPlugin YANG plugin config | 76 | * @param yangPlugin YANG plugin config |
| 70 | - * @throws TranslatorException when fails to generate java code file the current | 77 | + * @throws TranslatorException when fails to generate java code file the current node |
| 71 | - * node | 78 | + * @throws IOException when fails to do IO operations |
| 72 | */ | 79 | */ |
| 73 | public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin) | 80 | public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin) |
| 74 | - throws TranslatorException { | 81 | + throws TranslatorException, IOException { |
| 75 | 82 | ||
| 76 | YangNode codeGenNode = rootNode; | 83 | YangNode codeGenNode = rootNode; |
| 84 | + setRootNode(rootNode); | ||
| 77 | TraversalType curTraversal = ROOT; | 85 | TraversalType curTraversal = ROOT; |
| 78 | 86 | ||
| 79 | while (codeGenNode != null) { | 87 | while (codeGenNode != null) { |
| ... | @@ -94,6 +102,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -94,6 +102,7 @@ public final class JavaCodeGeneratorUtil { |
| 94 | } | 102 | } |
| 95 | continue; | 103 | continue; |
| 96 | } catch (Exception e) { | 104 | } catch (Exception e) { |
| 105 | + close(codeGenNode, yangPlugin); | ||
| 97 | throw new TranslatorException(e.getMessage()); | 106 | throw new TranslatorException(e.getMessage()); |
| 98 | } | 107 | } |
| 99 | 108 | ||
| ... | @@ -103,16 +112,18 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -103,16 +112,18 @@ public final class JavaCodeGeneratorUtil { |
| 103 | codeGenNode = codeGenNode.getChild(); | 112 | codeGenNode = codeGenNode.getChild(); |
| 104 | } else if (codeGenNode.getNextSibling() != null) { | 113 | } else if (codeGenNode.getNextSibling() != null) { |
| 105 | try { | 114 | try { |
| 106 | - generateCodeExit(codeGenNode); | 115 | + generateCodeExit(codeGenNode, yangPlugin); |
| 107 | } catch (Exception e) { | 116 | } catch (Exception e) { |
| 117 | + close(codeGenNode, yangPlugin); | ||
| 108 | throw new TranslatorException(e.getMessage()); | 118 | throw new TranslatorException(e.getMessage()); |
| 109 | } | 119 | } |
| 110 | curTraversal = SIBILING; | 120 | curTraversal = SIBILING; |
| 111 | codeGenNode = codeGenNode.getNextSibling(); | 121 | codeGenNode = codeGenNode.getNextSibling(); |
| 112 | } else { | 122 | } else { |
| 113 | try { | 123 | try { |
| 114 | - generateCodeExit(codeGenNode); | 124 | + generateCodeExit(codeGenNode, yangPlugin); |
| 115 | } catch (Exception e) { | 125 | } catch (Exception e) { |
| 126 | + close(codeGenNode, yangPlugin); | ||
| 116 | throw new TranslatorException(e.getMessage()); | 127 | throw new TranslatorException(e.getMessage()); |
| 117 | } | 128 | } |
| 118 | curTraversal = PARENT; | 129 | curTraversal = PARENT; |
| ... | @@ -124,18 +135,18 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -124,18 +135,18 @@ public final class JavaCodeGeneratorUtil { |
| 124 | /** | 135 | /** |
| 125 | * Generates the current nodes code snippet. | 136 | * Generates the current nodes code snippet. |
| 126 | * | 137 | * |
| 127 | - * @param codeGenNode current data model node for which the code needs to be | 138 | + * @param codeGenNode current data model node for which the code needs to be generated |
| 128 | - * generated | ||
| 129 | * @param yangPlugin YANG plugin config | 139 | * @param yangPlugin YANG plugin config |
| 130 | - * @throws TranslatorException when fails to generate java code file the current | 140 | + * @throws TranslatorException when fails to generate java code file the current node |
| 131 | - * node | 141 | + * @throws IOException when fails to do IO operations |
| 132 | */ | 142 | */ |
| 133 | private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin) | 143 | private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin) |
| 134 | - throws TranslatorException { | 144 | + throws TranslatorException, IOException { |
| 135 | 145 | ||
| 136 | if (codeGenNode instanceof JavaCodeGenerator) { | 146 | if (codeGenNode instanceof JavaCodeGenerator) { |
| 137 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); | 147 | ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin); |
| 138 | } else { | 148 | } else { |
| 149 | + close(codeGenNode, yangPlugin); | ||
| 139 | throw new TranslatorException( | 150 | throw new TranslatorException( |
| 140 | "Generated data model node cannot be translated to target language code"); | 151 | "Generated data model node cannot be translated to target language code"); |
| 141 | } | 152 | } |
| ... | @@ -144,25 +155,25 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -144,25 +155,25 @@ public final class JavaCodeGeneratorUtil { |
| 144 | /** | 155 | /** |
| 145 | * Generates the current nodes code target code from the snippet. | 156 | * Generates the current nodes code target code from the snippet. |
| 146 | * | 157 | * |
| 147 | - * @param codeGenNode current data model node for which the code needs to be | 158 | + * @param codeGenNode current data model node for which the code needs to be generated |
| 148 | - * generated | 159 | + * @param pluginConfig plugin configurations |
| 149 | - * @throws TranslatorException when fails to generate java code file the current | 160 | + * @throws TranslatorException when fails to generate java code file the current node |
| 150 | - * node | 161 | + * @throws IOException when fails to do IO operations |
| 151 | */ | 162 | */ |
| 152 | - private static void generateCodeExit(YangNode codeGenNode) | 163 | + private static void generateCodeExit(YangNode codeGenNode, YangPluginConfig pluginConfig) |
| 153 | - throws TranslatorException { | 164 | + throws TranslatorException, IOException { |
| 154 | 165 | ||
| 155 | if (codeGenNode instanceof JavaCodeGenerator) { | 166 | if (codeGenNode instanceof JavaCodeGenerator) { |
| 156 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); | 167 | ((JavaCodeGenerator) codeGenNode).generateCodeExit(); |
| 157 | } else { | 168 | } else { |
| 169 | + close(codeGenNode, pluginConfig); | ||
| 158 | throw new TranslatorException( | 170 | throw new TranslatorException( |
| 159 | "Generated data model node cannot be translated to target language code"); | 171 | "Generated data model node cannot be translated to target language code"); |
| 160 | } | 172 | } |
| 161 | } | 173 | } |
| 162 | 174 | ||
| 163 | /** | 175 | /** |
| 164 | - * Free other YANG nodes of data-model tree when error occurs while file | 176 | + * Free other YANG nodes of data-model tree when error occurs while file generation of current node. |
| 165 | - * generation of current node. | ||
| 166 | */ | 177 | */ |
| 167 | private static void freeRestResources() { | 178 | private static void freeRestResources() { |
| 168 | 179 | ||
| ... | @@ -214,21 +225,18 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -214,21 +225,18 @@ public final class JavaCodeGeneratorUtil { |
| 214 | /** | 225 | /** |
| 215 | * Delete Java code files corresponding to the YANG schema. | 226 | * Delete Java code files corresponding to the YANG schema. |
| 216 | * | 227 | * |
| 217 | - * @param rootNode root node of data-model tree | 228 | + * @param rootNode root node of data-model tree |
| 229 | + * @param yangPluginConfig plugin configurations | ||
| 218 | * @throws IOException when fails to delete java code file the current node | 230 | * @throws IOException when fails to delete java code file the current node |
| 219 | */ | 231 | */ |
| 220 | - public static void translatorErrorHandler(YangNode rootNode) | 232 | + public static void translatorErrorHandler(YangNode rootNode, YangPluginConfig yangPluginConfig) |
| 221 | throws IOException { | 233 | throws IOException { |
| 222 | 234 | ||
| 223 | if (rootNode != null) { | 235 | if (rootNode != null) { |
| 224 | - /** | 236 | + //Free other resources where translator has failed. |
| 225 | - * Free other resources where translator has failed. | ||
| 226 | - */ | ||
| 227 | freeRestResources(); | 237 | freeRestResources(); |
| 228 | 238 | ||
| 229 | - /** | 239 | + // Start removing all open files. |
| 230 | - * Start removing all open files. | ||
| 231 | - */ | ||
| 232 | YangNode tempNode = rootNode; | 240 | YangNode tempNode = rootNode; |
| 233 | setCurNode(tempNode.getChild()); | 241 | setCurNode(tempNode.getChild()); |
| 234 | TraversalType curTraversal = ROOT; | 242 | TraversalType curTraversal = ROOT; |
| ... | @@ -236,7 +244,7 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -236,7 +244,7 @@ public final class JavaCodeGeneratorUtil { |
| 236 | while (tempNode != null) { | 244 | while (tempNode != null) { |
| 237 | 245 | ||
| 238 | if (curTraversal != PARENT) { | 246 | if (curTraversal != PARENT) { |
| 239 | - close(tempNode); | 247 | + close(tempNode, yangPluginConfig); |
| 240 | } | 248 | } |
| 241 | if (curTraversal != PARENT && tempNode.getChild() != null) { | 249 | if (curTraversal != PARENT && tempNode.getChild() != null) { |
| 242 | curTraversal = CHILD; | 250 | curTraversal = CHILD; |
| ... | @@ -255,17 +263,45 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -255,17 +263,45 @@ public final class JavaCodeGeneratorUtil { |
| 255 | } | 263 | } |
| 256 | 264 | ||
| 257 | /** | 265 | /** |
| 258 | - * Closes all the current open file handles of node and delete all generated | 266 | + * Closes all the current open file handles of node and delete all generated files. |
| 259 | - * files. | ||
| 260 | * | 267 | * |
| 261 | - * @param node current YANG node | 268 | + * @param node current YANG node |
| 269 | + * @param yangPlugin plugin configurations | ||
| 262 | * @throws IOException when fails to do IO operations | 270 | * @throws IOException when fails to do IO operations |
| 263 | */ | 271 | */ |
| 264 | - private static void close(YangNode node) | 272 | + private static void close(YangNode node, YangPluginConfig yangPlugin) |
| 265 | throws IOException { | 273 | throws IOException { |
| 266 | if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node) | 274 | if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node) |
| 267 | .getTempJavaCodeFragmentFiles() != null) { | 275 | .getTempJavaCodeFragmentFiles() != null) { |
| 268 | ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true); | 276 | ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true); |
| 277 | + } else { | ||
| 278 | + | ||
| 279 | + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) getRootNode()).getJavaFileInfo(); | ||
| 280 | + if (javaFileInfo != null) { | ||
| 281 | + searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() + | ||
| 282 | + javaFileInfo.getPackageFilePath()); | ||
| 283 | + } else { | ||
| 284 | + searchAndDeleteTempDir(yangPlugin.getManagerCodeGenDir()); | ||
| 285 | + } | ||
| 286 | + | ||
| 269 | } | 287 | } |
| 270 | } | 288 | } |
| 289 | + | ||
| 290 | + /** | ||
| 291 | + * Returns root node. | ||
| 292 | + * | ||
| 293 | + * @return root node | ||
| 294 | + */ | ||
| 295 | + private static YangNode getRootNode() { | ||
| 296 | + return rootNode; | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + /** | ||
| 300 | + * Sets root node. | ||
| 301 | + * | ||
| 302 | + * @param rootNode root node | ||
| 303 | + */ | ||
| 304 | + private static void setRootNode(YangNode rootNode) { | ||
| 305 | + JavaCodeGeneratorUtil.rootNode = rootNode; | ||
| 306 | + } | ||
| 271 | } | 307 | } | ... | ... |
utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
| ... | @@ -21,6 +21,7 @@ import java.util.SortedSet; | ... | @@ -21,6 +21,7 @@ import java.util.SortedSet; |
| 21 | import java.util.TreeSet; | 21 | import java.util.TreeSet; |
| 22 | 22 | ||
| 23 | import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT; | 23 | import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT; |
| 24 | +import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; | ||
| 24 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS; |
| 25 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG; |
| 26 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | 27 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; |
| ... | @@ -31,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_I | ... | @@ -31,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_I |
| 31 | import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP; |
| 32 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 33 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
| 35 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; | ||
| 34 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.BITSET; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.BITSET; |
| 36 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; |
| ... | @@ -300,4 +302,14 @@ public class JavaImportData { | ... | @@ -300,4 +302,14 @@ public class JavaImportData { |
| 300 | return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + | 302 | return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + |
| 301 | YANG_AUGMENTED_OP_PARAM_INFO_CLASS; | 303 | YANG_AUGMENTED_OP_PARAM_INFO_CLASS; |
| 302 | } | 304 | } |
| 305 | + | ||
| 306 | + /** | ||
| 307 | + * Returns import for big integer. | ||
| 308 | + * | ||
| 309 | + * @return import for big integer | ||
| 310 | + */ | ||
| 311 | + public String getBigIntegerImport() { | ||
| 312 | + return IMPORT + JAVA_MATH + PERIOD + | ||
| 313 | + BIG_INTEGER + SEMI_COLAN + NEW_LINE; | ||
| 314 | + } | ||
| 303 | } | 315 | } | ... | ... |
| ... | @@ -48,7 +48,7 @@ public class TempJavaBeanFragmentFiles | ... | @@ -48,7 +48,7 @@ public class TempJavaBeanFragmentFiles |
| 48 | * @param javaFileInfo generated java file info | 48 | * @param javaFileInfo generated java file info |
| 49 | * @throws IOException when fails to create new file handle | 49 | * @throws IOException when fails to create new file handle |
| 50 | */ | 50 | */ |
| 51 | - public TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo) | 51 | + TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo) |
| 52 | throws IOException { | 52 | throws IOException { |
| 53 | 53 | ||
| 54 | super(javaFileInfo); | 54 | super(javaFileInfo); |
| ... | @@ -109,9 +109,7 @@ public class TempJavaBeanFragmentFiles | ... | @@ -109,9 +109,7 @@ public class TempJavaBeanFragmentFiles |
| 109 | /** | 109 | /** |
| 110 | * Removes all temporary file handles. | 110 | * Removes all temporary file handles. |
| 111 | * | 111 | * |
| 112 | - * @param isErrorOccurred when translator fails to generate java files we | 112 | + * @param isErrorOccurred flag to tell translator that error has occurred while code generation |
| 113 | - * need to close all open file handles include temporary files | ||
| 114 | - * and java files. | ||
| 115 | * @throws IOException when failed to delete the temporary files | 113 | * @throws IOException when failed to delete the temporary files |
| 116 | */ | 114 | */ |
| 117 | @Override | 115 | @Override | ... | ... |
| ... | @@ -346,6 +346,10 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -346,6 +346,10 @@ public class TempJavaCodeFragmentFiles { |
| 346 | getServiceTempFiles().freeTemporaryResources(isErrorOccurred); | 346 | getServiceTempFiles().freeTemporaryResources(isErrorOccurred); |
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | + if (getEventFragmentFiles() != null) { | ||
| 350 | + getEventFragmentFiles().freeTemporaryResources(isErrorOccurred); | ||
| 351 | + } | ||
| 352 | + | ||
| 349 | } | 353 | } |
| 350 | 354 | ||
| 351 | } | 355 | } | ... | ... |
| ... | @@ -43,8 +43,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX; | ... | @@ -43,8 +43,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX; |
| 43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; | 43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| 46 | - * Represents implementation of java code fragments temporary implementations. | 46 | + * Represents implementation of java code fragments temporary implementations. Maintains the temp files required |
| 47 | - * Maintains the temp files required specific for enumeration java snippet generation. | 47 | + * specific for enumeration java snippet generation. |
| 48 | */ | 48 | */ |
| 49 | public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | 49 | public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 50 | 50 | ||
| ... | @@ -89,7 +89,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -89,7 +89,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 89 | * @param javaFileInfo generated java file info | 89 | * @param javaFileInfo generated java file info |
| 90 | * @throws IOException when fails to create new file handle | 90 | * @throws IOException when fails to create new file handle |
| 91 | */ | 91 | */ |
| 92 | - public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo) | 92 | + TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo) |
| 93 | throws IOException { | 93 | throws IOException { |
| 94 | 94 | ||
| 95 | super(javaFileInfo); | 95 | super(javaFileInfo); |
| ... | @@ -107,7 +107,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -107,7 +107,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 107 | * | 107 | * |
| 108 | * @return enum class java file handle | 108 | * @return enum class java file handle |
| 109 | */ | 109 | */ |
| 110 | - public File getEnumClassJavaFileHandle() { | 110 | + private File getEnumClassJavaFileHandle() { |
| 111 | return enumClassJavaFileHandle; | 111 | return enumClassJavaFileHandle; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| ... | @@ -188,18 +188,18 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -188,18 +188,18 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 188 | /** | 188 | /** |
| 189 | * Adds enum attributes to temporary files. | 189 | * Adds enum attributes to temporary files. |
| 190 | * | 190 | * |
| 191 | - * @param curNode current YANG node | 191 | + * @param curNode current YANG node |
| 192 | * @param pluginConfig plugin configurations | 192 | * @param pluginConfig plugin configurations |
| 193 | * @throws IOException when fails to do IO operations | 193 | * @throws IOException when fails to do IO operations |
| 194 | */ | 194 | */ |
| 195 | - public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException { | 195 | + void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException { |
| 196 | 196 | ||
| 197 | super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig); | 197 | super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig); |
| 198 | if (curNode instanceof YangEnumeration) { | 198 | if (curNode instanceof YangEnumeration) { |
| 199 | YangEnumeration enumeration = (YangEnumeration) curNode; | 199 | YangEnumeration enumeration = (YangEnumeration) curNode; |
| 200 | for (YangEnum curEnum : enumeration.getEnumSet()) { | 200 | for (YangEnum curEnum : enumeration.getEnumSet()) { |
| 201 | String enumName = curEnum.getNamedValue(); | 201 | String enumName = curEnum.getNamedValue(); |
| 202 | - String prefixForIdentifier = null; | 202 | + String prefixForIdentifier; |
| 203 | if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) { | 203 | if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) { |
| 204 | prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver()); | 204 | prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver()); |
| 205 | if (prefixForIdentifier != null) { | 205 | if (prefixForIdentifier != null) { |
| ... | @@ -219,11 +219,11 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -219,11 +219,11 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | /** | 221 | /** |
| 222 | - * Returns java attribute for enum class. | 222 | + * Returns java attribute for enum class. |
| 223 | - * | 223 | + * |
| 224 | - * @param pluginConfig plugin configurations | 224 | + * @param pluginConfig plugin configurations |
| 225 | - * @return java attribute | 225 | + * @return java attribute |
| 226 | - */ | 226 | + */ |
| 227 | public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) { | 227 | public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) { |
| 228 | YangJavaType<?> javaType = new YangJavaType<>(); | 228 | YangJavaType<?> javaType = new YangJavaType<>(); |
| 229 | javaType.setDataType(YangDataTypes.INT32); | 229 | javaType.setDataType(YangDataTypes.INT32); |
| ... | @@ -248,11 +248,10 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -248,11 +248,10 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 248 | /** | 248 | /** |
| 249 | * Adds the new attribute info to the target generated temporary files. | 249 | * Adds the new attribute info to the target generated temporary files. |
| 250 | * | 250 | * |
| 251 | - * @param curEnumName the attribute name that needs to be added to temporary | 251 | + * @param curEnumName the attribute name that needs to be added to temporary files |
| 252 | - * files | ||
| 253 | * @throws IOException IO operation fail | 252 | * @throws IOException IO operation fail |
| 254 | */ | 253 | */ |
| 255 | - void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig) | 254 | + private void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig) |
| 256 | throws IOException { | 255 | throws IOException { |
| 257 | addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig); | 256 | addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig); |
| 258 | } | 257 | } |
| ... | @@ -261,7 +260,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -261,7 +260,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 261 | * Constructs java code exit. | 260 | * Constructs java code exit. |
| 262 | * | 261 | * |
| 263 | * @param fileType generated file type | 262 | * @param fileType generated file type |
| 264 | - * @param curNode current YANG node | 263 | + * @param curNode current YANG node |
| 265 | * @throws IOException when fails to generate java files | 264 | * @throws IOException when fails to generate java files |
| 266 | */ | 265 | */ |
| 267 | @Override | 266 | @Override |
| ... | @@ -275,9 +274,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -275,9 +274,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 275 | /** | 274 | /** |
| 276 | * Removes all temporary file handles. | 275 | * Removes all temporary file handles. |
| 277 | * | 276 | * |
| 278 | - * @param isErrorOccurred when translator fails to generate java files we | 277 | + * @param isErrorOccurred flag to tell translator that error has occurred while file generation |
| 279 | - * need to close all open file handles include temporary files | ||
| 280 | - * and java files. | ||
| 281 | * @throws IOException when failed to delete the temporary files | 278 | * @throws IOException when failed to delete the temporary files |
| 282 | */ | 279 | */ |
| 283 | @Override | 280 | @Override |
| ... | @@ -310,7 +307,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -310,7 +307,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 310 | * | 307 | * |
| 311 | * @param enumStringList the enumStringList to set | 308 | * @param enumStringList the enumStringList to set |
| 312 | */ | 309 | */ |
| 313 | - public void setEnumStringList(List<String> enumStringList) { | 310 | + private void setEnumStringList(List<String> enumStringList) { |
| 314 | this.enumStringList = enumStringList; | 311 | this.enumStringList = enumStringList; |
| 315 | } | 312 | } |
| 316 | } | 313 | } | ... | ... |
| ... | @@ -46,6 +46,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ... | @@ -46,6 +46,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
| 46 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 49 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; | ||
| 49 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; | 50 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; |
| 50 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 51 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 51 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD; | 52 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD; |
| ... | @@ -63,12 +64,11 @@ public class TempJavaEventFragmentFiles | ... | @@ -63,12 +64,11 @@ public class TempJavaEventFragmentFiles |
| 63 | /** | 64 | /** |
| 64 | * File name for generated class file for special type like union, typedef suffix. | 65 | * File name for generated class file for special type like union, typedef suffix. |
| 65 | */ | 66 | */ |
| 66 | - public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject"; | 67 | + private static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject"; |
| 67 | 68 | ||
| 68 | /** | 69 | /** |
| 69 | * File name for event enum temp file. | 70 | * File name for event enum temp file. |
| 70 | */ | 71 | */ |
| 71 | - | ||
| 72 | private static final String EVENT_ENUM_FILE_NAME = "EventEnum"; | 72 | private static final String EVENT_ENUM_FILE_NAME = "EventEnum"; |
| 73 | 73 | ||
| 74 | /** | 74 | /** |
| ... | @@ -149,7 +149,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -149,7 +149,7 @@ public class TempJavaEventFragmentFiles |
| 149 | * @param javaFileInfo generated file information | 149 | * @param javaFileInfo generated file information |
| 150 | * @throws IOException when fails to create new file handle | 150 | * @throws IOException when fails to create new file handle |
| 151 | */ | 151 | */ |
| 152 | - public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo) | 152 | + TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo) |
| 153 | throws IOException { | 153 | throws IOException { |
| 154 | setJavaExtendsListHolder(new JavaExtendsListHolder()); | 154 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
| 155 | setJavaImportData(new JavaImportData()); | 155 | setJavaImportData(new JavaImportData()); |
| ... | @@ -255,6 +255,9 @@ public class TempJavaEventFragmentFiles | ... | @@ -255,6 +255,9 @@ public class TempJavaEventFragmentFiles |
| 255 | generateEventJavaFile(curNode); | 255 | generateEventJavaFile(curNode); |
| 256 | generateEventListenerJavaFile(curNode); | 256 | generateEventListenerJavaFile(curNode); |
| 257 | generateEventSubjectJavaFile(curNode); | 257 | generateEventSubjectJavaFile(curNode); |
| 258 | + | ||
| 259 | + // Close all the file handles. | ||
| 260 | + freeTemporaryResources(false); | ||
| 258 | } | 261 | } |
| 259 | 262 | ||
| 260 | /** | 263 | /** |
| ... | @@ -263,7 +266,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -263,7 +266,7 @@ public class TempJavaEventFragmentFiles |
| 263 | * @param curNode current YANG node | 266 | * @param curNode current YANG node |
| 264 | * @throws IOException when fails to generate java files | 267 | * @throws IOException when fails to generate java files |
| 265 | */ | 268 | */ |
| 266 | - public void generateEventJavaFile(YangNode curNode) | 269 | + private void generateEventJavaFile(YangNode curNode) |
| 267 | throws IOException { | 270 | throws IOException { |
| 268 | 271 | ||
| 269 | List<String> imports = new ArrayList<>(); | 272 | List<String> imports = new ArrayList<>(); |
| ... | @@ -274,25 +277,19 @@ public class TempJavaEventFragmentFiles | ... | @@ -274,25 +277,19 @@ public class TempJavaEventFragmentFiles |
| 274 | 277 | ||
| 275 | addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX); | 278 | addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX); |
| 276 | 279 | ||
| 277 | - /** | 280 | + //Creates event interface file. |
| 278 | - * Creates event interface file. | ||
| 279 | - */ | ||
| 280 | setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX)); | 281 | setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX)); |
| 281 | generateEventFile(getEventJavaFileHandle(), curNode, imports); | 282 | generateEventFile(getEventJavaFileHandle(), curNode, imports); |
| 282 | 283 | ||
| 283 | - /** | ||
| 284 | - * Close all the file handles. | ||
| 285 | - */ | ||
| 286 | - freeTemporaryResources(false); | ||
| 287 | } | 284 | } |
| 288 | 285 | ||
| 289 | /** | 286 | /** |
| 290 | * Constructs java code exit. | 287 | * Constructs java code exit. |
| 291 | * | 288 | * |
| 292 | - * @param curNode current YANG node | 289 | + * @param curNode current YANG node |
| 293 | * @throws IOException when fails to generate java files | 290 | * @throws IOException when fails to generate java files |
| 294 | */ | 291 | */ |
| 295 | - public void generateEventListenerJavaFile(YangNode curNode) | 292 | + private void generateEventListenerJavaFile(YangNode curNode) |
| 296 | throws IOException { | 293 | throws IOException { |
| 297 | 294 | ||
| 298 | List<String> imports = new ArrayList<>(); | 295 | List<String> imports = new ArrayList<>(); |
| ... | @@ -300,17 +297,12 @@ public class TempJavaEventFragmentFiles | ... | @@ -300,17 +297,12 @@ public class TempJavaEventFragmentFiles |
| 300 | imports.add(getJavaImportData().getEventListenerImport()); | 297 | imports.add(getJavaImportData().getEventListenerImport()); |
| 301 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) | 298 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) |
| 302 | .getJavaFileInfo().getJavaName()); | 299 | .getJavaFileInfo().getJavaName()); |
| 303 | - /** | 300 | + |
| 304 | - * Creates event listener interface file. | 301 | + // Creates event listener interface file. |
| 305 | - */ | ||
| 306 | setEventListenerJavaFileHandle( | 302 | setEventListenerJavaFileHandle( |
| 307 | getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX)); | 303 | getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX)); |
| 308 | generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports); | 304 | generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports); |
| 309 | 305 | ||
| 310 | - /** | ||
| 311 | - * Close all the file handles. | ||
| 312 | - */ | ||
| 313 | - freeTemporaryResources(false); | ||
| 314 | } | 306 | } |
| 315 | 307 | ||
| 316 | /** | 308 | /** |
| ... | @@ -319,22 +311,17 @@ public class TempJavaEventFragmentFiles | ... | @@ -319,22 +311,17 @@ public class TempJavaEventFragmentFiles |
| 319 | * @param curNode current YANG node | 311 | * @param curNode current YANG node |
| 320 | * @throws IOException when fails to generate java files | 312 | * @throws IOException when fails to generate java files |
| 321 | */ | 313 | */ |
| 322 | - public void generateEventSubjectJavaFile(YangNode curNode) | 314 | + private void generateEventSubjectJavaFile(YangNode curNode) |
| 323 | throws IOException { | 315 | throws IOException { |
| 324 | 316 | ||
| 325 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) | 317 | String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode) |
| 326 | .getJavaFileInfo().getJavaName()); | 318 | .getJavaFileInfo().getJavaName()); |
| 327 | - /** | 319 | + |
| 328 | - * Creates event interface file. | 320 | + //Creates event interface file. |
| 329 | - */ | ||
| 330 | setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + | 321 | setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + |
| 331 | TempJavaEventFragmentFiles.EVENT_SUBJECT_NAME_SUFFIX)); | 322 | TempJavaEventFragmentFiles.EVENT_SUBJECT_NAME_SUFFIX)); |
| 332 | generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode); | 323 | generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode); |
| 333 | 324 | ||
| 334 | - /** | ||
| 335 | - * Close all the file handles. | ||
| 336 | - */ | ||
| 337 | - freeTemporaryResources(false); | ||
| 338 | } | 325 | } |
| 339 | 326 | ||
| 340 | /** | 327 | /** |
| ... | @@ -351,7 +338,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -351,7 +338,7 @@ public class TempJavaEventFragmentFiles |
| 351 | * | 338 | * |
| 352 | * @param eventEnumTempFileHandle event enum temp file | 339 | * @param eventEnumTempFileHandle event enum temp file |
| 353 | */ | 340 | */ |
| 354 | - public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) { | 341 | + private void setEventEnumTempFileHandle(File eventEnumTempFileHandle) { |
| 355 | this.eventEnumTempFileHandle = eventEnumTempFileHandle; | 342 | this.eventEnumTempFileHandle = eventEnumTempFileHandle; |
| 356 | } | 343 | } |
| 357 | 344 | ||
| ... | @@ -369,7 +356,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -369,7 +356,7 @@ public class TempJavaEventFragmentFiles |
| 369 | * | 356 | * |
| 370 | * @param eventMethodTempFileHandle event method temp file | 357 | * @param eventMethodTempFileHandle event method temp file |
| 371 | */ | 358 | */ |
| 372 | - public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) { | 359 | + private void setEventMethodTempFileHandle(File eventMethodTempFileHandle) { |
| 373 | this.eventMethodTempFileHandle = eventMethodTempFileHandle; | 360 | this.eventMethodTempFileHandle = eventMethodTempFileHandle; |
| 374 | } | 361 | } |
| 375 | 362 | ||
| ... | @@ -387,7 +374,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -387,7 +374,7 @@ public class TempJavaEventFragmentFiles |
| 387 | * | 374 | * |
| 388 | * @param eventSubjectAttributeTempFileHandle event subject attribute temp file | 375 | * @param eventSubjectAttributeTempFileHandle event subject attribute temp file |
| 389 | */ | 376 | */ |
| 390 | - public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) { | 377 | + private void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) { |
| 391 | this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle; | 378 | this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle; |
| 392 | } | 379 | } |
| 393 | 380 | ||
| ... | @@ -405,7 +392,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -405,7 +392,7 @@ public class TempJavaEventFragmentFiles |
| 405 | * | 392 | * |
| 406 | * @param eventSubjectGetterTempFileHandle event subject getter temp file | 393 | * @param eventSubjectGetterTempFileHandle event subject getter temp file |
| 407 | */ | 394 | */ |
| 408 | - public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) { | 395 | + private void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) { |
| 409 | this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle; | 396 | this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle; |
| 410 | } | 397 | } |
| 411 | 398 | ||
| ... | @@ -423,7 +410,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -423,7 +410,7 @@ public class TempJavaEventFragmentFiles |
| 423 | * | 410 | * |
| 424 | * @param eventSubjectSetterTempFileHandle event subject setter temp file | 411 | * @param eventSubjectSetterTempFileHandle event subject setter temp file |
| 425 | */ | 412 | */ |
| 426 | - public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) { | 413 | + private void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) { |
| 427 | this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle; | 414 | this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle; |
| 428 | } | 415 | } |
| 429 | 416 | ||
| ... | @@ -434,7 +421,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -434,7 +421,7 @@ public class TempJavaEventFragmentFiles |
| 434 | * @param pluginConfig plugin configurations | 421 | * @param pluginConfig plugin configurations |
| 435 | * @throws IOException when fails to do IO operations | 422 | * @throws IOException when fails to do IO operations |
| 436 | */ | 423 | */ |
| 437 | - public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) | 424 | + void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig) |
| 438 | throws IOException { | 425 | throws IOException { |
| 439 | 426 | ||
| 440 | String currentInfo = getCapitalCase(getCamelCase(curNode.getName(), | 427 | String currentInfo = getCapitalCase(getCamelCase(curNode.getName(), |
| ... | @@ -521,4 +508,28 @@ public class TempJavaEventFragmentFiles | ... | @@ -521,4 +508,28 @@ public class TempJavaEventFragmentFiles |
| 521 | private String getDirPath(JavaFileInfo parentInfo) { | 508 | private String getDirPath(JavaFileInfo parentInfo) { |
| 522 | return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase(); | 509 | return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase(); |
| 523 | } | 510 | } |
| 511 | + | ||
| 512 | + /** | ||
| 513 | + * Removes all temporary file handles. | ||
| 514 | + * | ||
| 515 | + * @param isErrorOccurred flag to tell translator that error has occurred while file generation | ||
| 516 | + * @throws IOException when failed to delete the temporary files | ||
| 517 | + */ | ||
| 518 | + @Override | ||
| 519 | + public void freeTemporaryResources(boolean isErrorOccurred) | ||
| 520 | + throws IOException { | ||
| 521 | + | ||
| 522 | + closeFile(getEventJavaFileHandle(), isErrorOccurred); | ||
| 523 | + closeFile(getEventListenerJavaFileHandle(), isErrorOccurred); | ||
| 524 | + closeFile(getEventSubjectJavaFileHandle(), isErrorOccurred); | ||
| 525 | + | ||
| 526 | + closeFile(getEventEnumTempFileHandle(), true); | ||
| 527 | + closeFile(getEventSubjectAttributeTempFileHandle(), true); | ||
| 528 | + closeFile(getEventMethodTempFileHandle(), true); | ||
| 529 | + closeFile(getEventSubjectGetterTempFileHandle(), true); | ||
| 530 | + closeFile(getEventSubjectSetterTempFileHandle(), true); | ||
| 531 | + | ||
| 532 | + super.freeTemporaryResources(isErrorOccurred); | ||
| 533 | + | ||
| 534 | + } | ||
| 524 | } | 535 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -78,7 +78,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -78,7 +78,7 @@ public class TempJavaServiceFragmentFiles |
| 78 | /** | 78 | /** |
| 79 | * Flag to set the manager files generation. | 79 | * Flag to set the manager files generation. |
| 80 | */ | 80 | */ |
| 81 | - boolean isManagerNeedToBeGenerated = false; | 81 | + private boolean isManagerNeedToBeGenerated = false; |
| 82 | 82 | ||
| 83 | /** | 83 | /** |
| 84 | * Temporary file handle for rpc interface. | 84 | * Temporary file handle for rpc interface. |
| ... | @@ -96,7 +96,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -96,7 +96,7 @@ public class TempJavaServiceFragmentFiles |
| 96 | private File serviceInterfaceJavaFileHandle; | 96 | private File serviceInterfaceJavaFileHandle; |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | - * Path for serive file to be generated. | 99 | + * Path for service file to be generated. |
| 100 | */ | 100 | */ |
| 101 | private String serviceGenPath; | 101 | private String serviceGenPath; |
| 102 | 102 | ||
| ... | @@ -111,7 +111,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -111,7 +111,7 @@ public class TempJavaServiceFragmentFiles |
| 111 | * @param javaFileInfo generated file information | 111 | * @param javaFileInfo generated file information |
| 112 | * @throws IOException when fails to create new file handle | 112 | * @throws IOException when fails to create new file handle |
| 113 | */ | 113 | */ |
| 114 | - public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo) | 114 | + TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo) |
| 115 | throws IOException { | 115 | throws IOException { |
| 116 | setJavaExtendsListHolder(new JavaExtendsListHolder()); | 116 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
| 117 | setJavaImportData(new JavaImportData()); | 117 | setJavaImportData(new JavaImportData()); |
| ... | @@ -150,7 +150,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -150,7 +150,7 @@ public class TempJavaServiceFragmentFiles |
| 150 | * | 150 | * |
| 151 | * @return java file handle | 151 | * @return java file handle |
| 152 | */ | 152 | */ |
| 153 | - public File getManagerJavaFileHandle() { | 153 | + private File getManagerJavaFileHandle() { |
| 154 | return managerJavaFileHandle; | 154 | return managerJavaFileHandle; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| ... | @@ -159,7 +159,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -159,7 +159,7 @@ public class TempJavaServiceFragmentFiles |
| 159 | * | 159 | * |
| 160 | * @param managerJavaFileHandle file handle for to manager | 160 | * @param managerJavaFileHandle file handle for to manager |
| 161 | */ | 161 | */ |
| 162 | - public void setManagerJavaFileHandle(File managerJavaFileHandle) { | 162 | + private void setManagerJavaFileHandle(File managerJavaFileHandle) { |
| 163 | this.managerJavaFileHandle = managerJavaFileHandle; | 163 | this.managerJavaFileHandle = managerJavaFileHandle; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| ... | @@ -195,7 +195,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -195,7 +195,7 @@ public class TempJavaServiceFragmentFiles |
| 195 | * | 195 | * |
| 196 | * @param rpcImplTempFileHandle the manager impl temp file | 196 | * @param rpcImplTempFileHandle the manager impl temp file |
| 197 | */ | 197 | */ |
| 198 | - public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) { | 198 | + private void setRpcImplTempFileHandle(File rpcImplTempFileHandle) { |
| 199 | this.rpcImplTempFileHandle = rpcImplTempFileHandle; | 199 | this.rpcImplTempFileHandle = rpcImplTempFileHandle; |
| 200 | } | 200 | } |
| 201 | 201 | ||
| ... | @@ -226,9 +226,8 @@ public class TempJavaServiceFragmentFiles | ... | @@ -226,9 +226,8 @@ public class TempJavaServiceFragmentFiles |
| 226 | if (isNotification) { | 226 | if (isNotification) { |
| 227 | addListenersImport(curNode, imports, true, LISTENER_SERVICE); | 227 | addListenersImport(curNode, imports, true, LISTENER_SERVICE); |
| 228 | } | 228 | } |
| 229 | - /** | 229 | + |
| 230 | - * Creates rpc interface file. | 230 | + // Creates rpc interface file. |
| 231 | - */ | ||
| 232 | setBaseCodePath(getServiceGenPath()); | 231 | setBaseCodePath(getServiceGenPath()); |
| 233 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); | 232 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); |
| 234 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports); | 233 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports); |
| ... | @@ -238,9 +237,8 @@ public class TempJavaServiceFragmentFiles | ... | @@ -238,9 +237,8 @@ public class TempJavaServiceFragmentFiles |
| 238 | addListenersImport(curNode, imports, true, LISTENER_REG); | 237 | addListenersImport(curNode, imports, true, LISTENER_REG); |
| 239 | } | 238 | } |
| 240 | addAnnotationsImports(imports, true); | 239 | addAnnotationsImports(imports, true); |
| 241 | - /** | 240 | + |
| 242 | - * Create builder class file. | 241 | + // Create builder class file. |
| 243 | - */ | ||
| 244 | if (isManagerNeedToBeGenerated()) { | 242 | if (isManagerNeedToBeGenerated()) { |
| 245 | setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX))); | 243 | setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX))); |
| 246 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode); | 244 | generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode); |
| ... | @@ -251,17 +249,16 @@ public class TempJavaServiceFragmentFiles | ... | @@ -251,17 +249,16 @@ public class TempJavaServiceFragmentFiles |
| 251 | } | 249 | } |
| 252 | addAnnotationsImports(imports, false); | 250 | addAnnotationsImports(imports, false); |
| 253 | 251 | ||
| 254 | - /** | 252 | + |
| 255 | - * Close all the file handles. | 253 | + // Close all the file handles. |
| 256 | - */ | ||
| 257 | freeTemporaryResources(false); | 254 | freeTemporaryResources(false); |
| 258 | } | 255 | } |
| 259 | 256 | ||
| 260 | /** | 257 | /** |
| 261 | * Adds rpc string information to applicable temp file. | 258 | * Adds rpc string information to applicable temp file. |
| 262 | * | 259 | * |
| 263 | - * @param javaAttributeInfoOfInput rpc's input node attribute info | 260 | + * @param javaAttributeInfoOfInput RPCs input node attribute info |
| 264 | - * @param javaAttributeInfoOfOutput rpc's output node attribute info | 261 | + * @param javaAttributeInfoOfOutput RPCs output node attribute info |
| 265 | * @param rpcName name of the rpc function | 262 | * @param rpcName name of the rpc function |
| 266 | * @param pluginConfig plugin configurations | 263 | * @param pluginConfig plugin configurations |
| 267 | * @throws IOException IO operation fail | 264 | * @throws IOException IO operation fail |
| ... | @@ -292,8 +289,8 @@ public class TempJavaServiceFragmentFiles | ... | @@ -292,8 +289,8 @@ public class TempJavaServiceFragmentFiles |
| 292 | /** | 289 | /** |
| 293 | * Adds the JAVA rpc snippet information. | 290 | * Adds the JAVA rpc snippet information. |
| 294 | * | 291 | * |
| 295 | - * @param javaAttributeInfoOfInput rpc's input node attribute info | 292 | + * @param javaAttributeInfoOfInput RPCs input node attribute info |
| 296 | - * @param javaAttributeInfoOfOutput rpc's output node attribute info | 293 | + * @param javaAttributeInfoOfOutput RPCs output node attribute info |
| 297 | * @param pluginConfig plugin configurations | 294 | * @param pluginConfig plugin configurations |
| 298 | * @param rpcName name of the rpc function | 295 | * @param rpcName name of the rpc function |
| 299 | * @throws IOException IO operation fail | 296 | * @throws IOException IO operation fail |
| ... | @@ -308,17 +305,15 @@ public class TempJavaServiceFragmentFiles | ... | @@ -308,17 +305,15 @@ public class TempJavaServiceFragmentFiles |
| 308 | /** | 305 | /** |
| 309 | * Removes all temporary file handles. | 306 | * Removes all temporary file handles. |
| 310 | * | 307 | * |
| 311 | - * @param isErrorOccurred when translator fails to generate java files we need to close all open file handles | 308 | + * @param isErrorOccurred flag to tell translator that error has occurred while file generation |
| 312 | - * include temporary files and java files. | ||
| 313 | * @throws IOException when failed to delete the temporary files | 309 | * @throws IOException when failed to delete the temporary files |
| 314 | */ | 310 | */ |
| 315 | @Override | 311 | @Override |
| 316 | public void freeTemporaryResources(boolean isErrorOccurred) | 312 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 317 | throws IOException { | 313 | throws IOException { |
| 318 | - boolean isError = isErrorOccurred; | ||
| 319 | 314 | ||
| 320 | - closeFile(getServiceInterfaceJavaFileHandle(), isError); | 315 | + closeFile(getServiceInterfaceJavaFileHandle(), isErrorOccurred); |
| 321 | - closeFile(getManagerJavaFileHandle(), isError); | 316 | + closeFile(getManagerJavaFileHandle(), isErrorOccurred); |
| 322 | 317 | ||
| 323 | closeFile(getRpcInterfaceTempFileHandle(), true); | 318 | closeFile(getRpcInterfaceTempFileHandle(), true); |
| 324 | closeFile(getRpcImplTempFileHandle(), true); | 319 | closeFile(getRpcImplTempFileHandle(), true); |
| ... | @@ -335,7 +330,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -335,7 +330,7 @@ public class TempJavaServiceFragmentFiles |
| 335 | * | 330 | * |
| 336 | * @return path where service file should be generated | 331 | * @return path where service file should be generated |
| 337 | */ | 332 | */ |
| 338 | - public String getServiceGenPath() { | 333 | + private String getServiceGenPath() { |
| 339 | return serviceGenPath; | 334 | return serviceGenPath; |
| 340 | } | 335 | } |
| 341 | 336 | ||
| ... | @@ -344,7 +339,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -344,7 +339,7 @@ public class TempJavaServiceFragmentFiles |
| 344 | * | 339 | * |
| 345 | * @param serviceGenPath path where service file should be generated | 340 | * @param serviceGenPath path where service file should be generated |
| 346 | */ | 341 | */ |
| 347 | - public void setServiceGenPath(String serviceGenPath) { | 342 | + private void setServiceGenPath(String serviceGenPath) { |
| 348 | this.serviceGenPath = serviceGenPath; | 343 | this.serviceGenPath = serviceGenPath; |
| 349 | } | 344 | } |
| 350 | 345 | ||
| ... | @@ -353,7 +348,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -353,7 +348,7 @@ public class TempJavaServiceFragmentFiles |
| 353 | * | 348 | * |
| 354 | * @return true if manager needs to be generated | 349 | * @return true if manager needs to be generated |
| 355 | */ | 350 | */ |
| 356 | - public boolean isManagerNeedToBeGenerated() { | 351 | + private boolean isManagerNeedToBeGenerated() { |
| 357 | return isManagerNeedToBeGenerated; | 352 | return isManagerNeedToBeGenerated; |
| 358 | } | 353 | } |
| 359 | 354 | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -147,7 +147,8 @@ public final class YangJavaModelUtils { | ... | @@ -147,7 +147,8 @@ public final class YangJavaModelUtils { |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | - } else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { | 150 | + } |
| 151 | + if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { | ||
| 151 | /* | 152 | /* |
| 152 | * Container | 153 | * Container |
| 153 | * Case | 154 | * Case |
| ... | @@ -189,7 +190,7 @@ public final class YangJavaModelUtils { | ... | @@ -189,7 +190,7 @@ public final class YangJavaModelUtils { |
| 189 | * @throws IOException IO operations fails | 190 | * @throws IOException IO operations fails |
| 190 | */ | 191 | */ |
| 191 | private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, | 192 | private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, |
| 192 | - YangPluginConfig yangPluginConfig) | 193 | + YangPluginConfig yangPluginConfig) |
| 193 | throws IOException { | 194 | throws IOException { |
| 194 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { | 195 | if (!(javaCodeGeneratorInfo instanceof YangNode)) { |
| 195 | throw new TranslatorException("translation is not supported for the node"); | 196 | throw new TranslatorException("translation is not supported for the node"); |
| ... | @@ -456,7 +457,7 @@ public final class YangJavaModelUtils { | ... | @@ -456,7 +457,7 @@ public final class YangJavaModelUtils { |
| 456 | /** | 457 | /** |
| 457 | * Returns augment class name. | 458 | * Returns augment class name. |
| 458 | * | 459 | * |
| 459 | - * @param augment YANG augment | 460 | + * @param augment YANG augment |
| 460 | * @param yangPluginConfig plugin configurations | 461 | * @param yangPluginConfig plugin configurations |
| 461 | * @return augment class name | 462 | * @return augment class name |
| 462 | */ | 463 | */ | ... | ... |
| ... | @@ -36,8 +36,8 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen | ... | @@ -36,8 +36,8 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen |
| 36 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq; | 36 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq; |
| 37 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired; | 37 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired; |
| 38 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 38 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
| 39 | -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | ||
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.SBI; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.SBI; |
| 40 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | ||
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Represents module information extended to support java code generation. | 43 | * Represents module information extended to support java code generation. |
| ... | @@ -212,7 +212,7 @@ public class YangJavaModule | ... | @@ -212,7 +212,7 @@ public class YangJavaModule |
| 212 | * @param rootNode root node of the data model | 212 | * @param rootNode root node of the data model |
| 213 | * @return status of rpc's existence | 213 | * @return status of rpc's existence |
| 214 | */ | 214 | */ |
| 215 | - public boolean isNotificationChildNodePresent(YangNode rootNode) { | 215 | + private boolean isNotificationChildNodePresent(YangNode rootNode) { |
| 216 | YangNode childNode = rootNode.getChild(); | 216 | YangNode childNode = rootNode.getChild(); |
| 217 | 217 | ||
| 218 | while (childNode != null) { | 218 | while (childNode != null) { |
| ... | @@ -222,9 +222,6 @@ public class YangJavaModule | ... | @@ -222,9 +222,6 @@ public class YangJavaModule |
| 222 | childNode = childNode.getNextSibling(); | 222 | childNode = childNode.getNextSibling(); |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | - if (!getNotificationNodes().isEmpty()) { | 225 | + return !getNotificationNodes().isEmpty(); |
| 226 | - return true; | ||
| 227 | - } | ||
| 228 | - return false; | ||
| 229 | } | 226 | } |
| 230 | } | 227 | } | ... | ... |
| ... | @@ -194,7 +194,6 @@ public class YangJavaSubModule | ... | @@ -194,7 +194,6 @@ public class YangJavaSubModule |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | - | ||
| 198 | /** | 197 | /** |
| 199 | * Returns notifications node list. | 198 | * Returns notifications node list. |
| 200 | * | 199 | * |
| ... | @@ -219,7 +218,7 @@ public class YangJavaSubModule | ... | @@ -219,7 +218,7 @@ public class YangJavaSubModule |
| 219 | * @param rootNode root node of the data model | 218 | * @param rootNode root node of the data model |
| 220 | * @return status of rpc's existence | 219 | * @return status of rpc's existence |
| 221 | */ | 220 | */ |
| 222 | - public boolean isNotificationChildNodePresent(YangNode rootNode) { | 221 | + private boolean isNotificationChildNodePresent(YangNode rootNode) { |
| 223 | YangNode childNode = rootNode.getChild(); | 222 | YangNode childNode = rootNode.getChild(); |
| 224 | 223 | ||
| 225 | while (childNode != null) { | 224 | while (childNode != null) { |
| ... | @@ -229,9 +228,6 @@ public class YangJavaSubModule | ... | @@ -229,9 +228,6 @@ public class YangJavaSubModule |
| 229 | childNode = childNode.getNextSibling(); | 228 | childNode = childNode.getNextSibling(); |
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | - if (!getNotificationNodes().isEmpty()) { | 231 | + return !getNotificationNodes().isEmpty(); |
| 233 | - return true; | ||
| 234 | - } | ||
| 235 | - return false; | ||
| 236 | } | 232 | } |
| 237 | } | 233 | } | ... | ... |
| ... | @@ -182,7 +182,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -182,7 +182,7 @@ public final class ClassDefinitionGenerator { |
| 182 | * @return definition | 182 | * @return definition |
| 183 | */ | 183 | */ |
| 184 | private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) { | 184 | private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) { |
| 185 | - if (!(curNode instanceof YangCase)) { | 185 | + if (!(curNode instanceof YangCase) && !(curNode instanceof YangAugment)) { |
| 186 | String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK); | 186 | String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK); |
| 187 | if (clsDef != null) { | 187 | if (clsDef != null) { |
| 188 | return clsDef; | 188 | return clsDef; | ... | ... |
| ... | @@ -42,10 +42,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP; | ... | @@ -42,10 +42,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; |
| 43 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 44 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 45 | +import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR; | ||
| 46 | +import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR; | ||
| 45 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
| 46 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT; | 50 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT; |
| 51 | +import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR; | ||
| 52 | +import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR; | ||
| 49 | import static org.onosproject.yangutils.utils.UtilConstants.MAP; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.MAP; |
| 50 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
| 51 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 55 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| ... | @@ -61,6 +65,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_I | ... | @@ -61,6 +65,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_I |
| 61 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 62 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | 66 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.TYPE; | 67 | import static org.onosproject.yangutils.utils.UtilConstants.TYPE; |
| 68 | +import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR; | ||
| 69 | +import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR; | ||
| 70 | +import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE_ATTR; | ||
| 71 | +import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE_ATTR; | ||
| 64 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; | 72 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; |
| 65 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; | 73 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; |
| 66 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | 74 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
| ... | @@ -97,22 +105,23 @@ public final class JavaCodeSnippetGen { | ... | @@ -97,22 +105,23 @@ public final class JavaCodeSnippetGen { |
| 97 | * @param importInfo import info | 105 | * @param importInfo import info |
| 98 | * @return the textual java code information corresponding to the import list | 106 | * @return the textual java code information corresponding to the import list |
| 99 | */ | 107 | */ |
| 100 | - public static String getImportText(JavaQualifiedTypeInfo importInfo) { | 108 | + static String getImportText(JavaQualifiedTypeInfo importInfo) { |
| 101 | return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE; | 109 | return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE; |
| 102 | } | 110 | } |
| 103 | 111 | ||
| 104 | /** | 112 | /** |
| 105 | * Returns the textual java code for attribute definition in class. | 113 | * Returns the textual java code for attribute definition in class. |
| 106 | * | 114 | * |
| 107 | - * @param javaAttributeTypePkg Package of the attribute type | 115 | + * @param javaAttributeTypePkg Package of the attribute type |
| 108 | - * @param javaAttributeType java attribute type | 116 | + * @param javaAttributeType java attribute type |
| 109 | - * @param javaAttributeName name of the attribute | 117 | + * @param javaAttributeName name of the attribute |
| 110 | - * @param isList is list attribute | 118 | + * @param isList is list attribute |
| 111 | - * @param attributeAccessType attribute access type | 119 | + * @param attributeAccessType attribute access type |
| 112 | - * @return the textual java code for attribute definition in class | 120 | + * @return the textual java code for attribute definition in class |
| 113 | */ | 121 | */ |
| 114 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, | 122 | public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType, |
| 115 | - String javaAttributeName, boolean isList, String attributeAccessType) { | 123 | + String javaAttributeName, boolean isList, |
| 124 | + String attributeAccessType) { | ||
| 116 | 125 | ||
| 117 | String attributeDefination = attributeAccessType + SPACE; | 126 | String attributeDefination = attributeAccessType + SPACE; |
| 118 | 127 | ||
| ... | @@ -209,7 +218,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -209,7 +218,7 @@ public final class JavaCodeSnippetGen { |
| 209 | * | 218 | * |
| 210 | * @return event enum start | 219 | * @return event enum start |
| 211 | */ | 220 | */ |
| 212 | - public static String getEventEnumTypeStart() { | 221 | + static String getEventEnumTypeStart() { |
| 213 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET | 222 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET |
| 214 | + NEW_LINE; | 223 | + NEW_LINE; |
| 215 | } | 224 | } |
| ... | @@ -261,7 +270,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -261,7 +270,7 @@ public final class JavaCodeSnippetGen { |
| 261 | * @param className enum's class name | 270 | * @param className enum's class name |
| 262 | * @return enum's attribute | 271 | * @return enum's attribute |
| 263 | */ | 272 | */ |
| 264 | - public static String getEnumsValueAttribute(String className) { | 273 | + static String getEnumsValueAttribute(String className) { |
| 265 | return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) | 274 | return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) |
| 266 | + SEMI_COLAN + NEW_LINE; | 275 | + SEMI_COLAN + NEW_LINE; |
| 267 | } | 276 | } |
| ... | @@ -271,7 +280,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -271,7 +280,7 @@ public final class JavaCodeSnippetGen { |
| 271 | * | 280 | * |
| 272 | * @return component string | 281 | * @return component string |
| 273 | */ | 282 | */ |
| 274 | - public static String addComponentString() { | 283 | + static String addComponentString() { |
| 275 | return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE | 284 | return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE |
| 276 | + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION; | 285 | + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION; |
| 277 | } | 286 | } |
| ... | @@ -281,11 +290,46 @@ public final class JavaCodeSnippetGen { | ... | @@ -281,11 +290,46 @@ public final class JavaCodeSnippetGen { |
| 281 | * | 290 | * |
| 282 | * @return attribute for augmentation | 291 | * @return attribute for augmentation |
| 283 | */ | 292 | */ |
| 284 | - public static String addAugmentationAttribute() { | 293 | + static String addAugmentationAttribute() { |
| 285 | return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING | 294 | return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING |
| 286 | + DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO | 295 | + DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO |
| 287 | + DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE + | 296 | + DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE + |
| 288 | NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS | 297 | NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS |
| 289 | + CLOSE_PARENTHESIS + SEMI_COLAN; | 298 | + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 290 | } | 299 | } |
| 300 | + | ||
| 301 | + /** | ||
| 302 | + * Adds attribute for int ranges. | ||
| 303 | + * | ||
| 304 | + * @param modifier modifier for attribute | ||
| 305 | + * @param addFirst true if int need to be added fist. | ||
| 306 | + * @return attribute for int ranges | ||
| 307 | + */ | ||
| 308 | + static String addStaticAttributeIntRange(String modifier, boolean addFirst) { | ||
| 309 | + if (addFirst) { | ||
| 310 | + return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + INT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + | ||
| 311 | + modifier + | ||
| 312 | + SPACE + INT_MAX_RANGE_ATTR; | ||
| 313 | + } else { | ||
| 314 | + return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + UINT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + | ||
| 315 | + modifier + SPACE + UINT_MAX_RANGE_ATTR; | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + /** | ||
| 320 | + * Adds attribute for long ranges. | ||
| 321 | + * | ||
| 322 | + * @param modifier modifier for attribute | ||
| 323 | + * @param addFirst if need to be added first | ||
| 324 | + * @return attribute for long ranges | ||
| 325 | + */ | ||
| 326 | + static String addStaticAttributeLongRange(String modifier, boolean addFirst) { | ||
| 327 | + if (addFirst) { | ||
| 328 | + return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + LONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + | ||
| 329 | + modifier + SPACE + LONG_MAX_RANGE_ATTR; | ||
| 330 | + } else { | ||
| 331 | + return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MIN_RANGE_ATTR + | ||
| 332 | + FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MAX_RANGE_ATTR; | ||
| 333 | + } | ||
| 334 | + } | ||
| 291 | } | 335 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -57,7 +57,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -57,7 +57,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
| 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK; | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK; |
| 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK; | 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK; |
| 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
| 60 | -import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK; | ||
| 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 60 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
| 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
| 63 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
| ... | @@ -120,10 +119,10 @@ public final class JavaFileGeneratorUtils { | ... | @@ -120,10 +119,10 @@ public final class JavaFileGeneratorUtils { |
| 120 | /** | 119 | /** |
| 121 | * Returns a file object for generated file. | 120 | * Returns a file object for generated file. |
| 122 | * | 121 | * |
| 123 | - * @param filePath file package path | 122 | + * @param filePath file package path |
| 124 | - * @param fileName file name | 123 | + * @param fileName file name |
| 125 | - * @param extension file extension | 124 | + * @param extension file extension |
| 126 | - * @param baseCodePath cached file handle | 125 | + * @param baseCodePath cached file handle |
| 127 | * @return file object | 126 | * @return file object |
| 128 | */ | 127 | */ |
| 129 | public static File getFileObject(String filePath, String fileName, String extension, String baseCodePath) { | 128 | public static File getFileObject(String filePath, String fileName, String extension, String baseCodePath) { |
| ... | @@ -205,10 +204,6 @@ public final class JavaFileGeneratorUtils { | ... | @@ -205,10 +204,6 @@ public final class JavaFileGeneratorUtils { |
| 205 | return tempJavaFragmentFiles | 204 | return tempJavaFragmentFiles |
| 206 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle(), | 205 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle(), |
| 207 | absolutePath); | 206 | absolutePath); |
| 208 | - } else if ((generatedTempFiles & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) { | ||
| 209 | - return tempJavaFragmentFiles | ||
| 210 | - .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAugmentConstructorImplTempFileHandle(), | ||
| 211 | - absolutePath); | ||
| 212 | } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { | 207 | } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { |
| 213 | if (typeFragmentFiles == null) { | 208 | if (typeFragmentFiles == null) { |
| 214 | throw new TranslatorException("Required of string implementation info is missing."); | 209 | throw new TranslatorException("Required of string implementation info is missing."); | ... | ... |
This diff is collapsed. Click to expand it.
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.translator.tojava.utils; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * Validator types for union when there is conflict between two types. | ||
| 21 | + */ | ||
| 22 | +public enum ValidatorTypeForUnionTypes { | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * When conflict is there for int32 and uint16. | ||
| 26 | + */ | ||
| 27 | + INT_TYPE_CONFLICT, | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * When conflict is there for int64 and uint32. | ||
| 31 | + */ | ||
| 32 | + LONG_TYPE_CONFLICT | ||
| 33 | +} |
| ... | @@ -127,6 +127,16 @@ public final class UtilConstants { | ... | @@ -127,6 +127,16 @@ public final class UtilConstants { |
| 127 | public static final String JAVA_DOC_GETTERS = " * Returns the attribute "; | 127 | public static final String JAVA_DOC_GETTERS = " * Returns the attribute "; |
| 128 | 128 | ||
| 129 | /** | 129 | /** |
| 130 | + * JavaDocs's description for getter method. | ||
| 131 | + */ | ||
| 132 | + public static final String JAVA_DOC_FOR_VALIDATOR = " * Validates if value is in given range."; | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * JavaDocs's description for getter method. | ||
| 136 | + */ | ||
| 137 | + public static final String JAVA_DOC_FOR_VALIDATOR_RETURN = " * @return true if value is in range"; | ||
| 138 | + | ||
| 139 | + /** | ||
| 130 | * JavaDocs's description for constructor. | 140 | * JavaDocs's description for constructor. |
| 131 | */ | 141 | */ |
| 132 | public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of "; | 142 | public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of "; |
| ... | @@ -292,6 +302,108 @@ public final class UtilConstants { | ... | @@ -292,6 +302,108 @@ public final class UtilConstants { |
| 292 | public static final String SPACE = " "; | 302 | public static final String SPACE = " "; |
| 293 | 303 | ||
| 294 | /** | 304 | /** |
| 305 | + * Static attribute for validateRange. | ||
| 306 | + */ | ||
| 307 | + public static final String VALIDATE_RANGE = "validateRange"; | ||
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * Static attribute for minRange. | ||
| 311 | + */ | ||
| 312 | + public static final String MIN_RANGE = "minRange"; | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * Static attribute for maxRange. | ||
| 316 | + */ | ||
| 317 | + public static final String MAX_RANGE = "maxRange"; | ||
| 318 | + | ||
| 319 | + /** | ||
| 320 | + * Static attribute for minRange. | ||
| 321 | + */ | ||
| 322 | + public static final String INT_MIN_RANGE_ATTR = "static final int INT32_MIN_RANGE = -2147483648;\n"; | ||
| 323 | + | ||
| 324 | + /** | ||
| 325 | + * Static attribute for minRange. | ||
| 326 | + */ | ||
| 327 | + public static final String INT_MIN_RANGE = "INT32_MIN_RANGE"; | ||
| 328 | + | ||
| 329 | + /** | ||
| 330 | + * Static attribute for minRange. | ||
| 331 | + */ | ||
| 332 | + public static final String INT_MAX_RANGE = "INT32_MAX_RANGE"; | ||
| 333 | + | ||
| 334 | + /** | ||
| 335 | + * Static attribute for maxRange. | ||
| 336 | + */ | ||
| 337 | + public static final String INT_MAX_RANGE_ATTR = "static final int INT32_MAX_RANGE = 2147483647;"; | ||
| 338 | + | ||
| 339 | + | ||
| 340 | + /** | ||
| 341 | + * Static attribute for minRange. | ||
| 342 | + */ | ||
| 343 | + public static final String UINT_MIN_RANGE_ATTR = "static final int UINT16_MIN_RANGE = 0;\n"; | ||
| 344 | + | ||
| 345 | + /** | ||
| 346 | + * Static attribute for maxRange. | ||
| 347 | + */ | ||
| 348 | + public static final String UINT_MAX_RANGE_ATTR = "static final int UINT16_MAX_RANGE = 2147483647;"; | ||
| 349 | + | ||
| 350 | + | ||
| 351 | + /** | ||
| 352 | + * Static attribute for minRange. | ||
| 353 | + */ | ||
| 354 | + public static final String UINT_MIN_RANGE = "UINT16_MIN_RANGE"; | ||
| 355 | + | ||
| 356 | + /** | ||
| 357 | + * Static attribute for maxRange. | ||
| 358 | + */ | ||
| 359 | + public static final String UINT_MAX_RANGE = "UINT16_MAX_RANGE"; | ||
| 360 | + | ||
| 361 | + /** | ||
| 362 | + * Static attribute for minRange. | ||
| 363 | + */ | ||
| 364 | + public static final String LONG_MIN_RANGE_ATTR = "static final BigInteger INT64_MIN_RANGE =" + | ||
| 365 | + " new BigInteger(\"-9223372036854775808\");\n"; | ||
| 366 | + | ||
| 367 | + /** | ||
| 368 | + * Static attribute for maxRange. | ||
| 369 | + */ | ||
| 370 | + public static final String LONG_MAX_RANGE_ATTR = "static final BigInteger INT64_MAX_RANGE =" + | ||
| 371 | + " new BigInteger(\"9223372036854775807\");"; | ||
| 372 | + | ||
| 373 | + /** | ||
| 374 | + * Static attribute for minRange. | ||
| 375 | + */ | ||
| 376 | + public static final String LONG_MIN_RANGE = "INT64_MIN_RANGE"; | ||
| 377 | + | ||
| 378 | + /** | ||
| 379 | + * Static attribute for maxRange. | ||
| 380 | + */ | ||
| 381 | + public static final String LONG_MAX_RANGE = "INT64_MAX_RANGE"; | ||
| 382 | + | ||
| 383 | + /** | ||
| 384 | + * Static attribute for minRange. | ||
| 385 | + */ | ||
| 386 | + public static final String ULONG_MIN_RANGE_ATTR = "static final BigInteger UINT32_MIN_RANGE =" + | ||
| 387 | + " new BigInteger(\"0\");\n"; | ||
| 388 | + | ||
| 389 | + /** | ||
| 390 | + * Static attribute for maxRange. | ||
| 391 | + */ | ||
| 392 | + public static final String ULONG_MAX_RANGE_ATTR = "static final BigInteger UINT32_MAX_RANGE =" + | ||
| 393 | + " new BigInteger(\"9223372036854775807\");"; | ||
| 394 | + | ||
| 395 | + | ||
| 396 | + /** | ||
| 397 | + * Static attribute for minRange. | ||
| 398 | + */ | ||
| 399 | + public static final String ULONG_MIN_RANGE = "UINT32_MIN_RANGE"; | ||
| 400 | + | ||
| 401 | + /** | ||
| 402 | + * Static attribute for maxRange. | ||
| 403 | + */ | ||
| 404 | + public static final String ULONG_MAX_RANGE = "UINT32_MAX_RANGE"; | ||
| 405 | + | ||
| 406 | + /** | ||
| 295 | * Static attribute for subject. | 407 | * Static attribute for subject. |
| 296 | */ | 408 | */ |
| 297 | public static final String SUBJECT = "Subject"; | 409 | public static final String SUBJECT = "Subject"; |
| ... | @@ -347,16 +459,6 @@ public final class UtilConstants { | ... | @@ -347,16 +459,6 @@ public final class UtilConstants { |
| 347 | public static final String IDENTITYREF = "identityref"; | 459 | public static final String IDENTITYREF = "identityref"; |
| 348 | 460 | ||
| 349 | /** | 461 | /** |
| 350 | - * Static attribute for binary string. | ||
| 351 | - */ | ||
| 352 | - public static final String BINARY_STRING = "binary"; | ||
| 353 | - | ||
| 354 | - /** | ||
| 355 | - * Static attribute for bits string. | ||
| 356 | - */ | ||
| 357 | - public static final String BITS_STRING = "bits"; | ||
| 358 | - | ||
| 359 | - /** | ||
| 360 | * Static attribute for output variable of rpc. | 462 | * Static attribute for output variable of rpc. |
| 361 | */ | 463 | */ |
| 362 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; | 464 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; |
| ... | @@ -612,6 +714,11 @@ public final class UtilConstants { | ... | @@ -612,6 +714,11 @@ public final class UtilConstants { |
| 612 | public static final String TMP_VAL = "tmpVal"; | 714 | public static final String TMP_VAL = "tmpVal"; |
| 613 | 715 | ||
| 614 | /** | 716 | /** |
| 717 | + * Static attribute for close curly bracket syntax. | ||
| 718 | + */ | ||
| 719 | + public static final String ELSE = "else"; | ||
| 720 | + | ||
| 721 | + /** | ||
| 615 | * From string parameter name. | 722 | * From string parameter name. |
| 616 | */ | 723 | */ |
| 617 | public static final String FROM_STRING_PARAM_NAME = "valInString"; | 724 | public static final String FROM_STRING_PARAM_NAME = "valInString"; | ... | ... |
| ... | @@ -17,6 +17,10 @@ | ... | @@ -17,6 +17,10 @@ |
| 17 | package org.onosproject.yangutils.utils.io.impl; | 17 | package org.onosproject.yangutils.utils.io.impl; |
| 18 | 18 | ||
| 19 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; | 19 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; |
| 20 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR; | ||
| 21 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN; | ||
| 22 | +import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE; | ||
| 23 | +import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE; | ||
| 20 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; |
| 21 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 22 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; |
| ... | @@ -519,6 +523,11 @@ public final class JavaDocGen { | ... | @@ -519,6 +523,11 @@ public final class JavaDocGen { |
| 519 | VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | 523 | VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
| 520 | } | 524 | } |
| 521 | 525 | ||
| 526 | + /** | ||
| 527 | + * Returns javadoc for get augmentation method. | ||
| 528 | + * | ||
| 529 | + * @return javadoc for get augmentation method | ||
| 530 | + */ | ||
| 522 | public static String generateForGetAugmentation() { | 531 | public static String generateForGetAugmentation() { |
| 523 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 532 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
| 524 | + JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE + | 533 | + JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE + |
| ... | @@ -529,6 +538,23 @@ public final class JavaDocGen { | ... | @@ -529,6 +538,23 @@ public final class JavaDocGen { |
| 529 | } | 538 | } |
| 530 | 539 | ||
| 531 | /** | 540 | /** |
| 541 | + * Returns javadoc for validator method. | ||
| 542 | + * | ||
| 543 | + * @return javadoc for validator method | ||
| 544 | + */ | ||
| 545 | + public static String generateForValidatorMethod() { | ||
| 546 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + | ||
| 547 | + JAVA_DOC_FOR_VALIDATOR + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + | ||
| 548 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MIN_RANGE + SPACE + MIN_RANGE + SPACE + OF + SPACE + | ||
| 549 | + VALUE + NEW_LINE + | ||
| 550 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MAX_RANGE + SPACE + MAX_RANGE + SPACE + OF + SPACE + VALUE + | ||
| 551 | + NEW_LINE + | ||
| 552 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + NEW_LINE + | ||
| 553 | + FOUR_SPACE_INDENTATION + JAVA_DOC_FOR_VALIDATOR_RETURN + NEW_LINE + FOUR_SPACE_INDENTATION + | ||
| 554 | + JAVA_DOC_END_LINE; | ||
| 555 | + } | ||
| 556 | + | ||
| 557 | + /** | ||
| 532 | * JavaDocs types. | 558 | * JavaDocs types. |
| 533 | */ | 559 | */ |
| 534 | public enum JavaDocType { | 560 | public enum JavaDocType { | ... | ... |
| ... | @@ -39,7 +39,7 @@ public class ManagerCodeGeneratorTest { | ... | @@ -39,7 +39,7 @@ public class ManagerCodeGeneratorTest { |
| 39 | /** | 39 | /** |
| 40 | * Checks manager translation should not result in any exception. | 40 | * Checks manager translation should not result in any exception. |
| 41 | * | 41 | * |
| 42 | - * @throws MojoExecutionException | 42 | + * @throws MojoExecutionException when fails to do mojo operations |
| 43 | */ | 43 | */ |
| 44 | @Test | 44 | @Test |
| 45 | public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException { | 45 | public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException { |
| ... | @@ -73,7 +73,7 @@ public class ManagerCodeGeneratorTest { | ... | @@ -73,7 +73,7 @@ public class ManagerCodeGeneratorTest { |
| 73 | /** | 73 | /** |
| 74 | * Checks manager translation in different package should not result in any exception. | 74 | * Checks manager translation in different package should not result in any exception. |
| 75 | * | 75 | * |
| 76 | - * @throws MojoExecutionException | 76 | + * @throws MojoExecutionException when fails to do mojo operations |
| 77 | */ | 77 | */ |
| 78 | @Test | 78 | @Test |
| 79 | public void processManagerInDifferentPackageTranslator() throws IOException, ParserException, | 79 | public void processManagerInDifferentPackageTranslator() throws IOException, ParserException, |
| ... | @@ -102,7 +102,7 @@ public class ManagerCodeGeneratorTest { | ... | @@ -102,7 +102,7 @@ public class ManagerCodeGeneratorTest { |
| 102 | /** | 102 | /** |
| 103 | * Checks manager translation in different package should not result in any exception. | 103 | * Checks manager translation in different package should not result in any exception. |
| 104 | * | 104 | * |
| 105 | - * @throws MojoExecutionException | 105 | + * @throws MojoExecutionException when fails to do mojo operations |
| 106 | */ | 106 | */ |
| 107 | @Test | 107 | @Test |
| 108 | public void processManagerforMultiChildTranslator() throws IOException, ParserException, | 108 | public void processManagerforMultiChildTranslator() throws IOException, ParserException, |
| ... | @@ -140,6 +140,42 @@ public class ManagerCodeGeneratorTest { | ... | @@ -140,6 +140,42 @@ public class ManagerCodeGeneratorTest { |
| 140 | assertThat(true, is(manager4.exists())); | 140 | assertThat(true, is(manager4.exists())); |
| 141 | 141 | ||
| 142 | deleteDirectory("target/manager/"); | 142 | deleteDirectory("target/manager/"); |
| 143 | + deleteDirectory("target/manager/"); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * Checks manager translation in different package should not result in any exception. | ||
| 148 | + * | ||
| 149 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 150 | + */ | ||
| 151 | + @Test | ||
| 152 | + public void processManagerforMultiChildWithDifferentPackageTranslator() throws IOException, ParserException, | ||
| 153 | + MojoExecutionException { | ||
| 154 | + | ||
| 155 | + String searchDir = "src/test/resources/manager/MultiChild"; | ||
| 156 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 157 | + utilManager.parseYangFileInfoSet(); | ||
| 158 | + utilManager.createYangNodeSet(); | ||
| 159 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 160 | + | ||
| 161 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 162 | + yangPluginConfig.setCodeGenDir("target/manager/"); | ||
| 163 | + yangPluginConfig.setManagerCodeGenDir("target/manager1/"); | ||
| 164 | + | ||
| 165 | + utilManager.translateToJava(yangPluginConfig); | ||
| 166 | + | ||
| 167 | + String file1 = "target/manager1/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java"; | ||
| 168 | + | ||
| 169 | + File manager1 = new File(file1); | ||
| 170 | + assertThat(true, is(manager1.exists())); | ||
| 171 | + | ||
| 172 | + | ||
| 173 | + String file2 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Service.java"; | ||
| 174 | + | ||
| 175 | + File service2 = new File(file2); | ||
| 176 | + assertThat(true, is(service2.exists())); | ||
| 177 | + | ||
| 178 | + deleteDirectory("target/manager/"); | ||
| 143 | deleteDirectory("target/manager1/"); | 179 | deleteDirectory("target/manager1/"); |
| 144 | } | 180 | } |
| 145 | } | 181 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.plugin.manager; | ||
| 18 | + | ||
| 19 | +import java.io.IOException; | ||
| 20 | + | ||
| 21 | +import org.apache.maven.plugin.MojoExecutionException; | ||
| 22 | +import org.junit.Test; | ||
| 23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 24 | +import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | ||
| 25 | +import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; | ||
| 26 | + | ||
| 27 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Unit test case for typedef translator. | ||
| 31 | + */ | ||
| 32 | +public class TypeDefTranslatorTest { | ||
| 33 | + | ||
| 34 | + private final YangUtilManager utilManager = new YangUtilManager(); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Checks typedef translation should not result in any exception. | ||
| 38 | + * | ||
| 39 | + * @throws MojoExecutionException | ||
| 40 | + */ | ||
| 41 | + @Test | ||
| 42 | + public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException { | ||
| 43 | + | ||
| 44 | + String searchDir = "src/test/resources/typedefTranslator"; | ||
| 45 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 46 | + utilManager.parseYangFileInfoSet(); | ||
| 47 | + utilManager.createYangNodeSet(); | ||
| 48 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 49 | + | ||
| 50 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 51 | + yangPluginConfig.setCodeGenDir("target/typedefTranslator/"); | ||
| 52 | + yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/"); | ||
| 53 | + utilManager.translateToJava(yangPluginConfig); | ||
| 54 | + | ||
| 55 | + deleteDirectory("target/typedefTranslator/"); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | +} |
| ... | @@ -18,10 +18,12 @@ package org.onosproject.yangutils.plugin.manager; | ... | @@ -18,10 +18,12 @@ package org.onosproject.yangutils.plugin.manager; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | 20 | ||
| 21 | +import org.apache.maven.plugin.MojoExecutionException; | ||
| 21 | import org.junit.Test; | 22 | import org.junit.Test; |
| 22 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 23 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 24 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 25 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 26 | +import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | ||
| 25 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; | 27 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
| 26 | 28 | ||
| 27 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | 29 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
| ... | @@ -52,5 +54,168 @@ public final class UnionTranslatorTest { | ... | @@ -52,5 +54,168 @@ public final class UnionTranslatorTest { |
| 52 | deleteDirectory("target/UnionTestGenFile/"); | 54 | deleteDirectory("target/UnionTestGenFile/"); |
| 53 | } | 55 | } |
| 54 | 56 | ||
| 57 | + /** | ||
| 58 | + * Unit test case to test conflicting types. | ||
| 59 | + * | ||
| 60 | + * @throws IOException when fails to do IO operations | ||
| 61 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 62 | + */ | ||
| 63 | + @Test | ||
| 64 | + public void processUnionIntUintConflictingTypes() throws IOException, MojoExecutionException { | ||
| 65 | + String searchDir = "src/test/resources/unionTranslator/intuint"; | ||
| 66 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 67 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 68 | + utilManager.parseYangFileInfoSet(); | ||
| 69 | + utilManager.createYangNodeSet(); | ||
| 70 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 71 | + | ||
| 72 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 73 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 74 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 75 | + | ||
| 76 | + utilManager.translateToJava(yangPluginConfig); | ||
| 77 | + deleteDirectory("target/unionTranslator/"); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Unit test case to test conflicting types. | ||
| 82 | + * | ||
| 83 | + * @throws IOException when fails to do IO operations | ||
| 84 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 85 | + */ | ||
| 86 | + @Test | ||
| 87 | + public void processUnionUintIntConflictingTypes() throws IOException, MojoExecutionException { | ||
| 88 | + String searchDir = "src/test/resources/unionTranslator/uintint"; | ||
| 89 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 90 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 91 | + utilManager.parseYangFileInfoSet(); | ||
| 92 | + utilManager.createYangNodeSet(); | ||
| 93 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 94 | + | ||
| 95 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 96 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 97 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 98 | + | ||
| 99 | + utilManager.translateToJava(yangPluginConfig); | ||
| 100 | + deleteDirectory("target/unionTranslator/"); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Unit test case to test conflicting types. | ||
| 105 | + * | ||
| 106 | + * @throws IOException when fails to do IO operations | ||
| 107 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 108 | + */ | ||
| 109 | + @Test | ||
| 110 | + public void processUnionLongUlongConflictingTypes() throws IOException, MojoExecutionException { | ||
| 111 | + String searchDir = "src/test/resources/unionTranslator/longulong"; | ||
| 112 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 113 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 114 | + utilManager.parseYangFileInfoSet(); | ||
| 115 | + utilManager.createYangNodeSet(); | ||
| 116 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 117 | + | ||
| 118 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 119 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 120 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 121 | + | ||
| 122 | + utilManager.translateToJava(yangPluginConfig); | ||
| 123 | + deleteDirectory("target/unionTranslator/"); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * Unit test case to test conflicting types. | ||
| 128 | + * | ||
| 129 | + * @throws IOException when fails to do IO operations | ||
| 130 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 131 | + */ | ||
| 132 | + @Test | ||
| 133 | + public void processUnionUlongLongConflictingTypes() throws IOException, MojoExecutionException { | ||
| 134 | + String searchDir = "src/test/resources/unionTranslator/ulonglong"; | ||
| 135 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 136 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 137 | + utilManager.parseYangFileInfoSet(); | ||
| 138 | + utilManager.createYangNodeSet(); | ||
| 139 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 140 | + | ||
| 141 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 142 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 143 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 144 | + | ||
| 145 | + utilManager.translateToJava(yangPluginConfig); | ||
| 146 | + deleteDirectory("target/unionTranslator/"); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * Unit test case to test conflicting types. | ||
| 151 | + * | ||
| 152 | + * @throws IOException when fails to do IO operations | ||
| 153 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 154 | + */ | ||
| 155 | + @Test | ||
| 156 | + public void processUnionIntUintUlongLongConflictingTypes() throws IOException, MojoExecutionException { | ||
| 157 | + String searchDir = "src/test/resources/unionTranslator/intuintulonglong"; | ||
| 158 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 159 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 160 | + utilManager.parseYangFileInfoSet(); | ||
| 161 | + utilManager.createYangNodeSet(); | ||
| 162 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 163 | + | ||
| 164 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 165 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 166 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 167 | + | ||
| 168 | + utilManager.translateToJava(yangPluginConfig); | ||
| 169 | + deleteDirectory("target/unionTranslator/"); | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Unit test case to test conflicting types. | ||
| 174 | + * | ||
| 175 | + * @throws IOException when fails to do IO operations | ||
| 176 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 177 | + */ | ||
| 178 | + @Test | ||
| 179 | + public void processUnionIntUintUlongLongStringConflictingTypes() throws IOException, | ||
| 180 | + MojoExecutionException { | ||
| 181 | + String searchDir = "src/test/resources/unionTranslator/intuintulonglongstring"; | ||
| 182 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 183 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 184 | + utilManager.parseYangFileInfoSet(); | ||
| 185 | + utilManager.createYangNodeSet(); | ||
| 186 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 187 | + | ||
| 188 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 189 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 190 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 191 | + | ||
| 192 | + utilManager.translateToJava(yangPluginConfig); | ||
| 193 | + deleteDirectory("target/unionTranslator/"); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * Unit test case to test conflicting types. | ||
| 198 | + * | ||
| 199 | + * @throws IOException when fails to do IO operations | ||
| 200 | + * @throws MojoExecutionException when fails to do mojo operations | ||
| 201 | + */ | ||
| 202 | + @Test | ||
| 203 | + public void processUnionIntUintStringConflictingTypes() throws IOException, | ||
| 204 | + MojoExecutionException { | ||
| 205 | + String searchDir = "src/test/resources/unionTranslator/intuintstring"; | ||
| 206 | + YangUtilManager utilManager = new YangUtilManager(); | ||
| 207 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 208 | + utilManager.parseYangFileInfoSet(); | ||
| 209 | + utilManager.createYangNodeSet(); | ||
| 210 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 211 | + | ||
| 212 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 213 | + yangPluginConfig.setCodeGenDir("target/unionTranslator/"); | ||
| 214 | + yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); | ||
| 215 | + | ||
| 216 | + utilManager.translateToJava(yangPluginConfig); | ||
| 217 | + deleteDirectory("target/unionTranslator/"); | ||
| 218 | + } | ||
| 219 | + | ||
| 55 | // TODO enhance the test cases, after having a framework of translator test. | 220 | // TODO enhance the test cases, after having a framework of translator test. |
| 56 | } | 221 | } | ... | ... |
This diff is collapsed. Click to expand it.
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type int32; | ||
| 18 | + type uint16; | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | +} | ||
| 23 | + |
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type int32; | ||
| 18 | + type string; | ||
| 19 | + type uint16; | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | +} | ||
| 24 | + |
| 1 | +module test2 { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type int64; | ||
| 18 | + type string; | ||
| 19 | + type uint16; | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | +} | ||
| 24 | + |
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type int32; | ||
| 18 | + type uint16; | ||
| 19 | + type uint32; | ||
| 20 | + type int64; | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | +} | ||
| 25 | + |
utils/yangutils/plugin/src/test/resources/unionTranslator/intuintulonglongstring/test.yang
0 → 100644
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type string; | ||
| 18 | + type int32; | ||
| 19 | + type uint16; | ||
| 20 | + type uint32; | ||
| 21 | + type int64; | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | +} | ||
| 26 | + |
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type int64; | ||
| 18 | + type uint32; | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | +} | ||
| 23 | + |
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type uint16; | ||
| 18 | + type int32; | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | +} | ||
| 23 | + |
| 1 | +module test { | ||
| 2 | + namespace "test:test"; | ||
| 3 | + prefix test ; | ||
| 4 | + | ||
| 5 | + organization ""; | ||
| 6 | + contact ""; | ||
| 7 | + | ||
| 8 | + description | ||
| 9 | + "Defines basic service types for L3VPN service."; | ||
| 10 | + | ||
| 11 | + revision "2015-12-16" { | ||
| 12 | + reference ""; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + leaf leaf1 { | ||
| 16 | + type union { | ||
| 17 | + type uint32; | ||
| 18 | + type int64; | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | +} | ||
| 23 | + |
-
Please register or login to post a comment